Display the list_limit combo choice
static public printPagerForm ( $action = "" ) : nothing | ||
$action | page would be posted when change the value (URL + param) (default '') ajax Pager will be displayed if empty | |
return | nothing | (print a combo) |
/** * Print the HTML array for infocoms linked * *@return Nothing (display) * **/ function showInfocoms() { global $DB, $CFG_GLPI; $instID = $this->fields['id']; if (!$this->can($instID, 'r')) { return false; } $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_infocoms`\n WHERE `suppliers_id` = '{$instID}'\n AND `itemtype` NOT IN ('ConsumableItem', 'CartridgeItem', 'Software')\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>"; Html::printPagerForm(); echo "</th><th colspan='3'>"; if ($DB->numrows($result) == 0) { _e('No associated item'); } else { echo _n('Associated item', 'Associated items', $DB->numrows($result)); } echo "</th></tr>"; echo "<tr><th>" . __('Type') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; $num = 0; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { $linktype = $itemtype; $linkfield = 'id'; $itemtable = getTableForItemType($itemtype); $query = "SELECT `glpi_infocoms`.`entities_id`, `name`, `{$itemtable}`.*\n FROM `glpi_infocoms`\n INNER JOIN `{$itemtable}` ON (`{$itemtable}`.`id` = `glpi_infocoms`.`items_id`) "; // Set $linktype for entity restriction AND link to search engine if ($itemtype == 'Cartridge') { $query .= "INNER JOIN `glpi_cartridgeitems`\n ON (`glpi_cartridgeitems`.`id`=`glpi_cartridges`.`cartridgeitems_id`) "; $linktype = 'CartridgeItem'; $linkfield = 'cartridgeitems_id'; } if ($itemtype == 'Consumable') { $query .= "INNER JOIN `glpi_consumableitems`\n ON (`glpi_consumableitems`.`id`=`glpi_consumables`.`consumableitems_id`) "; $linktype = 'ConsumableItem'; $linkfield = 'consumableitems_id'; } $linktable = getTableForItemType($linktype); $query .= "WHERE `glpi_infocoms`.`itemtype` = '{$itemtype}'\n AND `glpi_infocoms`.`suppliers_id` = '{$instID}'" . getEntitiesRestrictRequest(" AND", $linktable) . "\n ORDER BY `glpi_infocoms`.`entities_id`,\n `{$linktable}`.`name`"; $result_linked = $DB->query($query); $nb = $DB->numrows($result_linked); // Set $linktype for link to search engine pnly if ($itemtype == 'SoftwareLicense' && $nb > $_SESSION['glpilist_limit']) { $linktype = 'Software'; $linkfield = 'softwares_id'; } if ($nb > $_SESSION['glpilist_limit']) { echo "<tr class='tab_bg_1'>"; $title = $item->getTypeName($nb); if ($nb > 0) { $title = sprintf(__('%1$s: %2$s'), $title, $nb); } echo "<td class='center'>" . $title . "</td>"; echo "<td class='center' colspan='2'>"; echo "<a href='" . Toolbox::getItemTypeSearchURL($linktype) . "?" . rawurlencode("contains[0]") . "=" . rawurlencode('$$$$' . $instID) . "&" . rawurlencode("field[0]") . "=53&sort=80&order=ASC&is_deleted=0&start=0" . "'>" . __('Device list') . "</a></td>"; echo "<td class='center'>-</td><td class='center'>-</td></tr>"; } else { if ($nb) { for ($prem = true; $data = $DB->fetch_assoc($result_linked); $prem = false) { $name = $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); } $link = Toolbox::getItemTypeFormURL($linktype); $name = "<a href=\"" . $link . "?id=" . $data[$linkfield] . "\">" . $name . "</a>"; echo "<tr class='tab_bg_1'>"; if ($prem) { $title = $item->getTypeName($nb); if ($nb > 0) { $title = sprintf(__('%1$s: %2$s'), $title, $nb); } echo "<td class='center top' rowspan='{$nb}'>" . $title . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]) . "</td>"; echo "<td class='center"; echo (isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'") . ">"; echo $name . "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } $num += $nb; } } echo "<tr class='tab_bg_2'>"; echo "<td class='center'>" . ($num > 0 ? sprintf(__('%1$s = %2$s'), __('Total'), $num) : " ") . "</td>"; echo "<td colspan='4'> </td></tr> "; echo "</table></div>"; }
/** * Print the HTML array of Items on a budget * * @return Nothing (display) **/ function showItems() { global $DB; $budgets_id = $this->fields['id']; if (!$this->can($budgets_id, READ)) { return false; } $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_infocoms`\n WHERE `budgets_id` = '{$budgets_id}'\n AND itemtype NOT IN ('ConsumableItem', 'CartridgeItem', 'Software')\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>"; Html::printPagerForm(); echo "</th><th colspan='4'>"; if ($DB->numrows($result) == 0) { _e('No associated item'); } else { echo _n('Associated item', 'Associated items', $DB->numrows($result)); } echo "</th></tr>"; echo "<tr><th>" . __('Type') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "<th>" . _x('price', 'Value') . "</th>"; echo "</tr>"; $num = 0; $itemtypes = array(); for ($i = 0; $i < $number; $i++) { $itemtypes[] = $DB->result($result, $i, "itemtype"); } $itemtypes[] = 'Contract'; $itemtypes[] = 'Ticket'; $itemtypes[] = 'Problem'; $itemtypes[] = 'Change'; $itemtypes[] = 'Project'; foreach ($itemtypes as $itemtype) { if (!($item = getItemForItemtype($itemtype))) { continue; } if ($item->canView()) { switch ($itemtype) { case 'Contract': $query = "SELECT `" . $item->getTable() . "`.`id`,\n `" . $item->getTable() . "`.`entities_id`,\n SUM(`glpi_contractcosts`.`cost`) as value\n FROM `glpi_contractcosts`\n INNER JOIN `" . $item->getTable() . "`\n ON (`" . $item->getTable() . "`.`id` = `glpi_contractcosts`.`contracts_id`)\n WHERE `glpi_contractcosts`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $item->getTable()) . "\n AND NOT `" . $item->getTable() . "`.`is_template`\n GROUP BY `" . $item->getTable() . "`.`id`, `" . $item->getTable() . "`.`entities_id`\n ORDER BY `" . $item->getTable() . "`.`entities_id`,\n `" . $item->getTable() . "`.`name`"; break; case 'Ticket': case 'Problem': case 'Change': $costtable = getTableForItemType($item->getType() . 'Cost'); $query = "SELECT `" . $item->getTable() . "`.`id`,\n `" . $item->getTable() . "`.`entities_id`,\n SUM(`{$costtable}`.`actiontime`*`{$costtable}`.`cost_time`/" . HOUR_TIMESTAMP . "\n + `{$costtable}`.`cost_fixed`\n + `{$costtable}`.`cost_material`) as value\n FROM `{$costtable}`\n INNER JOIN `" . $item->getTable() . "`\n ON (`" . $item->getTable() . "`.`id` = `{$costtable}`.`" . $item->getForeignKeyField() . "`)\n WHERE `{$costtable}`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $item->getTable()) . "\n GROUP BY `" . $item->getTable() . "`.`id`, `" . $item->getTable() . "`.`entities_id`\n ORDER BY `" . $item->getTable() . "`.`entities_id`,\n `" . $item->getTable() . "`.`name`"; break; case 'Project': $query = "SELECT `" . $item->getTable() . "`.`id`,\n `" . $item->getTable() . "`.`entities_id`,\n SUM(`glpi_projectcosts`.`cost`) as value\n FROM `glpi_projectcosts`\n INNER JOIN `" . $item->getTable() . "`\n ON (`" . $item->getTable() . "`.`id` = `glpi_projectcosts`.`projects_id`)\n WHERE `glpi_projectcosts`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $item->getTable()) . "\n GROUP BY `" . $item->getTable() . "`.`id`, `" . $item->getTable() . "`.`entities_id`\n ORDER BY `" . $item->getTable() . "`.`entities_id`,\n `" . $item->getTable() . "`.`name`"; break; case 'Cartridge': $query = "SELECT `" . $item->getTable() . "`.*,\n `glpi_cartridgeitems`.`name`,\n `glpi_infocoms`.`value`\n FROM `glpi_infocoms`\n INNER JOIN `" . $item->getTable() . "`\n ON (`" . $item->getTable() . "`.`id` = `glpi_infocoms`.`items_id`)\n INNER JOIN `glpi_cartridgeitems`\n ON (`" . $item->getTable() . "`.`cartridgeitems_id`\n = `glpi_cartridgeitems`.`id`)\n WHERE `glpi_infocoms`.`itemtype`='{$itemtype}'\n AND `glpi_infocoms`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $item->getTable()) . "\n ORDER BY `entities_id`,\n `glpi_cartridgeitems`.`name`"; break; case 'Consumable': $query = "SELECT `" . $item->getTable() . "`.*,\n `glpi_consumableitems`.`name`,\n `glpi_infocoms`.`value`\n FROM `glpi_infocoms`\n INNER JOIN `" . $item->getTable() . "`\n ON (`" . $item->getTable() . "`.`id` = `glpi_infocoms`.`items_id`)\n INNER JOIN `glpi_consumableitems`\n ON (`" . $item->getTable() . "`.`consumableitems_id`\n = `glpi_consumableitems`.`id`)\n WHERE `glpi_infocoms`.`itemtype` = '{$itemtype}'\n AND `glpi_infocoms`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $item->getTable()) . "\n ORDER BY `entities_id`,\n `glpi_consumableitems`.`name`"; break; default: $query = "SELECT `" . $item->getTable() . "`.*,\n `glpi_infocoms`.`value`\n FROM `glpi_infocoms`\n INNER JOIN `" . $item->getTable() . "`\n ON (`" . $item->getTable() . "`.`id` = `glpi_infocoms`.`items_id`)\n WHERE `glpi_infocoms`.`itemtype` = '{$itemtype}'\n AND `glpi_infocoms`.`budgets_id` = '{$budgets_id}' " . getEntitiesRestrictRequest(" AND", $item->getTable()) . "\n " . ($item->maybeTemplate() ? " AND NOT `" . $item->getTable() . "`.`is_template`" : '') . "\n ORDER BY `" . $item->getTable() . "`.`entities_id`,"; if ($item instanceof Item_Devices) { $query .= " `" . $item->getTable() . "`.`itemtype`"; } else { $query .= " `" . $item->getTable() . "`.`name`"; } break; } if ($result_linked = $DB->query($query)) { $nb = $DB->numrows($result_linked); if ($nb > $_SESSION['glpilist_limit']) { echo "<tr class='tab_bg_1'>"; $name = $item->getTypeName($nb); //TRANS: %1$s is a name, %2$s is a number echo "<td class='center'>" . sprintf(__('%1$s: %2$s'), $name, $nb) . "</td>"; echo "<td class='center' colspan='2'>"; $opt = array('order' => 'ASC', 'is_deleted' => 0, 'reset' => 'reset', 'start' => 0, 'sort' => 80, 'criteria' => array(0 => array('value' => '$$$$' . $budgets_id, 'searchtype' => 'contains', 'field' => 50))); echo "<a href='" . $item->getSearchURL() . "?" . Toolbox::append_params($opt) . "'>" . __('Device list') . "</a></td>"; echo "<td class='center'>-</td><td class='center'>-</td><td class='center'>-" . "</td></tr>"; } else { if ($nb) { for ($prem = true; $data = $DB->fetch_assoc($result_linked); $prem = false) { $name = NOT_AVAILABLE; if ($item->getFromDB($data["id"])) { if ($item instanceof Item_Devices) { $tmpitem = new $item::$itemtype_2(); if ($tmpitem->getFromDB($data[$item::$items_id_2])) { $name = $tmpitem->getLink(array('additional' => true)); } } else { $name = $item->getLink(array('additional' => true)); } } echo "<tr class='tab_bg_1'>"; if ($prem) { $typename = $item->getTypeName($nb); echo "<td class='center top' rowspan='{$nb}'>" . ($nb > 1 ? sprintf(__('%1$s: %2$s'), $typename, $nb) : $typename) . "</td>"; } echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entities_id"]); echo "</td><td class='center"; echo isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'"; echo ">" . $name . "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-"); echo "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["value"]) ? "" . Html::formatNumber($data["value"], true) . "" : "-"); echo "</td></tr>"; } } } $num += $nb; } } } if ($num > 0) { echo "<tr class='tab_bg_2'>"; echo "<td class='center b'>" . sprintf(__('%1$s = %2$s'), __('Total'), $num) . "</td>"; echo "<td colspan='5'> </td></tr> "; } echo "</table></div>"; }
/** * Print pager for search option (first/previous/next/last) * * @param $start from witch item we start * @param $numrows total items * @param $target page would be open when click on the option (last,previous etc) * @param $parameters parameters would be passed on the URL. * @param $item_type_output item type display - if >0 display export PDF et Sylk form * (default 0) * @param $item_type_output_param item type parameter for export (default 0) * @param $additional_info Additional information to display (default '') * * @return nothing (print a pager) * * */ function printPager($start, $numrows, $target, $parameters, $item_type_output = 0, $item_type_output_param = 0, $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'>"; echo "<tr>"; // Back and fast backward button if (!$start == 0) { echo "<th class='left'>"; echo "<a href='{$target}?{$parameters}&start=0'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __s('Start') . "\" title=\"" . __s('Start') . "\">"; echo "</a></th>"; echo "<th class='left'>"; echo "<a href='{$target}?{$parameters}&start={$back}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\">"; echo "</a></th>"; } // Print the "where am I?" echo "<td width='50%' class='tab_bg_2'>"; Html::printPagerForm("{$target}?{$parameters}&start={$start}"); echo "</td>"; if (!empty($additional_info)) { echo "<td class='tab_bg_2'>"; echo $additional_info; echo "</td>"; } if (!empty($item_type_output) && isset($_SESSION["glpiactiveprofile"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") { echo "<td class='tab_bg_2' width='30%'>"; echo "<form method='GET' action='" . $target . "' target='_blank'>"; echo Html::hidden('item_type', array('value' => $item_type_output)); if ($item_type_output_param != 0) { echo Html::hidden('item_type_param', array('value' => Toolbox::prepareArrayForInput($item_type_output_param))); } $split = explode("&", $parameters); for ($i = 0; $i < count($split); $i++) { $pos = Toolbox::strpos($split[$i], '='); $length = Toolbox::strlen($split[$i]); echo Html::hidden(Toolbox::substr($split[$i], 0, $pos), array('value' => urldecode(Toolbox::substr($split[$i], $pos + 1)))); } Dropdown::showOutputFormat(); $this->showCSVOptions(); echo "<script type='text/javascript'>"; echo "\$('select[name=display_type]').change(function() {\r\n switch(\$(this).val()){\r\n case '3' :case '-3' :\r\n \$('#display_csv_preferences').css('display', 'block');\r\n break;\r\n default : \r\n \$('#display_csv_preferences').css('display', 'none');\r\n break;\r\n }\r\n });"; echo "</script>"; Html::closeForm(); echo "</td>"; } echo "<td width='50%' class='tab_bg_2 b'>"; //TRANS: %1$d, %2$d, %3$d are page numbers printf(__('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'>"; echo "<a href='{$target}?{$parameters}&start={$forward}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\">"; echo "</a></th>\n"; echo "<th class='right'>"; echo "<a href='{$target}?{$parameters}&start={$end}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/last.png' alt=\"" . __s('End') . "\" title=\"" . __s('End') . "\">"; echo "</a></th>\n"; } // End pager echo "</tr></table></div>"; }
public static function showItems(PluginOrderBill $bill) { global $DB; echo "<div class='spaced'><table class='tab_cadre_fixehov'>"; echo "<tr><th>"; Html::printPagerForm(); echo "</th><th colspan='5'>"; echo _n("Item", "Items", 2); echo "</th></tr>"; $bills_id = $bill->getID(); $table = getTableForItemType("PluginOrderOrder_Item"); $query = "SELECT * FROM `" . $table . "`"; $query .= " WHERE `plugin_order_bills_id` = '{$bills_id}'"; $query .= getEntitiesRestrictRequest(" AND", $table, "entities_id", $bill->getEntityID(), true); $query .= "GROUP BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); if (!$number) { echo "</th><td>"; echo _n("Item", "Items", 2); echo "</td></tr>"; } else { echo "<tr>"; echo "<th>" . __("Type") . "</th>"; echo "<th>" . __("Entity") . "</th>"; echo "<th>" . __("Reference") . "</th>"; echo "<th>" . __("Status") . "</th>"; echo "</tr>"; $old_itemtype = ''; $num = 0; while ($data = $DB->fetch_array($result)) { if (!class_exists($data['itemtype'])) { continue; } $item = new $data['itemtype'](); if ($data['itemtype']::canView()) { echo "<tr class='tab_bg_1'>"; $ID = ""; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $name = NOT_AVAILABLE; if ($item->getFromDB($data["id"])) { $name = $item->getLink(); } echo "<td class='center top'>" . $item->getTypeName() . "</td>"; echo "<td class='center top'>"; echo Dropdown::getDropdownName('glpi_entities', $item->getEntityID()) . "</td>"; $reference = new PluginOrderReference(); $reference->getFromDB($data["plugin_order_references_id"]); echo "<td class='center'>"; if (PluginOrderReference::canView()) { echo $reference->getLink(); } else { echo $reference->getName(true); } echo "</td>"; echo "<td class='center'>"; Dropdown::getDropdownName("glpi_plugin_order_deliverystates", $data["plugin_order_deliverystates_id"]); echo "</td>"; echo "</tr>"; } } } echo "</table></div>"; }
static function printPager($start, $numrows, $target, $parameters, $item_type_output = 0, $item_type_output_param = 0) { 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; } // Backward browsing if ($current_start - $list_limit <= 0) { $back = 0; } else { $back = $start - $list_limit; } // Print it echo "<table class='tab_cadre_pager'>\n"; echo "<tr>\n"; // Back and fast backward button if (!$start == 0) { echo "<th class='left'>"; echo "<a href='{$target}?{$parameters}&start=0'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/first.png' alt=\"" . __s('Start') . "\" title=\"" . __s('Start') . "\">"; echo "</a></th>"; echo "<th class='left'>"; echo "<a href='{$target}?{$parameters}&start={$back}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . __s('Previous') . "\" title=\"" . __s('Previous') . "\">"; echo "</a></th>"; } // Print the "where am I?" echo "<td width='50%' class='tab_bg_2'>"; Html::printPagerForm("{$target}?{$parameters}&start={$start}"); echo "</td>\n"; echo "<td width='50%' class='tab_bg_2 b'>"; //TRANS: %1$d, %2$d, %3$d are page numbers printf(__('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'>"; echo "<a href='{$target}?{$parameters}&start={$forward}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/right.png' alt=\"" . __s('Next') . "\" title=\"" . __s('Next') . "\">"; echo "</a></th>\n"; echo "<th class='right'>"; echo "<a href='{$target}?{$parameters}&start={$end}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/last.png' alt=\"" . __s('End') . "\" title=\"" . __s('End') . "\">"; echo "</a></th>\n"; } // End pager echo "</tr>\n"; echo "</table><br>\n"; }