/** * Returns the current value for the specified field / issue. This method just calls * the appropriate class / method * * @param integer $issue_id * @param integer $field_name * @return mixed */ private static function getValue($issue_id, $field_name) { switch ($field_name) { case 'assignee': return Issue::getAssignedUserIDs($issue_id); case 'priority': return Issue::getPriority($issue_id); case 'severity': return Issue::getSeverity($issue_id); } return false; }
/** * 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 bulk update a list of issues * * @access public * @return boolean */ function bulkUpdate() { global $HTTP_POST_VARS; // check if user performing this chance has the proper role if (Auth::getCurrentRole() < User::getRoleID('Manager')) { return -1; } $items = Misc::escapeInteger($HTTP_POST_VARS['item']); $new_status_id = Misc::escapeInteger($_POST['status']); $new_release_id = Misc::escapeInteger($_POST['release']); $new_priority_id = Misc::escapeInteger($_POST['priority']); $new_category_id = Misc::escapeInteger($_POST['category']); $new_project_id = Misc::escapeInteger($_POST['project']); for ($i = 0; $i < count($items); $i++) { if (!Issue::canAccess($items[$i], Auth::getUserID())) { continue; } elseif (Issue::getProjectID($HTTP_POST_VARS['item'][$i]) != Auth::getCurrentProject()) { // make sure issue is not in another project continue; } $updated_fields = array(); // update assignment if (count(@$HTTP_POST_VARS['users']) > 0) { $users = Misc::escapeInteger($HTTP_POST_VARS['users']); // get who this issue is currently assigned too $stmt = "SELECT\n isu_usr_id,\n CONCAT(en_firstname,' ', en_lastname) as usr_full_name\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user,\n " . ETEL_USER_TABLE_NOSUB . "\n WHERE\n isu_usr_id = en_ID AND\n isu_iss_id = " . $items[$i]; $current_assignees = $GLOBALS["db_api"]->dbh->getAssoc($stmt); if (PEAR::isError($current_assignees)) { Error_Handler::logError(array($current_assignees->getMessage(), $current_assignees->getDebugInfo()), __FILE__, __LINE__); return -1; } foreach ($current_assignees as $usr_id => $usr_name) { if (!in_array($usr_id, $users)) { Issue::deleteUserAssociation($items[$i], $usr_id, false); } } $new_user_names = array(); $new_assignees = array(); foreach ($users as $usr_id) { $new_user_names[$usr_id] = User::getFullName($usr_id); // check if the issue is already assigned to this person $stmt = "SELECT\n COUNT(*) AS total\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user\n WHERE\n isu_iss_id=" . $items[$i] . " AND\n isu_usr_id=" . $usr_id; $total = $GLOBALS["db_api"]->dbh->getOne($stmt); if ($total > 0) { continue; } else { $new_assignees[] = $usr_id; // add the assignment Issue::addUserAssociation(Auth::getUserID(), $items[$i], $usr_id, false); Notification::subscribeUser(Auth::getUserID(), $items[$i], $usr_id, Notification::getAllActions()); Workflow::handleAssignment(Auth::getCurrentProject(), $items[$i], Auth::getUserID()); } } Notification::notifyNewAssignment($new_assignees, $items[$i]); $updated_fields['Assignment'] = History::formatChanges(join(', ', $current_assignees), join(', ', $new_user_names)); } // update status if (!empty($new_status_id)) { $old_status_id = Issue::getStatusID($items[$i]); $res = Issue::setStatus($items[$i], $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 (!empty($new_release_id)) { $old_release_id = Issue::getRelease($items[$i]); $res = Issue::setRelease($items[$i], $new_release_id); if ($res == 1) { $updated_fields['Release'] = History::formatChanges(Release::getTitle($old_release_id), Release::getTitle($new_release_id)); } } // update priority if (!empty($new_priority_id)) { $old_priority_id = Issue::getPriority($items[$i]); $res = Issue::setPriority($items[$i], $new_priority_id); if ($res == 1) { $updated_fields['Priority'] = History::formatChanges(Priority::getTitle($old_priority_id), Priority::getTitle($new_priority_id)); } } // update category if (!empty($new_category_id)) { $old_category_id = Issue::getCategory($items[$i]); $res = Issue::setCategory($items[$i], $new_category_id); if ($res == 1) { $updated_fields['Category'] = History::formatChanges(Category::getTitle($old_category_id), Category::getTitle($new_category_id)); } } // update project if (!empty($new_project_id)) { $old_project_id = Issue::getProjectID($items[$i]); $res = Issue::setProject($items[$i], $new_project_id); if ($res == 1) { $updated_fields['Project'] = History::formatChanges(Category::getTitle($old_project_id), Category::getTitle($new_project_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++; } History::add($items[$i], Auth::getUserID(), History::getTypeID('issue_bulk_updated'), "Issue updated ({$changes}) by " . User::getFullName(Auth::getUserID())); } } return true; }