Html::printAjaxPager PHP Method

printAjaxPager() static public method

Print Ajax pager for list in tab panel
static public printAjaxPager ( $title, $start, $numrows, $additional_info = '' ) : nothing
$title displayed above
$start from witch item we start
$numrows total items
$additional_info Additional information to display (default '')
return nothing (print a pager)
    static function printAjaxPager($title, $start, $numrows, $additional_info = '')
    {
        global $CFG_GLPI;
        $list_limit = $_SESSION['glpilist_limit'];
        // Forward is the next step forward
        $forward = $start + $list_limit;
        // This is the end, my friend
        $end = $numrows - $list_limit;
        // Human readable count starts here
        $current_start = $start + 1;
        // And the human is viewing from start to end
        $current_end = $current_start + $list_limit - 1;
        if ($current_end > $numrows) {
            $current_end = $numrows;
        }
        // Empty case
        if ($current_end == 0) {
            $current_start = 0;
        }
        // Backward browsing
        if ($current_start - $list_limit <= 0) {
            $back = 0;
        } else {
            $back = $start - $list_limit;
        }
        // Print it
        echo "<div><table class='tab_cadre_pager'>";
        if (!empty($title)) {
            echo "<tr><th colspan='6'>{$title}</th></tr>";
        }
        echo "<tr>\n";
        // Back and fast backward button
        if (!$start == 0) {
            echo "<th class='left'><a href='javascript:reloadTab(\"start=0\");'>\n               <img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __s('Start') . "\" title=\"" . __s('Start') . "\" class='pointer'></a></th>";
            echo "<th class='left'><a href='javascript:reloadTab(\"start={$back}\");'>\n               <img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\" class='pointer'></th>";
        }
        echo "<td width='50%' class='tab_bg_2'>";
        self::printPagerForm();
        echo "</td>";
        if (!empty($additional_info)) {
            echo "<td class='tab_bg_2'>";
            echo $additional_info;
            echo "</td>";
        }
        // Print the "where am I?"
        echo "<td width='50%' class='tab_bg_2 b'>";
        //TRANS: %1$d, %2$d, %3$d are page numbers
        echo sprintf(__('From %1$d to %2$d on %3$d'), $current_start, $current_end, $numrows);
        echo "</td>\n";
        // Forward and fast forward button
        if ($forward < $numrows) {
            echo "<th class='right'><a href='javascript:reloadTab(\"start={$forward}\");'>\n               <img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\" class='pointer'></a></th>";
            echo "<th class='right'><a href='javascript:reloadTab(\"start={$end}\");'>\n               <img src='" . $CFG_GLPI["root_doc"] . "/pics/last.png' alt=\"" . __s('End') . "\" title=\"" . __s('End') . "\" class='pointer'></a></th>";
        }
        // End pager
        echo "</tr></table></div>";
    }

Usage Example

 /**
  * Print the wainting ticket form
  *
  * @param $ID integer ID of the item
  * @param $options array
  *     - target filename : where to go when done.
  *     - withtemplate boolean : template or basic item
  *
  * @return Nothing (display)
  * */
 static function showForTicket($item)
 {
     global $CFG_GLPI;
     // validation des droits
     if (!Session::haveRight('plugin_moreticket', READ)) {
         return false;
     }
     if (isset($_REQUEST["start"])) {
         $start = $_REQUEST["start"];
     } else {
         $start = 0;
     }
     // Total Number of events
     $number = countElementsInTable("glpi_plugin_moreticket_waitingtickets", "`tickets_id`='" . $item->getField('id') . "'");
     if ($number < 1) {
         echo "<div class='center'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('No historical') . "</th></tr>";
         echo "</table>";
         echo "</div><br>";
         return;
     } else {
         echo "<div class='center'>";
         // Display the pager
         Html::printAjaxPager(__('Ticket suspension history', 'moreticket'), $start, $number);
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr>";
         echo "<th>" . __('Suspension date', 'moreticket') . "</th>";
         echo "<th>" . __('Reason', 'moreticket') . "</th>";
         echo "<th>" . PluginMoreticketWaitingType::getTypeName(1) . "</th>";
         echo "<th>" . __('Postponement date', 'moreticket') . "</th>";
         echo "<th>" . __('Suspension end date', 'moreticket') . "</th>";
         echo "</tr>";
         foreach (self::getWaitingTicketFromDB($item->getField('id'), array('start' => $start, 'limit' => $_SESSION['glpilist_limit'])) as $waitingTicket) {
             echo "<tr class='tab_bg_2'>";
             echo "<td>";
             echo Html::convDateTime($waitingTicket['date_suspension']);
             echo "</td>";
             echo "<td>";
             echo $waitingTicket['reason'];
             echo "</td>";
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_plugin_moreticket_waitingtypes', $waitingTicket['plugin_moreticket_waitingtypes_id']);
             echo "</td>";
             echo "<td>";
             if ($waitingTicket['date_report'] == "0000-00-00 00:00:00") {
                 echo _x('periodicity', 'None');
             } else {
                 echo Html::convDateTime($waitingTicket['date_report']);
             }
             echo "</td>";
             echo "<td>";
             echo Html::convDateTime($waitingTicket['date_end_suspension']);
             echo "</td>";
             echo "</tr>";
         }
         echo "</table>";
         echo "</div>";
         Html::printAjaxPager(__('Ticket suspension history', 'moreticket'), $start, $number);
     }
 }
All Usage Examples Of Html::printAjaxPager
Html