The followings are the available columns in table '{{request_type}}':
Inheritance: extends CActiveRecord
 public function __construct(Prototyped $subject)
 {
     $this->subject = $subject;
     $this->map = MappedForm::create($this->subject->proto()->makeForm())->addSource('id', RequestType::get())->setDefaultType(RequestType::post());
     $this->setMethodMapping('drop', 'doDrop')->setMethodMapping('take', 'doTake')->setMethodMapping('save', 'doSave')->setMethodMapping('edit', 'doEdit')->setMethodMapping('add', 'doAdd');
     $this->setDefaultAction('edit');
 }
Esempio n. 2
0
 protected function configureCurlOptions($action, array $converted, $streamHandle = null, $contentMd5 = null)
 {
     $curlOptions = parent::configureCurlOptions($action, $converted, $streamHandle, $contentMd5);
     if (RequestType::getRequestType($action) == RequestType::POST_DOWNLOAD) {
         $this->responseBodyContents = $streamHandle;
         $curlOptions[CURLOPT_WRITEFUNCTION] = array($this, 'responseCallback');
     }
     return $curlOptions;
 }
 public function __construct(Prototyped $subject)
 {
     $this->subject = $subject;
     $form = $this->subject->proto()->makeForm()->add(Primitive::choice('action')->setList($this->commandMap)->setDefault($this->defaultAction));
     if ($this->idFieldName) {
         $form->add(Primitive::alias($this->idFieldName, $form->get('id')));
     }
     $this->map = MappedForm::create($form)->addSource('id', RequestType::get())->addSource('action', RequestType::get())->setDefaultType(RequestType::post());
     if ($this->idFieldName) {
         $this->map->addSource($this->idFieldName, RequestType::get());
     }
 }
Esempio n. 4
0
 function showForm($ID, $options = array())
 {
     global $DB, $CFG_GLPI;
     $default_values = self::getDefaultValues();
     // Get default values from posted values on reload form
     if (!isset($options['template_preview'])) {
         if (isset($_POST)) {
             $values = Html::cleanPostForTextArea($_POST);
         }
     }
     // 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;
             }
         }
     }
     // Default check
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         // Create item
         $this->check(-1, 'w', $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 :
     $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 ($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()) {
                         // Load template data
                         $values[$predeffield] = $predefvalue;
                         $this->fields[$predeffield] = $predefvalue;
                         $predefined_fields[$predeffield] = $predefvalue;
                     }
                 }
             }
         } 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('update_ticket', '1');
     $canpriority = Session::haveRight('update_priority', '1');
     $canstatus = $canupdate;
     if (in_array($this->fields['status'], $this->getClosedStatusArray())) {
         $canupdate = false;
     }
     $showuserlink = 0;
     if (Session::haveRight('user', 'r')) {
         $showuserlink = 1;
     }
     if (!$options['template_preview']) {
         $this->showTabs($options);
     } else {
         // 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'>";
     }
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe' id='mainformtable'>";
     // Optional line
     $ismultientities = Session::isMultiEntitiesMode();
     echo "<tr class='headerRow'>";
     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::showDateTimeFormItem("date", $date, 1, false);
     } else {
         echo Html::convDateTime($date);
     }
     echo $tt->getEndHiddenFieldValue('date', $this);
     echo "</td>";
     // SLA
     echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('due_date');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Due date'), $tt->getMandatoryMark('due_date'));
     } else {
         _e('Due date');
     }
     echo $tt->getEndHiddenFieldText('due_date');
     echo "</th>";
     echo "<td width='{$colsize4}%' class='nopadding'>";
     if ($ID) {
         if ($this->fields["slas_id"] > 0) {
             echo "<table width='100%'><tr><td class='nopadding'>";
             echo Html::convDateTime($this->fields["due_date"]);
             echo "</td><td class='b'>" . __('SLA') . "</td>";
             echo "<td class='nopadding'>";
             echo Dropdown::getDropdownName("glpi_slas", $this->fields["slas_id"]);
             $commentsla = "";
             $slalevel = new SlaLevel();
             if ($slalevel->getFromDB($this->fields['slalevels_id'])) {
                 $commentsla .= '<span class="b spaced">' . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()) . '</span><br>';
             }
             $nextaction = new SlaLevel_Ticket();
             if ($nextaction->getFromDBForTicket($this->fields["id"])) {
                 $commentsla .= '<span class="b spaced">' . sprintf(__('Next escalation: %s'), Html::convDateTime($nextaction->fields['date'])) . '</span>';
                 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('config', 'r')) {
                 $slaoptions['link'] = Toolbox::getItemTypeFormURL('SLA') . "?id=" . $this->fields["slas_id"];
             }
             Html::showToolTip($commentsla, $slaoptions);
             if ($canupdate) {
                 echo "&nbsp;<input type='submit' class='submit' name='sla_delete' value='" . _sx('button', 'Delete permanently') . "'>";
             }
             echo "</td>";
             echo "</tr></table>";
         } else {
             echo "<table><tr><td class='nopadding'>";
             echo $tt->getBeginHiddenFieldValue('due_date');
             Html::showDateTimeFormItem("due_date", $this->fields["due_date"], 1, true, $canupdate);
             echo $tt->getEndHiddenFieldValue('due_date', $this);
             echo "</td>";
             if ($canupdate) {
                 echo "<td>";
                 echo $tt->getBeginHiddenFieldText('slas_id');
                 echo "<span id='sla_action'>";
                 echo "<a class='vsubmit' " . Html::addConfirmationOnAction(array(__('The assignment of a SLA to a ticket causes the recalculation of the due date.'), __("Escalations defined in the SLA will be triggered under this new date.")), "cleanhide('sla_action');cleandisplay('sla_choice');") . ">" . __('Assign a SLA') . '</a>';
                 echo "</span>";
                 echo "<span id='sla_choice' style='display:none'>";
                 echo "<span  class='b'>" . __('SLA') . "</span>&nbsp;";
                 Sla::dropdown(array('entity' => $this->fields["entities_id"], 'value' => $this->fields["slas_id"]));
                 echo "</span>";
                 echo $tt->getEndHiddenFieldText('slas_id');
                 echo "</td>";
             }
             echo "</tr></table>";
         }
     } else {
         // New Ticket
         echo "<table><tr><td class='nopadding'>";
         if ($this->fields["due_date"] == 'NULL') {
             $this->fields["due_date"] = '';
         }
         echo $tt->getBeginHiddenFieldValue('due_date');
         Html::showDateTimeFormItem("due_date", $this->fields["due_date"], 1, false, $canupdate);
         echo $tt->getEndHiddenFieldValue('due_date', $this);
         echo "</td>";
         if ($canupdate) {
             echo "<td class='nopadding b'>" . $tt->getBeginHiddenFieldText('slas_id');
             printf(__('%1$s%2$s'), __('SLA'), $tt->getMandatoryMark('slas_id'));
             echo $tt->getEndHiddenFieldText('slas_id') . "</td>";
             echo "<td class='nopadding'>" . $tt->getBeginHiddenFieldValue('slas_id');
             Sla::dropdown(array('entity' => $this->fields["entities_id"], 'value' => $this->fields["slas_id"]));
             echo $tt->getEndHiddenFieldValue('slas_id', $this);
             echo "</td>";
         }
         echo "</tr></table>";
     }
     echo "</td></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::showDateTimeFormItem("solvedate", $this->fields["solvedate"], 1, false, $canupdate);
         echo "</td>";
         if (in_array($this->fields["status"], $this->getClosedStatusArray())) {
             echo "<th width='{$colsize3}%'>" . __('Close date') . "</th>";
             echo "<td width='{$colsize4}%'>";
             Html::showDateTimeFormItem("closedate", $this->fields["closedate"], 1, false, $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'] = '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'] = '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'));
     } else {
         echo self::getStatus($this->fields["status"]);
     }
     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"]));
     } else {
         echo Dropdown::getDropdownName('glpi_requesttypes', $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 parent::getUrgencyName($this->fields["urgency"]);
     }
     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('create_incident_validation', 1)) {
             $validation_right = 'validate_incident';
         }
         if ($values['type'] == self::DEMAND_TYPE && Session::haveRight('create_request_validation', 1)) {
             $validation_right = 'validate_request';
         }
         if (!empty($validation_right)) {
             User::dropdown(array('name' => "_add_validation", 'entity' => $this->fields['entities_id'], 'right' => $validation_right, 'value' => $values['_add_validation']));
         }
         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 ($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 rowspan='2'>" . $tt->getBeginHiddenFieldText('itemtype');
     printf(__('%1$s%2$s'), __('Associated element'), $tt->getMandatoryMark('itemtype'));
     if ($ID && $canupdate) {
         echo "&nbsp;<img title='" . __s('Update') . "' alt='" . __s('Update') . "'\n                      onClick=\"Ext.get('tickethardwareselection{$ID}').setDisplayed('block')\"\n                      class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/showselect.png'>";
     }
     echo $tt->getEndHiddenFieldText('itemtype');
     echo "</th>";
     echo "<td rowspan='2'>";
     echo $tt->getBeginHiddenFieldValue('itemtype');
     // Select hardware on creation or if have update right
     if ($canupdate || !$ID || $canupdate_descr) {
         if ($ID) {
             if ($this->fields['itemtype'] && ($item = getItemForItemtype($this->fields['itemtype'])) && $this->fields["items_id"]) {
                 if ($item->can($this->fields["items_id"], 'r')) {
                     printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getLink(array('comments' => true)));
                 } else {
                     printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getNameID());
                 }
             }
         }
         $dev_user_id = 0;
         $dev_itemtype = $this->fields["itemtype"];
         $dev_items_id = $this->fields["items_id"];
         if (!$ID) {
             $dev_user_id = $values['_users_id_requester'];
             $dev_itemtype = $values["itemtype"];
             $dev_items_id = $values["items_id"];
         } else {
             if (isset($this->users[CommonITILActor::REQUESTER]) && count($this->users[CommonITILActor::REQUESTER]) == 1) {
                 foreach ($this->users[CommonITILActor::REQUESTER] as $user_id_single) {
                     $dev_user_id = $user_id_single['users_id'];
                 }
             }
         }
         if ($ID) {
             echo "<div id='tickethardwareselection{$ID}' style='display:none'>";
         }
         if ($dev_user_id > 0) {
             self::dropdownMyDevices($dev_user_id, $this->fields["entities_id"], $dev_itemtype, $dev_items_id);
         }
         self::dropdownAllDevices("itemtype", $dev_itemtype, $dev_items_id, 1, $dev_user_id, $this->fields["entities_id"]);
         if ($ID) {
             echo "</div>";
         }
         echo "<span id='item_ticket_selection_information'></span>";
     } else {
         if ($ID && $this->fields['itemtype'] && ($item = getItemForItemtype($this->fields['itemtype']))) {
             $item->getFromDB($this->fields['items_id']);
             printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getNameID());
         } else {
             _e('General');
         }
     }
     echo $tt->getEndHiddenFieldValue('itemtype', $this);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . sprintf(__('%1$s%2$s'), __('Priority'), $tt->getMandatoryMark('priority')) . "</th>";
     echo "<td>";
     $idajax = 'change_priority_' . mt_rand();
     if ($canupdate && $canpriority && !$tt->isHiddenField('priority')) {
         $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true));
         echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     } else {
         $idpriority = 0;
         echo "<span id='{$idajax}'>" . parent::getPriorityName($this->fields["priority"]) . "</span>";
     }
     if ($canupdate || $canupdate_descr) {
         $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority);
         Ajax::updateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     // Need comment right to add a followup with the actiontime
     if (!$ID && Session::haveRight("global_add_followups", "1")) {
         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>";
     } else {
         echo "<th></th><td></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) {
         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></tr>";
     echo "</table>";
     if ($ID) {
         $values['canupdate'] = $canupdate;
         $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 width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('name');
     printf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name'));
     echo $tt->getEndHiddenFieldText('name') . "</th>";
     echo "<td width='" . (100 - $colsize1) . "%' colspan='3'>";
     if (!$ID || $canupdate_descr) {
         echo $tt->getBeginHiddenFieldValue('name');
         $rand = mt_rand();
         echo "<script type='text/javascript' >\n";
         echo "function showName{$rand}() {\n";
         echo "Ext.get('name{$rand}').setDisplayed('none');";
         $params = array('maxlength' => 250, 'size' => 90, 'name' => 'name', 'data' => rawurlencode($this->fields["name"]));
         Ajax::updateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params);
         echo "}";
         echo "</script>\n";
         echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n";
         if (empty($this->fields["name"])) {
             _e('Without title');
         } else {
             echo $this->fields["name"];
         }
         echo "</div>\n";
         echo "<div id='viewname{$rand}'>\n";
         echo "</div>\n";
         if (!$ID) {
             echo "<script type='text/javascript' >\n\n            showName{$rand}();\n            </script>";
         }
         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 width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('content');
     printf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content'));
     echo $tt->getEndHiddenFieldText('content') . "</th>";
     echo "<td width='" . (100 - $colsize1) . "%' colspan='3'>";
     if (!$ID || $canupdate_descr) {
         // Admin =oui on autorise la modification de la description
         echo $tt->getBeginHiddenFieldValue('content');
         $rand = mt_rand();
         echo "<script type='text/javascript' >\n";
         echo "function showDesc{$rand}() {\n";
         echo "Ext.get('desc{$rand}').setDisplayed('none');";
         $params = array('rows' => 6, 'cols' => 90, 'name' => 'content', 'data' => rawurlencode($this->fields["content"]));
         Ajax::updateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params);
         echo "}";
         echo "</script>\n";
         echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n";
         if (!empty($this->fields["content"])) {
             echo nl2br($this->fields["content"]);
         } else {
             _e('Empty description');
         }
         echo "</div>\n";
         echo "<div id='viewdesc{$rand}'></div>\n";
         if (!$ID) {
             echo "<script type='text/javascript' >\n\n            showDesc{$rand}();\n            </script>";
         }
         echo $tt->getEndHiddenFieldValue('content', $this);
     } else {
         echo nl2br($this->fields["content"]);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     // Permit to add doc when creating a ticket
     if (!$ID) {
         echo "<th width='{$colsize1}%'>" . sprintf(__('File (%s)'), Document::getMaxUploadSize());
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt=\"" . __s('Help') . "\" onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000," . "height=800')\">";
         echo "&nbsp;";
         self::showDocumentAddButton();
         echo "</th>";
         echo "<td width='{$colsize2}%'>";
         echo "<div id='uploadfiles'><input type='file' name='filename[]' size='20'></div></td>";
     } else {
         echo "<th colspan='2'>";
         $docnb = Document_Item::countForItem($this);
         echo "<a href=\"" . $this->getLinkURL() . "&amp;forcetab=Document_Item\$1\">";
         //TRANS: %d is the document number
         echo sprintf(_n('%d associated document', '%d associated documents', $docnb), $docnb);
         echo "</a></th>";
     }
     if ($view_linked_tickets) {
         echo "<th width='{$colsize3}%'>" . _n('Linked ticket', 'Linked tickets', 2);
         $rand_linked_ticket = mt_rand();
         if ($canupdate) {
             echo "&nbsp;";
             echo "<img onClick=\"Ext.get('linkedticket{$rand_linked_ticket}').setDisplayed('block')\"\n                   title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n                   class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         }
         echo '</th>';
         echo "<td width='{$colsize4}%'>";
         if ($canupdate) {
             echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>";
             Ticket_Ticket::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : '');
             printf(__('%1$s: %2$s'), __('Ticket'), __('ID'));
             echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n";
             echo "<input type='text' name='_link[tickets_id_2]'\n                   value='" . (isset($values["_link"]) ? $values["_link"]['tickets_id_2'] : '') . "'\n                   size='10'>\n";
             echo "&nbsp;";
             echo "</div>";
             if (isset($values["_link"]) && !empty($values["_link"]['tickets_id_2'])) {
                 echo "<script language='javascript'>Ext.get('linkedticket{$rand_linked_ticket}').\n                      setDisplayed('block');</script>";
             }
         }
         Ticket_Ticket::displayLinkedTicketsTo($ID);
         echo "</td>";
     } else {
         echo "<td></td>";
     }
     echo "</tr>";
     if ((!$ID || $canupdate || $canupdate_descr || Session::haveRight("assign_ticket", "1") || Session::haveRight("steal_ticket", "1")) && !$options['template_preview']) {
         echo "<tr class='tab_bg_1'>";
         if ($ID) {
             if (Session::haveRight('delete_ticket', 1)) {
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 if ($this->fields["is_deleted"] == 1) {
                     echo "<input type='submit' class='submit' name='restore' value='" . _sx('button', 'Restore') . "'></td>";
                 } else {
                     echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'></td>";
                 }
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 if ($this->fields["is_deleted"] == 1) {
                     echo "<input type='submit' class='submit' name='purge' value='" . _sx('button', 'Delete permanently') . "' " . Html::addConfirmationOnAction(__('Confirm the final deletion?')) . ">";
                 } else {
                     echo "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Put in dustbin') . "'></td>";
                 }
             } else {
                 echo "<td class='tab_bg_2 center' colspan='4'>";
                 echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'>";
             }
             echo "<input type='hidden' name='_read_date_mod' value='" . $this->getField('date_mod') . "'>";
         } 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) . "\">";
             }
         }
     }
     echo "</table>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</div>";
     if (!$options['template_preview']) {
         Html::closeForm();
         $this->addDivForTabs();
     }
     return true;
 }
Esempio n. 5
0
 function prepareInputForAdd($input)
 {
     global $CFG_GLPI, $LANG;
     // Check mandatory
     $mandatory_ok = true;
     // Do not check mandatory on auto import (mailgates)
     if (!isset($input['_auto_import'])) {
         $_SESSION["helpdeskSaved"] = $input;
         if (!isset($input["urgency"])) {
             addMessageAfterRedirect($LANG['tracking'][4], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_content_mandatory"] && (!isset($input['content']) || empty($input['content']))) {
             addMessageAfterRedirect($LANG['tracking'][8], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_title_mandatory"] && (!isset($input['name']) || empty($input['name']))) {
             addMessageAfterRedirect($LANG['help'][40], false, ERROR);
             $mandatory_ok = false;
         }
         if ($CFG_GLPI["is_ticket_category_mandatory"] && (!isset($input['ticketcategories_id']) || empty($input['ticketcategories_id']))) {
             addMessageAfterRedirect($LANG['help'][41], false, ERROR);
             $mandatory_ok = false;
         }
         //          if (isset($input['use_email_notification']) && $input['use_email_notification']
         //              && (!isset($input['user_email']) || empty($input['user_email']))) {
         //
         //             addMessageAfterRedirect($LANG['help'][16], false, ERROR);
         //             $mandatory_ok = false;
         //          }
         if (!$mandatory_ok) {
             return false;
         }
     }
     if (!isset($input["urgency"]) || !($CFG_GLPI['urgency_mask'] & 1 << $input["urgency"])) {
         $input["urgency"] = 3;
     }
     if (!isset($input["impact"]) || !($CFG_GLPI['impact_mask'] & 1 << $input["impact"])) {
         $input["impact"] = 3;
     }
     if (!isset($input["priority"])) {
         $input["priority"] = $this->computePriority($input["urgency"], $input["impact"]);
     }
     unset($_SESSION["helpdeskSaved"]);
     // No Auto set Import for external source
     if (!isset($input['_auto_import'])) {
         if (!isset($input["_users_id_requester"])) {
             if ($uid = getLoginUserID()) {
                 $input["_users_id_requester"] = $uid;
             }
         }
     }
     // set last updater
     if ($lastupdater = getLoginUserID(true)) {
         $input['users_id_lastupdater'] = $lastupdater;
     }
     // No Auto set Import for external source
     if (($uid = getLoginUserID()) && !isset($input['_auto_import'])) {
         $input["users_id_recipient"] = $uid;
     } else {
         if (isset($input["_users_id_requester"]) && $input["_users_id_requester"]) {
             $input["users_id_recipient"] = $input["_users_id_requester"];
         }
     }
     if (!isset($input["requesttypes_id"])) {
         $input["requesttypes_id"] = RequestType::getDefault('helpdesk');
     }
     if (!isset($input["status"])) {
         $input["status"] = "new";
     }
     if (!isset($input['global_validation'])) {
         $input['global_validation'] = 'none';
     }
     if (!isset($input["date"]) || empty($input["date"])) {
         $input["date"] = $_SESSION["glpi_currenttime"];
     }
     if (!isset($input["_users_id_assign"])) {
         $input["_users_id_assign"] = 0;
     }
     if (!isset($input["_groups_id_assign"])) {
         $input["_groups_id_assign"] = 0;
     }
     // Set default dropdown
     $dropdown_fields = array('entities_id', 'items_id', 'suppliers_id_assign', 'ticketcategories_id');
     foreach ($dropdown_fields as $field) {
         if (!isset($input[$field])) {
             $input[$field] = 0;
         }
     }
     if (!isset($input['itemtype']) || !($input['items_id'] > 0)) {
         $input['itemtype'] = '';
     }
     $item = NULL;
     if ($input["items_id"] > 0 && !empty($input["itemtype"])) {
         if (class_exists($input["itemtype"])) {
             $item = new $input["itemtype"]();
             if (!$item->getFromDB($input["items_id"])) {
                 $item = NULL;
             }
         }
     }
     // Auto group define from item
     //       if ($item != NULL) {
     //          if ($item->isField('groups_id')
     //              && (!isset($input["_groups_id_requester"]) || $input["_groups_id_requester"]==0)) {
     //             $input["_groups_id_requester"] = $item->getField('groups_id');
     //          }
     //       }
     // Manage auto assign
     $entitydata = new EntityData();
     $auto_assign_mode = $CFG_GLPI['auto_assign_mode'];
     if ($entitydata->getFromDB($input['entities_id'])) {
         $auto_assign_mode = $entitydata->getField('auto_assign_mode');
         // Set global config value
         if ($auto_assign_mode == -1) {
             $auto_assign_mode = $CFG_GLPI['auto_assign_mode'];
         }
     }
     switch ($auto_assign_mode) {
         case NO_AUTO_ASSIGN:
             break;
         case AUTO_ASSIGN_HARDWARE_CATEGORY:
             // Auto assign tech from item
             if ($input["_users_id_assign"] == 0 && $item != NULL) {
                 if ($item->isField('users_id_tech')) {
                     $input["_users_id_assign"] = $item->getField('users_id_tech');
                     if ($input["_users_id_assign"] > 0) {
                         $input["status"] = "assign";
                     }
                 }
             }
             // Auto assign tech/group from Category
             if ($input['ticketcategories_id'] > 0 && (!$input['_users_id_assign'] || !$input['_groups_id_assign'])) {
                 $cat = new TicketCategory();
                 $cat->getFromDB($input['ticketcategories_id']);
                 if (!$input['_users_id_assign'] && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if (!$input['_groups_id_assign'] && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             break;
         case AUTO_ASSIGN_CATEGORY_HARDWARE:
             // Auto assign tech/group from Category
             if ($input['ticketcategories_id'] > 0 && (!$input['_users_id_assign'] || !$input['_groups_id_assign'])) {
                 $cat = new TicketCategory();
                 $cat->getFromDB($input['ticketcategories_id']);
                 if (!$input['_users_id_assign'] && $cat->isField('users_id')) {
                     $input['_users_id_assign'] = $cat->getField('users_id');
                 }
                 if (!$input['_groups_id_assign'] && $cat->isField('groups_id')) {
                     $input['_groups_id_assign'] = $cat->getField('groups_id');
                 }
             }
             // Auto assign tech from item
             if ($input["_users_id_assign"] == 0 && $item != NULL) {
                 if ($item->isField('users_id_tech')) {
                     $input["_users_id_assign"] = $item->getField('users_id_tech');
                     if ($input["_users_id_assign"] > 0) {
                         $input["status"] = "assign";
                     }
                 }
             }
             break;
     }
     // Process Business Rules
     $rules = new RuleTicketCollection($input['entities_id']);
     // Set unset variables with are needed
     $user = new User();
     if (isset($input["_users_id_requester"]) && $user->getFromDB($input["_users_id_requester"])) {
         $input['users_locations'] = $user->fields['locations_id'];
     }
     $input = $rules->processAllRules($input, $input, array('recursive' => true));
     //       if (isset($input["use_email_notification"])
     //           && $input["use_email_notification"]
     //           && empty($input["user_email"])) {
     //
     //          if ($user->getFromDB($input["users_id"])) {
     //             $input["user_email"] = $user->fields["email"];
     //          }
     //       }
     if ((isset($input["_users_id_assign"]) && $input["_users_id_assign"] > 0 || isset($input["_groups_id_assign"]) && $input["_groups_id_assign"] > 0 || isset($input["suppliers_id_assign"]) && $input["suppliers_id_assign"] > 0) && $input["status"] == "new") {
         $input["status"] = "assign";
     }
     if (isset($input["hour"]) && isset($input["minute"])) {
         $input["actiontime"] = $input["hour"] * HOUR_TIMESTAMP + $input["minute"] * MINUTE_TIMESTAMP;
         $input["_hour"] = $input["hour"];
         $input["_minute"] = $input["minute"];
         unset($input["hour"]);
         unset($input["minute"]);
     }
     if (isset($input["status"]) && $input["status"] == "solved") {
         if (isset($input["date"])) {
             $input["solvedate"] = $input["date"];
         } else {
             $input["solvedate"] = $_SESSION["glpi_currenttime"];
         }
     }
     if (isset($input["status"]) && $input["status"] == "closed") {
         if (isset($input["date"])) {
             $input["closedate"] = $input["date"];
         } else {
             $input["closedate"] = $_SESSION["glpi_currenttime"];
         }
         $input['solvedate'] = $input["closedate"];
     }
     // Set begin waiting time if status is waiting
     if (isset($input["status"]) && $input["status"] == "waiting") {
         $input['begin_waiting_date'] = $input['date'];
     }
     // No name set name
     if (empty($input["name"])) {
         $input["name"] = preg_replace('/\\r\\n/', ' ', $input['content']);
         $input["name"] = preg_replace('/\\n/', ' ', $input['name']);
         $input["name"] = utf8_substr($input['name'], 0, 70);
     }
     //// Manage SLA assignment
     // due date defined : no SLA
     if (isset($input["due_date"]) && $input['due_date'] != 'NULL') {
         // Valid due date
         if ($input['due_date'] > $input['date']) {
             if (isset($input["slas_id"])) {
                 unset($input["slas_id"]);
             }
         } else {
             // Unset due date
             unset($input["due_date"]);
         }
     }
     if (isset($input["slas_id"]) && $input["slas_id"] > 0) {
         $sla = new SLA();
         if ($sla->getFromDB($input["slas_id"])) {
             // Get first SLA Level
             $input["slalevels_id"] = SlaLevel::getFirstSlaLevel($input["slas_id"]);
             // Compute due_date
             $input['due_date'] = $sla->computeDueDate($input['date']);
             $input['sla_waiting_duration'] = 0;
         } else {
             $input["slalevels_id"] = 0;
             $input["slas_id"] = 0;
             $input['sla_waiting_duration'] = 0;
         }
     }
     // auto set type if not set
     if (!isset($input["type"])) {
         $input['type'] = EntityData::getUsedConfig('tickettype', $input['entities_id']);
     }
     return $input;
 }
 /**
  * Configures specific curl options based on the request type.
  *
  * @param $action
  * @param $parameters
  * @param $streamHandle
  * @return array
  */
 private function configureCurlOptions($action, array $converted, $streamHandle = null, $contentMd5 = null)
 {
     $curlOptions = $this->getDefaultCurlOptions();
     if (!is_null($this->config['ProxyHost'])) {
         $proxy = $this->config['ProxyHost'];
         $proxy .= ':' . ($this->config['ProxyPort'] == -1 ? '80' : $this->config['ProxyPort']);
         $curlOptions[CURLOPT_PROXY] = $proxy;
     }
     $serviceUrl = $this->config['ServiceURL'];
     // append the '/' character to the end of the service URL if it doesn't exist.
     if (!(substr($serviceUrl, strlen($serviceUrl) - 1) === '/')) {
         $serviceUrl .= '/';
     }
     $requestType = RequestType::getRequestType($action);
     if ($requestType == RequestType::POST_UPLOAD) {
         if (is_null($streamHandle) || !is_resource($streamHandle)) {
             require_once dirname(__FILE__) . '/Exception.php';
             throw new MarketplaceWebService_Exception(array('Message' => 'Missing stream resource.'));
         }
         $serviceUrl .= '?' . $this->getParametersAsString($converted[CONVERTED_PARAMETERS_KEY]);
         $curlOptions[CURLOPT_URL] = $serviceUrl;
         $header[] = 'Expect: ';
         $header[] = 'Accept: ';
         $header[] = 'Transfer-Encoding: chunked';
         $header[] = 'Content-MD5: ' . $contentMd5;
         $curlOptions[CURLOPT_HTTPHEADER] = array_merge($header, $converted[CONVERTED_HEADERS_KEY]);
         rewind($streamHandle);
         $curlOptions[CURLOPT_INFILE] = $streamHandle;
         $curlOptions[CURLOPT_UPLOAD] = true;
         $curlOptions[CURLOPT_CUSTOMREQUEST] = self::REQUEST_TYPE;
     } else {
         if (!($requestType === RequestType::UNKNOWN)) {
             $curlOptions[CURLOPT_URL] = $this->config['ServiceURL'];
             $curlOptions[CURLOPT_POSTFIELDS] = $this->getParametersAsString($converted[CONVERTED_PARAMETERS_KEY]);
             if ($requestType == RequestType::POST_DOWNLOAD) {
                 $this->responseBodyContents = $streamHandle;
                 $curlOptions[CURLOPT_WRITEFUNCTION] = array($this, 'responseCallback');
             }
         } else {
             throw new InvalidArgumentException("{$action} is not a valid request type.");
         }
     }
     return $curlOptions;
 }
 /**
  * Print the config form for default user prefs
  *
  * @param $data array containing datas
  * (CFG_GLPI for global config / glpi_users fields for user prefs)
  *
  * @return Nothing (display)
  **/
 function showFormUserPrefs($data = array())
 {
     global $DB, $CFG_GLPI;
     $oncentral = $_SESSION["glpiactiveprofile"]["interface"] == "central";
     $userpref = false;
     $url = Toolbox::getItemTypeFormURL(__CLASS__);
     if (array_key_exists('last_login', $data)) {
         $userpref = true;
         if ($data["id"] === Session::getLoginUserID()) {
             $url = $CFG_GLPI['root_doc'] . "/front/preference.php";
         } else {
             $url = $CFG_GLPI['root_doc'] . "/front/user.form.php";
         }
     }
     echo "<form name='form' action='{$url}' method='post'>";
     // Only set id for user prefs
     if ($userpref) {
         echo "<input type='hidden' name='id' value='" . $data['id'] . "'>";
     }
     echo "<div class='center' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='4'>" . __('Personalization') . "</th></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td width='30%'>" . ($userpref ? __('Language') : __('Default language')) . "</td>";
     echo "<td width='20%'>";
     if (Config::canUpdate() || !GLPI_DEMO_MODE) {
         Dropdown::showLanguages("language", array('value' => $data["language"]));
     } else {
         echo "&nbsp;";
     }
     echo "<td width='30%'>" . __('Date format') . "</td>";
     echo "<td width='20%'>";
     $date_formats = array(0 => __('YYYY-MM-DD'), 1 => __('DD-MM-YYYY'), 2 => __('MM-DD-YYYY'));
     Dropdown::showFromArray('date_format', $date_formats, array('value' => $data["date_format"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Results to display by page') . "</td><td>";
     // Limit using global config
     $value = $data['list_limit'] < $CFG_GLPI['list_limit_max'] ? $data['list_limit'] : $CFG_GLPI['list_limit_max'];
     Dropdown::showNumber('list_limit', array('value' => $value, 'min' => 5, 'max' => $CFG_GLPI['list_limit_max'], 'step' => 5));
     echo "</td>";
     echo "<td>" . __('Number format') . "</td>";
     $values = array(0 => '1 234.56', 1 => '1,234.56', 2 => '1 234,56', 3 => '1234.56', 4 => '1234,56');
     echo "<td>";
     Dropdown::showFromArray('number_format', $values, array('value' => $data["number_format"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Display order of surnames firstnames') . "</td><td>";
     $values = array(User::REALNAME_BEFORE => __('Surname, First name'), User::FIRSTNAME_BEFORE => __('First name, Surname'));
     Dropdown::showFromArray('names_format', $values, array('value' => $data["names_format"]));
     echo "</td>";
     echo "<td>" . __("Color palette") . "</td><td>";
     $themes_files = scandir(GLPI_ROOT . "/css/palettes/");
     echo "<select name='palette' id='theme-selector'>";
     foreach ($themes_files as $key => $file) {
         if (strpos($file, ".css") !== false) {
             $name = substr($file, 0, -4);
             $selected = "";
             if ($data["palette"] == $name) {
                 $selected = "selected='selected'";
             }
             echo "<option value='{$name}' {$selected}>" . ucfirst($name) . "</option>";
         }
     }
     echo Html::scriptBlock("\n         function formatThemes(theme) {\n             return \"&nbsp;<img src='../css/palettes/previews/\" + theme.text.toLowerCase() + \".png'/>\"\n                     + \"&nbsp;\" + theme.text;\n         }\n         \$(\"#theme-selector\").select2({\n             formatResult: formatThemes,\n             formatSelection: formatThemes,\n             width: '100%',\n             escapeMarkup: function(m) { return m; }\n         });\n      ");
     echo "</select>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     if ($oncentral) {
         echo "<td>" . __('Display the complete name in tree dropdowns') . "</td><td>";
         Dropdown::showYesNo('use_flat_dropdowntree', $data["use_flat_dropdowntree"]);
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     if (!$userpref || $CFG_GLPI['show_count_on_tabs'] != -1) {
         echo "<td>" . __('Display counts in tabs') . "</td><td>";
         $values = array(0 => __('No'), 1 => __('Yes'));
         if (!$userpref) {
             $values[-1] = __('Never');
         }
         Dropdown::showFromArray('show_count_on_tabs', $values, array('value' => $data["show_count_on_tabs"]));
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     if ($oncentral) {
         echo "<td>" . __('Show GLPI ID') . "</td><td>";
         Dropdown::showYesNo("is_ids_visible", $data["is_ids_visible"]);
         echo "</td>";
     } else {
         echo "<td colspan='2'></td>";
     }
     echo "<td>" . __('CSV delimiter') . "</td><td>";
     $values = array(';' => ';', ',' => ',');
     Dropdown::showFromArray('csv_delimiter', $values, array('value' => $data["csv_delimiter"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Notifications for my changes') . "</td><td>";
     Dropdown::showYesNo("notification_to_myself", $data["notification_to_myself"]);
     echo "</td>";
     if ($oncentral) {
         echo "<td>" . __('Results to display on home page') . "</td><td>";
         Dropdown::showNumber('display_count_on_home', array('value' => $data['display_count_on_home'], 'min' => 0, 'max' => 30));
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('PDF export font') . "</td><td>";
     Dropdown::showFromArray("pdffont", GLPIPDF::getFontList(), array('value' => $data["pdffont"], 'width' => 200));
     echo "</td>";
     echo "<td>" . __('Keep devices when purging an item') . "</td><td>";
     Dropdown::showYesNo('keep_devices_when_purging_item', $data['keep_devices_when_purging_item']);
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Go to created item after creation') . "</td>";
     echo "<td>";
     Dropdown::showYesNo("backcreated", $data["backcreated"]);
     echo "</td>";
     echo "<td>" . __('Layout') . "</td><td>";
     $layout_options = array('lefttab' => __("Tabs on left"), 'classic' => __("Classic view"), 'vsplit' => __("Vertical split"));
     echo "<select name='layout' id='layout-selector'>";
     foreach ($layout_options as $key => $name) {
         $selected = "";
         if ($data["layout"] == $key) {
             $selected = "selected='selected'";
         }
         echo "<option value='{$key}' {$selected}>" . ucfirst($name) . "</option>";
     }
     echo Html::scriptBlock("\n         function formatLayout(layout) {\n             return \"&nbsp;<img src='../pics/layout_\" + layout.id.toLowerCase() + \".png'/>\"\n                     + \"&nbsp;\" + layout.text;\n         }\n         \$(\"#layout-selector\").select2({\n             formatResult: formatLayout,\n             formatSelection: formatLayout,\n             escapeMarkup: function(m) { return m; }\n         });\n      ");
     echo "</select>";
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_2'><td>" . __('Enable ticket timeline') . "</td>";
     echo "<td>";
     Dropdown::showYesNo('ticket_timeline', $data['ticket_timeline']);
     echo "</td>";
     echo "<td>" . __('Keep tabs replaced by the ticket timeline') . "</td><td>";
     Dropdown::showYesNo('ticket_timeline_keep_replaced_tabs', $data['ticket_timeline_keep_replaced_tabs']);
     echo "</td></tr>";
     if ($oncentral) {
         echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Assistance') . "</th></tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . __('Private followups by default') . "</td><td>";
         Dropdown::showYesNo("followup_private", $data["followup_private"]);
         echo "</td><td>" . __('Show new tickets on the home page') . "</td><td>";
         if (Session::haveRightsOr("ticket", array(Ticket::READMY, Ticket::READALL, Ticket::READASSIGN))) {
             Dropdown::showYesNo("show_jobs_at_login", $data["show_jobs_at_login"]);
         } else {
             echo Dropdown::getYesNo(0);
         }
         echo " </td></tr>";
         echo "<tr class='tab_bg_2'><td>" . __('Private tasks by default') . "</td><td>";
         Dropdown::showYesNo("task_private", $data["task_private"]);
         echo "</td><td> " . __('Request sources by default') . "</td><td>";
         RequestType::dropdown(array('value' => $data["default_requesttypes_id"], 'name' => "default_requesttypes_id"));
         echo "</td></tr>";
         echo "<tr class='tab_bg_2'><td>" . __('Tasks state by default') . "</td><td>";
         Planning::dropdownState("task_state", $data["task_state"]);
         echo "</td><td colspan='2'>&nbsp;</td></tr>";
         echo "<tr class='tab_bg_2'><td>" . __('Pre-select me as a technician when creating a ticket') . "</td><td>";
         if (!$userpref || Session::haveRight('ticket', Ticket::OWN)) {
             Dropdown::showYesNo("set_default_tech", $data["set_default_tech"]);
         } else {
             echo Dropdown::getYesNo(0);
         }
         echo "</td><td>" . __('Automatically refresh the list of tickets (minutes)') . "</td><td>";
         Dropdown::showNumber('refresh_ticket_list', array('value' => $data["refresh_ticket_list"], 'min' => 1, 'max' => 30, 'step' => 1, 'toadd' => array(0 => __('Never'))));
         echo "</td>";
         echo "</tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . __('Priority colors') . "</td>";
         echo "<td colspan='3'>";
         echo "<table><tr>";
         echo "<td>1&nbsp;";
         Html::showColorField('priority_1', array('value' => $data["priority_1"]));
         echo "</td>";
         echo "<td>2&nbsp;";
         Html::showColorField('priority_2', array('value' => $data["priority_2"]));
         echo "</td>";
         echo "<td>3&nbsp;";
         Html::showColorField('priority_3', array('value' => $data["priority_3"]));
         echo "</td>";
         echo "<td>4&nbsp;";
         Html::showColorField('priority_4', array('value' => $data["priority_4"]));
         echo "</td>";
         echo "<td>5&nbsp;";
         Html::showColorField('priority_5', array('value' => $data["priority_5"]));
         echo "</td>";
         echo "<td>6&nbsp;";
         Html::showColorField('priority_6', array('value' => $data["priority_6"]));
         echo "</td>";
         echo "</tr></table>";
         echo "</td></tr>";
     }
     // Only for user
     if (array_key_exists('personal_token', $data)) {
         echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Remote access key') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td>" . __('Remote access key');
         if (!empty($data["personal_token"])) {
             //TRANS: %s is the generation date
             echo "<br>" . sprintf(__('generated on %s'), Html::convDateTime($data["personal_token_date"]));
         }
         echo "</td><td colspan='3'>";
         echo "<input type='checkbox' name='_reset_personal_token'>&nbsp;" . __('Regenerate');
         echo "</td></tr>";
     }
     echo "<tr><th colspan='4'>" . __('Due date progression') . "</th></tr>";
     echo "<tr class='tab_bg_1'>" . "<td>" . __('OK state color') . "</td>";
     echo "<td>";
     Html::showColorField('duedateok_color', array('value' => $data["duedateok_color"]));
     echo "</td><td colspan='2'>&nbsp;</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Warning state color') . "</td>";
     echo "<td>";
     Html::showColorField('duedatewarning_color', array('value' => $data["duedatewarning_color"]));
     echo "</td>";
     echo "<td>" . __('Warning state threshold') . "</td>";
     echo "<td>";
     Dropdown::showNumber("duedatewarning_less", array('value' => $data['duedatewarning_less']));
     $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', Session::getPluralNumber()), 'days' => _n('Day', 'Days', Session::getPluralNumber()));
     echo "&nbsp;";
     Dropdown::showFromArray("duedatewarning_unit", $elements, array('value' => $data['duedatewarning_unit']));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>" . "<td>" . __('Critical state color') . "</td>";
     echo "<td>";
     Html::showColorField('duedatecritical_color', array('value' => $data["duedatecritical_color"]));
     echo "</td>";
     echo "<td>" . __('Critical state threshold') . "</td>";
     echo "<td>";
     Dropdown::showNumber("duedatecritical_less", array('value' => $data['duedatecritical_less']));
     echo "&nbsp;";
     $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', Session::getPluralNumber()), 'days' => _n('Day', 'Days', Session::getPluralNumber()));
     Dropdown::showFromArray("duedatecritical_unit", $elements, array('value' => $data['duedatecritical_unit']));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td colspan='4' class='center'>";
     echo "<input type='submit' name='update' class='submit' value=\"" . _sx('button', 'Save') . "\">";
     echo "</td></tr>";
     echo "</table></div>";
     Html::closeForm();
 }
/**
 * Print the helpdesk
 *
 * @param $ID int : ID of the user who want to display the Helpdesk
 * @param $from_helpdesk int : is display from the helpdesk.php ?
 *
 * @return nothing (print the helpdesk)
 **/
function printHelpDesk($ID, $from_helpdesk)
{
    global $DB, $CFG_GLPI, $LANG;
    if (!haveRight("create_ticket", "1")) {
        return false;
    }
    if (haveRight('validate_ticket', 1)) {
        $opt = array();
        $opt['reset'] = 'reset';
        $opt['field'][0] = 55;
        // validation status
        $opt['searchtype'][0] = 'equals';
        $opt['contains'][0] = 'waiting';
        $opt['link'][0] = 'AND';
        $opt['field'][1] = 59;
        // validation aprobator
        $opt['searchtype'][1] = 'equals';
        $opt['contains'][1] = getLoginUserID();
        $opt['link'][1] = 'AND';
        $url_validate = $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($opt, '&amp;');
        if (TicketValidation::getNumberTicketsToValidate(getLoginUserID()) > 0) {
            echo "<a href='{$url_validate}' title=\"" . $LANG['validation'][15] . "\"\n                alt=\"" . $LANG['validation'][15] . "\">" . $LANG['validation'][33] . "</a><br><br>";
        }
    }
    $query = "SELECT `email`, `realname`, `firstname`, `name`\n             FROM `glpi_users`\n             WHERE `id` = '{$ID}'";
    $result = $DB->query($query);
    $email = $DB->result($result, 0, "email");
    // Get saved data from a back system
    $use_email_notification = 1;
    if ($email == "") {
        $use_email_notification = 0;
    }
    $itemtype = 0;
    $items_id = "";
    $content = "";
    $title = "";
    $ticketcategories_id = 0;
    $urgency = 3;
    $type = 0;
    if (isset($_SESSION["helpdeskSaved"]['_users_id_requester_notif']) && isset($_SESSION["helpdeskSaved"]['_users_id_requester_notif']['use_notification'])) {
        $use_email_notification = stripslashes($_SESSION["helpdeskSaved"]['_users_id_requester_notif']['use_notification']);
    }
    if (isset($_SESSION["helpdeskSaved"]["email"])) {
        $email = stripslashes($_SESSION["helpdeskSaved"]["user_email"]);
    }
    if (isset($_SESSION["helpdeskSaved"]["itemtype"])) {
        $itemtype = stripslashes($_SESSION["helpdeskSaved"]["itemtype"]);
    }
    if (isset($_SESSION["helpdeskSaved"]["items_id"])) {
        $items_id = stripslashes($_SESSION["helpdeskSaved"]["items_id"]);
    }
    if (isset($_SESSION["helpdeskSaved"]["content"])) {
        $content = cleanPostForTextArea($_SESSION["helpdeskSaved"]["content"]);
    }
    if (isset($_SESSION["helpdeskSaved"]["name"])) {
        $title = stripslashes($_SESSION["helpdeskSaved"]["name"]);
    }
    if (isset($_SESSION["helpdeskSaved"]["ticketcategories_id"])) {
        $ticketcategories_id = stripslashes($_SESSION["helpdeskSaved"]["ticketcategories_id"]);
    }
    if (isset($_SESSION["helpdeskSaved"]["type"])) {
        $type = stripslashes($_SESSION["helpdeskSaved"]["type"]);
    }
    if (isset($_SESSION["helpdeskSaved"]["urgency"])) {
        $urgency = stripslashes($_SESSION["helpdeskSaved"]["urgency"]);
    }
    unset($_SESSION["helpdeskSaved"]);
    echo "<form method='post' name='helpdeskform' action='" . $CFG_GLPI["root_doc"] . "/front/tracking.injector.php' enctype='multipart/form-data'>";
    echo "<input type='hidden' name='_from_helpdesk' value='{$from_helpdesk}'>";
    echo "<input type='hidden' name='requesttypes_id' value='" . RequestType::getDefault('helpdesk') . "'>";
    if ($CFG_GLPI['urgency_mask'] == 1 << 3) {
        // Dont show dropdown if only 1 value enabled
        echo "<input type='hidden' name='urgency' value='3'>";
    }
    echo "<input type='hidden' name='entities_id' value='" . $_SESSION["glpiactive_entity"] . "'>";
    echo "<div class='center'><table class='tab_cadre'>";
    echo "<tr><th colspan='2'>" . $LANG['job'][11] . "&nbsp;:&nbsp;";
    if (isMultiEntitiesMode()) {
        echo "&nbsp;(" . Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]) . ")";
    }
    echo "</th></tr>";
    if ($CFG_GLPI['urgency_mask'] != 1 << 3) {
        echo "<tr class='tab_bg_1'>";
        echo "<td>" . $LANG['joblist'][29] . "&nbsp;:&nbsp;</td>";
        echo "<td>";
        Ticket::dropdownUrgency("urgency", $urgency);
        echo "</td></tr>";
    }
    if (NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) {
        echo "<tr class='tab_bg_1'>";
        echo "<td>" . $LANG['help'][8] . "&nbsp;:&nbsp;</td>";
        echo "<td>";
        $_REQUEST['value'] = getLoginUserID();
        $_REQUEST['field'] = '_users_id_requester_notif';
        $_REQUEST['use_notification'] = $use_email_notification;
        include GLPI_ROOT . "/ajax/uemailUpdate.php";
        echo "</td></tr>";
    }
    if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] != 0) {
        echo "<tr class='tab_bg_1'>";
        echo "<td>" . $LANG['help'][24] . "&nbsp;:&nbsp;</td>";
        echo "<td>";
        Ticket::dropdownMyDevices(getLoginUserID(), $_SESSION["glpiactive_entity"]);
        Ticket::dropdownAllDevices("itemtype", $itemtype, $items_id, 0, $_SESSION["glpiactive_entity"]);
        echo "</td></tr>";
    }
    echo "<tr class='tab_bg_1'>";
    echo "<td>" . $LANG['common'][17] . "&nbsp;:&nbsp;</td><td>";
    Ticket::dropdownType('type', $type);
    echo "</td></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td>" . $LANG['common'][36] . "&nbsp;:&nbsp;</td><td>";
    Dropdown::show('TicketCategory', array('value' => $ticketcategories_id, 'condition' => '`is_helpdeskvisible`=1'));
    echo "</td></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td>" . $LANG['common'][57] . "&nbsp;:&nbsp;</td>";
    echo "<td><input type='text' maxlength='250' size='50' name='name' value='{$title}'></td></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td colspan='2'><textarea name='content' cols='78' rows='14'>{$content}</textarea>";
    echo "</td></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td>" . $LANG['document'][2] . " (" . Document::getMaxUploadSize() . ")&nbsp;:&nbsp;";
    echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt='" . $LANG['central'][7] . "' onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000,height=800')\">";
    echo "</td>";
    echo "<td><input type='file' name='filename' value='' size='25'></td></tr>";
    echo "<tr class='tab_bg_1'>";
    echo "<td colspan='2' class='center'>";
    echo "<input type='submit' value=\"" . $LANG['help'][14] . "\" class='submit'>";
    echo "</td></tr>";
    echo "</table></div></form>";
}
Esempio n. 9
0
error_reporting(E_ALL ^ E_NOTICE);
header('Content-type: text/html; charset=utf-8');
include_once __DIR__ . '/local.php';
mb_internal_encoding("UTF-8");
// загружаем параметры---//
$taskPar = TaskParameters::getInstance();
$taskPar->setParameters($_GET, $_POST);
$operation = $taskPar->getParameter('operation');
$requestTree = new RequestTree();
$answ = ['successful' => false, 'message' => 'ERROR:тип запроса не распознан "' . $operation . '"'];
//$phrase = 'я хочу купить холодильник цена' ;
//$phrase ='Хочу
// купить     холодильник-стиральную машину..... !- , ???  ' ;
//$phrase = 'я хочу купить стиральную машину цена' ;
//$phrase = 'мне хотелось бы ознакомиться с ценами на компьютеры в челябинске' ;
//$phrase = 'срочно нужен мастер по ремонту телевизоров в городе Сочи' ;
//$phrase = 'нужен мастер-сантехник в москве срочно !!!!' ;
//$phrase = 'Где купить телевизор?' ;
//$phrase = 'почему я хочу купить холодильник по низкой цене в оренбурге' ;
//$phrase = 'помогите стать миллионером' ;
$phrase = 'цейлонский чай';
$reqGo = new RequestGo('requestRoot');
$reqGo->parseDo($phrase);
$answ = $reqGo->getResult();
//----------------------------------///
$requestResult = $answ['result'];
$rType = new RequestType();
$rType->init();
$rType->setResultRequest($requestResult);
$rType->typeRulesClc();
//var_dump($answ) ;
Esempio n. 10
0
 /** function buildTicket - Builds,and returns, the major structure of the ticket to be entered.
  *
  * @param $i                  mail ID
  * @param $options   array    of possible options
  *
  * @return ticket fields array
  */
 function buildTicket($i, $options = array())
 {
     global $CFG_GLPI;
     $play_rules = isset($options['play_rules']) && $options['play_rules'];
     $head = $this->getHeaders($i);
     // Get Header Info Return Array Of Headers
     // **Key Are (subject,to,toOth,toNameOth,from,fromName)
     $tkt = array();
     $tkt['_blacklisted'] = false;
     // For RuleTickets
     $tkt['_mailgate'] = $options['mailgates_id'];
     // Use mail date if it's defined
     if ($this->fields['use_mail_date']) {
         $tkt['date'] = $head['date'];
     }
     // Detect if it is a mail reply
     $glpi_message_match = "/GLPI-([0-9]+)\\.[0-9]+\\.[0-9]+@\\w*/";
     // Check if email not send by GLPI : if yes -> blacklist
     if (!isset($head['message_id']) || preg_match($glpi_message_match, $head['message_id'], $match)) {
         $tkt['_blacklisted'] = true;
         return $tkt;
     }
     // manage blacklist
     $blacklisted_emails = Blacklist::getEmails();
     // Add name of the mailcollector as blacklisted
     $blacklisted_emails[] = $this->fields['name'];
     if (Toolbox::inArrayCaseCompare($head['from'], $blacklisted_emails)) {
         $tkt['_blacklisted'] = true;
         return $tkt;
     }
     // max size = 0 : no import attachments
     if ($this->fields['filesize_max'] > 0) {
         if (is_writable(GLPI_TMP_DIR)) {
             $tkt['_filename'] = $this->getAttached($i, GLPI_TMP_DIR . "/", $this->fields['filesize_max']);
             $tkt['_tag'] = $this->tags;
         } else {
             //TRANS: %s is a directory
             Toolbox::logInFile('mailgate', sprintf(__('%s is not writable'), GLPI_TMP_DIR . "/"));
         }
     }
     //  Who is the user ?
     $tkt['_users_id_requester'] = User::getOrImportByEmail($head['from']);
     $tkt["_users_id_requester_notif"]['use_notification'] = 1;
     // Set alternative email if user not found / used if anonymous mail creation is enable
     if (!$tkt['_users_id_requester']) {
         $tkt["_users_id_requester_notif"]['alternative_email'] = $head['from'];
     }
     // Add to and cc as additional observer if user found
     if (count($head['ccs'])) {
         foreach ($head['ccs'] as $cc) {
             if ($cc != $head['from'] && !Toolbox::inArrayCaseCompare($cc, $blacklisted_emails) && ($tmp = User::getOrImportByEmail($cc)) > 0) {
                 $tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
             }
         }
     }
     if (count($head['tos'])) {
         foreach ($head['tos'] as $to) {
             if ($to != $head['from'] && !Toolbox::inArrayCaseCompare($to, $blacklisted_emails) && ($tmp = User::getOrImportByEmail($to)) > 0) {
                 $tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
             }
         }
     }
     // Auto_import
     $tkt['_auto_import'] = 1;
     // For followup : do not check users_id = login user
     $tkt['_do_not_check_users_id'] = 1;
     $body = $this->getBody($i);
     // Do it before using charset variable
     $head['subject'] = $this->decodeMimeString($head['subject']);
     $tkt['_head'] = $head;
     if (!empty($this->charset) && !$this->body_converted) {
         $body = Toolbox::encodeInUtf8($body, $this->charset);
         $this->body_converted = true;
     }
     if (!Toolbox::seems_utf8($body)) {
         $tkt['content'] = Toolbox::encodeInUtf8($body);
     } else {
         $tkt['content'] = $body;
     }
     // See In-Reply-To field
     if (isset($head['in_reply_to'])) {
         if (preg_match($glpi_message_match, $head['in_reply_to'], $match)) {
             $tkt['tickets_id'] = intval($match[1]);
         }
     }
     // See in References
     if (!isset($tkt['tickets_id']) && isset($head['references'])) {
         if (preg_match($glpi_message_match, $head['references'], $match)) {
             $tkt['tickets_id'] = intval($match[1]);
         }
     }
     // See in title
     if (!isset($tkt['tickets_id']) && preg_match('/\\[.+#(\\d+)\\]/', $head['subject'], $match)) {
         $tkt['tickets_id'] = intval($match[1]);
     }
     $is_html = false;
     //If files are present and content is html
     if (isset($this->files) && count($this->files) && $tkt['content'] != strip_tags($tkt['content']) && !isset($tkt['tickets_id'])) {
         $is_html = true;
         $tkt['content'] = Ticket::convertContentForTicket($tkt['content'], array_merge($this->files, $this->altfiles), $this->tags);
     }
     $tkt['content'] = $this->cleanMailContent($tkt['content']);
     if ($is_html && !isset($tkt['tickets_id'])) {
         $tkt['content'] = nl2br($tkt['content']);
     }
     $tkt['_supplier_email'] = false;
     // Found ticket link
     if (isset($tkt['tickets_id'])) {
         // it's a reply to a previous ticket
         $job = new Ticket();
         $tu = new Ticket_User();
         $st = new Supplier_Ticket();
         // Check if ticket  exists and users_id exists in GLPI
         /// TODO check if users_id have right to add a followup to the ticket
         if ($job->getFromDB($tkt['tickets_id']) && $job->fields['status'] != CommonITILObject::CLOSED && ($CFG_GLPI['use_anonymous_followups'] || $tkt['_users_id_requester'] > 0 || $tu->isAlternateEmailForITILObject($tkt['tickets_id'], $head['from']) || ($tkt['_supplier_email'] = $st->isSupplierEmail($tkt['tickets_id'], $head['from'])))) {
             if ($tkt['_supplier_email']) {
                 $tkt['content'] = sprintf(__('From %s'), $head['from']) . "\n\n" . $tkt['content'];
             }
             $content = explode("\n", $tkt['content']);
             $tkt['content'] = "";
             $to_keep = array();
             // Move requester to author of followup :
             $tkt['users_id'] = $tkt['_users_id_requester'];
             $begin_strip = -1;
             $end_strip = -1;
             $begin_match = "/" . NotificationTargetTicket::HEADERTAG . ".*" . NotificationTargetTicket::HEADERTAG . "/";
             $end_match = "/" . NotificationTargetTicket::FOOTERTAG . ".*" . NotificationTargetTicket::FOOTERTAG . "/";
             foreach ($content as $ID => $val) {
                 // Get first tag for begin
                 if ($begin_strip < 0) {
                     if (preg_match($begin_match, $val)) {
                         $begin_strip = $ID;
                     }
                 }
                 // Get last tag for end
                 if ($begin_strip >= 0) {
                     if (preg_match($end_match, $val)) {
                         $end_strip = $ID;
                         continue;
                     }
                 }
             }
             if ($begin_strip >= 0) {
                 // Clean first and last lines
                 $content[$begin_strip] = preg_replace($begin_match, '', $content[$begin_strip]);
             }
             if ($end_strip >= 0) {
                 // Clean first and last lines
                 $content[$end_strip] = preg_replace($end_match, '', $content[$end_strip]);
             }
             if ($begin_strip >= 0) {
                 $length = count($content);
                 // Use end strip if set
                 if ($end_strip >= 0 && $end_strip < $length) {
                     $length = $end_strip;
                 }
                 for ($i = $begin_strip + 1; $i < $length; $i++) {
                     unset($content[$i]);
                 }
             }
             $to_keep = array();
             // Aditional clean for thunderbird
             foreach ($content as $ID => $val) {
                 if (!isset($val[0]) || $val[0] != '>') {
                     $to_keep[$ID] = $ID;
                 }
             }
             $tkt['content'] = "";
             foreach ($to_keep as $ID) {
                 $tkt['content'] .= $content[$ID] . "\n";
             }
             // Do not play rules for followups : WRONG : play rules only for refuse options
             //$play_rules = false;
         } else {
             // => to handle link in Ticket->post_addItem()
             $tkt['_linkedto'] = $tkt['tickets_id'];
             unset($tkt['tickets_id']);
         }
     }
     // Add message from getAttached
     if ($this->addtobody) {
         $tkt['content'] .= $this->addtobody;
     }
     $tkt['name'] = $this->textCleaner($head['subject']);
     if (!isset($tkt['tickets_id'])) {
         // Which entity ?
         //$tkt['entities_id']=$this->fields['entities_id'];
         //$tkt['Subject']= $head['subject'];   // not use for the moment
         // Medium
         $tkt['urgency'] = "3";
         // No hardware associated
         $tkt['itemtype'] = "";
         // Mail request type
     } else {
         // Reopen if needed
         $tkt['add_reopen'] = 1;
     }
     $tkt['requesttypes_id'] = RequestType::getDefault('mail');
     if ($play_rules) {
         $rule_options['ticket'] = $tkt;
         $rule_options['headers'] = $head;
         $rule_options['mailcollector'] = $options['mailgates_id'];
         $rule_options['_users_id_requester'] = $tkt['_users_id_requester'];
         $rulecollection = new RuleMailCollectorCollection();
         $output = $rulecollection->processAllRules(array(), array(), $rule_options);
         // New ticket : compute all
         if (!isset($tkt['tickets_id'])) {
             foreach ($output as $key => $value) {
                 $tkt[$key] = $value;
             }
         } else {
             // Followup only copy refuse data
             $tobecopied = array('_refuse_email_no_response', '_refuse_email_with_response');
             foreach ($tobecopied as $val) {
                 if (isset($output[$val])) {
                     $tkt[$val] = $output[$val];
                 }
             }
         }
     }
     $tkt = Toolbox::addslashes_deep($tkt);
     return $tkt;
 }
 /** form for soluce's approbation
  *
  * @param $ticket Object : the ticket
  **/
 function showApprobationForm($ticket)
 {
     global $DB, $LANG, $CFG_GLPI;
     $input = array('tickets_id' => $ticket->getField('id'));
     if ($ticket->fields["status"] == 'solved' && $ticket->canApprove()) {
         echo "<form name='form' method='post' action='" . $this->getFormURL() . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='4'>" . $LANG['job'][51] . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2'>" . $LANG['common'][25] . "&nbsp;:<br>(" . $LANG['validation'][16] . ")</td>";
         echo "<td class='center middle' colspan='2'>";
         echo "<textarea name='content' cols='70' rows='6'></textarea>";
         echo "<input type='hidden' name='tickets_id' value='" . $ticket->getField('id') . "'>";
         echo "<input type='hidden' name='requesttypes_id' value='" . RequestType::getDefault('helpdesk') . "'>";
         echo "</td></tr>\n";
         echo "<tr class='tab_bg_2'>";
         echo "<td class='tab_bg_2 center' colspan='2' width='200'>\n";
         echo "<input type='submit' name='add_close' value=\"" . $LANG['jobresolution'][3] . "\"\n                class='submit'>";
         echo "</td>\n";
         echo "<td class='tab_bg_2 center' colspan='2'>\n";
         echo "<input type='submit' name='add_reopen' value=\"" . $LANG['jobresolution'][4] . "\"\n                class='submit'>";
         echo "</td></tr>\n";
         echo "</table></form>";
     }
     return true;
 }
Esempio n. 12
0
         $answ = ['pocketN' => $pocketN, 'pocketBegin' => $pocketBegin, 'pocketEnd' => $pocketEnd];
     }
     break;
 case 'requestGo':
     // тип запроса
     $phrase = $taskPar->getParameter('requestText');
     // 1 шаг - разбор
     $rootName = $taskPar->getParameter('nodeRoot');
     $reqGo = new RequestGo($rootName);
     $nodes = $reqGo->getRequestTree();
     $reqGo->parseDo($phrase);
     $answ = $reqGo->getResult();
     //-----------------------------------
     $requestResult = $answ['result'];
     // 2 шаг - определить тип
     $rType = new RequestType();
     $rType->init();
     $rType->setResultRequest($requestResult);
     $rType->typeRulesClc();
     $answ['requestTypes'] = $rType->getRequestTypes();
     break;
 case 'yandex':
     // запрос к информ системе yandex
     $query = $taskPar->getParameter('query');
     $page = $taskPar->getParameter('page');
     $yandex = new YandexController();
     $yandex->setQuery($query);
     $yandex->setPage($page);
     $yandex->queryGo();
     $answ = $yandex->getResultsForShow();
     break;
Esempio n. 13
0
 public function getByType(RequestType $type)
 {
     return $this->{$type->getName()};
 }
 public function __construct()
 {
     $this->requestType = RequestType::post();
 }
Esempio n. 15
0
 /**
  * Print the config form for default user prefs
  *
  * @param $data array containing datas
  * (CFG_GLPI for global config / glpi_users fields for user prefs)
  *
  * @return Nothing (display)
  **/
 function showFormUserPrefs($data = array())
 {
     global $DB, $CFG_GLPI;
     $oncentral = $_SESSION["glpiactiveprofile"]["interface"] == "central";
     $userpref = false;
     $url = Toolbox::getItemTypeFormURL(__CLASS__);
     if (array_key_exists('last_login', $data)) {
         $userpref = true;
         if ($data["id"] === Session::getLoginUserID()) {
             $url = $CFG_GLPI['root_doc'] . "/front/preference.php";
         } else {
             $url = $CFG_GLPI['root_doc'] . "/front/user.form.php";
         }
     }
     echo "<form name='form' action='{$url}' method='post'>";
     echo "<div class='center' id='tabsbody'>";
     echo "<input type='hidden' name='id' value='" . $data["id"] . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='4'>" . __('Personalization') . "</th></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . ($userpref ? __('Language') : __('Default language')) . "</td>";
     echo "<td>";
     if (Session::haveRight("config", "w") || !GLPI_DEMO_MODE) {
         Dropdown::showLanguages("language", array('value' => $data["language"]));
     } else {
         echo "&nbsp;";
     }
     echo "<td>" . __('Date format') . "</td>";
     echo "<td>";
     $date_formats = array(0 => __('YYYY-MM-DD'), 1 => __('DD-MM-YYYY'), 2 => __('MM-DD-YYYY'));
     Dropdown::showFromArray('date_format', $date_formats, array('value' => $data["date_format"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Results to display by page') . "</td><td>";
     // Limit using global config
     Dropdown::showInteger('list_limit', $data['list_limit'] < $CFG_GLPI['list_limit_max'] ? $data['list_limit'] : $CFG_GLPI['list_limit_max'], 5, $CFG_GLPI['list_limit_max'], 5);
     echo "</td>";
     echo "<td>" . __('Number format') . "</td>";
     $values = array(0 => '1 234.56', 1 => '1,234.56', 2 => '1 234,56');
     echo "<td>";
     Dropdown::showFromArray('number_format', $values, array('value' => $data["number_format"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     if ($oncentral) {
         echo "<td>" . __('Default characters limit in dropdowns') . "</td><td>";
         Dropdown::showInteger('dropdown_chars_limit', $data["dropdown_chars_limit"], 20, 100);
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "<td>" . __('Display order of surnames firstnames') . "</td><td>";
     $values = array(User::REALNAME_BEFORE => __('Surname, First name'), User::FIRSTNAME_BEFORE => __('First name, Surname'));
     Dropdown::showFromArray('names_format', $values, array('value' => $data["names_format"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     if ($oncentral) {
         echo "<td>" . __('Display the complete name in tree dropdowns') . "</td><td>";
         Dropdown::showYesNo('use_flat_dropdowntree', $data["use_flat_dropdowntree"]);
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     if (!$userpref || $CFG_GLPI['show_count_on_tabs'] != -1) {
         echo "<td>" . __('Display counts in tabs') . "</td><td>";
         $values = array(0 => __('No'), 1 => __('Yes'));
         if (!$userpref) {
             $values[-1] = __('Never');
         }
         Dropdown::showFromArray('show_count_on_tabs', $values, array('value' => $data["show_count_on_tabs"]));
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_2'>";
     if ($oncentral) {
         echo "<td>" . __('Show GLPI ID') . "</td><td>";
         Dropdown::showYesNo("is_ids_visible", $data["is_ids_visible"]);
         echo "</td>";
     } else {
         echo "<td colspan='2'></td>";
     }
     echo "<td>" . __('CSV delimiter') . "</td><td>";
     $values = array(';' => ';', ',' => ',');
     Dropdown::showFromArray('csv_delimiter', $values, array('value' => $data["csv_delimiter"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td>" . __('Notifications for my changes') . "</td><td>";
     Dropdown::showYesNo("notification_to_myself", $data["notification_to_myself"]);
     echo "</td>";
     if ($oncentral) {
         echo "<td>" . __('Results to display on home page') . "</td><td>";
         Dropdown::showInteger('display_count_on_home', $data['display_count_on_home'], 0, 30);
         echo "</td>";
     } else {
         echo "<td colspan='2'>&nbsp;</td>";
     }
     echo "</tr>";
     if ($oncentral) {
         echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Assistance') . "</th></tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . __('Private followups by default') . "</td><td>";
         Dropdown::showYesNo("followup_private", $data["followup_private"]);
         echo "</td><td> " . __('Show new tickets on the home page') . "</td><td>";
         Dropdown::showYesNo("show_jobs_at_login", $data["show_jobs_at_login"]);
         echo " </td></tr>";
         echo "<tr class='tab_bg_2'><td>" . __('Private tasks by default') . "</td><td>";
         Dropdown::showYesNo("task_private", $data["task_private"]);
         echo "</td><td> " . __('Request sources by default') . "</td><td>";
         RequestType::dropdown(array('value' => $data["default_requesttypes_id"], 'name' => "default_requesttypes_id"));
         echo "</td></tr>";
         echo "<tr class='tab_bg_2'><td>" . __('Pre-select me as a technician when creating a ticket') . "</td><td>";
         if (!$userpref || Session::haveRight('own_ticket', 1)) {
             Dropdown::showYesNo("set_default_tech", $data["set_default_tech"]);
         } else {
             echo Dropdown::getYesNo(0);
         }
         echo "</td><td>" . __('Automatically refresh the list of tickets (minutes)') . "</td><td>";
         Dropdown::showInteger('refresh_ticket_list', $data["refresh_ticket_list"], 1, 30, 1, array(0 => __('Never')));
         echo "</td>";
         echo "</tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . __('Priority colors') . "</td>";
         echo "<td colspan='3'>";
         echo "<table><tr>";
         echo "<td bgcolor='" . $data["priority_1"] . "'>1&nbsp;";
         echo "<input type='text' name='priority_1' size='7' value='" . $data["priority_1"] . "'></td>";
         echo "<td bgcolor='" . $data["priority_2"] . "'>2&nbsp;";
         echo "<input type='text' name='priority_2' size='7' value='" . $data["priority_2"] . "'></td>";
         echo "<td bgcolor='" . $data["priority_3"] . "'>3&nbsp;";
         echo "<input type='text' name='priority_3' size='7' value='" . $data["priority_3"] . "'></td>";
         echo "<td bgcolor='" . $data["priority_4"] . "'>4&nbsp;";
         echo "<input type='text' name='priority_4' size='7' value='" . $data["priority_4"] . "'></td>";
         echo "<td bgcolor='" . $data["priority_5"] . "'>5&nbsp;";
         echo "<input type='text' name='priority_5' size='7' value='" . $data["priority_5"] . "'></td>";
         echo "<td bgcolor='" . $data["priority_6"] . "'>6&nbsp;";
         echo "<input type='text' name='priority_6' size='7' value='" . $data["priority_6"] . "'></td>";
         echo "</tr></table>";
         echo "</td></tr>";
         echo "<tr class='tab_bg_1'>" . "<th colspan='4'>" . _n('Software category', 'Software categories', 2) . "</th></tr>";
         echo "<tr class='tab_bg_2'>";
         echo "<td>" . __('Unfold the software belonging to a category') . "</td><td>";
         Dropdown::showYesNo("is_categorized_soft_expanded", $data["is_categorized_soft_expanded"]);
         echo "</td><td>" . __('Unfold the software without category') . "</td><td>";
         Dropdown::showYesNo("is_not_categorized_soft_expanded", $data["is_not_categorized_soft_expanded"]);
         echo "</td></tr>";
     }
     // Only for user
     if (array_key_exists('personal_token', $data)) {
         echo "<tr class='tab_bg_1'><th colspan='4'>" . __('Remote access key') . "</th></tr>";
         echo "<tr class='tab_bg_1'><td>" . __('Remote access key');
         if (!empty($data["personal_token"])) {
             //TRANS: %s is the generation date
             echo "<br>" . sprintf(__('generated on %s'), Html::convDateTime($data["personal_token_date"]));
         }
         echo "</td><td colspan='3'>";
         echo "<input type='checkbox' name='_reset_personal_token'>&nbsp;" . __('Regenerate');
         echo "</td></tr>";
     }
     echo "<tr><th colspan='4'>" . __('Due date progression') . "</th></tr>";
     echo "<tr class='tab_bg_1'>" . "<td>" . __('OK state color') . "</td>";
     echo "<td bgcolor='" . $data['duedateok_color'] . "'>";
     echo "<input name='duedateok_color' size='7' value='" . $data['duedateok_color'] . "'\n             type='text'>";
     echo "</td><td colspan='2'>&nbsp;</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Warning state color') . "</td>";
     echo "<td bgcolor='" . $data['duedatewarning_color'] . "'>";
     echo "<input name='duedatewarning_color' size='7' value='" . $data['duedatewarning_color'] . "'\n             type='text'>";
     echo "</td>";
     echo "<td>" . __('Warning state threshold') . "</td>";
     echo "<td>";
     Dropdown::showNumber("duedatewarning_less", array('value' => $data['duedatewarning_less']));
     $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', 2), 'days' => _n('Day', 'Days', 2));
     echo "&nbsp;";
     Dropdown::showFromArray("duedatewarning_unit", $elements, array('value' => $data['duedatewarning_unit']));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>" . "<td>" . __('Critical state color') . "</td>";
     echo "<td bgcolor='" . $data['duedatecritical_color'] . "'>";
     echo "<input name='duedatecritical_color' size='7' value='" . $data['duedatecritical_color'] . "'\n             type='text'>";
     echo "</td>";
     echo "<td>" . __('Critical state threshold') . "</td>";
     echo "<td>";
     Dropdown::showNumber("duedatecritical_less", array('value' => $data['duedatecritical_less']));
     echo "&nbsp;";
     $elements = array('%' => '%', 'hours' => _n('Hour', 'Hours', 2), 'days' => _n('Day', 'Days', 2));
     Dropdown::showFromArray("duedatecritical_unit", $elements, array('value' => $data['duedatecritical_unit']));
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td colspan='4' class='center'>";
     echo "<input type='submit' name='update' class='submit' value=\"" . _sx('button', 'Save') . "\">";
     echo "</td></tr>";
     echo "</table></div>";
     Html::closeForm();
 }
Esempio n. 16
0
 /**
  * clone of function Ticket::showFormHelpdesk()
  */
 static function getHelpdesk($ID = 0, $ticket_template = false)
 {
     global $DB, $CFG_GLPI;
     // * Added by plugin survey ticket
     $ticket = new Ticket();
     // * End of adding
     if (!Session::haveRight("create_ticket", "1")) {
         return false;
     }
     if (!$ticket_template && (Session::haveRight('validate_incident', 1) || Session::haveRight('validate_request', 1))) {
         $opt = array();
         $opt['reset'] = 'reset';
         $opt['field'][0] = 55;
         // validation status
         $opt['searchtype'][0] = 'equals';
         $opt['contains'][0] = 'waiting';
         $opt['link'][0] = 'AND';
         $opt['field'][1] = 59;
         // validation aprobator
         $opt['searchtype'][1] = 'equals';
         $opt['contains'][1] = Session::getLoginUserID();
         $opt['link'][1] = 'AND';
         $url_validate = $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($opt, '&amp;');
         if (TicketValidation::getNumberTicketsToValidate(Session::getLoginUserID()) > 0) {
             echo "<a href='{$url_validate}' title=\"" . __s('Ticket waiting for your approval') . "\"\n                   alt=\"" . __s('Ticket waiting for your approval') . "\">" . __('Tickets awaiting approval') . "</a><br><br>";
         }
     }
     $query = "SELECT `realname`, `firstname`, `name`\n                FROM `glpi_users`\n                WHERE `id` = '{$ID}'";
     $result = $DB->query($query);
     $email = UserEmail::getDefaultForUser($ID);
     // Set default values...
     $default_values = array('_users_id_requester_notif' => array('use_notification' => $email == "" ? 0 : 1), 'nodelegate' => 1, '_users_id_requester' => 0, 'name' => '', 'content' => '', 'itilcategories_id' => 0, 'locations_id' => 0, 'urgency' => 3, 'itemtype' => '', 'items_id' => 0, 'entities_id' => $_SESSION['glpiactive_entity'], 'plan' => array(), 'global_validation' => 'none', 'due_date' => 'NULL', 'slas_id' => 0, '_add_validation' => 0, 'type' => Entity::getUsedConfig('tickettype', $_SESSION['glpiactive_entity'], '', Ticket::INCIDENT_TYPE), '_right' => "id");
     // Get default values from posted values on reload form
     if (!$ticket_template) {
         if (isset($_POST)) {
             $values = $_POST;
         }
     }
     // Restore saved value or override with page parameter
     $saved = $ticket->restoreInput();
     foreach ($default_values as $name => $value) {
         if (!isset($values[$name])) {
             if (isset($saved[$name])) {
                 $values[$name] = $saved[$name];
             } else {
                 $values[$name] = $value;
             }
         }
     }
     if (!$ticket_template) {
         echo "<form method='post' name='helpdeskform' action='" . $CFG_GLPI["root_doc"] . "/front/tracking.injector.php' enctype='multipart/form-data'>";
     }
     $delegating = User::getDelegateGroupsForUser($values['entities_id']);
     if (count($delegating)) {
         echo "<div class='center'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='2'>" . __('This ticket concerns me') . " ";
         $rand = Dropdown::showYesNo("nodelegate", $values['nodelegate']);
         $params = array('nodelegate' => '__VALUE__', 'rand' => $rand, 'right' => "delegate", '_users_id_requester' => $values['_users_id_requester'], '_users_id_requester_notif' => $values['_users_id_requester_notif'], 'use_notification' => $values['_users_id_requester_notif']['use_notification'], 'entity_restrict' => $_SESSION["glpiactive_entity"]);
         Ajax::UpdateItemOnSelectEvent("dropdown_nodelegate" . $rand, "show_result" . $rand, $CFG_GLPI["root_doc"] . "/ajax/dropdownDelegationUsers.php", $params);
         if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) {
             echo "</th><th>" . __('Check your personnal information');
         }
         echo "</th></tr>";
         echo "<tr class='tab_bg_1'><td colspan='2' class='center'>";
         echo "<div id='show_result{$rand}'>";
         $self = new Ticket();
         if ($values["_users_id_requester"] == 0) {
             $values['_users_id_requester'] = Session::getLoginUserID();
         } else {
             $values['_right'] = "delegate";
         }
         $self->showActorAddFormOnCreate(CommonITILActor::REQUESTER, $values);
         echo "</div>";
         if ($CFG_GLPI['use_check_pref'] && $values['nodelegate']) {
             echo "</td><td class='center'>";
             User::showPersonalInformation(Session::getLoginUserID());
         }
         echo "</td></tr>";
         echo "</table></div>";
         echo "<input type='hidden' name='_users_id_recipient' value='" . Session::getLoginUserID() . "'>";
     } else {
         // User as requester
         $values['_users_id_requester'] = Session::getLoginUserID();
         if ($CFG_GLPI['use_check_pref']) {
             echo "<div class='center'><table class='tab_cadre_fixe'>";
             echo "<tr><th>" . __('Check your personnal information') . "</th></tr>";
             echo "<tr class='tab_bg_1'><td class='center'>";
             User::showPersonalInformation(Session::getLoginUserID());
             echo "</td></tr>";
             echo "</table></div>";
         }
     }
     echo "<input type='hidden' name='_from_helpdesk' value='1'>";
     echo "<input type='hidden' name='requesttypes_id' value='" . RequestType::getDefault('helpdesk') . "'>";
     // Load ticket template if available :
     $tt = $ticket->getTicketTemplateToUse($ticket_template, $values['type'], $values['itilcategories_id'], $_SESSION["glpiactive_entity"]);
     // 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
     $predefined_fields = array();
     if (isset($tt->predefined) && count($tt->predefined)) {
         foreach ($tt->predefined as $predeffield => $predefvalue) {
             if (isset($values[$predeffield]) && isset($default_values[$predeffield])) {
                 // Is always default value : not set
                 // Set if already predefined field
                 // Set if ticket template change
                 if ($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()) {
                     $values[$predeffield] = $predefvalue;
                     $predefined_fields[$predeffield] = $predefvalue;
                 }
             } else {
                 // Not defined options set as hidden field
                 echo "<input type='hidden' name='{$predeffield}' value='{$predefvalue}'>";
             }
         }
     } 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];
                 }
             }
         }
     }
     if ($CFG_GLPI['urgency_mask'] == 1 << 3 || $tt->isHiddenField('urgency')) {
         // Dont show dropdown if only 1 value enabled or field is hidden
         echo "<input type='hidden' name='urgency' value='" . $values['urgency'] . "'>";
     }
     // Display predefined fields if hidden
     if ($tt->isHiddenField('itemtype')) {
         echo "<input type='hidden' name='itemtype' value='" . $values['itemtype'] . "'>";
         echo "<input type='hidden' name='items_id' value='" . $values['items_id'] . "'>";
     }
     if ($tt->isHiddenField('locations_id')) {
         echo "<input type='hidden' name='locations_id' value='" . $values['locations_id'] . "'>";
     }
     echo "<input type='hidden' name='entities_id' value='" . $_SESSION["glpiactive_entity"] . "'>";
     echo "<div class='center'><table class='tab_cadre_fixe'>";
     echo "<tr><th>" . __('Describe the incident or request') . "</th><th>";
     if (Session::isMultiEntitiesMode()) {
         echo "(" . Dropdown::getDropdownName("glpi_entities", $_SESSION["glpiactive_entity"]) . ")";
     }
     echo "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</td>";
     echo "<td>";
     Ticket::dropdownType('type', array('value' => $values['type'], 'on_change' => 'submit()'));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</td>";
     echo "<td>";
     $condition = "`is_helpdeskvisible`='1'";
     switch ($values['type']) {
         case Ticket::DEMAND_TYPE:
             $condition .= " AND `is_request`='1'";
             break;
         default:
             // Ticket::INCIDENT_TYPE :
             $condition .= " AND `is_incident`='1'";
     }
     $opt = array('value' => $values['itilcategories_id'], 'condition' => $condition, 'on_change' => 'submit()');
     if ($values['itilcategories_id'] && $tt->isMandatoryField("itilcategories_id")) {
         $opt['display_emptychoice'] = false;
     }
     ITILCategory::dropdown($opt);
     echo "</td></tr>";
     if ($CFG_GLPI['urgency_mask'] != 1 << 3) {
         if (!$tt->isHiddenField('urgency')) {
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . sprintf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency')) . "</td>";
             echo "<td>";
             Ticket::dropdownUrgency(array('value' => $values["urgency"]));
             echo "</td></tr>";
         }
     }
     if (empty($delegating) && NotificationTargetTicket::isAuthorMailingActivatedForHelpdesk()) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Inform me about the actions taken') . "</td>";
         echo "<td>";
         if ($values["_users_id_requester"] == 0) {
             $values['_users_id_requester'] = Session::getLoginUserID();
         }
         $_POST['value'] = $values['_users_id_requester'];
         $_POST['field'] = '_users_id_requester_notif';
         $_POST['use_notification'] = $values['_users_id_requester_notif']['use_notification'];
         include GLPI_ROOT . "/ajax/uemailUpdate.php";
         echo "</td></tr>";
     }
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] != 0) {
         if (!$tt->isHiddenField('itemtype')) {
             echo "<tr class='tab_bg_1'>";
             echo "<td>" . sprintf(__('%1$s%2$s'), __('Hardware type'), $tt->getMandatoryMark('itemtype')) . "</td>";
             echo "<td>";
             Ticket::dropdownMyDevices($values['_users_id_requester'], $_SESSION["glpiactive_entity"], $values['itemtype'], $values['items_id']);
             Ticket::dropdownAllDevices("itemtype", $values['itemtype'], $values['items_id'], 0, $values['_users_id_requester'], $_SESSION["glpiactive_entity"]);
             echo "<span id='item_ticket_selection_information'></span>";
             echo "</td></tr>";
         }
     }
     if (!$tt->isHiddenField('locations_id')) {
         echo "<tr class='tab_bg_1'><td>";
         printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id'));
         echo "</td><td>";
         Location::dropdown(array('value' => $values["locations_id"]));
         echo "</td></tr>";
     }
     if (!$tt->isHiddenField('name') || $tt->isPredefinedField('name')) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . sprintf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name')) . "</td>";
         echo "<td><input type='text' maxlength='250' size='80' name='name'\n                    value=\"" . $values['name'] . "\"></td></tr>";
     }
     if (!$tt->isHiddenField('content') || $tt->isPredefinedField('content')) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . sprintf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content')) . "</td>";
         // * Changed by plugin surveyticket
         // * Added by plugin surveyticket
         $psTicketTemplate = new PluginSurveyticketTicketTemplate();
         $psSurvey = new PluginSurveyticketSurvey();
         $plugin_surveyticket_surveys_id = 0;
         $a_tickettemplates = current($psTicketTemplate->find("`tickettemplates_id`='" . $tt->fields['id'] . "'\n                                                      AND `type`='" . $values['type'] . "'\n                                                      AND `is_helpdesk`='1'"));
         if (isset($a_tickettemplates['plugin_surveyticket_surveys_id'])) {
             echo "<td>";
             $psSurvey = new PluginSurveyticketSurvey();
             $psSurvey->getFromDB($a_tickettemplates['plugin_surveyticket_surveys_id']);
             if ($psSurvey->fields['is_active'] == 1) {
                 $plugin_surveyticket_surveys_id = $a_tickettemplates['plugin_surveyticket_surveys_id'];
                 $psSurvey = new PluginSurveyticketSurvey();
                 $psSurvey->startSurvey($plugin_surveyticket_surveys_id);
             }
         } else {
             echo "<td><textarea name='content' cols='80' rows='14'>" . $values['content'] . "</textarea>";
         }
         // * End of change
         echo "</td></tr>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . sprintf(__('%1$s (%2$s)'), __('File'), Document::getMaxUploadSize());
     echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt='" . __s('Help') . "' onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000,height=800')\">";
     echo "&nbsp;";
     Ticket::showDocumentAddButton(60);
     echo "</td>";
     echo "<td><div id='uploadfiles'><input type='file' name='filename[]' value='' size='60'></div>";
     echo "</td></tr>";
     if (!$ticket_template) {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2' class='center'>";
         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) . "\">";
         }
         echo "<input type='submit' name='add' value=\"" . __s('Submit message') . "\" class='submit'>";
         echo "</td></tr>";
     }
     echo "</table></div>";
     if (!$ticket_template) {
         Html::closeForm();
     }
 }
Esempio n. 17
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;
 }
 public function __construct()
 {
     $this->mav = ModelAndView::create()->setModel(Model::create());
     $this->defaultRequestType = RequestType::post();
 }
 /** form for soluce's approbation
  *
  * @param $ticket Object : the ticket
  **/
 function showApprobationForm($ticket)
 {
     global $DB, $CFG_GLPI;
     $input = array('tickets_id' => $ticket->getField('id'));
     if ($ticket->fields["status"] == CommonITILObject::SOLVED && $ticket->canApprove() && $ticket->isAllowedStatus($ticket->fields['status'], Ticket::CLOSED)) {
         echo "<form name='form' method='post' action='" . $this->getFormURL() . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='4'>" . __('Approval of the solution') . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='2'>" . __('Comments') . "<br>(" . __('Optional when approved') . ")</td>";
         echo "<td class='center middle' colspan='2'>";
         echo "<textarea name='content' cols='70' rows='6' class='form-control'></textarea>";
         echo "<input type='hidden' name='tickets_id' value='" . $ticket->getField('id') . "'>";
         echo "<input type='hidden' name='requesttypes_id' value='" . RequestType::getDefault('helpdesk') . "'>";
         echo "</td></tr>\n";
         echo "<tr class='tab_bg_2'>";
         echo "<td class='tab_bg_2 center' colspan='2' width='200'>\n";
         echo "<input type='submit' name='add_close' value=\"" . __('Approve the solution') . "\"\n                class='submit'>";
         echo "</td>\n";
         echo "<td class='tab_bg_2 center' colspan='2'>\n";
         echo "<input type='submit' name='add_reopen' value=\"" . __('Refuse the solution') . "\"\n                class='submit'>";
         echo "</td></tr>\n";
         echo "</table>";
         Html::closeForm();
     }
     return true;
 }
 /** function buildTicket - Builds,and returns, the major structure of the ticket to be entered.
  *
  * @param $i mail ID
  * @param $options array options
  *
  * @return ticket fields array
  */
 function buildTicket($i, $options = array())
 {
     $play_rules = isset($options['play_rules']) && $options['play_rules'];
     $head = $this->getHeaders($i);
     // Get Header Info Return Array Of Headers
     // **Key Are (subject,to,toOth,toNameOth,from,fromName)
     $tkt = array();
     $tkt['_blacklisted'] = false;
     // Detect if it is a mail reply
     $glpi_message_match = "/GLPI-([0-9]+)\\.[0-9]+\\.[0-9]+@\\w*/";
     // Check if email not send by GLPI : if yes -> blacklist
     if (preg_match($glpi_message_match, $head['message_id'], $match)) {
         $tkt['_blacklisted'] = true;
         return $tkt;
     }
     // max size = 0 : no import attachments
     if ($this->fields['filesize_max'] > 0) {
         if (is_writable(GLPI_DOC_DIR . "/_tmp/")) {
             $_FILES = $this->getAttached($i, GLPI_DOC_DIR . "/_tmp/", $this->fields['filesize_max']);
         } else {
             logInFile('mailgate', GLPI_DOC_DIR . "/_tmp/ is not writable");
         }
     }
     //  Who is the user ?
     $tkt['_users_id_requester'] = User::getOrImportByEmail($head['from']);
     $tkt["_users_id_requester_notif"]['use_notification'] = 1;
     if (!$tkt['_users_id_requester']) {
         $tkt["_users_id_requester_notif"]['alternative_email'] = $head['from'];
     }
     // Add to and cc as additional observer if user found
     if (count($head['ccs'])) {
         foreach ($head['ccs'] as $cc) {
             if ($cc != $head['from'] && strcasecmp($cc, $this->fields['name']) && ($tmp = User::getOrImportByEmail($cc)) > 0) {
                 $tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
             }
         }
     }
     if (count($head['tos'])) {
         foreach ($head['tos'] as $to) {
             if ($to != $head['from'] && strcasecmp($to, $this->fields['name']) && ($tmp = User::getOrImportByEmail($to, false)) > 0) {
                 $tkt['_additional_observers'][] = array('users_id' => $tmp, 'use_notification' => 1);
             }
         }
     }
     // Auto_import
     $tkt['_auto_import'] = 1;
     // For followup : do not check users_id = login user
     $tkt['_do_not_check_users_id'] = 1;
     $body = $this->getBody($i);
     // Do it before using charset variable
     $head['subject'] = $this->decodeMimeString($head['subject']);
     $tkt['_head'] = $head;
     if (!empty($this->charset) && !$this->body_converted) {
         $body = encodeInUtf8($body, $this->charset);
         $this->body_converted = true;
     }
     if (!seems_utf8($body)) {
         $tkt['content'] = encodeInUtf8($body);
     } else {
         $tkt['content'] = $body;
     }
     // Add message from getAttached
     if ($this->addtobody) {
         $tkt['content'] .= $this->addtobody;
     }
     // See In-Reply-To field
     if (isset($head['in_reply_to'])) {
         if (preg_match($glpi_message_match, $head['in_reply_to'], $match)) {
             $tkt['tickets_id'] = intval($match[1]);
         }
     }
     // See in References
     if (!isset($tkt['tickets_id']) && isset($head['references'])) {
         if (preg_match($glpi_message_match, $head['references'], $match)) {
             $tkt['tickets_id'] = intval($match[1]);
         }
     }
     // See in title
     if (!isset($tkt['tickets_id']) && preg_match('/\\[GLPI #(\\d+)\\]/', $head['subject'], $match)) {
         $tkt['tickets_id'] = intval($match[1]);
     }
     // Found ticket link
     if (isset($tkt['tickets_id'])) {
         // it's a reply to a previous ticket
         $job = new Ticket();
         // Check if ticket  exists and users_id exists in GLPI
         /// TODO check if users_id have right to add a followup to the ticket
         if ($job->getFromDB($tkt['tickets_id']) && $job->fields['status'] != 'closed' && ($tkt['_users_id_requester'] > 0 || Ticket_User::isAlternateEmailForTicket($tkt['tickets_id'], $head['from']))) {
             $content = explode("\n", $tkt['content']);
             $tkt['content'] = "";
             $first_comment = true;
             $to_keep = array();
             foreach ($content as $ID => $val) {
                 if (isset($val[0]) && $val[0] == '>') {
                     // Delete line at the top of the first comment
                     if ($first_comment) {
                         $first_comment = false;
                         if (isset($to_keep[$ID - 1])) {
                             unset($to_keep[$ID - 1]);
                         }
                     }
                 } else {
                     $to_keep[$ID] = $ID;
                 }
             }
             foreach ($to_keep as $ID) {
                 $tkt['content'] .= $content[$ID] . "\n";
             }
             // Do not play rules for followups : WRONG : play rules only for refuse options
             //$play_rules = false;
         } else {
             // => to handle link in Ticket->post_addItem()
             $tkt['_linkedto'] = $tkt['tickets_id'];
             unset($tkt['tickets_id']);
         }
     }
     $tkt['name'] = $this->textCleaner($head['subject']);
     if (!isset($tkt['tickets_id'])) {
         // Which entity ?
         //$tkt['entities_id']=$this->fields['entities_id'];
         //$tkt['Subject']= $head['subject'];   // not use for the moment
         // Medium
         $tkt['urgency'] = "3";
         // No hardware associated
         $tkt['itemtype'] = "";
         // Mail request type
     } else {
         // Reopen if needed
         $tkt['add_reopen'] = 1;
     }
     $tkt['requesttypes_id'] = RequestType::getDefault('mail');
     $tkt['content'] = clean_cross_side_scripting_deep(html_clean($tkt['content']));
     if ($play_rules) {
         $rule_options['ticket'] = $tkt;
         $rule_options['headers'] = $head;
         $rule_options['mailcollector'] = $options['mailgates_id'];
         $rule_options['_users_id_requester'] = $tkt['_users_id_requester'];
         $rulecollection = new RuleMailCollectorCollection();
         $output = $rulecollection->processAllRules(array(), array(), $rule_options);
         // New ticket : compute all
         if (!isset($tkt['tickets_id'])) {
             foreach ($output as $key => $value) {
                 $tkt[$key] = $value;
             }
         } else {
             // Followup only copy refuse data
             $tobecopied = array('_refuse_email_no_response', '_refuse_email_with_response');
             foreach ($tobecopied as $val) {
                 if (isset($output[$val])) {
                     $tkt[$val] = $output[$val];
                 }
             }
         }
     }
     $tkt = addslashes_deep($tkt);
     return $tkt;
 }