[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/reports/ -> customer_stats.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: customer_stats.php 3206 2007-01-24 20:24:35Z glen $
  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.date.php");
  35  require_once (APP_INC_PATH . "db_access.php");
  36  require_once (APP_INC_PATH . "class.customer.php");
  37  require_once (APP_INC_PATH . "class.customer_stats_report.php");
  38  require_once (APP_INC_PATH . "class.session.php");
  39  
  40  $tpl = new Template_API();
  41  $tpl->setTemplate("reports/customer_stats.tpl.html");
  42  
  43  Auth::checkAuthentication(APP_COOKIE);
  44  
  45  if (Auth::getCurrentRole() <= User::getRoleID("Customer")) {
  46      echo "Invalid role";
  47      exit;
  48  }
  49  
  50  // check if this project has customer integration
  51  $prj_id = Auth::getCurrentProject();
  52  if (!Customer::hasCustomerIntegration($prj_id)) {
  53      $tpl->assign("no_customer_integration", 1);
  54      $tpl->displayTemplate();
  55      exit;
  56  }
  57  
  58  if (count(@$_POST["start"]) > 0 &&
  59          (@$_POST["start"]["Year"] != 0) &&
  60          (@$_POST["start"]["Month"] != 0) &&
  61          (@$_POST["start"]["Day"] != 0)) {
  62      $start_date = join("-", $_POST["start"]);
  63  } else {
  64      $start_date = "0000-00-00";
  65  }
  66  if (count(@$_POST["end"]) > 0 &&
  67          (@$_POST["end"]["Year"] != 0) &&
  68          (@$_POST["end"]["Month"] != 0) &&
  69          (@$_POST["end"]["Day"] != 0)) {
  70      $end_date = join("-", $_POST["end"]);
  71  } else {
  72      $end_date = "0000-00-00";
  73  }
  74  
  75  if (count(@$_POST["display_sections"]) < 1) {
  76      $_POST["display_sections"] = array_keys(Customer_Stats_Report::getDisplaySections());
  77      unset($_POST["display_sections"][4]);
  78  }
  79  
  80  $support_levels = array('Aggregate' => 'Aggregate');
  81  $grouped_levels = Customer::getGroupedSupportLevels($prj_id);
  82  foreach ($grouped_levels as $level_name => $level_ids) {
  83      $support_levels[$level_name] = $level_name;
  84  }
  85  
  86  if (count(@$_POST["support_level"]) < 1) {
  87      $_POST["support_level"] = array('Aggregate');
  88  }
  89  
  90  // XXX: internal only - Remove all mentions of InnoDB
  91  
  92  $prj_id = Auth::getCurrentProject();
  93  $tpl->assign(array(
  94      "has_support_levels"=>  Customer::doesBackendUseSupportLevels($prj_id),
  95      "project_name"      =>  Auth::getCurrentProjectName(),
  96      "support_levels"    =>  $support_levels,
  97      "support_level"     =>  @$_POST["support_level"],
  98      "start_date"        =>  $start_date,
  99      "end_date"          =>  $end_date,
 100      "sections"          =>  Customer_Stats_Report::getDisplaySections(),
 101      "display_sections"  =>  $_POST["display_sections"],
 102      "split_innoDB"      =>  @$_POST["split_innoDB"],
 103      "include_expired"   =>  @$_POST["include_expired"],
 104      "graphs"            =>  Customer_Stats_Report::getGraphTypes()
 105  ));
 106  
 107  // only set customers if user has role of manager or above
 108  if (Auth::getCurrentRole() >= User::getRoleID('manager')) {
 109      $tpl->assign(array(
 110      "customers"         =>  Customer::getAssocList($prj_id),
 111      "customer"          =>  @$_POST["customer"]
 112      ));
 113  }
 114  
 115  // loop through display sections
 116  $display = array();
 117  foreach ($_POST["display_sections"] as $section) {
 118      $display[$section] = 1;
 119  }
 120  $tpl->assign("display", $display);
 121  
 122  
 123  if (@$_POST["cat"] == "Generate") {
 124      
 125      if ($start_date == "0000-00-00") {
 126          $start_date = '';
 127      }
 128      if ($end_date == "0000-00-00") {
 129          $end_date = '';
 130      }
 131      
 132      // set the date range msg
 133      if ((!empty($start_date)) && (!empty($end_date))) {
 134          $date_msg_text = "Date Range: $start_date - $end_date";
 135          $tpl->assign(array(
 136              "date_msg_text" =>  $date_msg_text,
 137              "date_msg"      =>  "<div align=\"center\" style=\"font-family: Verdana, Arial, Helvetica, sans-serif;font-style: normal;font-weight: bold; margin: 3px\">
 138                                      $date_msg_text
 139                                  </div>"
 140          ));
 141      }
 142      
 143      $csr = new Customer_Stats_Report(
 144                      $prj_id,
 145                      @$_POST["support_level"],
 146                      @$_POST["customer"],
 147                      $start_date,
 148                      $end_date);
 149      if (@$_POST["split_innoDB"] == 1) {
 150          $csr->splitByInnoDB(true);
 151      }
 152      if (@$_POST["include_expired"] == 1) {
 153          $csr->excludeExpired(false);
 154      } else {
 155          $csr->excludeExpired(true);
 156      }
 157      
 158      $data = $csr->getData();
 159      $tpl->assign("data", $data);
 160      $tpl->assign("time_tracking_categories", $csr->getTimeTrackingCategories());
 161      $tpl->assign("row_label", $csr->getRowLabel());
 162      
 163      Session::set("customer_stats_data", $data);
 164  }
 165  
 166  function formatValue($value, $all_value, $round_places = false, $alternate_value = false)
 167  {
 168      if ($alternate_value === false) {
 169          $compare_value = $value;
 170      } else {
 171          $compare_value = $alternate_value;
 172      }
 173      
 174      if ($all_value < $compare_value) {
 175          $color = "red";
 176      } else if ($all_value > $compare_value)  {
 177          $color = "blue";
 178      } else {
 179          if (is_int($round_places)) {
 180              $value = round($value, $round_places);
 181          }
 182          return $value;
 183      }
 184      if (is_int($round_places)) {
 185          $value = round($value, $round_places);
 186      }
 187      return "<span style=\"color: $color\">$value</span>";
 188  }
 189  
 190  $tpl->displayTemplate();
 191     // echo "<pre>";print_r(@$data);echo "</pre>";


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