[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 split_page_results.php

Zen Cart 源代码 split_page_results.php




下载文件

文件名: split_page_results.php
文件类型: PHP文件
文件大小: 7.03 KiB
MD5: e5a989edf0eb50fbe65ea219d8f1ae76

split_page_results.php - 关闭高亮
  1. <?php
  2. /**
  3.  * split_page_results Class.
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2012 Zen Cart Development Team
  7.  * @copyright Portions Copyright 2003 osCommerce
  8.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  9.  * @version GIT: $Id: Author: Ian Wilson  Fri Aug 17 17:54:58 2012 +0100 Modified in v1.5.1 $
  10.  */
  11. if (!defined('IS_ADMIN_FLAG')) {
  12.   die('Illegal Access');
  13. }
  14. /**
  15.  * Split Page Result Class
  16.  *
  17.  * An sql paging class, that allows for sql reslt to be shown over a number of pages using  simple navigation system
  18.  * Overhaul scheduled for subsequent release
  19.  *
  20.  * @package classes
  21.  */
  22. class splitPageResults extends base {
  23.   var $sql_query, $number_of_rows, $current_page_number, $number_of_pages, $number_of_rows_per_page, $page_name;
  24.  
  25.   /* class constructor */
  26.   function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page', $debug = false, $countQuery = "") {
  27.     global $db;
  28.     $max_rows = ($max_rows == '' || $max_rows == 0) ? 20 : $max_rows;
  29.  
  30.     $this->sql_query = preg_replace("/\n\r|\r\n|\n|\r/", " ", $query);
  31.     if ($countQuery != "") $countQuery = preg_replace("/\n\r|\r\n|\n|\r/", " ", $countQuery);
  32.     $this->countQuery = ($countQuery != "") ? $countQuery : $this->sql_query;
  33.     $this->page_name = $page_holder;
  34.  
  35.     if ($debug) {
  36.       echo '<br /><br />';
  37.       echo 'original_query=' . $query . '<br /><br />';
  38.       echo 'original_count_query=' . $countQuery . '<br /><br />';
  39.       echo 'sql_query=' . $this->sql_query . '<br /><br />';
  40.       echo 'count_query=' . $this->countQuery . '<br /><br />';
  41.     }
  42.     if (isset($_GET[$page_holder])) {
  43.       $page = $_GET[$page_holder];
  44.     } elseif (isset($_POST[$page_holder])) {
  45.       $page = $_POST[$page_holder];
  46.     } else {
  47.       $page = '';
  48.     }
  49.  
  50.     if (empty($page) || !is_numeric($page)) $page = 1;
  51.     $this->current_page_number = $page;
  52.  
  53.     $this->number_of_rows_per_page = $max_rows;
  54.  
  55.     $pos_to = strlen($this->countQuery);
  56.  
  57.     $query_lower = strtolower($this->countQuery);
  58.     $pos_from = strpos($query_lower, ' from', 0);
  59.  
  60.     $pos_group_by = strpos($query_lower, ' group by', $pos_from);
  61.     if (($pos_group_by < $pos_to) && ($pos_group_by != false)) $pos_to = $pos_group_by;
  62.  
  63.     $pos_having = strpos($query_lower, ' having', $pos_from);
  64.     if (($pos_having < $pos_to) && ($pos_having != false)) $pos_to = $pos_having;
  65.  
  66.     $pos_order_by = strpos($query_lower, ' order by', $pos_from);
  67.     if (($pos_order_by < $pos_to) && ($pos_order_by != false)) $pos_to = $pos_order_by;
  68.  
  69.     if (strpos($query_lower, 'distinct') || strpos($query_lower, 'group by')) {
  70.       $count_string = 'distinct ' . zen_db_input($count_key);
  71.     } else {
  72.       $count_string = zen_db_input($count_key);
  73.     }
  74.     $count_query = "select count(" . $count_string . ") as total " . substr($this->countQuery, $pos_from, ($pos_to - $pos_from));
  75.     if ($debug) {
  76.       echo 'count_query=' . $count_query . '<br /><br />';
  77.     }
  78.     $count = $db->Execute($count_query);
  79.  
  80.     $this->number_of_rows = $count->fields['total'];
  81.  
  82.     $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page);
  83.  
  84.     if ($this->current_page_number > $this->number_of_pages) {
  85.       $this->current_page_number = $this->number_of_pages;
  86.     }
  87.  
  88.     $offset = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
  89.  
  90.     // fix offset error on some versions
  91.     if ($offset <= 0) { $offset = 0; }
  92.  
  93.     $this->sql_query .= " limit " . ($offset > 0 ? $offset . ", " : '') . $this->number_of_rows_per_page;
  94.   }
  95.  
  96.   /* class functions */
  97.  
  98.   // display split-page-number-links
  99.   function display_links($max_page_links, $parameters = '') {
  100.     global $request_type;
  101.     if ($max_page_links == '') $max_page_links = 1;
  102.  
  103.     $display_links_string = '';
  104.  
  105.     $class = '';
  106.  
  107.     if (zen_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&';
  108.  
  109.     // previous button - not displayed on first page
  110.     if ($this->current_page_number > 1) $display_links_string .= '<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . ($this->current_page_number - 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_PREVIOUS_PAGE . ' ">' . PREVNEXT_BUTTON_PREV . '</a>&nbsp;&nbsp;';
  111.  
  112.     // check if number_of_pages > $max_page_links
  113.     $cur_window_num = intval($this->current_page_number / $max_page_links);
  114.     if ($this->current_page_number % $max_page_links) $cur_window_num++;
  115.  
  116.     $max_window_num = intval($this->number_of_pages / $max_page_links);
  117.     if ($this->number_of_pages % $max_page_links) $max_window_num++;
  118.  
  119.     // previous window of pages
  120.     if ($cur_window_num > 1) $display_links_string .= '<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>';
  121.  
  122.     // page nn button
  123.     for ($jump_to_page = 1 + (($cur_window_num - 1) * $max_page_links); ($jump_to_page <= ($cur_window_num * $max_page_links)) && ($jump_to_page <= $this->number_of_pages); $jump_to_page++) {
  124.       if ($jump_to_page == $this->current_page_number) {
  125.         $display_links_string .= '&nbsp;<strong class="current">' . $jump_to_page . '</strong>&nbsp;';
  126.       } else {
  127.         $display_links_string .= '&nbsp;<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . $jump_to_page, $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' ">' . $jump_to_page . '</a>&nbsp;';
  128.       }
  129.     }
  130.  
  131.     // next window of pages
  132.     if ($cur_window_num < $max_window_num) $display_links_string .= '<a href="' . zen_href_link($_GET['main_page'], $parameters . $this->page_name . '=' . (($cur_window_num) * $max_page_links + 1), $request_type) . '" title=" ' . sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>&nbsp;';
  133.  
  134.     // next button
  135.     if (($this->current_page_number < $this->number_of_pages) && ($this->number_of_pages != 1)) $display_links_string .= '&nbsp;<a href="' . zen_href_link($_GET['main_page'], $parameters . 'page=' . ($this->current_page_number + 1), $request_type) . '" title=" ' . PREVNEXT_TITLE_NEXT_PAGE . ' ">' . PREVNEXT_BUTTON_NEXT . '</a>&nbsp;';
  136.  
  137.     if ($display_links_string == '&nbsp;<strong class="current">1</strong>&nbsp;') {
  138.       return '&nbsp;';
  139.     } else {
  140.       return $display_links_string;
  141.     }
  142.   }
  143.  
  144.   // display number of total products found
  145.   function display_count($text_output) {
  146.     $to_num = ($this->number_of_rows_per_page * $this->current_page_number);
  147.     if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows;
  148.  
  149.     $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
  150.  
  151.     if ($to_num == 0) {
  152.       $from_num = 0;
  153.     } else {
  154.       $from_num++;
  155.     }
  156.  
  157.     if ($to_num <= 1) {
  158.       // don't show count when 1
  159.       return '';
  160.     } else {
  161.       return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
  162.     }
  163.   }
  164. }
  165.  


cron