/**
  * Display form for taskjob
  *
  * @param $items_id integer id of the taskjob
  * @param $options array
  *
  * @return bool TRUE if form is ok
  *
  **/
 function showForm($id, $options = array())
 {
     global $CFG_GLPI;
     $new_item = false;
     if ($id > 0) {
         if ($this->getFromDB($id)) {
             $this->checkConfiguration($id);
             $this->getFromDB($id);
         } else {
             $id = 0;
             $this->getEmpty();
             $this->fields['plugin_fusioninventory_tasks_id'] = $options['task_id'];
             $new_item = true;
         }
     } else {
         if (!array_key_exists('task_id', $options)) {
             echo $this->getMessage(__('A job can not be created outside a task form'), self::MSG_ERROR);
             return;
         }
         $this->getEmpty();
         $this->fields['plugin_fusioninventory_tasks_id'] = $options['task_id'];
         $new_item = true;
     }
     $pfTask = $this->getTask();
     echo "<form method='post' name='form_taskjob' action='" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/front/taskjob.form.php''>";
     if (!$new_item) {
         echo "<input type='hidden' name='id' value='" . $id . "' />";
     }
     echo "<input type='hidden' name='plugin_fusioninventory_tasks_id' " . "value='" . $pfTask->fields['id'] . "' />";
     echo "<table class='tab_cadre_fixe'>";
     // Optional line
     $ismultientities = Session::isMultiEntitiesMode();
     echo '<tr>';
     echo '<th colspan="4">';
     if (!$new_item) {
         echo $this->getTypeName() . " - " . __('ID') . " {$id} ";
         if ($ismultientities) {
             echo "(" . Dropdown::getDropdownName('glpi_entities', $this->fields['entities_id']) . ")";
         }
     } else {
         if ($ismultientities) {
             echo __('New action', 'fusioninventory') . "&nbsp;:&nbsp;" . Dropdown::getDropdownName("glpi_entities", $this->fields['entities_id']);
         } else {
             echo __('New action', 'fusioninventory');
         }
     }
     echo '</th>';
     echo '</tr>';
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='4'>";
     echo "<div class='fusinv_form'>";
     $this->showTextField(__('Name'), "name");
     //echo "<td>".__('Name')."&nbsp;:</td>";
     //echo "<td>";
     ////if ($pfTask->fields["is_advancedmode"] == '0'
     ////        AND $this->fields["name"] == '') {
     ////   $this->fields["name"] = $pfTask->fields["name"];
     ////}
     //Html::autocompletionTextField ($this, "name", $this->fields["name"]);
     /*
      * Display Module dropdown
      */
     //echo "</td>";
     //if ($this->fields['id'] > 0) {
     //   echo "<td>".__('Module', 'fusioninventory')."&nbsp;:</td>";
     //   echo "<td>";
     //   $randmethod = $this->dropdownMethod("method", $this->fields['method']);
     //   echo "<div style='display:none' id='methodupdate' >";
     //   $params = array('method' => '__VALUE__',
     //                   'rand'      => $randmethod,
     //                   'myname'    => 'method',
     //                   'name'      => 'methodupdate',
     //                   'taskjobs_id'=>$id );
     //   Ajax::updateItemOnEvent("dropdown_method".$randmethod,
     //                           "methodupdate",
     //                           $CFG_GLPI["root_doc"].
     //                              "/plugins/fusioninventory/ajax/taskmethodupdate.php",
     //                           $params);
     //   echo "</div>";
     //}
     //echo "</td>";
     //echo "</tr>";
     //echo "<tr class='tab_bg_1'>";
     //echo "<td>".__('Comments')."&nbsp;:</td>";
     //echo "<td>";
     //echo "<textarea cols='40' rows='2' name='comment' >".$this->fields["comment"]."</textarea>";
     //echo "</td>";
     $this->showTextArea(__('Comments'), "comment");
     $modules_methods = PluginFusioninventoryStaticmisc::getModulesMethods();
     $modules_methods_rand = $this->showDropdownFromArray(__('Module method', 'fusioninventory'), "method", $modules_methods);
     if (!$new_item) {
         echo "<script type='text/javascript'>";
         echo "   taskjobs.register_update_method( 'dropdown_method" . $modules_methods_rand . "');";
         echo "</script>";
         echo "<div style='display:none' id='method_selected'>" . $this->fields['method'] . "</div>";
     }
     //if (!$new_item) {
     //   $params = array('method' => '__VALUE__',
     //      'rand'      => $modules_methods_rand,
     //      'myname'    => 'method',
     //      'name'      => 'configuration_form',
     //      'taskjobs_id'=>$id );
     //   Ajax::updateItemOnEvent(
     //      "dropdown_method".$modules_methods_rand,
     //      "methodupdate",
     //      $CFG_GLPI["root_doc"].
     //      "/plugins/fusioninventory/ajax/taskmethodupdate.php",
     //      $params);
     //}
     //if (! $new_item) {
     //   foreach ($module_methods as $method) {
     //      echo
     //         "<input type='hidden' name='method-".$method['method']."' "
     //         ."value='".PluginFusioninventoryModule::getModuleId($method['module'])
     //         ."' />";
     //   }
     //}
     echo "</div>";
     // end of first inputs column wrapper
     // Display Definition choices
     if (!$new_item) {
         //Start second column of the form
         echo "<div class='fusinv_form'>";
         echo "<div class='input_wrap split_column tab_bg_4'>";
         echo $this->getAddItemtypeButton(__('Targets', 'fusioninventory'), 'targets', $this->fields['method']);
         //echo "<br/><span class='description' style='font-size:50%;font-style:italic'>";
         echo "<br/><span class='description'>";
         echo __('The items that should be applied for this job.', 'fusioninventory');
         echo "</span>";
         echo "</div>";
         echo "<div class='input_wrap split_column tab_bg_4'>";
         echo $this->getAddItemtypeButton(__('Actors', 'fusioninventory'), 'actors', $this->fields['method']);
         echo "<br/><span class='description'>";
         echo __('The items that should carry out those targets.', 'fusioninventory');
         echo "</span>";
         echo "</div>";
         echo "<div id='taskjob_moduletypes_dropdown' />";
         echo "<div id='taskjob_moduleitems_dropdown' />";
         echo "</div>";
     }
     $targets_display_list = $this->getItemsList('targets');
     // Display targets and actors lists
     echo implode("\n", array("<hr/>", "<div>", "  <div class='taskjob_list_header'>", "     <label>" . __('Targets', 'fusioninventory') . "&nbsp;:</label>", "  </div>", "  <div id='taskjob_targets_list'>", $targets_display_list, "  </div>", "  <div>", "     <a href='javascript:void(0)'", "        onclick='taskjobs.clear_list(\"targets\")'", "        >" . __('Clear list', 'fusioninventory') . "</a>", "        /", "     <a href='javascript:void(0)'", "        onclick='taskjobs.delete_items_selected(\"targets\")'", "        >" . __('Delete selected items', 'fusioninventory') . "</a>", "  </div>", "</div>"));
     $actors_display_list = $this->getItemsList('actors');
     echo implode("\n", array("<hr/>", "<div>", "  <div class='taskjob_list_header'>", "     <label>" . __('Actors', 'fusioninventory') . "&nbsp;:</label>", "  </div>", "  <div id='taskjob_actors_list'>", $actors_display_list, "  </div>", "  <div>", "     <a href='javascript:void(0)'", "        onclick='taskjobs.clear_list(\"actors\")'", "        >" . __('Clear list', 'fusioninventory') . "</a>", "        /", "     <a href='javascript:void(0)'", "        onclick='taskjobs.delete_items_selected(\"actors\")'", "        >" . __('Delete selected items', 'fusioninventory') . "</a>", "  </div>", "</div>"));
     /*
      * Advanced mode related display (should be dropped)
      */
     //echo "<tr class='tab_bg_1'>";
     //$rowspan = 4;
     //if ($pfTask->fields["is_advancedmode"] == '1') {
     //   echo "<td>";
     //   echo __('Time between task start and start this action', 'fusioninventory')."&nbsp;:";
     //   echo "</td>";
     //   echo "<td>";
     //   Dropdown::showNumber("periodicity_count", array(
     //          'value' => $this->fields['periodicity_count'],
     //          'min'   => 0,
     //          'max'   => 300)
     //   );
     //   $a_time = array();
     //   $a_time[] = "------";
     //   $a_time['minutes'] = strtolower(__('Minute(s)', 'fusioninventory'));
     //   $a_time['hours'] = strtolower(__('hour(s)', 'fusioninventory'));
     //   $a_time['days'] = __('day(s)', 'fusioninventory');
     //   $a_time['months'] = __('months');
     //   Dropdown::showFromArray("periodicity_type",
     //                           $a_time,
     //                           array('value'=>$this->fields['periodicity_type']));
     //   echo "</td>";
     //} else {
     //   if ($this->fields['id'] > 0) {
     //      $pfTaskjoblog->displayShortLogs($this->fields['id']);
     //   } else {
     //      echo "<td colspan='2'></td>";
     //   }
     //   $rowspan = 1;
     //}
     if (!$new_item) {
         // ** Definitions
         //echo "<td rowspan='".$rowspan."' valign='top'>";
         //$this->showTaskjobItems('definition', $modules_methods_rand, $id);
         //echo "</td>";
         // ** Actions
         //echo "<td rowspan='".$rowspan."' valign='top'>";
         //$this->showTaskjobItems('action', $modules_methods_rand, $id);
         //echo "</td>";
         //echo "</tr>";
     }
     //if ($pfTask->fields["is_advancedmode"] == '1') {
     //   echo "<tr class='tab_bg_1'>";
     //   echo "<td>".__('Number of trials', 'fusioninventory')."&nbsp;:</td>";
     //   echo "<td>";
     //   Dropdown::showNumber("retry_nb", array(
     //          'value' => $this->fields['retry_nb'],
     //          'min'   => 0,
     //          'max'   => 30)
     //   );
     //   echo "</td>";
     //   echo "</tr>";
     //   echo "<tr class='tab_bg_1'>";
     //   echo "<td>".__('Time between 2 trials (in minutes)', 'fusioninventory')."&nbsp;:</td>";
     //   echo "<td>";
     //   Dropdown::showNumber("retry_time", array(
     //          'value' => $this->fields['retry_time'],
     //          'min'   => 0,
     //          'max'   => 360)
     // );
     //   echo "</td>";
     //   echo "</tr>";
     //   echo "<tr>";
     //   echo "<td colspan='2'></td>";
     //   echo "</tr>";
     //}
     if ($new_item) {
         echo "<tr>";
         echo "<td colspan='4' valign='top' align='center'>";
         echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
         echo "</td>";
         echo '</tr>';
     } else {
         echo "<tr>";
         echo "<td class='center'>";
         echo "<input type='submit' name='update' value=\"" . __('Update') . "\" class='submit'>";
         echo "</td>";
         echo implode("\n", array("<td class='center' colspan='2'>", "<div id='cancel_job_changes_button' style='display:none'>", "<input type='button' class='submit'", "     onclick='taskjobs.edit(", "        \"" . $this->getBaseUrlFor('fi.job.edit') . "\", ", "        {$id}", "     )'", " value=\"" . __('Cancel modifications', 'fusioninventory') . "\"/>", "</div>", "</td>"));
         echo "<td class='center'>";
         echo "<input type='submit' name='delete' value=\"" . __('Purge', 'fusioninventory') . "\"\n                         class='submit' " . Html::addConfirmationOnAction(__('Confirm the final deletion ?', 'fusioninventory')) . ">";
         echo "</td>";
         echo '</tr>';
     }
     echo "</table>";
     Html::closeForm();
     echo implode("\n", array("<script type='text/javascript'>", "  taskjobs.register_form_changed();", "</script>"));
     echo implode("\n", array("<script language='javascript'>", "  function expandtaskjobform() {", "     document.getElementById('taskjobdisplay').style.overflow='visible';", "     document.getElementById('taskjobdisplay').style.height='auto';", "     document.getElementById('seemore').style.display = 'none';", "  }", "</script>"));
     echo "<br/>";
     //$pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     //$pfTaskjoblog->showHistory($id);
     return TRUE;
 }