/** * Method used to get the list of emails to be displayed in the * grid layout. * * @param array $options The search parameters * @param integer $current_row The current page number * @param integer $max The maximum number of rows per page * @return array The list of issues to be displayed */ public static function getEmailListing($options, $current_row = 0, $max = 5) { $prj_id = Auth::getCurrentProject(); if ($max == 'ALL') { $max = 9999999; } $start = $current_row * $max; $stmt = 'SELECT sup_id, sup_ema_id, sup_iss_id, sup_customer_id, sup_from, sup_date, sup_to, sup_subject, sup_has_attachment FROM ( {{%support_email}}, {{%email_account}}'; if (!empty($options['keywords'])) { $stmt .= ', {{%support_email_body}} '; } $stmt .= ' ) LEFT JOIN {{%issue}} ON sup_iss_id = iss_id'; $stmt .= self::buildWhereClause($options); $stmt .= ' ORDER BY ' . Misc::escapeString($options['sort_by']) . ' ' . Misc::escapeString($options['sort_order']); $total_rows = Pager::getTotalRows($stmt); $stmt .= ' LIMIT ' . Misc::escapeInteger($max) . ' OFFSET ' . Misc::escapeInteger($start); try { $res = DB_Helper::getInstance()->getAll($stmt); } catch (DbException $e) { return array('list' => '', 'info' => ''); } if (count($res) < 1 && $current_row > 0) { // if there are no results, and the page is not the first page reset page to one and reload results Auth::redirect("emails.php?pagerRow=0&rows={$max}"); } if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); $customer_ids = array(); foreach ($res as $row) { if (!empty($row['sup_customer_id']) && !in_array($row['sup_customer_id'], $customer_ids)) { $customer_ids[] = $row['sup_customer_id']; } } if (count($customer_ids) > 0) { $company_titles = $crm->getCustomerTitles($customer_ids); } } 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'] = implode(', ', Mail_Helper::getName($row['sup_from'], true)); if (empty($row['sup_to']) && !empty($row['sup_iss_id'])) { $row['sup_to'] = 'Notification List'; } else { $to = Mail_Helper::getName($row['sup_to']); // Ignore unformattable headers if (!Misc::isError($to)) { $row['sup_to'] = Mime_Helper::fixEncoding($to); } } if (CRM::hasCustomerIntegration($prj_id)) { // FIXME: $company_titles maybe used uninitialied $row['customer_title'] = $company_titles[$row['sup_customer_id']]; } } $total_pages = ceil($total_rows / $max); $last_page = $total_pages - 1; return array('list' => $res, 'info' => array('current_page' => $current_row, 'start_offset' => $start, 'end_offset' => $start + count($res), 'total_rows' => $total_rows, 'total_pages' => $total_pages, 'previous_page' => $current_row == 0 ? '-1' : $current_row - 1, 'next_page' => $current_row == $last_page ? '-1' : $current_row + 1, 'last_page' => $last_page)); }
/** * Method used to send an email notification to the sender of a * set of email messages that were manually converted into an * issue. * * @param integer $prj_id The project ID * @param integer $issue_id The issue ID * @param array $sup_ids The email IDs * @param bool|int $customer_id The customer ID * @return array The list of recipient emails */ public static function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = false) { if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); return $crm->notifyEmailConvertedIntoIssue($issue_id, $sup_ids, $customer_id); } else { // build the list of recipients $recipients = array(); $recipient_emails = array(); foreach ($sup_ids as $sup_id) { $senders = Support::getSender(array($sup_id)); if (count($senders) > 0) { $sender_email = Mail_Helper::getEmailAddress($senders[0]); $recipients[$sup_id] = $senders[0]; $recipient_emails[] = $sender_email; } } if (!$recipients) { return false; } $data = Issue::getDetails($issue_id); foreach ($recipients as $sup_id => $recipient) { $recipient_usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($recipient)); // open text template $tpl = new Template_Helper(); $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text'); $tpl->assign(array('data' => $data, 'sender_name' => Mail_Helper::getName($recipient), 'app_title' => Misc::getToolCaption(), 'recipient_name' => Mail_Helper::getName($recipient))); $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($sup_id), $sup_id); $tpl->assign(array('email' => array('date' => $email_details['sup_date'], 'from' => $email_details['sup_from'], 'subject' => $email_details['sup_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); $setup = $mail->getSMTPSettings(); $from = self::getFixedFromHeader($issue_id, $setup['from'], 'issue'); $mail->setHeaders(Mail_Helper::getBaseThreadingHeaders($issue_id)); // 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, 1, $issue_id, 'email_converted_to_issue'); } Language::restore(); return $recipient_emails; } }