[ Index ] |
PHP Cross Reference of Eventum |
[Summary view] [Print] [Text view]
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: João Prado Maia <jpm@mysql.com> | 26 // +----------------------------------------------------------------------+ 27 // 28 // @(#) $Id: class.phone_support.php 3246 2007-02-09 09:10:12Z glen $ 29 // 30 31 require_once (APP_INC_PATH . "class.error_handler.php"); 32 require_once (APP_INC_PATH . "class.auth.php"); 33 require_once (APP_INC_PATH . "class.user.php"); 34 require_once (APP_INC_PATH . "class.history.php"); 35 require_once (APP_INC_PATH . "class.issue.php"); 36 require_once (APP_INC_PATH . "class.misc.php"); 37 require_once (APP_INC_PATH . "class.date.php"); 38 39 /** 40 * Class to handle the business logic related to the phone support 41 * feature of the application. 42 * 43 * @version 1.0 44 * @author João Prado Maia <jpm@mysql.com> 45 */ 46 47 class Phone_Support 48 { 49 /** 50 * Method used to add a new category to the application. 51 * 52 * @access public 53 * @return integer 1 if the update worked properly, any other value otherwise 54 */ 55 function insertCategory() 56 { 57 if (Validation::isWhitespace($_POST["title"])) { 58 return -2; 59 } 60 $stmt = "INSERT INTO 61 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category 62 ( 63 phc_prj_id, 64 phc_title 65 ) VALUES ( 66 " . Misc::escapeInteger($_POST["prj_id"]) . ", 67 '" . Misc::escapeString($_POST["title"]) . "' 68 )"; 69 $res = $GLOBALS["db_api"]->dbh->query($stmt); 70 if (PEAR::isError($res)) { 71 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 72 return -1; 73 } else { 74 return 1; 75 } 76 } 77 78 79 /** 80 * Method used to update the values stored in the database. 81 * Typically the user would modify the title of the category in 82 * the application and this method would be called. 83 * 84 * @access public 85 * @return integer 1 if the update worked properly, any other value otherwise 86 */ 87 function updateCategory() 88 { 89 if (Validation::isWhitespace($_POST["title"])) { 90 return -2; 91 } 92 $stmt = "UPDATE 93 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category 94 SET 95 phc_title='" . Misc::escapeString($_POST["title"]) . "' 96 WHERE 97 phc_prj_id=" . Misc::escapeInteger($_POST["prj_id"]) . " AND 98 phc_id=" . Misc::escapeInteger($_POST["id"]); 99 $res = $GLOBALS["db_api"]->dbh->query($stmt); 100 if (PEAR::isError($res)) { 101 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 102 return -1; 103 } else { 104 return 1; 105 } 106 } 107 108 109 /** 110 * Method used to remove user-selected categories from the 111 * database. 112 * 113 * @access public 114 * @return boolean Whether the removal worked or not 115 */ 116 function removeCategory() 117 { 118 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 119 $stmt = "DELETE FROM 120 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category 121 WHERE 122 phc_id IN ($items)"; 123 $res = $GLOBALS["db_api"]->dbh->query($stmt); 124 if (PEAR::isError($res)) { 125 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 126 return false; 127 } else { 128 return true; 129 } 130 } 131 132 133 /** 134 * Method used to get the full details of a category. 135 * 136 * @access public 137 * @param integer $phc_id The category ID 138 * @return array The information about the category provided 139 */ 140 function getCategoryDetails($phc_id) 141 { 142 $stmt = "SELECT 143 * 144 FROM 145 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category 146 WHERE 147 phc_id=" . Misc::escapeInteger($phc_id); 148 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 149 if (PEAR::isError($res)) { 150 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 151 return ""; 152 } else { 153 return $res; 154 } 155 } 156 157 158 /** 159 * Method used to get the full list of categories associated with 160 * a specific project. 161 * 162 * @access public 163 * @param integer $prj_id The project ID 164 * @return array The full list of categories 165 */ 166 function getCategoryList($prj_id) 167 { 168 $stmt = "SELECT 169 phc_id, 170 phc_title 171 FROM 172 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category 173 WHERE 174 phc_prj_id=" . Misc::escapeInteger($prj_id) . " 175 ORDER BY 176 phc_title ASC"; 177 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 178 if (PEAR::isError($res)) { 179 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 180 return ""; 181 } else { 182 return $res; 183 } 184 } 185 186 187 /** 188 * Method used to get an associative array of the list of 189 * categories associated with a specific project. 190 * 191 * @access public 192 * @param integer $prj_id The project ID 193 * @return array The associative array of categories 194 */ 195 function getCategoryAssocList($prj_id) 196 { 197 $stmt = "SELECT 198 phc_id, 199 phc_title 200 FROM 201 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category 202 WHERE 203 phc_prj_id=" . Misc::escapeInteger($prj_id) . " 204 ORDER BY 205 phc_id ASC"; 206 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 207 if (PEAR::isError($res)) { 208 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 209 return ""; 210 } else { 211 return $res; 212 } 213 } 214 215 216 /** 217 * Method used to get the details of a given phone support entry. 218 * 219 * @access public 220 * @param integer $phs_id The phone support entry ID 221 * @return array The phone support entry details 222 */ 223 function getDetails($phs_id) 224 { 225 $stmt = "SELECT 226 * 227 FROM 228 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support 229 WHERE 230 phs_id=" . Misc::escapeInteger($phs_id); 231 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 232 if (PEAR::isError($res)) { 233 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 234 return ""; 235 } else { 236 return $res; 237 } 238 } 239 240 241 /** 242 * Method used to get the full listing of phone support entries 243 * associated with a specific issue. 244 * 245 * @access public 246 * @param integer $issue_id The issue ID 247 * @return array The list of notes 248 */ 249 function getListing($issue_id) 250 { 251 $stmt = "SELECT 252 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support.*, 253 usr_full_name, 254 phc_title, 255 iss_prj_id 256 FROM 257 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support, 258 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_phone_category, 259 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user, 260 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue 261 WHERE 262 phs_iss_id=iss_id AND 263 iss_prj_id=phc_prj_id AND 264 phs_phc_id=phc_id AND 265 phs_usr_id=usr_id AND 266 phs_iss_id=" . Misc::escapeInteger($issue_id) . " 267 ORDER BY 268 phs_created_date ASC"; 269 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 270 if (PEAR::isError($res)) { 271 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 272 return ""; 273 } else { 274 for ($i = 0; $i < count($res); $i++) { 275 $res[$i]["phs_description"] = Misc::activateLinks(nl2br(htmlspecialchars($res[$i]["phs_description"]))); 276 $res[$i]["phs_description"] = Link_Filter::processText($res[$i]['iss_prj_id'], $res[$i]["phs_description"]); 277 $res[$i]["phs_created_date"] = Date_API::getFormattedDate($res[$i]["phs_created_date"]); 278 } 279 return $res; 280 } 281 } 282 283 284 /** 285 * Method used to add a phone support entry using the user 286 * interface form available in the application. 287 * 288 * @access public 289 * @return integer 1 if the insert worked, -1 or -2 otherwise 290 */ 291 function insert() 292 { 293 $usr_id = Auth::getUserID(); 294 // format the date from the form 295 $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', 296 $_POST["date"]["Year"], $_POST["date"]["Month"], 297 $_POST["date"]["Day"], $_POST["date"]["Hour"], 298 $_POST["date"]["Minute"], 0); 299 // convert the date to GMT timezone 300 $created_date = Date_API::getDateGMT($created_date); 301 $stmt = "INSERT INTO 302 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support 303 ( 304 phs_iss_id, 305 phs_usr_id, 306 phs_phc_id, 307 phs_created_date, 308 phs_type, 309 phs_phone_number, 310 phs_description, 311 phs_phone_type, 312 phs_call_from_lname, 313 phs_call_from_fname, 314 phs_call_to_lname, 315 phs_call_to_fname 316 ) VALUES ( 317 " . Misc::escapeInteger($_POST["issue_id"]) . ", 318 $usr_id, 319 " . Misc::escapeInteger($_POST["phone_category"]) . ", 320 '" . Misc::escapeString($created_date) . "', 321 '" . Misc::escapeString($_POST["type"]) . "', 322 '" . Misc::escapeString($_POST["phone_number"]) . "', 323 '" . Misc::escapeString($_POST["description"]) . "', 324 '" . Misc::escapeString($_POST["phone_type"]) . "', 325 '" . Misc::escapeString($_POST["from_lname"]) . "', 326 '" . Misc::escapeString($_POST["from_fname"]) . "', 327 '" . Misc::escapeString($_POST["to_lname"]) . "', 328 '" . Misc::escapeString($_POST["to_fname"]) . "' 329 )"; 330 $res = $GLOBALS["db_api"]->dbh->query($stmt); 331 if (PEAR::isError($res)) { 332 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 333 return -1; 334 } else { 335 // enter the time tracking entry about this phone support entry 336 $phs_id = $GLOBALS["db_api"]->get_last_insert_id(); 337 $_POST['category'] = Time_Tracking::getCategoryID('Telephone Discussion'); 338 $_POST['time_spent'] = $_POST['call_length']; 339 $_POST['summary'] = ev_gettext("Time entry inserted from phone call."); 340 Time_Tracking::insertEntry(); 341 $stmt = "SELECT 342 max(ttr_id) 343 FROM 344 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking 345 WHERE 346 ttr_iss_id = " . Misc::escapeInteger($_POST["issue_id"]) . " AND 347 ttr_usr_id = $usr_id"; 348 $ttr_id = $GLOBALS["db_api"]->dbh->getOne($stmt); 349 350 Issue::markAsUpdated($_POST['issue_id'], 'phone call'); 351 // need to save a history entry for this 352 History::add($_POST['issue_id'], $usr_id, History::getTypeID('phone_entry_added'), 353 ev_gettext('Phone Support entry submitted by %1$s', User::getFullName($usr_id))); 354 // XXX: send notifications for the issue being updated (new notification type phone_support?) 355 356 // update phone record with time tracking ID. 357 if ((!empty($phs_id)) && (!empty($ttr_id))) { 358 $stmt = "UPDATE 359 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support 360 SET 361 phs_ttr_id = $ttr_id 362 WHERE 363 phs_id = " . Misc::escapeInteger($phs_id); 364 $res = $GLOBALS["db_api"]->dbh->query($stmt); 365 if (PEAR::isError($res)) { 366 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 367 return -1; 368 } 369 } 370 return 1; 371 } 372 } 373 374 375 /** 376 * Method used to remove a specific phone support entry from the 377 * application. 378 * 379 * @access public 380 * @param integer $phone_id The phone support entry ID 381 * @return integer 1 if the removal worked, -1 or -2 otherwise 382 */ 383 function remove($phone_id) 384 { 385 $phone_id = Misc::escapeInteger($phone_id); 386 387 $stmt = "SELECT 388 phs_iss_id, 389 phs_ttr_id, 390 phs_usr_id 391 FROM 392 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support 393 WHERE 394 phs_id=$phone_id"; 395 $details = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 396 if ($details['phs_usr_id'] != Auth::getUserID()) { 397 return -2; 398 } 399 400 $stmt = "DELETE FROM 401 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support 402 WHERE 403 phs_id=$phone_id"; 404 $res = $GLOBALS["db_api"]->dbh->query($stmt); 405 if (PEAR::isError($res)) { 406 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 407 return -1; 408 } else { 409 Issue::markAsUpdated($details["phs_iss_id"]); 410 // need to save a history entry for this 411 History::add($details["phs_iss_id"], Auth::getUserID(), History::getTypeID('phone_entry_removed'), 412 ev_gettext('Phone Support entry removed by %1$s', User::getFullName(Auth::getUserID()))); 413 414 if (!empty($details["phs_ttr_id"])) { 415 $time_result = Time_Tracking::removeEntry($details["phs_ttr_id"], $details['phs_usr_id']); 416 if ($time_result == 1) { 417 return 2; 418 } else { 419 return $time_result; 420 } 421 } else { 422 return 1; 423 } 424 } 425 } 426 427 428 /** 429 * Method used to remove all phone support entries associated with 430 * a given set of issues. 431 * 432 * @access public 433 * @param array $ids The array of issue IDs 434 * @return boolean 435 */ 436 function removeByIssues($ids) 437 { 438 $items = implode(", ", Misc::escapeInteger($ids)); 439 $stmt = "DELETE FROM 440 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support 441 WHERE 442 phs_iss_id IN ($items)"; 443 $res = $GLOBALS["db_api"]->dbh->query($stmt); 444 if (PEAR::isError($res)) { 445 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 446 return false; 447 } else { 448 return true; 449 } 450 } 451 452 453 /** 454 * Returns the number of calls by a user in a time range. 455 * 456 * @access public 457 * @param string $usr_id The ID of the user 458 * @param integer $start The timestamp of the start date 459 * @param integer $end The timestamp of the end date 460 * @return integer The number of phone calls by the user. 461 */ 462 function getCountByUser($usr_id, $start, $end) 463 { 464 $stmt = "SELECT 465 COUNT(phs_id) 466 FROM 467 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support, 468 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue 469 WHERE 470 phs_iss_id = iss_id AND 471 iss_prj_id = " . Auth::getCurrentProject() . " AND 472 phs_created_date BETWEEN '" . Misc::escapeString($start) . "' AND '" . Misc::escapeString($end) . "' AND 473 phs_usr_id = " . Misc::escapeInteger($usr_id); 474 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 475 if (PEAR::isError($res)) { 476 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 477 return ""; 478 } 479 return $res; 480 } 481 } 482 483 // benchmarking the included file (aka setup time) 484 if (APP_BENCHMARK) { 485 $GLOBALS['bench']->setMarker('Included Phone_Support Class'); 486 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 19 21:21:33 2007 | Cross-referenced by PHPXref 0.7 |