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.         if ($this->limit > $this->total{
  34.             $this->limitstart = 0;
  35.         }
  36.         if (($this->limit-1)*$this->limitstart > $this->total{
  37.             $this->limitstart -= $this->limitstart % $this->limit;
  38.         }
  39.     }
  40.     /**
  41.     * @return string The html for the limit # input box
  42.     */
  43.     function getLimitBox ({
  44.         $limits array();
  45.         for ($i=5$i <= 30$i+=5{
  46.             $limits[mosHTML::makeOption"$i);
  47.         }
  48.         $limits[mosHTML::makeOption"50" );
  49.  
  50.         // build the html select list
  51.         $html mosHTML::selectList$limits'limit''class="inputbox" size="1" onchange="document.adminForm.submit();"',
  52.         'value''text'$this->limit );
  53.         $html .= "\n<input type=\"hidden\" name=\"limitstart\" value=\"$this->limitstart\" />";
  54.         return $html;
  55.     }
  56.     /**
  57.     * Writes the html limit # input box
  58.     */
  59.     function writeLimitBox ({
  60.         echo mosPageNav::getLimitBox();
  61.     }
  62.     function writePagesCounter({
  63.         echo $this->getPagesCounter();
  64.     }
  65.     /**
  66.     * @return string The html for the pages counter, eg, Results 1-10 of x
  67.     */
  68.     function getPagesCounter({
  69.         $html '';
  70.         $from_result $this->limitstart+1;
  71.         if ($this->limitstart + $this->limit < $this->total{
  72.             $to_result $this->limitstart + $this->limit;
  73.         else {
  74.             $to_result $this->total;
  75.         }
  76.         if ($this->total > 0{
  77.             $html .= sprintf(T_("Results %d to %d of %d")$from_result$to_result$this->total);
  78.         else {
  79.             $html .= T_('No records found.');
  80.         }
  81.         return $html;
  82.     }
  83.     /**
  84.     * Writes the html for the pages counter, eg, Results 1-10 of x
  85.     */
  86.     function writePagesLinks({
  87.         echo $this->getPagesLinks();
  88.     }
  89.     /**
  90.     * @return string The html links for pages, eg, previous, next, 1 2 3 ... x
  91.     */
  92.     function getPagesLinks({
  93.         $html '';
  94.         $displayed_pages 10;
  95.         $total_pages ceil$this->total / $this->limit );
  96.         $this_page ceil( ($this->limitstart+1$this->limit );
  97.         $start_loop (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1;
  98.         if ($start_loop $displayed_pages $total_pages{
  99.             $stop_loop $start_loop $displayed_pages 1;
  100.         else {
  101.             $stop_loop $total_pages;
  102.         }
  103.  
  104.         if ($this_page 1{
  105.             $page ($this_page 2$this->limit;
  106.             $html .= "\n<a href=\"#beg\" class=\"pagenav\" title=\"".T_('first page')."\" onclick=\"javascript: document.adminForm.limitstart.value=0; document.adminForm.submit();return false;\"><< ".T_('Start')."</a>";
  107.             $html .= "\n<a href=\"#prev\" class=\"pagenav\" title=\"".T_('previous page')."\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\">< ".T_('Previous')."</a>";
  108.         else {
  109.             $html .= "\n<span class=\"pagenav\"><< ".T_('Start')."</span>";
  110.             $html .= "\n<span class=\"pagenav\">< ".T_('Previous')."</span>";
  111.         }
  112.  
  113.         for ($i=$start_loop$i <= $stop_loop$i++{
  114.             $page ($i 1$this->limit;
  115.             if ($i == $this_page{
  116.                 $html .= "\n<span class=\"pagenav\"> $i </span>";
  117.             else {
  118.                 $html .= "\n<a href=\"#$i\" class=\"pagenav\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"><strong>$i</strong></a>";
  119.             }
  120.         }
  121.  
  122.         if ($this_page $total_pages{
  123.             $page $this_page $this->limit;
  124.             $end_page ($total_pages-1$this->limit;
  125.             $html .= "\n<a href=\"#next\" class=\"pagenav\" title=\"".T_('next page')."\" onclick=\"javascript: document.adminForm.limitstart.value=$page; document.adminForm.submit();return false;\"> ".T_('Next')." ></a>";
  126.             $html .= "\n<a href=\"#end\" class=\"pagenav\" title=\"".T_('end page')."\" onclick=\"javascript: document.adminForm.limitstart.value=$end_page; document.adminForm.submit();return false;\"> ".T_('End')." >></a>";
  127.         else {
  128.             $html .= "\n<span class=\"pagenav\">".T_('Next')." ></span>";
  129.             $html .= "\n<span class=\"pagenav\">".T_('End')." >></span>";
  130.         }
  131.         return $html;
  132.     }
  133.     
  134.     function getListFooter({
  135.         $html '<table class="adminlist"><tr><th colspan="3">';
  136.         $html .= $this->getPagesLinks();
  137.         $html .= '</th></tr><tr>';
  138.         $html .= '<td nowrap="true" width="48%" align="right">'.T_('Display #').'</td>';
  139.         $html .= '<td>' .$this->getLimitBox('</td>';
  140.         $html .= '<td nowrap="true" width="48%" align="left">' $this->getPagesCounter('</td>';
  141.         $html .= '</tr></table>';
  142.           return $html;
  143.     }
  144. /**
  145. @param int The row index
  146. @return int 
  147. */
  148.     function rowNumber$i {
  149.         return $i $this->limitstart;
  150.     }
  151. /**
  152. @param int The row index
  153. @param string The task to fire
  154. @param string The alt text for the icon
  155. @return string 
  156. */
  157.     function orderUpIcon$i$condition=true$task='orderup' {
  158.         if (($i || ($i+$this->limitstart > 0)) && $condition{
  159.         $alt T_('Move Up');
  160.             return '<a href="#reorder" onClick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'">
  161.                 <img src="images/uparrow.png" width="12" height="12" border="0" alt="'.$alt.'">
  162.             </a>';
  163.           else {
  164.               return '&nbsp;';
  165.         }
  166.     }
  167. /**
  168. @param int The row index
  169. @param int The number of items in the list
  170. @param string The task to fire
  171. @param string The alt text for the icon
  172. @return string 
  173. */
  174.     function orderDownIcon$i$n$condition=true$task='orderdown' {
  175.         if (($i $n-|| $i+$this->limitstart < $this->total-1&& $condition{
  176.         $alt T_('Move Down');
  177.             return '<a href="#reorder" onClick="return listItemTask(\'cb'.$i.'\',\''.$task.'\')" title="'.$alt.'">
  178.                 <img src="images/downarrow.png" width="12" height="12" border="0" alt="'.$alt.'">
  179.             </a>';
  180.           else {
  181.               return '&nbsp;';
  182.         }
  183.     }
  184. }
  185. ?>

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