phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.graphics.inc.php, 1.9 class.gdimag


From: ceb
Subject: [Phpgroupware-cvs] phpgwapi/inc class.graphics.inc.php, 1.9 class.gdimage.inc.php, 1.10 class.gdbutton.inc.php, 1.4 class.gdgraph.inc.php, 1.19
Date: Thu, 24 Feb 2005 15:58:04 -0000

Update of phpgwapi/inc

Removed Files:
     Branch: MAIN
            class.graphics.inc.php
Added Files:
     Branch: MAIN
            class.gdimage.inc.php lines: +0 -0
            class.gdbutton.inc.php lines: +0 -0
            class.gdgraph.inc.php lines: +0 -0

Log Message:
added classes

====================================================
Index: class.gdimage.inc.php
<?php
        /*******************************************************************\
        * phpGroupWare - GD Image                                           *
        * http://www.phpgroupware.org                                       *
        *                                                                   *
        * Written by by Bettina Gille address@hidden                *
        *                                                                   *
        * Creates images using GD graphics library                          *
        * Copyright (C) 2003,2004 Free Software Foundation, Inc.            *
        * ----------------------------------------------------------------- *
        * This class based on htmlGD.php3                                   *
        * Double Choco Latte - Source Configuration Management System       *
        * Copyright (C) 1999  Michael L. Dean & Tim R. Norman               *
        * ----------------------------------------------------------------- *
        * This library is part of the phpGroupWare API                      *
        * ----------------------------------------------------------------- *
        * This library is free software; you can redistribute it and/or     *
        * modify it under the terms of the GNU General Public License as    *
        * published by the Free Software Foundation; either version 2 of    *
        * the License, or (at your option) any later version.               *
        *                                                                   *
        * This program is distributed in the hope that it will be useful,   *
        * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  *
        * General Public License for more details.                          *
        *                                                                   *
        * You should have received a copy of the GNU General Public License *
        * along with this program; if not, write to the Free Software       *
        * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.gdimage.inc.php,v 1.10 2005/01/13 11:36:43 ceb Exp $ */

        class gdimage
        {
                var $filename;
                var $type;
                var $cur_x;
                var $cur_y;
                var $width;
                var $height;
                var $hImage;
                var $colormap;
                var $hColor;
                var $font;

                function gdimage()
                {
                        $this->gd = $this->check_gd();

                        if ($this->gd == 0)
                        {
                                echo 'Your PHP installation does not seem to 
have the required GD library.
                                                Please see the PHP 
documentation on how to install and enable the GD library.';
                                exit;
                        }

                        $this->cur_x = 0;
                        $this->cur_y = 0;
                        $this->width = 0;
                        $this->height = 0;
                        $this->hImage = 0;
                        $this->colormap = array();
                        $this->hColor = 0;
                        $this->font = 0;
                        $this->type = 'png';
                        $this->temp_dir = PHPGW_SERVER_ROOT . SEP . 'phpgwapi' 
. SEP . 'images' . SEP;
                }

                function check_gd()
                {
                ob_start();
                phpinfo(8); // load the modules
                $a = ob_get_contents();
                ob_end_clean();

                        if(preg_match('/.*GD Version.*(1[0-9|\.]+).*/',$a,$m))
                        {
                                $r=1; //$v=$m[1];
                }
                        elseif(preg_match('/.*GD 
Version.*(2[0-9|\.]+).*/',$a,$m))
                        {
                                $r=2; //$v=$m[1];
                }
                else
                        {
                                $r=0; //$v=$m[1];
                }
                return $r;
                }

                function Init()
                {
                        $this->hImage = ImageCreate($this->width, 
$this->height) or die;
                        return True;
                }

                function Done()
                {
                        ImageDestroy($this->hImage);
                }

                /* Create a tmp filename */
                function tmp_file()
                {
                        $name = 'draw_tmp_' . 
$GLOBALS['phpgw_info']['user']['account_id'] . '_';
                        srand((double)microtime()*1000000);
                        return($this->tmpdir . $name . rand(1,100000));
                }

                function MoveTo($x, $y)
                {
                        if ($x >= 0 && $x <= $this->width && $y >= 0 && $y <= 
$this->height)
                        {
                                $this->cur_x = $x;
                                $this->cur_y = $y;

                                return true;
                        }
                        return false;
                }

                function LineTo($x, $y, $linestyle = 'solid')
                {
                        if ($x >= 0 && $x <= $this->width && $y >= 0 && $y <= 
$this->height)
                        {
                                if ($linestyle == 'dashed')
                                        ImageDashedLine($this->hImage, 
$this->cur_x, $this->cur_y, $x, $y, $this->hColor);
                                else
                                        ImageLine($this->hImage, $this->cur_x, 
$this->cur_y, $x, $y, $this->hColor);

                                $this->cur_x = $x;
                                $this->cur_y = $y;

                                return true;
                        }

                        return false;
                }

                function Line($x1, $y1, $x2, $y2, $linestyle = 'solid')
                {
                        if ($x1 >= 0 && $x1 <= $this->width && $y1 >= 0 && $y1 
<= $this->height && $x2 >= 0 && $x2 <= $this->width && $y2 >= 0 && $y2 <= 
$this->height)
                        {
                                if ($linestyle == 'solid')
                                        ImageLine($this->hImage, $x1, $y1, $x2, 
$y2, $this->hColor);
                                else
                                        ImageDashedLine($this->hImage, $x1, 
$y1, $x2, $y2, $this->hColor);

                                $this->cur_x = $x2;
                                $this->cur_y = $y2;

                                return true;
                        }

                        return false;
                }

                function SetColor($r, $g, $b, $set_transparent=False)
                {
                        $key = "$r,$g,$b";
                        if (!IsSet($this->colormap[$key]))
                        {
                                $this->hColor = 
ImageColorAllocate($this->hImage, $r, $g, $b);
                                $this->colormap[$key] = $this->hColor;
                        }
                        else
                        {
                                $this->hColor = $this->colormap[$key];
                        }

                        if ($set_transparent)
                        {
                                
ImageColorTransparent($this->hImage,$this->hColor);
                        }
                        return true;
                }

                function SetColorByName($name)
                {
                        $r = 0;
                        $g = 0;
                        $b = 0;
                        switch ($name)
                        {
                                case 'red':
                                        $r = 180;
                                        break;
                                case 'green':
                                        $g = 180;
                                        break;
                                case 'blue':
                                        $b = 180;
                                        break;
                                case 'bright red':
                                        $r = 255;
                                        break;
                                case 'bright green':
                                        $g = 255;
                                        break;
                                case 'bright blue':
                                        $b = 255;
                                        break;
                                case 'dark red':
                                        $r = 80;
                                        break;
                                case 'dark green':
                                        $g = 80;
                                        break;
                                case 'dark blue':
                                        $b = 80;
                                        break;
                                case 'olivedrab4':
                                        $r = 105;
                                        $g = 139;
                                        $b = 34;
                                        break;
                                case 'dove':
                                        $r = 0x2c;
                                        $g = 0x6D;
                                        $b = 0xAF;
                                        break;
                                case 'seagreen':
                                        $r = 46;
                                        $g = 139;
                                        $b = 87;
                                        break;
                                case 'midnightblue':
                                        $r = 25;
                                        $g = 25;
                                        $b = 112;
                                        break;
                                case 'darkorange':
                                        $r = 255;
                                        $g = 140;
                                        break;
                                case 'yellow':
                                        $r = 255;
                                        $g = 215;
                                        break;
                                case 'grey':
                                        $r = 180;
                                        $g = 180;
                                        $b = 180;
                                        break;
                        }
                        return $this->SetColor($r, $g, $b);
                }

                function SetFont($font)
                {
                        if ($font < 1 || $font > 5)
                                return false;

                        $this->font = $font;

                        return true;
                }

                function GetFontHeight()
                {
                        return ImageFontHeight($this->font);
                }

                function GetFontWidth()
                {
                        return ImageFontWidth($this->font);
                }

                function DrawText($params)
                {
                        $text                   = $params['text'];
                        $direction              = 
(isset($params['direction'])?$params['direction']:'');
                        $justification  = 
(isset($params['justification'])?$params['justification']:'center');
                        $margin_left    = 
(isset($params['margin_left'])?$params['margin_left']:'');

                        $textwidth = ImageFontWidth($this->font) * 
strlen($text);

                        /*if (isset($margin_left) && $textwidth >= $margin_left)
                        {
                                $text = strlen($text) - 1 . '.';
                        }*/

                        if ($justification == 'center')
                        {
                                if ($direction == 'up')
                                {
                                        $this->cur_y += $textwidth / 2;
                                        if ($this->cur_y > $this->height)
                                                $this->cur_y = $this->height;
                                }
                                else
                                {
                                        $this->cur_x -= $textwidth / 2;
                                        if ($this->cur_x < 0)
                                                $this->cur_x = 0;
                                }
                        }
                        else if ($justification == 'right')
                                {
                                        if ($direction == 'up')
                                        {
                                                $this->cur_y += $textwidth;
                                                if ($this->cur_y > 
$this->height)
                                                        $this->cur_y = 
$this->height;
                                        }
                                        else
                                        {
                                                $this->cur_x -= $textwidth;
                                                if ($this->cur_x < 0)
                                                        $this->cur_x = 0;
                                        }
                                }

                        if ($direction == 'up')
                                ImageStringUp($this->hImage, $this->font, 
$this->cur_x, $this->cur_y, $text, $this->hColor);
                        else
                                ImageString($this->hImage, $this->font, 
$this->cur_x, $this->cur_y, $text, $this->hColor);

                        return true;
                }

                function draw_triangle($points)
                {
                        
imagefilledpolygon($this->hImage,$points,3,$this->hColor);
                        return True;
                }

                function draw_rectangle($data = 0, $style = 'unused')
                {
                        imagefilledrectangle ($this->hImage, $data[0], 
$data[1], $data[2], $data[3],$this->hColor);

                        if($style != 'unused')
                        {
                                $this->SetColor(255,255,255);
                                switch($style)
                                {
                                        case 'open':
                                                imagefilledrectangle 
($this->hImage, $data[0]+1, $data[1]+4, $data[2]-1, $data[3]-4,$this->hColor);
                                                break;
                                        default:
                                                imagefilledrectangle 
($this->hImage, $data[0]+1, $data[1]+4, $data[2]-1, $data[3]-4,$this->hColor);
                                                imagefilledrectangle 
($this->hImage, $data[0]+4, $data[1]+1, $data[2]-4, $data[3]-1,$this->hColor);
                                }
                        }
                        return True;
                }

                function check_tmp_files()
                {
                        if (is_dir($this->temp_dir))
                        {
                                $basedir = opendir($this->temp_dir);

                                while ($files = readdir($basedir))
                                {
                                        if (($files != '.') && ($files != '..'))
                                        {
                                                $to_find = '_' . 
$GLOBALS['phpgw_info']['user']['account_id'] . '_';
                                                $pos = strpos($files,$to_find);
                                                if($pos)
                                                {
                                                        unlink($this->temp_dir 
. $files);
                                                }
                                        }
                                }
                                closedir($basedir);
                                return True;
                        }
                        return False;
                }

                function save_img()
                {
                        $this->check_tmp_files();
                        $filename = $this->tmp_file();
                        ImagePNG($this->hImage,$this->temp_dir . $filename);
                        return $filename;
                }

                function ToBrowser()
                {
                        //header('Content-type: image/' . $this->type);

                        switch ($this->type)
                        {
                                case 'png':
                                        
ImagePNG($this->hImage,$this->temp_file);
                                        break;
                                case 'gif':
                                        ImageGIF($this->hImage);
                                        break;
                                case 'jpeg':
                                        ImageJPEG($this->hImage);
                                        break;
                        }
                }
        }
?>

====================================================
Index: class.gdbutton.inc.php
<?php
        /*******************************************************************\
        * phpGroupWare - GD Button                                          *
        * http://www.phpgroupware.org                                       *
        *                                                                   *
        * Written by by Bettina Gille address@hidden                *
        *                                                                   *
        * Creates graphical buttons by using GD and TTF fonts               *
        * Copyright (C) 2002 Bettina Gille                                  *
        * ----------------------------------------------------------------- *
        * Some methods based on former class.graphics                       *
        * Copyright (C) 2001 Lars Kneschke                                  *
        * ----------------------------------------------------------------- *
        * This library is part of the phpGroupWare API                      *
        * ----------------------------------------------------------------- *
        * This library is free software; you can redistribute it and/or     *
        * modify it under the terms of the GNU General Public License as    *
        * published by the Free Software Foundation; either version 2 of    *
        * the License, or (at your option) any later version.               *
        *                                                                   *
        * This program is distributed in the hope that it will be useful,   *
        * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  *
        * General Public License for more details.                          *
        *                                                                   *
        * You should have received a copy of the GNU General Public License *
        * along with this program; if not, write to the Free Software       *
        * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.gdbutton.inc.php,v 1.4 2005/01/13 11:36:43 ceb Exp $ */

        class gdbutton
        {
                var $ttf_font;
                var $image;

                var $bg_color;
                var $font_color;

                var $font_size;
                var $font_text;

                var $filename;

                var $url_base;

                function gdbutton()
                {
                        $this->image            = 0;
                        $this->font_size        = 0;
                        $this->font_text        = '';
                        $this->ttf_font         = PHPGW_SERVER_ROOT . SEP . 
'phpgwapi' . SEP . 'fonts' . SEP . 'FreeSans.ttf';
                        $this->filename         = '';

                        $this->xspace           = 4;
                        $this->yspace           = 4;

                        $this->save_dir         = 
$GLOBALS['HTTP_SERVER_VARS']['DOCUMENT_ROOT'] . PHPGW_IMAGES_DIR . SEP;
                        $this->img_dir          = PHPGW_IMAGES_DIR . SEP;
                }

                function button_init()
                {
                        $this->image = ImageCreate($this->width,$this->height) 
or die;
                        ImageColorAllocate($this->image,0x2c,0x6D,0xAF);
                        return True;
                }

                function file_name()
                {
                        $this->filename = 'phpgw_button_' . 
md5($this->font_text) . '.png';
                        $this->filename = strtolower($this->filename);

                        return True;
                }

                function gd_button()
                {
                        if (file_exists($this->save_dir . $this->filename))
                        {
                                return $this->filename;
                        }

                        $this->font_size = 5;

                        $text_width             = 
ImageFontWidth($this->font_size) * strlen($this->font_text);
                        $text_height    = ImageFontHeight($this->font_size);

                        $this->width    = ($this->xspace*2) + $text_width;
                        $this->height   = $this->yspace + $text_height;

                        $this->xpos = ($this->width/2) - ($text_width/2);

                        if ($this->xpos < 0)
                        {
                                $this->xpos = $this->xspace;
                        }

                        $this->ypos = ($this->height/2) - ($text_height/2);

                        if ($this->ypos < 0)
                        {
                                $this->ypos = $this->yspace;
                        }

                        $this->button_init();

                        $black = ImageColorAllocate($this->image, 0,0,0);
                        
ImageRectangle($this->image,0,0,$this->width-1,$this->height-1,$black);

                        $white = ImageColorAllocate($this->image, 255,255,255);
                        
ImageRectangle($this->image,0,0,$this->width,$this->height,$white);

                        ImageString($this->image, $this->font_size, 
intval($this->xpos+1), intval($this->ypos), $this->font_text, $black);
                        ImageString($this->image, $this->font_size, 
intval($this->xpos), intval($this->ypos-1), $this->font_text, $white);

                        return $this->save_button();
                }

                function ttf_button()
                {
                        if (file_exists($this->save_dir . $this->filename))
                        {
                                return $this->filename;
                        }
                        $this->font_size = 11;

                        $size = 
imagettfbbox($this->font_size,0,$this->ttf_font,$this->font_text);
                        $dx = abs($size[2]-$size[0]);
                        $dy = abs($size[5]-$size[3]);

                        $xpad = 10;
                        $ypad = 10;

                        $this->width    = ($xpad/2) + $xpad + $dx;
                        $this->height   = $dy + $ypad;

                        $this->button_init();

                        $black = ImageColorAllocate($this->image, 0,0,0);
                        
ImageRectangle($this->image,0,0,$this->width-1,$this->height-1,$black);

                        $white = ImageColorAllocate($this->image, 255,255,255);
                        
ImageRectangle($this->image,0,0,$this->width,$this->height,$white);

                        ImageTTFText($this->image, $this->font_size, 0, 
intval($xpad/2)+1, $dy+intval($ypad/2), -$black, $this->ttf_font, 
$this->font_text);
                        ImageTTFText($this->image, $this->font_size, 0, 
intval($xpad/2), $dy+intval($ypad/2)-1, -$white, $this->ttf_font, 
$this->font_text);

                        return $this->save_button();
                }

                function save_button()
                {
                        ImagePNG($this->image,$this->save_dir . 
$this->filename);
                        ImageDestroy($this->image);

                        return $this->filename;
                }

                function input_button($data)
                {
                        if (is_array($data))
                        {
                                $this->font_text        = $data['font_text'];
                                $button_name            = $data['button_name'];
                        }

                        $this->file_name();

                        if (extension_loaded('gd') && $config['ttf'] == 'yes')
                        {
                                if (dl('gd.so'))
                                {
                                        return '<input type="image" src="' . 
$this->img_dir . $this->ttf_button() . '" border="0" name="' . $button_name . 
'" value="' . $button_name . '">';
                                }
                        }
                        elseif(extension_loaded('gd'))
                        {
                                        return '<input type="image" src="' . 
$this->img_dir . $this->gd_button() . '" border="0" name="' . $button_name . '" 
value="' . $button_name . '">';
                        }
                        else
                        {
                                return '<input type="submit" value="' . 
$this->font_text . '" name="' . $button_name.'">';
                        }
                }

                // this function checks, if there is a variable $aaa_x and 
$aaa_y
                // if so, it will create a new variable $aaa
                function parseHTTPPostVars()
                {
                        // execute only if libgd support is enabled
                        if (!extension_loaded('gd'))
                        {
                                return;
                        }

                        if (is_array($GLOBALS['HTTP_POST_VARS']))
                        {
                                while( list($key, $val) = 
each($GLOBALS['HTTP_POST_VARS']))
                                {
                                        if (ereg("(.*)_x",$key,$varName) && 
$HTTP_POST_VARS[$varName[1]."_y"])
                                        {
                                                $name = $varName[1];
                                                global $$name;
                                                $$name = "content generated by 
parseHTTPPostVars()";
                                        }
                                }
                        }
                }
        }

====================================================
Index: class.gdgraph.inc.php
<?php
        /*******************************************************************\
        * phpGroupWare - GD Graph                                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Written by Bettina Gille address@hidden                   *
        *                                                                   *
        * Creates graphical statistics using GD graphics library            *
        * Copyright (C) 2003,2004 Free Software Foundation, Inc.            *
        * ----------------------------------------------------------------- *
        * This class based on boGraph.php3                                  *
        * Double Choco Latte - Source Configuration Management System       *
        * Copyright (C) 1999  Michael L. Dean & Tim R. Norman               *
        * ----------------------------------------------------------------- *
        * This library is part of the phpGroupWare API                      *
        * ----------------------------------------------------------------- *
        * This library is free software; you can redistribute it and/or     *
        * modify it under the terms of the GNU General Public License as    *
        * published by the Free Software Foundation; either version 2 of    *
        * the License, or (at your option) any later version.               *
        *                                                                   *
        * This program is distributed in the hope that it will be useful,   *
        * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  *
        * General Public License for more details.                          *
        *                                                                   *
        * You should have received a copy of the GNU General Public License *
        * along with this program; if not, write to the Free Software       *
        * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.gdgraph.inc.php,v 1.19 2005/01/13 11:36:43 ceb Exp $ */

        class gdgraph
        {
                var $debug;
                var $popup_view;
                var $title;
                var $caption_x;
                var $caption_y;
                var $lines_x;
                var $lines_y;
                var $line_captions_x;
                var $data;
                var $colors;
                var $color_legend;
                var $graph_width;
                var $graph_height;
                var $margin_top;
                var $margin_left;
                var $margin_bottom;
                var $margin_right;
                var $img;

                function gdgraph($debug = False)
                {
                        $this->debug                    = $debug;

                        $this->title_font_size  = 3;
                        $this->line_font_size   = 2;
                        $this->x_font_size              = 1;

                        $this->title                    = 'Gantt Chart';
                        $this->legend_title             = 'Color Legend';

                        $this->caption_x                = 'x';
                        $this->caption_y                = 'y';

                        $this->num_lines_x              = 30;
                        $this->num_lines_y              = 10;

                        $this->split_val                = 1;

                        $this->line_captions_x  = array();
                        $this->line_captions_y  = array();

                        $this->data                             = array();

                        $this->colors                   = 
array('red','green','blue','bright green','bright blue','dark green','dark 
blue','olivedrab4','dove',
                                                                                
        'seagreen','midnightblue');

                        $this->color_legend             = array();
                        $this->color_extra              = 'yellow';
                        $this->legend_bottom    = 40;

                        $this->graph_width              = 800;
                        $this->graph_height             = 400;

                        $this->margin_top               = 70;
                        $this->margin_left              = 150;
                        $this->margin_bottom    = 40;
                        $this->margin_right             = 20;

                        $this->img                              = 
CreateObject('phpgwapi.gdimage');
                        $this->temp_file                = $this->img->temp_file;
                }

                function rRender()
                {
                        // Initialize image - map white since it's our 
background
                        $this->img->width = $this->graph_width;
                        $this->img->height = $this->graph_height;
                        $this->img->Init();
                        $this->img->SetColor(255, 255, 0);
                        $this->img->ToBrowser();
                        $this->img->Done();
                }

                function set_locale()
                {
                        
switch($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
                        {
                                case 'de':
                                        if(phpversion() >= '4.3.0')
                                        {
                                                $loc = 
setlocale(LC_ALL,'address@hidden','de_DE','de','ge','de_DE.ISO-8859-1','de_DE.UTF-8');
                                        }
                                        else
                                        {
                                                $loc = 
setlocale(LC_ALL,'de_DE');
                                        }
                                        break;
                                default:
                                        $loc = setlocale(LC_ALL,0); break;
                        }
                        //echo 'PREF_LOC: ' . $loc;
                }

                function date_format($sdate = 0,$edate = 0)
                {
                        $day_from = date('d',$sdate);
                        $mon_from = date('m',$sdate);
                        $year_from = date('Y',$sdate);

                        $day_to = date('d',$edate);
                        $mon_to = date('m',$edate);
                        $year_to = date('Y',$edate);

                        //if date_from is newer than date to, invert dates
                        $sign=1;

                        if ($year_from>$year_to)
                        {
                                $sign=-1;
                        }
                        else if ($year_from==$year_to)
                        {
                                if ($mon_from>$mon_to)
                                {
                                        $sign=-1;
                                }
                                else if ($mon_from==$mon_to)
                                {
                                        if ($day_from>$day_to)
                                        {
                                                $sign=-1;
                                        }
                                }
                        }

                /*if ($sign==-1)
                {
                        //invert dates
                        $day_from = $date_to_parts[0];
                        $mon_from = $date_to_parts[1];
                        $year_from = $date_to_parts[2];
                        $day_to = $date_from_parts[0];
                        $mon_to = $date_from_parts[1];
                        $year_to = $date_from_parts[2];
                }*/

                        $yearfrom1=$year_from;  //actual years
                        $yearto1=$year_to;      //(yearfrom2 and yearto2 are 
used to calculate inside the range "0")
                        //checks ini date
                        if ($yearfrom1<1980)
                        {//year is under range 0
                                $deltafrom=-floor((1999-$yearfrom1)/20)*20; 
//delta t1
                                $yearfrom2=$yearfrom1-$deltafrom;          
//year used for calculations
                        }
                        else if($yearfrom1>1999)
                        {//year is over range 0
                                $deltafrom=floor(($yearfrom1-1980)/20)*20; 
//delta t1
                                $yearfrom2=$yearfrom1-$deltafrom;          
//year used for calculations
                        }
                        else
                        {//year is in range 0
                                $deltafrom=0;
                                $yearfrom2=$yearfrom1;
                        }

                        //checks end date
                        if ($yearto1<1980)
                        {//year is under range 0
                                $deltato=-floor((1999-$yearto1)/20)*20; //delta 
t2
                                $yearto2=$yearto1-$deltato;            //year 
used for calculations
                        }
                        else if($yearto1>1999)
                        {//year is over range 0
                                $deltato=floor(($yearto1-1980)/20)*20; //delta 
t2
                                $yearto2=$yearto1-$deltato;            //year 
used for calculations
                        }
                        else
                        {//year is in range 0
                                $deltato=0;
                                $yearto2=$yearto1;
                        }

                        //Calculates the UNIX Timestamp for both dates (inside 
range 0)
                        $ts_from = mktime(0, 0, 0, $mon_from, $day_from, 
$yearfrom2);
                        $ts_to = mktime(0, 0, 0, $mon_to, $day_to, $yearto2);
                        $diff = ($ts_to-$ts_from)/86400;
                        //adjust ranges
                        $diff += 7305 * (($deltato-$deltafrom) / 20);

                        $date_diff = round($sign*$diff);
                        //echo 'DATE_DIFF: ' . $date_diff;
                        return $date_diff;
                }

                function format_data($sdate = 0,$edate = 0)
                {
                        $date_diff = $this->date_format($sdate,$edate);

                        if($date_diff <= 30)
                        {
                                $this->split_val        = 1;
                                $this->date_diff        = $date_diff;
                                $this->num_lines_x      = $date_diff+1;
                        }
                        else if($date_diff > 30)
                        {
                                $this->split_val        = round($date_diff/30);
                                $this->date_diff        = 
round($date_diff/$this->split_val);
                                $this->num_lines_x      = 
round($date_diff/$this->split_val)+1;
                        }

                        //echo 'OLD_SPLIT_VAL: ' . $this->split_val . '<br />';
                        if($this->split_val == 14)
                        {
                                $this->split_val = 15;
                        }

                        //echo 'SPLIT_VAL: ' . $this->split_val . '<br />';
                        //echo 'LINES_X: ' . $this->num_lines_x . '<br />';

                        $this->set_locale();

                        $this->line_captions_x[0] = array
                        (
                                'date'                          => 
mktime(12,0,0,date('m',$sdate),date('d',$sdate),date('Y',$sdate)),
                                'date_formatted'        => 
date('w',$sdate)==1?date('d/m',$sdate):date('d',$sdate),
                                'date_day'                      => 
substr(strftime ('%a',$sdate),0,1), //substr(date('D',$sdate),0,1),
                                'month'                         => 
strftime('%b',$sdate), //date('M',$sdate),
                                'year'                          => 
date('Y',$sdate)
                        );

                        for($i=1;$i<=$this->date_diff;$i++)
                        {
                                $add            = $this->split_val*$i;
                                $curr_date      = 
mktime(12,0,0,date('m',$sdate),date('d',$sdate)+$add,date('Y',$sdate));
                                $pref_date      = 
mktime(12,0,0,date('m',$curr_date),date('d',$curr_date)-$this->split_val,date('Y',$curr_date));

                                $this->line_captions_x[$i] = array
                                (
                                        'date'                          => 
$curr_date,
                                        'date_formatted'        => 
date('w',$curr_date)==1?date('d/m',$curr_date):date('d',$curr_date),
                                        'date_day'                      => 
substr(strftime ('%a',$curr_date),0,1)
                                );

                                /* if graph->height = 750 -> split_val > 13 */
                                if($this->split_val > 15)
                                {
                                        $this->line_captions_x[$i]['month'] = 
date('m',$curr_date);
                                }
                                else if(date('n',$pref_date) < 
date('n',$curr_date) || (date('n',$pref_date) > date('n',$curr_date) && 
date('Y',$pref_date) < date('Y',$curr_date)))
                                {
                                        $this->line_captions_x[$i]['month'] = 
strftime('%b',$curr_date); //date('M',$curr_date);
                                }

                                if(date('Y',$pref_date) < date('Y',$curr_date))
                                {
                                        $this->line_captions_x[$i]['year'] = 
date('Y',$curr_date);
                                }
                        }

                        if($this->line_captions_x[$this->date_diff]['date'] < 
$edate)
                        {
                                $last_date      = 
$this->line_captions_x[$this->date_diff]['date'];
                                $curr_date      = 
mktime(12,0,0,date('m',$last_date),date('d',$last_date)+$this->split_val,date('Y',$last_date));
                                $pref_date      = 
mktime(12,0,0,date('m',$curr_date),date('d',$curr_date)-$this->split_val,date('Y',$curr_date));

                                $this->line_captions_x[$this->date_diff+1] = 
array
                                (
                                        'date'                          => 
$curr_date,
                                        'date_formatted'        => 
date('w',$curr_date)==1?date('d/m',$curr_date):date('d',$curr_date),
                                        'date_day'                      => 
substr(strftime ('%a',$curr_date),0,1)  //substr(date('D',$curr_date),0,1)
                                );

                                if(date('m',$pref_date) < date('m',$curr_date))
                                {
                                        
$this->line_captions_x[$this->date_diff+1]['month'] = 
strftime('%b',$curr_date);  //date('M',$curr_date);
                                }

                                if(date('Y',$pref_date) < date('Y',$curr_date))
                                {
                                        
$this->line_captions_x[$this->date_diff+1]['year'] = date('Y',$curr_date);
                                }
                                $this->num_lines_x = $this->num_lines_x+1;
                        }

                        if($this->num_lines_x < 2)
                        {
                                $this->num_lines_x = 2;
                        }

                        /*case 'y': case 'Y': //calculates difference in years
                        $diff=$year_to-$year_from;
                        $adjust=0;
                if ($mon_from>$mon_to) $adjust=-1;
                        else if ($mon_from==$mon_to)
                if ($day_from>$day_to) $adjust=-1;
                        return $sign*($diff+$adjust);
                        break;
                        }*/
                }

                function Render($sdate = 0, $edate = 0)
                {
                        if(count($this->color_legend) > 0)
                        {
                                $this->margin_bottom = $this->margin_bottom + 
(count($this->color_legend)*25) + 25;
                        }

                        // get the graph height
                        if(count($this->data) > 0)
                        {
                                $this->graph_height = (count($this->data)*30) + 
$this->margin_top + $this->margin_bottom;
                        }

                        // Initialize image - map white since it's our 
background
                        $this->img->width = $this->graph_width;
                        $this->img->height = $this->graph_height;
                        $this->img->Init();
                        $this->img->SetColor(255, 255, 255);

                        // Draw the title
                        $this->img->SetFont($this->title_font_size);
                        $this->img->SetColor(0, 0, 0);
                        $this->img->MoveTo($this->graph_width / 2, 2);
                        $this->img->DrawText(array('text' => $this->title));

                        // line under title
                        $this->img->Line($this->margin_left - 4, 
$this->img->GetFontHeight() + 4, $this->graph_width - $this->margin_right, 
$this->img->GetFontHeight() + 4);

                        // Draw the x axis text plus month plus dashed lines 
for x axis
                        $linespace = ($this->graph_width - $this->margin_left - 
$this->margin_right) / ($this->num_lines_x - 1);

                        reset($this->line_captions_x);
                        $i = 0;

                        //_debug_array($this->line_captions_x);

                        foreach($this->line_captions_x as $day_text)
                        {
                                $this->img->SetColor(0, 0, 0);
                                if(isset($day_text['year']))
                                {
                                        
$this->img->SetFont($this->line_font_size);
                                        $this->img->MoveTo($i * $linespace + 
$this->margin_left, $this->img->GetFontHeight() + 10);
                                        $this->img->DrawText(array('text' => 
$day_text['year']));
                                }

                                if(isset($day_text['month']))
                                {
                                        
$this->img->SetFont($this->line_font_size);
                                        $this->img->MoveTo($i * $linespace + 
$this->margin_left, $this->img->GetFontHeight() + 25);
                                        $this->img->DrawText(array('text' => 
$day_text['month']));
                                }

                                $this->img->SetFont($this->x_font_size);
                                $this->img->MoveTo($i * $linespace + 
$this->margin_left, $this->img->GetFontHeight() + 45);

                                if(date('w',$day_text['date']) == 0 || 
date('w',$day_text['date']) == 6)
                                {
                                        $this->img->SetColor(190, 190, 190);
                                }
                                else if(date('w',$day_text['date']) == 1)
                                {
                                        $this->img->SetColor(0, 150, 255);
                                }
                                $this->img->DrawText(array('text' => 
$day_text['date_day']));

                                $x = $i * $linespace + $this->margin_left;

                                $this->img->SetColor(190, 190, 190);
                                if(date('w',$day_text['date']) == 0 || 
date('w',$day_text['date']) == 6)
                                {
                                        $this->img->Line($x, $this->margin_top, 
$x, $this->graph_height - $this->margin_bottom - 4);
                                }
                                else if(date('w',$day_text['date']) == 1)
                                {
                                        $this->img->SetColor(0, 150, 255);
                                        $this->img->Line($x, $this->margin_top, 
$x, $this->graph_height - $this->margin_bottom - 4);
                                }
                                else
                                {
                                        $this->img->Line($x, $this->margin_top, 
$x, $this->graph_height - $this->margin_bottom - 4, 'dashed');
                                }

                                $this->img->SetColor(0, 0, 0);
                                $this->img->Line($x, $this->graph_height - 
$this->margin_bottom - 4, $x, $this->graph_height - $this->margin_bottom + 4);
                                $i++;
                        }

                        //$this->img->MoveTo($this->graph_width / 2, 
$this->graph_height - $this->img->GetFontHeight() - 2);
                        //$this->img->MoveTo(2, $this->graph_height / 2);
                        //$this->img->DrawText($this->caption_y, 'up', 
'center');
                        //$this->img->MoveTo($this->graph_width / 2, 
$this->graph_height - $this->img->GetFontHeight() - 2);
                        //$this->img->DrawText($this->caption_x, '', 'center');

                        // Draw the two axis
                        $this->img->SetColor(0, 0, 0);
                        $this->img->Line($this->margin_left, $this->margin_top, 
$this->margin_left, $this->graph_height - $this->margin_bottom + 4);
                        $this->img->Line($this->margin_left - 4, 
$this->graph_height - $this->margin_bottom, $this->graph_width - 
$this->margin_right, $this->graph_height - $this->margin_bottom);

                        // Draw dashed lines for y axis
                        $linespace = ($this->graph_height - $this->margin_top - 
$this->margin_bottom) / ($this->num_lines_y - 1);
                        for ($i = 1; $i < $this->num_lines_y; $i++)
                        {
                                $y = $this->graph_height - $this->margin_bottom 
- ($i * $linespace);
                                $this->img->SetColor(0, 0, 0);
                                $this->img->Line($this->margin_left - 4, $y, 
$this->margin_left + 4, $y);
                                $this->img->SetColor(200, 200, 200);
                                $this->img->Line($this->margin_left + 4, $y, 
$this->graph_width - $this->margin_right, $y, 'dashed');
                        }

                        /* Find the largest numeric value in data (an array of 
arrays representing data)
                        $largest = 0;
                        reset($this->data);
                        while (list($junk, $line) = each($this->data))
                        {
                                reset($line);
                                while (list($junk2, $value) = each($line))
                                {
                                        if ($value > $largest)
                                        $largest = $value;
                                }
                        }

                        while ($largest < ($this->num_lines_y - 1))
                                $largest = ($this->num_lines_y - 1);

                        $spread = ceil($largest / ($this->num_lines_y - 1));
                        $largest = $spread * ($this->num_lines_y - 1);*/

                        $largest = $this->num_lines_x - 1;

                        // Draw the x axis text
                        $this->img->SetColor(0, 0, 0);
                        $this->img->SetFont($this->x_font_size);
                        $linespace = ($this->graph_width - $this->margin_left - 
$this->margin_right) / ($this->num_lines_x - 1);
                        reset($this->line_captions_x);
                        $i = 0;
                        while (list(,$text) = each($this->line_captions_x))
                        {
                                $this->img->MoveTo($i * $linespace + 
$this->margin_left, $this->graph_height - $this->margin_bottom + 8);
                                $this->img->DrawText(array('text' => 
$text['date_formatted']));
                                $i++;
                        }

                        // Draw the lines for the data
                        $this->img->SetColor(255, 0, 0);
                        reset($this->data);

                        if($this->debug)
                        {
                                _debug_array($this->data);
                        }
                        //_debug_array($this->data);
                        $i = 1;
                        $px = $py = 0;
                        if(is_array($this->data))
                        {
                        foreach($this->data as $line)
                        {
                                if($line['extracolor'])
                                {
                                        
$this->img->SetColorByName($line['extracolor']);
                                }
                                else
                                {
                                        
$this->img->SetColorByName($this->colors[$line['color']]);
                                }

                                $x1 = $x2 = $y1 = $y2 = 0;
                                $gx = 0; // progress

                                $linespace = ($this->graph_height - 
$this->margin_top - $this->margin_bottom) / ($this->num_lines_y - 1);

                                $y1 = $y2 = $this->graph_height - 
$this->margin_bottom - ($i * $linespace);
                                $py = $line['f_sdate']?$y2:$py; // previous

                                $linespace = ($this->graph_width - 
$this->margin_left - $this->margin_right) / ($this->num_lines_x - 1);

                                if ($line['sdate'] <= 
$this->line_captions_x[0]['date'] && $line['edate'] >= 
$this->line_captions_x[0]['date'])
                                {
                                        if($this->debug)
                                        {
                                                echo 'PRO sdate <= x sdate | 
PRO edate > x sdate<br>';
                                        }
                                        $x1 = $this->margin_left;
                                }
                                else if($line['sdate'] >= 
$this->line_captions_x[0]['date'])  //&& $line['edate'] <= 
$this->line_captions_x[$largest]['date'])
                                {
                                        if($this->debug)
                                        {
                                                echo 'PRO sdate >= date! 
pro_sdate = ' . $line['sdate'] . ', pro_edate = ' . $line['edate'] . '<br>';
                                                echo 'PRO sdate >= date! 
pro_sdate_formatted = ' . 
$GLOBALS['phpgw']->common->show_date($line['sdate'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
 . ', pro_edate_formatted = ' . 
$GLOBALS['phpgw']->common->show_date($line['edate'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
 . '<br>';
                                                echo 'x sdate: ' . 
$this->line_captions_x[0]['date'] . ', x edate: ' . 
$this->line_captions_x[$largest]['date'] . '<br><br>';
                                        }

                                        for($y=0;$y<$largest;$y++)
                                        {
                                                if($line['sdate'] == 
$this->line_captions_x[$y]['date'])
                                                {
                                                        if($this->debug)
                                                        {
                                                                echo 'PRO sdate 
== date! pro_sdate = ' . $line['sdate'] . ', date = ' . 
$this->line_captions_x[$y]['date'] . '<br>';
                                                        }
                                                        $x1 = $y * $linespace + 
$this->margin_left;
                                                }
                                                else if($line['sdate'] >= 
$this->line_captions_x[$y]['date'] && $line['sdate'] <= 
$this->line_captions_x[$y+1]['date'])
                                                {
                                                        $diff = ($line['sdate'] 
- $this->line_captions_x[$y]['date'])/86400;
                                                        if($this->debug)
                                                        {
                                                                echo 'PRO sdate 
>= date! pro_sdate = ' . $line['sdate'] . ', date = ' . 
$this->line_captions_x[$y]['date'] . '<br>';
                                                                echo 'diff: ' . 
($line['sdate'] - $this->line_captions_x[$y]['date'])/86400 . '<br />';
                                                        }
                                                        $x1 = $y * $linespace + 
$this->margin_left + (($linespace/$this->split_val)*$diff);
                                                }
                                        }
                                }
                                else if(($line['sdate'] <= 
$this->line_captions_x[0]['date'] && $line['edate'] <= 
$this->line_captions_x[0]['date']) ||
                                                ($line['sdate'] >= 
$this->line_captions_x[$largest]['date'] && $line['edate'] >= 
$this->line_captions_x[$largest]['date']))
                                {
                                        $x1 = 0;
                                }
                                else
                                {
                                        $x1 = $largest * $linespace + 
$this->margin_left;
                                }

                                if ($line['edate'] >= 
$this->line_captions_x[$largest]['date'])
                                {
                                        if($this->debug)
                                        {
                                                echo 'PRO edate >= x edate! 
pro_edate = ' . $line['edate'] . '<br>';
                                                echo 'PRO edate >= x edate! 
pro_edate_formatted = ' . 
$GLOBALS['phpgw']->common->show_date($line['edate'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
 . '<br>';
                                                echo 'x edate: ' . 
$this->line_captions_x[$largest]['date'] . '<br>';
                                        }
                                        $x2 = $this->graph_width - 
$this->margin_right;
                                        $px = $line['f_sdate']?$x2:$px;
                                }
                                else if($line['edate'] <= 
$this->line_captions_x[$largest]['date'] && $line['edate'] >= 
$this->line_captions_x[0]['date'])
                                {
                                        for($y=0;$y<$largest;$y++)
                                        {
                                                if($line['edate'] == 
$this->line_captions_x[$y]['date'])
                                                {
                                                        if($this->debug)
                                                        {
                                                                echo 'PRO edate 
== x edate! pro_edate = ' . $line['edate'] . '<br>';
                                                        }
                                                        $x2 = $y * $linespace + 
$this->margin_left;
                                                        $px = 
$line['f_sdate']?$x2:$px;
                                                }
                                                else if($line['edate'] >= 
$this->line_captions_x[$y]['date'] && $line['edate'] <= 
$this->line_captions_x[$y+1]['date'])
                                                {
                                                        $diff = ($line['edate'] 
- $this->line_captions_x[$y]['date'])/86400;
                                                        if($this->debug)
                                                        {
                                                                echo 'PRO edate 
>= x edate! pro_edate = ' . $line['edate'] . '<br>';
                                                                echo 'diff: ' . 
($line['edate'] - $this->line_captions_x[$y]['date'])/86400 . '<br />';
                                                        }
                                                        $x2 = $y * $linespace + 
$this->margin_left + (($linespace/$this->split_val)*$diff);
                                                        $px = 
$line['f_sdate']?$x2:$px;
                                                }
                                        }
                                }
                                else if($line['edate'] >= 
$this->line_captions_x[$largest]['date'] && $line['edate'] >= 
$this->line_captions_x[0]['date'] ||
                                                $line['edate'] <= 
$this->line_captions_x[$largest]['date'] && $line['edate'] <= 
$this->line_captions_x[0]['date'])
                                {
                                        $x2 = 0;
                                }
                                else
                                {
                                        $x2 = $largest * $linespace + 
$this->margin_left;
                                        $px = $line['f_sdate']?$x2:$px;
                                }

                                // progress

                                if ($line['progress'] >= 
$this->line_captions_x[$largest]['date'])
                                {
                                        if($this->debug)
                                        {
                                                echo 'PRO edate >= x edate! 
pro_edate = ' . $line['edate'] . '<br>';
                                                echo 'PRO edate >= x edate! 
pro_edate_formatted = ' . 
$GLOBALS['phpgw']->common->show_date($line['edate'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
 . '<br>';
                                                echo 'x edate: ' . 
$this->line_captions_x[$largest]['date'] . '<br>';
                                        }
                                        $gx = $this->graph_width - 
$this->margin_right;
                                }
                                else if($line['progress'] <= 
$this->line_captions_x[$largest]['date'] && $line['progress'] >= 
$this->line_captions_x[0]['date'])
                                {
                                        for($y=0;$y<$largest;$y++)
                                        {
                                                if($line['progress'] == 
$this->line_captions_x[$y]['date'])
                                                {
                                                        if($this->debug)
                                                        {
                                                                echo 'PRO edate 
== x edate! pro_edate = ' . $line['edate'] . '<br>';
                                                        }
                                                        $gx = $y * $linespace + 
$this->margin_left;
                                                }
                                                else if($line['progress'] >= 
$this->line_captions_x[$y]['date'] && $line['progress'] <= 
$this->line_captions_x[$y+1]['date'])
                                                {
                                                        $diff = 
($line['progress'] - $this->line_captions_x[$y]['date'])/86400;
                                                        if($this->debug)
                                                        {
                                                                echo 'PRO edate 
>= x edate! pro_edate = ' . $line['edate'] . '<br>';
                                                                echo 'diff: ' . 
($line['edate'] - $this->line_captions_x[$y]['date'])/86400 . '<br />';
                                                        }
                                                        $gx = $y * $linespace + 
$this->margin_left + (($linespace/$this->split_val)*$diff);
                                                }
                                        }
                                }
                                else if($line['progress'] >= 
$this->line_captions_x[$largest]['date'] && $line['progress'] >= 
$this->line_captions_x[0]['date'] ||
                                                $line['progress'] <= 
$this->line_captions_x[$largest]['date'] && $line['progress'] <= 
$this->line_captions_x[0]['date'])
                                {
                                        $gx = 0;
                                }
                                else
                                {
                                        $gx = $largest * $linespace + 
$this->margin_left;
                                }

                                if($x1 > 0 && $x2 > 0 && $y1 > 0 && $y2 > 0)
                                {
                                        /*for($w=-3;$w<4;$w++)
                                        {
                                                
$this->img->Line(1+$x1,$y1+$w,$x2,$y2+$w);
                                        }*/
                                        
$this->img->draw_rectangle(array($x1,$y1-5,$x2,$y2+5));
                                }

                                // progress
                                $this->img->SetColor(180, 180, 180);
                                if($x1 > 0 && $x2 > 0 && $gx > 0 && $y1 > 0 && 
$y2 > 0)
                                {
                                        
$this->img->draw_rectangle(array($x1,$y1-2,$gx,$y2+2));
                                }

                                //$color_index++;
                                $i++;

                                if(is_array($line['mstones']))
                                {
                                        foreach($line['mstones'] as $ms)
                                        {
                                                for($y=0;$y<$largest;$y++)
                                                {
                                                        if($ms['edate'] == 
$this->line_captions_x[$y]['date'])
                                                        {
                                                                if($this->debug)
                                                                {
                                                                        echo 
'PRO sdate == date! pro_sdate = ' . $line['sdate'] . ', date = ' . 
$this->line_captions_x[$y]['date'] . '<br>';
                                                                }
                                                                $mx1 = $y * 
$linespace + $this->margin_left;
                                                        }
                                                        else if($ms['edate'] >= 
$this->line_captions_x[$y]['date'] && $ms['edate'] <= 
$this->line_captions_x[$y+1]['date'])
                                                        {
                                                                $diff = 
($ms['edate'] - $this->line_captions_x[$y]['date'])/86400;
                                                                if($this->debug)
                                                                {
                                                                        echo 
'PRO sdate >= date! pro_sdate = ' . $line['sdate'] . ', date = ' . 
$this->line_captions_x[$y]['date'] . '<br>';
                                                                        echo 
'diff: ' . ($line['sdate'] - $this->line_captions_x[$y]['date'])/86400 . '<br 
/>';
                                                                }
                                                                $mx1 = $y * 
$linespace + $this->margin_left + (($linespace/$this->split_val)*$diff);
                                                        }
                                                }

                                                if($mx1>0)
                                                {
                                                        
$this->img->SetColorByName('yellow');

                                                        $mx2 = $mx1-5;
                                                        $mx3 = $mx1+5;
                                                        $my2 = $my3 = $y1-11;

                                                        
$this->img->draw_triangle(array($mx1,$y1,$mx2,$my2,$mx3,$my3));
                                                }
                                        }
                                }

                                if($line['previous'] > 0 && $px > 0 && $py > 0 
&& $x1 > 0 && $x2 > 0 && $y1 > 0 && $y2 > 0)
                                {
                                        $this->img->SetColor(0, 0, 0);

                                        for($w=-1;$w<1;$w++)
                                        {
                                                
$this->img->Line(1+$px,$py+$w,$x1,$y1+$w);
                                        }
                                }
                        }

                        // Draw the y axis text
                        $this->img->SetFont($this->line_font_size);
                        $linespace = ($this->graph_height - $this->margin_top - 
$this->margin_bottom) / ($this->num_lines_y - 1);
                        $space = 1;
                        foreach($this->data as $ytext)
                        {
                                if($ytext['extracolor'])
                                {
                                        
$this->img->SetColorByName($ytext['extracolor']);
                                }
                                else
                                {
                                        
$this->img->SetColorByName($this->colors[$ytext['color']]);
                                }

                                $y = $this->graph_height - $this->margin_bottom 
- ($space * $linespace);
                                $this->img->MoveTo(1,$y);

                                $strlen = $this->line_font_size==4?15:20;

                                if (strlen($ytext['title']) > $strlen)
                                {
                                        $ytext['title'] = 
substr($ytext['title'],0,$strlen) . '.';
                                }
                                $this->img->DrawText(array('text' => 
$ytext['title'],'justification' => 'left','margin_left' => $this->margin_left));
                                $space++;

                                if($ytext['use_map'] && $ytext['use_map'] != 
'unused')
                                {
                                        $this->img->SetColor(0,0,0);
                                        $map_start = 
(($this->img->GetFontWidth())*$strlen) + 10;
                                        $map = '';
                                        $map = array($map_start,$y + 
2,$map_start + 10,$y + 12);
                                        
$this->img->draw_rectangle($map,$ytext['use_map']);

                                        $gantt_map[] = array('project_id'       
=> $ytext['project_id'],
                                                                                
        'img_map'       => $map);
                                }
                        }
                        }

                        if(count($this->color_legend)>0)
                        {
                                // color legend
                                reset($this->color_legend);
                                $this->img->SetFont($this->title_font_size);
                                $this->img->SetColor(0, 0, 0);

                                $legend_start = $this->graph_height - 
$this->margin_bottom + 25 + $this->img->GetFontHeight();

                                $this->img->MoveTo($this->margin_left + 
(($this->img->GetFontWidth()*strlen($this->legend_title))/2), $legend_start);
                                $this->img->DrawText(array('text' => 
$this->legend_title));

                                $this->img->Line($this->margin_left - 4, 
$legend_start + $this->img->GetFontHeight(),$this->margin_left + 
($this->img->GetFontWidth()*strlen($this->legend_title)), $legend_start + 
$this->img->GetFontHeight());

                                $this->img->SetFont($this->line_font_size);
                                $linespace = ($this->margin_bottom - 
$this->legend_bottom) / (count($this->color_legend)+1);
                                $space = 1;

                                //_debug_array($this->color_legend);

                                foreach($this->color_legend as $legend)
                                {
                                        if($legend['extracolor'])
                                        {
                                                
$this->img->SetColorByName($legend['extracolor']);
                                        }
                                        else
                                        {
                                                
$this->img->SetColorByName($this->colors[$legend['color']]);
                                        }

                                        $y = $legend_start + ($space * 
$linespace);
                                        $this->img->MoveTo($this->margin_left + 
4,$y);
                                        $this->img->DrawText(array('text' => 
$legend['title'],'justification' => 'left','margin_left' => 
$this->margin_left));
                                        $space++;
                                }
                        }
                        $img_file = $this->img->save_img();
                        $this->img->Done();
                        return array('img_file' => $img_file,
                                                'img_map'       => $gantt_map);
                }

                function Open()
                {
                print('<script language="JavaScript">');
                print('window.open(\'main.php3?menuAction=boGraph.Show&');
                if (ereg('MSIE', $GLOBALS['HTTP_USER_AGENT']))
                        print('DCLINFO=' . $GLOBALS['DCLINFO'] . '&');
                print($this->ToURL() . '\', \'graph\', \'width=' . 
($this->graph_width + 20) . ',height=' . ($this->graph_height + 20) . 
',resizable=yes,scrollbars=yes\');');
                print('</script>');
        }

        function Show()
        {
                $this->FromURL();
                $this->Render();
        }

        function FromURL()
        {
                $this->title = $GLOBALS['title'];
                $this->caption_x = $GLOBALS['caption_x'];
                $this->caption_y = $GLOBALS['caption_y'];
                $this->num_lines_x = $GLOBALS['num_lines_x'];
                $this->num_lines_y = $GLOBALS['num_lines_y'];
                $this->line_captions_x = explode(',', 
$GLOBALS['line_captions_x']);

                $dataURL = explode('~', $GLOBALS['data']);
                $this->data = array();
                while (list($junk, $line) = each($dataURL))
                        $this->data[] = explode(',', $line);

                $this->colors = explode(',', $GLOBALS['colors']);
                $this->color_legend = explode(',', $GLOBALS['color_legend']);
                $this->graph_width = $GLOBALS['graph_width'];
                $this->graph_height = $GLOBALS['graph_height'];
                $this->margin_top = $GLOBALS['margin_top'];
                $this->margin_left = $GLOBALS['margin_left'];
                $this->margin_bottom = $GLOBALS['margin_bottom'];
                $this->margin_right = $GLOBALS['margin_right'];
        }

        function ToURL()
        {
                $url = 'title=' . rawurlencode($this->title) . '&';
                $url .= 'caption_x=' . rawurlencode($this->caption_x) . '&';
                $url .= 'caption_y=' . rawurlencode($this->caption_y) . '&';
                $url .= 'num_lines_x=' . $this->num_lines_x . '&';
                $url .= 'num_lines_y=' . $this->num_lines_y . '&';
                $url .= 'line_captions_x=' . rawurlencode(implode(',', 
$this->line_captions_x)) . '&';
                reset($this->data);
                $dataURL = '';
                while(list($junk, $line) = each($this->data))
                {
                        if ($dataURL != '')
                                $dataURL .= '~';
                        $dataURL .= implode(',', $line);
                }
                $url .= 'data=' . $dataURL . '&';
                $url .= 'colors=' . implode(',', $this->colors) . '&';
                $url .= 'color_legend=' . rawurlencode(implode(',', 
$this->color_legend)) . '&';
                $url .= 'graph_width=' . $this->graph_width . '&';
                $url .= 'graph_height=' . $this->graph_height . '&';
                $url .= 'margin_top=' . $this->margin_top . '&';
                $url .= 'margin_left=' . $this->margin_left . '&';
                $url .= 'margin_bottom=' . $this->margin_bottom . '&';
                $url .= 'margin_right=' . $this->margin_right;

                return $url;
        }
        }
?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]