/** * Returns the sequential number of the specified email ID. * * @param integer $sup_id The email ID * @return integer The sequence number of the email */ public static function getSequenceByID($sup_id) { if (empty($sup_id)) { return ''; } try { DB_Helper::getInstance()->query('SET @sup_seq = 0'); } catch (DbException $e) { return 0; } $issue_id = Support::getIssueFromEmail($sup_id); $sql = 'SELECT sup_id, @sup_seq := @sup_seq+1 FROM {{%support_email}} WHERE sup_iss_id = ? ORDER BY sup_id ASC'; try { $res = DB_Helper::getInstance()->getPair($sql, array($issue_id)); } catch (DbException $e) { return 0; } return @$res[$sup_id]; }
// | 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. | // +----------------------------------------------------------------------+ // | Authors: João Prado Maia <*****@*****.**> | // +----------------------------------------------------------------------+ require_once dirname(__FILE__) . '/../init.php'; $usr_id = Auth::getUserID(); $prj_id = Auth::getCurrentProject(); $tpl = new Template_Helper(); $tpl->setTemplate('view_email.tpl.html'); Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true); $issue_id = Support::getIssueFromEmail($_GET['id']); if ($issue_id != 0 && !Issue::canAccess($issue_id, $usr_id) || $issue_id == 0 && User::getRoleByUser($usr_id, $prj_id) < User::ROLE_USER) { $tpl->setTemplate('permission_denied.tpl.html'); $tpl->displayTemplate(); exit; } $email = Support::getEmailDetails($_GET['ema_id'], $_GET['id']); $email['seb_body'] = str_replace('&nbsp;', ' ', $email['seb_body']); $tpl->assign(array('email' => $email, 'issue_id' => $issue_id, 'extra_title' => ev_gettext('Issue #%1$s Email #%3$s: %2$s', $issue_id, $email['sup_subject'], Support::getSequenceByID($_GET['id'])), 'email_accounts' => Email_Account::getAssocList(array_keys(Project::getAssocList(Auth::getUserID())), true), 'recipients' => Mail_Queue::getMessageRecipients(array('customer_email', 'other_email'), $_GET['id']))); if (@$_GET['cat'] == 'list_emails') { $sides = Support::getListingSides($_GET['id']); $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next'])); } elseif (@$_GET['cat'] == 'move_email' && Auth::getCurrentRole() >= User::getRoleID('Standard User')) { $res = Support::moveEmail(@$_GET['id'], @$_GET['ema_id'], @$_GET['new_ema_id']); $tpl->assign('move_email_result', $res); $tpl->assign('current_user_prefs', Prefs::get(Auth::getUserID()));
/** * Method used to add a new support email to the system. * * @access public * @param array $row The support email details * @param object $structure The email structure object * @param integer $sup_id The support ID to be passed out * @param boolean $closing If this email comes from closing the issue * @return integer 1 if the insert worked, -1 otherwise */ function insertEmail($row, &$structure, &$sup_id, $closing = false) { // get usr_id from FROM header $usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($row['from'])); if (!empty($usr_id) && !empty($row["customer_id"])) { $row["customer_id"] = User::getCustomerID($usr_id); } if (empty($row['customer_id'])) { $row['customer_id'] = "NULL"; } // try to get the parent ID $reference_message_id = Mail_API::getReferenceMessageID($row['full_email']); $parent_id = ''; if (!empty($reference_message_id)) { $parent_id = Support::getIDByMessageID($reference_message_id); // make sure it is in the same issue if (!empty($parent_id) && (empty($row['issue_id']) || @$row['issue_id'] != Support::getIssueFromEmail($parent_id))) { $parent_id = ''; } } $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email\n (\n sup_ema_id,"; if (!empty($parent_id)) { $stmt .= "\nsup_parent_id,"; } $stmt .= "\n sup_iss_id,"; if (!empty($usr_id)) { $stmt .= "\nsup_usr_id,\n"; } $stmt .= " sup_customer_id,\n sup_message_id,\n sup_date,\n sup_from,\n sup_to,\n sup_cc,\n sup_subject,\n sup_has_attachment\n ) VALUES (\n " . Misc::escapeInteger($row["ema_id"]) . ",\n"; if (!empty($parent_id)) { $stmt .= "{$parent_id},\n"; } $stmt .= Misc::escapeInteger($row["issue_id"]) . ","; if (!empty($usr_id)) { $stmt .= "\n{$usr_id},\n"; } $stmt .= "\n " . Misc::escapeInteger($row["customer_id"]) . ",\n '" . Misc::escapeString($row["message_id"]) . "',\n '" . Misc::escapeString($row["date"]) . "',\n '" . Misc::escapeString($row["from"]) . "',\n '" . Misc::escapeString(@$row["to"]) . "',\n '" . Misc::escapeString(@$row["cc"]) . "',\n '" . Misc::escapeString($row["subject"]) . "',\n '" . Misc::escapeString($row["has_attachment"]) . "'\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 { $new_sup_id = $GLOBALS["db_api"]->get_last_insert_id(); $sup_id = $new_sup_id; // now add the body and full email to the separate table $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email_body\n (\n seb_sup_id,\n seb_body,\n seb_full_email\n ) VALUES (\n {$new_sup_id},\n '" . Misc::escapeString($row["body"]) . "',\n '" . Misc::escapeString($row["full_email"]) . "'\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 { Workflow::handleNewEmail(Email_Account::getProjectID($row["ema_id"]), @$row["issue_id"], $structure, $row, $closing); return 1; } } }
// // @(#) $Id: s.view_email.php 1.8 03/11/12 19:57:26-00:00 jpradomaia $ // include_once "config.inc.php"; include_once APP_INC_PATH . "class.template.php"; include_once APP_INC_PATH . "class.auth.php"; include_once APP_INC_PATH . "class.issue.php"; include_once APP_INC_PATH . "class.misc.php"; include_once APP_INC_PATH . "class.support.php"; include_once APP_INC_PATH . "db_access.php"; $tpl = new Template_API(); $tpl->setTemplate("view_email.tpl.html"); Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true); $email = Support::getEmailDetails($HTTP_GET_VARS["ema_id"], $HTTP_GET_VARS["id"]); $email["message"] = str_replace("&nbsp;", " ", $email["message"]); $issue_id = Support::getIssueFromEmail($HTTP_GET_VARS["id"]); if (!Issue::canAccess($issue_id, Auth::getUserID())) { $tpl->setTemplate("permission_denied.tpl.html"); $tpl->displayTemplate(); exit; } $tpl->bulkAssign(array("email" => $email, "issue_id" => $issue_id, 'extra_title' => "Email #" . $HTTP_GET_VARS['id'] . ": " . $email['sup_subject'], 'email_accounts' => Email_Account::getAssocList(array_keys(Project::getAssocList(Auth::getUserID())), true))); if (@$HTTP_GET_VARS['cat'] == 'list_emails') { $sides = Support::getListingSides($HTTP_GET_VARS["id"]); $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next'])); } elseif (@$HTTP_GET_VARS['cat'] == 'move_email' && Auth::getCurrentRole() >= User::getRoleID("Standard User")) { $res = Support::moveEmail(@$HTTP_GET_VARS['id'], @$HTTP_GET_VARS['ema_id'], @$HTTP_GET_VARS['new_ema_id']); $tpl->assign("move_email_result", $res); $tpl->assign("current_user_prefs", Prefs::get(Auth::getUserID())); } else { $sides = Support::getIssueSides($issue_id, $HTTP_GET_VARS["id"]);