Exemplo n.º 1
0
 function prepareInputForAdd($input)
 {
     $item = new ConsumableItem();
     if ($item->getFromDB($input["tID"])) {
         return array("consumableitems_id" => $item->fields["id"], "entities_id" => $item->getEntityID(), "date_in" => date("Y-m-d"));
     }
     return array();
 }
Exemplo n.º 2
0
 /**
  * Print out the consumables of a defined type
  *
  * @param $consitem           ConsumableItem object
  * @param $show_old  boolean  show old consumables or not. (default 0)
  *
  * @return Nothing (displays)
  **/
 static function showForConsumableItem(ConsumableItem $consitem, $show_old = 0)
 {
     global $DB, $CFG_GLPI;
     $tID = $consitem->getField('id');
     if (!$consitem->can($tID, READ)) {
         return false;
     }
     if (isset($_GET["start"])) {
         $start = $_GET["start"];
     } else {
         $start = 0;
     }
     $canedit = $consitem->can($tID, UPDATE);
     $rand = mt_rand();
     $where = "";
     if (!$show_old) {
         // NEW
         $where = " AND `date_out` IS NULL\n                  ORDER BY `date_in`, `id`";
     } else {
         //OLD
         $where = " AND `date_out` IS NOT NULL\n                  ORDER BY `date_out` DESC,\n                           `date_in`,\n                           `id`";
     }
     $number = countElementsInTable("glpi_consumables", "`consumableitems_id` = '{$tID}' {$where}");
     $query = "SELECT `glpi_consumables`.*\n                FROM `glpi_consumables`\n                WHERE `consumableitems_id` = '{$tID}'\n                      {$where}\n                LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     echo "<div class='spaced'>";
     // Display the pager
     Html::printAjaxPager(Consumable::getTypeName(Session::getPluralNumber()), $start, $number);
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $actions = array('delete' => _x('button', 'Delete permanently'), 'Infocom' . MassiveAction::CLASS_ACTION_SEPARATOR . 'activate' => __('Enable the financial and administrative information'));
         if ($show_old) {
             $actions['Consumable' . MassiveAction::CLASS_ACTION_SEPARATOR . 'backtostock'] = __('Back to stock');
         } else {
             $actions[__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'give'] = _x('button', 'Give');
         }
         $entparam = array('entities_id' => $consitem->getEntityID());
         if ($consitem->isRecursive()) {
             $entparam = array('entities_id' => getSonsOf('glpi_entities', $consitem->getEntityID()));
         }
         $massiveactionparams = array('num_displayed' => $number, 'specific_actions' => $actions, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => $entparam);
         Html::showMassiveActions($massiveactionparams);
         echo "<input type='hidden' name='consumableitems_id' value='{$tID}'>\n";
     }
     echo "<table class='tab_cadre_fixehov'>";
     if (!$show_old) {
         echo "<tr><th colspan=" . ($canedit ? '5' : '4') . ">";
         echo self::getCount($tID, -1);
         echo "</th></tr>";
     } else {
         // Old
         echo "<tr><th colspan='" . ($canedit ? '7' : '6') . "'>" . __('Used consumables') . "</th></tr>";
     }
     if ($number) {
         $i = 0;
         $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>" . __('ID') . "</th>";
         $header_end .= "<th>" . _x('item', 'State') . "</th>";
         $header_end .= "<th>" . __('Add date') . "</th>";
         if ($show_old) {
             $header_end .= "<th>" . __('Use date') . "</th>";
             $header_end .= "<th>" . __('Given to') . "</th>";
         }
         $header_end .= "<th width='200px'>" . __('Financial and administrative information') . "</th>";
         $header_end .= "</tr>";
         echo $header_begin . $header_top . $header_end;
         while ($data = $DB->fetch_assoc($result)) {
             $date_in = Html::convDate($data["date_in"]);
             $date_out = Html::convDate($data["date_out"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td class='center'>" . $data["id"] . "</td>";
             echo "<td class='center'>" . self::getStatus($data["id"]) . "</td>";
             echo "<td class='center'>" . $date_in . "</td>";
             if ($show_old) {
                 echo "<td class='center'>" . $date_out . "</td>";
                 echo "<td class='center'>";
                 if ($item = getItemForItemtype($data['itemtype'])) {
                     if ($item->getFromDB($data['items_id'])) {
                         echo $item->getLink();
                     }
                 }
                 echo "</td>";
             }
             echo "<td class='center'>";
             Infocom::showDisplayLink('Consumable', $data["id"]);
             echo "</td>";
             echo "</tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
     }
     echo "</table>";
     if ($canedit && $number) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
Exemplo n.º 3
0
 /**
  * Print out the consumables of a defined type
  *
  * @param $consitem           ConsumableItem object
  * @param $show_old  boolean  show old consumables or not. (default 0)
  *
  * @return Nothing (displays)
  **/
 static function showForConsumableItem(ConsumableItem $consitem, $show_old = 0)
 {
     global $DB, $CFG_GLPI;
     $tID = $consitem->getField('id');
     if (!$consitem->can($tID, 'r')) {
         return false;
     }
     $canedit = $consitem->can($tID, 'w');
     $rand = mt_rand();
     $where = "";
     if (!$show_old) {
         // NEW
         $where = " AND `date_out` IS NULL\n                  ORDER BY `date_in`, `id`";
     } else {
         //OLD
         $where = " AND `date_out` IS NOT NULL\n                  ORDER BY `date_out` DESC,\n                           `date_in`,\n                           `id`";
     }
     $query = "SELECT `glpi_consumables`.*\n                FROM `glpi_consumables`\n                WHERE `consumableitems_id` = '{$tID}'\n                      {$where}";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     if ($canedit && $number) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $actions = array('delete' => _x('button', 'Delete permanently'), 'activate_infocoms' => __('Enable the financial and administrative information'));
         if ($show_old) {
             $actions['restore'] = __('Back to stock');
         } else {
             $actions['give'] = _x('button', 'Give');
         }
         $paramsma = array('num_displayed' => $number, 'specific_actions' => $actions, 'extraparams' => array('entities_id' => $consitem->getEntityID()));
         Html::showMassiveActions(__CLASS__, $paramsma);
         echo "<input type='hidden' name='consumableitems_id' value='{$tID}'>\n";
     }
     echo "<div class='spaced'><table class='tab_cadre_fixe'>";
     if (!$show_old) {
         echo "<tr><th colspan=" . ($canedit ? '5' : '4') . ">";
         echo self::getCount($tID, -1);
         echo "</th></tr>";
     } else {
         // Old
         echo "<tr><th colspan='" . ($canedit ? '7' : '6') . "'>" . __('Used consumables') . "</th></tr>";
     }
     if ($number) {
         $i = 0;
         echo "<tr>";
         if ($canedit) {
             echo "<th width='10'>";
             Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
             echo "</th>";
         }
         echo "<th>" . __('ID') . "</th>";
         echo "<th>" . _x('item', 'State') . "</th>";
         echo "<th>" . __('Add date') . "</th>";
         if ($show_old) {
             echo "<th>" . __('Use date') . "</th>";
             echo "<th>" . __('Given to') . "</th>";
         }
         echo "<th width='200px'>" . __('Financial and administrative information') . "</th>";
         echo "</tr>";
     }
     if ($result = $DB->query($query)) {
         $number = $DB->numrows($result);
         while ($data = $DB->fetch_assoc($result)) {
             $date_in = Html::convDate($data["date_in"]);
             $date_out = Html::convDate($data["date_out"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
                 echo "</td>";
             }
             echo "<td class='center'>" . $data["id"] . "</td>";
             echo "<td class='center'>" . self::getStatus($data["id"]) . "</td>";
             echo "<td class='center'>" . $date_in . "</td>";
             if ($show_old) {
                 echo "<td class='center'>" . $date_out . "</td>";
                 echo "<td class='center'>";
                 if ($item = getItemForItemtype($data['itemtype'])) {
                     if ($item->getFromDB($data['items_id'])) {
                         echo $item->getLink();
                     }
                 }
                 echo "</td>";
             }
             echo "<td class='center'>";
             Infocom::showDisplayLink('Consumable', $data["id"], 1);
             echo "</td>";
             echo "</tr>";
         }
     }
     echo "</table>";
     if ($canedit && $number) {
         $paramsma['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $paramsma);
         Html::closeForm();
     }
     echo "</div>";
 }