~eventum-developers/eventum/trunk

« back to all changes in this revision

Viewing changes to lib/eventum/class.support.php

  • Committer: Bryan Alsdorf
  • Date: 2013-08-23 03:50:34 UTC
  • mto: (4033.1.168 eventum-skysql)
  • mto: This revision was merged to the branch mainline in revision 4660.
  • Revision ID: bryan@montyprogram.com-20130823035034-7f5r3pt1xg0xnnhk
Initial commit of CRM migration

Show diffs side-by-side

added added

removed removed

Lines of Context:
260
260
    /**
261
261
     * Method used to get the sender of a given set of emails.
262
262
     *
263
 
     * @access  public
264
 
     * @param   integer $sup_ids The email IDs
 
263
     * @param   integer[] $sup_ids The email IDs
265
264
     * @return  array The 'From:' headers for those emails
266
265
     */
267
 
    function getSender($sup_ids)
 
266
    public static function getSender($sup_ids)
268
267
    {
269
268
        $stmt = "SELECT
270
269
                    sup_from
913
912
 
914
913
        // only create a new issue if this email is coming from a known customer
915
914
        if (($should_create_issue) && ($info['ema_issue_auto_creation_options']['only_known_customers'] == 'yes') &&
916
 
                (Customer::hasCustomerIntegration($info['ema_prj_id']))) {
917
 
            list($customer_id,) = Customer::getCustomerIDByEmails($info['ema_prj_id'], array($sender_email));
918
 
            if (empty($customer_id)) {
 
915
                (CRM::hasCustomerIntegration($info['ema_prj_id']))) {
 
916
            try {
 
917
                $crm = CRM::getInstance($info['ema_prj_id']);
 
918
                $contact = $crm->getContactByEmail($sender_email);
 
919
                $should_create_issue = true;
 
920
            } catch (CRMException $e) {
919
921
                $should_create_issue = false;
920
922
            }
921
923
        }
941
943
        // need to check crm for customer association
942
944
        if (!empty($from)) {
943
945
            $details = Email_Account::getDetails($info['ema_id']);
944
 
            if (Customer::hasCustomerIntegration($info['ema_prj_id'])) {
 
946
            if (CRM::hasCustomerIntegration($info['ema_prj_id'])) {
945
947
                // check for any customer contact association
946
 
                @list($customer_id,) = Customer::getCustomerIDByEmails($info['ema_prj_id'], array($sender_email));
 
948
                try {
 
949
                    $crm = CRM::getInstance($info['ema_prj_id']);
 
950
                    $contact = $crm->getContactByEmail($sender_email);
 
951
                    $contact = $contact->getContactID();
 
952
                    $contract = $contact->getContracts(array(CRM_EXCLUDE_EXPIRED))[0];
 
953
                    $customer_id = $contract->getCustomerID();
 
954
                } catch (CRMException $e) {
 
955
                    $customer_id = null;
 
956
                    $contact_id = null;
 
957
                }
947
958
            }
948
959
        }
949
960
        return array(
950
961
            'should_create_issue'   =>  $should_create_issue,
951
962
            'associate_email'   =>  $associate_email,
952
963
            'issue_id'  =>  $issue_id,
953
 
            'customer_id'   =>  @$customer_id,
 
964
            'customer_id'   =>  $customer_id,
 
965
            'contact_id'   =>  $contact_id,
954
966
            'type'      =>  $type,
955
967
            'parent_id' =>  $parent_id
956
968
        );
1309
1321
            Auth::redirect("emails.php?pagerRow=0&rows=$max");
1310
1322
        }
1311
1323
 
1312
 
        if (Customer::hasCustomerIntegration($prj_id)) {
 
1324
        if (CRM::hasCustomerIntegration($prj_id)) {
 
1325
            $crm = CRM::getInstance($prj_id);
1313
1326
            $customer_ids = array();
1314
1327
            for ($i = 0; $i < count($res); $i++) {
1315
1328
                if ((!empty($res[$i]['sup_customer_id'])) && (!in_array($res[$i]['sup_customer_id'], $customer_ids))) {
1317
1330
                }
1318
1331
            }
1319
1332
            if (count($customer_ids) > 0) {
1320
 
                $company_titles = Customer::getTitles($prj_id, $customer_ids);
 
1333
                $company_titles = $crm->getCustomerTitles($customer_ids);
1321
1334
            }
1322
1335
        }
1323
1336
 
1334
1347
                    $res[$i]['sup_to'] = Mime_Helper::fixEncoding($to);
1335
1348
                }
1336
1349
            }
1337
 
            if (Customer::hasCustomerIntegration($prj_id)) {
 
1350
            if (CRM::hasCustomerIntegration($prj_id)) {
1338
1351
                @$res[$i]['customer_title'] = $company_titles[$res[$i]['sup_customer_id']];
1339
1352
            }
1340
1353
        }
1433
1446
        $prj_id = Issue::getProjectID($issue_id);
1434
1447
        $unknown_user = false;
1435
1448
        if (empty($usr_id)) {
1436
 
            if (Customer::hasCustomerIntegration($prj_id)) {
 
1449
            if (CRM::hasCustomerIntegration($prj_id)) {
1437
1450
                // try checking if a customer technical contact has this email associated with it
1438
 
                list(,$contact_id) = Customer::getCustomerIDByEmails($prj_id, array($sender_email));
1439
 
                if (!empty($contact_id)) {
1440
 
                    $usr_id = User::getUserIDByContactID($contact_id);
 
1451
                try {
 
1452
                    $crm = CRM::getInstance($prj_id);
 
1453
                    $contact = $crm->getContactByEmail($sender_email);
 
1454
                    $usr_id = User::getUserIDByContactID($contact->getContactID());
 
1455
                } catch (CRMException $e) {
 
1456
                    $usr_id = null;
1441
1457
                }
1442
1458
            }
1443
1459
            if (empty($usr_id)) {
1891
1907
        $is_allowed = true;
1892
1908
        $sender_usr_id = User::getUserIDByEmail($sender_email, true);
1893
1909
        if (empty($sender_usr_id)) {
1894
 
            if (Customer::hasCustomerIntegration($prj_id)) {
 
1910
            if (CRM::hasCustomerIntegration($prj_id)) {
1895
1911
                // check for a customer contact with several email addresses
1896
 
                $customer_id = Issue::getCustomerID($issue_id);
1897
 
                $contact_emails = array_keys(Customer::getContactEmailAssocList($prj_id, $customer_id));
1898
 
                $contact_emails = array_map('strtolower', $contact_emails);
 
1912
                $crm = CRM::getInstance($prj_id);
 
1913
                try {
 
1914
                    $contract = $crm->getContract(Issue::getContractID($issue_id));
 
1915
                    $contact_emails = array_keys($contract->getContactEmailAssocList());
 
1916
                    $contact_emails = array_map('strtolower', $contact_emails);
 
1917
                } catch (CRMException $e) {
 
1918
                    $contact_emails = array();
 
1919
                }
1899
1920
                if ((!in_array(strtolower($sender_email), $contact_emails)) &&
1900
1921
                        (!Authorized_Replier::isAuthorizedReplier($issue_id, $sender_email))) {
1901
1922
                    $is_allowed = false;