source: trunk/workflow/inc/class.powergraphic.inc.php @ 795

Revision 795, 50.4 KB checked in by viani, 15 years ago (diff)

Ticket #488 - Inclusão do módulo workflow no ramo trunk do repositório Expresso.

Line 
1<?php
2/**
3*
4*   PowerGraphic
5*   version 1.0
6*
7*
8*
9* Author: Carlos Reche
10* Author: Sidnei Augusto Drovetto Junior (revision) Apr 30, 2007
11* E-mail: carlosreche@yahoo.com
12* Sorocaba, SP - Brazil
13*
14* Created: Sep 20, 2004
15* Last Modification: Sep 20, 2004
16*
17*
18*
19*  Authors' comments:
20*
21*  PowerGraphic creates 6 different types of graphics with how many parameters you want. You can
22*  change the appearance of the graphics in 3 different skins, and you can still cross data from 2
23*  graphics in only 1! It's a powerful script, and I recommend you read all the instructions
24*  to learn how to use all of this features. Don't worry, it's very simple to use it.
25*
26*  This script is free. Please keep the credits.
27*
28*/
29
30/**
31
32   INSTRUNCTIONS OF HOW TO USE THIS SCRIPT  (Please, take a minute to read it. It's important!)
33
34
35   NOTE: make sure that your PHP is compiled to work with GD Lib.
36
37   NOTE: You may create test images using a form that comes with this script. Just add a "showform"
38   as a query string. (Example: "graphic.php?showform")
39
40
41   PowerGraphic works with query strings (information sent after the "?" of an URL). Here is an
42   example of how you will have to send the graphic information. Let's suppose that you want to
43   show a graphic of your user's sex:
44
45       <img src="graphic.php?title=Sex&type=5&x1=male&y1=50&x2=female&y2=55" />
46
47   This will create a pie graphic (set by type=5) with title as "Sex" and default skin.
48   Let's see the other parameters:
49
50       x1 = male
51       y1 = 50 (quantity of males)
52       x2 = female
53       y2 = 55 (quantity of females)
54
55   See how it's simple! :)
56   For those who don't know, to create a query string you have to put an "?" at the end of the URL and join
57   the parameters with "&". Example: "graphic.php?Parameter_1=Value_1&Parameter_2=Value_2" (and so on). You
58   can set how many parameters you want.
59
60   The boring step would be to create this query string. Well, "would be", if I didn't create a function to do that. :)
61   Let's see an example of how you can use this function in a PHP document:
62
63
64///// START OF EXAMPLE /////
65
66<?php
67
68require "class.graphics.php";
69$PG = new PowerGraphic;
70
71$PG->title = "Sex";
72$PG->type  = "5";
73$PG->x[0]  = "male";
74$PG->y[0]  = "50";
75$PG->x[1]  = "female";
76$PG->y[1]  = "55";
77
78echo '<img src="graphic.php?' . $PG->create_query_string() . '" />';
79
80
81// If you're going to create more than 1 graphic, it'll be important to reset the values before
82// create the next query string:
83$PG->reset_values();
84
85?>
86
87///// END OF EXAMPLE /////
88
89
90
91   Here is a list of all parameters you may set:
92
93   title      =>  Title of the graphic
94   axis_x     =>  Name of values from Axis X
95   axis_y     =>  Name of values from Axis Y
96   graphic_1  =>  Name of Graphic_1 (only shown if you are gonna cross data from 2 different graphics)
97   graphic_2  =>  Name of Graphic_2 (same comment of above)
98
99   type  =>  Type of graphic (values 1 to 6)
100                1 => Vertical bars (default)
101                2 => Horizontal bars
102                3 => Dots
103                4 => Lines
104                5 => Pie
105                6 => Donut
106
107   skin   => Skin of the graphic (values 1 to 3)
108                1 => Office (default)
109                2 => Matrix
110                3 => Spring
111
112   credits => Only if you want to show my credits in the image. :)
113                0 => doesn't show (default)
114                1 => shows
115
116   x[0]  =>  Name of the first parameter in Axis X
117   x[1]  =>  Name of the second parameter in Axis X
118   ... (etc)
119
120   y[0]  =>  Value from "graphic_1" relative for "x[0]"
121   y[1]  =>  Value from "graphic_1" relative for "x[1]"
122   ... (etc)
123
124   z[0]  =>  Value from "graphic_2" relative for "x[0]"
125   z[1]  =>  Value from "graphic_2" relative for "x[1]"
126   ... (etc)
127
128   NOTE: You can't cross data between graphics if you use "pie" or "donut" graphic. Values for "z"
129   won't be considerated.
130
131   That's all! Hope you make a good use of it!
132   It would be nice to receive feedback from others users. All comments are welcome!
133
134   Regards,
135
136   Carlos Reche
137
138*/
139
140
141
142
143$PowerGraphic = new powergraphic;
144
145$PowerGraphic->start();
146
147
148class powergraphic
149{
150        /**
151         * @var float $x coordenate
152         * @access public
153         */
154    var $x;
155    /**
156         * @var float $y y coordenate
157         * @access public
158         */
159    var $y;
160    /**
161         * @var float $z z coordenate
162         * @access public
163         */
164    var $z;
165    /**
166         * @var string $title
167         * @access public
168         */
169    var $title;
170   
171    /**
172     * @var float $axis_x
173     * @access public
174     */
175    var $axis_x;
176   
177    /**
178     * @var float $axis_y
179     * @access public
180     */
181    var $axis_y;
182   
183    /**
184     * @var $graphic_1
185     * @access public
186     */
187    var $graphic_1;
188   
189    /**
190     * @var $graphic_2
191     * @access public
192     */
193    var $graphic_2;
194   
195    /**
196     * @var string $type
197     * @access public
198     */
199    var $type;
200   
201    /**
202     * @var string $skin
203     * @access public
204     */
205    var $skin;
206   
207    /**
208     * @var $credits
209     * @access public
210     */
211    var $credits;
212   
213    /**
214     * @var $latin_notation
215     * @access public
216     */
217    var $latin_notation;
218
219        /**
220         * @var int $width
221         * @access public
222         */
223    var $width;
224   
225    /**
226         * @var float $height
227         * @access public
228         */
229    var $height;
230   
231    /**
232     * @var float $height_title
233     * @access public
234     */
235    var $height_title;
236   
237    /**
238     * @var float $alternate_x
239     * @access public
240     */
241    var $alternate_x;
242   
243        /**
244         * @var float $total_parameters
245     * @access public
246     */
247    var $total_parameters;
248   
249    /**
250     * @var float $sum_total
251     * @access public
252     */
253    var $sum_total;
254   
255    /**
256     * @var float $biggest_value
257     * @access public
258     */
259    var $biggest_value;
260   
261    /**
262     * @var float $biggest_parameter
263     * @access public
264     */
265    var $biggest_parameter;
266   
267    /**
268     * @var array $available_types
269     * @access public
270     */
271    var $available_types;
272
273        /**
274         * Constructor of class powergraphic
275         * @access public
276         * @return object
277         */
278    function powergraphic()
279    {
280        $this->x = $this->y = $this->z = array();
281
282        $this->biggest_x        = NULL;
283        $this->biggest_y        = NULL;
284       
285        $this->alternate_x      = false;
286        $this->graphic_2_exists = false;
287        $this->total_parameters = 0;
288        $this->sum_total        = 1;
289
290        $this->title     = (isset($_GET['title']))     ? $_GET['title']     : "";
291        $this->axis_x    = (isset($_GET['axis_x']))    ? $_GET['axis_x']    : "";
292        $this->axis_y    = (isset($_GET['axis_y']))    ? $_GET['axis_y']    : "";
293        $this->graphic_1 = (isset($_GET['graphic_1'])) ? $_GET['graphic_1'] : "";
294        $this->graphic_2 = (isset($_GET['graphic_2'])) ? $_GET['graphic_2'] : "";
295        $this->type      = (isset($_GET['type']))      ? $_GET['type']      : 1;
296        $this->skin      = (isset($_GET['skin']))      ? $_GET['skin']      : 1;
297        $this->credits        = ((isset($_GET['credits'])) && ($_GET['credits'] == 1))               ? true : false;
298        $this->latin_notation = ((isset($_GET['latin_notation'])) && ($_GET['latin_notation'] == 1)) ? true : false;
299
300        $this->legend_exists        = (ereg("(5|6)", $this->type)) ? true : false;
301        $this->biggest_graphic_name = (strlen($this->graphic_1) > strlen($this->graphic_2)) ? $this->graphic_1 : $this->graphic_2;
302        $this->height_title         = (!empty($this->title)) ? ($this->string_height(5) + 15) : 0;
303        $this->space_between_bars   = ($this->type == 1) ? 40 : 30;
304        $this->space_between_dots   = 40;
305        $this->higher_value         = 0;
306        $this->higher_value_str     = 0;
307
308        $this->width               = 0;
309        $this->height              = 0;
310        $this->graphic_area_width  = 0;
311        $this->graphic_area_height = 0;
312        $this->graphic_area_x1     = 30;
313        $this->graphic_area_y1     = 20 + $this->height_title;
314        $this->graphic_area_x2     = $this->graphic_area_x1 + $this->graphic_area_width;
315        $this->graphic_area_y2     = $this->graphic_area_y1 + $this->graphic_area_height;
316
317        $this->available_types = array(
318            1 => 'Vertical Bars',
319            2 => 'Horizontal Bars',
320            3 => 'Dots',
321            4 => 'Lines',
322            5 => 'Pie',
323            6 => 'Donut',
324        );
325        $this->available_skins = array(
326            1 => 'Office',
327            2 => 'Matrix',
328            3 => 'Spring',
329        );
330    }
331
332
333        /**
334         * Start the create of graphic
335         * @access public
336         * @return bool
337         */
338    function start()
339    {
340        if ( (!isset($_GET['x0'])) || (!isset($_GET['y0'])) )
341        {
342            if ($_SERVER['QUERY_STRING'] == 'showform')
343            {
344                $this->html();
345            }
346            return false;
347        }
348
349        // Defines array $temp
350        foreach ($_GET as $parameter => $value)
351        {
352            if (preg_match("/^x\d+$/i", $parameter))
353            {
354                if (strtolower($parameter{0}) == 'x')
355                {
356                    if (empty($value))
357                    {
358                        continue;
359                    }
360
361                    if (strlen($value) > strlen($this->biggest_x))
362                    {
363                        $this->biggest_x = $value;
364                    }
365
366                    $num        = substr($parameter, 1, (strlen($parameter)-1) );
367                    $temp[$num] = $value;
368
369                    if ((!empty($_GET['z'.$num])) && (ereg("(1|2|3|4)", $this->type)))
370                    {
371                        $this->graphic_2_exists = true;
372                    }
373                }
374            }
375        }
376
377        $i = 0;
378
379        // Defines arrays $this->x, $this->y and $this->z (if exists)
380        foreach ($temp as $index => $parameter)
381        {
382            $this->x[$i] = $parameter;
383            $this->y[$i] = 0;
384
385            if (!empty($_GET['y'.$index]))
386            {
387                $this->y[$i] = $_GET['y'.$index];
388
389                if ($_GET['y'.$index] > $this->biggest_y)
390                {
391                    $this->biggest_y = number_format(round($_GET['y'.$index], 1), 1, ".", "");
392                }
393            }
394
395            if ($this->graphic_2_exists)
396            {
397                $value       = (!empty($_GET['z'.$index])) ? $_GET['z'.$index] : 0;
398                $this->z[$i] = $value;
399
400                if ($value > $this->biggest_y)
401                {
402                    $this->biggest_y = number_format(round($value, 1), 1, ".", "");
403                }
404            }
405
406            unset($temp[$index]);
407            $i++;
408        }
409
410        if (($this->graphic_2_exists == true)  &&  ((!empty($this->graphic_1)) || (!empty($this->graphic_2))))
411        {
412            $this->legend_exists = true;
413        }
414
415
416        $this->total_parameters    = count($this->x);
417        $this->sum_total           = array_sum($this->y);
418        $this->space_between_bars += ($this->graphic_2_exists == true) ? 10 : 0;
419
420        $this->calculate_higher_value();
421        $this->calculate_width();
422        $this->calculate_height();
423
424        $this->create_graphic();
425    }
426
427
428        /**
429         * Create and draw a graphic
430         * @access public
431         * @return void
432         */
433    function create_graphic()
434    {
435        $this->img = imagecreatetruecolor($this->width, $this->height);
436
437        $this->load_color_palette();
438
439        // Fill background
440        imagefill($this->img, 0, 0, $this->color['background']);
441
442        // Draw title
443        if (!empty($this->title))
444        {
445            $center = ($this->width / 2) - ($this->string_width($this->title, 5) / 2);
446            imagestring($this->img, 5, $center, 10, $this->title, $this->color['title']);
447        }
448
449
450        // Draw axis and background lines for "vertical bars", "dots" and "lines"
451        if (ereg("^(1|3|4)$", $this->type))
452        {
453            if ($this->legend_exists == true)
454            {
455                $this->draw_legend();
456            }
457
458            $higher_value_y    = $this->graphic_area_y1 + (0.1 * $this->graphic_area_height);
459            $higher_value_size = 0.9 * $this->graphic_area_height;
460
461            $less  = 7 * strlen($this->higher_value_str);
462
463            imageline($this->img, $this->graphic_area_x1, $higher_value_y, $this->graphic_area_x2, $higher_value_y, $this->color['bg_lines']);
464            imagestring($this->img, 3, ($this->graphic_area_x1-$less-7), ($higher_value_y-7), $this->higher_value_str, $this->color['axis_values']);
465
466            for ($i = 1; $i < 10; $i++)
467            {
468                $dec_y = $i * ($higher_value_size / 10);
469                $x1 = $this->graphic_area_x1;
470                $y1 = $this->graphic_area_y2 - $dec_y;
471                $x2 = $this->graphic_area_x2;
472                $y2 = $this->graphic_area_y2 - $dec_y;
473
474                imageline($this->img, $x1, $y1, $x2, $y2, $this->color['bg_lines']);
475                if ($i % 2 == 0) {
476                    $value = $this->number_formated($this->higher_value * $i / 10);
477                    $less = 7 * strlen($value);
478                    imagestring($this->img, 3, ($x1-$less-7), ($y2-7), $value, $this->color['axis_values']);
479                }
480            }
481
482            // Axis X
483            imagestring($this->img, 3, $this->graphic_area_x2+10, $this->graphic_area_y2+3, $this->axis_x, $this->color['title']);
484            imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y2, $this->graphic_area_x2, $this->graphic_area_y2, $this->color['axis_line']);
485            // Axis Y
486            imagestring($this->img, 3, 20, $this->graphic_area_y1-20, $this->axis_y, $this->color['title']);
487            imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y1, $this->graphic_area_x1, $this->graphic_area_y2, $this->color['axis_line']);
488        }
489
490
491        // Draw axis and background lines for "horizontal bars"
492        else if ($this->type == 2)
493        {
494            if ($this->legend_exists == true)
495            {
496                $this->draw_legend();
497            }
498
499            $higher_value_x    = $this->graphic_area_x2 - (0.2 * $this->graphic_area_width);
500            $higher_value_size = 0.8 * $this->graphic_area_width;
501
502            imageline($this->img, ($this->graphic_area_x1+$higher_value_size), $this->graphic_area_y1, ($this->graphic_area_x1+$higher_value_size), $this->graphic_area_y2, $this->color['bg_lines']);
503            imagestring($this->img, 3, (($this->graphic_area_x1+$higher_value_size) - ($this->string_width($this->higher_value, 3)/2)), ($this->graphic_area_y2+2), $this->higher_value_str, $this->color['axis_values']);
504
505            for ($i = 1, $alt = 15; $i < 10; $i++)
506            {
507                $dec_x = number_format(round($i * ($higher_value_size  / 10), 1), 1, ".", "");
508
509                imageline($this->img, ($this->graphic_area_x1+$dec_x), $this->graphic_area_y1, ($this->graphic_area_x1+$dec_x), $this->graphic_area_y2, $this->color['bg_lines']);
510                if ($i % 2 == 0) {
511                    $alt   = (strlen($this->biggest_y) > 4 && $alt != 15) ? 15 : 2;
512                    $value = $this->number_formated($this->higher_value * $i / 10);
513                    imagestring($this->img, 3, (($this->graphic_area_x1+$dec_x) - ($this->string_width($this->higher_value, 3)/2)), ($this->graphic_area_y2+$alt), $value, $this->color['axis_values']);
514                }
515            }
516
517            // Axis X
518            imagestring($this->img, 3, ($this->graphic_area_x2+10), ($this->graphic_area_y2+3), $this->axis_y, $this->color['title']);
519            imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y2, $this->graphic_area_x2, $this->graphic_area_y2, $this->color['axis_line']);
520            // Axis Y
521            imagestring($this->img, 3, 20, ($this->graphic_area_y1-20), $this->axis_x, $this->color['title']);
522            imageline($this->img, $this->graphic_area_x1, $this->graphic_area_y1, $this->graphic_area_x1, $this->graphic_area_y2, $this->color['axis_line']);
523        }
524
525
526        // Draw legend box for "pie" or "donut"
527        else if (ereg("^(5|6)$", $this->type))
528        {
529            $this->draw_legend();
530        }
531
532
533
534        /**
535        * Draw graphic: VERTICAL BARS
536        */
537        if ($this->type == 1)
538        {
539            $num = 1;
540            $x   = $this->graphic_area_x1 + 20;
541
542            foreach ($this->x as $i => $parameter)
543            {
544                if (isset($this->z[$i])) {
545                    $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
546                    $x1   = $x + 10;
547                    $y1   = ($this->graphic_area_y2 - $size) + 1;
548                    $x2   = $x1 + 20;
549                    $y2   = $this->graphic_area_y2 - 1;
550                    imageline($this->img, ($x1+1), ($y1-1), $x2, ($y1-1), $this->color['bars_2_shadow']);
551                    imageline($this->img, ($x2+1), ($y1-1), ($x2+1), $y2, $this->color['bars_2_shadow']);
552                    imageline($this->img, ($x2+2), ($y1-1), ($x2+2), $y2, $this->color['bars_2_shadow']);
553                    imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars_2']);
554                }
555
556                $size = round($this->y[$i] * $higher_value_size / $this->higher_value);
557                $alt  = (($num % 2 == 0) && (strlen($this->biggest_x) > 5)) ? 15 : 2;
558                $x1   = $x;
559                $y1   = ($this->graphic_area_y2 - $size) + 1;
560                $x2   = $x1 + 20;
561                $y2   = $this->graphic_area_y2 - 1;
562                $x   += $this->space_between_bars;
563                $num++;
564
565                imageline($this->img, ($x1+1), ($y1-1), $x2, ($y1-1), $this->color['bars_shadow']);
566                imageline($this->img, ($x2+1), ($y1-1), ($x2+1), $y2, $this->color['bars_shadow']);
567                imageline($this->img, ($x2+2), ($y1-1), ($x2+2), $y2, $this->color['bars_shadow']);
568                imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars']);
569                imagestring($this->img, 3, ((($x1+$x2)/2) - (strlen($parameter)*7/2)), ($y2+$alt+2), $parameter, $this->color['axis_values']);
570            }
571        }
572
573
574        /**
575        * Draw graphic: HORIZONTAL BARS
576        */
577        else if ($this->type == 2)
578        {
579            $y = 10;
580
581            foreach ($this->x as $i => $parameter)
582            {
583                if (isset($this->z[$i])) {
584                    $size = round($this->z[$i] * $higher_value_size / $this->higher_value);
585                    $x1   = $this->graphic_area_x1 + 1;
586                    $y1   = $this->graphic_area_y1 + $y + 10;
587                    $x2   = $x1 + $size;
588                    $y2   = $y1 + 15;
589                    imageline($this->img, ($x1), ($y2+1), $x2, ($y2+1), $this->color['bars_2_shadow']);
590                    imageline($this->img, ($x1), ($y2+2), $x2, ($y2+2), $this->color['bars_2_shadow']);
591                    imageline($this->img, ($x2+1), ($y1+1), ($x2+1), ($y2+2), $this->color['bars_2_shadow']);
592                    imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars_2']);
593                    imagestring($this->img, 3, ($x2+7), ($y1+7), $this->number_formated($this->z[$i], 2), $this->color['bars_2_shadow']);
594                }
595
596                $size = round(($this->y[$i] / $this->higher_value) * $higher_value_size);
597                $x1   = $this->graphic_area_x1 + 1;
598                $y1   = $this->graphic_area_y1 + $y;
599                $x2   = $x1 + $size;
600                $y2   = $y1 + 15;
601                $y   += $this->space_between_bars;
602
603                imageline($this->img, ($x1), ($y2+1), $x2, ($y2+1), $this->color['bars_shadow']);
604                imageline($this->img, ($x1), ($y2+2), $x2, ($y2+2), $this->color['bars_shadow']);
605                imageline($this->img, ($x2+1), ($y1+1), ($x2+1), ($y2+2), $this->color['bars_shadow']);
606                imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bars']);
607                imagestring($this->img, 3, ($x2+7), ($y1+2), $this->number_formated($this->y[$i], 2), $this->color['bars_shadow']);
608
609                imagestring($this->img, 3, ($x1 - ((strlen($parameter)*7)+7)), ($y1+2), $parameter, $this->color['axis_values']);
610            }
611        }
612
613
614        /**
615        * Draw graphic: DOTS or LINE
616        */
617        else if (ereg("^(3|4)$", $this->type))
618        {
619
620            $x[0] = $this->graphic_area_x1+1;
621
622            foreach ($this->x as $i => $parameter)
623            {
624                if ($this->graphic_2_exists == true) {
625                    $size  = round($this->z[$i] * $higher_value_size / $this->higher_value);
626                    $z[$i] = $this->graphic_area_y2 - $size;
627                }
628
629                $alt   = (($i % 2 == 0) && (strlen($this->biggest_x) > 5)) ? 15 : 2;
630                $size  = round($this->y[$i] * $higher_value_size / $this->higher_value);
631                $y[$i] = $this->graphic_area_y2 - $size;
632
633                if ($i != 0) {
634                    imageline($this->img, $x[$i], ($this->graphic_area_y1+10), $x[$i], ($this->graphic_area_y2-1), $this->color['bg_lines']);
635                }
636                imagestring($this->img, 3, ($x[$i] - (strlen($parameter)*7/2 )), ($this->graphic_area_y2+$alt+2), $parameter, $this->color['axis_values']);
637
638                $x[$i+1] = $x[$i] + 40;
639            }
640
641            foreach ($x as $i => $value_x)
642            {
643                if ($this->graphic_2_exists == true)
644                {
645                    if (isset($z[$i+1])) {
646                        // Draw lines
647                        if ($this->type == 4)
648                        {
649                            imageline($this->img, $x[$i], $z[$i], $x[$i+1], $z[$i+1], $this->color['line_2']);
650                            imageline($this->img, $x[$i], ($z[$i]+1), $x[$i+1], ($z[$i+1]+1), $this->color['line_2']);
651                        }
652                        imagefilledrectangle($this->img, $x[$i]-1, $z[$i]-1, $x[$i]+2, $z[$i]+2, $this->color['line_2']);
653                    }
654                    else { // Draw last dot
655                        imagefilledrectangle($this->img, $x[$i-1]-1, $z[$i-1]-1, $x[$i-1]+2, $z[$i-1]+2, $this->color['line_2']);
656                    }
657                }
658
659                if (count($y) > 1)
660                {
661                    if (isset($y[$i+1])) {
662                        // Draw lines
663                        if ($this->type == 4)
664                        {
665                            imageline($this->img, $x[$i], $y[$i], $x[$i+1], $y[$i+1], $this->color['line']);
666                            imageline($this->img, $x[$i], ($y[$i]+1), $x[$i+1], ($y[$i+1]+1), $this->color['line']);
667                        }
668                        imagefilledrectangle($this->img, $x[$i]-1, $y[$i]-1, $x[$i]+2, $y[$i]+2, $this->color['line']);
669                    }
670                    else { // Draw last dot
671                        imagefilledrectangle($this->img, $x[$i-1]-1, $y[$i-1]-1, $x[$i-1]+2, $y[$i-1]+2, $this->color['line']);
672                    }
673                }
674
675            }
676        }
677
678
679        /**
680        * Draw graphic: PIE or DONUT
681        */
682        else if (ereg("^(5|6)$", $this->type))
683        {
684            $center_x = ($this->graphic_area_x1 + $this->graphic_area_x2) / 2;
685            $center_y = ($this->graphic_area_y1 + $this->graphic_area_y2) / 2;
686            $width    = $this->graphic_area_width;
687            $height   = $this->graphic_area_height;
688            $start    = 0;
689            $sizes    = array();
690
691            foreach ($this->x as $i => $parameter)
692            {
693                $size    = $this->y[$i] * 360 / $this->sum_total;
694                $sizes[] = $size;
695                $start  += $size;
696            }
697            $start = 270;
698
699            // Draw PIE
700            if ($this->type == 5)
701            {
702                // Draw shadow
703                foreach ($sizes as $i => $size)
704                {
705                    $num_color = $i%7 + 1;
706                    $color = 'arc_' . $num_color . '_shadow';
707
708                    for ($i = 10; $i >= 0; $i -= 1)
709                    {
710                        imagearc($this->img, $center_x, ($center_y+$i), $width, $height, $start, ($start+$size), $this->color[$color]);
711                    }
712                    $start += $size;
713                }
714
715                $start = 270;
716
717                // Draw pieces
718                foreach ($sizes as $i => $size)
719                {
720                    $num_color = $i%7 + 1;
721                    $color = 'arc_' . $num_color;
722
723                    imagefilledarc($this->img, $center_x, $center_y, ($width+2), ($height+2), $start, ($start+$size), $this->color[$color], IMG_ARC_EDGED);
724                    $start += $size;
725                }
726            }
727
728            // Draw DONUT
729            else if ($this->type == 6)
730            {
731                foreach ($sizes as $i => $size)
732                {
733                    $num_color = $i%7 + 1;
734                    $color        = 'arc_' . $num_color;
735                    $color_shadow = 'arc_' . $num_color . '_shadow';
736                    imagefilledarc($this->img, $center_x, $center_y, $width, $height, $start, ($start+$size), $this->color[$color], IMG_ARC_PIE);
737                    $start += $size;
738                }
739                imagefilledarc($this->img, $center_x, $center_y, 100, 100, 0, 360, $this->color['background'], IMG_ARC_PIE);
740                imagearc($this->img, $center_x, $center_y, 100, 100, 0, 360, $this->color['bg_legend']);
741                imagearc($this->img, $center_x, $center_y, ($width+1), ($height+1), 0, 360, $this->color['bg_legend']);
742            }
743        }
744
745
746        if ($this->credits == true) {
747            $this->draw_credits();
748        }
749
750
751        header('Content-type: image/png');
752        imagepng($this->img);
753        imagedestroy($this->img);
754        exit;
755    }
756
757
758
759        /**
760         * Calculate width of graphic elements
761         * @access public
762         * @return void
763         */
764    function calculate_width()
765    {
766        switch ($this->type)
767        {
768            // Vertical bars
769            case 1:
770                $this->legend_box_width   = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, 3) + 25) : 0;
771                $this->graphic_area_width = ($this->space_between_bars * $this->total_parameters) + 30;
772                $this->graphic_area_x1   += $this->string_width(($this->higher_value_str), 3);
773                $this->width += $this->graphic_area_x1 + 20;
774                $this->width += ($this->legend_exists == true) ? 50 : ((7 * strlen($this->axis_x)) + 10);
775                break;
776
777            // Horizontal bars
778            case 2:
779                $this->legend_box_width   = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, 3) + 25) : 0;
780                $this->graphic_area_width = ($this->string_width($this->higher_value_str, 3) > 50) ? (5 * ($this->string_width($this->higher_value_str, 3)) * 0.85) : 200;
781                $this->graphic_area_x1 += 7 * strlen($this->biggest_x);
782                $this->width += ($this->legend_exists == true) ? 60 : ((7 * strlen($this->axis_y)) + 30);
783                $this->width += $this->graphic_area_x1;
784                break;
785
786            // Dots
787            case 3:
788                $this->legend_box_width   = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, 3) + 25) : 0;
789                $this->graphic_area_width = ($this->space_between_dots * $this->total_parameters) - 10;
790                $this->graphic_area_x1   += $this->string_width(($this->higher_value_str), 3);
791                $this->width += $this->graphic_area_x1 + 20;
792                $this->width += ($this->legend_exists == true) ? 40 : ((7 * strlen($this->axis_x)) + 10);
793                break;
794
795            // Lines
796            case 4:
797                $this->legend_box_width   = ($this->legend_exists == true) ? ($this->string_width($this->biggest_graphic_name, 3) + 25) : 0;
798                $this->graphic_area_width = ($this->space_between_dots * $this->total_parameters) - 10;
799                $this->graphic_area_x1   += $this->string_width(($this->higher_value_str), 3);
800                $this->width += $this->graphic_area_x1 + 20;
801                $this->width += ($this->legend_exists == true) ? 40 : ((7 * strlen($this->axis_x)) + 10);
802                break;
803
804            // Pie
805            case 5:
806                $this->legend_box_width   = $this->string_width($this->biggest_x, 3) + 85;
807                $this->graphic_area_width = 200;
808                $this->width += 90;
809                break;
810
811            // Donut
812            case 6:
813                $this->legend_box_width   = $this->string_width($this->biggest_x, 3) + 85;
814                $this->graphic_area_width = 180;
815                $this->width += 90;
816                break;
817        }
818
819        $this->width += $this->graphic_area_width;
820        $this->width += $this->legend_box_width;
821
822
823        $this->graphic_area_x2 = $this->graphic_area_x1 + $this->graphic_area_width;
824        $this->legend_box_x1   = $this->graphic_area_x2 + 40;
825        $this->legend_box_x2   = $this->legend_box_x1 + $this->legend_box_width;
826    }
827
828
829        /**
830         * Calculate height
831         * @access public
832         * @return void
833         */
834    function calculate_height()
835    {
836        switch ($this->type)
837        {
838            // Vertical bars
839            case 1:
840                $this->legend_box_height   = ($this->graphic_2_exists == true) ? 40 : 0;
841                $this->graphic_area_height = 150;
842                $this->height += 65;
843                break;
844
845            // Horizontal bars
846            case 2:
847                $this->legend_box_height   = ($this->graphic_2_exists == true) ? 40 : 0;
848                $this->graphic_area_height = ($this->space_between_bars * $this->total_parameters) + 10;
849                $this->height += 65;
850                break;
851
852            // Dots
853            case 3:
854                $this->legend_box_height   = ($this->graphic_2_exists == true) ? 40 : 0;
855                $this->graphic_area_height = 150;
856                $this->height += 65;
857                break;
858
859            // Lines
860            case 4:
861                $this->legend_box_height   = ($this->graphic_2_exists == true) ? 40 : 0;
862                $this->graphic_area_height = 150;
863                $this->height += 65;
864                break;
865
866            // Pie
867            case 5:
868                $this->legend_box_height   = (!empty($this->axis_x)) ? 30 : 5;
869                $this->legend_box_height  += (14 * $this->total_parameters);
870                $this->graphic_area_height = 150;
871                $this->height += 50;
872                break;
873
874            // Donut
875            case 6:
876                $this->legend_box_height   = (!empty($this->axis_x)) ? 30 : 5;
877                $this->legend_box_height  += (14 * $this->total_parameters);
878                $this->graphic_area_height = 180;
879                $this->height += 50;
880                break;
881        }
882
883        $this->height += $this->height_title;
884        $this->height += ($this->legend_box_height > $this->graphic_area_height) ? ($this->legend_box_height - $this->graphic_area_height) : 0;
885        $this->height += $this->graphic_area_height;
886
887        $this->graphic_area_y2 = $this->graphic_area_y1 + $this->graphic_area_height;
888        $this->legend_box_y1   = $this->graphic_area_y1 + 10;
889        $this->legend_box_y2   = $this->legend_box_y1 + $this->legend_box_height;
890    }
891
892        /**
893         * Draw the graphic legend
894         * @access public
895         * @return void
896         */
897    function draw_legend()
898    {
899        $x1 = $this->legend_box_x1;
900        $y1 = $this->legend_box_y1;
901        $x2 = $this->legend_box_x2;
902        $y2 = $this->legend_box_y2;
903
904        imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $this->color['bg_legend']);
905
906        $x = $x1 + 5;
907        $y = $y1 + 5;
908
909
910        // Draw legend values for VERTICAL BARS, HORIZONTAL BARS, DOTS and LINES
911        if (ereg("^(1|2|3|4)$", $this->type))
912        {
913            $color_1 = (ereg("^(1|2)$", $this->type)) ? $this->color['bars']   : $this->color['line'];
914            $color_2 = (ereg("^(1|2)$", $this->type)) ? $this->color['bars_2'] : $this->color['line_2'];
915
916            imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $color_1);
917            imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
918            imagestring($this->img, 3, ($x+15), ($y-2), $this->graphic_1, $this->color['axis_values']);
919            $y += 20;
920            imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $color_2);
921            imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
922            imagestring($this->img, 3, ($x+15), ($y-2), $this->graphic_2, $this->color['axis_values']);
923        }
924
925        // Draw legend values for PIE or DONUT
926        else if (ereg("^(5|6)$", $this->type))
927        {
928            if (!empty($this->axis_x))
929            {
930                imagestring($this->img, 3, ((($x1+$x2)/2) - (strlen($this->axis_x)*7/2)), $y, $this->axis_x, $this->color['title']);
931                $y += 25;
932            }
933
934            $num = 0;
935
936            foreach ($this->x as $i => $parameter)
937            {
938                $num = $i%7 + 1;
939                $color = 'arc_' . $num;
940
941                $percent = number_format(round(($this->y[$i] * 100 / $this->sum_total), 2), 2, ".", "") . ' %';
942                $less    = (strlen($percent) * 7);
943
944                if ($num != 1) {
945                    imageline($this->img, ($x1+15), ($y-2), ($x2-5), ($y-2), $this->color['bg_lines']);
946                }
947                imagefilledrectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color[$color]);
948                imagerectangle($this->img, $x, $y, ($x+10), ($y+10), $this->color['title']);
949                imagestring($this->img, 3, ($x+15), ($y-2), $parameter, $this->color['axis_values']);
950                imagestring($this->img, 2, ($x2-$less), ($y-2), $percent, $this->color['axis_values']);
951                $y += 14;
952                $num++;
953            }
954        }
955    }
956
957        /**
958         * Calculate the string width
959         * @access public
960         * @return int string width
961         */
962    function string_width($string, $size) {
963        $single_width = $size + 4;
964        return $single_width * strlen($string);
965    }
966   
967        /**
968         * Calculate the string height
969         * @access public
970         * @return int string height
971         */
972    function string_height($size) {
973        if ($size <= 1) {
974            $height = 8;
975        } else if ($size <= 3) {
976            $height = 12;
977        } else if ($size >= 4) {
978            $height = 14;
979        }
980        return $height;
981    }
982
983        /**
984         * Calculate the higher value
985         * @access public
986         * @return void
987         */
988    function calculate_higher_value() {
989        $digits   = strlen(round($this->biggest_y));
990        $interval = pow(10, ($digits-1));
991        $this->higher_value     = round(($this->biggest_y - ($this->biggest_y % $interval) + $interval), 1);
992        $this->higher_value_str = $this->number_formated($this->higher_value);
993    }
994
995        /**
996         * Number formated (Float to string representation)
997         * @param float $number
998         * @param int $dec_size
999         * @access public
1000         * @return string
1001         */
1002    function number_formated($number, $dec_size = 1)
1003    {
1004        if ($this->latin_notation == true) {
1005            return number_format(round($number, $dec_size), $dec_size, ",", ".");
1006        }
1007        return number_format(round($number, $dec_size), $dec_size, ".", ",");
1008    }
1009       
1010        /**
1011         * Number float
1012         * @param string $number
1013         * @return float
1014         */
1015    function number_float($number)
1016    {
1017        if ($this->latin_notation == true) {
1018            $number = str_replace(".", "", $number);
1019            return (float)str_replace(",", ".", $number);
1020        }
1021        return (float)str_replace(",", "", $number);
1022    }
1023
1024        /**
1025         * Draw the credits string
1026         * @param int $number
1027         * @return void
1028         * @access public
1029         */
1030    function draw_credits() {
1031        imagestring($this->img, 1, ($this->width-120), ($this->height-10), "Powered by Carlos Reche", $this->color['title']);
1032    }
1033
1034        /**
1035         * Load color palette
1036         * @return void
1037         * @access public
1038         */
1039    function load_color_palette()
1040    {
1041        switch ($this->skin)
1042        {
1043            // Office
1044            case 1:
1045                $this->color['title']       = imagecolorallocate($this->img,   0,   0, 100);
1046                $this->color['background']  = imagecolorallocate($this->img, 220, 220, 220);
1047                $this->color['axis_values'] = imagecolorallocate($this->img,  50,  50,  50);
1048                $this->color['axis_line']   = imagecolorallocate($this->img, 100, 100, 100);
1049                $this->color['bg_lines']    = imagecolorallocate($this->img, 240, 240, 240);
1050                $this->color['bg_legend']   = imagecolorallocate($this->img, 205, 205, 205);
1051
1052                if (ereg("^(1|2)$", $this->type))
1053                {
1054                    $this->color['bars']          = imagecolorallocate($this->img, 100, 150, 200);
1055                    $this->color['bars_shadow']   = imagecolorallocate($this->img,  50, 100, 150);
1056                    $this->color['bars_2']        = imagecolorallocate($this->img, 200, 250, 150);
1057                    $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 120, 170,  70);
1058                }
1059                else if (ereg("^(3|4)$", $this->type))
1060                {
1061                    $this->color['line']   = imagecolorallocate($this->img, 100, 150, 200);
1062                    $this->color['line_2'] = imagecolorallocate($this->img, 230, 100, 100);
1063                }
1064                else if (ereg("^(5|6)$", $this->type))
1065                {
1066                    $this->color['arc_1']        = imagecolorallocate($this->img, 100, 150, 200);
1067                    $this->color['arc_2']        = imagecolorallocate($this->img, 200, 250, 150);
1068                    $this->color['arc_3']        = imagecolorallocate($this->img, 250, 200, 150);
1069                    $this->color['arc_4']        = imagecolorallocate($this->img, 250, 150, 150);
1070                    $this->color['arc_5']        = imagecolorallocate($this->img, 250, 250, 150);
1071                    $this->color['arc_6']        = imagecolorallocate($this->img, 230, 180, 250);
1072                    $this->color['arc_7']        = imagecolorallocate($this->img, 200, 200, 150);
1073                    $this->color['arc_1_shadow'] = imagecolorallocate($this->img,  60, 110, 170);
1074                    $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 120, 170,  70);
1075                    $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 180, 120,  70);
1076                    $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 170, 100, 100);
1077                    $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 180, 180, 110);
1078                    $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 160, 110, 190);
1079                    $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 140, 140, 100);
1080                }
1081                break;
1082
1083            // Matrix
1084            case 2:
1085                $this->color['title']       = imagecolorallocate($this->img, 255, 255, 255);
1086                $this->color['background']  = imagecolorallocate($this->img,   0,   0,   0);
1087                $this->color['axis_values'] = imagecolorallocate($this->img,   0, 230,   0);
1088                $this->color['axis_line']   = imagecolorallocate($this->img,   0, 200,   0);
1089                $this->color['bg_lines']    = imagecolorallocate($this->img, 100, 100, 100);
1090                $this->color['bg_legend']   = imagecolorallocate($this->img,  70,  70,  70);
1091
1092                if (ereg("^(1|2)$", $this->type))
1093                {
1094                    $this->color['bars']          = imagecolorallocate($this->img,  50, 200,  50);
1095                    $this->color['bars_shadow']   = imagecolorallocate($this->img,   0, 150,   0);
1096                    $this->color['bars_2']        = imagecolorallocate($this->img, 255, 255, 255);
1097                    $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 220, 220, 220);
1098                }
1099                else if (ereg("^(3|4)$", $this->type))
1100                {
1101                    $this->color['line']   = imagecolorallocate($this->img, 220, 220, 220);
1102                    $this->color['line_2'] = imagecolorallocate($this->img,   0, 180,   0);
1103                }
1104                else if (ereg("^(5|6)$", $this->type))
1105                {
1106                    $this->color['arc_1']        = imagecolorallocate($this->img, 255, 255, 255);
1107                    $this->color['arc_2']        = imagecolorallocate($this->img, 200, 220, 200);
1108                    $this->color['arc_3']        = imagecolorallocate($this->img, 160, 200, 160);
1109                    $this->color['arc_4']        = imagecolorallocate($this->img, 135, 180, 135);
1110                    $this->color['arc_5']        = imagecolorallocate($this->img, 115, 160, 115);
1111                    $this->color['arc_6']        = imagecolorallocate($this->img, 100, 140, 100);
1112                    $this->color['arc_7']        = imagecolorallocate($this->img,  90, 120,  90);
1113                    $this->color['arc_1_shadow'] = imagecolorallocate($this->img, 200, 220, 200);
1114                    $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 160, 200, 160);
1115                    $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 135, 180, 135);
1116                    $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 115, 160, 115);
1117                    $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 100, 140, 100);
1118                    $this->color['arc_6_shadow'] = imagecolorallocate($this->img,  90, 120,  90);
1119                    $this->color['arc_7_shadow'] = imagecolorallocate($this->img,  85, 100,  85);
1120                }
1121                break;
1122
1123
1124            // Spring
1125            case 3:
1126                $this->color['title']       = imagecolorallocate($this->img, 250,  50,  50);
1127                $this->color['background']  = imagecolorallocate($this->img, 250, 250, 220);
1128                $this->color['axis_values'] = imagecolorallocate($this->img,  50, 150,  50);
1129                $this->color['axis_line']   = imagecolorallocate($this->img,  50, 100,  50);
1130                $this->color['bg_lines']    = imagecolorallocate($this->img, 200, 224, 180);
1131                $this->color['bg_legend']   = imagecolorallocate($this->img, 230, 230, 200);
1132
1133                if (ereg("^(1|2)$", $this->type))
1134                {
1135                    $this->color['bars']          = imagecolorallocate($this->img, 255, 170,  80);
1136                    $this->color['bars_shadow']   = imagecolorallocate($this->img, 200, 120,  30);
1137                    $this->color['bars_2']        = imagecolorallocate($this->img, 250, 230,  80);
1138                    $this->color['bars_2_shadow'] = imagecolorallocate($this->img, 180, 150,   0);
1139                }
1140                else if (ereg("^(3|4)$", $this->type))
1141                {
1142                    $this->color['line']   = imagecolorallocate($this->img, 230, 100,   0);
1143                    $this->color['line_2'] = imagecolorallocate($this->img, 220, 200,  50);
1144                }
1145                else if (ereg("^(5|6)$", $this->type))
1146                {
1147                    $this->color['arc_1']        = imagecolorallocate($this->img, 100, 150, 200);
1148                    $this->color['arc_2']        = imagecolorallocate($this->img, 200, 250, 150);
1149                    $this->color['arc_3']        = imagecolorallocate($this->img, 250, 200, 150);
1150                    $this->color['arc_4']        = imagecolorallocate($this->img, 250, 150, 150);
1151                    $this->color['arc_5']        = imagecolorallocate($this->img, 250, 250, 150);
1152                    $this->color['arc_6']        = imagecolorallocate($this->img, 230, 180, 250);
1153                    $this->color['arc_7']        = imagecolorallocate($this->img, 200, 200, 150);
1154                    $this->color['arc_1_shadow'] = imagecolorallocate($this->img,  60, 110, 170);
1155                    $this->color['arc_2_shadow'] = imagecolorallocate($this->img, 120, 170,  70);
1156                    $this->color['arc_3_shadow'] = imagecolorallocate($this->img, 180, 120,  70);
1157                    $this->color['arc_4_shadow'] = imagecolorallocate($this->img, 170, 100, 100);
1158                    $this->color['arc_5_shadow'] = imagecolorallocate($this->img, 180, 180, 110);
1159                    $this->color['arc_6_shadow'] = imagecolorallocate($this->img, 160, 110, 190);
1160                    $this->color['arc_7_shadow'] = imagecolorallocate($this->img, 140, 140, 100);
1161                }
1162                break;
1163
1164        }
1165
1166    }
1167
1168        /**
1169         * Echo html code for powergraphic funcionalitty
1170         * @access public
1171         * @return void
1172         */
1173    function html()
1174    {
1175        echo
1176'<html>
1177<head>
1178<title>Power Graphic - by Carlos Reche</title>
1179<style type="text/css">
1180<!--
1181
1182body {
1183    margin-top: 50px;
1184    margin-bottom: 30px;
1185    margin-left: 70px;
1186    margin-right: 70px;
1187    background-color: #ffffff;
1188}
1189body, table {
1190    font-size: 13px;
1191    font-family: verdana;
1192    color: #666666;
1193}
1194input, select {
1195    font-size: 11px;
1196    font-family: verdana;
1197    color: #333333;
1198    border: 1px solid #aaaaaa;
1199}
1200
1201a:link    { color: #666666; font-weight: bold; text-decoration: none; }
1202a:visited { color: #666666; font-weight: bold; text-decoration: none; }
1203a:hover   { color: #cc0000; text-decoration: none; }
1204a:active  { color: #666666; text-decoration: none; }
1205
1206-->
1207</style>
1208<script type="text/javascript">
1209<!--
1210
1211var i = 4;
1212
1213function add_parameter() {
1214    i++;
1215    space = ((i+1) < 10) ? "8px" : "0px";
1216    display_status = (document.form_data.graphic_2_values.checked == true) ? "" : "none";
1217    new_line  = "<div style=\"margin-left: " + space + "\"> " + (i+1) + ". <input type=\"text\" name=\"x" + i + "\" id=\"x" + i + "\" size=\"20\" /> ";
1218    new_line += " <input type=\"text\" name=\"y" + i + "\" id=\"y" + i + "\" size=\"10\" onkeypress=\"return numbers();\" /> ";
1219    new_line += " <input type=\"text\" name=\"z" + i + "\" id=\"z" + i + "\" size=\"10\" onkeypress=\"return numbers();\" style=\"display: " + display_status + ";\" /> </div>";
1220    document.getElementById("add_parameter").innerHTML += new_line;
1221}
1222
1223function show_graphic_2_values() {
1224    var display_status = (document.form_data.graphic_2_values.checked == true) ? "" : "none";
1225    document.getElementById("value_2").style.display = display_status;
1226    for (var x = 0; x <= i; x++) {
1227        document.getElementById("z" + x).style.display = display_status;
1228    }
1229}
1230
1231function numbers() {
1232    key = event.keyCode;
1233    if ((key >= 48 && key <= 57) || key == 46 || key == 13) { return true; } else { return false; }
1234}
1235
1236//-->
1237</script>
1238</head>
1239<body>
1240
1241<div style="position: absolute; right: 0px; top: -10px; right: 20px; z-index: -1; text-align: right;">
1242  <div style="font-size: 60px;">
1243    <span style="letter-spacing: -5px; font-family: arial black; color: #ffbbbb;">Power</span><span style="color: #bbbbff;">Graphics</span>
1244  </div>
1245  <div style="font-style: italic; font-size: 15px;">Powered by Carlos Reche</div>
1246</div>
1247
1248
1249<form action="' . $_SERVER['SCRIPT_NAME'] . '" method="get" name="form_data" id="form_data"> <br />
1250  <div style="margin-bottom: 10px;">
1251    Title: <input type="text" name="title" id="title" size="30" style="margin: 0px 0px 0px 11px;" />
1252  </div>
1253  Axis X: <input type="text" name="axis_x" id="axis_x" size="30" /> <br />
1254  Axis Y: <input type="text" name="axis_y" id="axis_y" size="30" /> <br />
1255
1256  <div style="margin: 10px 0px 10px 0px;">
1257    Graphic 1: <input type="text" name="graphic_1" id="graphic_1" style="width: 172px;" /> <br />
1258    Graphic 2: <input type="text" name="graphic_2" id="graphic_2" style="width: 172px;" /> <br />
1259  </div>
1260
1261  Type: <select name="type" id="type" style="margin: 5px 0px 0px 7px;">';
1262        foreach ($this->available_types as $code => $type) {
1263            echo '    <option value="' . $code . '"> ' . $type . ' </option>';
1264        }
1265        echo
1266'  </select> <br />
1267Color: <select name="skin" id="skin" style="margin: 5px 0px 0px 7px;">';
1268        foreach ($this->available_skins as $code => $color) {
1269            echo '    <option value="' . $code . '"> ' . $color . ' </option>';
1270        }
1271        echo
1272'  </select>
1273
1274
1275  <div style="margin-top: 20px;" id="parameters">
1276    <div style="margin-bottom: 20px;">
1277      <input type="checkbox" name="graphic_2_values" id="graphic_2_values" value="1" onclick="javascript: show_graphic_2_values();" style="border-width: 0px;" /> Show values for Graphic 2
1278    </div>
1279
1280    <span style="margin-left: 5px; font-size: 15px; font-family: arial;"><a href="javascript: add_parameter();">+</a></span>
1281    <span style="margin-left: 40px;">Parameter</span>
1282    <span style="margin-left: 50px;">Value 1</span>  <span id="value_2" style="display: none; margin-left: 25px;">Value 2</span>';
1283        for ($i = 0; $i <= 4; $i++) {
1284            echo '<div style="margin-left: 8px;"> '.($i+1).'. <input type="text" name="x'.$i.'" id="x'.$i.'" size="20" /> ';
1285            echo ' <input type="text" name="y'.$i.'" id="y'.$i.'" size="10" onkeypress="return numbers();" /> ';
1286            echo ' <input type="text" name="z'.$i.'" id="z'.$i.'" size="10" onkeypress="return numbers();" style="display: none;" /> </div>';
1287        }
1288echo
1289'    <div id="add_parameter"></div>
1290    <span style="margin-left: 5px; font-size: 15px; font-family: arial;"><a href="javascript: add_parameter();">+</a></span>
1291  </div>
1292
1293  <input type="checkbox" name="credits" id="credits" value="1" checked="checked" style="border-width: 0px;" /> Show credits
1294
1295  <input type="submit" value="Create" style="cursor: pointer; margin: 10px 0px 0px 60px;" />
1296</form>
1297
1298
1299</body>
1300</html>';
1301    }
1302
1303        /**
1304         * Reset all graphics  value
1305         * @access public
1306         * @return void
1307         */
1308    function reset_values() {
1309        $this->title     = NULL;
1310        $this->axis_x    = NULL;
1311        $this->axis_y    = NULL;
1312        $this->type      = NULL;
1313        $this->skin      = NULL;
1314        $this->graphic_1 = NULL;
1315        $this->graphic_2 = NULL;
1316        $this->credits   = NULL;
1317        $this->x = $this->y = $this->z = array();
1318    }
1319   
1320        /**
1321         * Create query string array
1322         * @param array $array
1323         * @return string
1324         * @access public
1325         */
1326    function create_query_string_array($array) {
1327        if (!is_array($array)) {
1328            return false;
1329        }
1330        $query_string = array();
1331        foreach ($array as $parameter => $value) {
1332            $query_string[] = urlencode($parameter) . '=' . urlencode($value);
1333        }
1334        return implode("&", $query_string);
1335    }
1336       
1337        /**
1338         * Create query string
1339         * @return string query string
1340         * @access public
1341         */
1342    function create_query_string() {
1343        $graphic['title']     = $this->title;
1344        $graphic['axis_x']    = $this->axis_x;
1345        $graphic['axis_y']    = $this->axis_y;
1346        $graphic['type']      = $this->type;
1347        $graphic['skin']      = $this->skin;
1348        $graphic['graphic_1'] = $this->graphic_1;
1349        $graphic['graphic_2'] = $this->graphic_2;
1350        $graphic['credits']   = $this->credits;
1351
1352        foreach ($this->x as $i => $x)
1353        {
1354            $graphic['x'.$i] = $x;
1355            if (isset($this->y[$i])) { $graphic['y'.$i] = $this->y[$i]; }
1356            if (isset($this->z[$i])) { $graphic['z'.$i] = $this->z[$i]; }
1357        }
1358        return $this->create_query_string_array($graphic);
1359    }
1360}
1361
1362
1363?>
Note: See TracBrowser for help on using the repository browser.