/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { $itemtype = $ma->getItemtype(false); $item = new PluginConsumablesRequest(); $validation = new PluginConsumablesValidation(); $consumable = new Consumable(); $input = $ma->getInput(); if (count($ids)) { switch ($ma->getAction()) { case "validate": foreach ($ids as $key => $val) { if ($item->can($key, UPDATE)) { $item->getFromDB($key); // Get available consumables $outConsumable = array(); $availables = $consumable->find("`consumableitems_id` = '" . $item->fields['consumables_id'] . "' AND `items_id` = 0"); foreach ($availables as $available) { $outConsumable[] = $available; } // Check if enough stock if (!empty($outConsumable) && count($outConsumable) >= $item->fields['number']) { // Give consumable $result = array(1); for ($i = 0; $i < $item->fields['number']; $i++) { if (isset($outConsumable[$i]) && $consumable->out($outConsumable[$i]['id'], $item->fields['give_itemtype'], $item->fields['give_items_id'])) { $result[] = 1; } else { $result[] = 0; } } if (!in_array(0, $result)) { // Validation status update $validation->validationConsumable($item->fields, CommonITILValidation::ACCEPTED); // Send notification NotificationEvent::raiseEvent(PluginConsumablesNotificationTargetRequest::CONSUMABLE_RESPONSE, $item, array('entities_id' => $_SESSION['glpiactive_entity'], 'consumablerequest' => $item->fields, 'comment' => $input['comment'])); $ma->addMessage("<span style='color:green'>" . sprintf(__('Consumable %s validated', 'consumables'), Dropdown::getDropdownName("glpi_consumableitems", $item->fields['consumables_id'])) . "</span>"); $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_KO); } } else { $ma->addMessage(sprintf(__('Not enough stock for consumable %s', 'consumables'), Dropdown::getDropdownName("glpi_consumableitems", $item->fields['consumables_id']))); $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_KO); } } else { $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($validation->getErrorMessage(ERROR_RIGHT)); } } break; case "refuse": foreach ($ids as $key => $val) { if ($item->can($key, UPDATE)) { // Validation status update if ($validation->validationConsumable($item->fields, CommonITILValidation::REFUSED)) { // Send notification NotificationEvent::raiseEvent(PluginConsumablesNotificationTargetRequest::CONSUMABLE_RESPONSE, $item, array('entities_id' => $_SESSION['glpiactive_entity'], 'consumablerequest' => $item->fields, 'comment' => $input['comment'])); $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_OK); $ma->addMessage(__('Consumable refused', 'consumables')); } else { $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_KO); } } else { $ma->itemDone($validation->getType(), $key, MassiveAction::ACTION_NORIGHT); $ma->addMessage($validation->getErrorMessage(ERROR_RIGHT)); } } break; default: return parent::doSpecificMassiveActions($ma->POST); } } }
Event::log($_POST["tID"], "consumables", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][89] . ": " . $_POST["to_add"]); glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_GET["delete"])) { $constype->check($_GET["tID"], 'w'); if ($con->delete($_GET)) { Event::log($_GET["tID"], "consumables", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][91]); } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["give"])) { $constype->check($_POST["tID"], 'w'); if ($_POST["users_id"] > 0) { if (isset($_POST["out"])) { foreach ($_POST["out"] as $key => $val) { $con->out($key, $_POST["users_id"]); } } Event::log($_POST["tID"], "consumables", 5, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][97] . " " . $_POST["users_id"]); } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_GET["restore"])) { $constype->check($_GET["tID"], 'w'); if ($con->restore($_GET)) { Event::log($_GET["tID"], "consumables", 5, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][93]); } glpi_header($_SERVER['HTTP_REFERER']); } else { glpi_header($_SERVER['HTTP_REFERER']); }