File size: 7,125 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php

$w = 350;
$h = 90;

//how many task, single task or multiple
$t = isset( $_GET['t'] ) ? $_GET['t'] : 's';
if ($t != 's') {
    $t = 'm';
}

//when occurs, after time elapses or when starting
$o = isset( $_GET['o'] ) ? $_GET['o'] : 's';
if ($t != 's') {
    $t = 'a';
}

//status
$s = isset( $_GET['s'] ) ? $_GET['s'] : 'a';
if ($s != 'a') {
    $s = 'i';
}

//timeUnit
$timeunit = isset( $_GET['t'] ) ? $_GET['t'] : G::LoadTranslation('ID_DAYS');
$timeunit = ucfirst( strtolower( $timeunit ) );

//estimated
$estimated = abs( isset( $_GET['e'] ) ? (($timeunit == 'Hours') ? round( $_GET['e'] / 24, 5 ) : $_GET['e']) : '1' );

//when
$when = isset( $_GET['w'] ) ? $_GET['w'] : '0';

$im = imagecreate( $w, $h );
$bg = imagecolorallocate( $im, 0xFF, 0xFF, 0xFF );
$fg = imagecolorallocate( $im, 0x00, 200, 0x00 );
$sc = imagecolorallocate( $im, 200, 0, 0 );
$gray = imagecolorallocate( $im, 180, 180, 180 );
$red = imagecolorallocate( $im, 200, 0, 0 );
$green = imagecolorallocate( $im, 0, 200, 0 );
$blue = imagecolorallocate( $im, 0, 0, 200 );
$black = imagecolorallocate( $im, 0, 0, 0 );

imagerectangle( $im, 0, 0, $w - 1, $h - 1, $gray );

//  $incM = $media/60;


//  $mean = 60*$incM;
//  $d = $varianza;
//  if ( $d == 0 ) $d = 0.0001;


//	$val1 = 1 / ( sqrt( 2*pi() *$d*$d ));
// 	$val2 =  -( pow($mean-$mean,2) )/ (pow($d,2));
// 	$y = $val1  * exp ( $val2 );
//  $incY = 80/$y;


//   $range = 90/ $d;
//   $offsetX = 100 - $mean;
//   $antY = null;
//  for ( $x = $mean -$range*$d ; $x <= $mean +$range*$d; $x++ ) {
//  	$val1 = 1 / ( sqrt( 2*pi() *$d*$d ));
//  	$val2 =  -( pow($x-$mean,2) )/ (pow($d,2));
//  	$y = $val1  * exp ( $val2 )*$incY;
//  	if ( $antY != null )
//    imageline($im, $x-1+$offsetX, $h - $antY-15, $x+$offsetX, $h-$y-15, $blue);
//    $antY = $y;
//    imageline($im, $x +$mean, $h , $x + $mean, $h-1, $red);
//  }

function drawTask ($im, $x1, $x2, $y, $h)
{
    global $w;
    $blue = imagecolorallocate( $im, 160, 160, 180 );
    $gray = imagecolorallocate( $im, 100, 100, 100 );
    $black = imagecolorallocate( $im, 0, 0, 0 );

    for ($i = $y; $i < $h; $i += 2) {
        imageline( $im, $x1, $i, $x1, $i, $gray );
        imageline( $im, $x2, $i, $x2, $i, $gray );
    }

    for ($i = $x1; $i < $x2; $i += 2) {
        imageline( $im, $i, $y - 10, $i, $y, $blue );
    }
    imagerectangle( $im, $x1, $y - 10, $x2, $y, $black );
}

function smallTask ($im, $x1, $x2, $y)
{
    $blue = imagecolorallocate( $im, 160, 160, 180 );
    $black = imagecolorallocate( $im, 0, 0, 0 );

    for ($i = $x1; $i < $x2; $i += 2) {
        imageline( $im, $i, $y - 8, $i, $y, $blue );
    }
    imagerectangle( $im, $x1, $y - 9, $x2 - 1, $y, $black );
}

function drawMultipleTask ($im, $x1, $x2, $y, $h)
{
    global $w;
    $terca = ($x2 - $x1) / 3;
    $blue = imagecolorallocate( $im, 160, 160, 180 );
    $gray = imagecolorallocate( $im, 100, 100, 100 );
    $black = imagecolorallocate( $im, 0, 0, 0 );

    for ($i = $y; $i < $h; $i += 2) {
        imageline( $im, $x2, $i, $x2, $i, $gray );
    }
    for ($i = $y - 10; $i < $h; $i += 2) {
        imageline( $im, $x1, $i, $x1, $i, $gray );
    }

    smallTask( $im, $x1 + 0 * $terca, $x1 + 1 * $terca, $y - 12 );
    smallTask( $im, $x1 + 1 * $terca, $x1 + 2 * $terca, $y - 6 );
    smallTask( $im, $x1 + 2 * $terca, $x1 + 3 * $terca, $y );
}

function drawTimerEvent ($im, $x1, $y1, $h)
{
    $blue = imagecolorallocate( $im, 160, 160, 180 );
    $red = imagecolorallocate( $im, 200, 100, 0 );
    $gray = imagecolorallocate( $im, 100, 100, 100 );
    $black = imagecolorallocate( $im, 0, 0, 0 );
    $yellow = imagecolorallocate( $im, 240, 240, 220 );

    for ($i = $y1 + 15; $i < $h; $i += 2) {
        imageline( $im, $x1, $i, $x1, $i, $gray );
    }

    ImageEllipse( $im, $x1, $y1, 26, 26, $black );
    ImageEllipse( $im, $x1, $y1, 22, 22, $black );
    ImageFilledEllipse( $im, $x1, $y1, 16, 16, $yellow );
    ImageEllipse( $im, $x1, $y1, 16, 16, $red );
    imageline( $im, $x1, $y1 - 8, $x1, $y1 + 8, $red );
    //imageline($im, $x1  , $y1+8 , $x1, $y1+6,  $red);
    imageline( $im, $x1 - 8, $y1, $x1 + 8, $y1, $red );
    imageline( $im, $x1 - 7, $y1 - 4, $x1 + 7, $y1 + 4, $red );
    imageline( $im, $x1 - 4, $y1 - 7, $x1 + 4, $y1 + 7, $red );
    imageline( $im, $x1 + 7, $y1 - 4, $x1 - 7, $y1 + 4, $red );
    imageline( $im, $x1 + 4, $y1 - 7, $x1 - 4, $y1 + 7, $red );
    ImageFilledEllipse( $im, $x1, $y1, 10, 10, $yellow );
    imageline( $im, $x1 - 1, $y1 + 1, $x1 + 1, $y1 - 5, $red );
    imageline( $im, $x1 - 1, $y1 + 1, $x1 + 3, $y1 + 1, $red );

}

imageline( $im, 15, $h - 19, $w - 15, $h - 19, $red );
imageline( $im, $w - 23, $h - 23, $w - 15, $h - 19, $red );
imageline( $im, $w - 23, $h - 15, $w - 15, $h - 19, $red );
imagestring( $im, 2, $w - 30, $h - 37, utf8_decode(G::LoadTranslation('ID_DAYS')), $red );

if ($estimated == 0) {
    $s = 'i';
    header( "Content-Type: image/png" );
    imagepng( $im );
    die();
}

if ($t == 's') {
    drawTask( $im, 80, 220, $h - 30, $h - 15 );
} else {
    drawMultipleTask( $im, 80, 220, $h - 30, $h - 15 );
}

    //the zero
imagestring( $im, 3, 80 - 4, $h - 16, '0', $black );
//the estimated
imagestring( $im, 2, 220 - 4, $h - 16, $estimated, $black );

//when is negative and the event occurs at starting, then this event never will occurs
if ($when < 0 && $o == 's') {
    $xTimer = 30;
    imagestring( $im, 2, $xTimer - 8, $h - 16, $when, $black );
    $s = 'i';
}

//when is negative and the event occurs after, then this event will occurs
if ($when < 0 && $o == 'a') {
    if (abs( $when ) > abs( $estimated )) {
        //this event is before the start of the task, so will never occurs
        $xTimer = 30;
        $sWhen = abs( $when ) - abs( $estimated );
        imagestring( $im, 2, $xTimer - 8, $h - 16, $sWhen, $black );
        $s = 'i';
    }
    if (abs( $when ) < abs( $estimated )) {
        //this event is after the start of the task, drawing
        $xTimer = 170;
        $sWhen = $estimated + $when;
        imagestring( $im, 2, $xTimer - 4, $h - 16, $sWhen, $black );
    }
    if (abs( $when ) == abs( $estimated )) {
        //this event is exactly at starting
        $xTimer = 80;
        $sWhen = $estimated + $when;
        imagestring( $im, 2, $xTimer - 4, $h - 16, $sWhen, $black );
    }
}

//when is positive and the event occurs after, then this event will occurs
if ($when > 0 && $o == 'a') {
    $xTimer = 270;
    $sWhen = $estimated + $when;
    imagestring( $im, 2, $xTimer - 4, $h - 16, $sWhen, $black );
}

//when is positive and the event occurs starting, then this event will occurs
if ($when > 0 && $o == 's') {
    if (abs( $when ) < abs( $estimated )) {
        $xTimer = 140;
    }
    if (abs( $when ) > abs( $estimated )) {
        $xTimer = 270;
    }
    if (abs( $when ) == abs( $estimated )) {
        $xTimer = 220;
    }
    imagestring( $im, 2, $xTimer - 4, $h - 16, $when, $black );
}

if ($when == 0) {
    $xTimer = ($o == 's') ? 80 : 220;
}

if ($s == 'a') {
    drawTimerEvent( $im, $xTimer, $h - 70, $h - 15 );
}

header( "Content-Type: image/png" );
imagepng( $im );
die();