home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / pagenav.php < prev    next >
Encoding:
PHP Script  |  2007-09-17  |  7.7 KB  |  198 lines

  1. <?php
  2. // $Id: pagenav.php 1057 2007-09-17 07:05:32Z dugris $
  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. class XoopsPageNav
  42. {
  43.     /**#@+
  44.      * @access    private
  45.      */
  46.     var $total;
  47.     var $perpage;
  48.     var $current;
  49.     var $url;
  50.     /**#@-*/
  51.  
  52.     /**
  53.      * Constructor
  54.      *
  55.      * @param   int     $total_items    Total number of items
  56.      * @param   int     $items_perpage  Number of items per page
  57.      * @param   int     $current_start  First item on the current page
  58.      * @param   string  $start_name     Name for "start" or "offset"
  59.      * @param   string  $extra_arg      Additional arguments to pass in the URL
  60.      **/
  61.     function XoopsPageNav($total_items, $items_perpage, $current_start, $start_name="start", $extra_arg="")
  62.     {
  63.         $this->total = intval($total_items);
  64.         $this->perpage = intval($items_perpage);
  65.         $this->current = intval($current_start);
  66.         if ( $extra_arg != '' && ( substr($extra_arg, -5) != '&' || substr($extra_arg, -1) != '&' ) ) {
  67.             $extra_arg .= '&';
  68.         }
  69.         $this->url = $_SERVER['PHP_SELF'].'?'.$extra_arg.trim($start_name).'=';
  70.     }
  71.  
  72.     /**
  73.      * Create text navigation
  74.      *
  75.      * @param   integer $offset
  76.      * @return  string
  77.      **/
  78.     function renderNav($offset = 4)
  79.     {
  80.         $ret = '';
  81.         if ( $this->total <= $this->perpage ) {
  82.             return $ret;
  83.         }
  84.         $total_pages = ceil($this->total / $this->perpage);
  85.         if ( $total_pages > 1 ) {
  86.             $prev = $this->current - $this->perpage;
  87.             if ( $prev >= 0 ) {
  88.                 $ret .= '<a href="'.$this->url.$prev.'"><u>«</u></a> ';
  89.             }
  90.             $counter = 1;
  91.             $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage));
  92.             while ( $counter <= $total_pages ) {
  93.                 if ( $counter == $current_page ) {
  94.                     $ret .= '<b>('.$counter.')</b> ';
  95.                 } elseif ( ($counter > $current_page-$offset && $counter < $current_page + $offset ) || $counter == 1 || $counter == $total_pages ) {
  96.                     if ( $counter == $total_pages && $current_page < $total_pages - $offset ) {
  97.                         $ret .= '... ';
  98.                     }
  99.                     $ret .= '<a href="'.$this->url.(($counter - 1) * $this->perpage).'">'.$counter.'</a> ';
  100.                     if ( $counter == 1 && $current_page > 1 + $offset ) {
  101.                         $ret .= '... ';
  102.                     }
  103.                 }
  104.                 $counter++;
  105.             }
  106.             $next = $this->current + $this->perpage;
  107.             if ( $this->total > $next ) {
  108.                 $ret .= '<a href="'.$this->url.$next.'"><u>»</u></a> ';
  109.             }
  110.         }
  111.         return $ret;
  112.     }
  113.  
  114.     /**
  115.      * Create a navigational dropdown list
  116.      *
  117.      * @param   boolean     $showbutton Show the "Go" button?
  118.      * @return  string
  119.      **/
  120.     function renderSelect($showbutton = false)
  121.     {
  122.         if ( $this->total < $this->perpage ) {
  123.             return;
  124.         }
  125.         $total_pages = ceil($this->total / $this->perpage);
  126.         $ret = '';
  127.         if ( $total_pages > 1 ) {
  128.                $ret = '<form name="pagenavform">';
  129.             $ret .= '<select name="pagenavselect" onchange="location=this.options[this.options.selectedIndex].value;">';
  130.             $counter = 1;
  131.             $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage));
  132.             while ( $counter <= $total_pages ) {
  133.                 if ( $counter == $current_page ) {
  134.                     $ret .= '<option value="'.$this->url.(($counter - 1) * $this->perpage).'" selected="selected">'.$counter.'</option>';
  135.                 } else {
  136.                     $ret .= '<option value="'.$this->url.(($counter - 1) * $this->perpage).'">'.$counter.'</option>';
  137.                 }
  138.                 $counter++;
  139.             }
  140.             $ret .= '</select>';
  141.             if ($showbutton) {
  142.                 $ret .= ' <input type="submit" value="'._GO.'" />';
  143.             }
  144.             $ret .= '</form>';
  145.         }
  146.         return $ret;
  147.     }
  148.  
  149.     /**
  150.      * Create navigation with images
  151.      *
  152.      * @param   integer     $offset
  153.      * @return  string
  154.      **/
  155.     function renderImageNav($offset = 4)
  156.     {
  157.         if ( $this->total < $this->perpage ) {
  158.             return;
  159.         }
  160.         $total_pages = ceil($this->total / $this->perpage);
  161.         $ret = '';
  162.         if ( $total_pages > 1 ) {
  163.                $ret = '<table><tr>';
  164.             $prev = $this->current - $this->perpage;
  165.             if ( $prev >= 0 ) {
  166.                 $ret .= '<td class="pagneutral"><a href="'.$this->url.$prev.'"><</a></td><td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt="" /></td>';
  167.             } else {
  168.                 $ret .= '<td class="pagno"></a></td><td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt="" /></td>';
  169.             }
  170.             $counter = 1;
  171.             $current_page = intval(floor(($this->current + $this->perpage) / $this->perpage));
  172.             while ( $counter <= $total_pages ) {
  173.                 if ( $counter == $current_page ) {
  174.                     $ret .= '<td class="pagact"><b>'.$counter.'</b></td>';
  175.                 } elseif ( ($counter > $current_page-$offset && $counter < $current_page + $offset ) || $counter == 1 || $counter == $total_pages ) {
  176.                     if ( $counter == $total_pages && $current_page < $total_pages - $offset ) {
  177.                         $ret .= '<td class="paginact">...</td>';
  178.                     }
  179.                     $ret .= '<td class="paginact"><a href="'.$this->url.(($counter - 1) * $this->perpage).'">'.$counter.'</a></td>';
  180.                     if ( $counter == 1 && $current_page > 1 + $offset ) {
  181.                         $ret .= '<td class="paginact">...</td>';
  182.                     }
  183.                 }
  184.                 $counter++;
  185.             }
  186.             $next = $this->current + $this->perpage;
  187.             if ( $this->total > $next ) {
  188.                 $ret .= '<td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt="" /></td><td class="pagneutral"><a href="'.$this->url.$next.'">></a></td>';
  189.             } else {
  190.                 $ret .= '<td><img src="'.XOOPS_URL.'/images/blank.gif" width="6" alt="" /></td><td class="pagno"></td>';
  191.             }
  192.             $ret .= '</tr></table>';
  193.         }
  194.         return $ret;
  195.     }
  196. }
  197.  
  198. ?>