示例#1
0
 public function addExtraRecipientsToNotificationList($prj_id, $email, $is_auto_created = false)
 {
     if (empty($email['to']) && !empty($email['sup_to'])) {
         $email['to'] = $email['sup_to'];
     }
     if (empty($email['cc']) && !empty($email['sup_cc'])) {
         $email['cc'] = $email['sup_cc'];
     }
     $project_details = Project::getDetails($prj_id);
     $addresses_not_too_add = explode(',', strtolower($project_details['prj_mail_aliases']));
     array_push($addresses_not_too_add, $project_details['prj_outgoing_sender_email']);
     $addresses = array();
     $to_addresses = Mail_Helper::getEmailAddresses(@$email['to']);
     if (count($to_addresses)) {
         $addresses = $to_addresses;
     }
     $cc_addresses = Mail_Helper::getEmailAddresses(@$email['cc']);
     if (count($cc_addresses)) {
         $addresses = array_merge($addresses, $cc_addresses);
     }
     $subscribers = Notification::getSubscribedEmails($email['issue_id']);
     foreach ($addresses as $address) {
         $address = strtolower($address);
         if (!in_array($address, $subscribers) && !in_array($address, $addresses_not_too_add)) {
             Notification::subscribeEmail(Auth::getUserID(), $email['issue_id'], $address, Notification::getDefaultActions($email['issue_id'], $address, 'add_extra_recipients'));
             if ($is_auto_created) {
                 Notification::notifyAutoCreatedIssue($prj_id, $email['issue_id'], $email['from'], $email['date'], $email['subject'], $address);
             }
         }
     }
 }
示例#2
0
 /**
  * Creates an issue with the given email information.
  *
  * @param   integer $prj_id The project ID
  * @param   integer $usr_id The user responsible for this action
  * @param   string $sender The original sender of this email
  * @param   string $summary The issue summary
  * @param   string $description The issue description
  * @param   integer $category The category ID
  * @param   integer $priority The priority ID
  * @param   array $assignment The list of users to assign this issue to
  * @param   string $date The date the email was originally sent.
  * @param   string $msg_id The message ID of the email we are creating this issue from.
  * @param   integer $severity
  * @param   string $customer_id
  * @param   string $contact_id
  * @param   string $contract_id
  * @return int
  */
 public static function createFromEmail($prj_id, $usr_id, $sender, $summary, $description, $category, $priority, $assignment, $date, $msg_id, $severity, $customer_id, $contact_id, $contract_id)
 {
     $exclude_list = array();
     $managers = array();
     $sender_email = Mail_Helper::getEmailAddress($sender);
     $sender_usr_id = User::getUserIDByEmail($sender_email, true);
     if (!empty($sender_usr_id)) {
         $reporter = $sender_usr_id;
         $exclude_list[] = $sender_usr_id;
     }
     $data = array('category' => $category, 'priority' => $priority, 'severity' => $severity, 'description' => $description, 'summary' => $summary, 'msg_id' => $msg_id, 'customer' => false, 'contact' => false, 'contract' => false, 'contact_person_lname' => '', 'contact_person_fname' => '', 'contact_email' => '', 'contact_phone' => '', 'contact_timezone' => '');
     if (CRM::hasCustomerIntegration($prj_id)) {
         $crm = CRM::getInstance($prj_id);
         try {
             if ($contact_id != false) {
                 $contact = $crm->getContact($contact_id);
             } else {
                 $contact = $crm->getContactByEmail($sender_email);
             }
             // overwrite the reporter with the customer contact
             $reporter = User::getUserIDByContactID($contact->getContactID());
             $data['contact'] = $contact->getContactID();
             $data['contact_person_lname'] = $contact['last_name'];
             $data['contact_person_fname'] = $contact['first_name'];
             $data['contact_email'] = $sender_email;
             $data['contact_phone'] = $contact['phone'];
             $data['contact_timezone'] = Date_Helper::getPreferredTimezone($reporter);
         } catch (ContactNotFoundException $e) {
         }
         try {
             if ($contract_id != false) {
                 $contract = $crm->getContract($contract_id);
                 $data['contract'] = $contract->getContractID();
             } elseif (isset($contact)) {
                 // Just use first contract / customer for now.
                 $contracts = $contact->getContracts(array('active' => true));
                 $contract = $contracts[0];
                 $data['contract'] = $contract->getContractID();
             }
         } catch (ContractNotFoundException $e) {
         }
         try {
             if ($customer_id != false) {
                 $customer = $crm->getCustomer($customer_id);
                 $data['customer'] = $customer->getCustomerID();
             } elseif (isset($contract)) {
                 $customer = $contract->getCustomer();
                 $data['customer'] = $customer->getCustomerID();
             }
         } catch (CustomerNotFoundException $e) {
         }
     } else {
     }
     if (empty($reporter)) {
         $reporter = APP_SYSTEM_USER_ID;
     }
     $data['reporter'] = $reporter;
     $issue_id = self::insertIssue($prj_id, $data);
     if ($issue_id == -1) {
         return -1;
     }
     $has_RR = false;
     // log the creation of the issue
     History::add($issue_id, $usr_id, 'issue_opened', 'Issue opened by {sender}', array('sender' => $sender));
     $emails = array();
     // if there are any technical account managers associated with this customer, add these users to the notification list
     if ($data['customer']) {
         $managers = CRM::getAccountManagers($prj_id, $data['customer']);
         foreach ($managers as $manager) {
             $emails[] = $manager['usr_email'];
         }
     }
     // add the reporter to the notification list
     $emails[] = $sender;
     $emails = array_unique($emails);
     $actions = Notification::getDefaultActions($issue_id, false, 'issue_from_email');
     foreach ($emails as $address) {
         Notification::subscribeEmail($reporter, $issue_id, $address, $actions);
     }
     // only assign the issue to an user if the associated customer has any technical account managers
     $users = array();
     $has_TAM = false;
     if (CRM::hasCustomerIntegration($prj_id) && count($managers) > 0) {
         foreach ($managers as $manager) {
             if ($manager['cam_type'] == 'intpart') {
                 continue;
             }
             $users[] = $manager['cam_usr_id'];
             self::addUserAssociation($usr_id, $issue_id, $manager['cam_usr_id'], false);
             History::add($issue_id, $usr_id, 'issue_auto_assigned', 'Issue auto-assigned to {assignee} (TAM)', array('assignee' => User::getFullName($manager['cam_usr_id'])));
         }
         $has_TAM = true;
     }
     // now add the user/issue association
     if (@count($assignment) > 0) {
         foreach ($assignment as $ass_usr_id) {
             Notification::subscribeUser($reporter, $issue_id, $ass_usr_id, $actions);
             self::addUserAssociation(APP_SYSTEM_USER_ID, $issue_id, $ass_usr_id);
             if ($ass_usr_id != $usr_id) {
                 $users[] = $ass_usr_id;
             }
         }
     } else {
         // only use the round-robin feature if this new issue was not
         // already assigned to a customer account manager
         if (count($managers) < 1) {
             $assignee = Round_Robin::getNextAssignee($prj_id);
             // assign the issue to the round robin person
             if (!empty($assignee)) {
                 self::addUserAssociation(APP_SYSTEM_USER_ID, $issue_id, $assignee, false);
                 History::add($issue_id, APP_SYSTEM_USER_ID, 'rr_issue_assigned', 'Issue auto-assigned to {assignee} (RR)', array('assignee' => User::getFullName($assignee)));
                 $users[] = $assignee;
                 $has_RR = true;
             }
         }
     }
     Workflow::handleNewIssue($prj_id, $issue_id, $has_TAM, $has_RR);
     // send special 'an issue was auto-created for you' notification back to the sender
     Notification::notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $summary);
     // also notify any users that want to receive emails anytime a new issue is created
     Notification::notifyNewIssue($prj_id, $issue_id, $exclude_list);
     return $issue_id;
 }
示例#3
0
 /**
  * Creates an issue with the given email information.
  *
  * @access  public
  * @param   integer $prj_id The project ID
  * @param   integer $usr_id The user responsible for this action
  * @param   string $sender The original sender of this email
  * @param   string $summary The issue summary
  * @param   string $description The issue description
  * @param   integer $category The category ID
  * @param   integer $priority The priority ID
  * @param   array $assignment The list of users to assign this issue to
  * @param   string $date The date the email was originally sent.
  * @param   string $msg_id The message ID of the email we are creating this issue from.
  * @return  void
  */
 function createFromEmail($prj_id, $usr_id, $sender, $summary, $description, $category, $priority, $assignment, $date, $msg_id)
 {
     $exclude_list = array();
     $sender_email = Mail_API::getEmailAddress($sender);
     $sender_usr_id = User::getUserIDByEmail($sender_email);
     if (!empty($sender_usr_id)) {
         $reporter = $sender_usr_id;
         $exclude_list[] = $sender_usr_id;
     } else {
         $reporter = APP_SYSTEM_USER_ID;
     }
     if (Customer::hasCustomerIntegration($prj_id)) {
         list($customer_id, $customer_contact_id) = Customer::getCustomerIDByEmails($prj_id, array($sender_email));
         if (!empty($customer_id)) {
             $contact = Customer::getContactDetails($prj_id, $customer_contact_id);
             // overwrite the reporter with the customer contact
             $reporter = User::getUserIDByContactID($customer_contact_id);
             $contact_timezone = Date_API::getPreferredTimezone($reporter);
         }
     } else {
         $customer_id = FALSE;
     }
     $initial_status = Project::getInitialStatus($prj_id);
     // add new issue
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                 (\n                    iss_prj_id,\n";
     if (!empty($category)) {
         $stmt .= "iss_prc_id,\n";
     }
     $stmt .= "iss_pri_id,\n                    iss_usr_id,";
     if (!empty($initial_status)) {
         $stmt .= "iss_sta_id,";
     }
     if (!empty($customer_id)) {
         $stmt .= "\n                    iss_customer_id,\n                    iss_customer_contact_id,\n                    iss_contact_person_lname,\n                    iss_contact_person_fname,\n                    iss_contact_email,\n                    iss_contact_phone,\n                    iss_contact_timezone,";
     }
     $stmt .= "\n                    iss_created_date,\n                    iss_last_public_action_date,\n                    iss_last_public_action_type,\n                    iss_summary,\n                    iss_description,\n                    iss_root_message_id\n                 ) VALUES (\n                    " . $prj_id . ",\n";
     if (!empty($category)) {
         $stmt .= Misc::escapeInteger($category) . ",\n";
     }
     $stmt .= Misc::escapeInteger($priority) . ",\n                    " . Misc::escapeInteger($reporter) . ",";
     if (!empty($initial_status)) {
         $stmt .= Misc::escapeInteger($initial_status) . ",";
     }
     if (!empty($customer_id)) {
         $stmt .= "\n                    " . Misc::escapeInteger($customer_id) . ",\n                    " . Misc::escapeInteger($customer_contact_id) . ",\n                    '" . Misc::escapeString($contact['last_name']) . "',\n                    '" . Misc::escapeString($contact['first_name']) . "',\n                    '" . Misc::escapeString($sender_email) . "',\n                    '" . Misc::escapeString($contact['phone']) . "',\n                    '" . Misc::escapeString($contact_timezone) . "',";
     }
     $stmt .= "\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    'created',\n                    '" . Misc::escapeString($summary) . "',\n                    '" . Misc::escapeString($description) . "',\n                    '" . Misc::escapeString($msg_id) . "'\n                 )";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         $new_issue_id = $GLOBALS["db_api"]->get_last_insert_id();
         $has_TAM = false;
         $has_RR = false;
         // log the creation of the issue
         History::add($new_issue_id, $usr_id, History::getTypeID('issue_opened'), 'Issue opened by ' . $sender);
         $emails = array();
         $manager_usr_ids = array();
         if (Customer::hasCustomerIntegration($prj_id) && !empty($customer_id)) {
             // if there are any technical account managers associated with this customer, add these users to the notification list
             $managers = Customer::getAccountManagers($prj_id, $customer_id);
             $manager_usr_ids = array_keys($managers);
             $manager_emails = array_values($managers);
             $emails = array_merge($emails, $manager_emails);
         }
         // add the reporter to the notification list
         $emails[] = $sender;
         $emails = array_unique($emails);
         // COMPAT: version >= 4.0.1
         $actions = Notification::getDefaultActions();
         foreach ($emails as $address) {
             Notification::subscribeEmail($reporter, $new_issue_id, $address, $actions);
         }
         // only assign the issue to an user if the associated customer has any technical account managers
         $users = array();
         if (Customer::hasCustomerIntegration($prj_id) && count($manager_usr_ids) > 0) {
             foreach ($manager_usr_ids as $manager_usr_id) {
                 $users[] = $manager_usr_id;
                 Issue::addUserAssociation(APP_SYSTEM_USER_ID, $new_issue_id, $manager_usr_id, false);
                 History::add($new_issue_id, $usr_id, History::getTypeID('issue_auto_assigned'), 'Issue auto-assigned to ' . User::getFullName($manager_usr_id) . ' (TAM)');
             }
             $has_TAM = true;
         }
         // now add the user/issue association
         if (@count($assignment) > 0) {
             for ($i = 0; $i < count($assignment); $i++) {
                 Notification::subscribeUser($reporter, $new_issue_id, $assignment[$i], $actions);
                 Issue::addUserAssociation(APP_SYSTEM_USER_ID, $new_issue_id, $assignment[$i]);
                 if ($assignment[$i] != $usr_id) {
                     $users[] = $assignment[$i];
                 }
             }
         } else {
             // only use the round-robin feature if this new issue was not
             // already assigned to a customer account manager
             if (@count($manager_usr_ids) < 1) {
                 $assignee = Round_Robin::getNextAssignee($prj_id);
                 // assign the issue to the round robin person
                 if (!empty($assignee)) {
                     Issue::addUserAssociation(APP_SYSTEM_USER_ID, $new_issue_id, $assignee, false);
                     History::add($new_issue_id, APP_SYSTEM_USER_ID, History::getTypeID('rr_issue_assigned'), 'Issue auto-assigned to ' . User::getFullName($assignee) . ' (RR)');
                     $users[] = $assignee;
                     $has_RR = true;
                 }
             }
         }
         if (count($users) > 0) {
             $has_assignee = true;
         }
         // send special 'an issue was auto-created for you' notification back to the sender
         Notification::notifyAutoCreatedIssue($prj_id, $new_issue_id, $sender, $date, $summary);
         // also notify any users that want to receive emails anytime a new issue is created
         Notification::notifyNewIssue($prj_id, $new_issue_id, $exclude_list);
         Workflow::handleNewIssue($prj_id, $new_issue_id, $has_TAM, $has_RR);
         return $new_issue_id;
     }
 }