[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/Potentials/ -> Charts.php (source)

   1  <?php
   2  /*********************************************************************************
   3   * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
   4   * ("License"); You may not use this file except in compliance with the
   5   * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
   6   * Software distributed under the License is distributed on an  "AS IS"  basis,
   7   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
   8   * the specific language governing rights and limitations under the License.
   9   * The Original Code is:  SugarCRM Open Source
  10   * The Initial Developer of the Original Code is SugarCRM, Inc.
  11   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12   * All Rights Reserved.
  13   * Contributor(s): ______________________________________.
  14   ********************************************************************************/
  15  /*********************************************************************************
  16   * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Potentials/Charts.php,v 1.12 2005/04/20 20:23:34 ray Exp $
  17   * Description:  Includes the functions for Customer module specific charts.
  18   ********************************************************************************/
  19  
  20  require_once ('config.php');
  21  require_once ('include/logging.php');
  22  require_once ('modules/Potentials/Potentials.php');
  23  require_once ('Image/Graph.php');
  24  require_once ('include/utils/utils.php');
  25  require_once ('include/utils/GraphUtils.php');
  26  
  27  
  28  
  29  
  30  class jpgraph {
  31      /**
  32       * Creates opportunity pipeline image as a horizontal accumlated bar graph for multiple vtiger_users.
  33       * param $datax- the month data to display in the x-axis
  34       * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
  35       * All Rights Reserved..
  36       * Contributor(s): ______________________________________..
  37       */
  38  	function outcome_by_month($date_start='1971-10-15', $date_end='2071-10-15', $user_id=array('1'), $cache_file_name='a_file', $refresh=false,$width=900,$height=500){
  39          global $log;
  40          $log->debug("Entering outcome_by_month(".$date_start.",". $date_end.",". $user_id.") method ...");
  41          global $app_strings,$lang_crm, $app_list_strings, $current_module_strings,$current_user, $log, $charset, $tmp_dir;
  42          global $theme;
  43          include_once  ('Image/Graph.php');
  44          include_once  ('Image/Canvas.php');
  45  
  46          $log =& LoggerManager::getLogger('outcome_by_month chart');
  47          // Set the basic parameters of the graph
  48          $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
  49          $imagemap = $canvas->getImageMap();
  50          $graph =& Image_Graph::factory('graph', $canvas);
  51          $log->debug("graph object created");
  52  
  53          // add a TrueType font
  54          $font =& $graph->addNew('font', calculate_font_name($lang_crm));
  55          // set the font size to 11 pixels
  56          $font->setSize(8);
  57          
  58          $graph->setFont($font);
  59          // create the plotarea layout
  60          $title =& Image_Graph::factory('title', array('Title',10));
  61          $plotarea =& Image_Graph::factory('plotarea',array(
  62                      'axis',
  63                      'axis'
  64                  ));
  65          $footer =& Image_Graph::factory('title', array('Footer',8));
  66          $graph->add(
  67              Image_Graph::vertical($title,
  68              Image_Graph::vertical(
  69                  $plotarea,
  70                  $footer,
  71                  90
  72                  ),
  73              5
  74              )
  75          );   
  76  
  77          //$graph->SetScale("textlin");
  78  
  79          if (!file_exists($cache_file_name) || !file_exists($cache_file_name.'.map') || $refresh == true) {
  80              //$font = calculate_font_family($lang_crm);
  81  
  82              $log->debug("date_start is: $date_start");
  83              $log->debug("date_end is: $date_end");
  84              $log->debug("user_id is: ");
  85              $log->debug($user_id);
  86              $log->debug("cache_file_name is: $cache_file_name");
  87  
  88              //build the where clause for the query that matches $user
  89              $where = "(";
  90              $first = true;
  91              $current = 0;
  92              foreach ($user_id as $the_id) {
  93                  if (!$first) $where .= "OR ";
  94                  $first = false;
  95                  $where .= "vtiger_crmentity.smcreatorid='$the_id' ";
  96              }
  97              $where .= ") ";
  98  
  99              //build the where clause for the query that matches $date_start and $date_end
 100              $where .= "AND closingdate >= '$date_start' AND closingdate <= '$date_end'";
 101              $subtitle = $current_module_strings['LBL_DATE_RANGE']." ".getDisplayDate($date_start)." ".$current_module_strings['LBL_DATE_RANGE_TO']." ".getDisplayDate($date_end)."\n";
 102  
 103              //Now do the db queries
 104              //query for opportunity data that matches $datay and $user
 105              $opp = new Potentials();
 106              $opp_list = $opp->get_full_list("amount DESC, closingdate DESC", $where);
 107  
 108              //build pipeline by sales stage data
 109              $total = 0;
 110              $count = array();
 111              $sum = array();
 112              $months = array();
 113              $other = $current_module_strings['LBL_LEAD_SOURCE_OTHER'];
 114              if (isset($opp_list)) {
 115                  foreach ($opp_list as $record) {
 116                      $month = substr_replace($record->column_fields['closingdate'],'',-3);
 117                      if (!in_array($month, $months)) { array_push($months, $month); }
 118                      if ($record->column_fields['sales_stage'] == 'Closed Won' || $record->column_fields['sales_stage'] == 'Closed Lost') {
 119                          $sales_stage=$record->column_fields['sales_stage'];
 120                      }
 121                      else {
 122                          $sales_stage=$other;
 123                      }
 124  
 125                      if (!isset($sum[$month][$sales_stage])) {
 126                          $sum[$month][$sales_stage] = 0;
 127                      }
 128                      if (isset($record->column_fields['amount']))    {
 129                          // Strip all non numbers from this string.
 130                          $amount = convertFromMasterCurrency(ereg_replace('[^0-9]', '', floor($record->column_fields['amount'])),$current_user->conv_rate);
 131                          $sum[$month][$sales_stage] = $sum[$month][$sales_stage] + $amount;
 132                          if (isset($count[$month][$sales_stage])) {
 133                              $count[$month][$sales_stage]++;
 134                          }
 135                          else {
 136                              $count[$month][$sales_stage] = 1;
 137                          }
 138                          $total = $total + ($amount/1000);
 139                      }
 140                  }
 141              }
 142  
 143              $legend = array();
 144              $datax = array();
 145              $aTargets = array();
 146              $aAlts = array();
 147              $stages = array($other, 'Closed Lost', 'Closed Won');
 148              //sort the months or push a bogus month on the array so that an empty chart is drawn
 149              if (empty($months)) {
 150                  array_push($months, date('Y-m',time()));
 151              }
 152              else{
 153                  sort($months);
 154              }
 155              foreach($months as $month) {
 156                foreach($stages as $stage) {
 157                  $log->debug("stage is $stage");
 158                  if (!isset($datax[$stage])) {
 159                      $datax[$stage] = array();
 160                  }
 161                  if (!isset($aAlts[$stage])) {
 162                      $aAlts[$stage] = array();
 163                  }
 164                  if (!isset($aTargets[$stage])) {
 165                      $aTargets[$stage] = array();
 166                  }
 167  
 168                  if (isset($sum[$month][$stage])) {
 169                      array_push($datax[$stage], $sum[$month][$stage]/1000);
 170                      array_push($aAlts[$stage], $count[$month][$stage]." ".$current_module_strings['LBL_OPPS_OUTCOME']." $stage");
 171                  }
 172                  else {
 173                      array_push($datax[$stage], 0);
 174                      array_push($aAlts[$stage], "");
 175                  }
 176                  array_push($aTargets[$stage], "index.php?module=Potentials&action=ListView&date_closed=$month&sales_stage=".urlencode($stage)."&query=true&type=dbrd");
 177                }
 178                  array_push($legend,$month);
 179              }
 180  
 181              $log->debug("datax is:");
 182              $log->debug($datax);
 183              $log->debug("aAlts is:");
 184              $log->debug($aAlts);
 185              $log->debug("aTargets is:");
 186              $log->debug($aTargets);
 187              $log->debug("sum is:");
 188              $log->debug($sum);
 189              $log->debug("count is:");
 190              $log->debug($count);
 191  
 192              //now build the bar plots for each user across the sales stages
 193              $color = array('Closed Lost'=>'#FF9900','Closed Won'=>'#009933', $other=>'#0066CC');
 194              $index = 0;
 195              $datasets = array();
 196              $xlabels = array();
 197              $fills =& Image_Graph::factory('Image_Graph_Fill_Array');
 198              foreach($stages as $stage) {
 199                  // Now create a bar plot
 200                  $datasets[$index] = & Image_Graph::factory('dataset');
 201                  foreach($datax[$stage] as $i => $y) {
 202                        $x = 1+2*$i;
 203                      $datasets[$index]->addPoint(
 204                          $x,
 205                          $y,
 206                          array(
 207                              'url' => $aTargets[$stage][$i],
 208                              'alt' => $aAlts[$stage][$i]
 209                          )
 210                      );
 211                  }
 212  
 213                  // Set fill colors for bars
 214                  $fills->addColor($color[$stage]);
 215  
 216                  $index++;
 217              }
 218              for($i=0;$i<count($months); $i++)
 219              {
 220                $x = 1+2*$i;
 221                $xlabels[$x] = $months[$i];
 222                $xlabels[$x+1] = '';
 223              }
 224              
 225              // compute maximum value because of grace jpGraph parameter not supported
 226              $maximum = 0;
 227              foreach($months as $num=>$m) {
 228                    $monthSum = 0;
 229                    foreach($stages as $stage) $monthSum += $datax[$stage][$num];
 230                  if($monthSum > $maximum) $maximum = $monthSum;
 231                  $log->debug('maximum = '.$maximum.' month = '.$m.' sum = '.$monthSum);
 232              }
 233  
 234              if($theme == "blue")
 235              {
 236                  $font_color = "#212473";
 237              }
 238              else
 239              {
 240                  $font_color = "#000000";
 241              }
 242              $font->setColor($font_color);
 243  
 244              // Create the grouped bar plot
 245              $gbplot = & $plotarea->addNew('bar', array($datasets, 'stacked'));
 246              $gbplot->setFillStyle($fills);
 247  
 248              //You can change the width of the bars if you like
 249              $gbplot->setBarWidth(50/count($months),"%");
 250  
 251              // set margin
 252              $plotarea->setPadding(array('top'=>0,'bottom'=>0,'left'=>10,'right'=>20));
 253  
 254              // Set white margin color
 255              $graph->setBackgroundColor('#F5F5F5');
 256  
 257              // Use a box around the plot area
 258              $gbplot->setBorderColor('black');
 259  
 260              // Use a gradient to fill the plot area
 261              $gbplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', '#E5E5E5')));
 262  
 263              // Setup title
 264              $titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total.$app_strings['LBL_THOUSANDS_SYMBOL'];
 265                  //$titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total;
 266              
 267              $title->setText($titlestr);
 268  
 269              // Create the xaxis labels
 270              $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', 
 271                  array($xlabels) 
 272              ); 
 273  
 274              // Setup X-axis
 275              $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
 276              $xaxis->setDataPreprocessor($array_data);
 277              $xaxis->forceMinimum(0);
 278              $xaxis->forceMaximum(2*count($months));
 279              $xaxis->setLabelInterval(1);
 280              $xaxis->setTickOptions(0,0);
 281              $xaxis->setLabelInterval(2,2);
 282              $xaxis->setTickOptions(5,0,2);
 283  
 284              // set grid
 285              $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y);
 286              $gridY->setLineColor('#E5E5E5@0.5');
 287  
 288  
 289              // Add some grace to y-axis so the bars doesn't go
 290              // all the way to the end of the plot area
 291              $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
 292              $yaxis->forceMaximum($maximum * 1.1);
 293              $ticks = get_tickspacing($maximum);
 294  
 295              // Setup the Y-axis to be displayed in the bottom of the
 296              // graph. We also finetune the exact layout of the title,
 297              // ticks and labels to make them look nice.
 298              $yaxis->setAxisIntersection('max');
 299  
 300              // Then fix the tick marks
 301              $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol."%d");
 302              $yaxis->setFontSize(8);
 303              $yaxis->setDataPreprocessor($valueproc);
 304              // Arrange Y-Axis tick marks inside
 305              $yaxis->setLabelInterval($ticks[0]);
 306              $yaxis->setTickOptions(-5,0);
 307              $yaxis->setLabelInterval($ticks[1],2);
 308              $yaxis->setTickOptions(-2,0,2);
 309              $yaxis->setLabelOption('position','inside');
 310  
 311              // Finally setup the title
 312              $yaxis->setLabelOption('position','inside');
 313              
 314              // eliminate zero values
 315              $gbplot->setDataSelector(Image_Graph::factory('Image_Graph_DataSelector_NoZeros'));
 316              
 317              // set markers
 318              $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
 319              $marker->setDataPreprocessor($valueproc);
 320              $marker->setFillColor('000000@0.0');
 321              $marker->setBorderColor('000000@0.0');
 322              $marker->setFontColor('white');
 323              $marker->setFontSize(8);
 324              $gbplot->setMarker($marker);
 325  
 326              $subtitle .= $current_module_strings['LBL_OPP_SIZE'].$current_user->currency_symbol.$current_module_strings['LBL_OPP_SIZE_VALUE'];
 327              $footer->setText($subtitle);
 328              $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_RIGHT);
 329  
 330              // .. and stroke the graph
 331              $imgMap = $graph->done(
 332                                      array(
 333                                              'tohtml' => true,
 334                                              'border' => 0,
 335                                              'filename' => $cache_file_name,
 336                                              'filepath' => './',
 337                                              'urlpath' => ''
 338                                          ));
 339              //$imgMap = htmlspecialchars($output);
 340              save_image_map($cache_file_name.'.map', $imgMap);
 341          }
 342          else {
 343              $imgMap_fp = fopen($cache_file_name.'.map', "rb");
 344              $imgMap = fread($imgMap_fp, filesize($cache_file_name.'.map'));
 345              fclose($imgMap_fp);
 346          }
 347          $fileModTime = filemtime($cache_file_name.'.map');
 348          $return = "\n$imgMap";
 349          $log->debug("Exiting outcome_by_month method ...");
 350          return $return;
 351      }
 352  
 353      /**
 354       * Creates lead_source_by_outcome pipeline image as a horizontal accumlated bar graph for multiple vtiger_users.
 355       * param $datay- the lead source data to display in the x-axis
 356       * param $date_start- the begin date of opps to find
 357       * param $date_end- the end date of opps to find
 358       * param $ids - list of assigned vtiger_users of opps to find
 359       * param $cache_file_name - file name to write image to
 360       * param $refresh - boolean whether to rebuild image if exists
 361       * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
 362       * All Rights Reserved..
 363       * Contributor(s): ______________________________________..
 364       */
 365  	function lead_source_by_outcome($datay=array('foo','bar'), $user_id=array('1'), $cache_file_name='a_file', $refresh=false,$width=900,$height=500){
 366          global $log,$current_user;
 367          $log->debug("Entering lead_source_by_outcome(".$datay.",".$user_id.",".$cache_file_name.",".$refresh.") method ...");
 368          global $app_strings,$lang_crm, $current_module_strings,$charset, $tmp_dir;
 369          global $theme;
 370  
 371          include_once  ('Image/Graph.php');
 372          include_once  ('Image/Canvas.php');
 373  
 374          $log =& LoggerManager::getLogger('lead_source_by_outcome chart');
 375          // Set the basic parameters of the graph
 376          $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
 377          $imagemap = $canvas->getImageMap();
 378          $graph =& Image_Graph::factory('graph', $canvas);
 379          $log->debug("graph object created");
 380          // add a TrueType font
 381          $font =& $graph->addNew('font', calculate_font_name($lang_crm));
 382          // set the font size to 11 pixels
 383          $font->setSize(8);
 384          
 385          $graph->setFont($font);
 386          // create the plotarea layout
 387          $title =& Image_Graph::factory('title', array('Test',10));
 388          $plotarea =& Image_Graph::factory('plotarea',array(
 389                      'axis',
 390                      'axis',
 391                      'horizontal'
 392                  ));
 393          $footer =& Image_Graph::factory('title', array('Footer',8));
 394          $graph->add(
 395              Image_Graph::vertical($title,
 396              Image_Graph::vertical(
 397                  $plotarea,
 398                  $footer,
 399                  90
 400                  ),
 401              5
 402              )
 403          );   
 404  
 405          if (!file_exists($cache_file_name) || !file_exists($cache_file_name.'.map') || $refresh == true) {
 406  
 407              $log->debug("datay is:");
 408              $log->debug($datay);
 409              $log->debug("user_id is: ");
 410              $log->debug($user_id);
 411              $log->debug("cache_file_name is: $cache_file_name");
 412  
 413              $where="";
 414              //build the where clause for the query that matches $user
 415              $count = count($user_id);
 416              if ($count>0) {
 417                  $where = "(";
 418                  $first = true;
 419                  $current = 0;
 420                  foreach ($user_id as $the_id) {
 421                      if (!$first) $where .= "OR ";
 422                      $first = false;
 423                      $where .= "vtiger_crmentity.smcreatorid='$the_id' ";
 424                  }
 425                  $where .= ") ";
 426              }
 427  
 428              //build the where clause for the query that matches $datay
 429              $count = count($datay);
 430              if ($count>0) {
 431                  $where .= "AND ( ";
 432                  unset($first);
 433                  $first = true;
 434                  foreach ($datay as $key=>$value) {
 435                      if (!$first) $where .= "OR ";
 436                      $first = false;
 437                      $where .= "leadsource ='$key' ";
 438                  }
 439                  $where .= ")";
 440              }
 441  
 442              //Now do the db queries
 443              //query for opportunity data that matches $datay and $user
 444              $opp = new Potentials();
 445              $opp_list = $opp->get_full_list("amount DESC, closingdate DESC", $where);
 446  
 447              //build pipeline by sales stage data
 448              $total = 0;
 449              $count = array();
 450              $sum = array();
 451              $other = $current_module_strings['LBL_LEAD_SOURCE_OTHER'];
 452              if (isset($opp_list)) {
 453                  foreach ($opp_list as $record) {
 454                      //if lead source is blank, set it to the language's "none" value
 455                      if (isset($record->column_fields['leadsource']) && $record->column_fields['leadsource'] != '') {
 456                          $lead_source = $record->column_fields['leadsource'];
 457                      }
 458                      else {
 459                          $lead_source = $current_module_strings['NTC_NO_LEGENDS'];
 460                      }
 461  
 462                      if ($record->column_fields['sales_stage'] == 'Closed Won' || $record->column_fields['sales_stage'] == 'Closed Lost') {
 463                          $sales_stage=$record->column_fields['sales_stage'];
 464                      }
 465                      else {
 466                          $sales_stage=$other;
 467                      }
 468  
 469                      if (!isset($sum[$lead_source][$sales_stage])) {
 470                          $sum[$lead_source][$sales_stage] = 0;
 471                      }
 472                      if (isset($record->column_fields['amount']))    {
 473                          // Strip all non numbers from this string.
 474                          $amount = convertFromMasterCurrency(ereg_replace('[^0-9]', '', floor($record->column_fields['amount'])),$current_user->conv_rate);
 475                          $sum[$lead_source][$sales_stage] = $sum[$lead_source][$sales_stage] + $amount;
 476                          if (isset($count[$lead_source][$sales_stage])) {
 477                              $count[$lead_source][$sales_stage]++;
 478                          }
 479                          else {
 480                              $count[$lead_source][$sales_stage] = 1;
 481                          }
 482                          $total = $total + ($amount/1000);
 483                      }
 484                  }
 485              }
 486  
 487              $legend = array();
 488              $datax = array();
 489              $aTargets = array();
 490              $aAlts = array();
 491              $stages = array($other,'Closed Lost', 'Closed Won');
 492              foreach($datay as $lead=>$translation) {
 493                if ($lead == '') {
 494                      $lead = $current_module_strings['NTC_NO_LEGENDS'];
 495                      $translation = $current_module_strings['NTC_NO_LEGENDS'];
 496                }
 497                foreach($stages as $stage) {
 498                  $log->debug("stage_key is $stage");
 499                  if (!isset($datax[$stage])) {
 500                      $datax[$stage] = array();
 501                  }
 502                  if (!isset($aAlts[$stage])) {
 503                      $aAlts[$stage] = array();
 504                  }
 505                  if (!isset($aTargets[$stage])) {
 506                      $aTargets[$stage] = array();
 507                  }
 508  
 509                  if (isset($sum[$lead][$stage])) {
 510                      array_push($datax[$stage], $sum[$lead][$stage]/1000);
 511                      array_push($aAlts[$stage], $count[$lead][$stage]." ".$current_module_strings['LBL_OPPS_OUTCOME']." $stage");
 512                  }
 513                  else {
 514                      array_push($datax[$stage], 0);
 515                      array_push($aAlts[$stage], "");
 516                  }
 517                  array_push($aTargets[$stage], "index.php?module=Potentials&action=ListView&leadsource=".urlencode($lead)."&sales_stage=".urlencode($stage)."&query=true&type=dbrd");
 518                }
 519                array_push($legend,$translation);
 520              }
 521  
 522              $log->debug("datax is:");
 523              $log->debug($datax);
 524              $log->debug("aAlts is:");
 525              $log->debug($aAlts);
 526              $log->debug("aTargets is:");
 527              $log->debug($aTargets);
 528              $log->debug("sum is:");
 529              $log->debug($sum);
 530              $log->debug("count is:");
 531              $log->debug($count);
 532  
 533              //now build the bar plots for each user across the sales stages
 534              $color = array('Closed Lost'=>'FF9900','Closed Won'=>'009933', $other=>'0066CC');
 535              $index = 0;
 536              $xlabels = array();
 537              $datasets = array();
 538              $fills =& Image_Graph::factory('Image_Graph_Fill_Array');
 539              foreach($stages as $stage) {
 540                  // Now create a bar pot
 541                  $datasets[$index] = & Image_Graph::factory('dataset');
 542                  foreach($datax[$stage] as $i => $y) {
 543                        $x = 1+2*$i;
 544                      $datasets[$index]->addPoint(
 545                          //$datay[$legend[$x]],
 546                          $x,
 547                          $y,
 548                          array(
 549                              'url' => $aTargets[$stage][$i],
 550                              'alt' => $aAlts[$stage][$i],
 551                              'target' => ''
 552                          )
 553                      );
 554                  }
 555              for($i=0;$i<count($legend); $i++)
 556              {
 557                $x = 1+2*$i;
 558                $xlabels[$x] = $legend[$i];
 559                $xlabels[$x+1] = '';
 560              }
 561  
 562                  // Set fill colors for bars
 563                  $fills->addColor("#".$color[$stage]);
 564  
 565                  $log->debug("datax[$stage] is: ");
 566                  $log->debug($datax[$stage]);
 567                  $index++;
 568              }
 569              
 570              // compute maximum value because of grace jpGraph parameter not supported
 571              $maximum = 0;
 572              foreach($legend as $legendidx=>$legend_text) {
 573                    $dataxSum = 0;
 574                  foreach($stages as $stage) $dataxSum += $datax[$stage][$legendidx];
 575                  if($dataxSum > $maximum) $maximum = $dataxSum;
 576              }
 577  
 578              if($theme == "blue")
 579              {
 580                  $font_color = "#212473";
 581              }
 582              else
 583              {
 584                  $font_color = "#000000";
 585              }
 586              $font->setColor($font_color);
 587  
 588              // Create the grouped bar plot
 589              $gbplot = & $plotarea->addNew('bar', array($datasets, 'stacked'));
 590              $gbplot->setFillStyle($fills);
 591  
 592              //You can change the width of the bars if you like
 593              $gbplot->setBarWidth(50/count($legend),"%");
 594  
 595              // Set white margin color
 596              $graph->setBackgroundColor('#F5F5F5');
 597  
 598              // Use a box around the plot area
 599              $gbplot->setBorderColor('black');
 600  
 601              // Use a gradient to fill the plot area
 602              $gbplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', '#E5E5E5')));
 603  
 604              // Setup title
 605              $titlestr = $current_module_strings['LBL_ALL_OPPORTUNITIES'].$current_user->currency_symbol.$total.$app_strings['LBL_THOUSANDS_SYMBOL'];
 606              //$titlestr = $current_module_strings['LBL_ALL_OPPORTUNITIES'].$current_user->currency_symbol.$total;
 607              $title->setText($titlestr);
 608  
 609              // Create the xaxis labels
 610              $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', 
 611                  array($xlabels) 
 612              ); 
 613  
 614              // Setup X-axis
 615              $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
 616              $xaxis->setDataPreprocessor($array_data);
 617              $xaxis->forceMinimum(0);
 618              $xaxis->forceMaximum(2*count($legend));
 619              $xaxis->setLabelInterval(1);
 620              $xaxis->setTickOptions(0,0);
 621              $xaxis->setLabelInterval(2,2);
 622              $xaxis->setTickOptions(5,0,2);
 623              $xaxis->setInverted(true);
 624              
 625              // set grid
 626              $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y);
 627              $gridY->setLineColor('#E5E5E5@0.5');
 628  
 629              // Add some grace to y-axis so the bars doesn't go
 630              // all the way to the end of the plot area
 631              $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
 632              $yaxis->forceMaximum($maximum * 1.1);
 633              $ticks = get_tickspacing($maximum);
 634  
 635              // Then fix the tick marks
 636              $yaxis->setFontSize(8);
 637              $yaxis->setAxisIntersection('max');
 638              $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol."%d");
 639              $yaxis->setDataPreprocessor($valueproc);
 640              $yaxis->setLabelInterval($ticks[0]);
 641              $yaxis->setTickOptions(-5,0);
 642              $yaxis->setLabelInterval($ticks[1],2);
 643              $yaxis->setTickOptions(-2,0,2);
 644              
 645              // eliminate zero values
 646              $gbplot->setDataSelector(Image_Graph::factory('Image_Graph_DataSelector_NoZeros'));
 647              
 648              // set markers
 649              $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
 650              $marker->setDataPreprocessor($valueproc);
 651              $marker->setFillColor('#000000@0.0');
 652              $marker->setBorderColor('#000000@0.0');
 653              $marker->setFontColor('white');
 654              $marker->setFontSize(8);
 655              $gbplot->setMarker($marker);
 656  
 657              // Finally setup the title
 658              $subtitle = $current_module_strings['LBL_OPP_SIZE'].$current_user->currency_symbol.$current_module_strings['LBL_OPP_SIZE_VALUE']; 
 659              $footer->setText($subtitle);
 660              $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_RIGHT);
 661  
 662              // .. and stroke the graph
 663              $imgMap = $graph->done(
 664                                      array(
 665                                              'tohtml' => true,
 666                                              'border' => 0,
 667                                              'filename' => $cache_file_name,
 668                                              'filepath' => './',
 669                                              'urlpath' => ''
 670                                          ));
 671              //$imgMap = htmlspecialchars($output);
 672              save_image_map($cache_file_name.'.map', $imgMap);
 673          }
 674          else {
 675              $imgMap_fp = fopen($cache_file_name.'.map', "rb");
 676              $imgMap = fread($imgMap_fp, filesize($cache_file_name.'.map'));
 677              fclose($imgMap_fp);
 678          }
 679          $fileModTime = filemtime($cache_file_name.'.map');
 680          $return = "\n$imgMap";
 681          $log->debug("Exiting lead_source_by_outcome method ...");
 682          return $return;
 683      }
 684  
 685      /**
 686       * Creates opportunity pipeline image as a horizontal accumlated bar graph for multiple vtiger_users.
 687       * param $datax- the sales stage data to display in the x-axis
 688       * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
 689       * All Rights Reserved..
 690       * Contributor(s): ______________________________________..
 691       */
 692  	function pipeline_by_sales_stage($datax=array('foo','bar'), $date_start='2071-10-15', $date_end='2071-10-15', $user_id=array('1'), $cache_file_name='a_file', $refresh=false,$width=900,$height=500){
 693          global $log,$current_user;
 694          $log->debug("Entering pipeline_by_sales_stage(".$datax.",".$date_start.",".$date_end.",".$user_id.",".$cache_file_name.",".$refresh.") method ...");
 695          global $app_strings,$lang_crm, $current_module_strings, $charset, $tmp_dir;
 696          global $theme;
 697          include_once  ('Image/Graph.php');
 698          include_once  ('Image/Canvas.php');
 699  
 700          $log =& LoggerManager::getLogger('opportunity charts');
 701          // Set the basic parameters of the graph
 702  
 703          
 704          $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
 705          $imagemap = $canvas->getImageMap();
 706          $graph =& Image_Graph::factory('graph', $canvas);
 707          //$log->debug("graph object created");
 708          // add a TrueType font
 709          //$font =& $graph->addNew('font', calculate_font_name($lang_crm));
 710          $font =& $graph->addNew('font', calculate_font_name($lang_crm));
 711          // set the font size to 11 pixels
 712          $font->setSize(8);
 713          
 714          $graph->setFont($font);
 715          $title =& Image_Graph::factory('title', array('Test',10));
 716          $plotarea =& Image_Graph::factory('plotarea',array(
 717                      'axis',
 718                      'axis',
 719                      'horizontal'
 720                  ));
 721          $footer =& Image_Graph::factory('title', array('Footer',8));
 722          $graph->add(
 723              Image_Graph::vertical($title,
 724              Image_Graph::vertical(
 725                  $plotarea,
 726                  $footer,
 727                  90
 728                  ),
 729              5
 730              )
 731          );   
 732          $log->debug("graph object created");
 733          
 734  
 735          if (!file_exists($cache_file_name) || !file_exists($cache_file_name.'.map') || $refresh == true) {
 736  
 737              $log->debug("starting pipeline chart");
 738              $log->debug("datax is:");
 739              $log->debug($datax);
 740              $log->debug("user_id is: ");
 741              $log->debug($user_id);
 742              $log->debug("cache_file_name is: $cache_file_name");
 743  
 744              $where="";
 745              //build the where clause for the query that matches $user
 746              $count = count($user_id);
 747              if ($count>0) {
 748                  $where = "(";
 749                  $first = true;
 750                  $current = 0;
 751                  foreach ($user_id as $the_id) {
 752                      if (!$first) $where .= "OR ";
 753                      $first = false;
 754                      //reference post
 755                      //if I change the owner of a opportunity, the graph shown on Home does not update correctly, this is because the graph is looking for the creatorid and not for the ownerid
 756                      //fix incorporated based on /sak's feedback
 757                      $where .= "vtiger_crmentity.smownerid='$the_id' ";
 758                  }
 759                  $where .= ") ";
 760              }
 761  
 762              //build the where clause for the query that matches $datax
 763              $count = count($datax);
 764              if ($count>0) {
 765                  $where .= "AND ( ";
 766                  unset($first);
 767                  $first = true;
 768                  foreach ($datax as $key=>$value) {
 769                      if (!$first) $where .= "OR ";
 770                      $first = false;
 771                      $where .= "sales_stage ='$key' ";
 772                  }
 773                  $where .= ")";
 774              }
 775  
 776              //build the where clause for the query that matches $date_start and $date_end
 777              $where .= "AND closingdate >= '$date_start' AND closingdate <= '$date_end'";
 778              $subtitle = $current_module_strings['LBL_DATE_RANGE']." ".getDisplayDate($date_start)." ".$current_module_strings['LBL_DATE_RANGE_TO']." ".getDisplayDate($date_end)."\n";
 779  
 780              //Now do the db queries
 781              //query for opportunity data that matches $datax and $user
 782              $opp = new Potentials();
 783              $opp_list = $opp->get_full_list("amount DESC, closingdate DESC", $where);
 784  
 785              //build pipeline by sales stage data
 786              $total = 0;
 787              $count = array();
 788              $sum = array();
 789              if (isset($opp_list)) {
 790                  foreach ($opp_list as $record) {
 791                      if (!isset($sum[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']])) {
 792                          $sum[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']] = 0;
 793                      }
 794                      if (isset($record->column_fields['amount']))    {
 795                          // Strip all non numbers from this string.
 796                          $amount = convertFromMasterCurrency(ereg_replace('[^0-9]', '', floor($record->column_fields['amount'])),$current_user->conv_rate);
 797                          $sum[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']] = $sum[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']] + $amount;
 798                          if (isset($count[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']])) {
 799                              $count[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']]++;
 800                          }
 801                          else {
 802                              $count[$record->column_fields['sales_stage']][$record->column_fields['assigned_user_id']] = 1;
 803                          }
 804                          $total = $total + ($amount/1000);
 805                      }
 806                  }
 807              }
 808  
 809              $legend = array();
 810              $datay = array();
 811              $aTargets = array();
 812              $aAlts = array();
 813              foreach ($datax as $stage_key=>$stage_translation) {
 814                foreach ($user_id as $the_id) {
 815                    $the_user = get_assigned_user_name($the_id);
 816                  if (!isset($datay[$the_id])) {
 817                      $datay[$the_id] = array();
 818                  }
 819                  if (!isset($aAlts[$the_id])) {
 820                      $aAlts[$the_id] = array();
 821                  }
 822                  if (!isset($aTargets[$the_id])) {
 823                      $aTargets[$the_id] = array();
 824                  }
 825  
 826                  if (isset($sum[$stage_key][$the_id])) {
 827                      array_push($datay[$the_id], $sum[$stage_key][$the_id]/1000);
 828                      array_push($aAlts[$the_id], $the_user.' - '.$count[$stage_key][$the_id]." ".$current_module_strings['LBL_OPPS_IN_STAGE']." $stage_translation");
 829                  }
 830                  else {
 831                      array_push($datay[$the_id], 0);
 832                      array_push($aAlts[$the_id], "");
 833                  }
 834                  array_push($aTargets[$the_id], "index.php?module=Potentials&action=ListView&assigned_user_id=$the_id&sales_stage=".urlencode($stage_key)."&closingdate_start=".urlencode($date_start)."&closingdate_end=".urlencode($date_end)."&query=true&type=dbrd");
 835                }
 836                array_push($legend,$stage_translation);
 837              }
 838  
 839              $log->debug("datay is:");
 840              $log->debug($datay);
 841              $log->debug("aAlts is:");
 842              $log->debug($aAlts);
 843              $log->debug("aTargets is:");
 844              $log->debug($aTargets);
 845              $log->debug("sum is:");
 846              $log->debug($sum);
 847              $log->debug("count is:");
 848              $log->debug($count);
 849  
 850              //now build the bar plots for each user across the sales stages
 851              $colors = color_generator(count($user_id),'#D50100','#002222');
 852              $index = 0;
 853              $datasets = array();
 854              $xlabels = array();
 855              $fills =& Image_Graph::factory('Image_Graph_Fill_Array');
 856              foreach($user_id as $the_id) {
 857                  // Now create a bar pot
 858                  $datasets[$index] = & Image_Graph::factory('dataset');
 859                  foreach($datay[$the_id] as $i => $y) {
 860                      $x = 1+2*$i;
 861                      $datasets[$index]->addPoint(
 862                          $x,
 863                          $y,
 864                          array(
 865                              'url' => $aTargets[$the_id][$i],
 866                              'alt' => $aAlts[$the_id][$i]
 867                          )
 868                      );
 869                  }
 870  
 871                  // Set fill colors for bars
 872                  $fills->addColor($colors[$index]);
 873  
 874                  $index++;
 875              }
 876              for($i=0;$i<count($legend); $i++)
 877              {
 878                $x = 1+2*$i;
 879                $xlabels[$x] = $legend[$i];
 880                $xlabels[$x+1] = '';
 881              }
 882              
 883              // compute maximum value because of grace jpGraph parameter not supported
 884              $maximum = 0;
 885              foreach($legend as $legendidx=>$legend_text) {
 886                    $legendsum = 0;
 887                  foreach($user_id as $the_id) $legendsum += $datay[$the_id][$legendidx];
 888                  if($legendsum > $maximum) $maximum = $legendsum;
 889              }
 890              // Create the grouped bar plot
 891              $gbplot = & $plotarea->addNew('bar', array($datasets, 'stacked'));
 892              $gbplot->setFillStyle($fills);
 893  
 894              //You can change the width of the bars if you like
 895              $gbplot->setBarWidth(50/count($legend),"%");
 896  
 897  
 898              // Set white margin color
 899              $graph->setBackgroundColor('#F5F5F5');
 900  
 901              // Use a box around the plot area
 902              $gbplot->setBorderColor('black');
 903  
 904              // Use a gradient to fill the plot area
 905              $gbplot->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_HORIZONTAL, 'white', '#E5E5E5')));
 906  
 907              if($theme == "blue")
 908              {
 909                  $font_color = "#212473";
 910              }
 911              else
 912              {
 913                  $font_color = "#000000";
 914              }
 915              $font->setColor($font_color);
 916  
 917              // Setup title
 918              $titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total.$app_strings['LBL_THOUSANDS_SYMBOL'];
 919              //$titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total;
 920              $title->setText($titlestr);
 921  
 922              // Create the xaxis labels
 923              $array_data =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array', 
 924                  array($xlabels) 
 925              ); 
 926  
 927          
 928              // Setup X-axis
 929              $xaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
 930              $xaxis->setDataPreprocessor($array_data);
 931              $xaxis->forceMinimum(0);
 932              $xaxis->forceMaximum(2*count($legend));
 933              $xaxis->setLabelInterval(1);
 934              $xaxis->setTickOptions(0,0);
 935              $xaxis->setLabelInterval(2,2);
 936              $xaxis->setTickOptions(5,0,2);
 937              $xaxis->setInverted(true);
 938  
 939              // Setup Y-axis
 940              $yaxis =& $plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
 941              $yaxis->setFontSize(8);
 942              $yaxis->setAxisIntersection('max');
 943  
 944              // Add some grace to y-axis so the bars doesn't go
 945              // all the way to the end of the plot area
 946              $yaxis->forceMaximum($maximum * 1.1);
 947              $ticks = get_tickspacing($maximum);
 948              
 949              // set grid
 950              $gridY =& $plotarea->addNew('line_grid', IMAGE_GRAPH_AXIS_Y);
 951              $gridY->setLineColor('#E5E5E5@0.5');
 952  
 953              // First make the labels look right
 954              $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol."%d");
 955              $yaxis->setDataPreprocessor($valueproc);
 956              $yaxis->setLabelInterval($ticks[0]);
 957              $yaxis->setTickOptions(-5,0);
 958              $yaxis->setLabelInterval($ticks[1],2);
 959              $yaxis->setTickOptions(-2,0,2);
 960              
 961              // eliminate zero values
 962              $gbplot->setDataSelector(Image_Graph::factory('Image_Graph_DataSelector_NoZeros'));
 963              
 964              // set markers
 965              $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
 966              $marker->setDataPreprocessor($valueproc);
 967              $marker->setFillColor('000000@0.0');
 968              $marker->setBorderColor('000000@0.0');
 969              $marker->setFontColor('white');
 970              $marker->setFontSize(8);
 971              $gbplot->setMarker($marker);
 972  
 973              // Finally setup the title
 974  
 975              $subtitle .= $current_module_strings['LBL_OPP_SIZE'].$current_user->currency_symbol.$current_module_strings['LBL_OPP_SIZE_VALUE']; 
 976              $footer->setText($subtitle);
 977              $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_RIGHT);
 978  
 979              // .. and stroke the graph
 980              $imgMap = $graph->done(
 981                                      array(
 982                                              'tohtml' => true,
 983                                              'border' => 0,
 984                                              'filename' => $cache_file_name,
 985                                              'filepath' => './',
 986                                              'urlpath' => ''
 987                                          ));
 988              //$imgMap = $graph->GetHTMLImageMap('pipeline');
 989              save_image_map($cache_file_name.'.map', $imgMap);
 990          }
 991          else {
 992              $imgMap_fp = fopen($cache_file_name.'.map', "rb");
 993              $imgMap = fread($imgMap_fp, filesize($cache_file_name.'.map'));
 994              fclose($imgMap_fp);
 995          }
 996          $fileModTime = filemtime($cache_file_name.'.map');
 997          $return = "\n$imgMap";
 998          $log->debug("Exiting pipeline_by_sales_stage method ...");
 999          return $return;
1000      }
1001  
1002      /**
1003       * Creates pie chart image of opportunities by lead_source.
1004       * param $datax- the sales stage data to display in the x-axis
1005       * param $datay- the sum of opportunity amounts for each opportunity in each sales stage
1006       * to display in the y-axis
1007       * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
1008       * All Rights Reserved..
1009       * Contributor(s): ______________________________________..
1010       */
1011  	function pipeline_by_lead_source($legends=array('foo','bar'), $user_id=array('1'), $cache_file_name='a_file', $refresh=true,$width=900,$height=500){
1012          global $log,$current_user;
1013          $log->debug("Entering pipeline_by_lead_source(".$legends.") method ...");
1014          global $app_strings,$lang_crm, $current_module_strings, $log, $charset, $tmp_dir;
1015          global $theme;
1016  
1017          include_once  ('Image/Graph.php');
1018          include_once  ('Image/Canvas.php');
1019  
1020          $font = calculate_font_name($lang_crm);
1021  
1022          if (!file_exists($cache_file_name) || !file_exists($cache_file_name.'.map') || $refresh == true) {
1023              $log =& LoggerManager::getLogger('opportunity charts');
1024              $log->debug("starting pipeline chart");
1025              $log->debug("legends is:");
1026              $log->debug($legends);
1027              $log->debug("user_id is: ");
1028              $log->debug($user_id);
1029              $log->debug("cache_file_name is: $cache_file_name");
1030  
1031              //Now do the db queries
1032              //query for opportunity data that matches $legends and $user
1033              $where="";
1034              //build the where clause for the query that matches $user
1035              $count = count($user_id);
1036              if ($count>0) {
1037                  $where = "(";
1038                  $first = true;
1039                  foreach ($user_id as $the_id) {
1040                      if (!$first) $where .= "OR ";
1041                      $first = false;
1042                      $where .= "vtiger_crmentity.smcreatorid='$the_id' ";
1043                  }
1044                  $where .= ") ";
1045              }
1046  
1047              //build the where clause for the query that matches $datax
1048              $count = count($legends);
1049              if ($count>0) {
1050                  $where .= "AND ( ";
1051                  $first = true;
1052                  foreach ($legends as $key=>$value) {
1053                      if (!$first) $where .= "OR ";
1054                      $first = false;
1055                      $where .= "leadsource    ='$key' ";
1056                  }
1057                  $where .= ")";
1058              }
1059  
1060              $opp = new Potentials();
1061              $opp_list = $opp->get_full_list("amount DESC, closingdate DESC", $where);
1062  
1063              //build pipeline by lead source data
1064              $total = 0;
1065              $count = array();
1066              $sum = array();
1067              if (isset($opp_list)) {
1068                  foreach ($opp_list as $record) {
1069                      if (!isset($sum[$record->column_fields['leadsource']])) $sum[$record->column_fields['leadsource']] = 0;
1070                      if (isset($record->column_fields['amount']) && isset($record->column_fields['leadsource']))    {
1071                          // Strip all non numbers from this string.
1072                          $amount = convertFromMasterCurrency(ereg_replace('[^0-9]', '', floor($record->column_fields['amount'])),$current_user->conv_rate);
1073                          $sum[$record->column_fields['leadsource']] = $sum[$record->column_fields['leadsource']] + ($amount/1000);
1074                          if (isset($count[$record->column_fields['leadsource']])) $count[$record->column_fields['leadsource']]++;
1075                          else $count[$record->column_fields['leadsource']] = 1;
1076                          $total = $total + ($amount/1000);
1077                      }
1078                  }
1079              }
1080  
1081              $visible_legends = array();
1082              $data= array();
1083              $aTargets = array();
1084              $aAlts = array();
1085              foreach ($legends as $lead_source_key=>$lead_source_translation) {
1086                  if (isset($sum[$lead_source_key]))
1087                  {
1088                      array_push($data, $sum[$lead_source_key]);
1089                      if($lead_source_key != '')
1090                      {
1091                          array_push($visible_legends, $lead_source_translation);
1092                      }
1093                      else
1094                      {
1095                          // put none in if the vtiger_field is blank.
1096                          array_push($visible_legends, $current_module_strings['NTC_NO_LEGENDS']);
1097                      }
1098                      array_push($aTargets, "index.php?module=Potentials&action=ListView&leadsource=".urlencode($lead_source_key)."&query=true&type=dbrd");
1099                      array_push($aAlts, $count[$lead_source_key]." ".$current_module_strings['LBL_OPPS_IN_LEAD_SOURCE']." $lead_source_translation    ");
1100                  }
1101              }
1102  
1103              $log->debug("sum is:");
1104              $log->debug($sum);
1105              $log->debug("count is:");
1106              $log->debug($count);
1107              $log->debug("total is: $total");
1108              if ($total == 0) {
1109  $log->debug("Exiting pipeline_by_lead_source method ...");
1110                  return ($current_module_strings['ERR_NO_OPPS']);
1111              }
1112  
1113              if($theme == "blue")
1114              {
1115                  $font_color = "#212473";
1116              }
1117              else
1118              {
1119                  $font_color = "#000000";
1120              }
1121  
1122      
1123              $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true));
1124              $imagemap = $canvas->getImageMap();
1125              $graph =& Image_Graph::factory('graph', $canvas);
1126      
1127              $font =& $graph->addNew('font', calculate_font_name($lang_crm));
1128              // set the font size to 11 pixels
1129              $font->setSize(8);
1130              $font->setColor($font_color);
1131              
1132              $graph->setFont($font);
1133              // create the plotarea layout
1134              $title =& Image_Graph::factory('title', array('Test',10));
1135              $plotarea =& Image_Graph::factory('plotarea',array(
1136                      'category',
1137                      'axis'
1138                  ));
1139              $footer =& Image_Graph::factory('title', array('Footer',8));
1140              $graph->add(
1141                  Image_Graph::vertical($title,
1142                  Image_Graph::vertical(
1143                      $plotarea,
1144                      $footer,
1145                      90
1146                      ),
1147                  5
1148                  )
1149              );   
1150  
1151              // Generate colours
1152              $colors = color_generator(count($visible_legends),'#33CCFF','#3322FF');
1153              $index = 0;
1154              $dataset = & Image_Graph::factory('dataset');
1155              $fills =& Image_Graph::factory('Image_Graph_Fill_Array');
1156              foreach($visible_legends as $legend) {
1157                  $dataset->addPoint(
1158                      $legend,
1159                      $data[$index],
1160                      array(
1161                          'url' => $aTargets[$index],
1162                          'alt' => $aAlts[$index]
1163                      )
1164                  );
1165                  $fills->addColor($colors[$index]);
1166                  $log->debug('point ='.$legend.','.$data[$index]);
1167  
1168                  $index++;
1169              }
1170  
1171              // create the pie chart and associate the filling colours            
1172              $gbplot = & $plotarea->addNew('pie', $dataset);
1173              $plotarea->hideAxis();
1174              $gbplot->setFillStyle($fills);
1175  
1176              // Setup title
1177              $titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total.$app_strings['LBL_THOUSANDS_SYMBOL'];
1178              //$titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total;
1179  
1180              $title->setText($titlestr);
1181  
1182              // format the data values
1183              $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol."%d");
1184  
1185              // set markers
1186              $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y);
1187              $marker->setDataPreprocessor($valueproc);
1188              $marker->setFillColor('#FFFFFF');
1189              $marker->setBorderColor($font_color);
1190              $marker->setFontColor($font_color);
1191              $marker->setFontSize(8);
1192              $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker));
1193              $gbplot->setMarker($pointingMarker);
1194              
1195              // set legend
1196              $legend_box =& $plotarea->addNew('legend');
1197              $legend_box->setPadding(array('top'=>20,'bottom'=>0,'left'=>0,'right'=>0));
1198              $legend_box->setFillColor('#F5F5F5');
1199              $legend_box->showShadow();
1200  
1201              $subtitle = $current_module_strings['LBL_OPP_SIZE'].$current_user->currency_symbol.$current_module_strings['LBL_OPP_SIZE_VALUE'];
1202              $footer->setText($subtitle);
1203              $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_LEFT);
1204  
1205              $imgMap = $graph->done(
1206                                      array(
1207                                              'tohtml' => true,
1208                                              'border' => 0,
1209                                              'filename' => $cache_file_name,
1210                                              'filepath' => './',
1211                                              'urlpath' => ''
1212                                          ));
1213              //$imgMap = htmlspecialchars($output);
1214              save_image_map($cache_file_name.'.map', $imgMap);
1215          }
1216          else {
1217              $imgMap_fp = fopen($cache_file_name.'.map', "rb");
1218              $imgMap = fread($imgMap_fp, filesize($cache_file_name.'.map'));
1219              fclose($imgMap_fp);
1220          }
1221          $fileModTime = filemtime($cache_file_name.'.map');
1222          $return = "\n$imgMap";
1223          $log->debug("Exiting pipeline_by_lead_source method ...");
1224          return $return;
1225  
1226      }
1227  
1228  }
1229  
1230  
1231  /**
1232   * Creates a file with the image map
1233   * param $filename - file name to save to
1234   * param $image_map - image map string to save
1235   * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
1236   * All Rights Reserved.
1237   * Contributor(s): ______________________________________..
1238   */
1239  function save_image_map($filename,$image_map)
1240  {
1241      global $log;
1242      $log->debug("Entering save_image_map(".$filename.",".$image_map.") method ...");
1243      // save the image map to file
1244      $log =& LoggerManager::getLogger('save_image_file');
1245  
1246      if (!$handle = fopen($filename, 'w')) {
1247          $log->debug("Cannot open file ($filename)");
1248          $log->debug("Exiting save_image_map method ...");
1249          return;
1250      }
1251  
1252      // Write $somecontent to our opened file.
1253      if (fwrite($handle, $image_map) === FALSE) {
1254         $log->debug("Cannot write to file ($filename)");
1255         $log->debug("Exiting save_image_map method ...");
1256         return false;
1257      }
1258  
1259      $log->debug("Success, wrote ($image_map) to file ($filename)");
1260  
1261      fclose($handle);
1262      $log->debug("Exiting save_image_map method ...");
1263      return true;
1264  
1265  }
1266  
1267  // retrieve the translated strings.
1268  $app_strings = return_application_language($current_language);
1269  
1270  if(isset($app_strings['LBL_CHARSET']))
1271  {
1272      $charset = $app_strings['LBL_CHARSET'];
1273  }
1274  else
1275  {
1276      $charset = $default_charset;
1277  }
1278  
1279  
1280  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7