limits = $limits; } else { $this->limits = array(10); } $this->limit = ($limit > 0) ? $limit : $this->limits[0];// ilość produktów na stornie $this->limitstart = ($limitstart > 0) ? (floor($limitstart / $this->limit) * $this->limit) : 0; $this->total = $total; $this->page = intval($this->limitstart / $this->limit) + 1; $this->pages = (int)ceil($this->total / $this->limit); $this->max2show = 10; $this->req_method = 'GET'; $this->req_args = array(); $this->page_nr_arg_name = 'nr'; } public function set_request_args($args) { $this->req_args = $args; } public function set_request_arg_page_nr_name($nr_name) { $this->page_nr_arg_name = $nr_name; } public function set_request_method_post() { $this->req_method = 'POST'; $this->_post_uniq_id = uniqid('PageNav_'); } public function set_request_method_get() { $this->req_method = 'GET'; } /** * Generate page nr link. */ public function get_page_link($nr) { $params = array(); foreach ($this->req_args as $k => $v) { $params [$k] = $v; } $params[$this->page_nr_arg_name] = ($nr - 1) * $this->limit; $params_out = array(); foreach ($params as $k => $v) { $params_out[] = $k . "=" . $v; } return "?" . implode("&", $params_out); } function render_post_form() { $out = ''; if (!$this->_post_form_rendered) { $out .= ''; $out .= ''; $this->_post_form_rendered = true; } return $out; } /** * Render navigation links. */ public function render($type = 'table') { $out = ''; if ($this->req_method == 'POST') { $out .= $this->render_post_form(); } $out .= '';//.page-nav return $out; } public function show_page($nr) { if ($nr > 0 && $nr <= $this->total) { if ($nr == $this->page) { return ''.$nr.''; } else { return $this->link(''.$nr.'', $nr, array('title'=>"Strona {$nr}")); } } return ''; } public function link($label, $nr, $params = array()) { $out = ''; $link_out = $this->get_page_link($nr); $attrs = array(); if ('' != ($title = V::get('title', '', $params))) { $attrs[] = 'title="' . $title . '"'; } if ('' != ($class = V::get('class', '', $params))) { $attrs[] = 'class="' . $class . '"'; } if ($this->req_method == 'POST') { $offset = ($nr - 1) * $this->limit; $attrs[] = 'onclick="' . "return {$this->_post_uniq_id}_frm({$offset})" . '"'; } $attrs_out = (!empty($attrs))? ' ' . implode(' ', $attrs) : ''; $out = '' . $label . ''; return $out; } }