/** * Method used to get the list of emails to be displayed in the * grid layout. * * @access public * @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 */ function getEmailListing($options, $current_row = 0, $max = 5) { $prj_id = Auth::getCurrentProject(); $usr_id = Auth::getUserID(); if ($max == "ALL") { $max = 9999999; } $start = $current_row * $max; $stmt = "SELECT\n sup_id,\n sup_ema_id,\n sup_iss_id,\n sup_customer_id,\n sup_from,\n sup_date,\n sup_to,\n sup_subject,\n sup_has_attachment\n FROM\n (\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "email_account"; if (!empty($options['keywords'])) { $stmt .= "," . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email_body"; } $stmt .= "\n )\n LEFT JOIN\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n ON\n sup_iss_id = iss_id"; $stmt .= Support::buildWhereClause($options); $stmt .= "\n ORDER BY\n " . Misc::escapeString($options["sort_by"]) . " " . Misc::escapeString($options["sort_order"]); $total_rows = Pager::getTotalRows($stmt); $stmt .= "\n LIMIT\n " . Misc::escapeInteger($start) . ", " . Misc::escapeInteger($max); $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 array("list" => "", "info" => ""); } else { 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(APP_RELATIVE_URL . "emails.php?pagerRow=0&rows={$max}"); } if (Customer::hasCustomerIntegration($prj_id)) { $customer_ids = array(); for ($i = 0; $i < count($res); $i++) { if (!empty($res[$i]['sup_customer_id']) && !in_array($res[$i]['sup_customer_id'], $customer_ids)) { $customer_ids[] = $res[$i]['sup_customer_id']; } } if (count($customer_ids) > 0) { $company_titles = Customer::getTitles($prj_id, $customer_ids); } } 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"] = join(', ', Mail_API::getName($res[$i]["sup_from"], true)); if (empty($res[$i]["sup_to"]) && !empty($res[$i]["sup_iss_id"])) { $res[$i]["sup_to"] = "Notification List"; } else { $res[$i]["sup_to"] = Mime_Helper::fixEncoding(Mail_API::getName($res[$i]["sup_to"])); } if (Customer::hasCustomerIntegration($prj_id)) { @($res[$i]['customer_title'] = $company_titles[$res[$i]['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. * * @access public * @param integer $prj_id The project ID * @param integer $issue_id The issue ID * @param array $sup_ids The email IDs * @param integer $customer_id The customer ID * @return array The list of recipient emails */ function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = FALSE) { if (Customer::hasCustomerIntegration($prj_id)) { return Customer::notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id); } else { // build the list of recipients $recipients = array(); $recipient_emails = array(); for ($i = 0; $i < count($sup_ids); $i++) { $senders = Support::getSender(array($sup_ids[$i])); if (count($senders) > 0) { $sender_email = Mail_API::getEmailAddress($senders[0]); $recipients[$sup_ids[$i]] = $senders[0]; $recipient_emails[] = $sender_email; } } if (count($recipients) == 0) { return false; } $data = Issue::getDetails($issue_id); foreach ($recipients as $sup_id => $recipient) { // open text template $tpl = new Template_API(); $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text'); $tpl->bulkAssign(array("data" => $data, "sender_name" => Mail_API::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']))); $text_message = $tpl->getTemplateContents(); // send email (use PEAR's classes) $mail = new Mail_API(); $mail->setTextBody($text_message); $setup = $mail->getSMTPSettings(); $from = Notification::getFixedFromHeader($issue_id, $setup["from"], 'issue'); $mail->setHeaders(Mail_API::getBaseThreadingHeaders($issue_id)); $mail->send($from, $recipient, 'New Issue Created', 1, $issue_id, 'email_converted_to_issue'); } return $recipient_emails; } }