/**
  * Show the printer types that are compatible with a cartridge type
  *
  * @param $item   CartridgeItem object
  *
  * @return nothing (display)
  **/
 static function showForCartridgeItem(CartridgeItem $item)
 {
     global $DB, $CFG_GLPI;
     $instID = $item->getField('id');
     if (!$item->can($instID, READ)) {
         return false;
     }
     $canedit = $item->canEdit($instID);
     $rand = mt_rand();
     $query = "SELECT `" . static::getTable() . "`.`id`,\n                       `glpi_printermodels`.`name` AS `type`,\n                       `glpi_printermodels`.`id` AS `pmid`\n                FROM `" . static::getTable() . "`,\n                     `glpi_printermodels`\n                WHERE `" . static::getTable() . "`.`printermodels_id` = `glpi_printermodels`.`id`\n                      AND `" . static::getTable() . "`.`cartridgeitems_id` = '{$instID}'\n                ORDER BY `glpi_printermodels`.`name`";
     $result = $DB->query($query);
     $i = 0;
     $used = array();
     $datas = array();
     if ($number = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $used[$data["pmid"]] = $data["pmid"];
             $datas[$data["id"]] = $data;
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='printermodel_form{$rand}' id='printermodel_form{$rand}' method='post'";
         echo " action='" . static::getFormURL() . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='6'>" . __('Add a compatible printer model') . "</th></tr>";
         echo "<tr><td class='tab_bg_2 center'>";
         echo "<input type='hidden' name='cartridgeitems_id' value='{$instID}'>";
         PrinterModel::dropdown(array('used' => $used));
         echo "</td><td class='tab_bg_2 center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     if ($number) {
         echo "<div class='spaced'>";
         if ($canedit) {
             $rand = mt_rand();
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => count($used), 'container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         $header_begin = "<tr>";
         $header_top = '';
         $header_bottom = '';
         $header_end = '';
         if ($canedit) {
             $header_begin .= "<th width='10'>";
             $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
             $header_end .= "</th>";
         }
         $header_end .= "<th>" . __('Model') . "</th></tr>";
         echo $header_begin . $header_top . $header_end;
         foreach ($datas as $data) {
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td class='center'>" . $data['type'] . "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
         echo "</table>";
         if ($canedit) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
         echo "</div>";
     } else {
         echo "<p class='center b'>" . __('No item found') . "</p>";
     }
 }
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Julien Dombre
// Purpose of file:
// ----------------------------------------------------------------------
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
header_nocache();
if (!isset($_POST["id"])) {
    exit;
}
checkRight("cartridge", "r");
$cartridge = new CartridgeItem();
if ($_POST["id"] > 0 && $cartridge->can($_POST["id"], 'r')) {
    if (!isset($_REQUEST['glpi_tab'])) {
        exit;
    }
    switch ($_REQUEST['glpi_tab']) {
        case -1:
            $cartridge->showCompatiblePrinters();
            Cartridge::showAddForm($cartridge);
            Cartridge::showForCartridgeItem($cartridge);
            Cartridge::showForCartridgeItem($cartridge, 1);
            Infocom::showForItem($cartridge);
            Document::showAssociated($cartridge);
            Link::showForItem('CartridgeItem', $_POST["id"]);
            Plugin::displayAction($cartridge, $_REQUEST['glpi_tab']);
            break;
        case 4:
Esempio n. 3
0
 /**
  * Print out a link to add directly a new cartridge from a cartridge item.
  *
  * @param $cartitem  CartridgeItem object
  *
  * @return Nothing (displays)
  **/
 static function showAddForm(CartridgeItem $cartitem)
 {
     global $CFG_GLPI;
     $ID = $cartitem->getField('id');
     if (!$cartitem->can($ID, UPDATE)) {
         return false;
     }
     if ($ID > 0) {
         echo "<div class='firstbloc'>";
         echo "<form method='post' action=\"" . static::getFormURL() . "\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><td class='center tab_bg_2' width='20%'>";
         echo "<input type='hidden' name='cartridgeitems_id' value='{$ID}'>\n";
         Dropdown::showNumber('to_add', array('value' => 1, 'min' => 1, 'max' => 100));
         echo "</td><td>";
         echo " <input type='submit' name='add' value=\"" . __s('Add cartridges') . "\"\n                class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
 }
 /**
  * Print out a link to add directly a new cartridge from a cartridge item.
  *
  * @param $cartitem object of CartridgeItem class
  *
  * @return Nothing (displays)
  **/
 static function showAddForm(CartridgeItem $cartitem)
 {
     global $CFG_GLPI, $LANG;
     $ID = $cartitem->getField('id');
     if (!$cartitem->can($ID, 'w')) {
         return false;
     }
     if ($ID > 0) {
         echo "<div class='firstbloc'>";
         echo "<form method='post' action=\"" . $CFG_GLPI["root_doc"] . "/front/cartridge.form.php\">";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><td class='center tab_bg_2'>";
         echo "<input type='submit' name='add_several' value=\"" . $LANG['buttons'][8] . "\"\n                class='submit'>";
         echo "<input type='hidden' name='tID' value='{$ID}'>\n";
         echo "<span class='small_space'>";
         Dropdown::showInteger('to_add', 1, 1, 100);
         echo "</span>&nbsp;";
         echo $LANG['cartridges'][16] . "</td></tr>";
         echo "</table></form></div>";
     }
 }