[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/reports/ -> recent_activity.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  // This report shows a list of activity performed in recent history.
  29  require_once(dirname(__FILE__) . "/../init.php");
  30  require_once (APP_INC_PATH . "class.template.php");
  31  require_once (APP_INC_PATH . "class.auth.php");
  32  require_once (APP_INC_PATH . "db_access.php");
  33  
  34  $tpl = new Template_API();
  35  $tpl->setTemplate("reports/recent_activity.tpl.html");
  36  
  37  Auth::checkAuthentication(APP_COOKIE);
  38  
  39  if (Auth::getCurrentRole() <= User::getRoleID("Customer")) {
  40      echo "Invalid role";
  41      exit;
  42  }
  43  
  44  $units = array(
  45      "hour"  =>  "Hours",
  46      "day"   =>  "Days"
  47  );
  48  $type_list = array(
  49      "phone" =>  "Phone Calls",
  50      "note"  =>  "Notes",
  51      "email" =>  "Email",
  52      "draft" =>  "Drafts",
  53      "time"  =>  "Time Tracking",
  54      "reminder"  =>  "Reminders"
  55  );
  56  
  57  if (empty($_REQUEST['activity_types'])) {
  58      $_REQUEST['activity_types'] = array_keys($type_list);
  59  }
  60  
  61  $prj_id = Auth::getCurrentProject();
  62  $usr_id = Auth::getUserID();
  63  
  64  $tpl->assign(array(
  65      "units" =>  $units,
  66      "users" => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')),
  67      "developer" => $usr_id,
  68      "type_list" =>  $type_list,
  69      "activity_types"    =>  $_REQUEST['activity_types']
  70  ));
  71  
  72  
  73  if (((!empty($_REQUEST['unit'])) && (!empty($_REQUEST['amount']))) || (@count($_REQUEST['start']) == 3)) {
  74      
  75      if (count(@$_REQUEST["start"]) > 0 &&
  76              (@$_REQUEST["start"]["Year"] != 0) &&
  77              (@$_REQUEST["start"]["Month"] != 0) &&
  78              (@$_REQUEST["start"]["Day"] != 0)) {
  79          $start_date = join("-", $_POST["start"]);
  80      }
  81      if (count(@$_REQUEST["end"]) > 0 &&
  82              (@$_REQUEST["end"]["Year"] != 0) &&
  83              (@$_REQUEST["end"]["Month"] != 0) &&
  84              (@$_REQUEST["end"]["Day"] != 0)) {
  85          $end_date = join("-", $_POST["end"]);
  86      }
  87      
  88      $data = array();
  89      if (in_array('phone', $_REQUEST['activity_types'])) {
  90          $sql = "SELECT
  91                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support.*,
  92                      phc_title,
  93                      usr_full_name,
  94                      iss_summary,
  95                      sta_color
  96                  FROM
  97                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support,
  98                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category,
  99                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 100                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user,
 101                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 102                  WHERE
 103                      iss_sta_id = sta_id AND
 104                      phs_phc_id = phc_id AND
 105                      phs_iss_id = iss_id AND
 106                      phs_usr_id = usr_id AND
 107                      iss_prj_id = $prj_id AND\n";
 108          $sql .= createWhereClause('phs_created_date', 'usr_id');
 109          $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC);
 110          if (PEAR::isError($res)) {
 111              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 112          } else {
 113              $data['phone'] = processResult($res, 'phs_created_date', 'phs_iss_id');
 114          }
 115      }
 116      
 117      if (in_array('note', $_REQUEST['activity_types'])) {
 118          $sql = "SELECT
 119                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "note.*,
 120                      usr_full_name,
 121                      iss_summary,
 122                      sta_color
 123                  FROM
 124                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "note,
 125                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 126                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user,
 127                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 128                  WHERE
 129                      iss_sta_id = sta_id AND
 130                      not_iss_id = iss_id AND
 131                      not_usr_id = usr_id AND
 132                      iss_prj_id = $prj_id AND\n";
 133          $sql .= createWhereClause('not_created_date', 'not_usr_id');
 134          $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC);
 135          if (PEAR::isError($res)) {
 136              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 137          } else {
 138              $data['note'] = processResult($res, 'not_created_date', 'not_iss_id');
 139          }
 140      }
 141      
 142      if (in_array('email', $_REQUEST['activity_types'])) {
 143          $sql = "SELECT
 144                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email.*,
 145                      iss_summary,
 146                      CONCAT(sup_ema_id, '-', sup_id) AS composite_id,
 147                      sta_color
 148                  FROM
 149                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email,
 150                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 151                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 152                  WHERE
 153                      iss_sta_id = sta_id AND
 154                      sup_iss_id = iss_id AND
 155                      iss_prj_id = $prj_id AND\n";
 156          $sql .= createWhereClause('sup_date', 'sup_usr_id');
 157          $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC);
 158          if (PEAR::isError($res)) {
 159              print_r($res);
 160              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 161          } else {
 162              $data['email'] = processResult($res, 'sup_date', 'sup_iss_id');
 163          }
 164      }
 165      
 166      if (in_array('draft', $_REQUEST['activity_types'])) {
 167          $sql = "SELECT
 168                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_draft.*,
 169                      iss_summary,
 170                      sta_color
 171                  FROM
 172                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_draft,
 173                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 174                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 175                  WHERE
 176                      iss_sta_id = sta_id AND
 177                      emd_iss_id = iss_id AND
 178                      iss_prj_id = $prj_id AND\n";
 179          $sql .= createWhereClause('emd_updated_date', 'emd_usr_id');
 180          $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC);
 181          if (PEAR::isError($res)) {
 182              print_r($res);
 183              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 184          } else {
 185              $data['draft'] = processResult($res, 'emd_updated_date', 'emd_iss_id');
 186              for ($i = 0; $i < count($data['draft']); $i++) {
 187                  if (!empty($data['draft'][$i]['emd_unknown_user'])) {
 188                      $data['draft'][$i]['from'] = $data['draft'][$i]["emd_unknown_user"];
 189                  } else {
 190                      $data['draft'][$i]['from'] = User::getFromHeader($data['draft'][$i]['emd_usr_id']);
 191                  }
 192                  list($data['draft'][$i]['to'], ) = Draft::getEmailRecipients($data['draft'][$i]['emd_id']);
 193                  if (empty($data['draft'][$i]['to'])) {
 194                      $data['draft'][$i]['to'] = "Notification List";
 195                  }
 196              }
 197          }
 198      }
 199      
 200      if (in_array('time', $_REQUEST['activity_types'])) {
 201          $sql = "SELECT
 202                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking.*,
 203                      ttc_title,
 204                      iss_summary,
 205                      usr_full_name,
 206                      sta_color
 207                  FROM
 208                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking,
 209                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking_category,
 210                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 211                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user,
 212                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 213                  WHERE
 214                      iss_sta_id = sta_id AND
 215                      ttr_iss_id = iss_id AND
 216                      ttr_ttc_id = ttc_id AND
 217                      ttr_usr_id = usr_id AND
 218                      iss_prj_id = $prj_id AND\n";
 219          $sql .= createWhereClause('ttr_created_date', 'ttr_usr_id');
 220          $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC);
 221          if (PEAR::isError($res)) {
 222              print_r($res);
 223              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 224          } else {
 225              $data['time'] = processResult($res, 'ttr_created_date', 'ttr_iss_id');
 226              for ($i = 0; $i < count($data['time']); $i++) {
 227                  $data['time'][$i]['time_spent'] = Misc::getFormattedTime($data['time'][$i]['ttr_time_spent'], true);
 228              }
 229          }
 230      }
 231      
 232      if ((empty($_REQUEST['developer'])) && (in_array('reminder', $_REQUEST['activity_types']))) {
 233          $sql = "SELECT
 234                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_history.*,
 235                      iss_summary,
 236                      sta_color,
 237                      rma_title
 238                  FROM
 239                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_history,
 240                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_action,
 241                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 242                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status
 243                  WHERE
 244                      iss_sta_id = sta_id AND
 245                      rmh_iss_id = iss_id AND
 246                      rmh_rma_id = rma_id AND
 247                      iss_prj_id = $prj_id AND\n";
 248          $sql .= createWhereClause('rmh_created_date');
 249          $res = $GLOBALS["db_api"]->dbh->getAll($sql, DB_FETCHMODE_ASSOC);
 250          if (PEAR::isError($res)) {
 251              print_r($res);
 252              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 253          } else {
 254              $data['reminder'] = processResult($res, 'rmh_created_date', 'rmh_iss_id');
 255          }
 256      }
 257      
 258      $tpl->assign(array(
 259          "unit"  =>  $_REQUEST['unit'],
 260          "amount"    =>  $_REQUEST['amount'],
 261          "developer" =>  $_REQUEST['developer'],
 262          "start_date"    =>  @$start_date,
 263          "end_date"      =>  @$end_date,
 264          "data"  =>  $data
 265      ));
 266  }
 267  
 268  
 269  function createWhereClause($date_field, $user_field = false)
 270  {
 271      GLOBAL $start_date, $end_date;
 272      
 273      $sql = '';
 274      if ($_REQUEST['report_type'] == 'recent') {
 275          $sql .= "$date_field >= DATE_SUB('" . Date_API::getCurrentDateGMT() . "', INTERVAL " . Misc::escapeInteger($_REQUEST['amount']) . " " . Misc::escapeString($_REQUEST['unit']) . ")";
 276      } else {
 277          $sql .= "$date_field BETWEEN '$start_date' AND '$end_date'";
 278      }
 279      if (($user_field != false) && (!empty($_REQUEST['developer']))) {
 280          $sql .= " AND $user_field = " . Misc::escapeString($_REQUEST['developer']);
 281      }
 282      $sql .= " ORDER BY $date_field " . Misc::escapeString($_REQUEST['sort_order']);
 283      return $sql;
 284  }
 285  
 286  function processResult($res, $date_field, $issue_field)
 287  {
 288      GLOBAL $prj_id;
 289      GLOBAL $usr_id;
 290      
 291      $data = array();
 292      for ($i = 0; $i < count($res); $i++) {
 293          if (!Issue::canAccess($res[$i][$issue_field], $usr_id)) {
 294              continue;
 295          }
 296          if (Customer::hasCustomerIntegration($prj_id)) {
 297              $details = Customer::getDetails($prj_id, Issue::getCustomerID($res[$i][$issue_field]));
 298              $res[$i]["customer"] = @$details['customer_name'];
 299          }
 300          $res[$i]["date"] = Date_API::getFormattedDate($res[$i][$date_field], Date_API::getPreferredTimezone($usr_id));
 301          // need to decode From:, To: mail headers
 302          if (isset($res[$i]["sup_from"])) {
 303              $res[$i]["sup_from"] = Mime_Helper::fixEncoding($res[$i]["sup_from"]);
 304          }
 305          if (isset($res[$i]["sup_to"])) {
 306              $res[$i]["sup_to"] = Mime_Helper::fixEncoding($res[$i]["sup_to"]);
 307          }
 308  
 309          $data[] = $res[$i];
 310      }
 311      return $data;
 312  }
 313  
 314  $tpl->displayTemplate();


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