XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
pagenav.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
23 {
29  var $total;
30  var $perpage;
31  var $current;
32  var $url;
46  function XoopsPageNav($total_items, $items_perpage, $current_start, $start_name = "start", $extra_arg = "")
47  {
48  $this->total = intval($total_items);
49  $this->perpage = intval($items_perpage);
50  $this->current = intval($current_start);
51  $this->extra = $extra_arg;
52  if ($extra_arg != '' && (substr($extra_arg, - 5) != '&amp;' || substr($extra_arg, - 1) != '&')) {
53  $this->extra = '&amp;' . $extra_arg;
54  }
55  $this->url = $_SERVER['PHP_SELF'] . '?' . trim($start_name) . '=';
56  }
57 
64  function renderNav($offset = 4)
65  {
66  $ret = '';
67  if ($this->total <= $this->perpage) {
68  return $ret;
69  }
70  if(($this->total != 0) && ($this->perpage != 0)) {
71  $total_pages = ceil($this->total / $this->perpage);
72  if ($total_pages > 1) {
73  $ret .= '<div id="xo-pagenav">';
74  $prev = $this->current - $this->perpage;
75  if ($prev >= 0) {
76  $ret .= '<a class="xo-pagarrow" href="' . $this->url . $prev . $this->extra . '"><u>&laquo;</u></a> ';
77  }
78  $counter = 1;
79  $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage));
80  while ($counter <= $total_pages) {
81  if ($counter == $current_page) {
82  $ret .= '<strong class="xo-pagact" >(' . $counter . ')</strong> ';
83  } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || $counter == 1 || $counter == $total_pages) {
84  if ($counter == $total_pages && $current_page < $total_pages - $offset) {
85  $ret .= '... ';
86  }
87  $ret .= '<a class="xo-counterpage" href="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '">' . $counter . '</a> ';
88  if ($counter == 1 && $current_page > 1 + $offset) {
89  $ret .= '... ';
90  }
91  }
92  $counter ++;
93  }
94  $next = $this->current + $this->perpage;
95  if ($this->total > $next) {
96  $ret .= '<a class="xo-pagarrow" href="' . $this->url . $next . $this->extra . '"><u>&raquo;</u></a> ';
97  }
98  $ret .= '</div> ';
99  }
100  }
101  return $ret;
102  }
103 
110  function renderSelect($showbutton = false)
111  {
112  if ($this->total < $this->perpage) {
113  return;
114  }
115  $total_pages = ceil($this->total / $this->perpage);
116  $ret = '';
117  if ($total_pages > 1) {
118  $ret = '<form name="pagenavform">';
119  $ret .= '<select name="pagenavselect" onchange="location=this.options[this.options.selectedIndex].value;">';
120  $counter = 1;
121  $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage));
122  while ($counter <= $total_pages) {
123  if ($counter == $current_page) {
124  $ret .= '<option value="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '" selected="selected">' . $counter . '</option>';
125  } else {
126  $ret .= '<option value="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '">' . $counter . '</option>';
127  }
128  $counter ++;
129  }
130  $ret .= '</select>';
131  if ($showbutton) {
132  $ret .= '&nbsp;<input type="submit" value="' . _GO . '" />';
133  }
134  $ret .= '</form>';
135  }
136  return $ret;
137  }
138 
145  function renderImageNav($offset = 4)
146  {
147  if ($this->total < $this->perpage) {
148  return;
149  }
150  $total_pages = ceil($this->total / $this->perpage);
151  $ret = '';
152  if ($total_pages > 1) {
153  $ret = '<table><tr>';
154  $prev = $this->current - $this->perpage;
155  if ($prev >= 0) {
156  $ret .= '<td class="pagneutral"><a href="' . $this->url . $prev . $this->extra . '">&lt;</a></td><td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td>';
157  } else {
158  $ret .= '<td class="pagno"></a></td><td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td>';
159  }
160  $counter = 1;
161  $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage));
162  while ($counter <= $total_pages) {
163  if ($counter == $current_page) {
164  $ret .= '<td class="pagact"><strong>' . $counter . '</strong></td>';
165  } elseif (($counter > $current_page - $offset && $counter < $current_page + $offset) || $counter == 1 || $counter == $total_pages) {
166  if ($counter == $total_pages && $current_page < $total_pages - $offset) {
167  $ret .= '<td class="paginact">...</td>';
168  }
169  $ret .= '<td class="paginact"><a href="' . $this->url . (($counter - 1) * $this->perpage) . $this->extra . '">' . $counter . '</a></td>';
170  if ($counter == 1 && $current_page > 1 + $offset) {
171  $ret .= '<td class="paginact">...</td>';
172  }
173  }
174  $counter ++;
175  }
176  $next = $this->current + $this->perpage;
177  if ($this->total > $next) {
178  $ret .= '<td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td><td class="pagneutral"><a href="' . $this->url . $next . $this->extra . '">&gt;</a></td>';
179  } else {
180  $ret .= '<td><img src="' . XOOPS_URL . '/images/blank.gif" width="6" alt="" /></td><td class="pagno"></td>';
181  }
182  $ret .= '</tr></table>';
183  }
184  return $ret;
185  }
186 }
187 
188 ?>