コード例 #1
0
 /**
  * Method used to save the draft response in the database for
  * further use.
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @param   string $to The primary recipient of the draft
  * @param   string $cc The secondary recipients of the draft
  * @param   string $subject The subject of the draft
  * @param   string $message The draft body
  * @param   integer $parent_id The ID of the email that this draft is replying to, if any
  * @param   string $unknown_user The sender of the draft, if not a real user
  * @param   boolean $add_history_entry Whether to add a history entry automatically or not
  * @return  integer 1 if the update worked, -1 otherwise
  */
 function saveEmail($issue_id, $to, $cc, $subject, $message, $parent_id = FALSE, $unknown_user = FALSE, $add_history_entry = TRUE)
 {
     $issue_id = Misc::escapeInteger($issue_id);
     $parent_id = Misc::escapeInteger($parent_id);
     if (empty($parent_id)) {
         $parent_id = 'NULL';
     }
     // if unknown_user is not empty, set the usr_id to be the system user.
     if (!empty($unknown_user)) {
         $usr_id = APP_SYSTEM_USER_ID;
     } else {
         $usr_id = Auth::getUserID();
     }
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_draft\n                 (\n                    emd_updated_date,\n                    emd_usr_id,\n                    emd_iss_id,\n                    emd_sup_id,\n                    emd_subject,\n                    emd_body";
     if (!empty($unknown_user)) {
         $stmt .= ", emd_unknown_user";
     }
     $stmt .= ") VALUES (\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    {$usr_id},\n                    {$issue_id},\n                    {$parent_id},\n                    '" . Misc::escapeString($subject) . "',\n                    '" . Misc::escapeString($message) . "'";
     if (!empty($unknown_user)) {
         $stmt .= ", '" . Misc::escapeString($unknown_user) . "'";
     }
     $stmt .= ")";
     $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_emd_id = $GLOBALS['db_api']->get_last_insert_id();
         Draft::addEmailRecipient($new_emd_id, $to, false);
         $cc = str_replace(',', ';', $cc);
         $ccs = explode(';', $cc);
         foreach ($ccs as $cc) {
             Draft::addEmailRecipient($new_emd_id, $cc, true);
         }
         Issue::markAsUpdated($issue_id, "draft saved");
         if ($add_history_entry) {
             History::add($issue_id, $usr_id, History::getTypeID('draft_added'), 'Email message saved as a draft by ' . User::getFullName($usr_id));
         }
         return 1;
     }
 }