// | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to: | // | | // | Free Software Foundation, Inc. | // | 51 Franklin Street, Suite 330 | // | Boston, MA 02110-1301, USA. | // +----------------------------------------------------------------------+ require_once __DIR__ . '/../../../init.php'; // creates user accounts for all the customers $prj_id = 1; // FIXME: Customer::getAssocList does not exist $customers = Customer::getAssocList($prj_id); foreach ($customers as $customer_id => $customer_name) { echo "Customer: {$customer_name}<br />\n"; $details = Customer::getDetails($prj_id, $customer_id); foreach ($details['contacts'] as $contact) { echo 'Contact: ' . $contact['first_name'] . ' ' . $contact['last_name'] . ' (' . $contact['email'] . ")<br />\n"; $contact_id = User::getUserIDByContactID($contact['contact_id']); if (empty($contact_id)) { $sql = 'INSERT INTO {{%user}} SET usr_created_date = ?, usr_full_name = ?, usr_email = ?, usr_customer_id = ?, usr_customer_contact_id = ?, usr_preferences = ?'; $params = array(Date_Helper::getCurrentDateGMT(), $contact['first_name'] . ' ' . $contact['last_name'], $contact['email'], $customer_id, $contact['contact_id'], Prefs::getDefaults(array($prj_id))); try {
function getIncidentTypes($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)); $redeemed_only = XML_RPC_decode($p->getParam(3)); $prj_id = Issue::getProjectID($issue_id); createFakeCookie($email, $prj_id); $customer_id = Issue::getCustomerID($issue_id); if (!Customer::hasCustomerIntegration($prj_id)) { // no customer integration return new XML_RPC_Response(0, $XML_RPC_erruser + 1, "No customer integration for issue #{$issue_id}"); } elseif (!Customer::hasPerIncidentContract($prj_id, $customer_id)) { // check if is per incident contract return new XML_RPC_Response(0, $XML_RPC_erruser + 1, "Customer for issue #{$issue_id} does not have a per-incident contract"); } $details = Customer::getDetails($prj_id, $customer_id); foreach ($details['incident_details'] as $type_id => $type_details) { $is_redeemed = Customer::isRedeemedIncident($prj_id, $issue_id, $type_id); if ($redeemed_only && !$is_redeemed || !$redeemed_only && $is_redeemed) { unset($details['incident_details'][$type_id]); } } return new XML_RPC_Response(XML_RPC_Encode($details['incident_details'])); }
/** * Returns a list of issues touched by the specified user in the specified time frame. * * @access public * @param integer $usr_id The id of the user. * @param date $start The start date * @param date $end The end date * @param date $separate_closed If closed issues should be included in a separate array * @return array An array of issues touched by the user. */ function getTouchedIssuesByUser($usr_id, $start, $end, $separate_closed = false) { $stmt = "SELECT\n iss_id,\n iss_prj_id,\n iss_summary,\n iss_customer_id,\n sta_is_closed\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_history,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status\n ON\n iss_sta_id = sta_id\n WHERE\n his_iss_id = iss_id AND\n his_usr_id = " . Misc::escapeInteger($usr_id) . " AND\n his_created_date BETWEEN '" . Misc::escapeString($start) . "' AND '" . Misc::escapeString($end) . "' AND\n his_htt_id NOT IN(" . join(',', History::getTypeID(array('notification_removed', 'notification_added', 'notification_updated', 'remote_replier_added', 'replier_added', 'replier_removed', 'replier_other_added'))) . ")\n GROUP BY\n iss_id"; $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 ""; } else { $data = array("closed" => array(), "other" => array()); if (count($res) > 0) { foreach ($res as $index => $row) { if (!empty($row["iss_customer_id"]) && Customer::hasCustomerIntegration($row['iss_prj_id'])) { $details = Customer::getDetails($row["iss_prj_id"], $row["iss_customer_id"]); $row["customer_name"] = $details["customer_name"]; } if ($separate_closed && $row['sta_is_closed'] == 1) { $data['closed'][] = $row; } else { $data['other'][] = $row; } } $sort_function = create_function('$a,$b', 'return strcasecmp(@$a["customer_name"], @$b["customer_name"]);'); @usort($data['closed'], $sort_function); @usort($data['other'], $sort_function); } } return $data; }
function processResult($res, $date_field, $issue_field) { global $prj_id; global $usr_id; $data = array(); for ($i = 0; $i < count($res); $i++) { if (!Issue::canAccess($res[$i][$issue_field], $usr_id)) { continue; } if (Customer::hasCustomerIntegration($prj_id)) { $details = Customer::getDetails($prj_id, Issue::getCustomerID($res[$i][$issue_field])); $res[$i]["customer"] = @$details['customer_name']; } $res[$i]["date"] = Date_API::getFormattedDate($res[$i][$date_field], Date_API::getPreferredTimezone($usr_id)); // need to decode From:, To: mail headers if (isset($res[$i]["sup_from"])) { $res[$i]["sup_from"] = Mime_Helper::fixEncoding($res[$i]["sup_from"]); } if (isset($res[$i]["sup_to"])) { $res[$i]["sup_to"] = Mime_Helper::fixEncoding($res[$i]["sup_to"]); } $data[] = $res[$i]; } return $data; }
/** * Updates the incident counts * * @access public * @param integer $prj_id The project ID * @param integer $issue_id The issue ID * @param array $data An array of data containing which incident types to update. * @return integer 1 if all updates were successful, -1 or -2 otherwise. */ function updateRedeemedIncidents($prj_id, $issue_id, $data) { $details = Customer::getDetails($prj_id, Issue::getCustomerID($issue_id)); foreach ($details['incident_details'] as $type_id => $type_details) { $is_redeemed = Customer::isRedeemedIncident($prj_id, $issue_id, $type_id); if ($is_redeemed && @$data[$type_id] != 1) { // un-redeem issue $res = Customer::unflagIncident($prj_id, $issue_id, $type_id); } elseif (!$is_redeemed && @$data[$type_id] == 1) { // redeem issue if ($type_details['total'] - $type_details['redeemed'] > 0) { $res = Customer::flagIncident($prj_id, $issue_id, $type_id); } else { $res = -1; } } else { $res = 1; } if ($res != 1) { return $res; } } return $res; }
/** * Returns all data for this report. * * @access public * @return array */ function getData() { $data = array(); // determine if this should be customer based or support level based. if ($this->isCustomerBased()) { // customer based // get "all" row of data $data[] = $this->getAllRow(); foreach ($this->customers as $customer_id) { $details = Customer::getDetails($this->prj_id, $customer_id); $data[] = $this->getDataRow($details["customer_name"], array($customer_id)); } } else { // support level based if (count($this->levels) > 0) { $grouped_levels = Customer::getGroupedSupportLevels($this->prj_id); foreach ($this->levels as $level_name) { if ($level_name == "Aggregate") { // get "all" row of data $data[] = $this->getAllRow(); continue; } $support_options = array(); if ($this->exclude_expired_contracts) { $support_options[] = CUSTOMER_EXCLUDE_EXPIRED; } $customers = Customer::getListBySupportLevel($this->prj_id, $grouped_levels[$level_name], $support_options); $data[] = $this->getDataRow($level_name, $customers); } } } return $data; }
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to: | // | | // | Free Software Foundation, Inc. | // | 59 Temple Place - Suite 330 | // | Boston, MA 02111-1307, USA. | // +----------------------------------------------------------------------+ // | Authors: Bryan Alsdorf <*****@*****.**> | // +----------------------------------------------------------------------+ // // This page handles marking an issue as 'redeeming' an incident. include_once "config.inc.php"; include_once APP_INC_PATH . "class.template.php"; include_once APP_INC_PATH . "class.customer.php"; include_once APP_INC_PATH . "db_access.php"; Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true); $prj_id = Auth::getCurrentProject(); $issue_id = $_REQUEST['iss_id']; $tpl = new Template_API(); $tpl->setTemplate('redeem_incident.tpl.html'); if (!empty($_REQUEST['submit'])) { // update counts $res = Customer::updateRedeemedIncidents($prj_id, $issue_id, @$_REQUEST['redeem']); $tpl->assign('res', $res); } $details = Customer::getDetails($prj_id, Issue::getCustomerID($issue_id), true); $tpl->assign(array('issue_id' => $issue_id, 'redeemed' => Customer::getRedeemedIncidentDetails($prj_id, $issue_id), 'incident_details' => $details['incident_details'])); $tpl->displayTemplate();
/** * 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; }
$tpl = new Template_API(); $tpl->setTemplate("new.tpl.html"); Auth::checkAuthentication(APP_COOKIE); if (Auth::getCurrentRole() < User::getRoleID("Reporter")) { Auth::redirect("main.php"); } $usr_id = Auth::getUserID(); $prj_id = Auth::getCurrentProject(); if (Customer::hasCustomerIntegration($prj_id)) { if (Auth::getCurrentRole() == User::getRoleID('Customer')) { $customer_id = User::getCustomerID($usr_id); // check if the current customer has already redeemed all available per-incident tickets if (empty($HTTP_POST_VARS['cat']) && Customer::hasPerIncidentContract($prj_id, $customer_id) && !Customer::hasIncidentsLeft($prj_id, $customer_id)) { // show warning about per-incident limitation $tpl->setTemplate("customer/" . Customer::getBackendImplementationName($prj_id) . "/incident_limit_reached.tpl.html"); $tpl->assign('customer', Customer::getDetails($prj_id, $customer_id)); $tpl->displayTemplate(); exit; } $tpl->assign("message", Customer::getNewIssueMessage($prj_id, $customer_id)); } } if (@$HTTP_POST_VARS["cat"] == "report") { $res = Issue::insert(); if ($res != -1) { // show direct links to the issue page, issue listing page and // email listing page $tpl->assign("new_issue_id", $res); $tpl->assign("quarantine", Issue::getQuarantineInfo($res)); $tpl->assign("errors", $insert_errors); $tpl->assign("ticket", Issue::getDetails($res));
/** * Method used to get the details for a specific issue. * * @access public * @param integer $issue_id The issue ID * @param boolean $force_refresh If the cache should not be used. * @return array The details for the specified issue */ function getDetails($issue_id, $force_refresh = false) { global $HTTP_SERVER_VARS; static $returns; $issue_id = Misc::escapeInteger($issue_id); if (empty($issue_id)) { return ''; } if (!empty($returns[$issue_id]) && $force_refresh != true) { return $returns[$issue_id]; } $stmt = "SELECT\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue.*,\n prj_title,\n prc_title,\n pre_title,\n pri_title,\n sta_title,\n sta_abbreviation,\n sta_color status_color,\n sta_is_closed,\n\t\t\t\t\tsup_id as last_sup_id,\n\t\t\t\t\tseb_body as last_seb_body,\n\t\t\t\t\tema_id,\n\t\t\t\t\ten_email as reporter_email\n FROM\n (\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project\n )\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority\n ON\n iss_pri_id=pri_id\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status\n ON\n iss_sta_id=sta_id\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category\n ON\n iss_prc_id=prc_id\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release\n ON\n iss_pre_id=pre_id\n LEFT JOIN\n " . ETEL_USER_TABLE_NOSUB . "\n ON\n iss_usr_id=en_ID\n LEFT JOIN\n (\n\t\t\t\t\t\tSelect sup_id,sup_iss_id,seb_body\n\t\t\t\t\t\tfrom " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email\n\t\t\t\t\t\tleft join " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email_body on seb_sup_id = sup_id \n\t\t\t\t\t\twhere sup_iss_id = {$issue_id} order by sup_date desc\n\t\t\t\t\t) as sup\n ON\n sup_iss_id = iss_id\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account\n ON\n ema_prj_id = iss_prj_id\n WHERE\n iss_id={$issue_id} AND\n iss_prj_id=prj_id"; $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return ""; } else { if (empty($res)) { return ""; } else { $created_date_ts = Date_API::getUnixTimestamp($res['iss_created_date'], Date_API::getDefaultTimezone()); // get customer information, if any if (!empty($res['iss_customer_id']) && Customer::hasCustomerIntegration($res['iss_prj_id'])) { $res['customer_business_hours'] = Customer::getBusinessHours($res['iss_prj_id'], $res['iss_customer_id']); $res['contact_local_time'] = Date_API::getFormattedDate(Date_API::getCurrentDateGMT(), $res['iss_contact_timezone']); $res['customer_info'] = Customer::getDetails($res['iss_prj_id'], $res['iss_customer_id']); $res['redeemed_incidents'] = Customer::getRedeemedIncidentDetails($res['iss_prj_id'], $res['iss_id']); $max_first_response_time = Customer::getMaximumFirstResponseTime($res['iss_prj_id'], $res['iss_customer_id']); $res['max_first_response_time'] = Misc::getFormattedTime($max_first_response_time / 60); if (empty($res['iss_first_response_date'])) { $first_response_deadline = $created_date_ts + $max_first_response_time; if (Date_API::getCurrentUnixTimestampGMT() <= $first_response_deadline) { $res['max_first_response_time_left'] = Date_API::getFormattedDateDiff($first_response_deadline, Date_API::getCurrentUnixTimestampGMT()); } else { $res['overdue_first_response_time'] = Date_API::getFormattedDateDiff(Date_API::getCurrentUnixTimestampGMT(), $first_response_deadline); } } } $res['iss_original_description'] = $res["iss_description"]; if (!strstr($HTTP_SERVER_VARS["PHP_SELF"], 'update.php')) { $res["iss_description"] = nl2br(htmlspecialchars($res["iss_description"])); $res["iss_resolution"] = Resolution::getTitle($res["iss_res_id"]); } $res["iss_impact_analysis"] = nl2br(htmlspecialchars($res["iss_impact_analysis"])); $res["iss_created_date"] = Date_API::getFormattedDate($res["iss_created_date"]); $res['iss_created_date_ts'] = $created_date_ts; $res["assignments"] = @implode(", ", array_values(Issue::getAssignedUsers($res["iss_id"]))); list($res['authorized_names'], $res['authorized_repliers']) = Authorized_Replier::getAuthorizedRepliers($res["iss_id"]); $temp = Issue::getAssignedUsersStatus($res["iss_id"]); $res["has_inactive_users"] = 0; $res["assigned_users"] = array(); $res["assigned_inactive_users"] = array(); foreach ($temp as $usr_id => $usr_status) { if (!User::isActiveStatus($usr_status)) { $res["assigned_inactive_users"][] = $usr_id; $res["has_inactive_users"] = 1; } else { $res["assigned_users"][] = $usr_id; } } if (@in_array(Auth::getUserID(), $res["assigned_users"])) { $res["is_current_user_assigned"] = 1; } else { $res["is_current_user_assigned"] = 0; } $res["associated_issues_details"] = Issue::getAssociatedIssuesDetails($res["iss_id"]); $res["associated_issues"] = Issue::getAssociatedIssues($res["iss_id"]); $res["reporter"] = User::getFullName($res["iss_usr_id"]); $res["email_list_details"] = Support::getFirstEmailer($issue_id); if (!$res["reporter"]) { $first_emailer = Support::getFirstEmailer($issue_id); $res["reporter"] = $first_emailer . " (No Account)"; $res["reporter_email"] = preg_replace('/.*<|>/', '', $first_emailer); } if (empty($res["iss_updated_date"])) { $res["iss_updated_date"] = 'not updated yet'; } else { $res["iss_updated_date"] = Date_API::getFormattedDate($res["iss_updated_date"]); } $res["estimated_formatted_time"] = Misc::getFormattedTime($res["iss_dev_time"]); if (Release::isAssignable($res["iss_pre_id"])) { $release = Release::getDetails($res["iss_pre_id"]); $res["pre_title"] = $release["pre_title"]; $res["pre_status"] = $release["pre_status"]; } // need to return the list of issues that are duplicates of this one $res["duplicates"] = Issue::getDuplicateList($res["iss_id"]); $res["duplicates_details"] = Issue::getDuplicateDetailsList($res["iss_id"]); // also get the issue title of the duplicated issue if (!empty($res['iss_duplicated_iss_id'])) { $res['duplicated_issue'] = Issue::getDuplicatedDetails($res['iss_duplicated_iss_id']); } // get group information if (!empty($res["iss_grp_id"])) { $res["group"] = Group::getDetails($res["iss_grp_id"]); } // get quarantine issue $res["quarantine"] = Issue::getQuarantineInfo($res["iss_id"]); $returns[$issue_id] = $res; return $res; } } }
/** * Method used to get the details of a given issue. * * @access public * @param integer $issue_id The issue ID * @return array The issue details */ function getIssueDetails($issue_id) { $stmt = "SELECT\r\n iss_id,\r\n iss_customer_id,\r\n iss_summary,\r\n iss_description,\r\n iss_duplicated_iss_id,\r\n prj_id,\r\n prj_title,\r\n usr_full_name,\r\n usr_email,\r\n prc_title,\r\n pre_title,\r\n pri_title,\r\n sta_title,\r\n sta_color\r\n FROM\r\n (\r\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,\r\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project,\r\n " . ETEL_USER_TABLE . "\r\n )\r\n LEFT JOIN\r\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_priority\r\n ON\r\n iss_pri_id=pri_id\r\n LEFT JOIN\r\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_category\r\n ON\r\n iss_prc_id=prc_id\r\n LEFT JOIN\r\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project_release\r\n ON\r\n iss_pre_id=pre_id\r\n LEFT JOIN\r\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status\r\n ON\r\n iss_sta_id=sta_id\r\n WHERE\r\n iss_id=" . Misc::escapeInteger($issue_id) . " AND\r\n iss_prj_id=prj_id AND\r\n iss_usr_id=usr_id"; $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return ""; } else { $res['assigned_users'] = implode(", ", Issue::getAssignedUsers($issue_id)); // get customer information, if any if (!empty($res['iss_customer_id']) && Customer::hasCustomerIntegration($res['prj_id'])) { $res['customer_info'] = Customer::getDetails($res['prj_id'], $res['iss_customer_id']); } return $res; } }