示例#1
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $CFG_GLPI;
     switch ($ma->getAction()) {
         case "uninstall":
             $itemtype = $ma->getItemtype(false);
             foreach ($ids as $id) {
                 if ($item->getFromDB($id)) {
                     //Session::addMessageAfterRedirect(sprintf(__('Form duplicated: %s', 'formcreator'), $item->getName()));
                     $_SESSION['glpi_uninstalllist'][$itemtype][$id] = $id;
                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                 }
             }
             Html::redirect($CFG_GLPI["root_doc"] . '/plugins/uninstall/front/action.php?device_type=' . $itemtype . "&model_id=" . $_POST["model_id"]);
             return;
             break;
     }
     return;
 }
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::showMassiveActionsSubForm()
  **/
 static function showMassiveActionsSubForm(MassiveAction $ma)
 {
     global $CFG_GLPI;
     switch ($ma->getAction()) {
         case 'add_task':
             $itemtype = $ma->getItemtype(true);
             $tasktype = $itemtype . 'Task';
             if ($ttype = getItemForItemtype($tasktype)) {
                 $ttype->showFormMassiveAction();
                 return true;
             }
             return false;
         case 'add_actor':
             $types = array(0 => Dropdown::EMPTY_VALUE, CommonITILActor::REQUESTER => __('Requester'), CommonITILActor::OBSERVER => __('Watcher'), CommonITILActor::ASSIGN => __('Assigned to'));
             $rand = Dropdown::showFromArray('actortype', $types);
             $paramsmassaction = array('actortype' => '__VALUE__');
             Ajax::updateItemOnSelectEvent("dropdown_actortype{$rand}", "show_massiveaction_field", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionAddActor.php", $paramsmassaction);
             echo "<span id='show_massiveaction_field'>&nbsp;</span>\n";
             return true;
         case 'update_notif':
             Dropdown::showYesNo('use_notification');
             echo "<br><br>";
             echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction'));
             return true;
             return true;
     }
     return parent::showMassiveActionsSubForm($ma);
 }
 /**
  * Main entry of the modal window for massive actions
  *
  * @return nothing: display
  **/
 static function showMassiveActionsSubForm(MassiveAction $ma)
 {
     $PluginShellcommandsShellcommand = new PluginShellcommandsShellcommand();
     switch ($ma->getAction()) {
         case 'generate':
             $itemtype = $ma->getItemtype(false);
             if (in_array($itemtype, PluginShellcommandsShellcommand::getTypes(true))) {
                 echo PluginShellcommandsCommandGroup::getTypeName(1) . " ";
                 Dropdown::show('PluginShellcommandsCommandGroup', array('name' => 'commandgroup', 'entity' => $_SESSION['glpiactive_entity'], 'comments' => false));
                 echo "<br><br>";
             }
             break;
     }
     return false;
 }
 /**
  * @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);
         }
     }
 }
 static function showMassiveActionsSubForm(MassiveAction $ma)
 {
     switch ($ma->getAction()) {
         case "install":
             Dropdown::showItemTypes("item_item", self::getTypes(true));
             echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction'));
             return true;
             break;
         case "uninstall":
             Dropdown::showItemTypes("item_item", self::getTypes(true));
             echo Html::submit(_x('button', 'Post'), array('name' => 'massiveaction'));
             return true;
             break;
         case 'generate':
             $PluginShellcommandsShellcommand = new PluginShellcommandsShellcommand();
             $itemtype = $ma->getItemtype(false);
             if (in_array($itemtype, PluginShellcommandsShellcommand::getTypes(true))) {
                 $PluginShellcommandsShellcommand->dropdownCommands($itemtype);
                 echo "<br><br>";
             }
             break;
     }
     return parent::showMassiveActionsSubForm($ma);
 }