Esempio n. 1
0
 /**
  * Print the HTML array of Items on a budget
  *
  *@return Nothing (display)
  **/
 function showItems()
 {
     global $DB, $LANG;
     $budgets_id = $this->fields['id'];
     if (!$this->can($budgets_id, 'r')) {
         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_fixehov'>";
     echo "<tr><th colspan='2'>";
     printPagerForm();
     echo "</th><th colspan='4'>";
     if ($DB->numrows($result) == 0) {
         echo $LANG['document'][13];
     } else {
         echo $LANG['document'][19];
     }
     echo "</th></tr>";
     echo "<tr><th>" . $LANG['common'][17] . "</th>";
     echo "<th>" . $LANG['entity'][0] . "</th>";
     echo "<th>" . $LANG['common'][16] . "</th>";
     echo "<th>" . $LANG['common'][19] . "</th>";
     echo "<th>" . $LANG['common'][20] . "</th>";
     echo "<th>" . $LANG['financial'][21] . "</th>";
     echo "</tr>";
     $num = 0;
     for ($i = 0; $i < $number; $i++) {
         $itemtype = $DB->result($result, $i, "itemtype");
         if (!class_exists($itemtype)) {
             continue;
         }
         $item = new $itemtype();
         if ($item->canView()) {
             switch ($itemtype) {
                 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                            ORDER BY `entities_id`,\n                                     `" . $item->getTable() . "`.`name`";
                     break;
                 case 'Cartridge':
                     $query = "SELECT `" . $item->getTable() . "`.*,\n                                   `glpi_cartridgeitems`.`name`\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` = `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                            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` = `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;
             }
             if ($result_linked = $DB->query($query)) {
                 $nb = $DB->numrows($result_linked);
                 if ($nb > $_SESSION['glpilist_limit']) {
                     echo "<tr class='tab_bg_1'>";
                     echo "<td class='center'>" . $item->getTypeName($nb) . "&nbsp;:&nbsp;{$nb}</td>";
                     echo "<td class='center' colspan='2'>";
                     echo "<a href='" . $item->getSearchURL() . "?" . rawurlencode("contains[0]") . "=" . rawurlencode('$$$$' . $budgets_id) . "&" . rawurlencode("field[0]") . "=50&sort=80&order=ASC&is_deleted=0&start=0" . "'>" . $LANG['reports'][57] . "</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) {
                             $ID = "";
                             if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                                 $ID = " (" . $data["id"] . ")";
                             }
                             $name = NOT_AVAILABLE;
                             if ($item->getFromDB($data["id"])) {
                                 $name = $item->getLink();
                             }
                             echo "<tr class='tab_bg_1'>";
                             if ($prem) {
                                 echo "<td class='center top' rowspan='{$nb}'>" . $item->getTypeName($nb) . ($nb > 1 ? "&nbsp;:&nbsp;{$nb}</td>" : "</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"]) ? "" . formatNumber($data["value"], true) . "" : "-");
                             echo "</td></tr>";
                         }
                     }
                 }
                 $num += $nb;
             }
         }
     }
     if ($num > 0) {
         echo "<tr class='tab_bg_2'><td class='center b'>" . $LANG['common'][33] . "&nbsp;:&nbsp;{$num}</td><td colspan='5'>&nbsp;</td></tr> ";
     }
     echo "</table></div>";
 }
/**
 * Print Ajax pager for list in tab panel
 *
 * @param $title displayed above
 * @param $start from witch item we start
 * @param $numrows total items
 *
 * @return nothing (print a pager)
 **/
function printAjaxPager($title, $start, $numrows)
{
    global $CFG_GLPI, $LANG;
    $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 "<table class='tab_cadre_pager'>";
    if ($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=\"" . $LANG['buttons'][33] . "\" title=\"" . $LANG['buttons'][33] . "\"></a></th>";
        echo "<th class='left'><a href='javascript:reloadTab(\"start={$back}\");'>\n            <img src='" . $CFG_GLPI["root_doc"] . "/pics/left.png' alt=\"" . $LANG['buttons'][12] . "\" title=\"" . $LANG['buttons'][12] . "\"></th>";
    }
    echo "<td width='50%' class='tab_bg_2'>";
    printPagerForm();
    echo "</td>";
    // Print the "where am I?"
    echo "<td width='50%' class='tab_bg_2 b'>";
    echo $LANG['pager'][2] . "&nbsp;" . $current_start . "&nbsp;" . $LANG['pager'][1] . "&nbsp;" . $current_end . "&nbsp;" . $LANG['pager'][3] . "&nbsp;" . $numrows . "&nbsp;";
    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=\"" . $LANG['buttons'][11] . "\" title=\"" . $LANG['buttons'][11] . "\"></a></th>";
        echo "<th class='right'><a href='javascript:reloadTab(\"start={$end}\");'>\n            <img src='" . $CFG_GLPI["root_doc"] . "/pics/last.png' alt=\"" . $LANG['buttons'][32] . "\" title=\"" . $LANG['buttons'][32] . "\"></th>";
    }
    // End pager
    echo "</tr></table>";
}
Esempio n. 3
0
 /**
  * Print the HTML array for infocoms linked
  *
  *@return Nothing (display)
  *
  **/
 function showInfocoms()
 {
     global $DB, $CFG_GLPI, $LANG;
     $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'>";
     printPagerForm();
     echo "</th><th colspan='3'>";
     if ($DB->numrows($result) == 0) {
         echo $LANG['document'][13];
     } else {
         echo $LANG['document'][19];
     }
     echo "</th></tr>";
     echo "<tr><th>" . $LANG['common'][17] . "</th>";
     echo "<th>" . $LANG['entity'][0] . "</th>";
     echo "<th>" . $LANG['common'][16] . "</th>";
     echo "<th>" . $LANG['common'][19] . "</th>";
     echo "<th>" . $LANG['common'][20] . "</th>";
     echo "</tr>";
     $num = 0;
     for ($i = 0; $i < $number; $i++) {
         $itemtype = $DB->result($result, $i, "itemtype");
         if (!class_exists($itemtype)) {
             continue;
         }
         $item = new $itemtype();
         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'>";
                 echo "<td class='center'>" . $item->getTypeName($nb) . "&nbsp;:&nbsp;{$nb}</td>";
                 echo "<td class='center' colspan='2'>";
                 echo "<a href='" . getItemTypeSearchURL($linktype) . "?" . rawurlencode("contains[0]") . "=" . rawurlencode('$$$$' . $instID) . "&" . rawurlencode("field[0]") . "=53&sort=80&order=ASC&is_deleted=0&start=0" . "'>" . $LANG['reports'][57] . "</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) {
                         $ID = "";
                         if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) {
                             $ID = " (" . $data["id"] . ")";
                         }
                         $link = getItemTypeFormURL($linktype);
                         $name = "<a href=\"" . $link . "?id=" . $data[$linkfield] . "\">" . $data["name"] . "{$ID}</a>";
                         echo "<tr class='tab_bg_1'>";
                         if ($prem) {
                             echo "<td class='center top' rowspan='{$nb}'>" . $item->getTypeName($nb) . ($nb > 1 ? "&nbsp;:&nbsp;{$nb}</td>" : "</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 ? $LANG['common'][33] . "&nbsp;=&nbsp;{$num}" : "&nbsp;") . "</td>";
     echo "<td colspan='4'>&nbsp;</td></tr> ";
     echo "</table></div>";
 }