[ 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_account.php 3246 2007-02-09 09:10:12Z glen $ 29 // 30 31 32 require_once (APP_INC_PATH . "class.error_handler.php"); 33 34 class Email_Account 35 { 36 /** 37 * Method used to get the options related to the auto creation of 38 * new issues. 39 * 40 * @access public 41 * @param integer $ema_id The email account ID 42 * @return array The issue auto creation options 43 */ 44 function getIssueAutoCreationOptions($ema_id) 45 { 46 $stmt = "SELECT 47 ema_issue_auto_creation_options 48 FROM 49 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 50 WHERE 51 ema_id=$ema_id"; 52 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 53 if (PEAR::isError($res)) { 54 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 55 return ""; 56 } else { 57 if (!is_string($res)) { 58 $res = (string) $res; 59 } 60 return @unserialize($res); 61 } 62 } 63 64 65 /** 66 * Method used to update the issue auto creation related options. 67 * 68 * @access public 69 * @param integer $ema_id The email account ID 70 * @return integer 1 if the update worked, -1 otherwise 71 */ 72 function updateIssueAutoCreation($ema_id, $auto_creation, $options) 73 { 74 $stmt = "UPDATE 75 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 76 SET 77 ema_issue_auto_creation='" . Misc::escapeString($auto_creation) . "', 78 ema_issue_auto_creation_options='" . @serialize($options) . "' 79 WHERE 80 ema_id=" . Misc::escapeInteger($ema_id); 81 $res = $GLOBALS["db_api"]->dbh->query($stmt); 82 if (PEAR::isError($res)) { 83 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 84 return -1; 85 } else { 86 return 1; 87 } 88 } 89 90 91 /** 92 * Method used to get the support email account associated with a given 93 * support email message. 94 * 95 * @access public 96 * @param integer $sup_id The support email ID 97 * @return integer The email account ID 98 */ 99 function getAccountByEmail($sup_id) 100 { 101 $stmt = "SELECT 102 sup_ema_id 103 FROM 104 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email 105 WHERE 106 sup_id=$sup_id"; 107 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 108 if (PEAR::isError($res)) { 109 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 110 return ""; 111 } else { 112 return $res; 113 } 114 } 115 116 117 /** 118 * Method used to get the account ID for a given email account. 119 * 120 * @access public 121 * @param string $username The username for the specific email account 122 * @param string $hostname The hostname for the specific email account 123 * @param string $mailbox The mailbox for the specific email account 124 * @return integer The support email account ID 125 */ 126 function getAccountID($username, $hostname, $mailbox) 127 { 128 $stmt = "SELECT 129 ema_id 130 FROM 131 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 132 WHERE 133 ema_username='" . Misc::escapeString($username) . "' AND 134 ema_hostname='" . Misc::escapeString($hostname) . "' AND 135 ema_folder='" . Misc::escapeString($mailbox) . "'"; 136 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 137 if (PEAR::isError($res)) { 138 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 139 return 0; 140 } else { 141 if ($res == NULL) { 142 return 0; 143 } else { 144 return $res; 145 } 146 } 147 } 148 149 150 /** 151 * Method used to get the project ID associated with a given email account. 152 * 153 * @access public 154 * @param integer $ema_id The support email account ID 155 * @return integer The project ID 156 */ 157 function getProjectID($ema_id) 158 { 159 $details = Email_Account::getDetails($ema_id); 160 return $details['ema_prj_id']; 161 } 162 163 164 /** 165 * Method used to get the details of a given support email 166 * account. 167 * 168 * @access public 169 * @param integer $ema_id The support email account ID 170 * @return array The account details 171 */ 172 function getDetails($ema_id) 173 { 174 $ema_id = Misc::escapeInteger($ema_id); 175 $stmt = "SELECT 176 * 177 FROM 178 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 179 WHERE 180 ema_id=$ema_id"; 181 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 182 if (PEAR::isError($res)) { 183 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 184 return ""; 185 } else { 186 $res['ema_issue_auto_creation_options'] = @unserialize($res['ema_issue_auto_creation_options']); 187 return $res; 188 } 189 } 190 191 192 /** 193 * Method used to remove all support email accounts associated 194 * with a specified set of projects. 195 * 196 * @access public 197 * @param array $ids The list of projects 198 * @return boolean 199 */ 200 function removeAccountByProjects($ids) 201 { 202 $items = @implode(", ", Misc::escapeInteger($ids)); 203 $stmt = "SELECT 204 ema_id 205 FROM 206 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 207 WHERE 208 ema_prj_id IN ($items)"; 209 $res = $GLOBALS["db_api"]->dbh->getCol($stmt); 210 if (PEAR::isError($res)) { 211 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 212 return false; 213 } else { 214 Support::removeEmailByAccounts($res); 215 $stmt = "DELETE FROM 216 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 217 WHERE 218 ema_prj_id IN ($items)"; 219 $res = $GLOBALS["db_api"]->dbh->query($stmt); 220 if (PEAR::isError($res)) { 221 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 222 return false; 223 } else { 224 return true; 225 } 226 } 227 } 228 229 230 /** 231 * Method used to remove the specified support email accounts. 232 * 233 * @access public 234 * @return boolean 235 */ 236 function remove() 237 { 238 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 239 $stmt = "DELETE FROM 240 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 241 WHERE 242 ema_id IN ($items)"; 243 $res = $GLOBALS["db_api"]->dbh->query($stmt); 244 if (PEAR::isError($res)) { 245 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 246 return false; 247 } else { 248 Support::removeEmailByAccounts($_POST["items"]); 249 return true; 250 } 251 } 252 253 254 /** 255 * Method used to add a new support email account. 256 * 257 * @access public 258 * @return integer 1 if the update worked, -1 otherwise 259 */ 260 function insert() 261 { 262 if (empty($_POST["get_only_new"])) { 263 $_POST["get_only_new"] = 0; 264 } 265 if (empty($_POST["leave_copy"])) { 266 $_POST["leave_copy"] = 0; 267 } 268 if (empty($_POST["use_routing"])) { 269 $_POST["use_routing"] = 0; 270 } elseif ($_POST['use_routing'] == 1) { 271 // if an account will be used for routing, you can't leave the message on the server 272 $_POST['leave_copy'] = 0; 273 } 274 $stmt = "INSERT INTO 275 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 276 ( 277 ema_prj_id, 278 ema_type, 279 ema_hostname, 280 ema_port, 281 ema_folder, 282 ema_username, 283 ema_password, 284 ema_get_only_new, 285 ema_leave_copy, 286 ema_use_routing 287 ) VALUES ( 288 " . Misc::escapeInteger($_POST["project"]) . ", 289 '" . Misc::escapeString($_POST["type"]) . "', 290 '" . Misc::escapeString($_POST["hostname"]) . "', 291 '" . Misc::escapeString($_POST["port"]) . "', 292 '" . Misc::escapeString(@$_POST["folder"]) . "', 293 '" . Misc::escapeString($_POST["username"]) . "', 294 '" . Misc::escapeString($_POST["password"]) . "', 295 " . Misc::escapeInteger($_POST["get_only_new"]) . ", 296 " . Misc::escapeInteger($_POST["leave_copy"]) . ", 297 " . Misc::escapeInteger($_POST["use_routing"]) . " 298 )"; 299 $res = $GLOBALS["db_api"]->dbh->query($stmt); 300 if (PEAR::isError($res)) { 301 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 302 return -1; 303 } else { 304 return 1; 305 } 306 } 307 308 309 /** 310 * Method used to update a support email account details. 311 * 312 * @access public 313 * @return integer 1 if the update worked, -1 otherwise 314 */ 315 function update() 316 { 317 if (empty($_POST["get_only_new"])) { 318 $_POST["get_only_new"] = 0; 319 } 320 if (empty($_POST["leave_copy"])) { 321 $_POST["leave_copy"] = 0; 322 } 323 if (empty($_POST["use_routing"])) { 324 $_POST["use_routing"] = 0; 325 } elseif ($_POST['use_routing'] == 1) { 326 // if an account will be used for routing, you can't leave the message on the server 327 $_POST['leave_copy'] = 0; 328 } 329 $stmt = "UPDATE 330 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 331 SET 332 ema_prj_id=" . Misc::escapeInteger($_POST["project"]) . ", 333 ema_type='" . Misc::escapeString($_POST["type"]) . "', 334 ema_hostname='" . Misc::escapeString($_POST["hostname"]) . "', 335 ema_port='" . Misc::escapeString($_POST["port"]) . "', 336 ema_folder='" . Misc::escapeString(@$_POST["folder"]) . "', 337 ema_username='" . Misc::escapeString($_POST["username"]) . "', 338 ema_password='" . Misc::escapeString($_POST["password"]) . "', 339 ema_get_only_new=" . Misc::escapeInteger($_POST["get_only_new"]) . ", 340 ema_leave_copy=" . Misc::escapeInteger($_POST["leave_copy"]) . ", 341 ema_use_routing=" . Misc::escapeInteger($_POST["use_routing"]) . " 342 WHERE 343 ema_id=" . $_POST["id"]; 344 $res = $GLOBALS["db_api"]->dbh->query($stmt); 345 if (PEAR::isError($res)) { 346 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 347 return -1; 348 } else { 349 return 1; 350 } 351 } 352 353 354 /** 355 * Method used to get the list of available support email 356 * accounts in the system. 357 * 358 * @access public 359 * @return array The list of accounts 360 */ 361 function getList() 362 { 363 $stmt = "SELECT 364 * 365 FROM 366 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 367 ORDER BY 368 ema_hostname"; 369 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 370 if (PEAR::isError($res)) { 371 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 372 return ""; 373 } else { 374 for ($i = 0; $i < count($res); $i++) { 375 $res[$i]["prj_title"] = Project::getName($res[$i]["ema_prj_id"]); 376 } 377 return $res; 378 } 379 } 380 381 382 /** 383 * Method used to get an associative array of the support email 384 * accounts in the format of account ID => account title. 385 * 386 * @access public 387 * @param integer $projects An array of project IDs 388 * @return array The list of accounts 389 */ 390 function getAssocList($projects, $include_project_title = false) 391 { 392 $projects = Misc::escapeInteger($projects); 393 if (!is_array($projects)) { 394 $projects = array($projects); 395 } 396 if ($include_project_title) { 397 $title_sql = "CONCAT(prj_title, ': ', ema_username, '@', ema_hostname, ' ', ema_folder)"; 398 } else { 399 $title_sql = "CONCAT(ema_username, '@', ema_hostname, ' ', ema_folder)"; 400 } 401 $stmt = "SELECT 402 ema_id, 403 $title_sql AS ema_title 404 FROM 405 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account, 406 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project 407 WHERE 408 prj_id = ema_prj_id AND 409 ema_prj_id IN (" . join(',', $projects) . ") 410 ORDER BY 411 ema_title"; 412 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 413 if (PEAR::isError($res)) { 414 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 415 return ""; 416 } else { 417 return $res; 418 } 419 } 420 421 422 /** 423 * Method used to get the first support email account associated 424 * with the current activated project. 425 * 426 * @access public 427 * @param integer $prj_id The ID of the project. If blank the currently project will be used. 428 * @return integer The email account ID 429 */ 430 function getEmailAccount($prj_id = false) 431 { 432 if ($prj_id == false) { 433 $prj_id = Auth::getCurrentProject(); 434 } 435 $stmt = "SELECT 436 ema_id 437 FROM 438 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account 439 WHERE 440 ema_prj_id=" . Misc::escapeInteger($prj_id) . " 441 LIMIT 442 0, 1"; 443 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 444 if (PEAR::isError($res)) { 445 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 446 return ""; 447 } else { 448 return $res; 449 } 450 } 451 452 453 /** 454 * Method used to get the email account associated with the given 455 * issue' project. 456 * 457 * @access public 458 * @param integer $issue_id The issue ID 459 * @return integer The email account ID 460 */ 461 function getEmailAccountByIssueID($issue_id) 462 { 463 $stmt = "SELECT 464 ema_id 465 FROM 466 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account, 467 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue 468 WHERE 469 ema_prj_id=iss_prj_id AND 470 iss_id=$issue_id"; 471 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 472 if (PEAR::isError($res)) { 473 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 474 return ""; 475 } else { 476 return $res; 477 } 478 } 479 } 480 481 // benchmarking the included file (aka setup time) 482 if (APP_BENCHMARK) { 483 $GLOBALS['bench']->setMarker('Included Email_Account Class'); 484 }
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 |