/** * @param $item string ConsumableItem object **/ static function countForConsumableItem(ConsumableItem $item) { return countElementsInTable(array('glpi_consumables'), ['glpi_consumables.consumableitems_id' => $item->getField('id')]); }
/** * @param $item string ConsumableItem object **/ static function countForConsumableItem(ConsumableItem $item) { $restrict = "`glpi_consumables`.`consumableitems_id` = '" . $item->getField('id') . "'"; return countElementsInTable(array('glpi_consumables'), $restrict); }
/** * 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>"; } }