/** * Method used to perform a specific action to an issue. * * @access public * @param integer $issue_id The issue ID * @param array $reminder The reminder details * @param array $action The action details * @return boolean */ function perform($issue_id, $reminder, $action) { $type = ''; // - see which action type we're talking about here... $action_type = Reminder_Action::getActionType($action['rma_rmt_id']); // - do we also need to alert the group leader about this? $group_leader_usr_id = 0; if ($action['rma_alert_group_leader']) { if (Reminder::isDebug()) { echo " - Processing Group Leader notification\n"; } $group_id = Issue::getGroupID($issue_id); // check if there's even a group associated with this issue if (empty($group_id)) { if (Reminder::isDebug()) { echo " - No group associated with issue {$issue_id}\n"; } } else { $group_details = Group::getDetails($group_id); if (!empty($group_details['grp_manager_usr_id'])) { $group_leader_usr_id = $group_details['grp_manager_usr_id']; } } } if (Reminder::isDebug()) { echo " - Performing action '{$action_type}' for issue #{$issue_id}\n"; } switch ($action_type) { case 'email_assignee': $type = 'email'; $assignees = Issue::getAssignedUserIDs($issue_id); $to = array(); foreach ($assignees as $assignee) { $to[] = User::getFromHeader($assignee); } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id)) { $leader_email = User::getFromHeader($group_leader_usr_id); if (!empty($leader_email) && !in_array($leader_email, $to)) { $to[] = $leader_email; } } break; case 'email_list': $type = 'email'; $list = Reminder_Action::getUserList($action['rma_id']); $to = array(); foreach ($list as $key => $value) { // add the recipient to the list if it's a simple email address if (Validation::isEmail($key)) { $to[] = $key; } else { $to[] = User::getFromHeader($key); } } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id)) { $leader_email = User::getFromHeader($group_leader_usr_id); if (!empty($leader_email) && !in_array($leader_email, $to)) { $to[] = $leader_email; } } break; case 'sms_assignee': $type = 'sms'; $assignees = Issue::getAssignedUserIDs($issue_id); $to = array(); foreach ($assignees as $assignee) { if (User::isClockedIn($assignee)) { $sms_email = User::getSMS($assignee); if (!empty($sms_email)) { $to[] = $sms_email; } } } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id) && User::isClockedIn($group_leader_usr_id)) { $leader_sms_email = User::getSMS($group_leader_usr_id); if (!empty($leader_sms_email) && !in_array($leader_sms_email, $to)) { $to[] = $leader_sms_email; } } break; case 'sms_list': $type = 'sms'; $list = Reminder_Action::getUserList($action['rma_id']); $to = array(); foreach ($list as $key => $value) { // add the recipient to the list if it's a simple email address if (Validation::isEmail($key)) { $to[] = $key; } else { // otherwise, check for the clocked-in status if (User::isClockedIn($key)) { $sms_email = User::getSMS($key); if (!empty($sms_email)) { $to[] = $sms_email; } } } } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id) && User::isClockedIn($group_leader_usr_id)) { $leader_sms_email = User::getSMS($group_leader_usr_id); if (!empty($leader_sms_email) && !in_array($leader_sms_email, $to)) { $to[] = $leader_sms_email; } } break; } $data = Notification::getIssueDetails($issue_id); $conditions = Reminder_Condition::getAdminList($action['rma_id']); // alert IRC if needed if ($action['rma_alert_irc']) { if (Reminder::isDebug()) { echo " - Processing IRC notification\n"; } $irc_notice = "Issue #{$issue_id} (Priority: " . $data['pri_title']; // also add information about the assignee, if any $assignment = Issue::getAssignedUsers($issue_id); if (count($assignment) > 0) { $irc_notice .= "; Assignment: " . implode(', ', $assignment); } if (!empty($data['iss_grp_id'])) { $irc_notice .= "; Group: " . Group::getName($data['iss_grp_id']); } $irc_notice .= "), Reminder action '" . $action['rma_title'] . "' was just triggered"; Notification::notifyIRC(Issue::getProjectID($issue_id), $irc_notice, $issue_id); } $setup = Setup::load(); // if there are no recipients, then just skip to the next action if (count($to) == 0) { if (Reminder::isDebug()) { echo " - No recipients could be found\n"; } // if not even an irc alert was sent, then save // a notice about this on reminder_sent@, if needed if (!$action['rma_alert_irc']) { if (@$setup['email_reminder']['status'] == 'enabled') { Reminder_Action::_recordNoRecipientError($issue_id, $type, $reminder, $action); } return false; } } // - save a history entry about this action Reminder_Action::saveHistory($issue_id, $action['rma_id']); // - save this action as the latest triggered one for the given issue ID Reminder_Action::recordLastTriggered($issue_id, $action['rma_id']); // - perform the action if (count($to) > 0) { // send a copy of this reminder to reminder_sent@, if needed if (@$setup['email_reminder']['status'] == 'enabled' && !empty($setup['email_reminder']['addresses'])) { $addresses = Reminder::_getReminderAlertAddresses(); if (count($addresses) > 0) { $to = array_merge($to, $addresses); } } $tpl = new Template_API(); $tpl->setTemplate('reminders/' . $type . '_alert.tpl.text'); $tpl->bulkAssign(array("data" => $data, "reminder" => $reminder, "action" => $action, "conditions" => $conditions, "has_customer_integration" => Customer::hasCustomerIntegration(Issue::getProjectID($issue_id)))); $text_message = $tpl->getTemplateContents(); foreach ($to as $address) { // send email (use PEAR's classes) $mail = new Mail_API(); $mail->setTextBody($text_message); $setup = $mail->getSMTPSettings(); $mail->send($setup["from"], $address, "[#{$issue_id}] Reminder: " . $action['rma_title'], 0, $issue_id, 'reminder'); } } // - eventum saves the day once again return true; }
/** * Method used to perform a specific action to an issue. * * @param integer $issue_id The issue ID * @param array $reminder The reminder details * @param array $action The action details * @return boolean */ public static function perform($issue_id, $reminder, $action) { $type = ''; // - see which action type we're talking about here... $action_type = self::getActionType($action['rma_rmt_id']); // - do we also need to alert the group leader about this? $group_leader_usr_id = 0; if ($action['rma_alert_group_leader']) { if (Reminder::isDebug()) { echo ' - ' . ev_gettext('Processing Group Leader notification') . "\n"; } $group_id = Issue::getGroupID($issue_id); // check if there's even a group associated with this issue if (empty($group_id)) { if (Reminder::isDebug()) { echo ' - ' . ev_gettext('No group associated with issue %1$s', $issue_id) . "\n"; } } else { $group_details = Group::getDetails($group_id); if (!empty($group_details['grp_manager_usr_id'])) { $group_leader_usr_id = $group_details['grp_manager_usr_id']; } } } if (Reminder::isDebug()) { echo ' - ' . ev_gettext('Performing action %1$s for issue # %2$s', $action_type, $issue_id) . "\n"; } switch ($action_type) { case 'email_assignee': $type = 'email'; $assignees = Issue::getAssignedUserIDs($issue_id); $to = array(); foreach ($assignees as $assignee) { $to[] = User::getFromHeader($assignee); } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id)) { $leader_email = User::getFromHeader($group_leader_usr_id); if (!empty($leader_email) && !in_array($leader_email, $to)) { $to[] = $leader_email; } } break; case 'email_list': $type = 'email'; $list = self::getUserList($action['rma_id']); $to = array(); foreach ($list as $key => $value) { // add the recipient to the list if it's a simple email address if (Validation::isEmail($key)) { $to[] = $key; } else { $to[] = User::getFromHeader($key); } } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id)) { $leader_email = User::getFromHeader($group_leader_usr_id); if (!empty($leader_email) && !in_array($leader_email, $to)) { $to[] = $leader_email; } } break; case 'sms_assignee': $type = 'sms'; $assignees = Issue::getAssignedUserIDs($issue_id); $to = array(); foreach ($assignees as $assignee) { if (User::isClockedIn($assignee)) { $sms_email = User::getSMS($assignee); if (!empty($sms_email)) { $to[] = $sms_email; } } } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id) && User::isClockedIn($group_leader_usr_id)) { $leader_sms_email = User::getSMS($group_leader_usr_id); if (!empty($leader_sms_email) && !in_array($leader_sms_email, $to)) { $to[] = $leader_sms_email; } } break; case 'sms_list': $type = 'sms'; $list = self::getUserList($action['rma_id']); $to = array(); foreach ($list as $key => $value) { // add the recipient to the list if it's a simple email address if (Validation::isEmail($key)) { $to[] = $key; } else { // otherwise, check for the clocked-in status if (User::isClockedIn($key)) { $sms_email = User::getSMS($key); if (!empty($sms_email)) { $to[] = $sms_email; } } } } // add the group leader to the recipient list, if needed if (!empty($group_leader_usr_id) && User::isClockedIn($group_leader_usr_id)) { $leader_sms_email = User::getSMS($group_leader_usr_id); if (!empty($leader_sms_email) && !in_array($leader_sms_email, $to)) { $to[] = $leader_sms_email; } } break; } $data = Issue::getDetails($issue_id); $conditions = Reminder_Condition::getAdminList($action['rma_id']); // alert IRC if needed if ($action['rma_alert_irc']) { if (Reminder::isDebug()) { echo " - Processing IRC notification\n"; } $irc_notice = "Issue #{$issue_id} ("; if (!empty($data['pri_title'])) { $irc_notice .= 'Priority: ' . $data['pri_title']; } if (!empty($data['sev_title'])) { $irc_notice .= 'Severity: ' . $data['sev_title']; } // also add information about the assignee, if any $assignment = Issue::getAssignedUsers($issue_id); if (count($assignment) > 0) { $irc_notice .= '; Assignment: ' . implode(', ', $assignment); } if (!empty($data['iss_grp_id'])) { $irc_notice .= '; Group: ' . Group::getName($data['iss_grp_id']); } $irc_notice .= "), Reminder action '" . $action['rma_title'] . "' was just triggered; " . $action['rma_boilerplate']; Notification::notifyIRC(Issue::getProjectID($issue_id), $irc_notice, $issue_id, false, APP_EVENTUM_IRC_CATEGORY_REMINDER); } $setup = Setup::get(); // if there are no recipients, then just skip to the next action if (count($to) == 0) { if (Reminder::isDebug()) { echo " - No recipients could be found\n"; } // if not even an irc alert was sent, then save // a notice about this on reminder_sent@, if needed if (!$action['rma_alert_irc']) { if ($setup['email_reminder']['status'] == 'enabled') { self::_recordNoRecipientError($issue_id, $type, $reminder, $action, $data, $conditions); } return false; } } // - save a history entry about this action self::saveHistory($issue_id, $action['rma_id']); // - save this action as the latest triggered one for the given issue ID self::recordLastTriggered($issue_id, $action['rma_id']); // - perform the action if (count($to) > 0) { // send a copy of this reminder to reminder_sent@, if needed if ($setup['email_reminder']['status'] == 'enabled' && $setup['email_reminder']['addresses']) { $addresses = Reminder::_getReminderAlertAddresses(); if (count($addresses) > 0) { $to = array_merge($to, $addresses); } } $tpl = new Template_Helper(); $tpl->setTemplate('reminders/' . $type . '_alert.tpl.text'); $tpl->assign(array('data' => $data, 'reminder' => $reminder, 'action' => $action, 'conditions' => $conditions, 'has_customer_integration' => CRM::hasCustomerIntegration(Issue::getProjectID($issue_id)))); $text_message = $tpl->getTemplateContents(); foreach ($to as $address) { // send email (use PEAR's classes) $mail = new Mail_Helper(); $mail->setTextBody($text_message); $setup = $mail->getSMTPSettings(); // TRANSLATORS: %1 - issue_id, %2 - rma_title $subject = ev_gettext('[#%1$s] Reminder: %2$s', $issue_id, $action['rma_title']); $mail->send($setup['from'], $address, $subject, 0, $issue_id, 'reminder'); } } // - eventum saves the day once again return true; }
/** * Generates the specialized headers for an email. * * @access public * @param integer $issue_id The issue ID * @param string $type The type of message this is * @param string $headers The existing headers of this message. * @param integer $sender_usr_id The id of the user sending this email. * @return array An array of specialized headers */ function getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id) { $new_headers = array(); if (!empty($issue_id)) { $prj_id = Issue::getProjectID($issue_id); if (count(Group::getAssocList($prj_id)) > 0) { // group issue is currently assigned too $new_headers['X-Eventum-Group-Issue'] = Group::getName(Issue::getGroupID($issue_id)); // group of whoever is sending this message. if (empty($sender_usr_id)) { $new_headers['X-Eventum-Group-Replier'] = $new_headers['X-Eventum-Group-Issue']; } else { $new_headers['X-Eventum-Group-Replier'] = Group::getName(User::getGroupID($sender_usr_id)); } // group of current assignee $assignees = Issue::getAssignedUserIDs($issue_id); if (empty($assignees[0])) { $new_headers['X-Eventum-Group-Assignee'] = ''; } else { $new_headers['X-Eventum-Group-Assignee'] = @Group::getName(User::getGroupID($assignees[0])); } } if (Customer::hasCustomerIntegration($prj_id)) { if (empty($support_levels)) { $support_levels = Customer::getSupportLevelAssocList($prj_id); } $customer_id = Issue::getCustomerID($issue_id); if (!empty($customer_id)) { $customer_details = Customer::getDetails($prj_id, $customer_id); $new_headers['X-Eventum-Customer'] = $customer_details['customer_name']; } if (count($support_levels) > 0) { $new_headers['X-Eventum-Level'] = $support_levels[Customer::getSupportLevelID($prj_id, $customer_id)]; } } $new_headers['X-Eventum-Category'] = Category::getTitle(Issue::getCategory($issue_id)); $new_headers['X-Eventum-Project'] = Project::getName($prj_id); } $new_headers['X-Eventum-Type'] = $type; return $new_headers; }
/** * Generates the specialized headers for an email. * * @param integer $issue_id The issue ID * @param string $type The type of message this is * @param string $headers The existing headers of this message. * @param integer $sender_usr_id The id of the user sending this email. * @return array An array of specialized headers */ public static function getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id) { $new_headers = array(); if (!empty($issue_id)) { $prj_id = Issue::getProjectID($issue_id); if (count(Group::getAssocList($prj_id)) > 0) { // group issue is currently assigned too $new_headers['X-Eventum-Group-Issue'] = Group::getName(Issue::getGroupID($issue_id)); // group of whoever is sending this message. if (empty($sender_usr_id)) { $new_headers['X-Eventum-Group-Replier'] = $new_headers['X-Eventum-Group-Issue']; } else { $new_headers['X-Eventum-Group-Replier'] = Group::getName(User::getGroupID($sender_usr_id)); } // group of current assignee $assignees = Issue::getAssignedUserIDs($issue_id); if (empty($assignees[0])) { $new_headers['X-Eventum-Group-Assignee'] = ''; } else { $new_headers['X-Eventum-Group-Assignee'] = @Group::getName(User::getGroupID($assignees[0])); } } if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); try { $customer = $crm->getCustomer(Issue::getCustomerID($issue_id)); $new_headers['X-Eventum-Customer'] = $customer->getName(); } catch (CustomerNotFoundException $e) { } try { $contract = $crm->getContract(Issue::getContractID($issue_id)); $support_level = $contract->getSupportLevel(); if (is_object($support_level)) { $new_headers['X-Eventum-Level'] = $support_level->getName(); } } catch (ContractNotFoundException $e) { } } // add assignee header $new_headers['X-Eventum-Assignee'] = implode(',', User::getEmail(Issue::getAssignedUserIDs($issue_id))); $new_headers['X-Eventum-Category'] = Category::getTitle(Issue::getCategory($issue_id)); $new_headers['X-Eventum-Project'] = Project::getName($prj_id); $new_headers['X-Eventum-Priority'] = Priority::getTitle(Issue::getPriority($issue_id)); // handle custom fields $cf_values = Custom_Field::getValuesByIssue($prj_id, $issue_id); $cf_titles = Custom_Field::getFieldsToBeListed($prj_id); foreach ($cf_values as $fld_id => $values) { // skip empty titles // TODO: why they are empty? if (!isset($cf_titles[$fld_id])) { continue; } // skip empty values if (empty($values)) { continue; } $cf_value = implode(', ', (array) $values); // value could be empty after multivalued field join if (empty($cf_value)) { continue; } // convert spaces for header fields $cf_title = str_replace(' ', '_', $cf_titles[$fld_id]); $new_headers['X-Eventum-CustomField-' . $cf_title] = $cf_value; } } $new_headers['X-Eventum-Type'] = $type; return $new_headers; }