/** * Do the specific massive actions * * @since version 0.84 * * @param $input array of input datas * * @return an array of results (nbok, nbko, nbnoright counts) **/ public function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); $command_item = new PluginShellcommandsShellcommand_Item(); switch ($input['action']) { case "InstallTEST": foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($command_item->addItem($key, $input['item_item'])) { $res['ok']++; } else { $res['ko']++; } } } break; case "Desinstall": foreach ($input["item"] as $key => $val) { if ($val == 1) { if ($command_item->deleteItemByShellCommandsAndItem($key, $input['item_item'])) { $res['ok']++; } else { $res['ko']++; } } } break; default: return parent::doSpecificMassiveActions($input); break; } return $res; }
$command = new PluginShellcommandsShellcommand(); $command_item = new PluginShellcommandsShellcommand_Item(); if (isset($_POST["add"])) { $command->check(-1, UPDATE, $_POST); $newID = $command->add($_POST); Html::back(); } else { if (isset($_POST["update"])) { $command->check($_POST['id'], UPDATE); $command->update($_POST); Html::back(); } else { if (isset($_POST["additem"])) { if (!empty($_POST['itemtype'])) { if ($command->canCreate()) { $command_item->addItem($_POST["plugin_shellcommands_shellcommands_id"], $_POST['itemtype']); } } Html::back(); } else { if (isset($_POST["deleteitem"])) { if ($command->canCreate()) { $command_item->delete(array('id' => $_POST["id"])); } Html::back(); } else { $command->checkGlobal(READ); Html::header(PluginShellcommandsShellcommand::getTypeName(2), '', "tools", "pluginshellcommandsshellcommand", "shellcommand"); $command->display(array('id' => $_GET["id"])); Html::footer(); }
/** * @since version 0.85 * * @see CommonDBTM::processMassiveActionsForOneItemtype() **/ static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids) { global $CFG_GLPI; $command_item = new PluginShellcommandsShellcommand_Item(); switch ($ma->getAction()) { case 'install': $input = $ma->getInput(); foreach ($ids as $key) { if ($command_item->addItem($key, $input['item_item'])) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } break; case 'uninstall': $input = $ma->getInput(); foreach ($ids as $key) { if ($command_item->deleteItemByShellCommandsAndItem($key, $input['item_item'])) { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_OK); } else { $ma->itemDone($item->getType(), $key, MassiveAction::ACTION_KO); } } break; case 'generate': if ($ma->POST['command']) { $_SESSION["plugin_shellcommands"]["massiveaction"] = $ma; $_SESSION["plugin_shellcommands"]["ids"] = $ids; $ma->results['ok'] = 1; $ma->display_progress_bars = false; echo "<script type='text/javascript'>"; echo "location.href='" . $CFG_GLPI['root_doc'] . "/plugins/shellcommands/front/massiveexec.php';"; echo "</script>"; } break; } }