[ 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.customer.php 3394 2007-11-04 08:33:06Z balsdorf $ 29 // 30 31 require_once (APP_INC_PATH . 'class.misc.php'); 32 33 // Constants used by customer class. 34 define("CUSTOMER_EXCLUDE_EXPIRED", 1); 35 36 class Customer 37 { 38 /** 39 * Returns the list of available customer backends by listing the class 40 * files in the backend directory. 41 * 42 * @access public 43 * @return array Associative array of filename => name 44 */ 45 function getBackendList() 46 { 47 $files = Misc::getFileList(APP_INC_PATH . "customer"); 48 $list = array(); 49 for ($i = 0; $i < count($files); $i++) { 50 // make sure we only list the customer backends 51 if (preg_match('/^class\./', $files[$i])) { 52 // display a prettyfied backend name in the admin section 53 preg_match('/class\.(.*)\.php/', $files[$i], $matches); 54 if ($matches[1] == "abstract_customer_backend") { 55 continue; 56 } 57 $name = ucwords(str_replace('_', ' ', $matches[1])); 58 $list[$files[$i]] = $name; 59 } 60 } 61 return $list; 62 } 63 64 65 /** 66 * Returns the customer backend class file associated with the given 67 * project ID. 68 * 69 * @access public 70 * @param integer $prj_id The project ID 71 * @return string The customer backend class filename 72 */ 73 function _getBackendNameByProject($prj_id) 74 { 75 static $backends; 76 77 if (isset($backends[$prj_id])) { 78 return $backends[$prj_id]; 79 } 80 81 $stmt = "SELECT 82 prj_id, 83 prj_customer_backend 84 FROM 85 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project 86 ORDER BY 87 prj_id"; 88 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 89 if (PEAR::isError($res)) { 90 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 91 return ''; 92 } else { 93 $backends = $res; 94 return @$backends[$prj_id]; 95 } 96 } 97 98 99 /** 100 * Includes the appropriate customer backend class associated with the 101 * given project ID, instantiates it and returns the class. 102 * 103 * @access private 104 * @param integer $prj_id The project ID 105 * @return boolean 106 */ 107 function &_getBackend($prj_id) 108 { 109 static $setup_backends; 110 111 if (empty($setup_backends[$prj_id])) { 112 $backend_class = Customer::_getBackendNameByProject($prj_id); 113 if (empty($backend_class)) { 114 $setup_backends[$prj_id] = false; 115 } else { 116 $file_name_chunks = explode(".", $backend_class); 117 $class_name = $file_name_chunks[1] . "_Customer_Backend"; 118 119 require_once(APP_INC_PATH . "customer/$backend_class"); 120 121 $setup_backends[$prj_id] = new $class_name; 122 $setup_backends[$prj_id]->connect(); 123 } 124 } 125 return $setup_backends[$prj_id]; 126 } 127 128 129 /** 130 * Checks whether the given project ID is setup to use customer integration 131 * or not. 132 * 133 * @access public 134 * @param integer $prj_id The project ID 135 * @return boolean 136 */ 137 function hasCustomerIntegration($prj_id) 138 { 139 $backend = Customer::_getBackendNameByProject($prj_id); 140 if (empty($backend)) { 141 return false; 142 } else { 143 return true; 144 } 145 } 146 147 148 // XXX: put documentation here 149 function getBackendImplementationName($prj_id) 150 { 151 if (!Customer::hasCustomerIntegration($prj_id)) { 152 return ''; 153 } 154 $backend =& Customer::_getBackend($prj_id); 155 return $backend->getName(); 156 } 157 158 159 /** 160 * Returns true if the backend uses support levels, false otherwise 161 * 162 * @access public 163 * @param integer $prj_id The project ID 164 * @return boolean True if the project uses support levels. 165 */ 166 function doesBackendUseSupportLevels($prj_id) 167 { 168 $backend =& Customer::_getBackend($prj_id); 169 if ($backend === FALSE) { 170 return false; 171 } else { 172 return $backend->usesSupportLevels(); 173 } 174 } 175 176 177 /** 178 * Returns the contract status associated with the given customer ID. 179 * Possible return values are 'active', 'in_grace_period' and 'expired'. 180 * 181 * @access public 182 * @param integer $prj_id The project ID 183 * @param integer $customer_id The customer ID 184 * @param integer $contract_id The contract ID 185 * @return string The contract status 186 */ 187 function getContractStatus($prj_id, $customer_id, $contract_id = false) 188 { 189 $backend =& Customer::_getBackend($prj_id); 190 return $backend->getContractStatus($customer_id, $contract_id); 191 } 192 193 194 195 /** 196 * Retrieves the customer titles associated with the given list of issues. 197 * 198 * @access public 199 * @param integer $prj_id The project ID 200 * @param array $result The list of issues 201 * @see Issue::getListing() 202 */ 203 function getCustomerTitlesByIssues($prj_id, &$result) 204 { 205 $backend =& Customer::_getBackend($prj_id); 206 $backend->getCustomerTitlesByIssues($result); 207 } 208 209 210 211 /** 212 * Retrieves the support levels associated with the given list of issues. 213 * 214 * @access public 215 * @param integer $prj_id The project ID 216 * @param array $result The list of issues 217 * @see Issue::getListing() 218 */ 219 function getSupportLevelsByIssues($prj_id, &$result) 220 { 221 $backend =& Customer::_getBackend($prj_id); 222 $backend->getSupportLevelsByIssues($result); 223 } 224 225 226 /** 227 * Method used to get the details of the given customer. 228 * 229 * @access public 230 * @param integer $prj_id The project ID 231 * @param integer $customer_id The customer ID 232 * @param boolean $force_refresh If the cache should not be used. 233 * @param integer $contract_id The contract ID 234 * @return array The customer details 235 */ 236 function getDetails($prj_id, $customer_id, $force_refresh = false, $contract_id = false) 237 { 238 $backend =& Customer::_getBackend($prj_id); 239 return $backend->getDetails($customer_id, $force_refresh, $contract_id); 240 } 241 242 243 /** 244 * Returns true if this issue has been counted a valid incident 245 * 246 * @see /docs/Customer_API.html 247 * @access public 248 * @param integer $prj_id The project ID 249 * @param integer $issue_id The ID of the issue 250 * @param integer $incident_type The type of incident 251 * @return boolean True if this is a redeemed incident. 252 */ 253 function isRedeemedIncident($prj_id, $issue_id, $incident_type = false) 254 { 255 $backend =& Customer::_getBackend($prj_id); 256 return $backend->isRedeemedIncident($issue_id, $incident_type); 257 } 258 259 260 /** 261 * Returns an array of the curently redeemed incident types for the issue. 262 * 263 * @see /docs/Customer_API.html 264 * @access public 265 * @param integer $prj_id The project ID 266 * @return array An array containing the redeemed incident types 267 */ 268 function getRedeemedIncidentDetails($prj_id, $issue_id) 269 { 270 $types = Customer::getIncidentTypes($prj_id); 271 $data = array(); 272 foreach ($types as $id => $title) { 273 if (Customer::isRedeemedIncident($prj_id, $issue_id, $id)) { 274 $data[$id] = array( 275 'title' => $title, 276 'is_redeemed' => 1 277 ); 278 } 279 } 280 return $data; 281 } 282 283 284 /** 285 * Updates the incident counts 286 * 287 * @access public 288 * @param integer $prj_id The project ID 289 * @param integer $issue_id The issue ID 290 * @param array $data An array of data containing which incident types to update. 291 * @return integer 1 if all updates were successful, -1 or -2 otherwise. 292 */ 293 function updateRedeemedIncidents($prj_id, $issue_id, $data) 294 { 295 $details = Customer::getDetails($prj_id, Issue::getCustomerID($issue_id), Issue::getContractID($issue_id)); 296 foreach ($details['incident_details'] as $type_id => $type_details) { 297 $is_redeemed = Customer::isRedeemedIncident($prj_id, $issue_id, $type_id); 298 if (($is_redeemed) && (@$data[$type_id] != 1)) { 299 // un-redeem issue 300 $res = Customer::unflagIncident($prj_id, $issue_id, $type_id); 301 } elseif ((!$is_redeemed) && (@$data[$type_id] == 1)) { 302 // redeem issue 303 if (($type_details['total'] - $type_details['redeemed']) > 0) { 304 $res = Customer::flagIncident($prj_id, $issue_id, $type_id); 305 } else { 306 $res = -1; 307 } 308 } else { 309 $res = 1; 310 } 311 if ($res != 1) { 312 return $res; 313 } 314 } 315 return $res; 316 } 317 318 319 /** 320 * Marks an issue as a redeemed incident. 321 * @see /docs/Customer_API.html 322 * @access public 323 * @param integer $prj_id The project ID 324 * @param integer $issue_id The ID of the issue 325 * @param integer $incident_type The type of incident 326 */ 327 function flagIncident($prj_id, $issue_id, $incident_type) 328 { 329 $backend =& Customer::_getBackend($prj_id); 330 return $backend->flagIncident($issue_id, $incident_type); 331 } 332 333 334 /** 335 * Marks an issue as not a redeemed incident. 336 * 337 * @see /docs/Customer_API.html 338 * @access public 339 * @param integer $prj_id The project ID 340 * @param integer $issue_id The ID of the issue 341 * @param integer $incident_type The type of incident 342 */ 343 function unflagIncident($prj_id, $issue_id, $incident_type) 344 { 345 $backend =& Customer::_getBackend($prj_id); 346 return $backend->unflagIncident($issue_id, $incident_type); 347 } 348 349 350 /** 351 * Checks whether the active per-incident contract associated with the given 352 * customer ID has any incidents available to be redeemed. 353 * 354 * @access public 355 * @param integer $prj_id The project ID 356 * @param integer $customer_id The customer ID 357 * @param integer $incident_type The type of incident 358 * @return boolean 359 */ 360 function hasIncidentsLeft($prj_id, $customer_id, $incident_type = false) 361 { 362 $backend =& Customer::_getBackend($prj_id); 363 return $backend->hasIncidentsLeft($customer_id, $incident_type); 364 } 365 366 367 /** 368 * Checks whether the active contract associated with the given customer ID 369 * is a per-incident contract or not. 370 * 371 * @access public 372 * @param integer $prj_id The project ID 373 * @param integer $customer_id The customer ID 374 * @return boolean 375 */ 376 function hasPerIncidentContract($prj_id, $customer_id) 377 { 378 $backend =& Customer::_getBackend($prj_id); 379 return $backend->hasPerIncidentContract($customer_id); 380 } 381 382 383 /** 384 * Returns the total number of allowed incidents for the given support 385 * contract ID. 386 * 387 * @access public 388 * @param integer $prj_id The project ID 389 * @param integer $support_no The support contract ID 390 * @param integer $incident_type The type of incident 391 * @return integer The total number of incidents 392 */ 393 function getTotalIncidents($prj_id, $support_no, $incident_type) 394 { 395 $backend =& Customer::_getBackend($prj_id); 396 return $backend->getTotalIncidents($support_no, $incident_type); 397 } 398 399 400 /** 401 * Returns the number of incidents remaining for the given support 402 * contract ID. 403 * 404 * @access public 405 * @param integer $prj_id The project ID 406 * @param integer $support_no The support contract ID 407 * @param integer $incident_type The type of incident 408 * @return integer The number of incidents remaining. 409 */ 410 function getIncidentsRemaining($prj_id, $support_no, $incident_type) 411 { 412 $backend =& Customer::_getBackend($prj_id); 413 return $backend->getIncidentsRemaining($support_no, $incident_type); 414 } 415 416 417 /** 418 * Returns the incident types available. 419 * 420 * @access public 421 * @param integer $prj_id The project ID 422 * @return array An array of per incident types 423 */ 424 function getIncidentTypes($prj_id) 425 { 426 $backend =& Customer::_getBackend($prj_id); 427 return $backend->getIncidentTypes(); 428 } 429 430 431 /** 432 * Method used to send a notice that the per-incident limit being reached. 433 * 434 * @access public 435 * @param integer $prj_id The project ID 436 * @param integer $contact_id The customer contact ID 437 * @param integer $customer_id The customer ID 438 * @param boolean $new_issue If the customer just tried to create a new issue. 439 * @return void 440 */ 441 function sendIncidentLimitNotice($prj_id, $contact_id, $customer_id, $new_issue = false) 442 { 443 $backend =& Customer::_getBackend($prj_id); 444 return $backend->sendIncidentLimitNotice($contact_id, $customer_id, $new_issue); 445 } 446 447 448 /** 449 * Returns a list of customers (companies) in the customer database. 450 * 451 * @access public 452 * @param integer $prj_id The project ID 453 * @return array An associated array of customers. 454 */ 455 function getAssocList($prj_id) 456 { 457 $backend =& Customer::_getBackend($prj_id); 458 return $backend->getAssocList(); 459 } 460 461 462 /** 463 * Method used to get the customer names for the given customer id. 464 * 465 * @access public 466 * @param integer $customer_id The customer ID 467 * @return string The customer name 468 */ 469 function getTitle($prj_id, $customer_id) 470 { 471 $backend =& Customer::_getBackend($prj_id); 472 if ($backend === FALSE) { 473 return ''; 474 } else { 475 return $backend->getTitle($customer_id); 476 } 477 } 478 479 480 /** 481 * Method used to get an associative array of the customer names 482 * for the given list of customer ids. 483 * 484 * @access public 485 * @param array $customer_ids The list of customers 486 * @return array The associative array of customer id => customer name 487 */ 488 function getTitles($prj_id, $customer_ids) 489 { 490 $backend =& Customer::_getBackend($prj_id); 491 return $backend->getTitles($customer_ids); 492 } 493 494 495 /** 496 * Method used to get the list of email addresses associated with the 497 * contacts of a given customer. 498 * 499 * @access public 500 * @param integer $customer_id The customer ID 501 * @return array The list of email addresses 502 */ 503 function getContactEmailAssocList($prj_id, $customer_id) 504 { 505 $backend =& Customer::_getBackend($prj_id); 506 return $backend->getContactEmailAssocList($customer_id); 507 } 508 509 510 /** 511 * Method used to get the customer and customer contact IDs associated 512 * with a given list of email addresses. 513 * 514 * @access public 515 * @param array $emails The list of email addresses 516 * @return array The customer and customer contact ID 517 */ 518 function getCustomerIDByEmails($prj_id, $emails) 519 { 520 $backend =& Customer::_getBackend($prj_id); 521 return $backend->getCustomerIDByEmails($emails); 522 } 523 524 525 /** 526 * Method used to get the overall statistics of issues in the system for a 527 * given customer. 528 * 529 * @access public 530 * @param integer $customer_id The customer ID 531 * @return array The customer related issue statistics 532 */ 533 function getOverallStats($prj_id, $customer_id) 534 { 535 $backend =& Customer::_getBackend($prj_id); 536 return $backend->getOverallStats($customer_id); 537 } 538 539 540 /** 541 * Method used to build the overall customer profile from the information 542 * stored in the customer database. 543 * 544 * @access public 545 * @param integer $usr_id The Eventum user ID 546 * @return array The customer profile information 547 */ 548 function getProfile($prj_id, $usr_id) 549 { 550 $backend =& Customer::_getBackend($prj_id); 551 return $backend->getProfile($usr_id); 552 } 553 554 555 /** 556 * Method used to get the contract details for a given customer contact. 557 * 558 * @access public 559 * @param integer $contact_id The customer contact ID 560 * @return array The customer contract details 561 */ 562 function getContractDetails($prj_id, $contact_id, $restrict_expiration = TRUE) 563 { 564 $backend =& Customer::_getBackend($prj_id); 565 return $backend->getContractDetails($contact_id, $restrict_expiration); 566 } 567 568 569 /** 570 * Method used to get the details associated with a customer contact. 571 * 572 * @access public 573 * @param integer $prj_id The project ID 574 * @param integer $contact_id The customer contact ID 575 * @return array The contact details 576 */ 577 function getContactDetails($prj_id, $contact_id) 578 { 579 $backend =& Customer::_getBackend($prj_id); 580 return $backend->getContactDetails($contact_id); 581 } 582 583 584 /** 585 * Returns the list of customer IDs that are associated with the given 586 * email value (wildcards welcome). 587 * 588 * @access public 589 * @param integer $prj_id The project ID 590 * @param string $email The email value 591 * @return array The list of customer IDs 592 */ 593 function getCustomerIDsLikeEmail($prj_id, $email) 594 { 595 $backend =& Customer::_getBackend($prj_id); 596 return $backend->getCustomerIDsLikeEmail($email); 597 } 598 599 600 /** 601 * Method used to notify the customer contact that an existing issue 602 * associated with him was just marked as closed. 603 * 604 * @access public 605 * @param integer $prj_id The project ID 606 * @param integer $issue_id The issue ID 607 * @param integer $contact_id The customer contact ID 608 * @param boolean $send_notification Whether to send a notification about this action or not 609 * @param integer $resolution_id The resolution ID 610 * @param integer $status_id The status ID 611 * @param string $reason The reason for closing this issue 612 * @return void 613 */ 614 function notifyIssueClosed($prj_id, $issue_id, $contact_id, $send_notification, $resolution_id, $status_id, $reason) 615 { 616 $backend =& Customer::_getBackend($prj_id); 617 return $backend->notifyIssueClosed($issue_id, $contact_id, $send_notification, $resolution_id, $status_id, $reason); 618 } 619 620 621 /** 622 * Performs a customer lookup and returns the matches, if 623 * appropriate. 624 * 625 * @access public 626 * @param integer $prj_id The project ID 627 * @param string $field The field that we are trying to search against 628 * @param string $value The value that we are searching for 629 * @return array The list of customers 630 */ 631 function lookup($prj_id, $field, $value) 632 { 633 $backend =& Customer::_getBackend($prj_id); 634 return $backend->lookup($field, $value); 635 } 636 637 638 /** 639 * Method used to notify the customer contact that a new issue was just 640 * created and associated with his Eventum user. 641 * 642 * @access public 643 * @param integer $prj_id The project ID 644 * @param integer $issue_id The issue ID 645 * @param integer $contact_id The customer contact ID 646 * @return void 647 */ 648 function notifyCustomerIssue($prj_id, $issue_id, $contact_id) 649 { 650 $backend =& Customer::_getBackend($prj_id); 651 return $backend->notifyCustomerIssue($issue_id, $contact_id); 652 } 653 654 655 /** 656 * Method used to get the list of available support levels. 657 * 658 * @access public 659 * @param integer $prj_id The project ID 660 * @return array The list of available support levels 661 */ 662 function getSupportLevelAssocList($prj_id) 663 { 664 $backend =& Customer::_getBackend($prj_id); 665 return $backend->getSupportLevelAssocList(); 666 } 667 668 669 /** 670 * Returns the support level of the current support contract for a given 671 * customer ID. 672 * 673 * @access public 674 * @param integer $prj_id The project ID 675 * @param integer $customer_id The customer ID 676 * @param integer $contract_id The contract ID 677 * @return string The support contract level 678 */ 679 function getSupportLevelID($prj_id, $customer_id, $contract_id = false) 680 { 681 $backend =& Customer::_getBackend($prj_id); 682 return $backend->getSupportLevelID($customer_id, $contract_id); 683 } 684 685 686 /** 687 * Returns the list of customer IDs for a given support contract level. 688 * 689 * @access public 690 * @param integer $prj_id The project ID 691 * @param integer $support_level_id The support level ID 692 * @param mixed $support_options An integer or array of integers indicating various options to get customers with. 693 * @return array The list of customer IDs 694 */ 695 function getListBySupportLevel($prj_id, $support_level_id, $support_options = false) 696 { 697 $backend =& Customer::_getBackend($prj_id); 698 return $backend->getListBySupportLevel($support_level_id, $support_options); 699 } 700 701 702 /** 703 * Returns an array of support levels grouped together. 704 * 705 * @access public 706 * @param integer $prj_id The project ID 707 * @return array an array of support levels. 708 */ 709 function getGroupedSupportLevels($prj_id) 710 { 711 $backend =& Customer::_getBackend($prj_id); 712 return $backend->getGroupedSupportLevels($prj_id); 713 } 714 715 716 /** 717 * Method used to send an expiration notice. 718 * 719 * @access public 720 * @param integer $prj_id The project ID 721 * @param integer $contact_id The customer contact ID 722 * @param boolean $is_expired Whether this customer is expired or not 723 * @param string $contract_id The contract ID 724 * @return void 725 */ 726 function sendExpirationNotice($prj_id, $contact_id, $is_expired = FALSE, $contract_id = false) 727 { 728 $backend =& Customer::_getBackend($prj_id); 729 return $backend->sendExpirationNotice($contact_id, $is_expired, $contract_id); 730 } 731 732 733 /** 734 * Checks whether the given technical contact ID is allowed in the current 735 * support contract or not. 736 * 737 * @access public 738 * @param integer $prj_id The project ID 739 * @param integer $customer_contact_id The customer technical contact ID 740 * @return boolean 741 */ 742 function isAllowedSupportContact($prj_id, $customer_contact_id) 743 { 744 $backend =& Customer::_getBackend($prj_id); 745 return $backend->isAllowedSupportContact($customer_contact_id); 746 } 747 748 749 /** 750 * Method used to get the associated customer and customer contact from 751 * a given set of support emails. This is especially useful to automatically 752 * associate an issue to the appropriate customer contact that sent a 753 * support email. 754 * 755 * @access public 756 * @param integer $prj_id The project ID 757 * @param array $sup_ids The list of support email IDs 758 * @return array The customer and customer contact ID 759 */ 760 function getCustomerInfoFromEmails($prj_id, $sup_ids) 761 { 762 $backend =& Customer::_getBackend($prj_id); 763 return $backend->getCustomerInfoFromEmails($sup_ids); 764 } 765 766 767 /** 768 * Method used to send an email notification to the sender of a 769 * set of email messages that were manually converted into an 770 * issue. 771 * 772 * @access public 773 * @param integer $prj_id The project ID 774 * @param integer $issue_id The issue ID 775 * @param array $sup_ids The email IDs 776 * @param integer $customer_id The customer ID 777 * @return array The list of recipient emails 778 */ 779 function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = FALSE) 780 { 781 $backend =& Customer::_getBackend($prj_id); 782 return $backend->notifyEmailConvertedIntoIssue($issue_id, $sup_ids, $customer_id); 783 } 784 785 786 /** 787 * Method used to send an email notification to the sender of an 788 * email message that was automatically converted into an issue. 789 * 790 * @access public 791 * @param integer $prj_id The project ID 792 * @param integer $issue_id The issue ID 793 * @param string $sender The sender of the email message (and the recipient of this notification) 794 * @param string $date The arrival date of the email message 795 * @param string $subject The subject line of the email message 796 * @return void 797 */ 798 function notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $subject) 799 { 800 $backend =& Customer::_getBackend($prj_id); 801 return $backend->notifyAutoCreatedIssue($issue_id, $sender, $date, $subject); 802 } 803 804 805 /** 806 * Method used to get the customer login grace period (number of days). 807 * 808 * @access public 809 * @param integer $prj_id The project ID 810 * @return integer The customer login grace period 811 */ 812 function getExpirationOffset($prj_id) 813 { 814 $backend =& Customer::_getBackend($prj_id); 815 return $backend->_getExpirationOffset(); 816 } 817 818 819 /** 820 * Method used to get the details of the given customer contact. 821 * 822 * @access public 823 * @param integer $prj_id The project ID 824 * @param integer $contact_id The customer contact ID 825 * @return array The customer details 826 */ 827 function getContactLoginDetails($prj_id, $contact_id) 828 { 829 $backend =& Customer::_getBackend($prj_id); 830 return $backend->getContactLoginDetails($contact_id); 831 } 832 833 834 /** 835 * Returns the end date of the current support contract for a given 836 * customer ID. 837 * 838 * @access public 839 * @param integer $prj_id The project ID 840 * @param integer $customer_id The customer ID 841 * @param integer $contract_id The contract ID 842 * @return string The support contract end date 843 */ 844 function getContractEndDate($prj_id, $customer_id, $contract_id = false) 845 { 846 $backend =& Customer::_getBackend($prj_id); 847 return $backend->getContractEndDate($customer_id, $contract_id); 848 } 849 850 851 /** 852 * Returns the name and email of the sales account manager of the given customer ID. 853 * 854 * @access public 855 * @param integer $prj_id The project ID 856 * @param integer $customer_id The customer ID 857 * @return array An array containing the name and email of the sales account manager 858 */ 859 function getSalesAccountManager($prj_id, $customer_id) 860 { 861 $backend =& Customer::_getBackend($prj_id); 862 return $backend->getSalesAccountManager($customer_id); 863 } 864 865 866 /** 867 * Returns the start date of the current support contract for a given 868 * customer ID. 869 * 870 * @access public 871 * @param integer $prj_id The project ID 872 * @param integer $customer_id The customer ID 873 * @param integer $contract_id The contract ID 874 * @return string The support contract start date 875 */ 876 function getContractStartDate($prj_id, $customer_id, $contract_id = false) 877 { 878 $backend =& Customer::_getBackend($prj_id); 879 return $backend->getContractStartDate($customer_id, $contract_id); 880 } 881 882 883 /** 884 * Returns a message to be displayed to a customer on the top of the issue creation page. 885 * 886 * @param integer $prj_id The project ID 887 * @param array $customer_id Customer ID. 888 */ 889 function getNewIssueMessage($prj_id, $customer_id) 890 { 891 $backend =& Customer::_getBackend($prj_id); 892 return $backend->getNewIssueMessage($customer_id); 893 } 894 895 896 /** 897 * Return what business hours a customer falls into. Mainly used for international 898 * customers. 899 * 900 * @access public 901 * @param integer $prj_id The project ID 902 * @param integer $customer_id The customer ID 903 * @return string The business hours 904 */ 905 function getBusinessHours($prj_id, $customer_id) 906 { 907 $backend =& Customer::_getBackend($prj_id); 908 return $backend->getBusinessHours($customer_id); 909 } 910 911 912 /** 913 * Checks whether the given customer has a support contract that 914 * enforces limits for the minimum first response time or not. 915 * 916 * @access public 917 * @param integer $prj_id The project ID 918 * @param integer $customer_id The customer ID 919 * @param integer $contract_id The contract ID 920 * @return boolean 921 */ 922 function hasMinimumResponseTime($prj_id, $customer_id, $contract_id = false) 923 { 924 $backend =& Customer::_getBackend($prj_id); 925 return $backend->hasMinimumResponseTime($customer_id, $contract_id); 926 } 927 928 929 /** 930 * Returns the minimum first response time in seconds for the 931 * support level associated with the given customer. 932 * 933 * @access public 934 * @param integer $customer_id The customer ID 935 * @param integer $contract_id The contract ID 936 * @return integer The minimum first response time 937 */ 938 function getMinimumResponseTime($prj_id, $customer_id, $contract_id = false) 939 { 940 $backend =& Customer::_getBackend($prj_id); 941 return $backend->getMinimumResponseTime($customer_id, $contract_id); 942 } 943 944 945 /** 946 * Returns the maximum first response time associated with the 947 * support contract of the given customer. 948 * 949 * @access public 950 * @param integer $customer_id The customer ID 951 * @param integer $contract_id The contract ID 952 * @return integer The maximum first response time, in seconds 953 */ 954 function getMaximumFirstResponseTime($prj_id, $customer_id, $contract_id = false) 955 { 956 $backend =& Customer::_getBackend($prj_id); 957 return $backend->getMaximumFirstResponseTime($customer_id, $contract_id); 958 } 959 960 961 /** 962 * Performs needed checks to see if a contact can login. Performs some default 963 * checks if the backend does not implement checks 964 * 965 * @param integer $prj_id 966 * @param integer $customer_id 967 * @param integer $contact_id 968 */ 969 function authenticateCustomer($prj_id, $customer_id, $contact_id) 970 { 971 $backend =& Customer::_getBackend($prj_id); 972 if (method_exists($backend, 'authenticateCustomer')) { 973 $backend->authenticateCustomer($customer_id, $contact_id); 974 } else { 975 // check if customer is expired 976 $usr_id = Auth::getUserID(); 977 $contact_id = User::getCustomerContactID($usr_id); 978 if ((!empty($contact_id)) && ($contact_id != -1)) { 979 $status = Customer::getContractStatus($prj_id, User::getCustomerID($usr_id)); 980 $email = User::getEmailByContactID($contact_id); 981 if ($status == 'expired') { 982 Customer::sendExpirationNotice($prj_id, $contact_id, true); 983 Auth::saveLoginAttempt($email, 'failure', 'expired contract'); 984 985 Auth::removeCookie(APP_PROJECT_COOKIE); 986 987 $contact_id = User::getCustomerContactID($usr_id); 988 $tpl->setTemplate("customer/" . Customer::getBackendImplementationName($prj_id) . "/customer_expired.tpl.html"); 989 $tpl->assign('customer', Customer::getContractDetails($prj_id, $contact_id, false)); 990 $tpl->displayTemplate(); 991 exit; 992 } elseif ($status == 'in_grace_period') { 993 Customer::sendExpirationNotice($prj_id, $contact_id); 994 $tpl->setTemplate("customer/" . Customer::getBackendImplementationName($prj_id) . "/grace_period.tpl.html"); 995 $tpl->assign('customer', Customer::getContractDetails($prj_id, $contact_id, false)); 996 $tpl->assign('expiration_offset', Customer::getExpirationOffset($prj_id)); 997 $tpl->displayTemplate(); 998 exit; 999 } 1000 // check with cnt_support to see if this contact is allowed in this support contract 1001 if (!Customer::isAllowedSupportContact($prj_id, $contact_id)) { 1002 Auth::saveLoginAttempt($email, 'failure', 'not allowed as technical contact'); 1003 Auth::redirect(APP_RELATIVE_URL . "index.php?err=4&email=" . $email); 1004 } 1005 } 1006 } 1007 } 1008 1009 /** 1010 * Method used to get the list of technical account managers 1011 * currently available in the system. 1012 * 1013 * @access public 1014 * @return array The list of account managers 1015 */ 1016 function getAccountManagerList() 1017 { 1018 $stmt = "SELECT 1019 cam_id, 1020 cam_prj_id, 1021 cam_customer_id, 1022 cam_type, 1023 usr_full_name 1024 FROM 1025 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager, 1026 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user 1027 WHERE 1028 cam_usr_id=usr_id"; 1029 $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 1030 if (PEAR::isError($res)) { 1031 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1032 return ""; 1033 } else { 1034 for ($i = 0; $i < count($res); $i++) { 1035 $res[$i]['customer_title'] = Customer::getTitle($res[$i]['cam_prj_id'], $res[$i]['cam_customer_id']); 1036 } 1037 return $res; 1038 } 1039 } 1040 1041 1042 /** 1043 * Method used to add a new association of Eventum user => 1044 * customer ID. This association will provide the basis for a 1045 * new role of technical account manager in Eventum. 1046 * 1047 * @access public 1048 * @return integer 1 if the insert worked properly, any other value otherwise 1049 */ 1050 function insertAccountManager() 1051 { 1052 $stmt = "INSERT INTO 1053 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager 1054 ( 1055 cam_prj_id, 1056 cam_customer_id, 1057 cam_usr_id, 1058 cam_type 1059 ) VALUES ( 1060 " . Misc::escapeInteger($_POST['project']) . ", 1061 " . Misc::escapeInteger($_POST['customer']) . ", 1062 " . Misc::escapeInteger($_POST['manager']) . ", 1063 '" . Misc::escapeString($_POST['type']) . "' 1064 )"; 1065 $res = $GLOBALS["db_api"]->dbh->query($stmt); 1066 if (PEAR::isError($res)) { 1067 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1068 return -1; 1069 } else { 1070 return 1; 1071 } 1072 } 1073 1074 1075 /** 1076 * Method used to get the details of a given account manager. 1077 * 1078 * @access public 1079 * @param integer $cam_id The account manager ID 1080 * @return array The account manager details 1081 */ 1082 function getAccountManagerDetails($cam_id) 1083 { 1084 $stmt = "SELECT 1085 * 1086 FROM 1087 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager 1088 WHERE 1089 cam_id=" . Misc::escapeInteger($cam_id); 1090 $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 1091 if (PEAR::isError($res)) { 1092 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1093 return array(); 1094 } else { 1095 return $res; 1096 } 1097 } 1098 1099 1100 /** 1101 * Method used to update the details of an account manager. 1102 * 1103 * @access public 1104 * @return integer 1 if the update worked properly, any other value otherwise 1105 */ 1106 function updateAccountManager() 1107 { 1108 $stmt = "UPDATE 1109 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager 1110 SET 1111 cam_prj_id=" . Misc::escapeInteger($_POST['project']) . ", 1112 cam_customer_id=" . Misc::escapeInteger($_POST['customer']) . ", 1113 cam_usr_id=" . Misc::escapeInteger($_POST['manager']) . ", 1114 cam_type='" . Misc::escapeString($_POST['type']) . "' 1115 WHERE 1116 cam_id=" . $_POST['id']; 1117 $res = $GLOBALS["db_api"]->dbh->query($stmt); 1118 if (PEAR::isError($res)) { 1119 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1120 return -1; 1121 } else { 1122 return 1; 1123 } 1124 } 1125 1126 1127 /** 1128 * Method used to remove a technical account manager from the 1129 * system. 1130 * 1131 * @access public 1132 * @return boolean 1133 */ 1134 function removeAccountManager() 1135 { 1136 $items = @implode(", ", Misc::escapeInteger($_POST["items"])); 1137 $stmt = "DELETE FROM 1138 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager 1139 WHERE 1140 cam_id IN ($items)"; 1141 $res = $GLOBALS["db_api"]->dbh->query($stmt); 1142 if (PEAR::isError($res)) { 1143 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1144 return false; 1145 } else { 1146 return true; 1147 } 1148 } 1149 1150 1151 /** 1152 * Method used to get the list of technical account managers for 1153 * a given customer ID. 1154 * 1155 * @access public 1156 * @param integer $prj_id The project ID 1157 * @param integer $customer_id The customer ID 1158 * @return array The list of account managers 1159 */ 1160 function getAccountManagers($prj_id, $customer_id) 1161 { 1162 $stmt = "SELECT 1163 cam_usr_id, 1164 usr_email 1165 FROM 1166 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager, 1167 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user 1168 WHERE 1169 cam_usr_id=usr_id AND 1170 cam_prj_id=" . Misc::escapeInteger($prj_id) . " AND 1171 cam_customer_id=" . Misc::escapeInteger($customer_id); 1172 $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt); 1173 if (PEAR::isError($res)) { 1174 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1175 return array(); 1176 } else { 1177 if (empty($res)) { 1178 return array(); 1179 } else { 1180 return $res; 1181 } 1182 } 1183 } 1184 1185 1186 /** 1187 * Returns any notes for for the specified customer. 1188 * 1189 * @access public 1190 * @param integer $customer_id The customer ID 1191 * @return array An array containg the note details. 1192 */ 1193 function getNoteDetailsByCustomer($customer_id) 1194 { 1195 $stmt = "SELECT 1196 cno_id, 1197 cno_prj_id, 1198 cno_customer_id, 1199 cno_note 1200 FROM 1201 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note 1202 WHERE 1203 cno_customer_id = " . Misc::escapeInteger($customer_id); 1204 $res = $GLOBALS['db_api']->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 1205 if (PEAR::isError($res)) { 1206 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1207 return array(); 1208 } else { 1209 return $res; 1210 } 1211 } 1212 1213 1214 /** 1215 * Returns any note details for for the specified id. 1216 * 1217 * @access public 1218 * @param integer $customer_id The customer ID 1219 * @return array An array containg the note details. 1220 */ 1221 function getNoteDetailsByID($cno_id) 1222 { 1223 $stmt = "SELECT 1224 cno_prj_id, 1225 cno_customer_id, 1226 cno_note 1227 FROM 1228 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note 1229 WHERE 1230 cno_id = " . Misc::escapeInteger($cno_id); 1231 $res = $GLOBALS['db_api']->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); 1232 if (PEAR::isError($res)) { 1233 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1234 return array(); 1235 } else { 1236 return $res; 1237 } 1238 } 1239 1240 1241 /** 1242 * Returns an array of notes for all customers. 1243 * 1244 * @access public 1245 * @return array An array of notes. 1246 */ 1247 function getNoteList() 1248 { 1249 $stmt = "SELECT 1250 cno_id, 1251 cno_prj_id, 1252 cno_customer_id, 1253 cno_note 1254 FROM 1255 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note 1256 ORDER BY 1257 cno_customer_id ASC"; 1258 $res = $GLOBALS['db_api']->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); 1259 if (PEAR::isError($res)) { 1260 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1261 return array(); 1262 } else { 1263 for ($i = 0; $i < count($res); $i++) { 1264 $res[$i]['customer_title'] = Customer::getTitle($res[$i]['cno_prj_id'], $res[$i]['cno_customer_id']); 1265 } 1266 return $res; 1267 } 1268 } 1269 1270 1271 /** 1272 * Updates a note. 1273 * 1274 * @access public 1275 * @param integer $cno_id The id of this note. 1276 * @param integer $prj_id The project ID 1277 * @param integer $customer_id The id of the customer. 1278 * @param string $note The text of this note. 1279 */ 1280 function updateNote($cno_id, $prj_id, $customer_id, $note) 1281 { 1282 $stmt = "UPDATE 1283 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note 1284 SET 1285 cno_note='" . Misc::escapeString($note) . "', 1286 cno_prj_id=" . Misc::escapeInteger($prj_id) . ", 1287 cno_customer_id=" . Misc::escapeInteger($customer_id) . ", 1288 cno_updated_date='" . Date_API::getCurrentDateGMT() . "' 1289 WHERE 1290 cno_id=" . Misc::escapeInteger($cno_id); 1291 $res = $GLOBALS['db_api']->dbh->query($stmt); 1292 if (PEAR::isError($res)) { 1293 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1294 return -1; 1295 } else { 1296 return 1; 1297 } 1298 } 1299 1300 1301 /** 1302 * Adds a quick note for the specified customer. 1303 * 1304 * @access public 1305 * @param integer $prj_id The project ID 1306 * @param integer $customer_id The id of the customer. 1307 * @param string $note The note to add. 1308 */ 1309 function insertNote($prj_id, $customer_id, $note) 1310 { 1311 $stmt = "INSERT INTO 1312 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note 1313 ( 1314 cno_prj_id, 1315 cno_customer_id, 1316 cno_created_date, 1317 cno_updated_date, 1318 cno_note 1319 ) VALUES ( 1320 " . Misc::escapeInteger($prj_id) . ", 1321 " . Misc::escapeInteger($customer_id) . ", 1322 '" . Date_API::getCurrentDateGMT() . "', 1323 '" . Date_API::getCurrentDateGMT() . "', 1324 '" . Misc::escapeString($note) . "' 1325 )"; 1326 $res = $GLOBALS['db_api']->dbh->query($stmt); 1327 if (PEAR::isError($res)) { 1328 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1329 return -1; 1330 } else { 1331 return 1; 1332 } 1333 } 1334 1335 1336 /** 1337 * Removes the selected notes from the database. 1338 * 1339 * @access public 1340 * @param array $ids An array of cno_id's to be deleted. 1341 */ 1342 function removeNotes($ids) 1343 { 1344 $stmt = "DELETE FROM 1345 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note 1346 WHERE 1347 cno_id IN (" . join(", ", Misc::escapeInteger($ids)) . ")"; 1348 $res = $GLOBALS['db_api']->dbh->query($stmt); 1349 if (PEAR::isError($res)) { 1350 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 1351 return -1; 1352 } else { 1353 return 1; 1354 } 1355 } 1356 }
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 |