/** * 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>"; }
/** * Print out the consumables of a defined type * *@param $consitem oject of ConsumableItem class *@param $show_old boolean : show old consumables or not. * *@return Nothing (displays) **/ static function showForItem(ConsumableItem $consitem, $show_old = 0) { global $DB, $CFG_GLPI, $LANG; $tID = $consitem->getField('id'); if (!$consitem->can($tID, 'r')) { return false; } $canedit = $consitem->can($tID, 'w'); $query = "SELECT count(*) AS COUNT\n FROM `glpi_consumables`\n WHERE (`consumableitems_id` = '{$tID}')"; if ($result = $DB->query($query)) { if (!$show_old && $canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/consumable.form.php'>"; echo "<input type='hidden' name='tID' value='{$tID}'>\n"; } echo "<div class='spaced'><table class='tab_cadre_fixe'>"; if (!$show_old) { echo "<tr><th colspan='7'>"; echo self::getCount($tID, -1); echo "</th></tr>"; } else { // Old echo "<tr><th colspan='8'>" . $LANG['consumables'][35] . "</th></tr>"; } $i = 0; echo "<tr><th>" . $LANG['common'][2] . "</th><th>" . $LANG['consumables'][23] . "</th>"; echo "<th>" . $LANG['cartridges'][24] . "</th><th>" . $LANG['consumables'][26] . "</th>"; if ($show_old) { echo "<th>" . $LANG['common'][34] . "</th>"; } echo "<th>" . $LANG['financial'][3] . "</th>"; if (!$show_old && $canedit && $DB->result($result, 0, 0) != 0) { echo "<th>"; User::dropdown(array('value' => $consitem->fields["entities_id"], 'right' => 'all')); echo " <input type='submit' class='submit' name='give' value='" . $LANG['consumables'][32] . "'>"; echo "</th>"; } else { echo "<th> </th>"; } if ($canedit) { echo "<th> </th>"; } echo "</tr>"; } $where = ""; $leftjoin = ""; $addselect = ""; 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`"; $leftjoin = " LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `glpi_consumables`.`users_id`) "; $addselect = ", `glpi_users`.`realname` AS REALNAME,\n `glpi_users`.`firstname` AS FIRSTNAME,\n `glpi_users`.`id` AS USERID,\n `glpi_users`.`name` AS USERNAME "; } $query = "SELECT `glpi_consumables`.*\n {$addselect}\n FROM `glpi_consumables`\n {$leftjoin}\n WHERE `consumableitems_id` = '{$tID}'\n {$where}"; if ($result = $DB->query($query)) { $number = $DB->numrows($result); while ($data = $DB->fetch_array($result)) { $date_in = convDate($data["date_in"]); $date_out = convDate($data["date_out"]); echo "<tr class='tab_bg_1'><td class='center'>" . $data["id"] . "</td>"; echo "<td class='center'>" . self::getStatus($data["id"]) . "</td>"; echo "<td class='center'>" . $date_in . "</td>"; echo "<td class='center'>" . $date_out . "</td>"; if ($show_old) { echo "<td class='center'>"; echo formatUserName($data["USERID"], $data["USERNAME"], $data["REALNAME"], $data["FIRSTNAME"]); echo "</td>"; } echo "<td class='center'>"; Infocom::showDisplayLink('Consumable', $data["id"], 1); echo "</td>"; if (!$show_old && $canedit) { echo "<td class='center'>"; echo "<input type='checkbox' name='out[" . $data["id"] . "]'>"; echo "</td>"; } if ($show_old && $canedit) { echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/consumable.form.php?restore=restore&id=" . $data["id"] . "&tID={$tID}'>" . $LANG['consumables'][37] . "</a>"; echo "</td>"; } echo "<td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/consumable.form.php?delete=delete&id=" . $data["id"] . "&tID={$tID}'>" . $LANG['buttons'][6] . "</a>"; echo "</td></tr>"; } } echo "</table></div>"; if (!$show_old && $canedit) { echo "</form>"; } }
/** * 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>"; }
// 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; } if (!isset($_REQUEST['glpi_tab'])) { exit; } checkRight("consumable", "r"); $consumable = new ConsumableItem(); if ($_POST["id"] > 0 && $consumable->can($_POST["id"], 'r')) { switch ($_REQUEST['glpi_tab']) { case -1: Consumable::showAddForm($consumable); Consumable::showForItem($consumable); Consumable::showForItem($consumable, 1); Infocom::showForItem($consumable); Document::showAssociated($consumable); Link::showForItem('ConsumableItem', $_POST["id"]); Plugin::displayAction($consumable, $_REQUEST['glpi_tab']); break; case 4: Infocom::showForItem($consumable); break; case 5: Document::showAssociated($consumable);