/**
  *
  *
  * @param $items_id integer ID
  *
  * @param $host_id integer associated host ID
  * @param $options array
  *
  *@return bool true if form is ok
  *
  **/
 function showForm($items_id = -1, $options = array())
 {
     global $DB, $CFG_GLPI;
     $host_id = -1;
     if (isset($_GET['host_id'])) {
         $host_id = $_GET['host_id'];
     }
     if ($host_id == -1 && $items_id == -1) {
         return false;
     }
     $createDowntime = false;
     $pmHost = new PluginMonitoringHost();
     if ($host_id != -1) {
         $pmHost->getFromDB($host_id);
         if ($pmHost->isInScheduledDowntime()) {
             // If host already in scheduled downtime, show current downtime ...
             $pmDowntime = new PluginMonitoringDowntime();
             $pmDowntime->getFromDBByQuery("WHERE `" . $pmDowntime->getTable() . "`.`plugin_monitoring_hosts_id` = '" . $host_id . "' LIMIT 1");
             $items_id = $pmDowntime->getID();
             $this->getFromDB($items_id);
         } else {
             // .. else create new downtime
             $createDowntime = true;
             $this->getEmpty();
             $this->setDefaultContent($host_id);
         }
     } else {
         $this->getFromDB($items_id);
     }
     // Now ...
     $nowDate = date('Y-m-d');
     $nowTime = date('H:i:s');
     $this->showFormHeader(array('colspan' => '4'));
     $this->isExpired();
     $pmHost = new PluginMonitoringHost();
     $pmHost->getFromDB($this->fields["plugin_monitoring_hosts_id"]);
     $itemtype = $pmHost->getField("itemtype");
     $item = new $itemtype();
     $item->getFromDB($pmHost->getField("items_id"));
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $item->getTypeName() . "</td>";
     echo "<td>";
     echo "<input type='hidden' name='plugin_monitoring_hosts_id' value='" . $this->fields['plugin_monitoring_hosts_id'] . "' />";
     echo $item->getLink() . "&nbsp;" . $pmHost->getComments();
     echo "</td>";
     echo "<td></td>";
     echo "<td></td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Start time', 'monitoring') . "</td>";
     echo "<td>";
     $date = $this->fields["start_time"];
     Html::showDateTimeField("start_time", array('value' => $date, 'timestep' => 10, 'maybeempty' => false, 'canedit' => $createDowntime, 'mindate' => $nowDate, 'mintime' => $nowTime));
     echo "</td>";
     echo "<td>" . __('Flexible ?', 'monitoring') . "</td>";
     echo "<td>";
     if ($createDowntime) {
         Dropdown::showYesNo('flexible', $this->fields['flexible']);
     } else {
         echo Dropdown::getYesNo($this->fields['flexible']);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('End time', 'monitoring') . "</td>";
     echo "<td>";
     $date = $this->fields["end_time"];
     Html::showDateTimeField("end_time", array('value' => $date, 'timestep' => 10, 'maybeempty' => false, 'canedit' => $createDowntime, 'mindate' => $nowDate, 'mintime' => $nowTime));
     echo "</td>";
     echo "<td>" . __('Duration', 'monitoring') . "</td>";
     echo "<td>";
     if ($createDowntime) {
         Dropdown::showNumber("duration", array('value' => $this->fields['duration'], 'min' => 1, 'max' => 300));
     } else {
         echo $this->fields['duration'];
     }
     $a_duration_type = array();
     $a_duration_type['seconds'] = __('Second(s)', 'monitoring');
     $a_duration_type['minutes'] = __('Minute(s)', 'monitoring');
     $a_duration_type['hours'] = __('Hour(s)', 'monitoring');
     $a_duration_type['days'] = __('Day(s)', 'monitoring');
     if ($createDowntime) {
         Dropdown::showFromArray("duration_type", $a_duration_type, array('value' => $this->fields['duration_type']));
     } else {
         echo "&nbsp;" . $this->fields['duration_type'];
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comment', 'monitoring') . "</td>";
     echo "<td >";
     if ($createDowntime) {
         echo "<textarea cols='80' rows='4' name='comment' >" . $this->fields['comment'] . "</textarea>";
     } else {
         echo "<textarea cols='80' rows='4' name='comment' readonly='1' disabled='1' >" . $this->fields['comment'] . "</textarea>";
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('User', 'monitoring') . "</td>";
     echo "<td>";
     echo "<input type='hidden' name='users_id' value='" . $this->fields['users_id'] . "' />";
     echo $this->getUsername();
     echo "</td>";
     echo "<td>" . __('Expired ?', 'monitoring') . "</td>";
     echo "<td>";
     echo Dropdown::getYesNo($this->fields['expired']);
     echo "</td>";
     echo "</tr>";
     if (Ticket::canView()) {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='4'>&nbsp;</td>";
         echo "</tr>";
         if ($this->isAssociatedTicket()) {
             echo "<tr class='tab_bg_3'>";
             echo "<td colspan='4'>" . __('Downtime associated ticket', 'monitoring') . "</td>";
             echo "</tr>";
             // Find ticket in DB ...
             $track = new Ticket();
             $track->getFromDB($this->getField("tickets_id"));
             // Display ticket id, name and tracking ...
             $bgcolor = $_SESSION["glpipriority_" . $track->fields["priority"]];
             echo "<tr class='tab_bg_2'>";
             echo "<td class='center' bgcolor='{$bgcolor}'>" . sprintf(__('%1$s: %2$s'), __('ID'), $track->fields["id"]) . "</td>";
             echo "<td class='center'>";
             $showprivate = Session::haveRight("show_full_ticket", 1);
             $link = "<a id='ticket" . $track->fields["id"] . "' href='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $track->fields["id"];
             $link .= "'>";
             $link .= "<span class='b'>" . $track->getNameID() . "</span></a>";
             $link = sprintf(__('%1$s (%2$s)'), $link, sprintf(__('%1$s - %2$s'), $track->numberOfFollowups($showprivate), $track->numberOfTasks($showprivate)));
             $link = printf(__('%1$s %2$s'), $link, Html::showToolTip($track->fields['content'], array('applyto' => 'ticket' . $track->fields["id"], 'display' => false)));
             echo "</td>";
             echo "</tr>";
         } else {
             if ($createDowntime && Ticket::canCreate()) {
                 echo "<tr class='tab_bg_3'>";
                 echo "<td colspan='4'>" . __('Associated ticket (no declared category implies no ticket created):', 'monitoring') . "</td>";
                 echo "</tr>";
                 echo "<input type='hidden' name='redirect' value='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php' />";
                 echo "<input type='hidden' name='itemtype' value='" . $pmHost->getField("itemtype") . "' />";
                 echo "<input type='hidden' name='items_id' value='" . $pmHost->getField("items_id") . "' />";
                 echo '<input type="hidden" name="entities_id" value="' . $item->fields['entities_id'] . '" />';
                 $item = new $itemtype();
                 $item->getFromDB($pmHost->getField("items_id"));
                 echo "<input type='hidden' name='locations_id' value='" . $item->getField("locations_id") . "' />";
                 /*
                             // Find SLA ...
                             $sla = new Sla();
                             $slas = current($sla->find("`name` LIKE '%proactive%' LIMIT 1"));
                             $sla_id = isset($slas['id']) ? $slas['id'] : 0;
                 
                             echo "<tr class='tab_bg_3'>";
                             echo "<td>".__('Ticket SLA:', 'monitoring')."</td>";
                             echo "<td colspan='3'>";
                             Sla::dropdown(array('value'  => $sla_id));
                             echo "</td>";
                             echo "</tr>";
                 */
                 // Ticket type ...
                 echo "<tr class='tab_bg_3'>";
                 echo "<td>" . __('Ticket type:', 'monitoring') . "</td>";
                 echo "<td colspan='3'>";
                 Ticket::dropdownType("type", array('value' => Ticket::INCIDENT_TYPE));
                 echo "</td>";
                 echo "</tr>";
                 // Find category ...
                 $category = new ITILCategory();
                 $categories = current($category->find("`name` LIKE '%incident%' LIMIT 1"));
                 $category_id = isset($categories['id']) ? $categories['id'] : 0;
                 /*
                             echo "
                             <script>
                             function changeCategory() {
                                alert(document.getElementById('dropdown_itilcategories_idcategory'));
                                alert($('#dropdown_itilcategories_idcategory').val());
                             }
                             </script>
                             ";
                 */
                 echo "<tr class='tab_bg_3'>";
                 echo "<td>" . __('Ticket category:', 'monitoring') . "</td>";
                 echo "<td colspan='3'>";
                 ITILCategory::dropdown(array('value' => $category_id));
                 /*
                             ITILCategory::dropdown(array(
                                'value'     => $category_id,
                                'rand'      => 'category',
                                'on_change' => 'changeCategory();'
                             ));
                 */
                 echo "</td>";
                 echo "</tr>";
             } else {
                 echo "<tr class='tab_bg_3'>";
                 echo "<td colspan='4'>" . __('No associated ticket for this downtime', 'monitoring') . "</td>";
                 echo "</tr>";
             }
         }
     }
     $this->showFormButtons(array('canedit' => $createDowntime));
     return true;
 }