showDateTimeField() статический публичный Метод

Display DateTime form with calendar
static public showDateTimeField ( $name, $options = [] ) : rand
$name name of the element
$options array of possible options: - value : default value to display (default '') - timestep : step for time in minute (-1 use default config) (default -1) - maybeempty : may be empty ? (true by default) - canedit : could not modify element (true by default) - mindate : minimum allowed date (default '') - maxdate : maximum allowed date (default '') - mintime : minimum allowed time (default '') - maxtime : maximum allowed time (default '') - showyear : should we set/diplay the year? (true by default) - display : boolean display or get string (default true) - rand : specific random value (default generated one)
Результат rand value used if displayes else string
 public function displayField($canEdit = true)
 {
     if ($canEdit) {
         $required = $canEdit && $this->fields['required'] ? ' required' : '';
         $rand = mt_rand();
         Html::showDateTimeField('formcreator_field_' . $this->fields['id'], array('value' => $this->getValue(), 'rand' => $rand));
         echo '<script type="text/javascript">
               jQuery(document).ready(function($) {
                  $( "#showdate' . $rand . '" ).on("change", function() {
                     formcreatorChangeValueOf(' . $this->fields['id'] . ', this.value);
                  });
                  $( "#resetdate' . $rand . '" ).on("click", function() {
                     formcreatorChangeValueOf(' . $this->fields['id'] . ', "");
                  });
               });
            </script>';
     } else {
         echo $this->getAnswer();
     }
 }
Пример #2
0
 /** form for Task
  *
  * @param $ID        Integer : Id of the task
  * @param $options   array
  *     -  parent Object : the object
  **/
 function showForm($ID, $options = array())
 {
     global $DB, $CFG_GLPI;
     if (isset($options['parent']) && !empty($options['parent'])) {
         $item = $options['parent'];
     }
     $fkfield = $item->getForeignKeyField();
     if ($ID > 0) {
         $this->check($ID, READ);
     } else {
         // Create item
         $options[$fkfield] = $item->getField('id');
         $this->check(-1, CREATE, $options);
     }
     $rand = mt_rand();
     $this->showFormHeader($options);
     $canplan = !$item->isStatusExists(CommonITILObject::PLANNED) || $item->isAllowedStatus($item->fields['status'], CommonITILObject::PLANNED);
     $rowspan = 3;
     if ($this->maybePrivate()) {
         $rowspan++;
     }
     if (isset($this->fields["state"])) {
         $rowspan++;
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td rowspan='{$rowspan}' class='middle'>" . __('Description') . "</td>";
     echo "<td class='center middle' rowspan='{$rowspan}'>" . "<textarea id ='content{$rand}' name='content' cols='50' rows='{$rowspan}'>" . $this->fields["content"] . "</textarea>";
     echo Html::scriptBlock("\$(document).ready(function() { \$('#content{$rand}').autogrow(); });");
     echo "</td>";
     if ($ID > 0) {
         echo "<td>" . __('Date') . "</td>";
         echo "<td>";
         Html::showDateTimeField("date", array('value' => $this->fields["date"], 'timestep' => 1, 'maybeempty' => false));
     } else {
         echo "<td colspan='2'>&nbsp;";
     }
     echo "<input type='hidden' name='{$fkfield}' value='" . $this->fields[$fkfield] . "'>";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Category') . "</td><td>";
     TaskCategory::dropdown(array('value' => $this->fields["taskcategories_id"], 'entity' => $item->fields["entities_id"]));
     echo "</td></tr>\n";
     if (isset($this->fields["state"])) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Status') . "</td><td>";
         Planning::dropdownState("state", $this->fields["state"]);
         echo "</td></tr>\n";
     }
     if ($this->maybePrivate()) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Private') . "</td>";
         echo "<td>";
         Dropdown::showYesNo('is_private', $this->fields["is_private"]);
         echo "</td>";
         echo "</tr>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Duration') . "</td><td>";
     $toadd = array();
     for ($i = 9; $i <= 100; $i++) {
         $toadd[] = $i * HOUR_TIMESTAMP;
     }
     Dropdown::showTimeStamp("actiontime", array('min' => 0, 'max' => 8 * HOUR_TIMESTAMP, 'value' => $this->fields["actiontime"], 'addfirstminutes' => true, 'inhours' => true, 'toadd' => $toadd));
     echo "</td></tr>\n";
     Document_Item::showSimpleAddForItem($item);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('By');
     echo " <a href='#' onClick=\"" . Html::jsGetElementbyID('planningcheck' . $rand) . ".dialog('open');\">";
     echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png'\n             title=\"" . __s('Availability') . "\" alt=\"" . __s('Availability') . "\"\n             class='calendrier'>";
     echo "</a>";
     Ajax::createIframeModalWindow('planningcheck' . $rand, $CFG_GLPI["root_doc"] . "/front/planning.php?checkavailability=checkavailability" . "&itemtype=" . $item->getType() . "&{$fkfield}=" . $item->getID(), array('title' => __('Availability')));
     echo "</td>";
     echo "<td class='center'>";
     $rand_user = mt_rand();
     $params = array('name' => "users_id_tech", 'value' => $this->fields["users_id_tech"] ? $this->fields["users_id_tech"] : Session::getLoginUserID(), 'right' => "own_ticket", 'rand' => $rand_user, 'entity' => $item->fields["entities_id"]);
     $params['toupdate'] = array('value_fieldname' => 'users_id', 'to_update' => "user_available{$rand_user}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/planningcheck.php");
     User::dropdown($params);
     echo "</td>\n";
     if ($canplan) {
         echo "<td>" . __('Planning') . "</td>";
     }
     echo "<td>";
     if (!empty($this->fields["begin"])) {
         if (Session::haveRight('planning', Planning::READMY)) {
             echo "<script type='text/javascript' >\n";
             echo "function showPlan" . $ID . "() {\n";
             echo Html::jsHide('plan');
             $params = array('form' => 'followups', 'users_id' => $this->fields["users_id_tech"], 'id' => $this->fields["id"], 'begin' => $this->fields["begin"], 'end' => $this->fields["end"], 'rand_user' => $rand_user, 'entity' => $item->fields["entities_id"], 'itemtype' => $this->getType(), 'items_id' => $this->getID());
             Ajax::updateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params);
             echo "}";
             echo "</script>\n";
             echo "<div id='plan' onClick='showPlan" . $ID . "()'>\n";
             echo "<span class='showplan'>";
         }
         if (isset($this->fields["state"])) {
             echo Planning::getState($this->fields["state"]) . "<br>";
         }
         printf(__('From %1$s to %2$s'), Html::convDateTime($this->fields["begin"]), Html::convDateTime($this->fields["end"]));
         echo "<br>" . getUserName($this->fields["users_id_tech"]);
         if (Session::haveRight('planning', Planning::READMY)) {
             echo "</span>";
             echo "</div>\n";
             echo "<div id='viewplan'></div>\n";
         }
     } else {
         if ($canplan) {
             echo "<script type='text/javascript' >\n";
             echo "function showPlanUpdate() {\n";
             echo Html::jsHide('plan');
             $params = array('form' => 'followups', 'entity' => $_SESSION["glpiactive_entity"], 'rand_user' => $rand_user, 'itemtype' => $this->getType(), 'items_id' => $this->getID());
             Ajax::updateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params);
             echo "};";
             echo "</script>";
             if ($canplan) {
                 echo "<div id='plan'  onClick='showPlanUpdate()'>\n";
                 echo "<span class='vsubmit'>" . __('Plan this task') . "</span>";
                 echo "</div>\n";
                 echo "<div id='viewplan'></div>\n";
             }
         } else {
             _e('None');
         }
     }
     echo "</td></tr>";
     if (!empty($this->fields["begin"]) && PlanningRecall::isAvailable()) {
         echo "<tr class='tab_bg_1'><td>" . _x('Planning', 'Reminder') . "</td><td class='center'>";
         PlanningRecall::dropdown(array('itemtype' => $this->getType(), 'items_id' => $this->getID()));
         echo "</td></tr>";
     }
     $this->showFormButtons($options);
     return true;
 }
Пример #3
0
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $DB;
     if (!static::canView()) {
         return false;
     }
     // In percent
     $colsize1 = '13';
     $colsize2 = '37';
     $default_use_notif = Entity::getUsedConfig('is_notif_enable_default', $_SESSION['glpiactive_entity'], '', 1);
     // Set default options
     if (!$ID) {
         $values = array('_users_id_requester' => Session::getLoginUserID(), '_users_id_requester_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_requester' => 0, '_users_id_assign' => 0, '_users_id_assign_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_assign' => 0, '_users_id_observer' => 0, '_users_id_observer_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_suppliers_id_assign_notif' => array('use_notification' => $default_use_notif, 'alternative_email' => ''), '_groups_id_observer' => 0, '_suppliers_id_assign' => 0, 'priority' => 3, 'urgency' => 3, 'impact' => 3, 'content' => '', 'entities_id' => $_SESSION['glpiactive_entity'], 'name' => '', 'itilcategories_id' => 0);
         foreach ($values as $key => $val) {
             if (!isset($options[$key])) {
                 $options[$key] = $val;
             }
         }
         if (isset($options['tickets_id'])) {
             $ticket = new Ticket();
             if ($ticket->getFromDB($options['tickets_id'])) {
                 $options['content'] = $ticket->getField('content');
                 $options['name'] = $ticket->getField('name');
                 $options['impact'] = $ticket->getField('impact');
                 $options['urgency'] = $ticket->getField('urgency');
                 $options['priority'] = $ticket->getField('priority');
                 $options['itilcategories_id'] = $ticket->getField('itilcategories_id');
                 $options['due_date'] = $ticket->getField('due_date');
             }
         }
         if (isset($options['problems_id'])) {
             $problem = new Problem();
             if ($problem->getFromDB($options['problems_id'])) {
                 $options['content'] = $problem->getField('content');
                 $options['name'] = $problem->getField('name');
                 $options['impact'] = $problem->getField('impact');
                 $options['urgency'] = $problem->getField('urgency');
                 $options['priority'] = $problem->getField('priority');
                 $options['itilcategories_id'] = $problem->getField('itilcategories_id');
                 $options['due_date'] = $problem->getField('due_date');
             }
         }
     }
     if ($ID > 0) {
         $this->check($ID, READ);
     } else {
         // Create item
         $this->check(-1, CREATE, $options);
     }
     $showuserlink = 0;
     if (User::canView()) {
         $showuserlink = 1;
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<th class='left' width='{$colsize1}%'>" . __('Opening date') . "</th>";
     echo "<td class='left' width='{$colsize2}%'>";
     if (isset($options['tickets_id'])) {
         echo "<input type='hidden' name='_tickets_id' value='" . $options['tickets_id'] . "'>";
     }
     if (isset($options['problems_id'])) {
         echo "<input type='hidden' name='_problems_id' value='" . $options['problems_id'] . "'>";
     }
     $date = $this->fields["date"];
     if (!$ID) {
         $date = date("Y-m-d H:i:s");
     }
     Html::showDateTimeField("date", array('value' => $date, 'timestep' => 1, 'maybeempty' => false));
     echo "</td>";
     echo "<th width='{$colsize1}%'>" . __('Due date') . "</th>";
     echo "<td width='{$colsize2}%' class='left'>";
     if ($this->fields["due_date"] == 'NULL') {
         $this->fields["due_date"] = '';
     }
     Html::showDateTimeField("due_date", array('value' => $this->fields["due_date"], 'timestep' => 1));
     echo "</td></tr>";
     if ($ID) {
         echo "<tr class='tab_bg_1'><th>" . __('By') . "</th><td>";
         User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
         echo "</td>";
         echo "<th>" . __('Last update') . "</th>";
         echo "<td>" . Html::convDateTime($this->fields["date_mod"]) . "\n";
         if ($this->fields['users_id_lastupdater'] > 0) {
             printf(__('%1$s: %2$s'), __('By'), getUserName($this->fields["users_id_lastupdater"], $showuserlink));
         }
         echo "</td></tr>";
     }
     if ($ID && (in_array($this->fields["status"], $this->getSolvedStatusArray()) || in_array($this->fields["status"], $this->getClosedStatusArray()))) {
         echo "<tr class='tab_bg_1'>";
         echo "<th>" . __('Date of solving') . "</th>";
         echo "<td>";
         Html::showDateTimeField("solvedate", array('value' => $this->fields["solvedate"], 'timestep' => 1, 'maybeempty' => false));
         echo "</td>";
         if (in_array($this->fields["status"], $this->getClosedStatusArray())) {
             echo "<th>" . __('Closing date') . "</th>";
             echo "<td>";
             Html::showDateTimeField("closedate", array('value' => $this->fields["closedate"], 'timestep' => 1, 'maybeempty' => false));
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
         echo "</tr>";
     }
     echo "</table>";
     echo "<table class='tab_cadre_fixe' id='mainformtable2'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . __('Status') . "</th>";
     echo "<td width='{$colsize2}%'>";
     self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed'));
     ChangeValidation::alertValidation($this, 'status');
     echo "</td>";
     echo "<th width='{$colsize1}%'>" . __('Urgency') . "</th>";
     echo "<td width='{$colsize2}%'>";
     // Only change during creation OR when allowed to change priority OR when user is the creator
     $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Category') . "</th>";
     echo "<td >";
     $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_change`='1'");
     ITILCategory::dropdown($opt);
     echo "</td>";
     echo "<th>" . __('Impact') . "</th>";
     echo "<td>";
     $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"]));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Total duration') . "</th>";
     echo "<td>" . parent::getActionTime($this->fields["actiontime"]) . "</td>";
     echo "<th class='left'>" . __('Priority') . "</th>";
     echo "<td>";
     $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true));
     $idajax = 'change_priority_' . mt_rand();
     echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => 'dropdown_priority' . $idpriority);
     Ajax::updateItemOnSelectEvent(array('dropdown_urgency' . $idurgency, 'dropdown_impact' . $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
     echo "</td>";
     echo "</tr>";
     echo "</table>";
     $this->showActorsPartForm($ID, $options);
     echo "<table class='tab_cadre_fixe' id='mainformtable3'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . __('Title') . "</th>";
     echo "<td colspan='3'>";
     echo "<input type='text' size='90' maxlength=250 name='name' " . " value=\"" . Html::cleanInputText($this->fields["name"]) . "\">";
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Description') . "</th>";
     echo "<td colspan='3'>";
     $rand = mt_rand();
     echo "<textarea id='content{$rand}' name='content' cols='90' rows='6'>" . Html::clean(Html::entity_decode_deep($this->fields["content"])) . "</textarea>";
     echo "</td>";
     echo "</tr>";
     $options['colspan'] = 3;
     $this->showFormButtons($options);
     return true;
 }
Пример #4
0
 function displayAnswers($questions_id)
 {
     $psQuestion = new PluginSurveyticketQuestion();
     $psAnswer = new PluginSurveyticketAnswer();
     $a_answers = $psAnswer->find("`plugin_surveyticket_questions_id`='" . $questions_id . "'");
     $psQuestion->getFromDB($questions_id);
     switch ($psQuestion->fields['type']) {
         case 'dropdown':
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='2' align='center'>";
             echo "<select name='question" . $questions_id . "' id='question" . $questions_id . "' >";
             echo "<option>" . Dropdown::EMPTY_VALUE . "</option>";
             foreach ($a_answers as $data_answer) {
                 echo "<option value='" . $data_answer['id'] . "'>" . $psAnswer->getAnswer($data_answer) . "</option>";
             }
             echo "</select>";
             echo "</td>";
             echo "</tr>";
             break;
         case 'checkbox':
             $i = 0;
             foreach ($a_answers as $data_answer) {
                 echo "<tr class='tab_bg_1'>";
                 echo "<td width='40' align='center'>";
                 echo "<input type='checkbox' name='question" . $questions_id . "[]' id='question" . $questions_id . "-" . $i . "' \n                  value='" . $data_answer['id'] . "' />";
                 echo "</td>";
                 echo "<td>";
                 echo $psAnswer->getAnswer($data_answer);
                 echo "</td>";
                 $this->displayAnswertype($data_answer['answertype'], "text-" . $questions_id . "-" . $data_answer['id']);
                 echo "</tr>";
                 $i++;
             }
             break;
         case 'radio':
         case 'yesno':
             $i = 0;
             foreach ($a_answers as $data_answer) {
                 echo "<tr class='tab_bg_1'>";
                 echo "<td width='40' align='center'>";
                 echo "<input type='radio' name='question" . $questions_id . "' id='question" . $questions_id . "-" . $i . "' \n                  value='" . $data_answer['id'] . "' />";
                 echo "</td>";
                 echo "<td>";
                 echo $psAnswer->getAnswer($data_answer);
                 echo "</td>";
                 $this->displayAnswertype($data_answer['answertype'], "text-" . $questions_id . "-" . $data_answer['id']);
                 echo "</tr>";
                 $i++;
             }
             break;
         case 'date':
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='2' align='center'>";
             $data_answer = current($a_answers);
             Html::showDateTimeField("question" . $questions_id, array('rand' => "question" . $questions_id));
             echo '<input type="hidden" name="realquestion' . $questions_id . '" id="realquestion' . $questions_id . '" value="' . $data_answer['id'] . '" />';
             echo "</td>";
             echo "</tr>";
             break;
         case 'input':
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='2' align='center'>";
             $data_answer = current($a_answers);
             echo '<input type="text" name="question' . $questions_id . '" id="question' . $questions_id . '" value="" size="71" />';
             echo '<input type="hidden" name="realquestion' . $questions_id . '" id="realquestion' . $questions_id . '" value="' . $data_answer['id'] . '" />';
             echo "</td>";
             echo "</tr>";
             break;
     }
     return count($a_answers);
 }
Пример #5
0
 function showForm($ID, $options = array())
 {
     global $DB, $CFG_GLPI;
     $default_values = self::getDefaultValues();
     // Get default values from posted values on reload form
     // On get because of tabs
     // we use REQUEST because method differ with layout (lefttab : GET, vsplit: POST)
     if (!isset($options['template_preview'])) {
         if (isset($_REQUEST)) {
             $values = Html::cleanPostForTextArea($_REQUEST);
         }
     }
     // Restore saved value or override with page parameter
     $saved = $this->restoreInput();
     foreach ($default_values as $name => $value) {
         if (!isset($values[$name])) {
             if (isset($saved[$name])) {
                 $values[$name] = $saved[$name];
             } else {
                 $values[$name] = $value;
             }
         }
     }
     if (isset($values['content'])) {
         // Clean new lines to be fix encoding
         $order = array('\\r', '\\n', "\\");
         $replace = array("", "", "");
         $values['content'] = str_replace($order, $replace, $values['content']);
     }
     if (isset($values['name'])) {
         $values['name'] = str_replace("\\", "", $values['name']);
     }
     if (!$ID) {
         // Override defaut values from projecttask if needed
         if (isset($options['_projecttasks_id'])) {
             $pt = new ProjectTask();
             if ($pt->getFromDB($options['_projecttasks_id'])) {
                 $values['name'] = $pt->getField('name');
                 $values['content'] = $pt->getField('name');
             }
         }
     }
     // Check category / type validity
     if ($values['itilcategories_id']) {
         $cat = new ITILCategory();
         if ($cat->getFromDB($values['itilcategories_id'])) {
             switch ($values['type']) {
                 case self::INCIDENT_TYPE:
                     if (!$cat->getField('is_incident')) {
                         $values['itilcategories_id'] = 0;
                     }
                     break;
                 case self::DEMAND_TYPE:
                     if (!$cat->getField('is_request')) {
                         $values['itilcategories_id'] = 0;
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     // Default check
     if ($ID > 0) {
         $this->check($ID, READ);
     } else {
         // Create item
         $this->check(-1, CREATE, $values);
     }
     if (!$ID) {
         $this->userentities = array();
         if ($values["_users_id_requester"]) {
             //Get all the user's entities
             $all_entities = Profile_User::getUserEntities($values["_users_id_requester"], true, true);
             //For each user's entity, check if the technician which creates the ticket have access to it
             foreach ($all_entities as $tmp => $ID_entity) {
                 if (Session::haveAccessToEntity($ID_entity)) {
                     $this->userentities[] = $ID_entity;
                 }
             }
         }
         $this->countentitiesforuser = count($this->userentities);
         if ($this->countentitiesforuser > 0 && !in_array($this->fields["entities_id"], $this->userentities)) {
             // If entity is not in the list of user's entities,
             // then use as default value the first value of the user's entites list
             $this->fields["entities_id"] = $this->userentities[0];
             // Pass to values
             $values['entities_id'] = $this->userentities[0];
         }
     }
     if ($values['type'] <= 0) {
         $values['type'] = Entity::getUsedConfig('tickettype', $values['entities_id'], '', Ticket::INCIDENT_TYPE);
     }
     if (!isset($options['template_preview'])) {
         $options['template_preview'] = 0;
     }
     // Load ticket template if available :
     if ($ID) {
         $tt = $this->getTicketTemplateToUse($options['template_preview'], $this->fields['type'], $this->fields['itilcategories_id'], $this->fields['entities_id']);
     } else {
         $tt = $this->getTicketTemplateToUse($options['template_preview'], $values['type'], $values['itilcategories_id'], $values['entities_id']);
     }
     // Predefined fields from template : reset them
     if (isset($values['_predefined_fields'])) {
         $values['_predefined_fields'] = Toolbox::decodeArrayFromInput($values['_predefined_fields']);
     } else {
         $values['_predefined_fields'] = array();
     }
     // Store predefined fields to be able not to take into account on change template
     // Only manage predefined values on ticket creation
     $predefined_fields = array();
     if (!$ID) {
         if (isset($tt->predefined) && count($tt->predefined)) {
             foreach ($tt->predefined as $predeffield => $predefvalue) {
                 if (isset($default_values[$predeffield])) {
                     // Is always default value : not set
                     // Set if already predefined field
                     // Set if ticket template change
                     if (count($values['_predefined_fields']) == 0 && $values[$predeffield] == $default_values[$predeffield] || isset($values['_predefined_fields'][$predeffield]) && $values[$predeffield] == $values['_predefined_fields'][$predeffield] || isset($values['_tickettemplates_id']) && $values['_tickettemplates_id'] != $tt->getID() || $predeffield == 'requesttypes_id' && empty($saved)) {
                         // Load template data
                         $values[$predeffield] = $predefvalue;
                         $this->fields[$predeffield] = $predefvalue;
                         $predefined_fields[$predeffield] = $predefvalue;
                     }
                 }
             }
             // All predefined override : add option to say predifined exists
             if (count($predefined_fields) == 0) {
                 $predefined_fields['_all_predefined_override'] = 1;
             }
         } else {
             // No template load : reset predefined values
             if (count($values['_predefined_fields'])) {
                 foreach ($values['_predefined_fields'] as $predeffield => $predefvalue) {
                     if ($values[$predeffield] == $predefvalue) {
                         $values[$predeffield] = $default_values[$predeffield];
                     }
                 }
             }
         }
     }
     // Put ticket template on $values for actors
     $values['_tickettemplate'] = $tt;
     $canupdate = Session::haveRight(self::$rightname, UPDATE);
     $canpriority = Session::haveRight(self::$rightname, self::CHANGEPRIORITY);
     $canstatus = $canupdate;
     if ($ID && in_array($this->fields['status'], $this->getClosedStatusArray())) {
         $canupdate = false;
         // No update for actors
         $values['_noupdate'] = true;
     }
     $showuserlink = 0;
     if (Session::haveRight('user', READ)) {
         $showuserlink = 1;
     }
     if ($options['template_preview']) {
         // Add all values to fields of tickets for template preview
         foreach ($values as $key => $val) {
             if (!isset($this->fields[$key])) {
                 $this->fields[$key] = $val;
             }
         }
     }
     // In percent
     $colsize1 = '13';
     $colsize2 = '29';
     $colsize3 = '13';
     $colsize4 = '45';
     $canupdate_descr = $canupdate || $this->fields['status'] == self::INCOMING && $this->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID()) && $this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0;
     if (!$options['template_preview']) {
         echo "<form method='post' name='form_ticket' enctype='multipart/form-data' action='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'>";
         if (isset($options['_projecttasks_id'])) {
             echo "<input type='hidden' name='_projecttasks_id' value='" . $options['_projecttasks_id'] . "'>";
         }
     }
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe' id='mainformtable'>";
     // Optional line
     $ismultientities = Session::isMultiEntitiesMode();
     echo "<tr class='headerRow responsive_hidden'>";
     echo "<th colspan='4'>";
     if ($ID) {
         $text = sprintf(__('%1$s - %2$s'), $this->getTypeName(1), sprintf(__('%1$s: %2$s'), __('ID'), $ID));
         if ($ismultientities) {
             $text = sprintf(__('%1$s (%2$s)'), $text, Dropdown::getDropdownName('glpi_entities', $this->fields['entities_id']));
         }
         echo $text;
     } else {
         if ($ismultientities) {
             printf(__('The ticket will be added in the entity %s'), Dropdown::getDropdownName("glpi_entities", $this->fields['entities_id']));
         } else {
             _e('New ticket');
         }
     }
     echo "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>";
     echo $tt->getBeginHiddenFieldText('date');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Opening date'), $tt->getMandatoryMark('date'));
     } else {
         _e('Opening date');
     }
     echo $tt->getEndHiddenFieldText('date');
     echo "</th>";
     echo "<td width='{$colsize2}%'>";
     echo $tt->getBeginHiddenFieldValue('date');
     $date = $this->fields["date"];
     if ($canupdate) {
         Html::showDateTimeField("date", array('value' => $date, 'timestep' => 1, 'maybeempty' => false));
     } else {
         echo Html::convDateTime($date);
     }
     echo $tt->getEndHiddenFieldValue('date', $this);
     echo "</td><td colspan='2'></td></tr>";
     // SLTs
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('time_to_own');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Time to own'), $tt->getMandatoryMark('time_to_own'));
     } else {
         _e('Time to own');
     }
     echo $tt->getEndHiddenFieldText('time_to_own');
     echo "</th>";
     echo "<td width='{$colsize2}%' class='nopadding'>";
     $slt = new SLT();
     $slt->showSltForTicket($this, SLT::TTO, $tt, $canupdate);
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('due_date');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Time to resolve'), $tt->getMandatoryMark('due_date'));
     } else {
         _e('Time to resolve');
     }
     echo $tt->getEndHiddenFieldText('due_date');
     echo "</th>";
     echo "<td width='{$colsize4}%' class='nopadding'>";
     $slt->showSltForTicket($this, SLT::TTR, $tt, $canupdate);
     echo "</td>";
     echo "</tr>";
     if ($ID) {
         echo "<tr class='tab_bg_1'>";
         echo "<th width='{$colsize1}%'>" . __('By') . "</th>";
         echo "<td width='{$colsize2}%'>";
         if ($canupdate) {
             User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
         } else {
             echo getUserName($this->fields["users_id_recipient"], $showuserlink);
         }
         echo "</td>";
         echo "<th width='{$colsize3}%'>" . __('Last update') . "</th>";
         echo "<td width='{$colsize4}%'>";
         if ($this->fields['users_id_lastupdater'] > 0) {
             //TRANS: %1$s is the update date, %2$s is the last updater name
             printf(__('%1$s by %2$s'), Html::convDateTime($this->fields["date_mod"]), getUserName($this->fields["users_id_lastupdater"], $showuserlink));
         }
         echo "</td>";
         echo "</tr>";
     }
     if ($ID && (in_array($this->fields["status"], $this->getSolvedStatusArray()) || in_array($this->fields["status"], $this->getClosedStatusArray()))) {
         echo "<tr class='tab_bg_1'>";
         echo "<th width='{$colsize1}%'>" . __('Resolution date') . "</th>";
         echo "<td width='{$colsize2}%'>";
         Html::showDateTimeField("solvedate", array('value' => $this->fields["solvedate"], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate));
         echo "</td>";
         if (in_array($this->fields["status"], $this->getClosedStatusArray())) {
             echo "<th width='{$colsize3}%'>" . __('Close date') . "</th>";
             echo "<td width='{$colsize4}%'>";
             Html::showDateTimeField("closedate", array('value' => $this->fields["closedate"], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate));
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
         echo "</tr>";
     }
     if ($ID) {
         echo "</table>";
         echo "<table  class='tab_cadre_fixe' id='mainformtable2'>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</th>";
     echo "<td width='{$colsize2}%'>";
     // Permit to set type when creating ticket without update right
     if ($canupdate || !$ID) {
         $opt = array('value' => $this->fields["type"]);
         /// Auto submit to load template
         if (!$ID) {
             $opt['on_change'] = 'this.form.submit()';
         }
         $rand = self::dropdownType('type', $opt);
         if ($ID) {
             $params = array('type' => '__VALUE__', 'entity_restrict' => $this->fields['entities_id'], 'value' => $this->fields['itilcategories_id'], 'currenttype' => $this->fields['type']);
             Ajax::updateItemOnSelectEvent("dropdown_type{$rand}", "show_category_by_type", $CFG_GLPI["root_doc"] . "/ajax/dropdownTicketCategories.php", $params);
         }
     } else {
         echo self::getTicketTypeName($this->fields["type"]);
     }
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</th>";
     echo "<td width='{$colsize4}%'>";
     // Permit to set category when creating ticket without update right
     if ($canupdate || !$ID || $canupdate_descr) {
         $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"]);
         if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
             $opt['condition'] = "`is_helpdeskvisible`='1' AND ";
         } else {
             $opt['condition'] = '';
         }
         /// Auto submit to load template
         if (!$ID) {
             $opt['on_change'] = 'this.form.submit()';
         }
         /// if category mandatory, no empty choice
         /// no empty choice is default value set on ticket creation, else yes
         if (($ID || $values['itilcategories_id']) && $tt->isMandatoryField("itilcategories_id") && $this->fields["itilcategories_id"] > 0) {
             $opt['display_emptychoice'] = false;
         }
         switch ($this->fields["type"]) {
             case self::INCIDENT_TYPE:
                 $opt['condition'] .= "`is_incident`='1'";
                 break;
             case self::DEMAND_TYPE:
                 $opt['condition'] .= "`is_request`='1'";
                 break;
             default:
                 break;
         }
         echo "<span id='show_category_by_type'>";
         ITILCategory::dropdown($opt);
         echo "</span>";
     } else {
         echo Dropdown::getDropdownName("glpi_itilcategories", $this->fields["itilcategories_id"]);
     }
     echo "</td>";
     echo "</tr>";
     if (!$ID) {
         echo "</table>";
         $this->showActorsPartForm($ID, $values);
         echo "<table class='tab_cadre_fixe' id='mainformtable3'>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('status');
     printf(__('%1$s%2$s'), __('Status'), $tt->getMandatoryMark('status'));
     echo $tt->getEndHiddenFieldText('status') . "</th>";
     echo "<td width='{$colsize2}%'>";
     echo $tt->getBeginHiddenFieldValue('status');
     if ($canstatus) {
         self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed'));
         TicketValidation::alertValidation($this, 'status');
     } else {
         echo self::getStatus($this->fields["status"]);
         if (in_array($this->fields["status"], $this->getClosedStatusArray()) && $this->isAllowedStatus($this->fields['status'], Ticket::INCOMING)) {
             echo "&nbsp;<a class='vsubmit' href='" . $this->getLinkURL() . "&amp;forcetab=TicketFollowup\$1&amp;_openfollowup=1'>" . __('Reopen') . "</a>";
         }
     }
     echo $tt->getEndHiddenFieldValue('status', $this);
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('requesttypes_id');
     printf(__('%1$s%2$s'), __('Request source'), $tt->getMandatoryMark('requesttypes_id'));
     echo $tt->getEndHiddenFieldText('requesttypes_id') . "</th>";
     echo "<td width='{$colsize4}%'>";
     echo $tt->getBeginHiddenFieldValue('requesttypes_id');
     if ($canupdate) {
         RequestType::dropdown(array('value' => $this->fields["requesttypes_id"], 'condition' => 'is_active = 1 AND is_ticketheader = 1'));
     } else {
         echo Dropdown::getDropdownName('glpi_requesttypes', $this->fields["requesttypes_id"]);
         echo Html::hidden('requesttypes_id', array('value' => $this->fields["requesttypes_id"]));
     }
     echo $tt->getEndHiddenFieldValue('requesttypes_id', $this);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('urgency');
     printf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency'));
     echo $tt->getEndHiddenFieldText('urgency') . "</th>";
     echo "<td>";
     if ($canupdate && $canpriority || !$ID || $canupdate_descr) {
         // Only change during creation OR when allowed to change priority OR when user is the creator
         echo $tt->getBeginHiddenFieldValue('urgency');
         $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"]));
         echo $tt->getEndHiddenFieldValue('urgency', $this);
     } else {
         $idurgency = "value_urgency" . mt_rand();
         echo "<input id='{$idurgency}' type='hidden' name='urgency' value='" . $this->fields["urgency"] . "'>";
         echo $tt->getBeginHiddenFieldValue('urgency');
         echo parent::getUrgencyName($this->fields["urgency"]);
         echo $tt->getEndHiddenFieldValue('urgency', $this);
     }
     echo "</td>";
     // Display validation state
     echo "<th>";
     if (!$ID) {
         echo $tt->getBeginHiddenFieldText('_add_validation');
         printf(__('%1$s%2$s'), __('Approval request'), $tt->getMandatoryMark('_add_validation'));
         echo $tt->getEndHiddenFieldText('_add_validation');
     } else {
         echo $tt->getBeginHiddenFieldText('global_validation');
         _e('Approval');
         echo $tt->getEndHiddenFieldText('global_validation');
     }
     echo "</th>";
     echo "<td>";
     if (!$ID) {
         echo $tt->getBeginHiddenFieldValue('_add_validation');
         $validation_right = '';
         if ($values['type'] == self::INCIDENT_TYPE && Session::haveRight('ticketvalidation', TicketValidation::CREATEINCIDENT)) {
             $validation_right = 'validate_incident';
         }
         if ($values['type'] == self::DEMAND_TYPE && Session::haveRight('ticketvalidation', TicketValidation::CREATEREQUEST)) {
             $validation_right = 'validate_request';
         }
         if (!empty($validation_right)) {
             echo "<input type='hidden' name='_add_validation' value='" . $values['_add_validation'] . "'>";
             $params = array('name' => "users_id_validate", 'entity' => $this->fields['entities_id'], 'right' => $validation_right, 'users_id_validate' => $values['users_id_validate']);
             TicketValidation::dropdownValidator($params);
         }
         echo $tt->getEndHiddenFieldValue('_add_validation', $this);
         if ($tt->isPredefinedField('global_validation')) {
             echo "<input type='hidden' name='global_validation' value='" . $tt->predefined['global_validation'] . "'>";
         }
     } else {
         echo $tt->getBeginHiddenFieldValue('global_validation');
         if (Session::haveRightsOr('ticketvalidation', TicketValidation::getCreateRights()) && $canupdate) {
             TicketValidation::dropdownStatus('global_validation', array('global' => true, 'value' => $this->fields['global_validation']));
         } else {
             echo TicketValidation::getStatus($this->fields['global_validation']);
         }
         echo $tt->getEndHiddenFieldValue('global_validation', $this);
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('impact');
     printf(__('%1$s%2$s'), __('Impact'), $tt->getMandatoryMark('impact'));
     echo $tt->getEndHiddenFieldText('impact') . "</th>";
     echo "<td>";
     echo $tt->getBeginHiddenFieldValue('impact');
     if ($canupdate) {
         $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"]));
     } else {
         $idimpact = "value_impact" . mt_rand();
         echo "<input id='{$idimpact}' type='hidden' name='impact' value='" . $this->fields["impact"] . "'>";
         echo parent::getImpactName($this->fields["impact"]);
     }
     echo $tt->getEndHiddenFieldValue('impact', $this);
     echo "</td>";
     echo "<th>" . $tt->getBeginHiddenFieldText('locations_id');
     printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id'));
     echo $tt->getEndHiddenFieldText('locations_id') . "</th>";
     echo "<td>";
     echo $tt->getBeginHiddenFieldValue('locations_id');
     if ($canupdate || !$ID) {
         Location::dropdown(array('value' => $this->fields['locations_id'], 'entity' => $this->fields['entities_id']));
     } else {
         echo Dropdown::getDropdownName('glpi_locations', $this->fields["locations_id"]);
     }
     echo $tt->getEndHiddenFieldValue('locations_id', $this);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('priority');
     printf(__('%1$s%2$s'), __('Priority'), $tt->getMandatoryMark('priority'));
     echo $tt->getEndHiddenFieldText('priority') . "</th>";
     echo "<td>";
     $idajax = 'change_priority_' . mt_rand();
     if ($canpriority && !$tt->isHiddenField('priority')) {
         $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true));
         $idpriority = 'dropdown_priority' . $idpriority;
         echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     } else {
         $idpriority = 0;
         echo $tt->getBeginHiddenFieldValue('priority');
         echo "<span id='{$idajax}'>" . parent::getPriorityName($this->fields["priority"]) . "</span>";
         echo $tt->getEndHiddenFieldValue('priority', $this);
     }
     if ($canupdate || $canupdate_descr) {
         $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority);
         Ajax::updateItemOnSelectEvent(array('dropdown_urgency' . $idurgency, 'dropdown_impact' . $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
     }
     echo "</td>";
     echo "<th rowspan='2'>" . $tt->getBeginHiddenFieldText('items_id');
     printf(__('%1$s%2$s'), _n('Associated element', 'Associated elements', Session::getPluralNumber()), $tt->getMandatoryMark('items_id'));
     if ($ID && $canupdate) {
         echo "&nbsp;<a  href='" . $this->getFormURL() . "?id=" . $ID . "&amp;forcetab=Item_Ticket\$1'><img title='" . __s('Update') . "' alt='" . __s('Update') . "'\n                      class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/showselect.png'></a>";
     }
     echo $tt->getEndHiddenFieldText('items_id');
     echo "</th>";
     if (!$ID) {
         echo "<td rowspan='2'>";
         echo $tt->getBeginHiddenFieldValue('items_id');
         $values['_canupdate'] = Session::haveRight('ticket', CREATE);
         if ($values['_canupdate']) {
             Item_Ticket::itemAddForm($this, $values);
         }
         echo $tt->getEndHiddenFieldValue('items_id', $this);
         echo "</td>";
     } else {
         echo "<td>";
         echo $tt->getBeginHiddenFieldValue('items_id');
         $values['_canupdate'] = $canupdate || $canupdate_descr;
         Item_Ticket::itemAddForm($this, $values);
         echo $tt->getEndHiddenFieldValue('items_id', $this);
         echo "</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     // Need comment right to add a followup with the actiontime
     if (!$ID && Session::haveRight('followup', TicketFollowup::ADDALLTICKET)) {
         echo "<th>" . $tt->getBeginHiddenFieldText('actiontime');
         printf(__('%1$s%2$s'), __('Total duration'), $tt->getMandatoryMark('actiontime'));
         echo $tt->getEndHiddenFieldText('actiontime') . "</th>";
         echo "<td>";
         echo $tt->getBeginHiddenFieldValue('actiontime');
         Dropdown::showTimeStamp('actiontime', array('value' => $values['actiontime'], 'addfirstminutes' => true));
         echo $tt->getEndHiddenFieldValue('actiontime', $this);
         echo "</td>";
     }
     echo "</tr>";
     echo "</table>";
     if ($ID) {
         $this->showActorsPartForm($ID, $values);
     }
     $view_linked_tickets = $ID || $canupdate;
     echo "<table class='tab_cadre_fixe' id='mainformtable4'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th style='width:{$colsize1}%'>" . $tt->getBeginHiddenFieldText('name');
     printf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name'));
     echo $tt->getEndHiddenFieldText('name') . "</th>";
     echo "<td colspan='3'>";
     if (!$ID || $canupdate_descr) {
         echo $tt->getBeginHiddenFieldValue('name');
         echo "<input type='text' style='width:98%' maxlength=250 name='name' " . " value=\"" . Html::cleanInputText($this->fields["name"]) . "\">";
         echo $tt->getEndHiddenFieldValue('name', $this);
     } else {
         if (empty($this->fields["name"])) {
             _e('Without title');
         } else {
             echo $this->fields["name"];
         }
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th style='width:{$colsize1}%'>" . $tt->getBeginHiddenFieldText('content');
     printf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content'));
     if (!$ID || $canupdate_descr) {
         $content = Toolbox::unclean_cross_side_scripting_deep(Html::entity_decode_deep($this->fields['content']));
         Html::showTooltip(nl2br(Html::Clean($content)));
     }
     echo $tt->getEndHiddenFieldText('content') . "</th>";
     echo "<td colspan='3'>";
     if (!$ID || $canupdate_descr) {
         // Admin =oui on autorise la modification de la description
         echo $tt->getBeginHiddenFieldValue('content');
         $rand = mt_rand();
         $rand_text = mt_rand();
         $rows = 6;
         $content_id = "content{$rand}";
         if ($CFG_GLPI["use_rich_text"]) {
             $this->fields["content"] = $this->setRichTextContent($content_id, $this->fields["content"], $rand);
             $rows = 10;
         } else {
             $this->fields["content"] = $this->setSimpleTextContent($this->fields["content"]);
         }
         echo "<div id='content{$rand_text}'>";
         echo "<textarea id='{$content_id}' name='content' style='width:100%' rows='{$rows}'>" . $this->fields["content"] . "</textarea></div>";
         echo Html::scriptBlock("\$(document).ready(function() { \$('#{$content_id}').autogrow(); });");
         echo $tt->getEndHiddenFieldValue('content', $this);
     } else {
         $content = Toolbox::unclean_cross_side_scripting_deep(Html::entity_decode_deep($this->fields['content']));
         echo nl2br(Html::Clean($content));
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     if ($view_linked_tickets) {
         echo "<th style='width:{$colsize1}%'>" . _n('Linked ticket', 'Linked tickets', Session::getPluralNumber());
         $rand_linked_ticket = mt_rand();
         if ($canupdate) {
             echo "&nbsp;";
             echo "<img onClick=\"" . Html::jsShow("linkedticket{$rand_linked_ticket}") . "\"\n                   title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n                   class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         }
         echo '</th>';
         echo "<td colspan='3'>";
         if ($canupdate) {
             echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>";
             echo "<table class='tab_format' width='100%'><tr><td width='30%'>";
             Ticket_Ticket::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : '');
             echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n";
             echo "</td><td width='70%'>";
             $linkparam = array('name' => '_link[tickets_id_2]', 'displaywith' => array('id'));
             if (isset($values["_link"])) {
                 $linkparam['value'] = $values["_link"]['tickets_id_2'];
             }
             Ticket::dropdown($linkparam);
             echo "</td></tr></table>";
             echo "</div>";
             if (isset($values["_link"]) && !empty($values["_link"]['tickets_id_2'])) {
                 echo "<script language='javascript'>";
                 echo Html::jsShow("linkedticket{$rand_linked_ticket}");
                 echo "</script>";
             }
         }
         Ticket_Ticket::displayLinkedTicketsTo($ID);
         echo "</td>";
     }
     echo "</tr>";
     // View files added
     echo "<tr class='tab_bg_1'>";
     // Permit to add doc when creating a ticket
     echo "<th style='width:{$colsize1}%'>";
     echo $tt->getBeginHiddenFieldText('_documents_id');
     $doctitle = sprintf(__('File (%s)'), Document::getMaxUploadSize());
     printf(__('%1$s%2$s'), $doctitle, $tt->getMandatoryMark('_documents_id'));
     // Do not show if hidden.
     if (!$tt->isHiddenField('_documents_id')) {
         DocumentType::showAvailableTypesLink();
     }
     echo $tt->getEndHiddenFieldText('_documents_id');
     echo "</th>";
     echo "<td colspan='3'>";
     // Do not set values
     echo $tt->getEndHiddenFieldValue('_documents_id');
     if ($tt->isPredefinedField('_documents_id')) {
         if (isset($values['_documents_id']) && is_array($values['_documents_id']) && count($values['_documents_id'])) {
             echo "<span class='b'>" . __('Default documents:') . '</span>';
             echo "<br>";
             $doc = new Document();
             foreach ($values['_documents_id'] as $key => $val) {
                 if ($doc->getFromDB($val)) {
                     echo "<input type='hidden' name='_documents_id[{$key}]' value='{$val}'>";
                     echo "- " . $doc->getNameID() . "<br>";
                 }
             }
         }
     }
     echo "<div id='fileupload_info'></div>";
     echo "</td>";
     echo "</tr>";
     if ((!$ID || $canupdate || $canupdate_descr || Session::haveRightsOr(self::$rightname, array(self::ASSIGN, self::STEAL, DELETE, PURGE))) && !$options['template_preview']) {
         echo "<tr class='tab_bg_1'>";
         if ($ID) {
             if (Session::haveRightsOr(self::$rightname, array(UPDATE, DELETE, PURGE)) || $this->canDeleteItem() || $this->canUpdateItem()) {
                 echo "<td class='tab_bg_2 center' colspan='4'>";
                 if ($this->fields["is_deleted"] == 1) {
                     if (self::canPurge()) {
                         echo "<input type='submit' class='submit' name='restore' value='" . _sx('button', 'Restore') . "'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                     }
                 } else {
                     if (self::canUpdate()) {
                         echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                     }
                 }
                 if ($this->fields["is_deleted"] == 1) {
                     if (self::canPurge()) {
                         echo "<input type='submit' class='submit' name='purge' value='" . _sx('button', 'Delete permanently') . "' " . Html::addConfirmationOnAction(__('Confirm the final deletion?')) . ">";
                     }
                 } else {
                     if ($this->canDeleteItem()) {
                         echo "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Put in dustbin') . "'>";
                     }
                 }
                 echo "<input type='hidden' name='_read_date_mod' value='" . $this->getField('date_mod') . "'>";
                 echo "</td>";
             }
         } else {
             echo "<td class='tab_bg_2 center' colspan='4'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             if ($tt->isField('id') && $tt->fields['id'] > 0) {
                 echo "<input type='hidden' name='_tickettemplates_id' value='" . $tt->fields['id'] . "'>";
                 echo "<input type='hidden' name='_predefined_fields'\n                      value=\"" . Toolbox::prepareArrayForInput($predefined_fields) . "\">";
             }
         }
     }
     // File upload system
     $colspan = 3;
     if (!$CFG_GLPI['use_rich_text']) {
         $colspan = 4;
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='{$colspan}'>";
     echo $tt->getBeginHiddenFieldValue('_documents_id');
     echo Html::file(array('multiple' => true, 'showfilecontainer' => 'fileupload_info', 'values' => array('filename' => $values['_filename'], 'tag' => $values['_tag_filename'])));
     echo "</td>";
     if ($CFG_GLPI['use_rich_text']) {
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='{$colspan}'>";
         if (!isset($rand)) {
             $rand = mt_rand();
         }
         if ($canupdate_descr) {
             echo Html::initImagePasteSystem($content_id, $rand);
         }
         echo "</td>";
     }
     echo "</tr>";
     echo "</table>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</div>";
     if (!$options['template_preview']) {
         Html::closeForm();
     }
     return true;
 }
 /**
  *
  *
  * @param $items_id integer ID
  *
  * @param $host_id integer associated host ID
  * @param $options array
  *
  *@return bool true if form is ok
  *
  **/
 function showForm($id = -1, $itemtype = 'Host', $items_id = -1, $options = array())
 {
     global $DB, $CFG_GLPI;
     // Toolbox::logInFile("pm-ack", "acknowledge, showForm, id : $id, item type : $itemtype / $items_id\n");
     $createAcknowledge = false;
     if ($id == -1) {
         // if ($itemtype == 'N/A') $itemtype = 'Computer';
         // if ($itemtype == '') $itemtype = 'Computer';
         $itemtype = 'PluginMonitoring' . $itemtype;
         $item = new $itemtype();
         $item->getFromDB($items_id);
         if ($item->isCurrentlyAcknowledged()) {
             // If host currently acknowledged, show current acknowledge ...
             $pmAcknowledge = new PluginMonitoringAcknowledge();
             $this->getFromDB($pmAcknowledge->getFromHost($this->getID()));
         } else {
             // .. else create new acknowledge
             $createAcknowledge = true;
             $this->getEmpty();
             $this->setDefaultContent($itemtype, $items_id);
         }
     } else {
         $this->getFromDB($id);
         $createAcknowledge = true;
     }
     // Now ...
     $nowDate = date('Y-m-d');
     $nowTime = date('H:i:s');
     $this->showFormHeader($options);
     $this->isExpired();
     $itemtype = $this->getField('itemtype');
     if ($itemtype == 'N/A') {
         $itemtype = 'Computer';
     }
     if ($itemtype == '') {
         $itemtype = 'Computer';
     }
     $item = new $itemtype();
     $item->getFromDB($this->getField("items_id"));
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . $item->getTypeName() . "</td>";
     echo "<td>";
     echo "<input type='hidden' name='itemtype' value='" . $this->fields['itemtype'] . "' />";
     echo "<input type='hidden' name='items_id' value='" . $this->fields['items_id'] . "' />";
     echo $item->getLink() . "&nbsp;" . $item->getComments();
     echo "</td>";
     echo "<td>" . __('Sticky ?', 'monitoring') . "</td>";
     echo "<td>";
     if ($createAcknowledge) {
         Dropdown::showYesNo('sticky', $this->fields['sticky']);
     } else {
         echo Dropdown::getYesNo($this->fields['sticky']);
     }
     echo "</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' => $createAcknowledge, 'mindate' => $nowDate, 'mintime' => $nowTime));
     echo "</td>";
     echo "<td>" . __('Persistent ?', 'monitoring') . "</td>";
     echo "<td>";
     if ($createAcknowledge) {
         Dropdown::showYesNo('persistent', $this->fields['persistent']);
     } else {
         echo Dropdown::getYesNo($this->fields['persistent']);
     }
     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' => $createAcknowledge, 'mindate' => $nowDate, 'mintime' => $nowTime));
     echo "</td>";
     echo "<td>" . __('Notify ?', 'monitoring') . "</td>";
     echo "<td>";
     if ($createAcknowledge) {
         Dropdown::showYesNo('notify', $this->fields['notify']);
     } else {
         echo Dropdown::getYesNo($this->fields['notify']);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comment', 'monitoring') . "</td>";
     echo "<td >";
     if ($createAcknowledge) {
         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>";
     $this->showFormButtons();
     return true;
 }
Пример #7
0
 /**
  * Display for reservation
  *
  * @param $ID              ID of the reservation (empty for create new)
  * @param $options   array of possibles options:
  *     - item  reservation items ID for creation process
  *     - date date for creation process
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if (!Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) {
         return false;
     }
     $resa = new self();
     if (!empty($ID)) {
         if (!$resa->getFromDB($ID)) {
             return false;
         }
         if (!$resa->can($ID, UPDATE)) {
             return false;
         }
         // Set item if not set
         if ((!isset($options['item']) || count($options['item']) == 0) && ($itemid = $resa->getField('reservationitems_id'))) {
             $options['item'][$itemid] = $itemid;
         }
     } else {
         $resa->getEmpty();
         $resa->fields["begin"] = $options['begin'];
         if (!isset($options['end'])) {
             $resa->fields["end"] = date("Y-m-d H:00:00", strtotime($resa->fields["begin"]) + HOUR_TIMESTAMP);
         } else {
             $resa->fields["end"] = $options['end'];
         }
     }
     // No item : problem
     if (!isset($options['item']) || count($options['item']) == 0) {
         return false;
     }
     echo "<div class='center'><form method='post' name=form action='reservation.form.php'>";
     if (!empty($ID)) {
         echo "<input type='hidden' name='id' value='{$ID}'>";
     }
     echo "<table class='tab_cadre' width='700px'>";
     echo "<tr><th colspan='2'>" . __('Reserve an item') . "</th></tr>\n";
     // Add Hardware name
     $r = new ReservationItem();
     echo "<tr class='tab_bg_1'><td>" . __('Item') . "</td>";
     echo "<td>";
     foreach ($options['item'] as $itemID) {
         $r->getFromDB($itemID);
         $type = $r->fields["itemtype"];
         $name = NOT_AVAILABLE;
         $item = NULL;
         if ($item = getItemForItemtype($r->fields["itemtype"])) {
             $type = $item->getTypeName();
             if ($item->getFromDB($r->fields["items_id"])) {
                 $name = $item->getName();
             } else {
                 $item = NULL;
             }
         }
         echo "<span class='b'>" . sprintf(__('%1$s - %2$s'), $type, $name) . "</span><br>";
         echo "<input type='hidden' name='items[{$itemID}]' value='{$itemID}'>";
     }
     echo "</td></tr>\n";
     if (!Session::haveRight("reservation", UPDATE) || is_null($item) || !Session::haveAccessToEntity($item->fields["entities_id"])) {
         echo "<input type='hidden' name='users_id' value='" . Session::getLoginUserID() . "'>";
     } else {
         echo "<tr class='tab_bg_2'><td>" . __('By') . "</td>";
         echo "<td>";
         if (empty($ID)) {
             User::dropdown(array('value' => Session::getLoginUserID(), 'entity' => $item->getEntityID(), 'right' => 'all'));
         } else {
             User::dropdown(array('value' => $resa->fields["users_id"], 'entity' => $item->getEntityID(), 'right' => 'all'));
         }
         echo "</td></tr>\n";
     }
     echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>";
     $rand_begin = Html::showDateTimeField("resa[begin]", array('value' => $resa->fields["begin"], 'timestep' => -1, 'maybeempty' => false));
     echo "</td></tr>\n";
     $default_delay = floor((strtotime($resa->fields["end"]) - strtotime($resa->fields["begin"])) / $CFG_GLPI['time_step'] / MINUTE_TIMESTAMP) * $CFG_GLPI['time_step'] * MINUTE_TIMESTAMP;
     echo "<tr class='tab_bg_2'><td>" . __('Duration') . "</td><td>";
     $rand = Dropdown::showTimeStamp("resa[_duration]", array('min' => 0, 'max' => 24 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date')));
     echo "<br><div id='date_end{$rand}'></div>";
     $params = array('duration' => '__VALUE__', 'end' => $resa->fields["end"], 'name' => "resa[end]");
     Ajax::updateItemOnSelectEvent("dropdown_resa[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params);
     if ($default_delay == 0) {
         $params['duration'] = 0;
         Ajax::updateItem("date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params);
     }
     Alert::displayLastAlert('Reservation', $ID);
     echo "</td></tr>\n";
     if (empty($ID)) {
         echo "<tr class='tab_bg_2'><td>" . __('Rehearsal') . "</td>";
         echo "<td>";
         $values = array('' => _x('periodicity', 'None'), 'day' => _x('periodicity', 'Daily'), 'week' => _x('periodicity', 'Weekly'), 'month' => _x('periodicity', 'Monthly'));
         $rand = Dropdown::showFromArray('periodicity[type]', $values);
         $field_id = Html::cleanId("dropdown_periodicity[type]{$rand}");
         $params = array('type' => '__VALUE__', 'end' => $resa->fields["end"]);
         Ajax::updateItemOnSelectEvent($field_id, "resaperiodcontent{$rand}", $CFG_GLPI["root_doc"] . "/ajax/resaperiod.php", $params);
         echo "<br><div id='resaperiodcontent{$rand}'></div>";
         echo "</td></tr>\n";
     }
     echo "<tr class='tab_bg_2'><td>" . __('Comments') . "</td>";
     echo "<td><textarea name='comment' rows='8' cols='60'>" . $resa->fields["comment"] . "</textarea>";
     echo "</td></tr>\n";
     if (empty($ID)) {
         echo "<tr class='tab_bg_2'>";
         echo "<td colspan='2' class='top center'>";
         echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
         echo "</td></tr>\n";
     } else {
         if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRightsOr(static::$rightname, array(PURGE, UPDATE))) {
             echo "<tr class='tab_bg_2'>";
             if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, PURGE)) {
                 echo "<td class='top center'>";
                 echo "<input type='submit' name='purge' value=\"" . _sx('button', 'Delete permanently') . "\"\n                      class='submit'>";
                 if ($resa->fields["group"] > 0) {
                     echo "<br><input type='checkbox' name='_delete_group'>&nbsp;" . __s('Delete all rehearsals');
                 }
                 echo "</td>";
             }
             if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, UPDATE)) {
                 echo "<td class='top center'>";
                 echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n                     class='submit'>";
                 echo "</td>";
             }
             echo "</tr>\n";
         }
     }
     echo "</table>";
     Html::closeForm();
     echo "</div>\n";
 }
    public static function show($field, $datas)
    {
        $value = $datas['formcreator_field_' . $field['id']] != 'NULL' ? $datas['formcreator_field_' . $field['id']] : $field['default_values'];
        if ($field['required']) {
            $required = ' required';
        } else {
            $required = '';
        }
        echo '<div class="form-group' . $required . '" id="form-group-field' . $field['id'] . '">';
        echo '<label>';
        echo $field['name'];
        if ($field['required']) {
            echo ' <span class="red">*</span>';
        }
        echo '</label>';
        echo '<div>';
        Html::showDateTimeField('formcreator_field_' . $field['id'], array('value' => $value));
        echo '</div>';
        echo '<div class="help-block">' . html_entity_decode($field['description']) . '</div>';
        switch ($field['show_condition']) {
            case 'notequal':
                $condition = '!=';
                break;
            case 'lower':
                $condition = '<';
                break;
            case 'greater':
                $condition = '>';
                break;
            default:
                $condition = '==';
                break;
        }
        if ($field['show_type'] == 'hide') {
            $conditionnalField = new PluginFormcreatorQuestion();
            $conditionnalField->getFromDB($field['show_field']);
            switch ($conditionnalField->fields['fieldtype']) {
                case 'checkboxes':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]");

                  for(var i=0; inputElements[i]; ++i) {
                     inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  }

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }';
                    break;
                case 'multiselect':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '[]")[1];
                  inputElements.addEventListener("change", function(){showFormGroup' . $field['id'] . '()});

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].selected) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }';
                    break;
                case 'radios':
                    echo '<script type="text/javascript">
                  var inputElements = document.getElementsByName("formcreator_field_' . $field['show_field'] . '");

                  for(var i=0; inputElements[i]; ++i) {
                     inputElements[i].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  }

                  function showFormGroup' . $field['id'] . '() {
                     var checkedValue = false;

                     for(var i=0; inputElements[i]; ++i) {
                        if (inputElements[i].value ' . $condition . ' "' . $field['show_value'] . '" && inputElements[i].checked) {
                           checkedValue = true;
                        }
                     }

                     if(checkedValue) {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }';
                    break;
                default:
                    echo '<script type="text/javascript">
                  document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].addEventListener("change", function(){showFormGroup' . $field['id'] . '()});
                  function showFormGroup' . $field['id'] . '() {
                     var field_value = document.getElementsByName("formcreator_field_' . $field['show_field'] . '")[0].value;
                     if(field_value ' . $condition . ' "' . $field['show_value'] . '") {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "block";
                     } else {
                        document.getElementById("form-group-field' . $field['id'] . '").style.display = "none";
                     }
                  }';
            }
            echo '
                  Ext.onReady(function() {showFormGroup' . $field['id'] . '()});
               </script>';
        }
        echo '</div>' . PHP_EOL;
    }
 /**
  * Affiche le cadre avec la date de debut / date de fin
  **/
 function showFormDate()
 {
     global $datesresa;
     /*if(isset($_GET['resareturn'])) {
         $_POST['reserve'] = $datesresa;
       } 
       else */
     if (!isset($datesresa)) {
         $jour = date("d", time());
         $mois = date("m", time());
         $annee = date("Y", time());
         $begin_time = time();
         $datesresa["begin"] = date("Y-m-d H:i:s", $begin_time);
         if ($begin_time > mktime(19, 0, 0, $mois, $jour, $annee)) {
             $datesresa["end"] = date("Y-m-d H:i:s", $begin_time + 3600);
         } else {
             $datesresa["end"] = date("Y-m-d H:i:s", mktime(19, 0, 0, $mois, $jour, $annee));
         }
     }
     if (isset($_POST['nextday'])) {
         $tmpbegin = $datesresa["begin"];
         $tmpend = $datesresa["end"];
         $datesresa["begin"] = date("Y-m-d H:i:s", strtotime($datesresa["begin"]) + DAY_TIMESTAMP);
         $datesresa["end"] = date("Y-m-d H:i:s", strtotime($datesresa["end"]) + DAY_TIMESTAMP);
     }
     if (isset($_POST['previousday'])) {
         $tmpbegin = $datesresa["begin"];
         $tmpend = $datesresa["end"];
         $datesresa["begin"] = date("Y-m-d H:i:s", strtotime($datesresa["begin"]) - DAY_TIMESTAMP);
         $datesresa["end"] = date("Y-m-d H:i:s", strtotime($datesresa["end"]) - DAY_TIMESTAMP);
     }
     echo "<div id='viewresasearch'  class='center'>";
     echo "<form method='post' name='form' action='" . Toolbox::getItemTypeSearchURL(__CLASS__) . "'>";
     echo "<table class='tab_cadre'><tr class='tab_bg_2'>";
     echo "<th colspan='5'>Choisissez une date</th></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td rowspan='3'>";
     echo "<input type='submit' class='submit' name='previousday' value=\"Jour precedent\">";
     echo "</td>";
     echo "<td>" . __('Start date') . "</td><td>";
     Html::showDateTimeField("reserve[begin]", array('value' => $datesresa["begin"], 'maybeempty' => false));
     echo "</td><td rowspan='3'>";
     echo "<input type='submit' class='submit' name='submit' value=\"" . _sx('button', 'Search') . "\">";
     echo "</td>";
     echo "<td rowspan='3'>";
     echo "<input type='submit' class='submit' name='nextday' value=\"Jour suivant\">";
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('End date') . "</td><td>";
     Html::showDateTimeField("reserve[end]", array('value' => $datesresa["end"], 'maybeempty' => false));
     echo "</td></tr>";
     echo "</td></tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
Пример #10
0
 /**
  * Print the computer form
  *
  * @param $ID        integer ID of the item
  * @param $options   array
  *     - target for the Form
  *     - withtemplate template or basic computer
  *
  *@return Nothing (display)
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $DB;
     $this->initForm($ID, $options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Creation date') . "</td>";
     echo "<td>";
     $date = $this->fields["date"];
     if (!$ID) {
         $date = $_SESSION['glpi_currenttime'];
     }
     Html::showDateTimeField("date", array('value' => $date, 'timestep' => 1, 'maybeempty' => false));
     echo "</td>";
     if ($ID) {
         echo "<td>" . __('Last update') . "</td>";
         echo "<td >" . Html::convDateTime($this->fields["date_mod"]) . "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, 'name');
     echo "</td>";
     echo "<td>" . __('Code') . "</td>";
     echo "<td>";
     Html::autocompletionTextField($this, 'code');
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Priority') . "</td>";
     echo "<td>";
     CommonITILObject::dropdownPriority(array('value' => $this->fields['priority'], 'withmajor' => 1));
     echo "</td>";
     echo "<td>" . __('As child of') . "</td>";
     echo "<td>";
     $this->dropdown(array('entity' => $this->fields['entities_id'], 'value' => $this->fields['projects_id'], 'used' => array($this->fields['id'])));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . _x('item', 'State') . "</td>";
     echo "<td>";
     ProjectState::dropdown(array('value' => $this->fields["projectstates_id"]));
     echo "</td>";
     echo "<td>" . __('Percent done') . "</td>";
     echo "<td>";
     Dropdown::showNumber("percent_done", array('value' => $this->fields['percent_done'], 'min' => 0, 'max' => 100, 'step' => 5, 'unit' => '%'));
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Type') . "</td>";
     echo "<td>";
     ProjectType::dropdown(array('value' => $this->fields["projecttypes_id"]));
     echo "</td>";
     echo "<td>" . __('Show on global GANTT') . "</td>";
     echo "<td>";
     Dropdown::showYesNo("show_on_global_gantt", $this->fields["show_on_global_gantt"]);
     echo "</td>";
     echo "</tr>";
     echo "<tr><td colspan='4' class='subheader'>" . __('Manager') . "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('User') . "</td>";
     echo "<td>";
     User::dropdown(array('name' => 'users_id', 'value' => $this->fields["users_id"], 'right' => 'see_project', 'entity' => $this->fields["entities_id"]));
     echo "</td>";
     echo "<td>" . __('Group') . "</td>";
     echo "<td>";
     Group::dropdown(array('name' => 'groups_id', 'value' => $this->fields['groups_id'], 'entity' => $this->fields['entities_id'], 'condition' => '`is_manager`'));
     echo "</td></tr>\n";
     echo "<tr><td colspan='4' class='subheader'>" . __('Planning') . "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned start date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("plan_start_date", array('value' => $this->fields['plan_start_date']));
     echo "</td>";
     echo "<td>" . __('Real start date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("real_start_date", array('value' => $this->fields['real_start_date']));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned end date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("plan_end_date", array('value' => $this->fields['plan_end_date']));
     echo "</td>";
     echo "<td>" . __('Real end date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("real_end_date", array('value' => $this->fields['real_end_date']));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned duration');
     echo Html::showTooltip(__('Sum of planned durations of tasks'));
     echo "</td>";
     echo "<td>";
     echo Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($this->fields['id']), false);
     echo "</td>";
     echo "<td>" . __('Effective duration');
     echo Html::showTooltip(__('Sum of total effective durations of tasks'));
     echo "</td>";
     echo "<td>";
     echo Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($this->fields['id']), false);
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Description') . "</td>";
     echo "<td colspan='3'>";
     echo "<textarea id='content' name='content' cols='90' rows='6'>" . $this->fields["content"] . "</textarea>";
     echo "</td>";
     echo "</tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comments') . "</td>";
     echo "<td colspan='3'>";
     echo "<textarea id='comment' name='comment' cols='90' rows='6'>" . $this->fields["comment"] . "</textarea>";
     echo "</td>";
     echo "</tr>\n";
     $this->showFormButtons($options);
     return true;
 }
 static function showForTicket(Ticket $item)
 {
     if (!self::canView()) {
         return false;
     }
     $canedit = $item->canUpdate() && self::canUpdate();
     echo "<form name='form' method='post' action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     echo "<div align='center'><table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='2'>" . __('Close ticket informations', 'moreticket') . "</th></tr>";
     // Writer
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     echo __('Writer');
     echo "</td>";
     echo "<td>";
     echo getUserName(Session::getLoginUserID());
     echo "<input name='requesters_id' type='hidden' value='" . Session::getLoginUserID() . "'>";
     echo "</td>";
     echo "</tr>";
     // Date
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     echo "</td>";
     echo "<td>";
     Html::showDateTimeField("date", array('value' => date('Y-m-d H:i:s')));
     echo "</td>";
     echo "</tr>";
     // Comments
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     echo __('Comments');
     echo "</td>";
     echo "<td>";
     echo "<textarea cols='80' rows='8' name='comment'></textarea>";
     echo "</td>";
     echo "</tr>";
     // Documents
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='2' style='padding:10px 20px 0px 20px'>";
     echo Html::file();
     echo "(" . Document::getMaxUploadSize() . ")&nbsp;";
     echo "</td>";
     echo "</tr>";
     if ($canedit) {
         echo "<tr>";
         echo "<td class='tab_bg_2 center' colspan='6'>";
         echo "<input type='submit' name='add' class='submit' value='" . _sx('button', 'Add') . "' >";
         echo "<input type='hidden' name='tickets_id' class='submit' value='" . $item->fields['id'] . "' >";
         echo "<input type='hidden' name='items_id' class='submit' value='" . $item->fields['id'] . "' >";
         echo "<input type='hidden' name='itemtype' class='submit' value='Ticket' >";
         echo "</td>";
         echo "</tr>";
     }
     echo "</table></div>";
     Html::closeForm();
     // List
     self::showList($item, $canedit);
 }
 public function showDateTimeField($title, $varname, $options = array())
 {
     // Get datetime value if the object is defined
     if ($this->fields['id'] > 0) {
         $value = $this->fields[$varname];
     } else {
         // Else set default value to current date and time
         if (array_key_exists('maybeempty', $options) and $options['maybeempty']) {
             $value = "";
         } else {
             $value = date("Y-m-d H:i:s");
         }
     }
     $options['value'] = $value;
     echo "<label>" . $title . "&nbsp;:</label>";
     echo "<div class='input_wrap datetime'>";
     Html::showDateTimeField($varname, $options);
     echo "</div>";
 }
Пример #13
0
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if (!$this->isNewID($ID)) {
         $this->check($ID, READ);
     } else {
         // Create item
         $this->check(-1, CREATE);
     }
     $this->showFormHeader($options);
     $fields = $this->getAdditionalFields();
     $nb = count($fields);
     echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
     echo "<td>";
     if ($this instanceof CommonDevice) {
         // Awfull hack for CommonDevice where name is designation
         Html::autocompletionTextField($this, "designation");
     } else {
         Html::autocompletionTextField($this, "name");
     }
     echo "</td>";
     echo "<td rowspan='" . ($nb + 1) . "'>" . __('Comments') . "</td>";
     echo "<td rowspan='" . ($nb + 1) . "'>\n            <textarea cols='45' rows='" . ($nb + 2) . "' name='comment' >" . $this->fields["comment"];
     echo "</textarea></td></tr>\n";
     foreach ($fields as $field) {
         if ($field['name'] == 'entities_id' && $ID == 0 && !$this->isNewID($ID)) {
             // No display for root entity
             echo "<tr class='tab_bg_1'><td colspan='2'>&nbsp;</td></tr>";
             break;
         }
         if (!isset($field['type'])) {
             $field['type'] = '';
         }
         if ($field['name'] == 'header') {
             echo "<tr class='tab_bg_1'><th colspan='2'>" . $field['label'] . "</th></tr>";
             continue;
         }
         echo "<tr class='tab_bg_1'><td>" . $field['label'];
         if (isset($field['comment']) && !empty($field['comment'])) {
             echo "&nbsp;";
             Html::showToolTip($field['comment']);
         }
         echo "</td><td>";
         switch ($field['type']) {
             case 'UserDropdown':
                 $param = array('name' => $field['name'], 'value' => $this->fields[$field['name']], 'right' => 'interface', 'entity' => $this->fields["entities_id"]);
                 if (isset($field['right'])) {
                     $params['right'] = $field['right'];
                 }
                 User::dropdown($param);
                 break;
             case 'dropdownValue':
                 $params = array('value' => $this->fields[$field['name']], 'name' => $field['name'], 'entity' => $this->getEntityID());
                 if (isset($field['condition'])) {
                     $params['condition'] = $field['condition'];
                 }
                 Dropdown::show(getItemTypeForTable(getTableNameForForeignKeyField($field['name'])), $params);
                 break;
             case 'text':
                 Html::autocompletionTextField($this, $field['name']);
                 break;
             case 'textarea':
                 $cols = 40;
                 $rows = 3;
                 if (isset($field['rows'])) {
                     $rows = $field['rows'];
                 }
                 if (isset($field['cols'])) {
                     $cols = $field['cols'];
                 }
                 echo "<textarea name='" . $field['name'] . "' cols='{$cols}' rows='{$rows}'>" . $this->fields[$field['name']] . "</textarea >";
                 break;
             case 'integer':
                 Dropdown::showNumber($field['name'], array('value' => $this->fields[$field['name']]));
                 break;
             case 'timestamp':
                 $param = array('value' => $this->fields[$field['name']]);
                 if (isset($field['min'])) {
                     $param['min'] = $field['min'];
                 }
                 if (isset($field['max'])) {
                     $param['max'] = $field['max'];
                 }
                 if (isset($field['step'])) {
                     $param['step'] = $field['step'];
                 }
                 Dropdown::showTimeStamp($field['name'], $param);
                 break;
             case 'parent':
                 if ($field['name'] == 'entities_id') {
                     $restrict = -1;
                 } else {
                     $restrict = $this->getEntityID();
                 }
                 Dropdown::show(getItemTypeForTable($this->getTable()), array('value' => $this->fields[$field['name']], 'name' => $field['name'], 'entity' => $restrict, 'used' => $ID > 0 ? getSonsOf($this->getTable(), $ID) : array()));
                 break;
             case 'icon':
                 Dropdown::dropdownIcons($field['name'], $this->fields[$field['name']], GLPI_ROOT . "/pics/icones");
                 if (!empty($this->fields[$field['name']])) {
                     echo "&nbsp;<img style='vertical-align:middle;' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $this->fields[$field['name']] . "'>";
                 }
                 break;
             case 'bool':
                 Dropdown::showYesNo($field['name'], $this->fields[$field['name']]);
                 break;
             case 'color':
                 Html::showColorField($field['name'], array('value' => $this->fields[$field['name']]));
                 break;
             case 'date':
                 Html::showDateField($field['name'], array('value' => $this->fields[$field['name']]));
                 break;
             case 'datetime':
                 Html::showDateTimeField($field['name'], array('value' => $this->fields[$field['name']]));
                 break;
             case 'password':
                 echo "<input type='password' name='password' value='' size='20' autocomplete='off'>";
                 break;
             default:
                 $this->displaySpecificTypeField($ID, $field);
                 break;
         }
         if (isset($field['unit'])) {
             echo "&nbsp;" . $field['unit'];
         }
         echo "</td></tr>\n";
     }
     if (isset($this->fields['is_protected']) && $this->fields['is_protected']) {
         $options['candel'] = false;
     }
     if (isset($_REQUEST['_in_modal'])) {
         echo "<input type='hidden' name='_in_modal' value='1'>";
     }
     $this->showFormButtons($options);
     return true;
 }
Пример #14
0
 /**
  * Select a field using standard system
  *
  * @since version 0.83
  *
  * @param $field_id_or_search_options  integer/string/array id of the search option field
  *                                                             or field name
  *                                                             or search option array
  * @param $name                        string               name of the select (if empty use linkfield)
  *                                                          (default '')
  * @param $values                                           mixed default value to display
  *                                                          (default '')
  * @param $options                     array                of possible options:
  * Parameters which could be used in options array :
  *    - comments : boolean / is the comments displayed near the value (default false)
  *    - any others options passed to specific display method
  *
  * @return return the string to display
  **/
 function getValueToSelect($field_id_or_search_options, $name = '', $values = '', $options = array())
 {
     global $CFG_GLPI;
     $param['comments'] = false;
     $param['html'] = false;
     foreach ($param as $key => $val) {
         if (!isset($options[$key])) {
             $options[$key] = $val;
         }
     }
     $searchoptions = array();
     if (is_array($field_id_or_search_options)) {
         $searchoptions = $field_id_or_search_options;
     } else {
         $searchopt = $this->getSearchOptions();
         // Get if id of search option is passed
         if (is_numeric($field_id_or_search_options)) {
             if (isset($searchopt[$field_id_or_search_options])) {
                 $searchoptions = $searchopt[$field_id_or_search_options];
             }
         } else {
             // Get if field name is passed
             $searchoptions = $this->getSearchOptionByField('field', $field_id_or_search_options, $this->getTable());
         }
     }
     if (count($searchoptions)) {
         $field = $searchoptions['field'];
         // Normalize option
         if (is_array($values)) {
             $value = $values[$field];
         } else {
             $value = $values;
             $values = array($field => $value);
         }
         if (empty($name)) {
             $name = $searchoptions['linkfield'];
         }
         // If not set : set to specific
         if (!isset($searchoptions['datatype'])) {
             $searchoptions['datatype'] = 'specific';
         }
         $options['display'] = false;
         $unit = '';
         if (isset($searchoptions['unit'])) {
             $unit = $searchoptions['unit'];
         }
         if (isset($options[$searchoptions['table'] . '.' . $searchoptions['field']])) {
             $options = array_merge($options, $options[$searchoptions['table'] . '.' . $searchoptions['field']]);
         }
         switch ($searchoptions['datatype']) {
             case "count":
             case "number":
             case "integer":
                 $copytooption = array('min', 'max', 'step', 'toadd', 'unit');
                 foreach ($copytooption as $key) {
                     if (isset($searchoptions[$key]) && !isset($options[$key])) {
                         $options[$key] = $searchoptions[$key];
                     }
                 }
                 $options['value'] = $value;
                 return Dropdown::showNumber($name, $options);
             case "decimal":
             case "mac":
             case "ip":
             case "string":
             case "email":
             case "weblink":
                 $this->fields[$name] = $value;
                 return Html::autocompletionTextField($this, $name, $options);
             case "text":
                 $out = '';
                 if (isset($searchoptions['htmltext']) && $searchoptions['htmltext']) {
                     $out = Html::initEditorSystem($name, '', false);
                 }
                 return $out . "<textarea cols='45' rows='5' name='{$name}'>{$value}</textarea>";
             case "bool":
                 return Dropdown::showYesNo($name, $value, -1, $options);
             case "color":
                 return Html::showColorField($name, $options);
             case "date":
             case "date_delay":
                 if (isset($options['relative_dates']) && $options['relative_dates']) {
                     if (isset($searchoptions['maybefuture']) && $searchoptions['maybefuture']) {
                         $options['with_future'] = true;
                     }
                     return Html::showGenericDateTimeSearch($name, $value, $options);
                 }
                 $copytooption = array('min', 'max', 'maybeempty', 'showyear');
                 foreach ($copytooption as $key) {
                     if (isset($searchoptions[$key]) && !isset($options[$key])) {
                         $options[$key] = $searchoptions[$key];
                     }
                 }
                 $options['value'] = $value;
                 return Html::showDateField($name, $options);
             case "datetime":
                 if (isset($options['relative_dates']) && $options['relative_dates']) {
                     if (isset($searchoptions['maybefuture']) && $searchoptions['maybefuture']) {
                         $options['with_future'] = true;
                     }
                     $options['with_time'] = true;
                     return Html::showGenericDateTimeSearch($name, $value, $options);
                 }
                 $copytooption = array('mindate', 'maxdate', 'mintime', 'maxtime', 'maybeempty', 'timestep');
                 foreach ($copytooption as $key) {
                     if (isset($searchoptions[$key]) && !isset($options[$key])) {
                         $options[$key] = $searchoptions[$key];
                     }
                 }
                 $options['value'] = $value;
                 return Html::showDateTimeField($name, $options);
             case "timestamp":
                 $copytooption = array('addfirstminutes', 'emptylabel', 'inhours', 'max', 'min', 'step', 'toadd', 'display_emptychoice');
                 foreach ($copytooption as $key) {
                     if (isset($searchoptions[$key]) && !isset($options[$key])) {
                         $options[$key] = $searchoptions[$key];
                     }
                 }
                 $options['value'] = $value;
                 return Dropdown::showTimeStamp($name, $options);
             case "itemlink":
                 // Do not use dropdown if wanted to select string value instead of ID
                 if (isset($options['itemlink_as_string']) && $options['itemlink_as_string']) {
                     break;
                 }
             case "dropdown":
                 $copytooption = array('condition', 'displaywith', 'emptylabel', 'right', 'toadd');
                 $options['name'] = $name;
                 $options['value'] = $value;
                 foreach ($copytooption as $key) {
                     if (isset($searchoptions[$key]) && !isset($options[$key])) {
                         $options[$key] = $searchoptions[$key];
                     }
                 }
                 if (!isset($options['entity'])) {
                     $options['entity'] = $_SESSION['glpiactiveentities'];
                 }
                 $itemtype = getItemTypeForTable($searchoptions['table']);
                 return $itemtype::dropdown($options);
             case "right":
                 return Profile::dropdownRights(Profile::getRightsFor($searchoptions['rightclass']), $name, $value, array('multiple' => false, 'display' => false));
             case "itemtypename":
                 if (isset($searchoptions['itemtype_list'])) {
                     $options['types'] = $CFG_GLPI[$searchoptions['itemtype_list']];
                 }
                 $copytooption = array('types');
                 $options['value'] = $value;
                 foreach ($copytooption as $key) {
                     if (isset($searchoptions[$key]) && !isset($options[$key])) {
                         $options[$key] = $searchoptions[$key];
                     }
                 }
                 if (isset($options['types'])) {
                     return Dropdown::showItemTypes($name, $options['types'], $options);
                 }
                 return false;
             case "language":
                 $copytooption = array('emptylabel', 'display_emptychoice');
                 foreach ($copytooption as $key) {
                     if (isset($searchoptions[$key]) && !isset($options[$key])) {
                         $options[$key] = $searchoptions[$key];
                     }
                 }
                 $options['value'] = $value;
                 return Dropdown::showLanguages($name, $options);
         }
         // Get specific display if available
         $itemtype = getItemTypeForTable($searchoptions['table']);
         if ($item = getItemForItemtype($itemtype)) {
             $specific = $item->getSpecificValueToSelect($searchoptions['field'], $name, $values, $options);
             if (strlen($specific)) {
                 return $specific;
             }
         }
     }
     // default case field text
     $this->fields[$name] = $value;
     return Html::autocompletionTextField($this, $name, $options);
 }
Пример #15
0
    }
    if ($_POST['inquest_config'] > 0) {
        echo "<table class='tab_cadre_fixe' width='50%'>";
        echo "<tr class='tab_bg_1'><td width='50%'>" . __('Create survey after') . "</td>";
        echo "<td>";
        Dropdown::showNumber('inquest_delay', array('value' => $inquest_delay, 'min' => 1, 'max' => 90, 'step' => 1, 'toadd' => array('0' => __('As soon as possible')), 'unit' => 'day'));
        echo "</td></tr>";
        echo "<tr class='tab_bg_1'>" . "<td>" . __('Rate to trigger survey') . "</td>";
        echo "<td>";
        Dropdown::showNumber('inquest_rate', array('value' => $inquest_rate, 'min' => 10, 'max' => 100, 'step' => 10, 'toadd' => array(0 => __('Disabled')), 'unit' => '%'));
        echo "</td></tr>";
        echo "<tr class='tab_bg_1'><td width='50%'>" . __('Duration of survey') . "</td>";
        echo "<td>";
        Dropdown::showNumber('inquest_duration', array('value' => $inquest_duration, 'min' => 1, 'max' => 180, 'step' => 1, 'toadd' => array('0' => __('Unspecified')), 'unit' => 'day'));
        echo "</td></tr>";
        if ($max_closedate != '') {
            echo "<tr class='tab_bg_1'><td>" . __('For tickets closed after') . "</td><td>";
            Html::showDateTimeField("max_closedate", array('value' => $max_closedate, 'timestep' => 1));
            echo "</td></tr>";
        }
        if ($_POST['inquest_config'] == 2) {
            echo "<tr class='tab_bg_1'>";
            echo "<td>" . __('Valid tags') . "</td><td>" . "[TICKET_ID] [TICKET_NAME] [TICKET_CREATEDATE] [TICKET_SOLVEDATE] " . "[REQUESTTYPE_ID] [REQUESTTYPE_NAME] [TICKET_PRIORITY] [TICKET_PRIORITYNAME]  " . "[TICKETCATEGORY_ID] [TICKETCATEGORY_NAME] [TICKETTYPE_ID] " . "[TICKETTYPE_NAME] [SOLUTIONTYPE_ID] [SOLUTIONTYPE_NAME] " . "[SLA_ID] [SLA_NAME] [SLALEVEL_ID] [SLALEVEL_NAME]</td></tr>";
            echo "<tr class='tab_bg_1'><td>" . __('URL') . "</td>";
            echo "<td>";
            Html::autocompletionTextField($entity, "inquest_URL");
            echo "</td></tr>";
        }
        echo "</table>";
    }
}
Пример #16
0
 /**
  * Print the reminder form
  *
  * @param $ID        integer  Id of the item to print
  * @param $options   array of possible options:
  *     - target filename : where to go when done.
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     $this->initForm($ID, $options);
     // Show Reminder or blank form
     $onfocus = "";
     if (!$ID > 0) {
         // Create item : do getempty before check right to set default values
         $onfocus = "onfocus=\"if (this.value=='" . $this->fields['name'] . "') this.value='';\"";
     }
     $canedit = $this->can($ID, UPDATE);
     if ($canedit) {
         Html::initEditorSystem('text');
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_2'><td>" . __('Title') . "</td>";
     echo "<td>";
     if ($canedit) {
         Html::autocompletionTextField($this, "name", array('size' => 80, 'entity' => -1, 'user' => $this->fields["users_id"], 'option' => $onfocus));
     } else {
         echo $this->fields['name'];
     }
     echo "</td>\n";
     echo "<td>" . __('By') . "</td>";
     echo "<td>";
     echo getUserName($this->fields["users_id"]);
     if (!$ID) {
         echo "<input type='hidden' name='users_id' value='" . $this->fields['users_id'] . "'>\n";
     }
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Visibility') . "</td>";
     echo "<td>";
     echo '<table><tr><td>';
     echo __('Begin') . '</td><td>';
     Html::showDateTimeField("begin_view_date", array('value' => $this->fields["begin_view_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
     echo '</td><td>' . __('End') . '</td><td>';
     Html::showDateTimeField("end_view_date", array('value' => $this->fields["end_view_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
     echo '</td></tr></table>';
     echo "</td>";
     echo "<td>" . __('Status') . "</td>";
     echo "<td>";
     if ($canedit) {
         Planning::dropdownState("state", $this->fields["state"]);
     } else {
         echo Planning::getState($this->fields["state"]);
     }
     echo "</td>\n";
     echo "</tr>\n";
     echo "<tr class='tab_bg_2'><td >" . __('Calendar') . "</td>";
     echo "<td class='center'>";
     if ($canedit) {
         echo "<script type='text/javascript' >\n";
         echo "function showPlan() {\n";
         echo Html::jsHide('plan');
         $params = array('form' => 'remind', 'users_id' => $this->fields["users_id"], 'itemtype' => $this->getType(), 'items_id' => $this->getID());
         if ($ID && $this->fields["is_planned"]) {
             $params['begin'] = $this->fields["begin"];
             $params['end'] = $this->fields["end"];
         }
         Ajax::updateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params);
         echo "}";
         echo "</script>\n";
     }
     if (!$ID || !$this->fields["is_planned"]) {
         if (Session::haveRightsOr("planning", array(Planning::READMY, Planning::READGROUP, Planning::READALL))) {
             echo "<div id='plan' onClick='showPlan()'>\n";
             echo "<a href='#' class='vsubmit'>" . __('Add to schedule') . "</a>";
         }
     } else {
         if ($canedit) {
             echo "<div id='plan' onClick='showPlan()'>\n";
             echo "<span class='showplan'>";
         }
         //TRANS: %1$s is the begin date, %2$s is the end date
         printf(__('From %1$s to %2$s'), Html::convDateTime($this->fields["begin"]), Html::convDateTime($this->fields["end"]));
         if ($canedit) {
             echo "</span>";
         }
     }
     if ($canedit) {
         echo "</div>\n";
         echo "<div id='viewplan'>\n</div>\n";
     }
     echo "</td>";
     if ($ID && $this->fields["is_planned"] && PlanningRecall::isAvailable()) {
         echo "<td>" . _x('Planning', 'Reminder') . "</td>";
         echo "<td>";
         if ($canedit) {
             PlanningRecall::dropdown(array('itemtype' => 'Reminder', 'items_id' => $ID));
         } else {
             // No edit right : use specific Planning Recall Form
             PlanningRecall::specificForm(array('itemtype' => 'Reminder', 'items_id' => $ID));
         }
         echo "</td>";
     } else {
         echo "<td colspan='2'></td>";
     }
     echo "</tr>\n";
     echo "<tr class='tab_bg_2'><td>" . __('Description') . "</td>" . "<td colspan='3'>";
     if ($canedit) {
         echo "<textarea cols='115' rows='15' name='text'>" . $this->fields["text"] . "</textarea>";
     } else {
         echo "<div  id='kbanswer'>";
         echo Toolbox::unclean_html_cross_side_scripting_deep($this->fields["text"]);
         echo "</div>";
     }
     echo "</td></tr>\n";
     $this->showFormButtons($options);
     return true;
 }
Пример #17
0
    /** form for Task
     *
     * @param $ID        Integer : Id of the task
     * @param $options   array
     *     -  parent Object : the object
     **/
    function showForm($ID, $options = array())
    {
        global $DB, $CFG_GLPI;
        $rand_template = mt_rand();
        $rand_text = mt_rand();
        $rand_type = mt_rand();
        $rand_time = mt_rand();
        if (isset($options['parent']) && !empty($options['parent'])) {
            $item = $options['parent'];
        }
        $fkfield = $item->getForeignKeyField();
        if ($ID > 0) {
            $this->check($ID, READ);
        } else {
            // Create item
            $options[$fkfield] = $item->getField('id');
            $this->check(-1, CREATE, $options);
        }
        $rand = mt_rand();
        $this->showFormHeader($options);
        $canplan = !$item->isStatusExists(CommonITILObject::PLANNED) || $item->isAllowedStatus($item->fields['status'], CommonITILObject::PLANNED);
        $rowspan = 5;
        if ($this->maybePrivate()) {
            $rowspan++;
        }
        if (isset($this->fields["state"])) {
            $rowspan++;
        }
        echo "<tr class='tab_bg_1'>";
        echo "<td rowspan='{$rowspan}' style='width:100px'>" . __('Description') . "</td>";
        echo "<td rowspan='{$rowspan}' style='width:50%' id='content{$rand_text}'>" . "<textarea name='content' style='width: 95%; height: 160px' id='task{$rand_text}'>" . $this->fields["content"] . "</textarea>";
        echo Html::scriptBlock("\$(document).ready(function() { \$('#content{$rand}').autogrow(); });");
        echo "</td>";
        echo "<input type='hidden' name='{$fkfield}' value='" . $this->fields[$fkfield] . "'>";
        echo "</td></tr>\n";
        echo "<tr class='tab_bg_1'>";
        echo "<td style='width:100px'>" . _n('Task template', 'Task templates', 1) . "</td><td>";
        TaskTemplate::dropdown(array('value' => 0, 'entity' => $this->getEntityID(), 'rand' => $rand_template, 'on_change' => 'tasktemplate_update(this.value)'));
        echo "</td>";
        echo "</tr>";
        echo Html::scriptBlock('
         function tasktemplate_update(value) {
            jQuery.ajax({
               url: "' . $CFG_GLPI["root_doc"] . '/ajax/task.php",
               type: "POST",
               data: {
                  tasktemplates_id: value
               }
            }).done(function(datas) {
               datas.taskcategories_id = isNaN(parseInt(datas.taskcategories_id)) ? 0 : parseInt(datas.taskcategories_id);
               datas.actiontime = isNaN(parseInt(datas.actiontime)) ? 0 : parseInt(datas.actiontime);

               $("#task' . $rand_text . '").html(datas.content);
               $("#dropdown_taskcategories_id' . $rand_type . '").select2("val", parseInt(datas.taskcategories_id));
               $("#dropdown_actiontime' . $rand_time . '").select2("val", parseInt(datas.actiontime));
            });
         }
      ');
        if ($ID > 0) {
            echo "<tr class='tab_bg_1'>";
            echo "<td>" . __('Date') . "</td>";
            echo "<td>";
            Html::showDateTimeField("date", array('value' => $this->fields["date"], 'timestep' => 1, 'maybeempty' => false));
            echo "</tr>";
        } else {
            echo "<tr class='tab_bg_1'>";
            echo "<td colspan='2'>&nbsp;";
            echo "</tr>";
        }
        echo "<tr class='tab_bg_1'>";
        echo "<td>" . __('Category') . "</td><td>";
        TaskCategory::dropdown(array('value' => $this->fields["taskcategories_id"], 'rand' => $rand_type, 'entity' => $item->fields["entities_id"], 'condition' => "`is_active` = '1'"));
        echo "</td></tr>\n";
        if (isset($this->fields["state"])) {
            echo "<tr class='tab_bg_1'>";
            echo "<td>" . __('Status') . "</td><td>";
            Planning::dropdownState("state", $this->fields["state"]);
            echo "</td></tr>\n";
        }
        if ($this->maybePrivate()) {
            echo "<tr class='tab_bg_1'>";
            echo "<td>" . __('Private') . "</td>";
            echo "<td>";
            Dropdown::showYesNo('is_private', $this->fields["is_private"]);
            echo "</td>";
            echo "</tr>";
        }
        echo "<tr class='tab_bg_1'>";
        echo "<td>" . __('Duration') . "</td><td>";
        $toadd = array();
        for ($i = 9; $i <= 100; $i++) {
            $toadd[] = $i * HOUR_TIMESTAMP;
        }
        Dropdown::showTimeStamp("actiontime", array('min' => 0, 'max' => 8 * HOUR_TIMESTAMP, 'value' => $this->fields["actiontime"], 'rand' => $rand_time, 'addfirstminutes' => true, 'inhours' => true, 'toadd' => $toadd));
        echo "</td></tr>\n";
        if ($ID <= 0) {
            Document_Item::showSimpleAddForItem($item);
        }
        echo "<tr class='tab_bg_1'>";
        echo "<td>" . __('By') . "</td>";
        echo "<td colspan='2'>";
        echo Html::image($CFG_GLPI['root_doc'] . "/pics/user.png") . "&nbsp;";
        echo _n('User', 'Users', 1);
        $rand_user = mt_rand();
        $params = array('name' => "users_id_tech", 'value' => $ID > -1 ? $this->fields["users_id_tech"] : Session::getLoginUserID(), 'right' => "own_ticket", 'rand' => $rand_user, 'entity' => $item->fields["entities_id"], 'width' => '');
        $params['toupdate'] = array('value_fieldname' => 'users_id', 'to_update' => "user_available{$rand_user}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/planningcheck.php");
        User::dropdown($params);
        echo " <a href='#' onClick=\"" . Html::jsGetElementbyID('planningcheck' . $rand) . ".dialog('open');\">";
        echo "&nbsp;<img src='" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png'\n             title=\"" . __s('Availability') . "\" alt=\"" . __s('Availability') . "\"\n             class='calendrier'>";
        echo "</a>";
        Ajax::createIframeModalWindow('planningcheck' . $rand, $CFG_GLPI["root_doc"] . "/front/planning.php?checkavailability=checkavailability" . "&itemtype=" . $item->getType() . "&{$fkfield}=" . $item->getID(), array('title' => __('Availability')));
        echo "<br />";
        echo Html::image($CFG_GLPI['root_doc'] . "/pics/group.png") . "&nbsp;";
        echo _n('Group', 'Groups', 1) . "&nbsp;";
        $rand_group = mt_rand();
        $params = array('name' => "groups_id_tech", 'value' => $ID > -1 ? $this->fields["groups_id_tech"] : Dropdown::EMPTY_VALUE, 'condition' => "is_task", 'rand' => $rand_group, 'entity' => $item->fields["entities_id"]);
        $params['toupdate'] = array('value_fieldname' => 'users_id', 'to_update' => "group_available{$rand_group}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/planningcheck.php");
        Group::dropdown($params);
        echo "</td>\n";
        echo "<td>";
        if ($canplan) {
            echo __('Planning');
        }
        if (!empty($this->fields["begin"])) {
            if (Session::haveRight('planning', Planning::READMY)) {
                echo "<script type='text/javascript' >\n";
                echo "function showPlan" . $ID . $rand_text . "() {\n";
                echo Html::jsHide("plan{$rand_text}");
                $params = array('action' => 'add_event_classic_form', 'form' => 'followups', 'users_id' => $this->fields["users_id_tech"], 'groups_id' => $this->fields["groups_id_tech"], 'id' => $this->fields["id"], 'begin' => $this->fields["begin"], 'end' => $this->fields["end"], 'rand_user' => $rand_user, 'rand_group' => $rand_group, 'entity' => $item->fields["entities_id"], 'itemtype' => $this->getType(), 'items_id' => $this->getID());
                Ajax::updateItemJsCode("viewplan{$rand_text}", $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params);
                echo "}";
                echo "</script>\n";
                echo "<div id='plan{$rand_text}' onClick='showPlan" . $ID . $rand_text . "()'>\n";
                echo "<span class='showplan'>";
            }
            if (isset($this->fields["state"])) {
                echo Planning::getState($this->fields["state"]) . "<br>";
            }
            printf(__('From %1$s to %2$s'), Html::convDateTime($this->fields["begin"]), Html::convDateTime($this->fields["end"]));
            if (isset($this->fields["users_id_tech"]) && $this->fields["users_id_tech"] > 0) {
                echo "<br>" . getUserName($this->fields["users_id_tech"]);
            }
            if (isset($this->fields["groups_id_tech"]) && $this->fields["groups_id_tech"] > 0) {
                echo "<br>" . Dropdown::getDropdownName('glpi_groups', $this->fields["groups_id_tech"]);
            }
            if (Session::haveRight('planning', Planning::READMY)) {
                echo "</span>";
                echo "</div>\n";
                echo "<div id='viewplan{$rand_text}'></div>\n";
            }
        } else {
            if ($canplan) {
                echo "<script type='text/javascript' >\n";
                echo "function showPlanUpdate{$rand_text}() {\n";
                echo Html::jsHide("plan{$rand_text}");
                $params = array('action' => 'add_event_classic_form', 'form' => 'followups', 'entity' => $item->fields['entities_id'], 'rand_user' => $rand_user, 'rand_group' => $rand_group, 'itemtype' => $this->getType(), 'items_id' => $this->getID());
                Ajax::updateItemJsCode("viewplan{$rand_text}", $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params);
                echo "};";
                echo "</script>";
                if ($canplan) {
                    echo "<div id='plan{$rand_text}'  onClick='showPlanUpdate{$rand_text}()'>\n";
                    echo "<span class='vsubmit'>" . __('Plan this task') . "</span>";
                    echo "</div>\n";
                    echo "<div id='viewplan{$rand_text}'></div>\n";
                }
            } else {
                _e('None');
            }
        }
        echo "</td></tr>";
        if (!empty($this->fields["begin"]) && PlanningRecall::isAvailable()) {
            echo "<tr class='tab_bg_1'><td>" . _x('Planning', 'Reminder') . "</td><td class='center'>";
            PlanningRecall::dropdown(array('itemtype' => $this->getType(), 'items_id' => $this->getID()));
            echo "</td><td colspan='2'></td></tr>";
        }
        $this->showFormButtons($options);
        return true;
    }
Пример #18
0
 /**
  * Former front/planning.php before 9.1.
  * Display a classic form to plan an event (with begin fiel and duration)
  *
  * @since 9.1
  *
  * @param $params (array): array of parameters whou should contain :
  *   - id (integer): id of item who receive the planification
  *   - itemtype (string): itemtype of item who receive the planification
  *   - begin (string) : start date of event
  *   - end (optionnal) (string) : end date of event. Ifg missing, it will computerd from begin+1hour
  *   - rand_user (integer) : users_id to check planning avaibility
  */
 static function showAddEventClassicForm($params = array())
 {
     global $CFG_GLPI;
     if (isset($params["id"]) && $params["id"] > 0) {
         echo "<input type='hidden' name='plan[id]' value='" . $params["id"] . "'>";
     }
     $mintime = $CFG_GLPI["planning_begin"];
     if (isset($params["begin"]) && !empty($params["begin"])) {
         $begin = $params["begin"];
         $begintime = date("H:i:s", strtotime($begin));
         if ($begintime < $mintime) {
             $mintime = $begintime;
         }
     } else {
         $ts = $CFG_GLPI['time_step'] * 60;
         // passage en minutes
         $time = time() + $ts - 60;
         $time = floor($time / $ts) * $ts;
         $begin = date("Y-m-d H:i", $time);
     }
     if (isset($params["end"]) && !empty($params["end"])) {
         $end = $params["end"];
     } else {
         $end = date("Y-m-d H:i:s", strtotime($begin) + HOUR_TIMESTAMP);
     }
     echo "<table class='tab_cadre'>";
     echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>";
     $rand_begin = Html::showDateTimeField("plan[begin]", array('value' => $begin, 'timestep' => -1, 'maybeempty' => false, 'canedit' => true, 'mindate' => '', 'maxdate' => '', 'mintime' => $mintime, 'maxtime' => $CFG_GLPI["planning_end"]));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_2'><td>" . __('Period') . "&nbsp;";
     if (isset($params["rand_user"])) {
         echo "<span id='user_available" . $params["rand_user"] . "'>";
         include_once GLPI_ROOT . '/ajax/planningcheck.php';
         echo "</span>";
     }
     echo "</td><td>";
     $default_delay = floor((strtotime($end) - strtotime($begin)) / 15 / MINUTE_TIMESTAMP) * 15 * MINUTE_TIMESTAMP;
     $rand = Dropdown::showTimeStamp("plan[_duration]", array('min' => 0, 'max' => 50 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date')));
     echo "<br><div id='date_end{$rand}'></div>";
     $event_options = array('duration' => '__VALUE__', 'end' => $end, 'name' => "plan[end]", 'global_begin' => $CFG_GLPI["planning_begin"], 'global_end' => $CFG_GLPI["planning_end"]);
     Ajax::updateItemOnSelectEvent("dropdown_plan[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $event_options);
     if ($default_delay == 0) {
         $params['duration'] = 0;
         Ajax::updateItem("date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params);
     }
     echo "</td></tr>\n";
     if ((!isset($params["id"]) || $params["id"] == 0) && isset($params['itemtype']) && PlanningRecall::isAvailable()) {
         echo "<tr class='tab_bg_2'><td>" . _x('Planning', 'Reminder') . "</td><td>";
         PlanningRecall::dropdown(array('itemtype' => $params['itemtype'], 'items_id' => $params['items_id']));
         echo "</td></tr>";
     }
     echo "</table>\n";
 }
Пример #19
0
 /**
  * Print out an HTML "<form>" for knowbase item
  *
  * @param $ID
  * @param $options array
  *     - target for the Form
  *
  * @return nothing (display the form)
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     // show kb item form
     if (!Session::haveRightsOr(self::$rightname, array(UPDATE, self::PUBLISHFAQ, self::KNOWBASEADMIN))) {
         return false;
     }
     $this->initForm($ID, $options);
     $canedit = $this->can($ID, UPDATE);
     // Load ticket solution
     if (empty($ID) && isset($options['item_itemtype']) && !empty($options['item_itemtype']) && isset($options['item_items_id']) && !empty($options['item_items_id'])) {
         if ($item = getItemForItemtype($options['item_itemtype'])) {
             if ($item->getFromDB($options['item_items_id'])) {
                 $this->fields['name'] = $item->getField('name');
                 $this->fields['answer'] = $item->getField('solution');
                 if ($item->isField('itilcategories_id')) {
                     $ic = new ItilCategory();
                     if ($ic->getFromDB($item->getField('itilcategories_id'))) {
                         $this->fields['knowbaseitemcategories_id'] = $ic->getField('knowbaseitemcategories_id');
                     }
                 }
             }
         }
     }
     $rand = mt_rand();
     Html::initEditorSystem('answer');
     $this->initForm($ID, $options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Category name') . "</td>";
     echo "<td>";
     echo "<input type='hidden' name='users_id' value=\"" . Session::getLoginUserID() . "\">";
     KnowbaseItemCategory::dropdown(array('value' => $this->fields["knowbaseitemcategories_id"]));
     echo "</td>";
     echo "<td>";
     if ($this->fields["date"]) {
         //TRANS: %s is the datetime of insertion
         printf(__('Created on %s'), Html::convDateTime($this->fields["date"]));
     }
     echo "</td><td>";
     if ($this->fields["date_mod"]) {
         //TRANS: %s is the datetime of update
         printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
     }
     echo "</td>";
     echo "</tr>\n";
     echo "<tr class='tab_bg_1'>";
     if (Session::haveRight(self::$rightname, self::PUBLISHFAQ)) {
         echo "<td>" . __('Put this item in the FAQ') . "</td>";
         echo "<td>";
         Dropdown::showYesNo('is_faq', $this->fields["is_faq"]);
         echo "</td>";
     } else {
         echo "<td colspan='2'>";
         if ($this->fields["is_faq"]) {
             _e('This item is part of the FAQ');
         } else {
             _e('This item is not part of the FAQ');
         }
         echo "</td>";
     }
     echo "<td>";
     $showuserlink = 0;
     if (Session::haveRight('user', READ)) {
         $showuserlink = 1;
     }
     if ($this->fields["users_id"]) {
         //TRANS: %s is the writer name
         printf(__('%1$s: %2$s'), __('Writer'), getUserName($this->fields["users_id"], $showuserlink));
     }
     echo "</td><td>";
     //TRANS: %d is the number of view
     if ($ID) {
         printf(_n('%d view', '%d views', $this->fields["view"]), $this->fields["view"]);
     }
     echo "</td>";
     echo "</tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Visible since') . "</td><td>";
     Html::showDateTimeField("begin_date", array('value' => $this->fields["begin_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
     echo "</td>";
     echo "<td>" . __('Visible until') . "</td><td>";
     Html::showDateTimeField("end_date", array('value' => $this->fields["end_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Subject') . "</td>";
     echo "<td colspan='3'>";
     echo "<textarea cols='100' rows='1' name='name'>" . $this->fields["name"] . "</textarea>";
     echo "</td>";
     echo "</tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Content') . "</td>";
     echo "<td colspan='3'>";
     $cols = 100;
     $rows = 30;
     if (isset($options['_in_modal']) && $options['_in_modal']) {
         $rows = 15;
         echo Html::hidden('_in_modal', array('value' => 1));
     }
     echo "<textarea cols='{$cols}' rows='{$rows}' id='answer' name='answer'>" . $this->fields["answer"];
     echo "</textarea>";
     echo "</td>";
     echo "</tr>\n";
     if ($this->isNewID($ID)) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . _n('Target', 'Targets', 1) . "</td>";
         echo "<td>";
         $types = array('Entity', 'Group', 'Profile', 'User');
         $addrand = Dropdown::showItemTypes('_visibility[_type]', $types);
         echo "</td><td colspan='2'>";
         $params = array('type' => '__VALUE__', 'right' => 'knowbase', 'prefix' => '_visibility', 'nobutton' => 1);
         Ajax::updateItemOnSelectEvent("dropdown__visibility__type_" . $addrand, "visibility{$rand}", $CFG_GLPI["root_doc"] . "/ajax/visibility.php", $params);
         echo "<span id='visibility{$rand}'></span>";
         echo "</td></tr>\n";
     }
     $this->showFormButtons($options);
     return true;
 }
Пример #20
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
$AJAX_INCLUDE = 1;
include '../inc/includes.php';
// Send UTF8 Headers
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
if (isset($_POST['value']) && strcmp($_POST['value'], '0') == 0) {
    if ($_POST['withtime']) {
        Html::showDateTimeField($_POST['name'], array('value' => $_POST['specificvalue']));
    } else {
        Html::showDateField($_POST['name'], array('value' => $_POST['specificvalue']));
    }
} else {
    echo "<input type='hidden' name='" . $_POST['name'] . "' value='" . $_POST['value'] . "'>";
}
Пример #21
0
 /**
  * Print the user form
  *
  * @param $ID        integer : Id of the user
  * @param $options   array
  *     - target form target
  *     - withtemplate boolean : template or basic item
  *
  * @return boolean : user found
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     // Affiche un formulaire User
     if ($ID != Session::getLoginUserID() && !self::canView()) {
         return false;
     }
     $this->initForm($ID, $options);
     if ($ID) {
         $caneditpassword = $this->currentUserHaveMoreRightThan($ID);
     } else {
         // can edit on creation form
         $caneditpassword = true;
     }
     $extauth = !($this->fields["authtype"] == Auth::DB_GLPI || $this->fields["authtype"] == Auth::NOT_YET_AUTHENTIFIED && !empty($this->fields["password"]));
     $options['formoptions'] = " enctype='multipart/form-data'";
     $this->showFormHeader($options);
     $rand = mt_rand();
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Login') . "</td>";
     // si on est dans le cas d'un ajout , cet input ne doit plus etre hidden
     if ($this->fields["name"] == "") {
         echo "<td><input name='name' value=\"" . $this->fields["name"] . "\"></td>";
         // si on est dans le cas d'un modif on affiche la modif du login si ce n'est pas une auth externe
     } else {
         if (!empty($this->fields["password"]) || $this->fields["authtype"] == Auth::DB_GLPI) {
             echo "<td>";
             echo "<input name='name' value=\"" . $this->fields["name"] . "\"></td>";
         } else {
             echo "<td class='b'>" . $this->fields["name"];
             echo "<input type='hidden' name='name' value=\"" . $this->fields["name"] . "\"></td>";
         }
     }
     if (!empty($this->fields["name"])) {
         echo "<td rowspan='3'>" . __('Picture') . "</td>";
         echo "<td rowspan='3'>";
         echo "<div class='user_picture_border_small' id='picture{$rand}'>";
         echo "<img class='user_picture_small' alt=\"" . __s('Picture') . "\" src='" . User::getThumbnailURLForPicture($this->fields['picture']) . "'>";
         //         echo "<img src='".self::getURLForPicture($this->fields["picture"])."' class='user_picture'/>";
         echo "</div>";
         $full_picture = "<div class='user_picture_border'>";
         $full_picture .= "<img class='user_picture' alt=\"" . __s('Picture') . "\" src='" . User::getURLForPicture($this->fields['picture']) . "'>";
         $full_picture .= "</div>";
         Html::showTooltip($full_picture, array('applyto' => "picture{$rand}"));
         echo "<input type='file' name='picture' accept='image/*'>";
         echo "<input type='checkbox' name='_blank_picture'>&nbsp;" . __('Clear');
         echo "</td>";
     } else {
         echo "<td rowspan='3'></td>";
         echo "<td rowspan='3'></td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Surname') . "</td><td>";
     Html::autocompletionTextField($this, "realname");
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('First name') . "</td><td>";
     Html::autocompletionTextField($this, "firstname");
     echo "</td></tr>";
     //do some rights verification
     if (self::canUpdate() && (!$extauth || empty($ID)) && $caneditpassword) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Password') . "</td>";
         echo "<td><input id='password' type='password' name='password' value='' size='20'\n                    autocomplete='off' onkeyup=\"return passwordCheck();\"></td>";
         echo "<td rowspan='2'>" . __('Password security policy') . "</td>";
         echo "<td rowspan='2'>";
         Config::displayPasswordSecurityChecks();
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Password confirmation') . "</td>";
         echo "<td><input type='password' name='password2' value='' size='20' autocomplete='off'>";
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1'>";
     if (!GLPI_DEMO_MODE) {
         echo "<td>" . __('Active') . "</td><td>";
         Dropdown::showYesNo('is_active', $this->fields['is_active']);
         echo "</td>";
     } else {
         echo "<td colspan='2'></td>";
     }
     echo "<td>" . _n('Email', 'Emails', Session::getPluralNumber());
     UserEmail::showAddEmailButton($this);
     echo "</td><td>";
     UserEmail::showForUser($this);
     echo "</td>";
     echo "</tr>";
     if (!GLPI_DEMO_MODE) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Valid since') . "</td><td>";
         Html::showDateTimeField("begin_date", array('value' => $this->fields["begin_date"], 'timestep' => 1, 'maybeempty' => true));
         echo "</td>";
         echo "<td>" . __('Valid until') . "</td><td>";
         Html::showDateTimeField("end_date", array('value' => $this->fields["end_date"], 'timestep' => 1, 'maybeempty' => true));
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Phone') . "</td><td>";
     Html::autocompletionTextField($this, "phone");
     echo "</td>";
     //Authentications information : auth method used and server used
     //don't display is creation of a new user'
     if (!empty($ID)) {
         if (Session::haveRight(self::$rightname, self::READAUTHENT)) {
             echo "<td>" . __('Authentication') . "</td><td>";
             echo Auth::getMethodName($this->fields["authtype"], $this->fields["auths_id"]);
             if (!empty($this->fields["date_sync"])) {
                 //TRANS: %s is the date of last sync
                 echo '<br>' . sprintf(__('Last synchronization on %s'), HTML::convDateTime($this->fields["date_sync"]));
             }
             if (!empty($this->fields["user_dn"])) {
                 //TRANS: %s is the user dn
                 echo '<br>' . sprintf(__('%1$s: %2$s'), __('User DN'), $this->fields["user_dn"]);
             }
             if ($this->fields['is_deleted_ldap']) {
                 echo '<br>' . __('User missing in LDAP directory');
             }
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
     } else {
         echo "<td colspan='2'><input type='hidden' name='authtype' value='1'></td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Mobile phone') . "</td><td>";
     Html::autocompletionTextField($this, "mobile");
     echo "</td>";
     echo "<td>" . __('Category') . "</td><td>";
     UserCategory::dropdown(array('value' => $this->fields["usercategories_id"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Phone 2') . "</td><td>";
     Html::autocompletionTextField($this, "phone2");
     echo "</td>";
     echo "<td rowspan='4' class='middle'>" . __('Comments') . "</td>";
     echo "<td class='center middle' rowspan='4'>";
     echo "<textarea cols='45' rows='6' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Administrative number') . "</td><td>";
     Html::autocompletionTextField($this, "registration_number");
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . _x('person', 'Title') . "&nbsp;:</td><td>";
     UserTitle::dropdown(array('value' => $this->fields["usertitles_id"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     if (!empty($ID)) {
         echo "<td>" . __('Location') . "</td><td>";
         $entities = Profile_User::getUserEntities($ID, true);
         if (count($entities) <= 0) {
             $entities = -1;
         }
         Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $entities));
         echo "</td>";
     }
     echo "</tr>";
     if (empty($ID)) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'>" . _n('Authorization', 'Authorizations', 1) . "</th>";
         echo "<td>" . __('Recursive') . "</td><td>";
         Dropdown::showYesNo("_is_recursive", 0);
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Profile') . "</td><td>";
         Profile::dropdownUnder(array('name' => '_profiles_id', 'value' => Profile::getDefault()));
         echo "</td><td>" . __('Entity') . "</td><td>";
         Entity::dropdown(array('name' => '_entities_id', 'display_emptychoice' => false, 'entity' => $_SESSION['glpiactiveentities']));
         echo "</td></tr>";
     } else {
         if ($caneditpassword) {
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . __('Default profile') . "</td><td>";
             $options = Dropdown::getDropdownArrayNames('glpi_profiles', Profile_User::getUserProfiles($this->fields['id']));
             Dropdown::showFromArray("profiles_id", $options, array('value' => $this->fields["profiles_id"], 'display_emptychoice' => true));
             echo "</td><td>" . __('Default entity') . "</td><td>";
             $entities = Profile_User::getUserEntities($this->fields['id'], 1);
             Entity::dropdown(array('value' => $this->fields["entities_id"], 'entity' => $entities));
             echo "</td></tr>";
         }
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2' class='center'>";
         //TRANS: %s is the date
         printf(__('Last update on %s'), HTML::convDateTime($this->fields["date_mod"]));
         echo "<br>";
         printf(__('Last login on %s'), HTML::convDateTime($this->fields["last_login"]));
         echo "</td><td colspan='2'class='center'>";
         if ($ID > 0) {
             echo "<a target='_blank' href='" . $CFG_GLPI["root_doc"] . "/front/user.form.php?getvcard=1&amp;id={$ID}'>" . __('Vcard') . "</a>";
         }
         echo "</td></tr>";
     }
     $this->showFormButtons($options);
     return true;
 }
Пример #22
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
$AJAX_INCLUDE = 1;
include '../inc/includes.php';
// Send UTF8 Headers
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkLoginUser();
if (isset($_POST['duration']) && $_POST['duration'] == 0 && isset($_POST['name'])) {
    if (!isset($_POST['global_begin'])) {
        $_POST['global_begin'] = '';
    }
    if (!isset($_POST['global_end'])) {
        $_POST['global_end'] = '';
    }
    Html::showDateTimeField($_POST['name'], array('value' => $_POST['end'], 'timestep' => -1, 'maybeempty' => false, 'canedit' => true, 'mindate' => '', 'maxdate' => '', 'mintime' => $_POST['global_begin'], 'maxtime' => $_POST['global_end']));
}
Пример #23
0
 /**
  * @param $options  array
  **/
 static function showDateRestrictionForm($options = array())
 {
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_2'>";
     $enabled = isset($options['enabled']) ? $options['enabled'] : false;
     if (!$enabled) {
         echo "<td colspan='4' class='center'>";
         echo "<a href='#' onClick='activateRestriction()'>" . __('Enable filtering by date') . "</a>";
         echo "</td></tr>";
     }
     if ($enabled) {
         echo "<td>" . __('View updated users') . "</td>";
         echo "<td>" . __('from') . "</td>";
         echo "<td>";
         $begin_date = isset($_SESSION['ldap_import']['begin_date']) ? $_SESSION['ldap_import']['begin_date'] : '';
         Html::showDateTimeField("begin_date", array('value' => $begin_date, 'timestep' => 1));
         echo "</td>";
         echo "<td>" . __('to') . "</td>";
         echo "<td>";
         $end_date = isset($_SESSION['ldap_import']['end_date']) ? $_SESSION['ldap_import']['end_date'] : date('Y-m-d H:i:s', time() - DAY_TIMESTAMP);
         Html::showDateTimeField("end_date", array('value' => $end_date, 'timestep' => 1));
         echo "</td></tr>";
         echo "<tr class='tab_bg_2'><td colspan='4' class='center'>";
         echo "<a href='#' onClick='deactivateRestriction()'>" . __('Disable filtering by date') . "</a>";
         echo "</td></tr>";
     }
     echo "</table>";
 }
Пример #24
0
 /**
  * Print the Project task form
  *
  * @param $ID        integer  Id of the project task
  * @param $options   array    of possible options:
  *     - target form target
  *     - projects_id ID of the software for add process
  *
  * @return true if displayed  false if item not found or not right to display
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if ($ID > 0) {
         $this->check($ID, READ);
         $projects_id = $this->fields['projects_id'];
         $projecttasks_id = $this->fields['projecttasks_id'];
     } else {
         $projects_id = $options['projects_id'];
         $projecttasks_id = $options['projecttasks_id'];
         $this->check(-1, CREATE, $options);
     }
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'><td>" . _n('Project', 'Projects', Session::getPluralNumber()) . "</td>";
     echo "<td>";
     if ($this->isNewID($ID)) {
         echo "<input type='hidden' name='projects_id' value='{$projects_id}'>";
     }
     echo "<a href='project.form.php?id=" . $projects_id . "'>" . Dropdown::getDropdownName("glpi_projects", $projects_id) . "</a>";
     echo "</td>";
     echo "<td>" . __('As child of') . "</td>";
     echo "<td>";
     $this->dropdown(array('entity' => $this->fields['entities_id'], 'value' => $projecttasks_id, 'condition' => "`glpi_projecttasks`.`projects_id`='" . $this->fields['projects_id'] . "'", 'used' => array($this->fields['id'])));
     echo "</td></tr>";
     $showuserlink = 0;
     if (Session::haveRight('user', READ)) {
         $showuserlink = 1;
     }
     if ($ID) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Creation date') . "</td>";
         echo "<td>";
         echo sprintf(__('%1$s by %2$s'), Html::convDateTime($this->fields["date"]), getUserName($this->fields["users_id"], $showuserlink));
         echo "</td>";
         echo "<td>" . __('Last update') . "</td>";
         echo "<td>";
         echo Html::convDateTime($this->fields["date_mod"]);
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
     echo "<td colspan='3'>";
     Html::autocompletionTextField($this, "name", array('size' => 80));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . _x('item', 'State') . "</td>";
     echo "<td>";
     ProjectState::dropdown(array('value' => $this->fields["projectstates_id"]));
     echo "</td>";
     echo "<td>" . __('Type') . "</td>";
     echo "<td>";
     ProjectTaskType::dropdown(array('value' => $this->fields["projecttasktypes_id"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Percent done') . "</td>";
     echo "<td>";
     Dropdown::showNumber("percent_done", array('value' => $this->fields['percent_done'], 'min' => 0, 'max' => 100, 'step' => 5, 'unit' => '%'));
     echo "</td>";
     echo "<td>";
     _e('Milestone');
     echo "</td>";
     echo "<td>";
     Dropdown::showYesNo("is_milestone", $this->fields["is_milestone"]);
     echo "</td>";
     echo "</tr>";
     echo "<tr><td colspan='4' class='subheader'>" . __('Planning') . "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned start date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("plan_start_date", array('value' => $this->fields['plan_start_date']));
     echo "</td>";
     echo "<td>" . __('Real start date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("real_start_date", array('value' => $this->fields['real_start_date']));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned end date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("plan_end_date", array('value' => $this->fields['plan_end_date']));
     echo "</td>";
     echo "<td>" . __('Real end date') . "</td>";
     echo "<td>";
     Html::showDateTimeField("real_end_date", array('value' => $this->fields['real_end_date']));
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Planned duration') . "</td>";
     echo "<td>";
     Dropdown::showTimeStamp("planned_duration", array('min' => 0, 'max' => 100 * HOUR_TIMESTAMP, 'step' => HOUR_TIMESTAMP, 'value' => $this->fields["planned_duration"], 'addfirstminutes' => true, 'inhours' => true));
     echo "</td>";
     echo "<td>" . __('Effective duration') . "</td>";
     echo "<td>";
     Dropdown::showTimeStamp("effective_duration", array('min' => 0, 'max' => 100 * HOUR_TIMESTAMP, 'step' => HOUR_TIMESTAMP, 'value' => $this->fields["effective_duration"], 'addfirstminutes' => true, 'inhours' => true));
     if ($ID) {
         $ticket_duration = ProjectTask_Ticket::getTicketsTotalActionTime($this->getID());
         echo "<br>";
         printf(__('%1$s: %2$s'), __('Tickets duration'), Html::timestampToString($ticket_duration, false));
         echo '<br>';
         printf(__('%1$s: %2$s'), __('Total duration'), Html::timestampToString($ticket_duration + $this->fields["effective_duration"], false));
     }
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Description') . "</td>";
     echo "<td colspan='3'>";
     echo "<textarea id='content' name='content' cols='90' rows='6'>" . $this->fields["content"] . "</textarea>";
     echo "</td></tr>\n";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Comments') . "</td>";
     echo "<td colspan='3'>";
     echo "<textarea id='comment' name='comment' cols='90' rows='6'>" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>\n";
     $this->showFormButtons($options);
     return true;
 }
    $begin = $_POST["begin"];
} else {
    $minute = floor(date('i') / 10) * 10;
    if ($minute < 10) {
        $minute = '0' . $minute;
    }
    $begin = date("Y-m-d H") . ":{$minute}:00";
}
if (isset($_POST["end"]) && !empty($_POST["end"])) {
    $end = $_POST["end"];
} else {
    $end = date("Y-m-d H:i:s", strtotime($begin) + HOUR_TIMESTAMP);
}
echo "<table class='tab_cadre'>";
echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>";
$rand_begin = Html::showDateTimeField("plan[begin]", array('value' => $begin, 'timestep' => -1, 'maybeempty' => false, 'canedit' => true, 'mindate' => '', 'maxdate' => '', 'mintime' => $CFG_GLPI["planning_begin"], 'maxtime' => $CFG_GLPI["planning_end"]));
echo "</td></tr>\n";
echo "<tr class='tab_bg_2'><td>" . __('Period') . "&nbsp;";
if (isset($_POST["rand_user"])) {
    echo "<span id='user_available" . $_POST["rand_user"] . "'>";
    include_once GLPI_ROOT . '/ajax/planningcheck.php';
    echo "</span>";
}
echo "</td><td>";
$default_delay = floor((strtotime($end) - strtotime($begin)) / 15 / MINUTE_TIMESTAMP) * 15 * MINUTE_TIMESTAMP;
$rand = Dropdown::showTimeStamp("plan[_duration]", array('min' => 0, 'max' => 50 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date')));
echo "<br><div id='date_end{$rand}'></div>";
$params = array('duration' => '__VALUE__', 'end' => $end, 'name' => "plan[end]", 'global_begin' => $CFG_GLPI["planning_begin"], 'global_end' => $CFG_GLPI["planning_end"]);
Ajax::updateItemOnSelectEvent("dropdown_plan[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params);
if ($default_delay == 0) {
    $params['duration'] = 0;
Пример #26
0
 /**
  * Show SLT for ticket
  *
  * @param $ticket      Ticket item
  * @param $type
  * @param $tt
  * @param $canupdate
  **/
 function showSltForTicket(Ticket $ticket, $type, $tt, $canupdate)
 {
     global $CFG_GLPI;
     list($dateField, $sltField) = self::getSltFieldNames($type);
     echo "<table width='100%'>";
     echo "<tr class='tab_bg_1'>";
     if (!isset($ticket->fields[$dateField]) || $ticket->fields[$dateField] == 'NULL') {
         $ticket->fields[$dateField] = '';
     }
     if ($ticket->fields['id']) {
         if ($this->getSltDataForTicket($ticket->fields['id'], $type)) {
             echo "<td>";
             echo Html::convDateTime($ticket->fields[$dateField]);
             echo "</td>";
             echo "<th>" . __('SLT') . "</th>";
             echo "<td>";
             echo Dropdown::getDropdownName('glpi_slts', $ticket->fields[$sltField]) . "&nbsp;";
             $commentsla = "";
             $slalevel = new SlaLevel();
             $nextaction = new SlaLevel_Ticket();
             if ($nextaction->getFromDBForTicket($ticket->fields["id"], $type)) {
                 $commentsla .= '<span class="b spaced">' . sprintf(__('Next escalation: %s'), Html::convDateTime($nextaction->fields['date'])) . '</span><br>';
                 if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) {
                     $commentsla .= '<span class="b spaced">' . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()) . '</span>';
                 }
             }
             $slaoptions = array();
             if (Session::haveRight('sla', READ)) {
                 $slaoptions['link'] = Toolbox::getItemTypeFormURL('SLT') . "?id=" . $this->fields["id"];
             }
             Html::showToolTip($commentsla, $slaoptions);
             if ($canupdate) {
                 $fields = array('slt_delete' => 'slt_delete', 'id' => $ticket->getID(), 'type' => $type, '_glpi_csrf_token' => Session::getNewCSRFToken(), '_glpi_simple_form' => 1);
                 $JS = "  function delete_date{$type}(){\n                           if (nativeConfirm('" . addslashes(__('Also delete date ?')) . "')) {\n                              submitGetLink('" . $ticket->getFormURL() . "',\n                                            " . json_encode(array_merge($fields, array('delete_date' => 1))) . ");\n                           } else {\n                              submitGetLink('" . $ticket->getFormURL() . "',\n                                            " . json_encode(array_merge($fields, array('delete_date' => 0))) . ");\n                           }\n                        }";
                 echo Html::scriptBlock($JS);
                 echo "<a class='pointer' onclick='delete_date{$type}();return false;'>";
                 echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/delete.png' title='" . _x('button', 'Delete permanently') . "' " . "alt='" . _x('button', 'Delete permanently') . "' class='pointer'>";
                 echo "</a>";
             }
             echo "</td>";
         } else {
             echo "<td width='200px'>";
             echo $tt->getBeginHiddenFieldValue($dateField);
             if ($canupdate) {
                 Html::showDateTimeField($dateField, array('value' => $ticket->fields[$dateField], 'timestep' => 1, 'maybeempty' => true));
             } else {
                 echo Html::convDateTime($ticket->fields[$dateField]);
             }
             echo $tt->getEndHiddenFieldValue($dateField, $ticket);
             echo "</td>";
             $slt_data = $this->getSltData("`type` = '{$type}'\n                                           AND `entities_id` = '" . $ticket->fields['entities_id'] . "'");
             if ($canupdate && !empty($slt_data)) {
                 echo "<td>";
                 echo $tt->getBeginHiddenFieldText($sltField);
                 echo "<span id='slt_action{$type}'>";
                 echo "<a " . Html::addConfirmationOnAction(array(__('The assignment of a SLT to a ticket causes the recalculation of the date.'), __("Escalations defined in the SLT will be triggered under this new date.")), "cleanhide('slt_action{$type}');cleandisplay('slt_choice{$type}');") . "><img src='" . $CFG_GLPI['root_doc'] . "/pics/clock.png' title='" . __('SLT') . "' alt='" . __('SLT') . "' class='pointer'></a>";
                 echo "</span>";
                 echo "<div id='slt_choice{$type}' style='display:none'>";
                 echo "<span  class='b'>" . __('SLT') . "</span>&nbsp;";
                 Slt::dropdown(array('name' => $sltField, 'entity' => $ticket->fields["entities_id"], 'condition' => "`type` = '" . $type . "'"));
                 echo "</div>";
                 echo $tt->getEndHiddenFieldText($sltField);
                 echo "</td>";
             }
         }
     } else {
         // New Ticket
         echo "<td>";
         echo $tt->getBeginHiddenFieldValue($dateField);
         Html::showDateTimeField($dateField, array('value' => $ticket->fields[$dateField], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate));
         echo $tt->getEndHiddenFieldValue($dateField, $ticket);
         echo "</td>";
         $slt_data = $this->getSltData("`type` = '{$type}'\n                                        AND `entities_id` = '" . $ticket->fields['entities_id'] . "'");
         if ($canupdate && !empty($slt_data)) {
             echo "<th>" . $tt->getBeginHiddenFieldText($sltField);
             printf(__('%1$s%2$s'), __('SLT'), $tt->getMandatoryMark($sltField));
             echo $tt->getEndHiddenFieldText('slas_id') . "</th>";
             echo "<td class='nopadding'>" . $tt->getBeginHiddenFieldValue($sltField);
             Slt::dropdown(array('name' => $sltField, 'entity' => $ticket->fields["entities_id"], 'value' => isset($ticket->fields[$sltField]) ? $ticket->fields[$sltField] : 0, 'condition' => "`type` = '" . $type . "'"));
             echo $tt->getEndHiddenFieldValue($sltField, $ticket);
             echo "</td>";
         }
     }
     echo "</tr>";
     echo "</table>";
 }
Пример #27
0
 static function showListSimple()
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight(self::$rightname, self::RESERVEANITEM)) {
         return false;
     }
     $ri = new self();
     $ok = false;
     $showentity = Session::isMultiEntitiesMode();
     $values = array();
     if (isset($_SESSION['glpi_saved']['ReservationItem'])) {
         $_POST = $_SESSION['glpi_saved']['ReservationItem'];
     }
     if (isset($_POST['reserve'])) {
         echo "<div id='viewresasearch'  class='center'>";
         Toolbox::manageBeginAndEndPlanDates($_POST['reserve']);
         echo "<div id='nosearch' class='center firstbloc'>" . "<a href=\"" . $CFG_GLPI['root_doc'] . "/front/reservationitem.php\">";
         echo __('See all reservable items') . "</a></div>\n";
     } else {
         echo "<div id='makesearch' class='center firstbloc'>" . "<a class='pointer' onClick=\"javascript:showHideDiv('viewresasearch','','','');" . "showHideDiv('makesearch','','','')\">";
         echo __('Find a free item in a specific period') . "</a></div>\n";
         echo "<div id='viewresasearch' style=\"display:none;\" class='center'>";
         $begin_time = time();
         $begin_time -= $begin_time % HOUR_TIMESTAMP;
         $_POST['reserve']["begin"] = date("Y-m-d H:i:s", $begin_time);
         $_POST['reserve']["end"] = date("Y-m-d H:i:s", $begin_time + HOUR_TIMESTAMP);
         $_POST['reservation_types'] = '';
     }
     echo "<form method='post' name='form' action='" . Toolbox::getItemTypeSearchURL(__CLASS__) . "'>";
     echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2'>";
     echo "<th colspan='3'>" . __('Find a free item in a specific period') . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>";
     Html::showDateTimeField("reserve[begin]", array('value' => $_POST['reserve']["begin"], 'maybeempty' => false));
     echo "</td><td rowspan='3'>";
     echo "<input type='submit' class='submit' name='submit' value=\"" . _sx('button', 'Search') . "\">";
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Duration') . "</td><td>";
     $default_delay = floor((strtotime($_POST['reserve']["end"]) - strtotime($_POST['reserve']["begin"])) / $CFG_GLPI['time_step'] / MINUTE_TIMESTAMP) * $CFG_GLPI['time_step'] * MINUTE_TIMESTAMP;
     $rand = Dropdown::showTimeStamp("reserve[_duration]", array('min' => 0, 'max' => 48 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date')));
     echo "<br><div id='date_end{$rand}'></div>";
     $params = array('duration' => '__VALUE__', 'end' => $_POST['reserve']["end"], 'name' => "reserve[end]");
     Ajax::updateItemOnSelectEvent("dropdown_reserve[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params);
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Item type') . "</td><td>";
     $sql = "SELECT DISTINCT(`itemtype`)\n              FROM `glpi_reservationitems`\n              WHERE `is_active` = 1" . getEntitiesRestrictRequest(" AND", 'glpi_reservationitems', 'entities_id', $_SESSION['glpiactiveentities']);
     $result = $DB->query($sql);
     while ($data = $DB->fetch_assoc($result)) {
         $values[$data['itemtype']] = $data['itemtype']::getTypeName();
     }
     $query = "SELECT `glpi_peripheraltypes`.`name`, `glpi_peripheraltypes`.`id`\n                FROM `glpi_peripheraltypes`\n                LEFT JOIN `glpi_peripherals`\n                  ON `glpi_peripherals`.`peripheraltypes_id` = `glpi_peripheraltypes`.`id`\n                LEFT JOIN `glpi_reservationitems`\n                  ON `glpi_reservationitems`.`items_id` = `glpi_peripherals`.`id`\n                WHERE `itemtype` = 'Peripheral'\n                      AND `is_active` = 1\n                      AND `peripheraltypes_id`" . getEntitiesRestrictRequest(" AND", 'glpi_reservationitems', 'entities_id', $_SESSION['glpiactiveentities']) . "\n                ORDER BY `glpi_peripheraltypes`.`name`";
     foreach ($DB->request($query) as $ptype) {
         $id = $ptype['id'];
         $values["Peripheral#{$id}"] = $ptype['name'];
     }
     Dropdown::showFromArray("reservation_types", $values, array('value' => $_POST['reservation_types'], 'display_emptychoice' => true));
     echo "</td></tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
     // GET method passed to form creation
     echo "<div id='nosearch' class='center'>";
     echo "<form name='form' method='GET' action='reservation.form.php'>";
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr><th colspan='" . ($showentity ? "5" : "4") . "'>" . self::getTypeName(1) . "</th></tr>\n";
     foreach ($CFG_GLPI["reservation_types"] as $itemtype) {
         if (!($item = getItemForItemtype($itemtype))) {
             continue;
         }
         $itemtable = getTableForItemType($itemtype);
         $otherserial = "'' AS otherserial";
         if ($item->isField('otherserial')) {
             $otherserial = "`{$itemtable}`.`otherserial`";
         }
         $begin = $_POST['reserve']["begin"];
         $end = $_POST['reserve']["end"];
         $left = "";
         $where = "";
         if (isset($_POST['submit']) && isset($begin) && isset($end)) {
             $left = "LEFT JOIN `glpi_reservations`\n                        ON (`glpi_reservationitems`.`id` = `glpi_reservations`.`reservationitems_id`\n                            AND '" . $begin . "' < `glpi_reservations`.`end`\n                            AND '" . $end . "' > `glpi_reservations`.`begin`)";
             $where = " AND `glpi_reservations`.`id` IS NULL ";
         }
         if (isset($_POST["reservation_types"]) && !empty($_POST["reservation_types"])) {
             $tmp = explode('#', $_POST["reservation_types"]);
             $where .= " AND `glpi_reservationitems`.`itemtype` = '" . $tmp[0] . "'";
             if (isset($tmp[1]) && $tmp[0] == 'Peripheral' && $itemtype == 'Peripheral') {
                 $left .= " LEFT JOIN `glpi_peripheraltypes`\n                              ON (`glpi_peripherals`.`peripheraltypes_id` = `glpi_peripheraltypes`.`id`)";
                 $where .= " AND `{$itemtable}`.`peripheraltypes_id` = '" . $tmp[1] . "'";
             }
         }
         $query = "SELECT `glpi_reservationitems`.`id`,\n                          `glpi_reservationitems`.`comment`,\n                          `{$itemtable}`.`name` AS name,\n                          `{$itemtable}`.`entities_id` AS entities_id,\n                          {$otherserial},\n                          `glpi_locations`.`id` AS location,\n                          `glpi_reservationitems`.`items_id` AS items_id\n                   FROM `glpi_reservationitems`\n                   INNER JOIN `{$itemtable}`\n                        ON (`glpi_reservationitems`.`itemtype` = '{$itemtype}'\n                            AND `glpi_reservationitems`.`items_id` = `{$itemtable}`.`id`)\n                   {$left}\n                   LEFT JOIN `glpi_locations`\n                        ON (`{$itemtable}`.`locations_id` = `glpi_locations`.`id`)\n                   WHERE `glpi_reservationitems`.`is_active` = '1'\n                         AND `glpi_reservationitems`.`is_deleted` = '0'\n                         AND `{$itemtable}`.`is_deleted` = '0'\n                         {$where} " . getEntitiesRestrictRequest(" AND", $itemtable, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive()) . "\n                   ORDER BY `{$itemtable}`.`entities_id`,\n                            `{$itemtable}`.`name`";
         if ($result = $DB->query($query)) {
             while ($row = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2'><td>";
                 echo "<input type='checkbox' name='item[" . $row["id"] . "]' value='" . $row["id"] . "'>" . "</td>";
                 $typename = $item->getTypeName();
                 if ($itemtype == 'Peripheral') {
                     $item->getFromDB($row['items_id']);
                     if (isset($item->fields["peripheraltypes_id"]) && $item->fields["peripheraltypes_id"] != 0) {
                         $typename = Dropdown::getDropdownName("glpi_peripheraltypes", $item->fields["peripheraltypes_id"]);
                     }
                 }
                 echo "<td><a href='reservation.php?reservationitems_id=" . $row['id'] . "'>" . sprintf(__('%1$s - %2$s'), $typename, $row["name"]) . "</a></td>";
                 echo "<td>" . Dropdown::getDropdownName("glpi_locations", $row["location"]) . "</td>";
                 echo "<td>" . nl2br($row["comment"]) . "</td>";
                 if ($showentity) {
                     echo "<td>" . Dropdown::getDropdownName("glpi_entities", $row["entities_id"]) . "</td>";
                 }
                 echo "</tr>\n";
                 $ok = true;
             }
         }
     }
     if ($ok) {
         echo "<tr class='tab_bg_1 center'><td colspan='" . ($showentity ? "5" : "4") . "'>";
         if (isset($_POST['reserve'])) {
             echo Html::hidden('begin', array('value' => $_POST['reserve']["begin"]));
             echo Html::hidden('end', array('value' => $_POST['reserve']["end"]));
         }
         echo "<input type='submit' value=\"" . _sx('button', 'Add') . "\" class='submit'></td></tr>\n";
     }
     echo "</table>\n";
     echo "<input type='hidden' name='id' value=''>";
     echo "</form>";
     // No CSRF token needed
     echo "</div>\n";
 }
 /**
  *
  *
  * @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;
 }