/**
  * Show config menu
  */
 function showMenu()
 {
     global $CFG_GLPI;
     if (!$this->canView()) {
         return false;
     }
     echo "<div align='center'>";
     echo "<table class='tab_cadre' cellpadding='5' height='150'>";
     echo "<tr>";
     echo "<th colspan='5'>" . PluginShellcommandsShellcommand::getTypeName(2) . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1' style='background-color:white;'>";
     // Add shell command
     echo "<td class='center shellcommands_menu_item'>";
     echo "<a  class='shellcommands_menu_a' href=\"./shellcommand.php\">";
     echo "<img class='shellcommands_menu_img' src='" . $CFG_GLPI["root_doc"] . "/plugins/shellcommands/pics/shellcommand.png' alt=\"" . PluginShellcommandsShellcommand::getTypeName(2) . "\">";
     echo "<br>" . PluginShellcommandsShellcommand::getTypeName(2) . "</a>";
     echo "</td>";
     // Command group
     echo "<td class='center shellcommands_menu_item'>";
     echo "<a  class='shellcommands_menu_a' href=\"./commandgroup.php\">";
     echo "<img class='shellcommands_menu_img' src='" . $CFG_GLPI["root_doc"] . "/plugins/shellcommands/pics/commandgroup.png' alt=\"" . PluginShellcommandsCommandGroup::getTypeName(2) . "\">";
     echo "<br>" . PluginShellcommandsCommandGroup::getTypeName(2) . "</a>";
     echo "</td>";
     // Advanced execution
     echo "<td class='center shellcommands_menu_item'>";
     echo "<a  class='shellcommands_menu_a' href=\"./advanced_execution.php\">";
     echo "<img class='shellcommands_menu_img' src='" . $CFG_GLPI["root_doc"] . "/plugins/shellcommands/pics/advanced_execution.png' alt=\"" . PluginShellcommandsAdvanced_Execution::getTypeName(2) . "\">";
     echo "<br>" . PluginShellcommandsAdvanced_Execution::getTypeName(2) . "</a>";
     echo "</td>";
     echo "</table></div>";
 }
 /**
  * Show form
  * 
  * @global type $CFG_GLPI
  * @param type $ID
  * @param type $options
  */
 function showForm($ID = 0, $options = array())
 {
     global $CFG_GLPI;
     echo "<div class='center first-bloc'>";
     echo "<form name='field_form' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . self::getTypeName() . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='tab_bg_2 center'>";
     echo PluginShellcommandsCommandGroup::getTypeName(1) . " ";
     Dropdown::show('PluginShellcommandsCommandGroup', array('entity' => $_SESSION['glpiactive_entity'], 'width' => 200));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td class='tab_bg_2 center'>";
     $this->getEditValue();
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='tab_bg_2 center'>";
     echo "<input type='button' class='submit' onclick='shellcommand_advanced_execution(\"" . $CFG_GLPI['root_doc'] . "\",\"field_form\", \"advanced_execution_result\");' name='advanced_execution' value='" . __('Execute') . "'/>";
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
     echo "<div class='spaced' id='advanced_execution_result'></div>";
 }
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Shellcommands. If not, see <http://www.gnu.org/licenses/>.
 --------------------------------------------------------------------------  */
include '../../../inc/includes.php';
if (empty($_GET["id"])) {
    $_GET["id"] = "";
}
$commandgroup = new PluginShellcommandsCommandGroup();
if (isset($_POST["add"])) {
    // Check add rights for fields
    $commandgroup->check(-1, UPDATE, $_POST);
    $commandgroup->add($_POST);
    Html::back();
} elseif (isset($_POST["update"])) {
    // Check update rights for fields
    $commandgroup->check($_POST['id'], UPDATE, $_POST);
    $commandgroup->update($_POST);
    Html::back();
} elseif (isset($_POST["delete"])) {
    // Check delete rights for fields
    $commandgroup->check($_POST['id'], UPDATE, $_POST);
    $commandgroup->delete($_POST, 1);
    $commandgroup->redirectToList();
} else {
    $commandgroup->checkGlobal(READ);
    Html::header(PluginShellcommandsCommandGroup::getTypeName(2), '', "tools", "pluginshellcommandsshellcommand", "commandgroup");
    $commandgroup->display(array('id' => $_GET["id"]));
    Html::footer();
}
 /**
  * Custom fonction to process shellcommand massive action
  **/
 function doMassiveAction(MassiveAction $ma, array $ids)
 {
     if (!empty($ids)) {
         $input = $ma->getInput();
         $itemtype = $ma->getItemType(false);
         $commands_id = $input['commandgroup'];
         switch ($ma->getAction()) {
             case 'generate':
                 echo "<div class='center'>";
                 echo "<table class='tab_cadre_fixe center'>";
                 echo "<tr class='tab_bg_1'>";
                 echo "<th colspan='4'>" . PluginShellcommandsCommandGroup::getTypeName(2) . "</th>";
                 echo "</tr>";
                 foreach ($ids as $key => $items_id) {
                     PluginShellcommandsCommandGroup_Item::lauchCommand(array('itemID' => $items_id, 'itemtype' => $itemtype, 'id' => $commands_id, 'value' => null));
                 }
                 echo "</table>";
                 echo "</div>";
                 break;
         }
     }
 }
 /**
  * Function list items
  * 
  * @global type $CFG_GLPI
  * @param type $ID
  * @param type $data
  * @param type $canedit
  * @param type $rand
  */
 private function listItemsForShellCommand($data, $canedit)
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $numrows = count($data);
     $target = Toolbox::getItemTypeFormURL('PluginShellcommandsCommandGroup_Item');
     echo "<div class='center'>";
     if ($canedit) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('item' => __CLASS__, 'container' => 'mass' . __CLASS__ . $rand, 'num_displayed' => $numrows);
         Html::showMassiveActions($massiveactionparams);
     }
     //      Html::printAjaxPager(self::getTypeName(2), $start, countElementsInTable($this->getTable()));
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10'>";
     if ($canedit) {
         echo Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         Html::closeForm();
     }
     echo "</th>";
     echo "<th colspan='3'>" . PluginShellcommandsCommandGroup::getTypeName(2) . "</th>";
     echo "</tr>";
     $commandgroup = new PluginShellcommandsCommandGroup();
     $i = 0;
     foreach ($data as $field) {
         echo "<tr class='tab_bg_2'>";
         echo "<td width='10'>";
         if ($canedit) {
             Html::showMassiveActionCheckBox(__CLASS__, $field['id']);
         }
         echo "</td>";
         // Command
         $commandgroup->getFromDB($field['plugin_shellcommands_commandgroups_id']);
         echo "<td>" . $commandgroup->getLink() . "</td>";
         echo "</tr>";
         $i++;
     }
     if ($canedit) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</table>";
     echo "</div>";
 }