if ($res) { list($HTTP_POST_VARS["from"]) = Support::getSender(array($HTTP_POST_VARS['item'][$i])); Workflow::handleBlockedEmail(Issue::getProjectID($HTTP_POST_VARS['issue']), $HTTP_POST_VARS['issue'], $HTTP_POST_VARS, 'associated'); Support::removeEmail($HTTP_POST_VARS['item'][$i]); } } $tpl->assign("associate_result", $res); } @$tpl->assign('total_emails', count($HTTP_POST_VARS['item'])); } else { @$tpl->assign('emails', $HTTP_GET_VARS['item']); @$tpl->assign('total_emails', count($HTTP_GET_VARS['item'])); $prj_id = Issue::getProjectID($HTTP_GET_VARS['issue']); if (Customer::hasCustomerIntegration($prj_id)) { // check if the selected emails all have sender email addresses that are associated with the issue' customer $senders = Support::getSender($HTTP_GET_VARS['item']); $sender_emails = array(); for ($i = 0; $i < count($senders); $i++) { $email = Mail_API::getEmailAddress($senders[$i]); $sender_emails[$email] = $senders[$i]; } $customer_id = Issue::getCustomerID($HTTP_GET_VARS['issue']); if (!empty($customer_id)) { $contact_emails = array_keys(Customer::getContactEmailAssocList($prj_id, $customer_id)); $unknown_contacts = array(); foreach ($sender_emails as $email => $address) { if (!@in_array($email, $contact_emails)) { $usr_id = User::getUserIDByEmail($email); if (empty($usr_id)) { $unknown_contacts[] = $address; } else {
list($_POST['from']) = Support::getSender(array($item)); Workflow::handleBlockedEmail(Issue::getProjectID($_POST['issue_id']), $_POST['issue_id'], $_POST, 'associated'); Support::removeEmail($item); } } $tpl->assign('associate_result', $res); } @$tpl->assign('total_emails', count($_POST['item'])); } else { @$tpl->assign('emails', $_GET['item']); @$tpl->assign('total_emails', count($_GET['item'])); $prj_id = Issue::getProjectID($_GET['issue_id']); if (CRM::hasCustomerIntegration($prj_id)) { // check if the selected emails all have sender email addresses that are associated with the issue' customer $crm = CRM::getInstance($prj_id); $senders = Support::getSender($_GET['item']); $sender_emails = array(); foreach ($senders as $sender) { $email = Mail_Helper::getEmailAddress($sender); $sender_emails[$email] = $sender; } $contract_id = Issue::getContractID($_GET['issue_id']); if (!empty($contract_id)) { try { $contract = $crm->getContract($contract_id); // TODOCRM: Active contacts only $contact_emails = array_keys($contract->getContactEmailAssocList()); } catch (CRMException $e) { $contact_emails = array(); } $unknown_contacts = array();
/** * Method used to send an email notification to the sender of a * set of email messages that were manually converted into an * issue. * * @param integer $prj_id The project ID * @param integer $issue_id The issue ID * @param array $sup_ids The email IDs * @param bool|int $customer_id The customer ID * @return array The list of recipient emails */ public static function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = false) { if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); return $crm->notifyEmailConvertedIntoIssue($issue_id, $sup_ids, $customer_id); } else { // build the list of recipients $recipients = array(); $recipient_emails = array(); foreach ($sup_ids as $sup_id) { $senders = Support::getSender(array($sup_id)); if (count($senders) > 0) { $sender_email = Mail_Helper::getEmailAddress($senders[0]); $recipients[$sup_id] = $senders[0]; $recipient_emails[] = $sender_email; } } if (!$recipients) { return false; } $data = Issue::getDetails($issue_id); foreach ($recipients as $sup_id => $recipient) { $recipient_usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($recipient)); // open text template $tpl = new Template_Helper(); $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text'); $tpl->assign(array('data' => $data, 'sender_name' => Mail_Helper::getName($recipient), 'app_title' => Misc::getToolCaption(), 'recipient_name' => Mail_Helper::getName($recipient))); $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($sup_id), $sup_id); $tpl->assign(array('email' => array('date' => $email_details['sup_date'], 'from' => $email_details['sup_from'], 'subject' => $email_details['sup_subject']))); // change the current locale if (!empty($recipient_usr_id)) { Language::set(User::getLang($recipient_usr_id)); } else { Language::set(APP_DEFAULT_LOCALE); } $text_message = $tpl->getTemplateContents(); // send email (use PEAR's classes) $mail = new Mail_Helper(); $mail->setTextBody($text_message); $setup = $mail->getSMTPSettings(); $from = self::getFixedFromHeader($issue_id, $setup['from'], 'issue'); $mail->setHeaders(Mail_Helper::getBaseThreadingHeaders($issue_id)); // TRANSLATORS: %1 - issue_id, %2 - iss_summary $subject = ev_gettext('[#%1$s] Issue Created: %2$s', $issue_id, $data['iss_summary']); $mail->send($from, $recipient, $subject, 1, $issue_id, 'email_converted_to_issue'); } Language::restore(); return $recipient_emails; } }
/** * Method used to get the associated customer and customer contact from * a given set of support emails. This is especially useful to automatically * associate an issue to the appropriate customer contact that sent a * support email. * * @access public * @param array $sup_ids The list of support email IDs * @return array The customer and customer contact ID */ function getCustomerInfoFromEmails($sup_ids) { $senders = Support::getSender($sup_ids); if (count($senders) > 0) { $emails = array(); for ($i = 0; $i < count($senders); $i++) { $emails[] = Mail_API::getEmailAddress($senders[$i]); } list($customer_id, $contact_id) = $this->getCustomerIDByEmails($emails); $company = $this->getDetails($customer_id); $contact = $this->getContactDetails($contact_id); return array('customer_id' => $customer_id, 'customer_name' => $company['customer_name'], 'contact_id' => $contact_id, 'contact_name' => $contact['first_name'] . " " . $contact['last_name'], 'contacts' => $this->getContactEmailAssocList($customer_id)); } else { return array('customer_id' => '', 'customer_name' => '', 'contact_id' => '', 'contact_name' => '', 'contacts' => ''); } }
/** * Method used to send an email notification to the sender of a * set of email messages that were manually converted into an * issue. * * @access public * @param integer $prj_id The project ID * @param integer $issue_id The issue ID * @param array $sup_ids The email IDs * @param integer $customer_id The customer ID * @return array The list of recipient emails */ function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = FALSE) { if (Customer::hasCustomerIntegration($prj_id)) { return Customer::notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id); } else { // build the list of recipients $recipients = array(); $recipient_emails = array(); for ($i = 0; $i < count($sup_ids); $i++) { $senders = Support::getSender(array($sup_ids[$i])); if (count($senders) > 0) { $sender_email = Mail_API::getEmailAddress($senders[0]); $recipients[$sup_ids[$i]] = $senders[0]; $recipient_emails[] = $sender_email; } } if (count($recipients) == 0) { return false; } $data = Issue::getDetails($issue_id); foreach ($recipients as $sup_id => $recipient) { // open text template $tpl = new Template_API(); $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text'); $tpl->bulkAssign(array("data" => $data, "sender_name" => Mail_API::getName($recipient))); $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($sup_id), $sup_id); $tpl->assign(array('email' => array('date' => $email_details['sup_date'], 'from' => $email_details['sup_from'], 'subject' => $email_details['sup_subject']))); $text_message = $tpl->getTemplateContents(); // send email (use PEAR's classes) $mail = new Mail_API(); $mail->setTextBody($text_message); $setup = $mail->getSMTPSettings(); $from = Notification::getFixedFromHeader($issue_id, $setup["from"], 'issue'); $mail->setHeaders(Mail_API::getBaseThreadingHeaders($issue_id)); $mail->send($from, $recipient, 'New Issue Created', 1, $issue_id, 'email_converted_to_issue'); } return $recipient_emails; } }