XOOPS Docs - kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Source for file pagenav.php

Documentation is available at pagenav.php

  1. <?php
  2. // $Id: pagenav.php 2 2005-11-02 18:23:29Z skalpa $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27. // Author: Kazumi Ono (AKA onokazu)                                          //
  28. // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
  29. // Project: The XOOPS Project                                                //
  30. // ------------------------------------------------------------------------- //
  31.  
  32. /**
  33.  * Class to facilitate navigation in a multi page document/list
  34.  *
  35.  * @package        kernel
  36.  * @subpackage    util
  37.  *
  38.  * @author        Kazumi Ono     <onokazu@xoops.org>
  39.  * @copyright    (c) 2000-2003 The Xoops Project - www.xoops.org
  40.  */
  41. {
  42.     /**#@+
  43.      * @access    private
  44.      */
  45.     var $total;
  46.     var $perpage;
  47.     var $current;
  48.     var $url;
  49.     /**#@-*/
  50.  
  51.     /**
  52.      * Constructor
  53.      *
  54.      * @param   int     $total_items    Total number of items
  55.      * @param   int     $items_perpage  Number of items per page
  56.      * @param   int     $current_start  First item on the current page
  57.      * @param   string  $start_name     Name for "start" or "offset"
  58.      * @param   string  $extra_arg      Additional arguments to pass in the URL
  59.      ***/
  60.     function XoopsPageNav($total_items$items_perpage$current_start$start_name="start"$extra_arg="")
  61.     {
  62.         $this->total intval($total_items);
  63.         $this->perpage intval($items_perpage);
  64.         $this->current intval($current_start);
  65.         if $extra_arg != '' && substr($extra_arg-5!= '&amp;' || substr($extra_arg-1!= '&' ) ) {
  66.             $extra_arg .= '&amp;';
  67.         }
  68.         $this->url $_SERVER['PHP_SELF'].'?'.$extra_arg.trim($start_name).'=';
  69.     }
  70.  
  71.     /**
  72.      * Create text navigation
  73.      *
  74.      * @param   integer $offset 
  75.      * @return  string 
  76.      ***/
  77.     function renderNav($offset 4)
  78.     {
  79.         $ret '';
  80.         if $this->total <= $this->perpage {
  81.             return $ret;
  82.         }
  83.         $total_pages ceil($this->total $this->perpage);
  84.         if $total_pages {
  85.             $prev $this->current $this->perpage;
  86.             if $prev >= {
  87.                 $ret .= '<a href="'.$this->url.$prev.'"><u>&laquo;</u></a> ';
  88.             }
  89.             $counter 1;
  90.             $current_page intval(floor(($this->current $this->perpage$this->perpage));
  91.             while $counter <= $total_pages {
  92.                 if $counter == $current_page {
  93.                     $ret .= '<b>('.$counter.')</b> ';
  94.                 elseif ( ($counter $current_page-$offset && $counter $current_page $offset || $counter == || $counter == $total_pages {
  95.                     if $counter == $total_pages && $current_page $total_pages $offset {
  96.                         $ret .= '... ';
  97.                     }
  98.                     $ret .= '<a href="'.$this->url.(($counter 1$this->perpage).'">'.$counter.'</a> ';
  99.                     if $counter == && $current_page $offset {
  100.                         $ret .= '... ';
  101.                     }
  102.                 }
  103.                 $counter++;
  104.             }
  105.             $next $this->current $this->perpage;
  106.             if $this->total $next {
  107.                 $ret .= '<a href="'.$this->url.$next.'"><u>&raquo;</u></a> ';
  108.             }
  109.         }
  110.         return $ret;
  111.     }
  112.  
  113.     /**
  114.      * Create a navigational dropdown list
  115.      *
  116.      * @param   boolean     $showbutton Show the "Go" button?
  117.      * @return  string 
  118.      ***/
  119.     function renderSelect($showbutton false)
  120.     {
  121.         if $this->total $this->perpage {
  122.             return;
  123.         }
  124.         $total_pages ceil($this->total $this->perpage);
  125.         $ret '';
  126.         if $total_pages {
  127.                $ret '<form name="pagenavform">';
  128.             $ret .= '<select name="pagenavselect" onchange="location=this.options[this.options.selectedIndex].value;">';
  129.             $counter 1;
  130.             $current_page intval(floor(($this->current $this->perpage$this->perpage));
  131.             while $counter <= $total_pages {
  132.                 if $counter == $current_page {
  133.                     $ret .= '<option value="'.$this->url.(($counter 1$this->perpage).'" selected="selected">'.$counter.'</option>';
  134.                 else {
  135.                     $ret .= '<option value="'.$this->url.(($counter 1$this->perpage).'">'.$counter.'</option>';
  136.                 }
  137.                 $counter++;
  138.             }
  139.             $ret .= '</select>';
  140.             if ($showbutton{
  141.                 $ret .= '&nbsp;<input type="submit" value="'._GO.'" />';
  142.             }
  143.             $ret .= '</form>';
  144.         }
  145.         return $ret;
  146.     }
  147.  
  148.     /**
  149.      * Create navigation with images
  150.      *
  151.      * @param   integer     $offset 
  152.      * @return  string 
  153.      ***/
  154.     function renderImageNav($offset 4)
  155.     {
  156.         if $this->total $this->perpage {
  157.             return;
  158.         }
  159.         $total_pages ceil($this->total $this->perpage);
  160.         $ret '';
  161.         if $total_pages {
  162.                $ret '<table><tr>';
  163.             $prev $this->current $this->perpage;
  164.             if $prev >= {
  165.                 $ret .= '<td class="pagneutral"><a href="'.$this->url.$prev.'">&lt;</a></td><td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt="" /></td>';
  166.             }
  167.             $counter 1;
  168.             $current_page intval(floor(($this->current $this->perpage$this->perpage));
  169.             while $counter <= $total_pages {
  170.                 if $counter == $current_page {
  171.                     $ret .= '<td class="pagact"><b>'.$counter.'</b></td>';
  172.                 elseif ( ($counter $current_page-$offset && $counter $current_page $offset || $counter == || $counter == $total_pages {
  173.                     if $counter == $total_pages && $current_page $total_pages $offset {
  174.                         $ret .= '<td class="paginact">...</td>';
  175.                     }
  176.                     $ret .= '<td class="paginact"><a href="'.$this->url.(($counter 1$this->perpage).'">'.$counter.'</a></td>';
  177.                     if $counter == && $current_page $offset {
  178.                         $ret .= '<td class="paginact">...</td>';
  179.                     }
  180.                 }
  181.                 $counter++;
  182.             }
  183.             $next $this->current $this->perpage;
  184.             if $this->total $next {
  185.                 $ret .= '<td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt="" /></td><td class="pagneutral"><a href="'.$this->url.$next.'">&gt;</a></td>';
  186.             }
  187.             $ret .= '</tr></table>';
  188.         }
  189.         return $ret;
  190.     }
  191. }
  192.  
  193. ?>

XOOPS Docs generated by phpDocumentor