[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/ -> associate.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: associate.php 3336 2007-06-13 09:26:06Z glen $
  29  
  30  require_once(dirname(__FILE__) . "/init.php");
  31  require_once (APP_INC_PATH . "db_access.php");
  32  require_once (APP_INC_PATH . "class.template.php");
  33  require_once (APP_INC_PATH . "class.auth.php");
  34  require_once (APP_INC_PATH . "class.issue.php");
  35  require_once (APP_INC_PATH . "class.note.php");
  36  require_once (APP_INC_PATH . "class.support.php");
  37  require_once (APP_INC_PATH . "class.mail.php");
  38  
  39  $tpl = new Template_API();
  40  $tpl->setTemplate("associate.tpl.html");
  41  
  42  Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true);
  43  
  44  if (@$_POST['cat'] == 'associate') {
  45      if ($_POST['target'] == 'email') {
  46          $res = Support::associate(Auth::getUserID(), $_POST['issue'], $_POST['item']);
  47          if ($res == 1) {
  48              Workflow::handleManualEmailAssociation(Issue::getProjectID($_POST['issue']), $_POST['issue']);
  49          }
  50          $tpl->assign("associate_result", $res);
  51      } elseif ($_POST['target'] == 'reference') {
  52          $res = Support::associateEmail(Auth::getUserID(), $_POST['issue'], $_POST['item']);
  53          if ($res == 1) {
  54              Workflow::handleManualEmailAssociation(Issue::getProjectID($_POST['issue']), $_POST['issue']);
  55          }
  56          $tpl->assign("associate_result", $res);
  57      } else {
  58          for ($i = 0; $i < count($_POST['item']); $i++) {
  59              $email = Support::getEmailDetails(Email_Account::getAccountByEmail($_POST['item'][$i]), $_POST['item'][$i]);
  60              // add the message body as a note
  61              $_POST['blocked_msg'] = $email['seb_full_email'];
  62              $_POST['title'] = $email['sup_subject'];
  63              $_POST['note'] = $email['seb_body'];
  64              // XXX: probably broken to use the current logged in user as the 'owner' of 
  65              // XXX: this new note, but that's how it was already
  66              $res = Note::insert(Auth::getUserID(), $_POST['issue']);
  67              // remove the associated email
  68              if ($res) {
  69                  list($_POST["from"]) = Support::getSender(array($_POST['item'][$i]));
  70                  Workflow::handleBlockedEmail(Issue::getProjectID($_POST['issue']), $_POST['issue'], $_POST, 'associated');
  71                  Support::removeEmail($_POST['item'][$i]);
  72              }
  73          }
  74          $tpl->assign("associate_result", $res);
  75      }
  76      @$tpl->assign('total_emails', count($_POST['item']));
  77  } else {
  78      @$tpl->assign('emails', $_GET['item']);
  79      @$tpl->assign('total_emails', count($_GET['item']));
  80      $prj_id = Issue::getProjectID($_GET['issue']);
  81      if (Customer::hasCustomerIntegration($prj_id)) {
  82          // check if the selected emails all have sender email addresses that are associated with the issue' customer
  83          $senders = Support::getSender($_GET['item']);
  84          $sender_emails = array();
  85          for ($i = 0; $i < count($senders); $i++) {
  86              $email = Mail_API::getEmailAddress($senders[$i]);
  87              $sender_emails[$email] = $senders[$i];
  88          }
  89          $customer_id = Issue::getCustomerID($_GET['issue']);
  90          if (!empty($customer_id)) {
  91              $contact_emails = array_keys(Customer::getContactEmailAssocList($prj_id, $customer_id));
  92              $unknown_contacts = array();
  93              foreach ($sender_emails as $email => $address) {
  94                  if (!@in_array($email, $contact_emails)) {
  95                      $usr_id = User::getUserIDByEmail($email);
  96                      if (empty($usr_id)) {
  97                          $unknown_contacts[] = $address;
  98                      } else {
  99                          // if we got a real user ID, check if the customer user is the correct one
 100                          // (e.g. a contact from the customer associated with the selected issue)
 101                          if (User::getRoleByUser($usr_id, $prj_id) == User::getRoleID('Customer')) {
 102                              // also check if the associated customer ID, if any, matches the one in the issue
 103                              $user_customer_id = User::getCustomerID($usr_id);
 104                              if ($user_customer_id != $customer_id) {
 105                                  $unknown_contacts[] = $address;
 106                              }
 107                          }
 108                      }
 109                  }
 110              }
 111              if (count($unknown_contacts) > 0) {
 112                  $tpl->assign('unknown_contacts', $unknown_contacts);
 113              }
 114          }
 115      }
 116  }
 117  
 118  $tpl->assign("current_user_prefs", Prefs::get(Auth::getUserID()));
 119  
 120  $tpl->displayTemplate();


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