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