[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/ -> send.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
   3  // +----------------------------------------------------------------------+
   4  // | Eventum - Issue Tracking System                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB                  |
   7  // |                                                                      |
   8  // | This program is free software; you can redistribute it and/or modify |
   9  // | it under the terms of the GNU General Public License as published by |
  10  // | the Free Software Foundation; either version 2 of the License, or    |
  11  // | (at your option) any later version.                                  |
  12  // |                                                                      |
  13  // | This program is distributed in the hope that it will be useful,      |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  16  // | GNU General Public License for more details.                         |
  17  // |                                                                      |
  18  // | You should have received a copy of the GNU General Public License    |
  19  // | along with this program; if not, write to:                           |
  20  // |                                                                      |
  21  // | Free Software Foundation, Inc.                                       |
  22  // | 59 Temple Place - Suite 330                                          |
  23  // | Boston, MA 02111-1307, USA.                                          |
  24  // +----------------------------------------------------------------------+
  25  // | Authors: João Prado Maia <jpm@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  // @(#) $Id: send.php 3258 2007-02-14 23:25:56Z glen $
  29  
  30  require_once(dirname(__FILE__) . "/init.php");
  31  require_once (APP_INC_PATH . "class.template.php");
  32  require_once (APP_INC_PATH . "class.auth.php");
  33  require_once (APP_INC_PATH . "class.user.php");
  34  require_once (APP_INC_PATH . "class.support.php");
  35  require_once (APP_INC_PATH . "class.email_response.php");
  36  require_once (APP_INC_PATH . "class.draft.php");
  37  require_once (APP_INC_PATH . "db_access.php");
  38  
  39  $tpl = new Template_API();
  40  $tpl->setTemplate("send.tpl.html");
  41  
  42  Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true);
  43  
  44  $prj_id = Auth::getCurrentProject();
  45  $usr_id = Auth::getUserID();
  46  
  47  @$issue_id = $_GET["issue_id"] ? $_GET["issue_id"] : $_POST["issue_id"];
  48  $tpl->assign("issue_id", $issue_id);
  49  
  50  if (!Issue::canAccess($issue_id, $usr_id)) {
  51      $tpl->setTemplate("permission_denied.tpl.html");
  52      $tpl->displayTemplate();
  53      exit;
  54  }
  55  
  56  // since emails associated with issues are sent to the notification list, not the to: field, set the to field to be blank
  57  // this field should already be blank, but may also be unset.
  58  if (!empty($issue_id)) {
  59      $_POST['to'] = '';
  60  }
  61  
  62  if (@$_POST["cat"] == "send_email") {
  63      $res = Support::sendEmail($_POST['parent_id']);
  64      $tpl->assign("send_result", $res);
  65      if (!@empty($_POST['new_status'])) {
  66          $res = Issue::setStatus($issue_id, $_POST['new_status']);
  67          if ($res != -1) {
  68              $new_status = Status::getStatusTitle($_POST['new_status']);
  69              History::add($issue_id, $usr_id, History::getTypeID('status_changed'), "Status changed to '$new_status' by " . User::getFullName($usr_id) . " when sending an email");
  70          }
  71      }
  72      // remove the existing email draft, if appropriate
  73      if (!empty($_POST['draft_id'])) {
  74          Draft::remove($_POST['draft_id']);
  75      }
  76      // enter the time tracking entry about this new email
  77      if (!empty($_POST['time_spent'])) {
  78          $_POST['issue_id'] = $issue_id;
  79          $_POST['category'] = Time_Tracking::getCategoryID('Email Discussion');
  80          $_POST['summary'] = 'Time entry inserted when sending outgoing email.';
  81          Time_Tracking::insertEntry();
  82      }
  83  } elseif (@$_POST["cat"] == "save_draft") {
  84      $res = Draft::saveEmail($issue_id, $_POST["to"], $_POST["cc"], $_POST["subject"], $_POST["message"], $_POST["parent_id"]);
  85      $tpl->assign("draft_result", $res);
  86  } elseif (@$_POST["cat"] == "update_draft") {
  87      $res = Draft::update($issue_id, $_POST["draft_id"], $_POST["to"], $_POST["cc"], $_POST["subject"], $_POST["message"], $_POST["parent_id"]);
  88      $tpl->assign("draft_result", $res);
  89  }
  90  
  91  // enter the time tracking entry about this new email
  92  if ((@$_POST["cat"] == "save_draft") || (@$_POST["cat"] == "update_draft")) {
  93      if (!empty($_POST['time_spent'])) {
  94          $_POST['issue_id'] = $issue_id;
  95          $_POST['category'] = Time_Tracking::getCategoryID('Email Discussion');
  96          $_POST['summary'] = 'Time entry inserted when saving an email draft.';
  97          Time_Tracking::insertEntry();
  98      }
  99  }
 100  
 101  if (@$_GET['cat'] == 'view_draft') {
 102      $draft = Draft::getDetails($_GET['id']);
 103      $email = array(
 104          'sup_subject' => $draft['emd_subject'],
 105          'seb_body'    => $draft['emd_body'],
 106          'sup_from'    => $draft['to'],
 107          'cc'          => implode('; ', $draft['cc'])
 108      );
 109      // try to guess the correct email account to be associated with this email
 110      if (!empty($draft['emd_sup_id'])) {
 111          $_GET['ema_id'] = Email_Account::getAccountByEmail($draft['emd_sup_id']);
 112      } else {
 113          // if we are not replying to an existing message, just get the first email account you can find...
 114          $_GET['ema_id'] = Email_Account::getEmailAccount();
 115      }
 116      $tpl->bulkAssign(array(
 117          "draft_id"        => $_GET['id'],
 118          "email"           => $email,
 119          "parent_email_id" => $draft['emd_sup_id'],
 120          "draft_status"    => $draft['emd_status']
 121      ));
 122      if ($draft['emd_status'] != 'pending') {
 123          $tpl->assign("read_only", 1);
 124      }
 125  } elseif (@$_GET['cat'] == 'create_draft') {
 126      $tpl->assign("hide_email_buttons", "yes");
 127  } else {
 128      if (!@empty($_GET["id"])) {
 129          $email = Support::getEmailDetails($_GET["ema_id"], $_GET["id"]);
 130          $date = Misc::formatReplyDate($email["timestamp"]);
 131          $header = "\n\n\nOn $date, " . $email["sup_from"] . " wrote:\n>\n";
 132          $email['seb_body'] = $header . Misc::formatReply($email['seb_body']);
 133          $tpl->bulkAssign(array(
 134              "email"           => $email,
 135              "parent_email_id" => $_GET["id"]
 136          ));
 137      }
 138  }
 139  
 140  // special handling when someone tries to 'reply' to an issue
 141  if (@$_GET["cat"] == 'reply') {
 142      $details = Issue::getReplyDetails($_GET['issue_id']);
 143      if ($details != '') {
 144          $date = Misc::formatReplyDate($details['created_date_ts']);
 145          $header = "\n\n\nOn $date, " . $details['reporter'] . " wrote:\n>\n";
 146          $details['seb_body'] = $header . Misc::formatReply($details['description']);
 147          $details['sup_from'] = Mail_API::getFormattedName($details['reporter'], $details['reporter_email']);
 148          $tpl->bulkAssign(array(
 149              "email"           => $details,
 150              "parent_email_id" => 0,
 151              "extra_title"     => "Issue #" . $_GET['issue_id'] . ": Reply"
 152          ));
 153      }
 154  }
 155  
 156  if (!empty($issue_id)) {
 157      // list the available statuses
 158      $tpl->assign("statuses", Status::getAssocStatusList($prj_id, false));
 159      $tpl->assign("current_issue_status", Issue::getStatusID($issue_id));
 160      // set if the current user is allowed to send emails on this issue or not
 161      $sender_details = User::getDetails($usr_id);
 162      $tpl->assign("can_send_email", Support::isAllowedToEmail($issue_id, $sender_details["usr_email"]));
 163      $tpl->assign('subscribers', Notification::getSubscribers($issue_id, 'emails'));
 164  }
 165  if ((!@empty($_GET["ema_id"])) || (!@empty($_POST["ema_id"]))) {
 166      @$tpl->assign("ema_id", $_GET["ema_id"] ? $_GET["ema_id"] : $_POST["ema_id"]);
 167  }
 168  $tpl->assign("from", User::getFromHeader($usr_id));
 169  
 170  // list of users to display in the lookup field in the To: and Cc: fields
 171  $t = Project::getAddressBook($prj_id, $issue_id);
 172  $tpl->assign("assoc_users", $t);
 173  $tpl->assign("assoc_emails", array_keys($t));
 174  
 175  $tpl->assign("canned_responses", Email_Response::getAssocList($prj_id));
 176  $tpl->assign("js_canned_responses", Email_Response::getAssocListBodies($prj_id));
 177  
 178  $user_prefs = Prefs::get($usr_id);
 179  $tpl->assign("current_user_prefs", $user_prefs);
 180  
 181  // don't add signature if it already exists. Note: This won't handle multiple user duplicate sigs.
 182  if ((@!empty($draft['emd_body'])) && ($user_prefs["auto_append_sig"] == 'yes') &&
 183          (strpos($draft['emd_body'], $user_prefs["email_signature"]) !== false)) {
 184      $tpl->assign('body_has_sig_already', 1);
 185  }
 186  
 187  $tpl->displayTemplate();


Generated: Wed Dec 19 21:21:33 2007 Cross-referenced by PHPXref 0.7