$tpl->assign('delete_filter_result', $res); } elseif ($cat == 'remove_support_email') { $res = Support::removeAssociation(); $tpl->assign('remove_association_result', $res); } elseif ($cat == 'delete_attachment') { $res = Attachment::remove($id); $tpl->assign('remove_attachment_result', $res); } elseif ($cat == 'delete_file') { $res = Attachment::removeIndividualFile($id); $tpl->assign('remove_file_result', $res); } elseif ($cat == 'remove_checkin') { $res = SCM::remove($items); $tpl->assign('remove_checkin_result', $res); } elseif ($cat == 'unassign') { $res = Issue::deleteUserAssociation($iss_id, $usr_id); Workflow::handleAssignmentChange($prj_id, $iss_id, Auth::getUserID(), Issue::getDetails($iss_id), Issue::getAssignedUserIDs($iss_id)); $tpl->assign('unassign_result', $res); } elseif ($cat == 'remove_email') { $res = Support::removeEmails(); $tpl->assign('remove_email_result', $res); } elseif ($cat == 'clear_duplicate') { $res = Issue::clearDuplicateStatus($iss_id); $tpl->assign('clear_duplicate_result', $res); } elseif ($cat == 'delete_phone') { $res = Phone_Support::remove($id); $tpl->assign('delete_phone_result', $res); } elseif ($cat == 'new_status') { $res = Issue::setStatus($iss_id, $status_id, true); if ($res == 1) { History::add($iss_id, $usr_id, 'status_changed', "Issue manually set to status '{status}' by {user}", array('status' => Status::getStatusTitle($status_id), 'user' => User::getFullName($usr_id))); }
// | 51 Franklin Street, Suite 330 | // | Boston, MA 02110-1301, USA. | // +----------------------------------------------------------------------+ // | Authors: João Prado Maia <*****@*****.**> | // +----------------------------------------------------------------------+ require_once dirname(__FILE__) . '/../init.php'; $tpl = new Template_Helper(); $tpl->setTemplate('self_assign.tpl.html'); Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true); $usr_id = Auth::getUserID(); $prj_id = Auth::getCurrentProject(); $issue_id = $_REQUEST['iss_id']; $tpl->assign('issue_id', $issue_id); // check if issue is assigned to someone else and if so, confirm change. $assigned_user_ids = Issue::getAssignedUserIDs($issue_id); if (count($assigned_user_ids) > 0 && empty($_REQUEST['target'])) { $tpl->assign(array('prompt_override' => 1, 'assigned_users' => Issue::getAssignedUsers($issue_id))); } else { $issue_details = Issue::getDetails($issue_id); // force assignment change if (@$_REQUEST['target'] == 'replace') { // remove current user(s) first Issue::deleteUserAssociations($issue_id, $usr_id); } $res = Issue::addUserAssociation($usr_id, $issue_id, $usr_id); $tpl->assign('self_assign_result', $res); Notification::subscribeUser($usr_id, $issue_id, $usr_id, Notification::getDefaultActions($issue_id, User::getEmail($usr_id), 'self_assign')); Workflow::handleAssignmentChange($prj_id, $issue_id, $usr_id, $issue_details, Issue::getAssignedUserIDs($issue_id), false); } $tpl->assign('current_user_prefs', Prefs::get($usr_id)); $tpl->displayTemplate();
function mayChangeIssue($p) { $email = XML_RPC_decode($p->getParam(0)); $password = XML_RPC_decode($p->getParam(1)); $auth = authenticate($email, $password); if (is_object($auth)) { return $auth; } $issue_id = XML_RPC_decode($p->getParam(2)); $usr_id = User::getUserIDByEmail($email); $assignees = Issue::getAssignedUserIDs($issue_id); if (count($assignees) > 0) { if (in_array($usr_id, $assignees)) { return new XML_RPC_Response(XML_RPC_Encode("yes")); } else { return new XML_RPC_Response(XML_RPC_Encode("no")); } } else { return new XML_RPC_Response(XML_RPC_Encode("yes")); } }
/** * TODO: use boolean return * * @param int $issue_id * @return string * @access protected */ public function mayChangeIssue($issue_id) { $usr_id = Auth::getUserID(); $assignees = Issue::getAssignedUserIDs($issue_id); if (count($assignees) > 0) { if (in_array($usr_id, $assignees)) { return 'yes'; } else { return 'no'; } } else { return 'yes'; } }
/** * 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; }
$tpl->assign("delete_filter_result", $res); } elseif (@$HTTP_POST_VARS["cat"] == "remove_support_email") { $res = Support::removeAssociation(); $tpl->assign("remove_association_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "delete_attachment") { $res = Attachment::remove($HTTP_GET_VARS["id"]); $tpl->assign("remove_attachment_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "delete_file") { $res = Attachment::removeIndividualFile($HTTP_GET_VARS["id"]); $tpl->assign("remove_file_result", $res); } elseif (@$HTTP_POST_VARS["cat"] == "remove_checkin") { $res = SCM::remove(); $tpl->assign("remove_checkin_result", $res); } elseif (@$HTTP_GET_VARS['cat'] == 'unassign') { $res = Issue::deleteUserAssociation($HTTP_GET_VARS["iss_id"], $usr_id); Workflow::handleAssignmentChange($prj_id, $HTTP_GET_VARS["iss_id"], Auth::getUserID(), Issue::getDetails($HTTP_GET_VARS["iss_id"]), Issue::getAssignedUserIDs($HTTP_GET_VARS["iss_id"])); $tpl->assign('unassign_result', $res); } elseif (@$HTTP_POST_VARS["cat"] == "remove_email") { $res = Support::removeEmails(); $tpl->assign("remove_email_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "clear_duplicate") { $res = Issue::clearDuplicateStatus($HTTP_GET_VARS["iss_id"]); $tpl->assign("clear_duplicate_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "delete_phone") { $res = Phone_Support::remove($HTTP_GET_VARS["id"]); $tpl->assign("delete_phone_result", $res); } elseif (@$HTTP_GET_VARS["cat"] == "new_status") { // XXX: need to call the workflow api in the following function? $res = Issue::setStatus($HTTP_GET_VARS["iss_id"], $HTTP_GET_VARS["new_sta_id"], true); if ($res == 1) { History::add($HTTP_GET_VARS["iss_id"], $usr_id, History::getTypeID('status_changed'), "Issue manually set to status '" . Status::getStatusTitle($HTTP_GET_VARS["new_sta_id"]) . "' by " . User::getFullName($usr_id));
/** * 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; }
/** * Returns the options associated with a specific field * * @param string $field_name The name of the field * @param integer $issue_id The ID of the issue * @return array An array of options for the specified field */ private static function getOptions($field_name, $issue_id) { $prj_id = Issue::getProjectID($issue_id); switch ($field_name) { case 'assignee': $users = Project::getUserAssocList($prj_id, 'active', User::ROLE_CUSTOMER); $current_assignees = Issue::getAssignedUserIDs($issue_id); foreach ($current_assignees as $usr_id) { if (!isset($users[$usr_id])) { $users[$usr_id] = User::getFullName($usr_id); } asort($users); } return $users; case 'priority': return Priority::getAssocList($prj_id); case 'severity': return Severity::getAssocList($prj_id); } return array(); }
/** * 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; }
/** * 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; }
/** * Method used to see if a user is assigned to an issue. * * @access public * @param integer $issue_id The issue ID * @param integer $usr_id An integer containg the ID of the user. * @return boolean true if the user(s) are assigned to the issue. */ function isAssignedToUser($issue_id, $usr_id) { $assigned_users = Issue::getAssignedUserIDs($issue_id); if (in_array($usr_id, $assigned_users)) { return true; } else { return false; } }
/** * Send an email to all issue assignees * * @param integer $issue_id The ID of the issue * @param string $type The type of notification to send * @param array $data Any extra data to pass to the template */ public function notifyAssignees($issue_id, $type, $data, $title = '') { $prj_id = Issue::getProjectID($issue_id); $assignees = Issue::getAssignedUserIDs($issue_id); if (count($assignees) > 0) { // get issue details $issue = Issue::getDetails($issue_id); // open text template $tpl = new Template_Helper(); $tpl->setTemplate('notifications/' . $type . '.tpl.text'); $tpl->assign(array('app_title' => Misc::getToolCaption(), 'issue' => $issue, 'data' => $data)); foreach ($assignees as $usr_id) { $usr_email = User::getFromHeader($usr_id); if (!Workflow::shouldEmailAddress($prj_id, Mail_Helper::getEmailAddress($usr_email))) { continue; } // change the current locale Language::set(User::getLang($usr_id)); $text_message = $tpl->getTemplateContents(); $from = self::getFixedFromHeader($issue_id, '', 'issue'); $subject = "[#{$issue_id}] {$title}: " . $issue['iss_summary']; // send email (use PEAR's classes) $mail = new Mail_Helper(); $mail->setTextBody($text_message); $mail->setHeaders(Mail_Helper::getBaseThreadingHeaders($issue_id)); $mail->send($from, $usr_email, $subject, true, $issue_id, $type); } Language::restore(); } }
/** * Method used to bulk update a list of issues * * @return boolean */ public static function bulkUpdate() { // check if user performing this chance has the proper role if (Auth::getCurrentRole() < User::getRoleID('Manager')) { return -1; } $items = (array) $_POST['item']; $new_status_id = (int) $_POST['status']; $new_release_id = (int) $_POST['release']; $new_priority_id = (int) $_POST['priority']; $new_category_id = (int) $_POST['category']; foreach ($items as $issue_id) { $issue_id = (int) $issue_id; if (!self::canAccess($issue_id, Auth::getUserID())) { continue; } if (self::getProjectID($issue_id) != Auth::getCurrentProject()) { // make sure issue is not in another project continue; } $issue_details = Issue::getDetails($issue_id); $updated_fields = array(); // update assignment if (count(@$_POST['users']) > 0) { $users = (array) $_POST['users']; // get who this issue is currently assigned too $stmt = 'SELECT isu_usr_id, usr_full_name FROM {{%issue_user}}, {{%user}} WHERE isu_usr_id = usr_id AND isu_iss_id = ?'; try { $current_assignees = DB_Helper::getInstance()->getPair($stmt, array($issue_id)); } catch (DbException $e) { return -1; } foreach ($current_assignees as $usr_id => $usr_name) { if (!in_array($usr_id, $users)) { self::deleteUserAssociation($issue_id, $usr_id, false); } } $new_user_names = array(); $new_assignees = array(); foreach ($users as $usr_id) { $usr_id = (int) $usr_id; $new_user_names[$usr_id] = User::getFullName($usr_id); // check if the issue is already assigned to this person $stmt = 'SELECT COUNT(*) AS total FROM {{%issue_user}} WHERE isu_iss_id=? AND isu_usr_id=?'; $total = DB_Helper::getInstance()->getOne($stmt, array($issue_id, $usr_id)); if ($total > 0) { continue; } else { $new_assignees[] = $usr_id; // add the assignment self::addUserAssociation(Auth::getUserID(), $issue_id, $usr_id, false); Notification::subscribeUser(Auth::getUserID(), $issue_id, $usr_id, Notification::getAllActions()); } } $prj_id = Auth::getCurrentProject(); $usr_ids = Issue::getAssignedUserIDs($issue_id); Workflow::handleAssignmentChange($prj_id, $issue_id, Auth::getUserID(), $issue_details, $usr_ids, false); Notification::notifyNewAssignment($new_assignees, $issue_id); $updated_fields['Assignment'] = History::formatChanges(implode(', ', $current_assignees), implode(', ', $new_user_names)); } // update status if ($new_status_id) { $old_status_id = self::getStatusID($issue_id); $res = self::setStatus($issue_id, $new_status_id, false); if ($res == 1) { $updated_fields['Status'] = History::formatChanges(Status::getStatusTitle($old_status_id), Status::getStatusTitle($new_status_id)); } } // update release if ($new_release_id) { $old_release_id = self::getRelease($issue_id); $res = self::setRelease($issue_id, $new_release_id); if ($res == 1) { $updated_fields['Release'] = History::formatChanges(Release::getTitle($old_release_id), Release::getTitle($new_release_id)); } } // update priority if ($new_priority_id) { $old_priority_id = self::getPriority($issue_id); $res = self::setPriority($issue_id, $new_priority_id); if ($res == 1) { $updated_fields['Priority'] = History::formatChanges(Priority::getTitle($old_priority_id), Priority::getTitle($new_priority_id)); } } // update category if ($new_category_id) { $old_category_id = self::getCategory($issue_id); $res = self::setCategory($issue_id, $new_category_id); if ($res == 1) { $updated_fields['Category'] = History::formatChanges(Category::getTitle($old_category_id), Category::getTitle($new_category_id)); } } if (count($updated_fields) > 0) { // log the changes $changes = ''; $k = 0; foreach ($updated_fields as $key => $value) { if ($k > 0) { $changes .= '; '; } $changes .= "{$key}: {$value}"; $k++; } $usr_id = Auth::getUserID(); History::add($issue_id, $usr_id, 'issue_bulk_updated', 'Issue updated ({changes}) by {user}', array('changes' => $changes, 'user' => User::getFullName(Auth::getUserID()))); } // close if request if (isset($_REQUEST['closed_status']) && !empty($_REQUEST['closed_status'])) { self::close(Auth::getUserID(), $issue_id, true, 0, $_REQUEST['closed_status'], $_REQUEST['closed_message'], $_REQUEST['notification_list']); } } return true; }
} if ($ref_id) { $stmt = "SELECT\n\t\t\t\ten_ID\n\t\t\t FROM\n\t\t\t\t" . ETEL_USER_TRANS_TABLE_NOSUB . "\n\t\t\t WHERE\n\t\t\t\treference_number='" . Misc::escapeString($ref_id) . "'"; $info = $GLOBALS["db_api"]->dbh->getOne($stmt); if (PEAR::isError($info)) { Error_Handler::logError(array($info->getMessage(), $info->getDebugInfo()), __FILE__, __LINE__); return false; } else { $target_usr_id = $info; $newstatus = 8; $_REQUEST["target"] = "replace"; } } } // check if issue is assigned to someone else and if so, confirm change. $assigned_user_ids = Issue::getAssignedUserIDs($issue_id); if (count($assigned_user_ids) > 0 && empty($_REQUEST["target"]) && !$_REQUEST['assigntomerc']) { $tpl->assign(array("prompt_override" => 1, "assigned_users" => Issue::getAssignedUsers($issue_id))); } else { // force assignment change if (@$_REQUEST["target"] == "replace") { // remove current user(s) first Issue::deleteUserAssociations($issue_id, $usr_id); } $res = Issue::addUserAssociation($usr_id, $issue_id, $target_usr_id); $tpl->assign("self_assign_result", $res); if ($newstatus) { $res = Issue::setStatus($issue_id, $newstatus, true); } Notification::subscribeUser($usr_id, $issue_id, $target_usr_id, Notification::getDefaultActions()); Workflow::handleAssignment($prj_id, $issue_id, $target_usr_id);
/** * Send an email to all issue assignees * * @access public * @param integer $issue_id The ID of the issue * @param string $type The type of notification to send * @param array $data Any extra data to pass to the template */ function notifyAssignees($issue_id, $type, $data, $title = '') { $prj_id = Issue::getProjectID($issue_id); $assignees = Issue::getAssignedUserIDs($issue_id); if (count($assignees) > 0) { // get issue details $issue = Notification::getIssueDetails($issue_id); // open text template $tpl = new Template_API(); $tpl->setTemplate('notifications/' . $type . '.tpl.text'); $tpl->bulkAssign(array("app_title" => Misc::getToolCaption(), "issue" => $issue, "data" => $data)); $text_message = $tpl->getTemplateContents(); for ($i = 0; $i < count($assignees); $i++) { if (!Workflow::shouldEmailAddress($prj_id, Mail_API::getEmailAddress(User::getFromHeader($assignees[$i])))) { continue; } // send email (use PEAR's classes) $mail = new Mail_API(); $mail->setTextBody($text_message); $mail->setHeaders(Mail_API::getBaseThreadingHeaders($issue_id)); $mail->send(Notification::getFixedFromHeader($issue_id, '', 'issue'), User::getFromHeader($assignees[$i]), "[#{$issue_id}] {$title}: " . $issue['iss_summary'], TRUE, $issue_id, $type); } } }