[ 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.email_response.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.misc.php"); 33 34 /** 35 * Class to handle the business logic related to the administration 36 * of canned email responses in the system. 37 * 38 * @version 1.0 39 * @author João Prado Maia <jpm@mysql.com> 40 */ 41 42 class Email_Response 43 { 44 /** 45 * Method used to add a project association to a email 46 * response entry. 47 * 48 * @access public 49 * @param integer $ere_id The email response ID 50 * @param integer $prj_id The project ID 51 * @return void 52 */ 53 function addProjectAssociation($ere_id, $prj_id) 54 { 55 $stmt = "INSERT INTO 56 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_email_response 57 ( 58 per_ere_id, 59 per_prj_id 60 ) VALUES ( 61 " . Misc::escapeInteger($ere_id) . ", 62 " . Misc::escapeInteger($prj_id) . " 63 )"; 64 $GLOBALS["db_api"]->dbh->query($stmt); 65 } 66 67 68 /** 69 * Method used to add a new canned email response to the system. 70 * 71 * @access public 72 * @return integer 1 if the insert worked, -1 otherwise 73 */ 74 function insert() 75 { 76 if (Validation::isWhitespace($_POST["title"])) { 77 return -2; 78 } 79 $stmt = "INSERT INTO 80 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_response 81 ( 82 ere_title, 83 ere_response_body 84 ) VALUES ( 85 '" . Misc::escapeString($_POST["title"]) . "', 86 '" . Misc::escapeString($_POST["response_body"]) . "' 87 )"; 88 $res = $GLOBALS["db_api"]->dbh->query($stmt); 89 if (PEAR::isError($res)) { 90 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 91 return -1; 92 } else { 93 $new_response_id = $GLOBALS["db_api"]->get_last_insert_id(); 94 // now populate the project-news mapping table 95 foreach ($_POST['projects'] as $prj_id) { 96 Email_Response::addProjectAssociation($new_response_id, $prj_id); 97 } 98 return 1; 99 } 100 } 101 102 103 /** 104 * Method used to remove a canned email response from the system. 105 * 106 * @access public 107 * @return boolean 108 */ 109 function remove() 110 { 111 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 112 $stmt = "DELETE FROM 113 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_response 114 WHERE 115 ere_id IN ($items)"; 116 $res = $GLOBALS["db_api"]->dbh->query($stmt); 117 if (PEAR::isError($res)) { 118 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 119 return false; 120 } else { 121 Email_Response::removeProjectAssociations($_POST['items']); 122 return true; 123 } 124 } 125 126 127 /** 128 * Method used to remove the project associations for a given 129 * email response entry. 130 * 131 * @access public 132 * @param integer $ere_id The email response ID 133 * @param integer $prj_id The project ID 134 * @return boolean 135 */ 136 function removeProjectAssociations($ere_id, $prj_id=FALSE) 137 { 138 $ere_id = Misc::escapeInteger($ere_id); 139 if (!is_array($ere_id)) { 140 $ere_id = array($ere_id); 141 } 142 $items = @implode(", ", $ere_id); 143 $stmt = "DELETE FROM 144 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_email_response 145 WHERE 146 per_ere_id IN ($items)"; 147 if ($prj_id) { 148 $stmt .= " AND per_prj_id=$prj_id"; 149 } 150 $res = $GLOBALS["db_api"]->dbh->query($stmt); 151 if (PEAR::isError($res)) { 152 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 153 return false; 154 } else { 155 return true; 156 } 157 } 158 159 160 /** 161 * Method used to update a canned email response in the system. 162 * 163 * @access public 164 * @return integer 1 if the update worked, -1 otherwise 165 */ 166 function update() 167 { 168 $_POST['id'] = Misc::escapeInteger($_POST['id']); 169 170 if (Validation::isWhitespace($_POST["title"])) { 171 return -2; 172 } 173 $stmt = "UPDATE 174 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_response 175 SET 176 ere_title='" . Misc::escapeString($_POST["title"]) . "', 177 ere_response_body='" . Misc::escapeString($_POST["response_body"]) . "' 178 WHERE 179 ere_id=" . $_POST["id"]; 180 $res = $GLOBALS["db_api"]->dbh->query($stmt); 181 if (PEAR::isError($res)) { 182 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 183 return -1; 184 } else { 185 // remove all of the associations with projects, then add them all again 186 Email_Response::removeProjectAssociations($_POST['id']); 187 foreach ($_POST['projects'] as $prj_id) { 188 Email_Response::addProjectAssociation($_POST['id'], $prj_id); 189 } 190 return 1; 191 } 192 } 193 194 195 /** 196 * Method used to get the details of a canned email response for a given 197 * response ID. 198 * 199 * @access public 200 * @param integer $ere_id The email response ID 201 * @return array The canned email response details 202 */ 203 function getDetails($ere_id) 204 { 205 $ere_id = Misc::escapeInteger($ere_id); 206 $stmt = "SELECT 207 * 208 FROM 209 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_response 210 WHERE 211 ere_id=$ere_id"; 212 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 213 if (PEAR::isError($res)) { 214 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 215 return ""; 216 } else { 217 // get all of the project associations here as well 218 $res['projects'] = array_keys(Email_Response::getAssociatedProjects($res['ere_id'])); 219 return $res; 220 } 221 } 222 223 224 /** 225 * Method used to get the list of associated projects for a given 226 * email response entry. 227 * 228 * @access public 229 * @param integer $ere_id The email response ID 230 * @return array The list of projects 231 */ 232 function getAssociatedProjects($ere_id) 233 { 234 $ere_id = Misc::escapeInteger($ere_id); 235 $stmt = "SELECT 236 prj_id, 237 prj_title 238 FROM 239 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project, 240 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_email_response 241 WHERE 242 prj_id=per_prj_id AND 243 per_ere_id=$ere_id"; 244 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 245 if (PEAR::isError($res)) { 246 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 247 return array(); 248 } else { 249 return $res; 250 } 251 } 252 253 254 /** 255 * Method used to get the list of canned email responses available in the 256 * system. 257 * 258 * @access public 259 * @return array The list of canned email responses 260 */ 261 function getList() 262 { 263 $stmt = "SELECT 264 ere_id, 265 ere_title 266 FROM 267 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_response 268 ORDER BY 269 ere_title ASC"; 270 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 271 if (PEAR::isError($res)) { 272 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 273 return ""; 274 } else { 275 // get the list of associated projects 276 for ($i = 0; $i < count($res); $i++) { 277 $res[$i]['projects'] = implode(", ", array_values(Email_Response::getAssociatedProjects($res[$i]['ere_id']))); 278 } 279 return $res; 280 } 281 } 282 283 284 /** 285 * Method used to get an associate array of all canned email responses 286 * available in the system. 287 * 288 * @access public 289 * @param integer $prj_id The project ID 290 * @return array The list of canned email responses 291 */ 292 function getAssocList($prj_id) 293 { 294 $stmt = "SELECT 295 ere_id, 296 ere_title 297 FROM 298 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_response, 299 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_email_response 300 WHERE 301 per_ere_id=ere_id AND 302 per_prj_id=" . Misc::escapeInteger($prj_id) . " 303 ORDER BY 304 ere_title ASC"; 305 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 306 if (PEAR::isError($res)) { 307 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 308 return ""; 309 } else { 310 return $res; 311 } 312 } 313 314 315 /** 316 * Method used to get an associative array of all of the canned email 317 * responses' bodies. 318 * 319 * @access public 320 * @param integer $prj_id The project ID 321 * @return array The list of canned email responses' bodies. 322 */ 323 function getAssocListBodies($prj_id) 324 { 325 $stmt = "SELECT 326 ere_id, 327 ere_response_body 328 FROM 329 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_response, 330 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_email_response 331 WHERE 332 per_ere_id=ere_id AND 333 per_prj_id=" . Misc::escapeInteger($prj_id); 334 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 335 if (PEAR::isError($res)) { 336 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 337 return ""; 338 } else { 339 // fix the newlines in the response bodies so javascript doesn't die 340 for ($i = 0; $i < count($res); $i++) { 341 $res[$i]['ere_response_body'] = Misc::escapeWhitespace($res[$i]['ere_response_body']); 342 $res[$i]['ere_response_body'] = str_replace('"', '\"', $res[$i]['ere_response_body']); 343 } 344 return $res; 345 } 346 } 347 } 348 349 // benchmarking the included file (aka setup time) 350 if (APP_BENCHMARK) { 351 $GLOBALS['bench']->setMarker('Included Email_Response Class'); 352 }
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 |