[ 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.reminder_condition.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.status.php"); 33 34 /** 35 * Class to handle the business logic related to the reminder emails 36 * that the system sends out. 37 * 38 * @version 1.0 39 * @author João Prado Maia <jpm@mysql.com> 40 */ 41 42 class Reminder_Condition 43 { 44 /** 45 * Method used to get the details for a specific reminder condition. 46 * 47 * @access public 48 * @param integer $rlc_id The reminder condition ID 49 * @return array The details for the specified reminder condition 50 */ 51 function getDetails($rlc_id) 52 { 53 $stmt = "SELECT 54 * 55 FROM 56 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition 57 WHERE 58 rlc_id=" . Misc::escapeInteger($rlc_id); 59 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 60 if (PEAR::isError($res)) { 61 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 62 return ''; 63 } else { 64 return $res; 65 } 66 } 67 68 69 /** 70 * Method used to create a new reminder condition. 71 * 72 * @access public 73 * @return integer 1 if the insert worked, -1 or -2 otherwise 74 */ 75 function insert() 76 { 77 $stmt = "INSERT INTO 78 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition 79 ( 80 rlc_created_date, 81 rlc_rma_id, 82 rlc_rmf_id, 83 rlc_rmo_id, 84 rlc_value, 85 rlc_comparison_rmf_id 86 ) VALUES ( 87 '" . Date_API::getCurrentDateGMT() . "', 88 " . Misc::escapeInteger($_POST['rma_id']) . ", 89 " . Misc::escapeInteger($_POST['field']) . ", 90 " . Misc::escapeInteger($_POST['operator']) . ", 91 '" . Misc::escapeString(@$_POST['value']) . "', 92 '" . Misc::escapeInteger(@$_POST['comparison_field']) . "' 93 )"; 94 $res = $GLOBALS["db_api"]->dbh->query($stmt); 95 if (PEAR::isError($res)) { 96 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 97 return -1; 98 } else { 99 return 1; 100 } 101 } 102 103 104 /** 105 * Method used to update the details of a specific reminder condition. 106 * 107 * @access public 108 * @return integer 1 if the update worked, -1 or -2 otherwise 109 */ 110 function update() 111 { 112 $stmt = "UPDATE 113 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition 114 SET 115 rlc_last_updated_date='" . Date_API::getCurrentDateGMT() . "', 116 rlc_rmf_id=" . Misc::escapeInteger($_POST['field']) . ", 117 rlc_rmo_id=" . Misc::escapeInteger($_POST['operator']) . ", 118 rlc_value='" . Misc::escapeString(@$_POST['value']) . "', 119 rlc_comparison_rmf_id = '" . Misc::escapeInteger(@$_POST['comparison_field']) . "' 120 WHERE 121 rlc_id=" . Misc::escapeInteger($_POST['id']); 122 $res = $GLOBALS["db_api"]->dbh->query($stmt); 123 if (PEAR::isError($res)) { 124 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 125 return -1; 126 } else { 127 return 1; 128 } 129 } 130 131 132 /** 133 * Method used to remove reminder conditions by using the administrative 134 * interface of the system. 135 * 136 * @access public 137 * @return boolean 138 */ 139 function remove() 140 { 141 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 142 $stmt = "DELETE FROM 143 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition 144 WHERE 145 rlc_id IN ($items)"; 146 $GLOBALS["db_api"]->dbh->query($stmt); 147 } 148 149 150 /** 151 * Method used to get the list of reminder conditions associated with a given 152 * reminder action ID. 153 * 154 * @access public 155 * @param integer $action_id The reminder action ID 156 * @return array The list of reminder conditions 157 */ 158 function getList($action_id) 159 { 160 $stmt = "SELECT 161 * 162 FROM 163 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition, 164 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field, 165 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_operator 166 WHERE 167 rlc_rma_id=" . Misc::escapeInteger($action_id) . " AND 168 rlc_rmf_id=rmf_id AND 169 rlc_rmo_id=rmo_id"; 170 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 171 if (PEAR::isError($res)) { 172 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 173 return array(); 174 } else { 175 if (empty($res)) { 176 return array(); 177 } else { 178 return $res; 179 } 180 } 181 } 182 183 184 /** 185 * Method used to get the list of reminder conditions to be displayed in the 186 * administration section. 187 * 188 * @access public 189 * @param integer $rma_id The reminder action ID 190 * @return array The list of reminder conditions 191 */ 192 function getAdminList($rma_id) 193 { 194 $stmt = "SELECT 195 rlc_id, 196 rlc_value, 197 rlc_comparison_rmf_id, 198 rmf_title, 199 rmo_title 200 FROM 201 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition, 202 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field, 203 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_operator 204 WHERE 205 rlc_rmf_id=rmf_id AND 206 rlc_rmo_id=rmo_id AND 207 rlc_rma_id=" . Misc::escapeInteger($rma_id) . " 208 ORDER BY 209 rlc_id ASC"; 210 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 211 if (PEAR::isError($res)) { 212 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 213 return array(); 214 } else { 215 for ($i = 0; $i < count($res); $i++) { 216 if (!empty($res[$i]['rlc_comparison_rmf_id'])) { 217 $res[$i]['rlc_value'] = ev_gettext("Field") . ': ' . Reminder_Condition::getFieldTitle($res[$i]['rlc_comparison_rmf_id']); 218 }elseif (strtolower($res[$i]['rmf_title']) == 'status') { 219 $res[$i]['rlc_value'] = Status::getStatusTitle($res[$i]['rlc_value']); 220 } elseif (strtolower($res[$i]['rmf_title']) == 'category') { 221 $res[$i]['rlc_value'] = Category::getTitle($res[$i]['rlc_value']); 222 } elseif (strtoupper($res[$i]['rlc_value']) != 'NULL') { 223 $res[$i]['rlc_value'] .= ' ' . ev_gettext("hours"); 224 } 225 } 226 return $res; 227 } 228 } 229 230 231 /** 232 * Method used to get the title of a specific reminder field. 233 * 234 * @access public 235 * @param integer $field_id The reminder field ID 236 * @return string The title of the reminder field 237 */ 238 function getFieldTitle($field_id) 239 { 240 $stmt = "SELECT 241 rmf_title 242 FROM 243 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field 244 WHERE 245 rmf_id=" . Misc::escapeInteger($field_id); 246 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 247 if (PEAR::isError($res)) { 248 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 249 return ''; 250 } else { 251 return $res; 252 } 253 } 254 255 256 /** 257 * Method used to get the sql_field of a specific reminder field. 258 * 259 * @access public 260 * @param integer $field_id The reminder field ID 261 * @return string The sql_field of the reminder field 262 */ 263 function getSQLField($field_id) 264 { 265 $stmt = "SELECT 266 rmf_sql_field 267 FROM 268 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field 269 WHERE 270 rmf_id=" . Misc::escapeInteger($field_id); 271 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 272 if (PEAR::isError($res)) { 273 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 274 return ''; 275 } else { 276 return $res; 277 } 278 } 279 280 281 /** 282 * Method used to get the list of reminder fields to be displayed in the 283 * administration section. 284 * 285 * @access public 286 * @param boolean $comparable_only If true, only fields that can be compared to other fields will be returned 287 * @return array The list of reminder fields 288 */ 289 function getFieldAdminList($comparable_only = false) 290 { 291 $stmt = "SELECT 292 rmf_id, 293 rmf_title 294 FROM 295 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field\n"; 296 if ($comparable_only == true) { 297 $stmt .= "WHERE rmf_allow_column_compare = 1\n"; 298 } 299 $stmt .= "ORDER BY 300 rmf_title ASC"; 301 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 302 if (PEAR::isError($res)) { 303 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 304 return array(); 305 } else { 306 return $res; 307 } 308 } 309 310 311 /** 312 * Method used to get the list of reminder operators to be displayed in the 313 * administration section. 314 * 315 * @access public 316 * @return array The list of reminder operators 317 */ 318 function getOperatorAdminList() 319 { 320 $stmt = "SELECT 321 rmo_id, 322 rmo_title 323 FROM 324 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_operator 325 ORDER BY 326 rmo_title ASC"; 327 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 328 if (PEAR::isError($res)) { 329 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 330 return array(); 331 } else { 332 return $res; 333 } 334 } 335 336 337 /** 338 * Method used to see if a specific reminder field can be compared to other fields. 339 * 340 * @access public 341 * @param integer $field_id The reminder field ID 342 * @return boolean If this field can be compared to other fields. 343 */ 344 function canFieldBeCompared($field_id) 345 { 346 $stmt = "SELECT 347 rmf_allow_column_compare 348 FROM 349 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field 350 WHERE 351 rmf_id=" . Misc::escapeInteger($field_id); 352 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 353 if (PEAR::isError($res)) { 354 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 355 return ''; 356 } else { 357 return $res; 358 } 359 } 360 } 361 362 // benchmarking the included file (aka setup time) 363 if (APP_BENCHMARK) { 364 $GLOBALS['bench']->setMarker('Included Reminder_Condition Class'); 365 }
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 |