Source for file pageNavigation.php

Documentation is available at pageNavigation.php

  1. <?php
  2. /**
  3. @package Mambo
  4. @author Mambo Foundation Inc see README.php
  5. @copyright Mambo Foundation Inc.
  6. *  See COPYRIGHT.php for copyright notices and details.
  7. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  8. *  LICENSE.php
  9. *  Mambo is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU General Public License
  11. *  as published by the Free Software Foundation; version 2 of the
  12. *  License.
  13. */ 
  14.  
  15. /** ensure this file is being included by a parent file */
  16. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  17.  
  18. /**
  19. * Page navigation support class
  20. */
  21. class mosPageNav {
  22.     /** @var int The record number to start dislpaying from */
  23.     var $limitstart = null;
  24.     /** @var int Number of rows to display per page */
  25.     var $limit = null;
  26.     /** @var int Total number of rows */
  27.     var $total = null;
  28.  
  29.     function mosPageNav$total$limitstart$limit {
  30.         $this->total = intval$total );
  31.         $this->limitstart = maxintval($limitstart));
  32.         $this->limit = maxintval($limit));
  33.     }
  34.     /**
  35.     * Returns the html limit # input box
  36.     * @param string The basic link to include in the href
  37.     * @return string 
  38.     */
  39.     function getLimitBox ({
  40.         $limits array();
  41.         for ($i=5$i <= 30$i+=5{
  42.             $limits[mosHTML::makeOption"$i);
  43.         }
  44.         $limits[mosHTML::makeOption"50" );
  45.         $limits[mosHTML::makeOption"100" );
  46.         $limits[mosHTML::makeOption"500" );
  47.         $limits[mosHTML::makeOption"1000" );
  48.         $limits[mosHTML::makeOption"2500" );
  49.         $limits[mosHTML::makeOption"5000" );
  50.  
  51.         // build the html select list
  52.         $html mosHTML::selectList$limits'limit''class="inputbox" size="1" onchange="document.adminForm.submit();"',
  53.         'value''text'$this->limit );
  54.         $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"$this->limitstart\" />";
  55.         return $html;
  56.     }
  57.     /**
  58.     * Writes the html limit # input box
  59.     * @param string The basic link to include in the href
  60.     */
  61.     function writeLimitBox $link {
  62.         echo mosPageNav::getLimitBox$link );
  63.     }
  64.     /**
  65.     * Writes the html for the pages counter, eg, Results 1-10 of x
  66.     */
  67.     function writePagesCounter({
  68.         $txt '';
  69.         $from_result $this->limitstart+1;
  70.         if ($this->limitstart + $this->limit < $this->total{
  71.             $to_result $this->limitstart + $this->limit;
  72.         else {
  73.             $to_result $this->total;
  74.         }
  75.         if ($this->total > 0{
  76.             $txt .= sprintf(T_('Results %d - %d of %d')$from_result$to_result$this->total);
  77.         }
  78.         return $txt;
  79.     }
  80.  
  81.     /**
  82.     * Writes the html for the leafs counter, eg, Page 1 of x
  83.     */
  84.     function writeLeafsCounter({
  85.         $txt '';
  86.         $page $this->limitstart+1;
  87.         if ($this->total > 0{
  88.             $txt .= sprintf(T_('Page %d of %d')$page$this->total);
  89.         }
  90.         return $txt;
  91.     }
  92.  
  93.     /**
  94.     * Writes the html links for pages, eg, previous, next, 1 2 3 ... x
  95.     * @param string The basic link to include in the href
  96.     */
  97.     function writePagesLinks$link {
  98.  
  99.         // clean link - could be better filtered in rewrite
  100.         // stops XSS
  101.         require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php');
  102.         $iFilter new InputFilternullnull1);
  103.         $link trim$iFilter->process$link ) );
  104.  
  105.         // Removing task breaks nagivation - temporarily removed for 4.6.2 release
  106.         // For more information, See FS#127
  107.         //        $link = preg_replace("/(task.*?)&/i", "", $link);
  108.  
  109.         $txt '';
  110.  
  111.         $displayed_pages 10;
  112.         $total_pages ceil$this->total / $this->limit );
  113.         $this_page ceil( ($this->limitstart+1$this->limit );
  114.         $start_loop (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1;
  115.         if ($start_loop $displayed_pages $total_pages{
  116.             $stop_loop $start_loop $displayed_pages 1;
  117.         else {
  118.             $stop_loop $total_pages;
  119.         }
  120.  
  121.         $link .= '&amp;limit='$this->limit;
  122.  
  123.         if ($this_page 1{
  124.             $page ($this_page 2$this->limit;
  125.             $txt .= '<a href="'sefRelToAbs"$link&amp;limitstart=0.'" class="pagenav" title="'.T_('first page').'">&lt;&lt; 'T_('Start'.'</a> ';
  126.             $txt .= '<a href="'sefRelToAbs"$link&amp;limitstart=$page.'" class="pagenav" title="'.T_('previous page').'">&lt; 'T_('Previous'.'</a> ';
  127.         else {
  128.             $txt .= '<span class="pagenav">&lt;&lt; 'T_('Start'.'</span> ';
  129.             $txt .= '<span class="pagenav">&lt; 'T_('Previous'.'</span> ';
  130.         }
  131.  
  132.         for ($i=$start_loop$i <= $stop_loop$i++{
  133.             $page ($i 1$this->limit;
  134.             if ($i == $this_page{
  135.                 $txt .= '<span class="pagenav">'$i .'</span> ';
  136.             else {
  137.                 $txt .= '<a href="'sefRelToAbs$link .'&amp;limitstart='$page .'" class="pagenav"><strong>'$i .'</strong></a> ';
  138.             }
  139.         }
  140.  
  141.         if ($this_page $total_pages{
  142.             $page $this_page $this->limit;
  143.             $end_page ($total_pages-1$this->limit;
  144.             $txt .= '<a href="'sefRelToAbs$link .'&amp;limitstart='$page .' " class="pagenav" title="'.T_('next page').'">'T_('Next'.' &gt;</a> ';
  145.             $txt .= '<a href="'sefRelToAbs$link .'&amp;limitstart='$end_page .' " class="pagenav" title="'.T_('end page').'">'T_('End'.' &gt;&gt;</a>';
  146.         else {
  147.             $txt .= '<span class="pagenav">'T_('Next'.' &gt;</span> ';
  148.             $txt .= '<span class="pagenav">'T_('End'.' &gt;&gt;</span>';
  149.         }
  150.  
  151.  
  152.  
  153.         return $txt;
  154.     }
  155. }
  156. ?>

Documentation generated on Mon, 05 May 2008 16:21:42 +0400 by phpDocumentor 1.4.0