Time_Tracking::insertEntry(); } } elseif (@$HTTP_POST_VARS["cat"] == "save_draft") { $res = Draft::saveEmail($issue_id, $HTTP_POST_VARS["to"], $HTTP_POST_VARS["cc"], $HTTP_POST_VARS["subject"], $HTTP_POST_VARS["message"], $HTTP_POST_VARS["parent_id"]); $tpl->assign("draft_result", $res); } elseif (@$HTTP_POST_VARS["cat"] == "update_draft") { $res = Draft::update($issue_id, $HTTP_POST_VARS["draft_id"], $HTTP_POST_VARS["to"], $HTTP_POST_VARS["cc"], $HTTP_POST_VARS["subject"], $HTTP_POST_VARS["message"], $HTTP_POST_VARS["parent_id"]); $tpl->assign("draft_result", $res); } elseif (Auth::getCurrentRole() >= User::getRoleID('Developer')) { $res = Issue::addUserAssociation($usr_id, $issue_id, $usr_id); } // enter the time tracking entry about this new email if (@$HTTP_POST_VARS["cat"] == "save_draft" || @$HTTP_POST_VARS["cat"] == "update_draft") { if (!empty($HTTP_POST_VARS['time_spent'])) { $HTTP_POST_VARS['issue_id'] = $issue_id; $HTTP_POST_VARS['category'] = Time_Tracking::getCategoryID('Email Discussion'); $HTTP_POST_VARS['summary'] = 'Time entry inserted when saving an email draft.'; Time_Tracking::insertEntry(); } } if (@$HTTP_GET_VARS['cat'] == 'view_draft') { $draft = Draft::getDetails($HTTP_GET_VARS['id']); $email = array('sup_subject' => $draft['emd_subject'], 'seb_body' => $draft['emd_body'], 'sup_from' => $draft['to'], 'cc' => implode('; ', $draft['cc'])); // try to guess the correct email account to be associated with this email if (!empty($draft['emd_sup_id'])) { $HTTP_GET_VARS['ema_id'] = Email_Account::getAccountByEmail($draft['emd_sup_id']); } else { // if we are not replying to an existing message, just get the first email account you can find... $HTTP_GET_VARS['ema_id'] = Email_Account::getEmailAccount(); } $tpl->bulkAssign(array("draft_id" => $HTTP_GET_VARS['id'], "email" => $email, "parent_email_id" => $draft['emd_sup_id'], "draft_status" => $draft['emd_status']));
if (!@empty($HTTP_POST_VARS['new_status'])) { $res = Issue::setStatus($issue_id, $HTTP_POST_VARS['new_status']); if ($res != -1) { $new_status = Status::getStatusTitle($HTTP_POST_VARS['new_status']); History::add($issue_id, $usr_id, History::getTypeID('status_changed'), "Status changed to '{$new_status}' by " . User::getFullName($usr_id)); } } $res = Note::insert($usr_id, $issue_id); $tpl->assign("post_result", $res); // enter the time tracking entry about this phone support entry if (!empty($HTTP_POST_VARS['time_spent'])) { $HTTP_POST_VARS['issue_id'] = $issue_id; $HTTP_POST_VARS['category'] = $HTTP_POST_VARS['time_category']; $HTTP_POST_VARS['summary'] = 'Time entry inserted when sending an internal note.'; Time_Tracking::insertEntry(); } } elseif (@$HTTP_GET_VARS["cat"] == "reply") { if (!@empty($HTTP_GET_VARS["id"])) { $note = Note::getDetails($HTTP_GET_VARS["id"]); $date = Misc::formatReplyDate($note["timestamp"]); $header = "\n\n\nOn {$date}, " . $note["not_from"] . " wrote:\n>\n"; $note["not_body"] = $header . Misc::formatReply($note["not_note"]); $tpl->bulkAssign(array("note" => $note, "parent_note_id" => $HTTP_GET_VARS["id"])); $reply_subject = Mail_API::removeExcessRe($note['not_title']); } } if (empty($reply_subject)) { $reply_subject = 'Re: ' . $details['iss_summary']; } $tpl->assign(array('from' => User::getFromHeader($usr_id), 'users' => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')), 'current_user_prefs' => Prefs::get($usr_id), 'subscribers' => Notification::getSubscribers($issue_id, false, User::getRoleID("Standard User")), 'statuses' => Status::getAssocStatusList($prj_id, false), 'current_issue_status' => Issue::getStatusID($issue_id), 'time_categories' => Time_Tracking::getAssocCategories(), 'note_category_id' => Time_Tracking::getCategoryID('Note Discussion'), 'reply_subject' => $reply_subject)); $tpl->displayTemplate();
/** * Method used to add a phone support entry using the user * interface form available in the application. * * @access public * @return integer 1 if the insert worked, -1 or -2 otherwise */ function insert() { global $HTTP_POST_VARS; $usr_id = Auth::getUserID(); // format the date from the form $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $HTTP_POST_VARS["date"]["Year"], $HTTP_POST_VARS["date"]["Month"], $HTTP_POST_VARS["date"]["Day"], $HTTP_POST_VARS["date"]["Hour"], $HTTP_POST_VARS["date"]["Minute"], 0); // convert the date to GMT timezone $created_date = Date_API::getDateGMT($created_date); $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support\n (\n phs_iss_id,\n phs_usr_id,\n phs_phc_id,\n phs_created_date,\n phs_type,\n phs_phone_number,\n phs_description,\n phs_phone_type,\n phs_call_from_lname,\n phs_call_from_fname,\n phs_call_to_lname,\n phs_call_to_fname\n ) VALUES (\n " . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]) . ",\n {$usr_id},\n " . Misc::escapeInteger($HTTP_POST_VARS["phone_category"]) . ",\n '" . Misc::escapeString($created_date) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["type"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["phone_number"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["description"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["phone_type"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["from_lname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["from_fname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["to_lname"]) . "',\n '" . Misc::escapeString($HTTP_POST_VARS["to_fname"]) . "'\n )"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } else { // enter the time tracking entry about this phone support entry $phs_id = $GLOBALS["db_api"]->get_last_insert_id(); $HTTP_POST_VARS['category'] = Time_Tracking::getCategoryID('Telephone Discussion'); $HTTP_POST_VARS['time_spent'] = $HTTP_POST_VARS['call_length']; $HTTP_POST_VARS['summary'] = 'Time entry inserted from phone call.'; Time_Tracking::insertEntry(); $stmt = "SELECT\n max(ttr_id)\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking\n WHERE\n ttr_iss_id = " . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]) . " AND\n ttr_usr_id = {$usr_id}"; $ttr_id = $GLOBALS["db_api"]->dbh->getOne($stmt); Issue::markAsUpdated($HTTP_POST_VARS['issue_id'], 'phone call'); // need to save a history entry for this History::add($HTTP_POST_VARS['issue_id'], $usr_id, History::getTypeID('phone_entry_added'), 'Phone Support entry submitted by ' . User::getFullName($usr_id)); // XXX: send notifications for the issue being updated (new notification type phone_support?) // update phone record with time tracking ID. if (!empty($phs_id) && !empty($ttr_id)) { $stmt = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "phone_support\n SET\n phs_ttr_id = {$ttr_id}\n WHERE\n phs_id = " . Misc::escapeInteger($phs_id); $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } } return 1; } }