Exemplo n.º 1
0
 /**
  * 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));
     }
 }