[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文件
文件大小: 6.55 KiB
MD5: 3cb72c4c0ed2ee2fbef047c80229df2d

split_page_results.php - 关闭高亮
  1. <?php
  2. /**
  3.  * split_page_results Class.
  4.  *
  5.  * @package classes
  6.  * @copyright Copyright 2003-2009 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 $Id: split_page_results.php 17066 2010-07-29 19:18:14Z wilt $
  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) {
  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.     $this->page_name = $page_holder;
  32.  
  33.     if ($debug) {
  34.       echo 'original_query=' . $query . '<br /><br />';
  35.     }
  36.     if (isset($_GET[$page_holder])) {
  37.       $page = $_GET[$page_holder];
  38.     } elseif (isset($_POST[$page_holder])) {
  39.       $page = $_POST[$page_holder];
  40.     } else {
  41.       $page = '';
  42.     }
  43.  
  44.     if (empty($page) || !is_numeric($page)) $page = 1;
  45.     $this->current_page_number = $page;
  46.  
  47.     $this->number_of_rows_per_page = $max_rows;
  48.  
  49.     $pos_to = strlen($this->sql_query);
  50.  
  51.     $query_lower = strtolower($this->sql_query);
  52.     $pos_from = strpos($query_lower, ' from', 0);
  53.  
  54.     $pos_group_by = strpos($query_lower, ' group by', $pos_from);
  55.     if (($pos_group_by < $pos_to) && ($pos_group_by != false)) $pos_to = $pos_group_by;
  56.  
  57.     $pos_having = strpos($query_lower, ' having', $pos_from);
  58.     if (($pos_having < $pos_to) && ($pos_having != false)) $pos_to = $pos_having;
  59.  
  60.     $pos_order_by = strpos($query_lower, ' order by', $pos_from);
  61.     if (($pos_order_by < $pos_to) && ($pos_order_by != false)) $pos_to = $pos_order_by;
  62.  
  63.     if (strpos($query_lower, 'distinct') || strpos($query_lower, 'group by')) {
  64.       $count_string = 'distinct ' . zen_db_input($count_key);
  65.     } else {
  66.       $count_string = zen_db_input($count_key);
  67.     }
  68.     $count_query = "select count(" . $count_string . ") as total " .
  69.     substr($this->sql_query, $pos_from, ($pos_to - $pos_from));
  70.     if ($debug) {
  71.       echo 'count_query=' . $count_query . '<br /><br />';
  72.     }
  73.     $count = $db->Execute($count_query);
  74.  
  75.     $this->number_of_rows = $count->fields['total'];
  76.  
  77.     $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page);
  78.  
  79.     if ($this->current_page_number > $this->number_of_pages) {
  80.       $this->current_page_number = $this->number_of_pages;
  81.     }
  82.  
  83.     $offset = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
  84.  
  85.     // fix offset error on some versions
  86.     if ($offset <= 0) { $offset = 0; }
  87.  
  88.     $this->sql_query .= " limit " . ($offset > 0 ? $offset . ", " : '') . $this->number_of_rows_per_page;
  89.   }
  90.  
  91.   /* class functions */
  92.  
  93.   // display split-page-number-links
  94.   function display_links($max_page_links, $parameters = '') {
  95.     global $request_type;
  96.  
  97.     $display_links_string = '';
  98.  
  99.     $class = '';
  100.  
  101.     if (zen_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&';
  102.  
  103.     // previous button - not displayed on first page
  104.     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;';
  105.  
  106.     // check if number_of_pages > $max_page_links
  107.     $cur_window_num = intval($this->current_page_number / $max_page_links);
  108.     if ($this->current_page_number % $max_page_links) $cur_window_num++;
  109.  
  110.     $max_window_num = intval($this->number_of_pages / $max_page_links);
  111.     if ($this->number_of_pages % $max_page_links) $max_window_num++;
  112.  
  113.     // previous window of pages
  114.     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>';
  115.  
  116.     // page nn button
  117.     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++) {
  118.       if ($jump_to_page == $this->current_page_number) {
  119.         $display_links_string .= '&nbsp;<strong class="current">' . $jump_to_page . '</strong>&nbsp;';
  120.       } else {
  121.         $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;';
  122.       }
  123.     }
  124.  
  125.     // next window of pages
  126.     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;';
  127.  
  128.     // next button
  129.     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;';
  130.  
  131.     if ($display_links_string == '&nbsp;<strong class="current">1</strong>&nbsp;') {
  132.       return '&nbsp;';
  133.     } else {
  134.       return $display_links_string;
  135.     }
  136.   }
  137.  
  138.   // display number of total products found
  139.   function display_count($text_output) {
  140.     $to_num = ($this->number_of_rows_per_page * $this->current_page_number);
  141.     if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows;
  142.  
  143.     $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1));
  144.  
  145.     if ($to_num == 0) {
  146.       $from_num = 0;
  147.     } else {
  148.       $from_num++;
  149.     }
  150.  
  151.     if ($to_num <= 1) {
  152.       // don't show count when 1
  153.       return '';
  154.     } else {
  155.       return sprintf($text_output, $from_num, $to_num, $this->number_of_rows);
  156.     }
  157.   }
  158. }
  159. ?>