2
/* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
3
// +----------------------------------------------------------------------+
4
// | Eventum - Issue Tracking System |
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 2003 - 2008 MySQL AB |
7
// | Copyright (c) 2008 - 2010 Sun Microsystem Inc. |
8
// | Copyright (c) 2011 - 2013 Eventum Team. |
10
// | This program is free software; you can redistribute it and/or modify |
11
// | it under the terms of the GNU General Public License as published by |
12
// | the Free Software Foundation; either version 2 of the License, or |
13
// | (at your option) any later version. |
15
// | This program is distributed in the hope that it will be useful, |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
// | GNU General Public License for more details. |
20
// | You should have received a copy of the GNU General Public License |
21
// | along with this program; if not, write to: |
23
// | Free Software Foundation, Inc. |
24
// | 59 Temple Place - Suite 330 |
25
// | Boston, MA 02111-1307, USA. |
26
// +----------------------------------------------------------------------+
27
// | Authors: João Prado Maia <jpm@mysql.com> |
28
// +----------------------------------------------------------------------+
31
// Constants used by customer class.
32
define("CUSTOMER_EXCLUDE_EXPIRED", 1);
37
* Returns the list of available customer backends by listing the class
38
* files in the backend directory.
41
* @return array Associative array of filename => name
43
function getBackendList()
45
$files = Misc::getFileList(APP_INC_PATH . '/customer');
46
$files = array_merge($files, Misc::getFileList(APP_LOCAL_PATH. '/customer'));
48
for ($i = 0; $i < count($files); $i++) {
49
// make sure we only list the customer backends
50
if (preg_match('/^class\.(.*)\.php$/', $files[$i], $matches)) {
51
// display a prettyfied backend name in the admin section
52
if ($matches[1] == "abstract_customer_backend") {
55
$name = ucwords(str_replace('_', ' ', $matches[1]));
56
$list[$files[$i]] = $name;
64
* Returns the customer backend class file associated with the given
67
* @param integer $prj_id The project ID
68
* @return string The customer backend class filename
70
private static function _getBackendNameByProject($prj_id)
74
if (isset($backends[$prj_id])) {
75
return $backends[$prj_id];
82
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project
85
$res = DB_Helper::getInstance()->getAssoc($stmt);
86
if (PEAR::isError($res)) {
87
/** @var $res PEAR_Error */
88
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
92
return @$backends[$prj_id];
98
* Includes the appropriate customer backend class associated with the
99
* given project ID, instantiates it and returns the class.
101
* @param integer $prj_id The project ID
102
* @return Abstract_Customer_Backend
104
public static function &_getBackend($prj_id)
106
static $setup_backends;
108
if (empty($setup_backends[$prj_id])) {
109
$backend_class = self::_getBackendNameByProject($prj_id);
110
if (empty($backend_class)) {
111
$setup_backends[$prj_id] = false;
113
$file_name_chunks = explode(".", $backend_class);
114
$class_name = $file_name_chunks[1] . "_Customer_Backend";
117
if (file_exists(APP_LOCAL_PATH . "/customer/$backend_class")) {
118
require_once(APP_LOCAL_PATH . "/customer/$backend_class");
120
require_once APP_INC_PATH . "/customer/$backend_class";
123
$setup_backends[$prj_id] = new $class_name;
124
$setup_backends[$prj_id]->connect();
127
return $setup_backends[$prj_id];
132
* Checks whether the given project ID is setup to use customer integration
135
* @param integer $prj_id The project ID
138
public static function hasCustomerIntegration($prj_id)
140
$backend = self::_getBackendNameByProject($prj_id);
141
if (empty($backend)) {
149
// XXX: put documentation here
150
public static function getBackendImplementationName($prj_id)
152
if (!self::hasCustomerIntegration($prj_id)) {
155
$backend =& self::_getBackend($prj_id);
156
return $backend->getName();
161
* Returns true if the backend uses support levels, false otherwise
164
* @param integer $prj_id The project ID
165
* @return boolean True if the project uses support levels.
167
function doesBackendUseSupportLevels($prj_id)
169
$backend =& self::_getBackend($prj_id);
170
if ($backend === FALSE) {
173
return $backend->usesSupportLevels();
179
* Returns the contract status associated with the given customer ID.
180
* Possible return values are 'active', 'in_grace_period' and 'expired'.
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
187
public static function getContractStatus($prj_id, $customer_id, $contract_id = false)
189
$backend =& self::_getBackend($prj_id);
190
return $backend->getContractStatus($customer_id, $contract_id);
196
* Retrieves the customer titles associated with the given list of issues.
199
* @param integer $prj_id The project ID
200
* @param array $result The list of issues
201
* @see Search::getListing()
203
function getCustomerTitlesByIssues($prj_id, &$result)
205
$backend =& self::_getBackend($prj_id);
206
$backend->getCustomerTitlesByIssues($result);
212
* Retrieves the support levels associated with the given list of issues.
215
* @param integer $prj_id The project ID
216
* @param array $result The list of issues
217
* @see Search::getListing()
219
function getSupportLevelsByIssues($prj_id, &$result)
221
$backend =& self::_getBackend($prj_id);
222
$backend->getSupportLevelsByIssues($result);
227
* Method used to get the details of the given customer.
229
* @param integer $prj_id The project ID
230
* @param integer $customer_id The customer ID
231
* @param boolean $force_refresh If the cache should not be used.
232
* @param bool|int $contract_id The contract ID
233
* @param bool|int $contact_id
234
* @return array The customer details
236
public static function getDetails($prj_id, $customer_id, $force_refresh = false, $contract_id = false,
239
$backend =& self::_getBackend($prj_id);
240
return $backend->getDetails($customer_id, $force_refresh, $contract_id, $contact_id);
245
* Returns true if this issue has been counted a valid incident
247
* @see /docs/Customer_API.html
249
* @param integer $prj_id The project ID
250
* @param integer $issue_id The ID of the issue
251
* @param integer $incident_type The type of incident
252
* @return boolean True if this is a redeemed incident.
254
function isRedeemedIncident($prj_id, $issue_id, $incident_type = false)
256
$backend =& self::_getBackend($prj_id);
257
return $backend->isRedeemedIncident($issue_id, $incident_type);
262
* Returns an array of the curently redeemed incident types for the issue.
264
* @see /docs/Customer_API.html
266
* @param integer $prj_id The project ID
267
* @return array An array containing the redeemed incident types
269
function getRedeemedIncidentDetails($prj_id, $issue_id)
271
$types = self::getIncidentTypes($prj_id);
273
foreach ($types as $id => $title) {
274
if (self::isRedeemedIncident($prj_id, $issue_id, $id)) {
286
* Updates the incident counts
289
* @param integer $prj_id The project ID
290
* @param integer $issue_id The issue ID
291
* @param array $data An array of data containing which incident types to update.
292
* @return integer 1 if all updates were successful, -1 or -2 otherwise.
294
function updateRedeemedIncidents($prj_id, $issue_id, $data)
296
$details = self::getDetails($prj_id, Issue::getCustomerID($issue_id), Issue::getContractID($issue_id));
297
foreach ($details['incident_details'] as $type_id => $type_details) {
298
$is_redeemed = self::isRedeemedIncident($prj_id, $issue_id, $type_id);
299
if (($is_redeemed) && (@$data[$type_id] != 1)) {
301
$res = self::unflagIncident($prj_id, $issue_id, $type_id);
302
} elseif ((!$is_redeemed) && (@$data[$type_id] == 1)) {
304
if (($type_details['total'] - $type_details['redeemed']) > 0) {
305
$res = self::flagIncident($prj_id, $issue_id, $type_id);
321
* Marks an issue as a redeemed incident.
322
* @see /docs/Customer_API.html
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
327
public static function flagIncident($prj_id, $issue_id, $incident_type)
329
$backend =& self::_getBackend($prj_id);
330
return $backend->flagIncident($issue_id, $incident_type);
335
* Marks an issue as not a redeemed incident.
337
* @see /docs/Customer_API.html
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
343
function unflagIncident($prj_id, $issue_id, $incident_type)
345
$backend =& self::_getBackend($prj_id);
346
return $backend->unflagIncident($issue_id, $incident_type);
351
* Checks whether the active per-incident contract associated with the given
352
* customer ID has any incidents available to be redeemed.
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
360
function hasIncidentsLeft($prj_id, $customer_id, $incident_type = false)
362
$backend =& self::_getBackend($prj_id);
363
return $backend->hasIncidentsLeft($customer_id, $incident_type);
368
* Checks whether the active contract associated with the given customer ID
369
* is a per-incident contract or not.
372
* @param integer $prj_id The project ID
373
* @param integer $customer_id The customer ID
376
function hasPerIncidentContract($prj_id, $customer_id)
378
$backend =& self::_getBackend($prj_id);
379
return $backend->hasPerIncidentContract($customer_id);
384
* Returns the total number of allowed incidents for the given support
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
393
function getTotalIncidents($prj_id, $support_no, $incident_type)
395
$backend =& self::_getBackend($prj_id);
396
return $backend->getTotalIncidents($support_no, $incident_type);
401
* Returns the number of incidents remaining for the given support
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.
410
function getIncidentsRemaining($prj_id, $support_no, $incident_type)
412
$backend =& self::_getBackend($prj_id);
413
return $backend->getIncidentsRemaining($support_no, $incident_type);
418
* Returns the incident types available.
421
* @param integer $prj_id The project ID
422
* @return array An array of per incident types
424
function getIncidentTypes($prj_id)
426
$backend =& self::_getBackend($prj_id);
427
return $backend->getIncidentTypes();
432
* Method used to send a notice that the per-incident limit being reached.
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.
441
function sendIncidentLimitNotice($prj_id, $contact_id, $customer_id, $new_issue = false)
443
$backend =& self::_getBackend($prj_id);
444
return $backend->sendIncidentLimitNotice($contact_id, $customer_id, $new_issue);
449
* Returns a list of customers (companies) in the customer database.
452
* @param integer $prj_id The project ID
453
* @return array An associated array of customers.
455
function getAssocList($prj_id)
457
$backend =& self::_getBackend($prj_id);
458
return $backend->getAssocList();
463
* Method used to get the customer names for the given customer id.
465
* @param integer $customer_id The customer ID
466
* @return string The customer name
468
public static function getTitle($prj_id, $customer_id)
470
$backend =& self::_getBackend($prj_id);
471
if ($backend === FALSE) {
474
return $backend->getTitle($customer_id);
480
* Method used to get an associative array of the customer names
481
* for the given list of customer ids.
484
* @param array $customer_ids The list of customers
485
* @return array The associative array of customer id => customer name
487
function getTitles($prj_id, $customer_ids)
489
// TODO: this or backend prototype mismatches
490
$backend =& self::_getBackend($prj_id);
491
return $backend->getTitles($customer_ids);
496
* Method used to get the list of email addresses associated with the
497
* contacts of a given customer.
500
* @param integer $customer_id The customer ID
501
* @return array The list of email addresses
503
function getContactEmailAssocList($prj_id, $customer_id)
505
$backend =& self::_getBackend($prj_id);
506
return $backend->getContactEmailAssocList($customer_id);
511
* Method used to get the customer and customer contact IDs associated
512
* with a given list of email addresses.
515
* @param array $emails The list of email addresses
516
* @return array The customer and customer contact ID
518
function getCustomerIDByEmails($prj_id, $emails)
520
$backend =& self::_getBackend($prj_id);
521
return $backend->getCustomerIDByEmails($emails);
526
* Method used to get the overall statistics of issues in the system for a
530
* @param integer $customer_id The customer ID
531
* @return array The customer related issue statistics
533
function getOverallStats($prj_id, $customer_id)
535
$backend =& self::_getBackend($prj_id);
536
return $backend->getOverallStats($customer_id);
541
* Method used to build the overall customer profile from the information
542
* stored in the customer database.
545
* @param integer $usr_id The Eventum user ID
546
* @return array The customer profile information
548
function getProfile($prj_id, $usr_id)
550
$backend =& self::_getBackend($prj_id);
551
return $backend->getProfile($usr_id);
556
* Method used to get the contract details for a given customer contact.
559
* @param integer $contact_id The customer contact ID
560
* @return array The customer contract details
562
function getContractDetails($prj_id, $contact_id, $restrict_expiration = TRUE)
564
$backend =& self::_getBackend($prj_id);
565
return $backend->getContractDetails($contact_id, $restrict_expiration);
570
* Method used to get the details associated with a customer contact.
573
* @param integer $prj_id The project ID
574
* @param integer $contact_id The customer contact ID
575
* @return array The contact details
577
function getContactDetails($prj_id, $contact_id)
579
$backend =& self::_getBackend($prj_id);
580
return $backend->getContactDetails($contact_id);
585
* Returns the list of customer IDs that are associated with the given
586
* email value (wildcards welcome).
589
* @param integer $prj_id The project ID
590
* @param string $email The email value
591
* @return array The list of customer IDs
593
function getCustomerIDsLikeEmail($prj_id, $email)
595
$backend =& self::_getBackend($prj_id);
596
return $backend->getCustomerIDsLikeEmail($email);
601
* Method used to notify the customer contact that an existing issue
602
* associated with him was just marked as closed.
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
614
function notifyIssueClosed($prj_id, $issue_id, $contact_id, $send_notification, $resolution_id, $status_id, $reason)
616
$backend =& self::_getBackend($prj_id);
617
return $backend->notifyIssueClosed($issue_id, $contact_id, $send_notification, $resolution_id, $status_id, $reason);
622
* Performs a customer lookup and returns the matches, if
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
* @param array $options An array of options for search
630
* @return array The list of customers
632
function lookup($prj_id, $field, $value, $options=array())
634
$backend =& self::_getBackend($prj_id);
635
return $backend->lookup($field, $value, $options);
640
* Method used to notify the customer contact that a new issue was just
641
* created and associated with his Eventum user.
644
* @param integer $prj_id The project ID
645
* @param integer $issue_id The issue ID
646
* @param integer $contact_id The customer contact ID
649
function notifyCustomerIssue($prj_id, $issue_id, $contact_id)
651
$backend =& self::_getBackend($prj_id);
652
return $backend->notifyCustomerIssue($issue_id, $contact_id);
657
* Method used to get the list of available support levels.
660
* @param integer $prj_id The project ID
661
* @return array The list of available support levels
663
function getSupportLevelAssocList($prj_id)
665
$backend =& self::_getBackend($prj_id);
666
return $backend->getSupportLevelAssocList();
671
* Returns the support level of the current support contract for a given
675
* @param integer $prj_id The project ID
676
* @param integer $customer_id The customer ID
677
* @param integer $contract_id The contract ID
678
* @return string The support contract level
680
function getSupportLevelID($prj_id, $customer_id, $contract_id = false)
682
$backend =& self::_getBackend($prj_id);
683
return $backend->getSupportLevelID($customer_id, $contract_id);
688
* Returns the list of customer IDs for a given support contract level.
691
* @param integer $prj_id The project ID
692
* @param integer $support_level_id The support level ID
693
* @param mixed $support_options An integer or array of integers indicating various options to get customers with.
694
* @return array The list of customer IDs
696
function getListBySupportLevel($prj_id, $support_level_id, $support_options = false)
698
$backend =& self::_getBackend($prj_id);
699
return $backend->getListBySupportLevel($support_level_id, $support_options);
704
* Returns an array of support levels grouped together.
706
* @param integer $prj_id The project ID
707
* @return array an array of support levels.
709
public static function getGroupedSupportLevels($prj_id)
711
$backend =& self::_getBackend($prj_id);
712
return $backend->getGroupedSupportLevels($prj_id);
717
* Method used to send an expiration notice.
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
726
function sendExpirationNotice($prj_id, $contact_id, $is_expired = FALSE, $contract_id = false)
728
$backend =& self::_getBackend($prj_id);
729
return $backend->sendExpirationNotice($contact_id, $is_expired, $contract_id);
734
* Checks whether the given technical contact ID is allowed in the current
735
* support contract or not.
738
* @param integer $prj_id The project ID
739
* @param integer $customer_contact_id The customer technical contact ID
742
function isAllowedSupportContact($prj_id, $customer_contact_id)
744
$backend =& self::_getBackend($prj_id);
745
return $backend->isAllowedSupportContact($customer_contact_id);
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
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
760
function getCustomerInfoFromEmails($prj_id, $sup_ids)
762
$backend =& self::_getBackend($prj_id);
763
return $backend->getCustomerInfoFromEmails($sup_ids);
768
* Method used to send an email notification to the sender of a
769
* set of email messages that were manually converted into an
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
779
function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = FALSE)
781
$backend =& self::_getBackend($prj_id);
782
return $backend->notifyEmailConvertedIntoIssue($issue_id, $sup_ids, $customer_id);
787
* Method used to send an email notification to the sender of an
788
* email message that was automatically converted into an issue.
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
798
function notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $subject)
800
$backend =& self::_getBackend($prj_id);
801
return $backend->notifyAutoCreatedIssue($issue_id, $sender, $date, $subject);
806
* Method used to get the customer login grace period (number of days).
809
* @param integer $prj_id The project ID
810
* @return integer The customer login grace period
812
function getExpirationOffset($prj_id)
814
$backend =& self::_getBackend($prj_id);
815
return $backend->_getExpirationOffset();
820
* Method used to get the details of the given customer contact.
823
* @param integer $prj_id The project ID
824
* @param integer $contact_id The customer contact ID
825
* @return array The customer details
827
function getContactLoginDetails($prj_id, $contact_id)
829
$backend =& self::_getBackend($prj_id);
830
return $backend->getContactLoginDetails($contact_id);
835
* Returns the end date of the current support contract for a given
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
844
function getContractEndDate($prj_id, $customer_id, $contract_id = false)
846
$backend =& self::_getBackend($prj_id);
847
return $backend->getContractEndDate($customer_id, $contract_id);
852
* Returns the name and email of the sales account manager of the given customer ID.
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
859
function getSalesAccountManager($prj_id, $customer_id)
861
$backend =& self::_getBackend($prj_id);
862
return $backend->getSalesAccountManager($customer_id);
867
* Returns the start date of the current support contract for a given
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
876
function getContractStartDate($prj_id, $customer_id, $contract_id = false)
878
$backend =& self::_getBackend($prj_id);
879
return $backend->getContractStartDate($customer_id, $contract_id);
884
* Returns a message to be displayed to a customer on the top of the issue creation page.
886
* @param integer $prj_id The project ID
887
* @param array $customer_id Customer ID.
889
function getNewIssueMessage($prj_id, $customer_id)
891
$backend =& self::_getBackend($prj_id);
892
return $backend->getNewIssueMessage($customer_id);
897
* Return what business hours a customer falls into. Mainly used for international
901
* @param integer $prj_id The project ID
902
* @param integer $customer_id The customer ID
903
* @return string The business hours
905
function getBusinessHours($prj_id, $customer_id)
907
$backend =& self::_getBackend($prj_id);
908
return $backend->getBusinessHours($customer_id);
913
* Checks whether the given customer has a support contract that
914
* enforces limits for the minimum first response time or not.
917
* @param integer $prj_id The project ID
918
* @param integer $customer_id The customer ID
919
* @param integer $contract_id The contract ID
922
function hasMinimumResponseTime($prj_id, $customer_id, $contract_id = false)
924
$backend =& self::_getBackend($prj_id);
925
return $backend->hasMinimumResponseTime($customer_id, $contract_id);
930
* Returns the minimum first response time in seconds for the
931
* support level associated with the given customer.
934
* @param integer $customer_id The customer ID
935
* @param integer $contract_id The contract ID
936
* @return integer The minimum first response time
938
function getMinimumResponseTime($prj_id, $customer_id, $contract_id = false)
940
$backend =& self::_getBackend($prj_id);
941
return $backend->getMinimumResponseTime($customer_id, $contract_id);
946
* Returns the maximum first response time associated with the
947
* support contract of the given customer.
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
954
function getMaximumFirstResponseTime($prj_id, $customer_id, $contract_id = false)
956
$backend =& self::_getBackend($prj_id);
957
return $backend->getMaximumFirstResponseTime($customer_id, $contract_id);
962
* Returns the path php files for this customer backend are stored in.
964
* @param integer $prj_id The project ID
966
function getPath($prj_id)
968
$backend =& self::_getBackend($prj_id);
969
if (method_exists($backend, 'getPath')) {
970
return $backend->getPath();
972
return 'customer/' . $backend->getName() . '/';
978
* Returns the path templates for this customer backend are stored in.
980
* @param integer $prj_id The project ID
982
function getTemplatePath($prj_id)
984
$backend =& self::_getBackend($prj_id);
985
if (method_exists($backend, 'getTemplatePath')) {
986
return $backend->getTemplatePath();
988
return 'customer/' . Customer::getBackendImplementationName($prj_id) . '/';
994
* Returns if the specified customer / contract has the specified feature
996
* @param integer $prj_id The project ID
997
* @param string $customer_id
998
* @param string $contract_id
999
* @param string $feature
1000
* @return boolean True if the contract has the feature, false otherwise.
1002
function hasFeature($prj_id, $customer_id, $contract_id, $feature)
1004
$backend =& self::_getBackend($prj_id);
1005
if (method_exists($backend, 'hasFeature')) {
1006
return $backend->hasFeature($customer_id, $contract_id, $feature);
1014
* Performs needed checks to see if a contact can login. Performs some default
1015
* checks if the backend does not implement checks
1017
* @param integer $prj_id
1018
* @param integer $customer_id
1019
* @param integer $contact_id
1021
function authenticateCustomer($prj_id, $customer_id, $contact_id)
1023
$tpl = new Template_Helper();
1024
$backend =& self::_getBackend($prj_id);
1025
if (method_exists($backend, 'authenticateCustomer')) {
1026
$backend->authenticateCustomer($customer_id, $contact_id);
1028
// check if customer is expired
1029
$usr_id = Auth::getUserID();
1030
$contact_id = User::getCustomerContactID($usr_id);
1031
if ((!empty($contact_id)) && ($contact_id != -1)) {
1032
$status = self::getContractStatus($prj_id, User::getCustomerID($usr_id));
1033
$email = User::getEmailByContactID($contact_id);
1034
if ($status == 'expired') {
1035
self::sendExpirationNotice($prj_id, $contact_id, true);
1036
Auth::saveLoginAttempt($email, 'failure', 'expired contract');
1038
Auth::removeCookie(APP_PROJECT_COOKIE);
1040
$contact_id = User::getCustomerContactID($usr_id);
1041
$tpl->setTemplate(Customer::getTemplatePath($prj_id) . "/customer_expired.tpl.html");
1042
$tpl->assign('customer', self::getContractDetails($prj_id, $contact_id, false));
1043
$tpl->displayTemplate();
1045
} elseif ($status == 'in_grace_period') {
1046
self::sendExpirationNotice($prj_id, $contact_id);
1047
$tpl->setTemplate(Customer::getTemplatePath($prj_id) . "/grace_period.tpl.html");
1048
$tpl->assign('customer', self::getContractDetails($prj_id, $contact_id, false));
1049
$tpl->assign('expiration_offset', self::getExpirationOffset($prj_id));
1050
$tpl->displayTemplate();
1053
// check with cnt_support to see if this contact is allowed in this support contract
1054
if (!self::isAllowedSupportContact($prj_id, $contact_id)) {
1055
Auth::saveLoginAttempt($email, 'failure', 'not allowed as technical contact');
1056
Auth::removeCookie(APP_COOKIE);
1057
Auth::redirect("index.php?err=4&email=" . $email);
1064
* Method used to get the list of technical account managers
1065
* currently available in the system.
1068
* @return array The list of account managers
1070
function getAccountManagerList()
1079
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager,
1080
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user
1083
$res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
1084
if (PEAR::isError($res)) {
1085
/** @var $res PEAR_Error */
1086
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1089
for ($i = 0; $i < count($res); $i++) {
1090
$res[$i]['customer_title'] = self::getTitle($res[$i]['cam_prj_id'], $res[$i]['cam_customer_id']);
1098
* Method used to add a new association of Eventum user =>
1099
* customer ID. This association will provide the basis for a
1100
* new role of technical account manager in Eventum.
1103
* @return integer 1 if the insert worked properly, any other value otherwise
1105
function insertAccountManager()
1107
$stmt = "INSERT INTO
1108
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager
1115
" . Misc::escapeInteger($_POST['project']) . ",
1116
" . Misc::escapeInteger($_POST['customer']) . ",
1117
" . Misc::escapeInteger($_POST['manager']) . ",
1118
'" . Misc::escapeString($_POST['type']) . "'
1120
$res = DB_Helper::getInstance()->query($stmt);
1121
if (PEAR::isError($res)) {
1122
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1131
* Method used to get the details of a given account manager.
1134
* @param integer $cam_id The account manager ID
1135
* @return array The account manager details
1137
function getAccountManagerDetails($cam_id)
1142
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager
1144
cam_id=" . Misc::escapeInteger($cam_id);
1145
$res = DB_Helper::getInstance()->getRow($stmt, DB_FETCHMODE_ASSOC);
1146
if (PEAR::isError($res)) {
1147
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1156
* Method used to update the details of an account manager.
1159
* @return integer 1 if the update worked properly, any other value otherwise
1161
function updateAccountManager()
1164
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager
1166
cam_prj_id=" . Misc::escapeInteger($_POST['project']) . ",
1167
cam_customer_id='" . Misc::escapeString($_POST['customer']) . "',
1168
cam_usr_id=" . Misc::escapeInteger($_POST['manager']) . ",
1169
cam_type='" . Misc::escapeString($_POST['type']) . "'
1171
cam_id=" . $_POST['id'];
1172
$res = DB_Helper::getInstance()->query($stmt);
1173
if (PEAR::isError($res)) {
1174
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1183
* Method used to remove a technical account manager from the
1189
function removeAccountManager()
1191
$items = @implode(", ", Misc::escapeInteger($_POST["items"]));
1192
$stmt = "DELETE FROM
1193
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager
1195
cam_id IN ($items)";
1196
$res = DB_Helper::getInstance()->query($stmt);
1197
if (PEAR::isError($res)) {
1198
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1207
* Method used to get the list of technical account managers for
1208
* a given customer ID.
1211
* @param integer $prj_id The project ID
1212
* @param integer $customer_id The customer ID
1213
* @return array The list of account managers
1215
function getAccountManagers($prj_id, $customer_id)
1222
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_account_manager,
1223
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user
1225
cam_usr_id=usr_id AND
1226
cam_prj_id=" . Misc::escapeInteger($prj_id) . " AND
1227
cam_customer_id='" . Misc::escapeString($customer_id) . "'";
1228
$res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
1229
if (PEAR::isError($res)) {
1230
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1243
* Returns any notes for for the specified customer.
1246
* @param integer $customer_id The customer ID
1247
* @return array An array containg the note details.
1249
function getNoteDetailsByCustomer($customer_id)
1257
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note
1259
cno_customer_id = '" . Misc::escapeString($customer_id) . "'";
1260
$res = DB_Helper::getInstance()->getRow($stmt, DB_FETCHMODE_ASSOC);
1261
if (PEAR::isError($res)) {
1262
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1271
* Returns any note details for for the specified id.
1274
* @param integer $customer_id The customer ID
1275
* @return array An array containg the note details.
1277
function getNoteDetailsByID($cno_id)
1284
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note
1286
cno_id = " . Misc::escapeInteger($cno_id);
1287
$res = DB_Helper::getInstance()->getRow($stmt, DB_FETCHMODE_ASSOC);
1288
if (PEAR::isError($res)) {
1289
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1298
* Returns an array of notes for all customers.
1301
* @return array An array of notes.
1303
function getNoteList()
1311
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note
1313
cno_customer_id ASC";
1314
$res = DB_Helper::getInstance()->getAll($stmt, DB_FETCHMODE_ASSOC);
1315
if (PEAR::isError($res)) {
1316
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1319
for ($i = 0; $i < count($res); $i++) {
1320
$res[$i]['customer_title'] = self::getTitle($res[$i]['cno_prj_id'], $res[$i]['cno_customer_id']);
1331
* @param integer $cno_id The id of this note.
1332
* @param integer $prj_id The project ID
1333
* @param integer $customer_id The id of the customer.
1334
* @param string $note The text of this note.
1336
function updateNote($cno_id, $prj_id, $customer_id, $note)
1339
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note
1341
cno_note='" . Misc::escapeString($note) . "',
1342
cno_prj_id=" . Misc::escapeInteger($prj_id) . ",
1343
cno_customer_id='" . Misc::escapeString($customer_id) . "',
1344
cno_updated_date='" . Date_Helper::getCurrentDateGMT() . "'
1346
cno_id=" . Misc::escapeInteger($cno_id);
1347
$res = DB_Helper::getInstance()->query($stmt);
1348
if (PEAR::isError($res)) {
1349
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1358
* Adds a quick note for the specified customer.
1361
* @param integer $prj_id The project ID
1362
* @param integer $customer_id The id of the customer.
1363
* @param string $note The note to add.
1365
function insertNote($prj_id, $customer_id, $note)
1367
$stmt = "INSERT INTO
1368
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note
1376
" . Misc::escapeInteger($prj_id) . ",
1377
" . Misc::escapeInteger($customer_id) . ",
1378
'" . Date_Helper::getCurrentDateGMT() . "',
1379
'" . Date_Helper::getCurrentDateGMT() . "',
1380
'" . Misc::escapeString($note) . "'
1382
$res = DB_Helper::getInstance()->query($stmt);
1383
if (PEAR::isError($res)) {
1384
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
1393
* Removes the selected notes from the database.
1396
* @param array $ids An array of cno_id's to be deleted.
1398
function removeNotes($ids)
1400
$stmt = "DELETE FROM
1401
" . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "customer_note
1403
cno_id IN (" . join(", ", Misc::escapeInteger($ids)) . ")";
1404
$res = DB_Helper::getInstance()->query($stmt);
1405
if (PEAR::isError($res)) {
1406
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);