function plugin_item_purge_consumables($item) { switch (get_class($item)) { case 'ConsumableItem': $temp = new PluginConsumablesRequest(); $temp->deleteByCriteria(array('consumables_id' => $item->getField('id')), 1); break; } }
/** * Show wizard form of the current step */ function showWizard($step) { echo "<div class='consumables_wizard'>"; switch ($step) { case 'consumablerequest': $consumablerequest = new PluginConsumablesRequest(); $consumablerequest->showConsumableRequest(); break; case 'consumablevalidation': $consumablevalidation = new PluginConsumablesValidation(); $consumablevalidation->showConsumableValidation(); break; } echo "</div>"; }
/** * @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); } } }
break; case 'reloadAvailableConsumables': header("Content-Type: text/html; charset=UTF-8"); $request = new PluginConsumablesRequest(); $request->loadAvailableConsumables($_POST['used'], $_POST['type']); break; case 'reloadAvailableConsumablesNumber': header("Content-Type: text/html; charset=UTF-8"); $request = new PluginConsumablesRequest(); $request->loadAvailableConsumablesNumber($_POST['used'], $_POST['consumables_id']); break; case 'loadConsumableInformation': header("Content-Type: text/html; charset=UTF-8"); $validation = new PluginConsumablesValidation(); $validation->loadConsumableInformation(Session::getLoginUserID(), $_POST['consumables_id']); break; case 'validationConsumables': header('Content-Type: application/json; charset=UTF-8"'); $validation = new PluginConsumablesValidation(); echo json_encode($validation->validationConsumable($_POST)); break; case 'searchConsumables': header('Content-Type: application/json; charset=UTF-8"'); $request = new PluginConsumablesRequest(); echo json_encode($request->listItemsForUser($_POST['requesters_id'], $_POST)); break; case 'loadAvailableConsumablesNumber': $request = new PluginConsumablesRequest(); $request->loadAvailableConsumablesNumber($_POST['consumables_id']); break; }
/** * Show consumable request */ function showConsumableRequest() { global $CFG_GLPI; if (!$this->canView()) { return false; } $request = new PluginConsumablesRequest(); $request->getEmpty(); // Wizard title echo "<form name='wizard_form' id='consumables_wizardForm' method='post'>"; echo "<div class='consumables_wizard_title'><p>"; echo "<img class='consumables_wizard_img' src='" . $CFG_GLPI['root_doc'] . "/plugins/consumables/pics/consumablerequest.png' alt='consumablerequest'/> "; _e("Consumable request", "consumables"); echo "</p></div>"; // Add consumables request echo "<table class='tab_cadre_fixe consumables_wizard_rank'>"; echo "<tr>"; echo "<th colspan='4'>" . __("Consumable request", "consumables") . "</th>"; echo "</tr>"; echo "<tr>"; echo "<td>" . __('Requester') . "</td>"; echo "<td>"; echo getUserName(Session::getLoginUserID()); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . _n('Consumable type', 'Consumable types', 1) . " <span class='red'>*</span></td>"; echo "<td>"; $rand = Dropdown::show("ConsumableItemType", array('entity' => $_SESSION['glpiactive_entity'], 'on_change' => 'loadAvailableConsumables(this);')); $script = "function loadAvailableConsumables(object){this.consumableTypeID = object.value; consumables_reloadAvailableConsumables();}"; echo Html::scriptBlock($script); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . _n('Consumable', 'Consumables', 1) . " <span class='red'>*</span></td>"; echo "<td id='loadAvailableConsumables'>"; $this->loadAvailableConsumables(); echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td>" . __('Number', 'consumables') . " <span class='red'>*</span></td>"; echo "<td id='loadAvailableConsumablesNumber'>"; $this->loadAvailableConsumablesNumber(); echo "</td>"; echo "</tr>"; if (self::canRequestGroup() || self::canRequestUser()) { $itemtypes = array(); if (self::canRequestGroup()) { $itemtypes[] = "Group"; } if (self::canRequestUser()) { $itemtypes[] = "User"; } echo "<tr>"; echo "<td>" . __("Give to") . "</td>"; echo "<td>"; self::showSelectItemFromItemtypes(array('itemtype_name' => 'give_itemtype', 'items_id_name' => 'give_items_id', 'entity_restrict' => $_SESSION['glpiactive_entity'], 'itemtypes' => $itemtypes)); echo "</td>"; echo "</tr>"; } if ($this->canCreate() && $this->canRequest()) { echo "<tr>"; echo "<td class='center' colspan='4'>"; echo "<input type=\"button\" class=\"submit\" name=\"addToCart\" onclick=\"consumables_addToCart('addToCart','consumables_wizardForm', 'consumables_cart');\" value=\"" . __('Add to cart', 'consumables') . "\">"; echo "</td>"; echo "</tr>"; } echo "</table>"; // Cart echo "<br><div class='center'>"; echo "<table class='tab_cadre_fixe consumables_wizard_rank' id='consumables_cart' style='display:none'>"; echo "<tr><th colspan='7'>" . __("Cart", "consumables") . "</th></tr>"; echo "<tr>"; echo "<th>" . __('Requester') . "</th>"; echo "<th>" . _n('Consumable type', 'Consumable types', 1) . "</th>"; echo "<th>" . _n('Consumable', 'Consumables', 1) . "</th>"; echo "<th>" . __('Number', 'consumables') . "</th>"; echo "<th>" . __("Give to") . "</th>"; echo "<th></th>"; echo "</tr>"; echo "</table>"; echo "</div>"; // Footer if ($this->canCreate() && $this->canRequest()) { echo "<br/><table width='100%'>"; echo "<tr>"; echo "<td class='consumables_wizard_button'>"; echo "<div id='dialog-confirm'></div>"; echo "<input type=\"button\" class=\"submit consumable_next_button\" name=\"addConsumables\" value=\"" . _sx('button', 'Post') . "\" onclick=\"consumables_addConsumables('addConsumables','consumables_wizardForm');\">"; echo "<input type=\"button\" class=\"consumable_previous_button submit\" name=\"previous\" value=\"" . _sx('button', 'Cancel') . "\" onclick=\"consumables_cancel('" . $CFG_GLPI['root_doc'] . "/plugins/consumables/front/wizard.php');\">"; echo "</td>"; echo "</tr>"; echo "</table>"; } // Init consumable cart javascript echo "<script type='text/javascript'>"; echo "consumables_initJs('" . $CFG_GLPI['root_doc'] . "', 'dropdown_consumable_itemtypes_id{$rand}');"; echo "</script>"; Html::closeForm(); }