| [ Index ] |
|
Code source de osCommerce 2.2ms2-060817 |
1 <?php 2 /* 3 $Id: split_page_results.php,v 1.15 2003/06/09 22:35:34 hpdl Exp $ 4 5 osCommerce, Open Source E-Commerce Solutions 6 http://www.oscommerce.com 7 8 Copyright (c) 2003 osCommerce 9 10 Released under the GNU General Public License 11 */ 12 13 class splitPageResults { 14 var $sql_query, $number_of_rows, $current_page_number, $number_of_pages, $number_of_rows_per_page, $page_name; 15 16 /* class constructor */ 17 function splitPageResults($query, $max_rows, $count_key = '*', $page_holder = 'page') { 18 global $HTTP_GET_VARS, $HTTP_POST_VARS; 19 20 $this->sql_query = $query; 21 $this->page_name = $page_holder; 22 23 if (isset($HTTP_GET_VARS[$page_holder])) { 24 $page = $HTTP_GET_VARS[$page_holder]; 25 } elseif (isset($HTTP_POST_VARS[$page_holder])) { 26 $page = $HTTP_POST_VARS[$page_holder]; 27 } else { 28 $page = ''; 29 } 30 31 if (empty($page) || !is_numeric($page)) $page = 1; 32 $this->current_page_number = $page; 33 34 $this->number_of_rows_per_page = $max_rows; 35 36 $pos_to = strlen($this->sql_query); 37 $pos_from = strpos($this->sql_query, ' from', 0); 38 39 $pos_group_by = strpos($this->sql_query, ' group by', $pos_from); 40 if (($pos_group_by < $pos_to) && ($pos_group_by != false)) $pos_to = $pos_group_by; 41 42 $pos_having = strpos($this->sql_query, ' having', $pos_from); 43 if (($pos_having < $pos_to) && ($pos_having != false)) $pos_to = $pos_having; 44 45 $pos_order_by = strpos($this->sql_query, ' order by', $pos_from); 46 if (($pos_order_by < $pos_to) && ($pos_order_by != false)) $pos_to = $pos_order_by; 47 48 if (strpos($this->sql_query, 'distinct') || strpos($this->sql_query, 'group by')) { 49 $count_string = 'distinct ' . tep_db_input($count_key); 50 } else { 51 $count_string = tep_db_input($count_key); 52 } 53 54 $count_query = tep_db_query("select count(" . $count_string . ") as total " . substr($this->sql_query, $pos_from, ($pos_to - $pos_from))); 55 $count = tep_db_fetch_array($count_query); 56 57 $this->number_of_rows = $count['total']; 58 59 $this->number_of_pages = ceil($this->number_of_rows / $this->number_of_rows_per_page); 60 61 if ($this->current_page_number > $this->number_of_pages) { 62 $this->current_page_number = $this->number_of_pages; 63 } 64 65 $offset = ($this->number_of_rows_per_page * ($this->current_page_number - 1)); 66 67 $this->sql_query .= " limit " . max($offset, 0) . ", " . $this->number_of_rows_per_page; 68 } 69 70 /* class functions */ 71 72 // display split-page-number-links 73 function display_links($max_page_links, $parameters = '') { 74 global $PHP_SELF, $request_type; 75 76 $display_links_string = ''; 77 78 $class = 'class="pageResults"'; 79 80 if (tep_not_null($parameters) && (substr($parameters, -1) != '&')) $parameters .= '&'; 81 82 // previous button - not displayed on first page 83 if ($this->current_page_number > 1) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . ($this->current_page_number - 1), $request_type) . '" class="pageResults" title=" ' . PREVNEXT_TITLE_PREVIOUS_PAGE . ' "><u>' . PREVNEXT_BUTTON_PREV . '</u></a> '; 84 85 // check if number_of_pages > $max_page_links 86 $cur_window_num = intval($this->current_page_number / $max_page_links); 87 if ($this->current_page_number % $max_page_links) $cur_window_num++; 88 89 $max_window_num = intval($this->number_of_pages / $max_page_links); 90 if ($this->number_of_pages % $max_page_links) $max_window_num++; 91 92 // previous window of pages 93 if ($cur_window_num > 1) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . (($cur_window_num - 1) * $max_page_links), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_PREV_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a>'; 94 95 // page nn button 96 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++) { 97 if ($jump_to_page == $this->current_page_number) { 98 $display_links_string .= ' <b>' . $jump_to_page . '</b> '; 99 } else { 100 $display_links_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . $jump_to_page, $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_PAGE_NO, $jump_to_page) . ' "><u>' . $jump_to_page . '</u></a> '; 101 } 102 } 103 104 // next window of pages 105 if ($cur_window_num < $max_window_num) $display_links_string .= '<a href="' . tep_href_link(basename($PHP_SELF), $parameters . $this->page_name . '=' . (($cur_window_num) * $max_page_links + 1), $request_type) . '" class="pageResults" title=" ' . sprintf(PREVNEXT_TITLE_NEXT_SET_OF_NO_PAGE, $max_page_links) . ' ">...</a> '; 106 107 // next button 108 if (($this->current_page_number < $this->number_of_pages) && ($this->number_of_pages != 1)) $display_links_string .= ' <a href="' . tep_href_link(basename($PHP_SELF), $parameters . 'page=' . ($this->current_page_number + 1), $request_type) . '" class="pageResults" title=" ' . PREVNEXT_TITLE_NEXT_PAGE . ' "><u>' . PREVNEXT_BUTTON_NEXT . '</u></a> '; 109 110 return $display_links_string; 111 } 112 113 // display number of total products found 114 function display_count($text_output) { 115 $to_num = ($this->number_of_rows_per_page * $this->current_page_number); 116 if ($to_num > $this->number_of_rows) $to_num = $this->number_of_rows; 117 118 $from_num = ($this->number_of_rows_per_page * ($this->current_page_number - 1)); 119 120 if ($to_num == 0) { 121 $from_num = 0; 122 } else { 123 $from_num++; 124 } 125 126 return sprintf($text_output, $from_num, $to_num, $this->number_of_rows); 127 } 128 } 129 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 19:48:25 2007 | par Balluche grâce à PHPXref 0.7 |
|