} $tpl->assign("info", $info); } if (!empty($HTTP_GET_VARS['field'])) { $field_title = Reminder_Condition::getFieldTitle($HTTP_GET_VARS['field']); if (Reminder_Condition::canFieldBeCompared($HTTP_GET_VARS['field'])) { $tpl->assign(array('show_field_options' => 'yes', 'comparable_fields' => Reminder_Condition::getFieldAdminList(true))); } elseif (strtolower($field_title) == 'status') { $prj_id = Reminder::getProjectID($rem_id); $tpl->assign(array('show_status_options' => 'yes', 'statuses' => Status::getAssocStatusList($prj_id))); } elseif (strtolower($field_title) == 'category') { $prj_id = Reminder::getProjectID($rem_id); $tpl->assign(array('show_category_options' => 'yes', 'categories' => Category::getAssocList($prj_id))); } else { $tpl->assign('show_status_options', 'no'); } if (@$HTTP_GET_VARS["cat"] != "edit") { $tpl->assign('info', array('rlc_rmf_id' => $HTTP_GET_VARS['field'], 'rlc_rmo_id' => '', 'rlc_value' => '')); } } $tpl->assign("rem_id", $rem_id); $tpl->assign("rma_id", $rma_id); $tpl->assign("rem_title", Reminder::getTitle($rem_id)); $tpl->assign("rma_title", Reminder_Action::getTitle($rma_id)); $tpl->assign("fields", Reminder_Condition::getFieldAdminList()); $tpl->assign("operators", Reminder_Condition::getOperatorAdminList()); $tpl->assign("list", Reminder_Condition::getAdminList($rma_id)); } else { $tpl->assign("show_not_allowed_msg", true); } $tpl->displayTemplate();
$reminders = Reminder::getList(); for ($i = 0; $i < count($reminders); $i++) { // if this is the weekend and this reminder isn't supposed to run on weekends skip if ($reminders[$i]['rem_skip_weekend'] == 1 && in_array(date("w"), array(0, 6))) { if (Reminder::isDebug()) { echo "Skipping Reminder '" . $reminders[$i]['rem_title'] . "' due to weekend exclusion\n"; } continue; } // for each action, get the conditions and see if it triggered any issues $found = 0; for ($y = 0; $y < count($reminders[$i]['actions']); $y++) { if (Reminder::isDebug()) { echo "Processing Reminder Action '" . $reminders[$i]['actions'][$y]['rma_title'] . "'\n"; } $conditions = Reminder_Condition::getList($reminders[$i]['actions'][$y]['rma_id']); if (count($conditions) == 0) { if (Reminder::isDebug()) { echo " - Skipping Reminder because there were no reminder conditions found\n"; } continue; } $issues = Reminder::getTriggeredIssues($reminders[$i], $conditions); // avoid repeating reminder actions, so get the list of issues // that were last triggered with this reminder action ID $repeat_issues = Reminder_Action::getRepeatActions($issues, $reminders[$i]['actions'][$y]['rma_id']); if (count($repeat_issues) > 0) { // add the repeated issues to the list of already triggered // issues, so they get ignored for the next reminder actions for ($w = 0; $w < count($repeat_issues); $w++) { if (Reminder::isDebug()) {
$weekday = date('w'); foreach ($reminders as $reminder) { // if this is the weekend and this reminder isn't supposed to run on weekends skip if ($reminder['rem_skip_weekend'] == 1 && in_array($weekday, array(0, 6))) { if (Reminder::isDebug()) { echo "Skipping Reminder '" . $reminder['rem_title'] . "' due to weekend exclusion\n"; } continue; } // for each action, get the conditions and see if it triggered any issues $found = 0; foreach ($reminder['actions'] as $action) { if (Reminder::isDebug()) { echo "Processing Reminder Action '" . $action['rma_title'] . "'\n"; } $conditions = Reminder_Condition::getList($action['rma_id']); if (count($conditions) == 0) { if (Reminder::isDebug()) { echo " - Skipping Reminder because there were no reminder conditions found\n"; } continue; } $issues = Reminder::getTriggeredIssues($reminder, $conditions); // avoid repeating reminder actions, so get the list of issues // that were last triggered with this reminder action ID $repeat_issues = Reminder_Action::getRepeatActions($issues, $action['rma_id']); if (count($repeat_issues) > 0) { // add the repeated issues to the list of already triggered // issues, so they get ignored for the next reminder actions foreach ($repeat_issues as $issue) { if (Reminder::isDebug()) {
/** * 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 generate an SQL query to be used in debugging the reminder * conditions. * * @access public * @param integer $rem_id The reminder ID * @param integer $rma_id The reminder action ID * @return string The SQL query */ function getSQLQuery($rem_id, $rma_id) { $reminder = Reminder::getDetails($rem_id); $conditions = Reminder_Condition::getList($rma_id); $stmt = "SELECT\n iss_id\n FROM\n " . APP_TABLE_PREFIX . "issue"; $stmt .= Reminder::getWhereClause($reminder, $conditions); // can't rely on the mysql server's timezone setting, so let's use gmt dates throughout $stmt = str_replace('UNIX_TIMESTAMP()', "UNIX_TIMESTAMP('" . Date_API::getCurrentDateGMT() . "')", $stmt); return $stmt; }
/** * Method used to get the list of reminder conditions to be displayed in the * administration section. * * @access public * @param integer $rma_id The reminder action ID * @return array The list of reminder conditions */ function getAdminList($rma_id) { $stmt = "SELECT\n rlc_id,\n rlc_value,\n rlc_comparison_rmf_id,\n rmf_title,\n rmo_title\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_level_condition,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_field,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "reminder_operator\n WHERE\n rlc_rmf_id=rmf_id AND\n rlc_rmo_id=rmo_id AND\n rlc_rma_id=" . Misc::escapeInteger($rma_id) . "\n ORDER BY\n rlc_id ASC"; $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return array(); } else { for ($i = 0; $i < count($res); $i++) { if (!empty($res[$i]['rlc_comparison_rmf_id'])) { $res[$i]['rlc_value'] = 'Field: ' . Reminder_Condition::getFieldTitle($res[$i]['rlc_comparison_rmf_id']); } elseif (strtolower($res[$i]['rmf_title']) == 'status') { $res[$i]['rlc_value'] = Status::getStatusTitle($res[$i]['rlc_value']); } elseif (strtolower($res[$i]['rmf_title']) == 'category') { $res[$i]['rlc_value'] = Category::getTitle($res[$i]['rlc_value']); } elseif (strtoupper($res[$i]['rlc_value']) != 'NULL') { $res[$i]['rlc_value'] .= ' hours'; } } return $res; } }
/** * Method used to generate an SQL query to be used in debugging the reminder * conditions. * * @param integer $rem_id The reminder ID * @param integer $rma_id The reminder action ID * @return string The SQL query */ public static function getSQLQuery($rem_id, $rma_id) { $reminder = self::getDetails($rem_id); $conditions = Reminder_Condition::getList($rma_id); $stmt = 'SELECT iss_id FROM {{%issue}}'; $products = self::getAssociatedProducts($reminder['rem_id']); if (count($products) > 0) { $stmt .= ', issue_product_version'; } $stmt .= self::getWhereClause($reminder, $conditions); // can't rely on the mysql server's timezone setting, so let's use gmt dates throughout $stmt = str_replace('UNIX_TIMESTAMP()', "UNIX_TIMESTAMP('" . Date_Helper::getCurrentDateGMT() . "')", $stmt); return $stmt; }
/** * 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; }