Exemplo n.º 1
0
 private function processResult(&$data, $date_field, $issue_field)
 {
     $timezone = Date_Helper::getPreferredTimezone($this->usr_id);
     foreach ($data as &$res) {
         if (!Issue::canAccess($res[$issue_field], $this->usr_id)) {
             continue;
         }
         $res['customer'] = null;
         if ($this->crm) {
             try {
                 $customer = $this->crm->getCustomer(Issue::getCustomerID($res[$issue_field]));
                 $res['customer'] = $customer->getName();
             } catch (CRMException $e) {
             }
         }
         $res['date'] = Date_Helper::getFormattedDate($res[$date_field], $timezone);
         // need to decode From:, To: mail headers
         if (isset($res['sup_from'])) {
             $res['sup_from'] = Mime_Helper::fixEncoding($res['sup_from']);
         }
         if (isset($res['sup_to'])) {
             $res['sup_to'] = Mime_Helper::fixEncoding($res['sup_to']);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Method used to get all of the support email entries associated
  * with a given issue.
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @return  array The list of support emails
  */
 function getEmailsByIssue($issue_id)
 {
     $usr_id = Auth::getUserID();
     $stmt = "SELECT\n                    sup_id,\n                    sup_ema_id,\n                    sup_from,\n                    sup_to,\n                    sup_cc,\n                    sup_date,\n                    sup_subject,\n                    seb_body,\n                    sup_has_attachment,\n                    CONCAT(sup_ema_id, '-', sup_id) AS composite_id\n                 FROM\n                    (\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email_body,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                    )\n                 WHERE\n                    sup_id=seb_sup_id AND\n                    ema_id=sup_ema_id AND\n                    iss_id = sup_iss_id AND\n                    ema_prj_id=iss_prj_id AND\n                    sup_iss_id=" . Misc::escapeInteger($issue_id) . "\n                 ORDER BY\n                    sup_id ASC";
     $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return "";
     } else {
         if (count($res) == 0) {
             return "";
         } else {
             for ($i = 0; $i < count($res); $i++) {
                 $res[$i]["sup_date"] = Date_API::getFormattedDate($res[$i]["sup_date"]);
                 $res[$i]["sup_subject"] = Mime_Helper::fixEncoding($res[$i]["sup_subject"]);
                 $res[$i]["sup_from"] = Mime_Helper::fixEncoding($res[$i]["sup_from"]);
                 $res[$i]["sup_to"] = Mime_Helper::fixEncoding($res[$i]["sup_to"]);
                 $res[$i]["sup_cc"] = Mime_Helper::fixEncoding($res[$i]["sup_cc"]);
             }
             return $res;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Method used to get all of the support email entries associated
  * with a given issue.
  *
  * @param   integer $issue_id The issue ID
  * @return  array The list of support emails
  */
 public static function getEmailsByIssue($issue_id)
 {
     $stmt = "SELECT\n                    sup_id,\n                    sup_ema_id,\n                    sup_from,\n                    sup_to,\n                    sup_cc,\n                    sup_date,\n                    UNIX_TIMESTAMP(sup_date) as date_ts,\n                    sup_subject,\n                    sup_has_attachment,\n                    CONCAT(sup_ema_id, '-', sup_id) AS composite_id\n                 FROM\n                    {{%support_email}}\n                 WHERE\n                    sup_iss_id=?\n                 ORDER BY\n                    sup_id ASC";
     try {
         $res = DB_Helper::getInstance()->getAll($stmt, array($issue_id));
     } catch (DbException $e) {
         return '';
     }
     if (count($res) == 0) {
         return array();
     }
     foreach ($res as &$row) {
         $row['sup_date'] = Date_Helper::getFormattedDate($row['sup_date']);
         $row['sup_subject'] = Mime_Helper::fixEncoding($row['sup_subject']);
         $row['sup_from'] = Mime_Helper::fixEncoding($row['sup_from']);
         $row['sup_to'] = Mime_Helper::fixEncoding($row['sup_to']);
         $row['sup_cc'] = Mime_Helper::fixEncoding($row['sup_cc']);
     }
     return $res;
 }
Exemplo n.º 4
0
 /**
  * Returns the mail queue for a specific issue.
  *
  * @param   integer $issue_id The issue ID
  * @return  array An array of emails from the queue
  */
 public static function getListByIssueID($issue_id)
 {
     $stmt = 'SELECT
                 maq_id,
                 maq_queued_date,
                 maq_status,
                 maq_recipient,
                 maq_subject
              FROM
                 {{%mail_queue}}
              WHERE
                 maq_iss_id = ?
              ORDER BY
                 maq_queued_date ASC';
     try {
         $res = DB_Helper::getInstance()->getAll($stmt, array($issue_id));
     } catch (DbException $e) {
         return false;
     }
     if (count($res) > 0) {
         foreach ($res as &$row) {
             $row['maq_recipient'] = Mime_Helper::decodeAddress($row['maq_recipient']);
             $row['maq_queued_date'] = Date_Helper::getFormattedDate(Date_Helper::getUnixTimestamp($row['maq_queued_date'], 'GMT'));
             $row['maq_subject'] = Mime_Helper::fixEncoding($row['maq_subject']);
         }
     }
     return $res;
 }
Exemplo n.º 5
0
 *
 * @copyright (c) Eventum Team
 * @license GNU General Public License, version 2 or later (GPL-2+)
 *
 * For the full copyright and license information,
 * please see the COPYING and AUTHORS files
 * that were distributed with this source code.
 */
/*
 * Update database fields with fixEncoding instead doing that runtime
 */
/** @var DbInterface $db */
$logger = Logger::getInstance('db');
$res = $db->getAll("SELECT sup_id,sup_subject,sup_from,sup_to,sup_cc FROM {{%support_email}} WHERE concat(sup_subject,sup_from,sup_to,sup_cc) LIKE '%=?%'");
$changed = 0;
foreach ($res as $idx => $row) {
    $params = array();
    foreach ($row as $k => $v) {
        $params[$k] = Mime_Helper::fixEncoding($v);
    }
    if ($row == $params) {
        $logger->warning("sup_id={$row['sup_id']} no changes", array('sup_id' => $row['sup_id'], 'old' => $row));
        continue;
    }
    $logger->info("updated sup_id={$row['sup_id']}", array('sup_id' => $row['sup_id'], 'old' => $row, 'new' => $params));
    $params[] = $row['sup_id'];
    $db->query('UPDATE {{%support_email}} SET ' . DB_Helper::buildSet($row) . ' WHERE sup_id=?', $params);
    $changed++;
}
$count = count($res);
$logger->info("Updated {$changed} out of {$count} entries");
Exemplo n.º 6
0
 /**
  * Method used to get the list of changes made against a specific issue.
  *
  * @access  public
  * @param   integer $iss_id The issue ID
  * @param   string $order_by The order to sort the history
  * @return  array The list of changes
  */
 function getListing($iss_id, $order_by = 'DESC')
 {
     $stmt = "SELECT\n                    *\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_history,\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "history_type\n                 WHERE\n                    htt_id = his_htt_id AND\n                    his_is_hidden != 1 AND\n                    his_iss_id=" . Misc::escapeInteger($iss_id) . " AND\n                    htt_role <= " . Auth::getCurrentRole() . "\n                 ORDER BY\n                    his_id {$order_by}";
     $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return "";
     } else {
         for ($i = 0; $i < count($res); $i++) {
             $res[$i]["his_created_date"] = Date_API::getFormattedDate($res[$i]["his_created_date"]);
             $res[$i]["his_summary"] = Mime_Helper::fixEncoding($res[$i]["his_summary"]);
         }
         return $res;
     }
 }
Exemplo n.º 7
0
function processResult($res, $date_field, $issue_field)
{
    global $prj_id;
    global $usr_id;
    $data = array();
    for ($i = 0; $i < count($res); $i++) {
        if (!Issue::canAccess($res[$i][$issue_field], $usr_id)) {
            continue;
        }
        if (Customer::hasCustomerIntegration($prj_id)) {
            $details = Customer::getDetails($prj_id, Issue::getCustomerID($res[$i][$issue_field]));
            $res[$i]["customer"] = @$details['customer_name'];
        }
        $res[$i]["date"] = Date_API::getFormattedDate($res[$i][$date_field], Date_API::getPreferredTimezone($usr_id));
        // need to decode From:, To: mail headers
        if (isset($res[$i]["sup_from"])) {
            $res[$i]["sup_from"] = Mime_Helper::fixEncoding($res[$i]["sup_from"]);
        }
        if (isset($res[$i]["sup_to"])) {
            $res[$i]["sup_to"] = Mime_Helper::fixEncoding($res[$i]["sup_to"]);
        }
        $data[] = $res[$i];
    }
    return $data;
}
Exemplo n.º 8
0
 /**
  * Method used to get the name portion of a given recipient information.
  *
  * @access  public
  * @param   string $address The email address value
  * @param   boolean $multiple If multiple addresses should be returned
  * @return  mixed The name or an array of names if multiple is true
  */
 function getName($address, $multiple = false)
 {
     $info = Mail_API::getAddressInfo($address, true);
     $returns = array();
     foreach ($info as $row) {
         if (!empty($row['sender_name'])) {
             $returns[] = Mime_Helper::fixEncoding($row['sender_name']);
         } else {
             $returns[] = $row['email'];
         }
     }
     if ($multiple) {
         return $returns;
     } else {
         return $returns[0];
     }
 }
Exemplo n.º 9
0
 /**
  * Returns the mail queue for a specific issue.
  *
  * @access  public
  * @param   integer $issue_is The issue ID
  * @return  array An array of emails from the queue
  */
 function getListByIssueID($issue_id)
 {
     $issue_id = Misc::escapeInteger($issue_id);
     $stmt = "SELECT\n                    maq_id,\n                    maq_queued_date,\n                    maq_status,\n                    maq_recipient,\n                    maq_subject\n                 FROM\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "mail_queue\n                 WHERE\n                    maq_iss_id = " . Misc::escapeInteger($issue_id) . "\n                 ORDER BY\n                    maq_queued_date ASC";
     $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return false;
     }
     if (count($res) > 0) {
         for ($i = 0; $i < count($res); $i++) {
             $res[$i]['maq_recipient'] = Mime_Helper::decodeAddress($res[$i]['maq_recipient']);
             $res[$i]['maq_queued_date'] = Date_API::getFormattedDate(Date_API::getUnixTimestamp($res[$i]['maq_queued_date'], 'GMT'));
             $res[$i]['maq_subject'] = Mime_Helper::fixEncoding($res[$i]['maq_subject']);
         }
     }
     return $res;
 }
Exemplo n.º 10
0
 /**
  * Method used to get the name portion of a given recipient information.
  *
  * @param   string $address The email address value
  * @param   boolean $multiple If multiple addresses should be returned
  * @return  mixed The name or an array of names if multiple is true
  */
 public static function getName($address, $multiple = false)
 {
     $info = self::getAddressInfo($address, true);
     if (Misc::isError($info)) {
         return $info;
     }
     $returns = array();
     foreach ($info as $row) {
         if (!empty($row['sender_name'])) {
             if (substr($row['sender_name'], 0, 1) == '"' && substr($row['sender_name'], -1) == '"') {
                 $row['sender_name'] = substr($row['sender_name'], 1, -1);
             }
             $returns[] = Mime_Helper::fixEncoding($row['sender_name']);
         } else {
             $returns[] = $row['email'];
         }
     }
     if ($multiple) {
         return $returns;
     } else {
         return $returns[0];
     }
 }
Exemplo n.º 11
0
 /**
  * Method used to send an email notification to the sender of an
  * email message that was automatically converted into an issue.
  *
  * @param   integer $prj_id The project ID
  * @param   integer $issue_id The issue ID
  * @param   string $sender The sender of the email message (and the recipient of this notification)
  * @param   string $date The arrival date of the email message
  * @param   string $subject The subject line of the email message
  * @param bool|string $additional_recipient The user who should receive this email who is not the sender of the original email.
  * @return  void
  */
 public static function notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $subject, $additional_recipient = false)
 {
     if (CRM::hasCustomerIntegration($prj_id)) {
         $crm = CRM::getInstance($prj_id);
         $crm->notifyAutoCreatedIssue($issue_id, $sender, $date, $subject);
         $sent = true;
     } else {
         $sent = false;
     }
     if ($sent === false) {
         if ($additional_recipient != false) {
             $recipient = $additional_recipient;
             $is_message_sender = false;
         } else {
             $recipient = $sender;
             $is_message_sender = true;
         }
         $recipient_usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($recipient));
         if (!Workflow::shouldEmailAddress($prj_id, Mail_Helper::getEmailAddress($recipient), $issue_id, 'auto_created')) {
             return;
         }
         $data = Issue::getDetails($issue_id);
         // open text template
         $tpl = new Template_Helper();
         $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text');
         $tpl->assign(array('app_title' => Misc::getToolCaption(), 'data' => $data, 'sender_name' => Mail_Helper::getName($sender), 'recipient_name' => Mail_Helper::getName($recipient), 'is_message_sender' => $is_message_sender));
         // figure out if sender has a real account or not
         $sender_usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($sender), true);
         if (!empty($sender_usr_id) && Issue::canAccess($issue_id, $sender_usr_id)) {
             $can_access = 1;
         } else {
             $can_access = 0;
         }
         $tpl->assign(array('sender_can_access' => $can_access, 'email' => array('date' => $date, 'from' => Mime_Helper::fixEncoding($sender), 'subject' => $subject)));
         // change the current locale
         if (!empty($recipient_usr_id)) {
             Language::set(User::getLang($recipient_usr_id));
         } else {
             Language::set(APP_DEFAULT_LOCALE);
         }
         $text_message = $tpl->getTemplateContents();
         // send email (use PEAR's classes)
         $mail = new Mail_Helper();
         $mail->setTextBody($text_message);
         $mail->setHeaders(Mail_Helper::getBaseThreadingHeaders($issue_id));
         $setup = $mail->getSMTPSettings();
         $from = self::getFixedFromHeader($issue_id, $setup['from'], 'issue');
         $recipient = Mime_Helper::fixEncoding($recipient);
         // TRANSLATORS: %1: $issue_id, %2 = iss_summary
         $subject = ev_gettext('[#%1$s] Issue Created: %2$s', $issue_id, $data['iss_summary']);
         $mail->send($from, $recipient, $subject, 0, $issue_id, 'auto_created_issue');
         Language::restore();
     }
 }
Exemplo n.º 12
0
 /**
  * Method used to send an email notification to the sender of an
  * email message that was automatically converted into an issue.
  *
  * @access  public
  * @param   integer $prj_id The project ID
  * @param   integer $issue_id The issue ID
  * @param   string $sender The sender of the email message (and the recipient of this notification)
  * @param   string $date The arrival date of the email message
  * @param   string $subject The subject line of the email message
  * @return  void
  */
 function notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $subject)
 {
     if (Customer::hasCustomerIntegration($prj_id)) {
         Customer::notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $subject);
     } else {
         if (!Workflow::shouldEmailAddress($prj_id, Mail_API::getEmailAddress($sender))) {
             return;
         }
         $data = Issue::getDetails($issue_id);
         // open text template
         $tpl = new Template_API();
         $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text');
         $tpl->bulkAssign(array("app_title" => Misc::getToolCaption(), "data" => $data, "sender_name" => Mail_API::getName($sender)));
         // figure out if sender has a real account or not
         $sender_usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($sender));
         if (!empty($sender_usr_id) && Issue::canAccess($issue_id, $sender_usr_id)) {
             $can_access = 1;
         } else {
             $can_access = 0;
         }
         $tpl->assign(array('sender_can_access' => $can_access, 'email' => array('date' => $date, 'from' => Mime_Helper::fixEncoding($sender), 'subject' => $subject)));
         $text_message = $tpl->getTemplateContents();
         // send email (use PEAR's classes)
         $mail = new Mail_API();
         $mail->setTextBody($text_message);
         $mail->setHeaders(Mail_API::getBaseThreadingHeaders($issue_id));
         $setup = $mail->getSMTPSettings();
         $from = Notification::getFixedFromHeader($issue_id, $setup["from"], 'issue');
         $sender = Mime_Helper::fixEncoding($sender);
         $mail->send($from, $sender, "[#{$issue_id}] Issue Created: " . $data['iss_summary'], 0, $issue_id, 'auto_created_issue');
     }
 }