Пример #1
0
        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;
}
Пример #2
0
 /**
  * @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);
         }
     }
 }