// | 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();
/** * Sets the assignees for the issue * * @param integer $issue_id * @param array $assignees * @return int 1 if success, -1 if error, 0 if no change was needed. */ public static function setAssignees($issue_id, $assignees) { if (!is_array($assignees)) { $assignees = array(); } // see if there is anything to change $old_assignees = self::getAssignedUserIDs($issue_id); if (count(array_diff($old_assignees, $assignees)) == 0 && count(array_diff($assignees, $old_assignees)) == 0) { return 0; } $old_assignee_names = self::getAssignedUsers($issue_id); Workflow::handleAssignmentChange(self::getProjectID($issue_id), $issue_id, Auth::getUserID(), self::getDetails($issue_id), $assignees, true); // clear up the assignments for this issue, and then assign it to the current user self::deleteUserAssociations($issue_id); $assignee_names = array(); foreach ($assignees as $assignee) { $res = self::addUserAssociation(Auth::getUserID(), $issue_id, $assignee, false); if ($res == -1) { return -1; } $assignee_names[] = User::getFullName($assignee); Notification::subscribeUser(Auth::getUserID(), $issue_id, $assignee, Notification::getDefaultActions($issue_id, User::getEmail($assignee), 'set_assignees'), false); } Notification::notifyNewAssignment($assignees, $issue_id); $usr_id = Auth::getUserID(); History::add($issue_id, $usr_id, 'user_associated', 'Issue assignment to changed ({changes}) by {user}', array('changes' => History::formatChanges(implode(', ', $old_assignee_names), implode(', ', $assignee_names)), 'user' => User::getFullName($usr_id))); return 1; }
$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));
$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))); }
/** * Method used to update the details of a specific issue. * * @access public * @param integer $issue_id The issue ID * @return integer 1 if the update worked, -1 or -2 otherwise */ function update($issue_id) { global $HTTP_POST_VARS; $issue_id = Misc::escapeInteger($issue_id); $usr_id = Auth::getUserID(); $prj_id = Issue::getProjectID($issue_id); // get all of the 'current' information of this issue $current = Issue::getDetails($issue_id); // update the issue associations $association_diff = Misc::arrayDiff($current['associated_issues'], @$HTTP_POST_VARS['associated_issues']); if (count($association_diff) > 0) { // go through the new assocations, if association already exists, skip it $associations_to_remove = $current['associated_issues']; if (count(@$HTTP_POST_VARS['associated_issues']) > 0) { foreach ($HTTP_POST_VARS['associated_issues'] as $index => $associated_id) { if (!in_array($associated_id, $current['associated_issues'])) { Issue::addAssociation($issue_id, $associated_id, $usr_id); } else { // already assigned, remove this user from list of users to remove unset($associations_to_remove[array_search($associated_id, $associations_to_remove)]); } } } if (count($associations_to_remove) > 0) { foreach ($associations_to_remove as $associated_id) { Issue::deleteAssociation($issue_id, $associated_id); } } } if (!empty($HTTP_POST_VARS['expected_resolution_date']['Year']) && !empty($HTTP_POST_VARS['expected_resolution_date']['Month']) && !empty($HTTP_POST_VARS['expected_resolution_date']['Day'])) { $HTTP_POST_VARS['expected_resolution_date'] = sprintf('%s-%s-%s', $HTTP_POST_VARS['expected_resolution_date']['Year'], $HTTP_POST_VARS['expected_resolution_date']['Month'], $HTTP_POST_VARS['expected_resolution_date']['Day']); } else { $HTTP_POST_VARS['expected_resolution_date'] = ''; } $assignments_changed = false; if (@$HTTP_POST_VARS["keep_assignments"] == "no") { // only change the issue-user associations if there really were any changes $old_assignees = array_merge($current['assigned_users'], $current['assigned_inactive_users']); if (!empty($HTTP_POST_VARS['assignments'])) { $new_assignees = @$HTTP_POST_VARS['assignments']; } else { $new_assignees = array(); } $assignment_notifications = array(); // remove people from the assignment list, if appropriate foreach ($old_assignees as $assignee) { if (!in_array($assignee, $new_assignees)) { Issue::deleteUserAssociation($issue_id, $assignee); $assignments_changed = true; } } // add people to the assignment list, if appropriate foreach ($new_assignees as $assignee) { if (!in_array($assignee, $old_assignees)) { Issue::addUserAssociation($usr_id, $issue_id, $assignee); Notification::subscribeUser($usr_id, $issue_id, $assignee, Notification::getDefaultActions(), TRUE); $assignment_notifications[] = $assignee; $assignments_changed = true; } } if (count($assignment_notifications) > 0) { Notification::notifyNewAssignment($assignment_notifications, $issue_id); } } if (empty($HTTP_POST_VARS["estimated_dev_time"])) { $HTTP_POST_VARS["estimated_dev_time"] = 0; } $stmt = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n SET\n iss_updated_date='" . Date_API::getCurrentDateGMT() . "',\n iss_last_public_action_date='" . Date_API::getCurrentDateGMT() . "',\n iss_last_public_action_type='updated',"; if (!empty($HTTP_POST_VARS["category"])) { $stmt .= "iss_prc_id=" . Misc::escapeInteger($HTTP_POST_VARS["category"]) . ","; } if (@$HTTP_POST_VARS["keep"] == "no") { $stmt .= "iss_pre_id=" . Misc::escapeInteger($HTTP_POST_VARS["release"]) . ","; } if (!empty($HTTP_POST_VARS['expected_resolution_date'])) { $stmt .= "iss_expected_resolution_date='" . Misc::escapeString($HTTP_POST_VARS['expected_resolution_date']) . "',"; } else { $stmt .= "iss_expected_resolution_date=null,"; } $stmt .= "\n iss_pre_id=" . Misc::escapeInteger($HTTP_POST_VARS["release"]) . ",\n iss_pri_id=" . Misc::escapeInteger($HTTP_POST_VARS["priority"]) . ",\n iss_sta_id=" . Misc::escapeInteger($HTTP_POST_VARS["status"]) . ",\n iss_res_id=" . Misc::escapeInteger($HTTP_POST_VARS["resolution"]) . ",\n iss_summary='" . Misc::escapeString($HTTP_POST_VARS["summary"]) . "',\n iss_description='" . Misc::escapeString($HTTP_POST_VARS["description"]) . "',\n iss_dev_time='" . Misc::escapeString($HTTP_POST_VARS["estimated_dev_time"]) . "',\n iss_percent_complete= '" . Misc::escapeString($HTTP_POST_VARS["percent_complete"]) . "',\n iss_trigger_reminders=" . Misc::escapeInteger($HTTP_POST_VARS["trigger_reminders"]) . ",\n iss_grp_id ='" . Misc::escapeInteger($HTTP_POST_VARS["group"]) . "'"; if (isset($HTTP_POST_VARS['private'])) { $stmt .= ",\n iss_private = " . Misc::escapeInteger($HTTP_POST_VARS['private']); } $stmt .= "\n WHERE\n iss_id={$issue_id}"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } else { // add change to the history (only for changes on specific fields?) $updated_fields = array(); if ($current["iss_expected_resolution_date"] != $HTTP_POST_VARS['expected_resolution_date']) { $updated_fields["Expected Resolution Date"] = History::formatChanges($current["iss_expected_resolution_date"], $HTTP_POST_VARS['expected_resolution_date']); } if ($current["iss_prc_id"] != $HTTP_POST_VARS["category"]) { $updated_fields["Category"] = History::formatChanges(Category::getTitle($current["iss_prc_id"]), Category::getTitle($HTTP_POST_VARS["category"])); } if ($current["iss_pre_id"] != $HTTP_POST_VARS["release"]) { $updated_fields["Release"] = History::formatChanges(Release::getTitle($current["iss_pre_id"]), Release::getTitle($HTTP_POST_VARS["release"])); } if ($current["iss_pri_id"] != $HTTP_POST_VARS["priority"]) { $updated_fields["Priority"] = History::formatChanges(Priority::getTitle($current["iss_pri_id"]), Priority::getTitle($HTTP_POST_VARS["priority"])); Workflow::handlePriorityChange($prj_id, $issue_id, $usr_id, $current, $HTTP_POST_VARS); } if ($current["iss_sta_id"] != $HTTP_POST_VARS["status"]) { // clear out the last-triggered-reminder flag when changing the status of an issue Reminder_Action::clearLastTriggered($issue_id); // if old status was closed and new status is not, clear closed data from issue. $old_status_details = Status::getDetails($current['iss_sta_id']); if ($old_status_details['sta_is_closed'] == 1) { $new_status_details = Status::getDetails($HTTP_POST_VARS["status"]); if ($new_status_details['sta_is_closed'] != 1) { Issue::clearClosed($issue_id); } } $updated_fields["Status"] = History::formatChanges(Status::getStatusTitle($current["iss_sta_id"]), Status::getStatusTitle($HTTP_POST_VARS["status"])); } if ($current["iss_res_id"] != $HTTP_POST_VARS["resolution"]) { $updated_fields["Resolution"] = History::formatChanges(Resolution::getTitle($current["iss_res_id"]), Resolution::getTitle($HTTP_POST_VARS["resolution"])); } if ($current["iss_dev_time"] != $HTTP_POST_VARS["estimated_dev_time"]) { $updated_fields["Estimated Dev. Time"] = History::formatChanges(Misc::getFormattedTime($current["iss_dev_time"] * 60), Misc::getFormattedTime($HTTP_POST_VARS["estimated_dev_time"] * 60)); } if ($current["iss_summary"] != $HTTP_POST_VARS["summary"]) { $updated_fields["Summary"] = ''; } if ($current["iss_description"] != $HTTP_POST_VARS["description"]) { $updated_fields["Description"] = ''; } if (count($updated_fields) > 0) { // log the changes $changes = ''; $i = 0; foreach ($updated_fields as $key => $value) { if ($i > 0) { $changes .= "; "; } if ($key != "Summary" && $key != "Description") { $changes .= "{$key}: {$value}"; } else { $changes .= "{$key}"; } $i++; } History::add($issue_id, $usr_id, History::getTypeID('issue_updated'), "Issue updated ({$changes}) by " . User::getFullName($usr_id)); // send notifications for the issue being updated Notification::notifyIssueUpdated($issue_id, $current, $HTTP_POST_VARS); } // record group change as a seperate change if ($current["iss_grp_id"] != $HTTP_POST_VARS["group"]) { History::add($issue_id, $usr_id, History::getTypeID('group_changed'), "Group changed (" . History::formatChanges(Group::getName($current["iss_grp_id"]), Group::getName($HTTP_POST_VARS["group"])) . ") by " . User::getFullName($usr_id)); } // now update any duplicates, if any $update_dupe = array('Category', 'Release', 'Priority', 'Release', 'Resolution'); // COMPAT: the following line requires PHP > 4.0.4 $intersect = array_intersect($update_dupe, array_keys($updated_fields)); if ($current["duplicates"] != '' && count($intersect) > 0) { Issue::updateDuplicates($issue_id); } // if there is customer integration, mark last customer action if (Customer::hasCustomerIntegration($prj_id) && User::getRoleByUser($usr_id, $prj_id) == User::getRoleID('Customer')) { Issue::recordLastCustomerAction($issue_id); } if ($assignments_changed) { // XXX: we may want to also send the email notification for those "new" assignees Workflow::handleAssignmentChange(Issue::getProjectID($issue_id), $issue_id, $usr_id, Issue::getDetails($issue_id), @$HTTP_POST_VARS['assignments'], false); } Workflow::handleIssueUpdated($prj_id, $issue_id, $usr_id, $current, $HTTP_POST_VARS); return 1; } }