/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php

class WELCOME {
 var $req;
 var $height, $width;
 var $graph;
 
 var $tmpfile;
 var $ready;
 
 function __construct(REQUEST $req = NULL) {
    global $TMP_PATH;
    global $GRAPH_DEFAULT_HEIGHT;
    global $GRAPH_DEFAULT_WIDTH;
    
    if ($req) $this->req = $req;
    else $this->req = new REQUEST();
    

    if (isset($this->req->props['frame_height'])) $this->height = $this->req->props['frame_height'];
    else $this->height = $GRAPH_DEFAULT_HEIGHT;
    if (isset($this->req->props['frame_width'])) $this->width = $this->req->props['frame_width'];
    else $this->width = $GRAPH_DEFAULT_WIDTH;

    $this->tmpfile = $this->GetTmpFile();

    if (is_file($TMP_PATH . "/" .  $this->tmpfile)) $this->ready = true;
    else $this->ready = false;
 }

 function GetTmpFile() {
    global $ADEI_SESSION;
    global $TMP_PATH;


    $props = $this->req->props;
    unset($props['window']);
    unset($props['format']);
    unset($props['mask_mode']);
    unset($props['resample']);
    unset($props['filename']);

    $dir = "clients/" . $ADEI_SESSION . "/";

    if (!is_dir($TMP_PATH . "/" .  $dir)) {
	if (!@mkdir($TMP_PATH . "/" . $dir, 0755, true)) 
	    throw new ADEIException(translate("DRAW class have not access to the temporary directory"));
    }

    return $dir . "welcome-" . $this->width . "x" . $this->height .  ".png";
 }

 
 function Create() {
    if ($this->ready) return;
    
    $this->graph = new CanvasGraph($this->width, $this->height, 'auto');
    $this->graph->SetMargin(5,11,6,11);
/*
    $this->graph->SetShadow();
    $this->graph->SetMarginColor( "teal");
    $this->graph->InitFrame(); 
*/    

    $hpos = 15;
    
    $text = new Text("ADEI", $this->width/2, $hpos);
    $text->SetFont(FF_ARIAL, FS_BOLD, 24);
    $text->Align('center', 'top');
    $text->Stroke( $this->graph->img); 

    $hpos += $text->GetTextHeight($this->graph->img) + 10;

//    $msg = "Welcome to the Advanced Data Extraction Infrastructure! Please";
    $msg = preg_replace(
	array("/\n([^\n])/"),
	array(' \1'),
	file_get_contents("docs/welcome.txt")
    );
    

    $text_width = $this->width - 50;
    if ($text_width < 100) return;

    $text = new Text($msg, $this->width/2, $hpos);
    $text->SetFont(FF_ARIAL, FS_NORMAL, 18);
    $text->Align('center', 'top');

    $width = $text->GetWidth($this->graph->img);
    if ($width > $text_width) {
	$char_width = ceil($width / strlen($msg));
	$cpl = $text_width / $char_width;

	$wmsg = wordwrap($msg, $cpl, "\n", true);
	$text->Set($wmsg);
	
	$width = $text->GetWidth($this->graph->img);
        while (($width > $text_width)&&($cpl>10)) {
	    $cpl-=$cpl/10;
	    $wmsg = wordwrap($msg, $cpl, "\n", true);
	    $text->Set($wmsg);
	    $width = $text->GetWidth($this->graph->img);
	}
    }


    $text->Stroke( $this->graph->img); 
    

//    $text->ParagraphAlign('center'); 
//    $text->SetBox( "white", "black","gray"); 


/*
//    $text->Align('left', 'top');
//    $text->ParagraphAlign('left'); 
//    $text->SetBox( "white", "black","gray"); 
    
    $width = $text->GetWidth($this->graph->img);
    
*/    
//    $text->Stroke( $this->graph->img); 
 }

 function Save($file = false) {
    global $TMP_PATH;

    if ($this->ready) {
	if ($file) {
	    copy($TMP_PATH . "/" .  $this->tmpfile, $file);
	    return true;
	}

	return $this->tmpfile;
    }

    if ($file) {
        $this->graph->Stroke($file);
	return true;
    }

    $this->graph->Stroke($TMP_PATH . "/" . $this->tmpfile);
    return $this->tmpfile;
 }

 static function Display($file = false) {
    global $TMP_PATH;
    
    if ($file) {
	if (preg_match("/^[A-Za-z0-9\/_]\.png$/",$str)) return false;
	return @readfile($TMP_PATH . "/" . $file);
    }

    return false;    
 }
}

?>