[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/reports/ -> custom_fields_graph.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
   3  // +----------------------------------------------------------------------+
   4  // | Eventum - Issue Tracking System                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB                              |
   7  // |                                                                      |
   8  // | This program is free software; you can redistribute it and/or modify |
   9  // | it under the terms of the GNU General Public License as published by |
  10  // | the Free Software Foundation; either version 2 of the License, or    |
  11  // | (at your option) any later version.                                  |
  12  // |                                                                      |
  13  // | This program is distributed in the hope that it will be useful,      |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  16  // | GNU General Public License for more details.                         |
  17  // |                                                                      |
  18  // | You should have received a copy of the GNU General Public License    |
  19  // | along with this program; if not, write to:                           |
  20  // |                                                                      |
  21  // | Free Software Foundation, Inc.                                       |
  22  // | 59 Temple Place - Suite 330                                          |
  23  // | Boston, MA 02111-1307, USA.                                          |
  24  // +----------------------------------------------------------------------+
  25  // | Authors: Bryan Alsdorf <bryan@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  // @(#) $Id: custom_fields_graph.php 3364 2007-08-27 09:58:52Z balsdorf $
  29  //
  30  require_once(dirname(__FILE__) . "/../init.php");
  31  require_once (APP_INC_PATH . "class.template.php");
  32  require_once (APP_INC_PATH . "class.auth.php");
  33  require_once (APP_INC_PATH . "class.report.php");
  34  require_once (APP_INC_PATH . "class.custom_field.php");
  35  require_once (APP_INC_PATH . "db_access.php");
  36  require_once(APP_JPGRAPH_PATH . "jpgraph.php");
  37  require_once(APP_JPGRAPH_PATH . "jpgraph_bar.php");
  38  require_once(APP_JPGRAPH_PATH . "jpgraph_pie.php");
  39  
  40  Auth::checkAuthentication(APP_COOKIE);
  41  
  42  if (Auth::getCurrentRole() <= User::getRoleID("Customer")) {
  43      echo "Invalid role";
  44      exit;
  45  }
  46  
  47  /**
  48   * Generates a graph for the selected custom field
  49   */
  50  
  51  if ((!empty($_REQUEST['start']['Year'])) && (!empty($_REQUEST['start']['Month'])) &&(!empty($_REQUEST['start']['Day']))) {
  52      $start = join('-', $_REQUEST['start']);
  53  } else {
  54      $start = false;
  55  }
  56  if ((!empty($_REQUEST['end']['Year'])) && (!empty($_REQUEST['end']['Month'])) &&(!empty($_REQUEST['end']['Day']))) {
  57      $end = join('-', $_REQUEST['end']);
  58  } else {
  59      $end = false;
  60  }
  61  
  62  $data = Report::getCustomFieldReport(@$_GET["custom_field"], @$_GET["custom_options"], @$_GET["group_by"], $start, $end, false, @$_REQUEST['interval']);
  63  $field_details = Custom_Field::getDetails(@$_GET["custom_field"]);
  64  
  65  if (count($data) < 2) {
  66      header("Location: " . APP_RELATIVE_URL . "images/no_data.gif");
  67  }
  68  
  69  if (@$_GET["type"] == "pie") {
  70  
  71      if (empty($data["All Others"])) {
  72          unset($data["All Others"]);
  73      }
  74  
  75      // A new graph
  76      $graph = new PieGraph(500,300,"auto");
  77  
  78      // The pie plot
  79      $plot = new PiePlot(array_values($data));
  80      $plot->SetTheme('pastel');
  81  
  82      // Move center of pie to the left to make better room
  83      // for the legend
  84      $plot->SetCenter(0.26,0.55);
  85  
  86      // Label font and color setup
  87      $plot->SetFont(FF_FONT1, FS_BOLD);
  88      $plot->SetFontColor("black");
  89  
  90      // Use percentages
  91      $plot->SetLabelType(0);
  92  
  93      // Size of pie in fraction of the width of the graph
  94      $plot->SetSize(0.3);
  95  
  96      // Legends
  97      $plot->SetLegends(array_keys($data));
  98      $graph->legend->SetFont(FF_FONT1);
  99      $graph->legend->Pos(0.06,0.27);
 100  
 101  } else {
 102      // bar chart
 103  
 104      unset($data["All Others"]);
 105  
 106      // figure out the best size for this graph.
 107      $width = 75;
 108      if (count($data) > 3) {
 109          foreach ($data as $label => $value) {
 110              $label_width = imagefontwidth(FF_FONT1) * strlen($label) + 15;
 111              if ($label_width < 50) {
 112                  $label_width = 50;
 113              }
 114              $width += $label_width;
 115  
 116              unset($data[$label]);
 117              $label = str_replace(array( '-', '/'), array("-\n", "/\n"), $label);
 118              $data[$label] = $value;
 119          }
 120      }
 121      if ($width < 500) {
 122          $width = 500;
 123      }
 124  
 125      // Create a bar pot
 126      $plot = new BarPlot(array_values($data));
 127      $plot->showValue(true);
 128      $plot->SetFillColor("#0000ff");
 129  
 130      $graph = new Graph($width,350);
 131      $graph->SetScale("textlin");
 132      $graph->img->SetMargin(60,30,40,60);
 133      $graph->yaxis->SetTitleMargin(45);
 134      $graph->SetShadow();
 135  
 136      // Turn the tickmarks
 137      $graph->xaxis->SetTickDirection(SIDE_DOWN);
 138      $graph->yaxis->SetTickDirection(SIDE_LEFT);
 139      $graph->xaxis->SetTickLabels(array_keys($data));
 140  
 141      $graph->xaxis->title->Set($field_details["fld_title"]);
 142      $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
 143      $graph->xaxis->SetTitleMargin(18);
 144      $graph->title->SetFont(FF_FONT1,FS_BOLD);
 145      $graph->yaxis->title->Set("Issue Count");
 146      $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
 147  }
 148  
 149  if (@$_GET["group_by"] == "customers") {
 150      "Customers by " . $field_details["fld_title"];
 151  } else {
 152      $title = "Issues by " . $field_details["fld_title"];
 153  }
 154  
 155  $graph->title->Set($title);
 156  $graph->title->SetFont(FF_FONT1,FS_BOLD);
 157  
 158  $graph->Add($plot);
 159  $graph->Stroke();


Generated: Wed Dec 19 21:21:33 2007 Cross-referenced by PHPXref 0.7