/**
  * Print the mandatory fields
  *
  * @since version 0.83
  *
  * @param $tt                       Ticket Template
  * @param $withtemplate    boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '')
 {
     global $DB;
     $ID = $tt->fields['id'];
     if (!$tt->getFromDB($ID) || !$tt->can($ID, READ)) {
         return false;
     }
     $canedit = $tt->canEdit($ID);
     $ttm = new self();
     $used = $ttm->getMandatoryFields($ID);
     $fields = $tt->getAllowedFieldsNames(true);
     $simplified_fields = $tt->getSimplifiedInterfaceFields();
     $both_interfaces = sprintf(__('%1$s + %2$s'), __('Simplified interface'), __('Standard interface'));
     $rand = mt_rand();
     $query = "SELECT `glpi_tickettemplatemandatoryfields`.*\n                FROM `glpi_tickettemplatemandatoryfields`\n                WHERE (`tickettemplates_id` = '{$ID}')";
     if ($result = $DB->query($query)) {
         $mandatoryfields = array();
         $used = array();
         if ($numrows = $DB->numrows($result)) {
             while ($data = $DB->fetch_assoc($result)) {
                 $mandatoryfields[$data['id']] = $data;
                 $used[$data['num']] = $data['num'];
             }
         }
         if ($canedit) {
             echo "<div class='firstbloc'>";
             echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a mandatory field') . "</th></tr>";
             echo "<tr class='tab_bg_2'><td class='right'>";
             echo "<input type='hidden' name='tickettemplates_id' value='{$ID}'>";
             $select_fields = $fields;
             foreach ($select_fields as $key => $val) {
                 if (in_array($key, $simplified_fields)) {
                     $select_fields[$key] = sprintf(__('%1$s (%2$s)'), $val, $both_interfaces);
                 } else {
                     $select_fields[$key] = sprintf(__('%1$s (%2$s)'), $val, __('Standard interface'));
                 }
             }
             Dropdown::showFromArray('num', $select_fields, array('used' => $used));
             echo "</td><td class='center'>";
             echo "&nbsp;<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             echo "</td></tr>";
             echo "</table>";
             Html::closeForm();
             echo "</div>";
         }
         echo "<div class='spaced'>";
         if ($canedit && $numrows) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr class='noHover'><th colspan='3'>";
         echo self::getTypeName($DB->numrows($result));
         echo "</th></tr>";
         if ($numrows) {
             $header_begin = "<tr>";
             $header_top = '';
             $header_bottom = '';
             $header_end = '';
             if ($canedit) {
                 $header_top .= "<th width='10'>";
                 $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
                 $header_bottom .= "<th width='10'>";
                 $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
             }
             $header_end .= "<th>" . __('Name') . "</th>";
             $header_end .= "<th>" . __("Profile's interface") . "</th>";
             $header_end .= "</tr>";
             echo $header_begin . $header_top . $header_end;
             foreach ($mandatoryfields as $data) {
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 }
                 echo "<td>" . $fields[$data['num']] . "</td>";
                 echo "<td>";
                 if (in_array($data['num'], $simplified_fields)) {
                     echo $both_interfaces;
                 } else {
                     _e('Standard interface');
                 }
                 echo "</td>";
                 echo "</tr>";
             }
             echo $header_begin . $header_bottom . $header_end;
         } else {
             echo "<tr><th colspan='2'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
         if ($canedit && $numrows) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
         echo "</div>";
     }
 }
 /**
  * @param $tt           TicketTemplate object
  * @param $withtemplate (default '')
  **/
 static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $itilcategory = new self();
     $ID = $tt->fields['id'];
     if (!$tt->getFromDB($ID) || !$tt->can($ID, READ)) {
         return false;
     }
     $ttm = new self();
     $rand = mt_rand();
     echo "<div class='center'>";
     $query = "SELECT `glpi_itilcategories`.*\n                FROM `glpi_itilcategories`\n                WHERE (`tickettemplates_id_incident` = '{$ID}')\n                       OR (`tickettemplates_id_demand` = '{$ID}')\n                ORDER BY `name`";
     if ($result = $DB->query($query)) {
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='3'>";
         echo "<a href='" . Toolbox::getItemTypeSearchURL($itilcategory->getType()) . "'>";
         echo self::getTypeName($DB->numrows($result));
         echo "</a>";
         echo "</th></tr>";
         $used_incident = array();
         $used_demand = array();
         if ($DB->numrows($result)) {
             echo "<th>" . __('Name') . "</th>";
             echo "<th>" . __('Incident') . "</th>";
             echo "<th>" . __('Request') . "</th>";
             echo "</tr>";
             while ($data = $DB->fetch_assoc($result)) {
                 echo "<tr class='tab_bg_2'>";
                 $itilcategory->getFromDB($data['id']);
                 echo "<td>" . $itilcategory->getLink(array('comments' => true)) . "</td>";
                 if ($data['tickettemplates_id_incident'] == $ID) {
                     echo "<td class='center'>\n                        <img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' alt=\"" . __('OK') . "\" width='14' height='14'>\n                        </td>";
                     $used_incident[] = $data["id"];
                 } else {
                     echo "<td>&nbsp;</td>";
                 }
                 if ($data['tickettemplates_id_demand'] == $ID) {
                     echo "<td class='center'>\n                        <img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' alt=\"" . __('OK') . "\" width='14' height='14'>\n                        </td>";
                     $used_demand[] = $data["id"];
                 } else {
                     echo "<td>&nbsp;</td>";
                 }
             }
         } else {
             echo "<tr><th colspan='3'>" . __('No item found') . "</th></tr>";
         }
         echo "</table></div>";
     }
 }
 /**
  * Print the predefined fields
  *
  * @since version 0.83
  *
  * @param $tt                       Ticket Template
  * @param $withtemplate    boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $tt->fields['id'];
     if (!$tt->getFromDB($ID) || !$tt->can($ID, READ)) {
         return false;
     }
     $canedit = $tt->canEdit($ID);
     $fields = $tt->getAllowedFieldsNames(true, true);
     $searchOption = Search::getOptions('Ticket');
     $ticket = new Ticket();
     $rand = mt_rand();
     $query = "SELECT `glpi_tickettemplatepredefinedfields`.*\n                FROM `glpi_tickettemplatepredefinedfields`\n                WHERE (`tickettemplates_id` = '{$ID}')\n                ORDER BY 'id'";
     $display_options = array('relative_dates' => true, 'comments' => true, 'html' => true);
     if ($result = $DB->query($query)) {
         $predeffields = array();
         $used = array();
         if ($numrows = $DB->numrows($result)) {
             while ($data = $DB->fetch_assoc($result)) {
                 $predeffields[$data['id']] = $data;
                 $used[$data['num']] = $data['num'];
             }
         }
         if ($canedit) {
             echo "<div class='firstbloc'>";
             echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n                  action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_2'><th colspan='3'>" . __('Add a predefined field') . "</th></tr>";
             echo "<tr class='tab_bg_2'><td class='right top' width='30%'>";
             echo "<input type='hidden' name='tickettemplates_id' value='{$ID}'>";
             $display_fields[-1] = Dropdown::EMPTY_VALUE;
             $display_fields += $fields;
             // Force validation request as used
             $used[-2] = -2;
             // Unset multiple items
             $multiple = self::getMultiplePredefinedValues();
             foreach ($multiple as $val) {
                 if (isset($used[$val])) {
                     unset($used[$val]);
                 }
             }
             $rand_dp = Dropdown::showFromArray('num', $display_fields, array('used' => $used, 'toadd'));
             echo "</td><td class='top'>";
             $paramsmassaction = array('id_field' => '__VALUE__', 'itemtype' => 'Ticket', 'inline' => true, 'submitname' => _sx('button', 'Add'), 'options' => array('relative_dates' => 1, 'with_time' => 1, 'with_days' => 0, 'with_specific_date' => 0, 'itemlink_as_string' => 1, 'entity' => $tt->getEntityID()));
             Ajax::updateItemOnSelectEvent("dropdown_num" . $rand_dp, "show_massiveaction_field", $CFG_GLPI["root_doc"] . "/ajax/dropdownMassiveActionField.php", $paramsmassaction);
             echo "</td><td>";
             echo "<span id='show_massiveaction_field'>&nbsp;</span>\n";
             echo "</td></tr>";
             echo "</table>";
             Html::closeForm();
             echo "</div>";
         }
         echo "<div class='spaced'>";
         if ($canedit && $numrows) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $numrows, 'container' => 'mass' . __CLASS__ . $rand);
             Html::showMassiveActions($massiveactionparams);
         }
         echo "<table class='tab_cadre_fixehov'>";
         echo "<tr class='noHover'><th colspan='3'>";
         echo self::getTypeName($DB->numrows($result));
         echo "</th></tr>";
         if ($numrows) {
             $header_begin = "<tr>";
             $header_top = '';
             $header_bottom = '';
             $header_end = '';
             if ($canedit) {
                 $header_top .= "<th width='10'>";
                 $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
                 $header_bottom .= "<th width='10'>";
                 $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
             }
             $header_end .= "<th>" . __('Name') . "</th>";
             $header_end .= "<th>" . __('Value') . "</th>";
             $header_end .= "</tr>";
             echo $header_begin . $header_top . $header_end;
             foreach ($predeffields as $data) {
                 if (!isset($fields[$data['num']])) {
                     // could happen when itemtype removed and items_id present
                     continue;
                 }
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 }
                 echo "<td>" . $fields[$data['num']] . "</td>";
                 echo "<td>";
                 $display_datas[$searchOption[$data['num']]['field']] = $data['value'];
                 echo $ticket->getValueToDisplay($searchOption[$data['num']], $display_datas, $display_options);
                 echo "</td>";
                 echo "</tr>";
             }
             echo $header_begin . $header_bottom . $header_end;
         } else {
             echo "<tr><th colspan='3'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
         if ($canedit && $numrows) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
         }
         echo "</div>";
     }
 }
Exemple #4
0
 /**
  * @since version 0.84 (before in entitydata.class)
  *
  * @param $entity Entity object
  **/
 static function showHelpdeskOptions(Entity $entity)
 {
     global $CFG_GLPI;
     $ID = $entity->getField('id');
     if (!$entity->can($ID, READ) || !Session::haveRightsOr(self::$rightname, array(self::READHELPDESK, self::UPDATEHELPDESK))) {
         return false;
     }
     $canedit = Session::haveRight(self::$rightname, self::UPDATEHELPDESK) && Session::haveAccessToEntity($ID);
     echo "<div class='spaced'>";
     if ($canedit) {
         echo "<form method='post' name=form action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
     }
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'><td colspan='2'>" . _n('Ticket template', 'Ticket templates', 1) . "</td>";
     echo "<td colspan='2'>";
     $toadd = array();
     if ($ID != 0) {
         $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
     }
     $options = array('value' => $entity->fields["tickettemplates_id"], 'entity' => $ID, 'toadd' => $toadd);
     TicketTemplate::dropdown($options);
     if ($entity->fields["tickettemplates_id"] == self::CONFIG_PARENT && $ID != 0) {
         echo "<font class='green'>&nbsp;&nbsp;";
         $tt = new TicketTemplate();
         $tid = self::getUsedConfig('tickettemplates_id', $ID, '', 0);
         if (!$tid) {
             echo Dropdown::EMPTY_VALUE;
         } else {
             if ($tt->getFromDB($tid)) {
                 echo $tt->getLink();
             }
         }
         echo "</font>";
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='2'>" . __('Calendar') . "</td>";
     echo "<td colspan='2'>";
     $options = array('value' => $entity->fields["calendars_id"], 'emptylabel' => __('24/7'));
     if ($ID != 0) {
         $options['toadd'] = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
     }
     Calendar::dropdown($options);
     if ($entity->fields["calendars_id"] == self::CONFIG_PARENT && $ID != 0) {
         echo "<font class='green'>&nbsp;&nbsp;";
         $calendar = new Calendar();
         $cid = self::getUsedConfig('calendars_id', $ID, '', 0);
         if (!$cid) {
             _e('24/7');
         } else {
             if ($calendar->getFromDB($cid)) {
                 echo $calendar->getLink();
             }
         }
         echo "</font>";
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td colspan='2'>" . __('Tickets default type') . "</td>";
     echo "<td colspan='2'>";
     $toadd = array();
     if ($ID != 0) {
         $toadd = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'));
     }
     Ticket::dropdownType('tickettype', array('value' => $entity->fields["tickettype"], 'toadd' => $toadd));
     if ($entity->fields['tickettype'] == self::CONFIG_PARENT && $ID != 0) {
         echo "<font class='green'>&nbsp;&nbsp;";
         echo Ticket::getTicketTypeName(self::getUsedConfig('tickettype', $ID, '', Ticket::INCIDENT_TYPE));
         echo "</font>";
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td  colspan='2'>" . __('Automatic assignment of tickets') . "</td>";
     echo "<td colspan='2'>";
     $autoassign = self::getAutoAssignMode();
     if ($ID == 0) {
         unset($autoassign[self::CONFIG_PARENT]);
     }
     Dropdown::showFromArray('auto_assign_mode', $autoassign, array('value' => $entity->fields["auto_assign_mode"]));
     if ($entity->fields['auto_assign_mode'] == self::CONFIG_PARENT && $ID != 0) {
         $auto_assign_mode = self::getUsedConfig('auto_assign_mode', $entity->fields['entities_id']);
         echo "<font class='green'>&nbsp;&nbsp;";
         echo $autoassign[$auto_assign_mode];
         echo "</font>";
     }
     echo "</td></tr>";
     echo "<tr><th colspan='4'>" . __('Automatic closing configuration') . "</th></tr>";
     echo "<tr class='tab_bg_1'>" . "<td colspan='2'>" . __('Automatic closing of solved tickets after') . "</td>";
     echo "<td colspan='2'>";
     $autoclose = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'), self::CONFIG_NEVER => __('Never'), 0 => __('Immediatly'));
     if ($ID == 0) {
         unset($autoclose[self::CONFIG_PARENT]);
     }
     Dropdown::showNumber('autoclose_delay', array('value' => $entity->fields['autoclose_delay'], 'min' => 1, 'max' => 99, 'step' => 1, 'toadd' => $autoclose, 'unit' => 'day'));
     if ($entity->fields['autoclose_delay'] == self::CONFIG_PARENT && $ID != 0) {
         $autoclose_mode = self::getUsedConfig('autoclose_delay', $entity->fields['entities_id'], '', self::CONFIG_NEVER);
         echo "<br><font class='green'>&nbsp;&nbsp;";
         if ($autoclose_mode >= 0) {
             printf(_n('%d day', '%d days', $autoclose_mode), $autoclose_mode);
         } else {
             echo $autoclose[$autoclose_mode];
         }
         echo "</font>";
     }
     echo "</td></tr>";
     echo "<tr><th colspan='4'>" . __('Configuring the satisfaction survey') . "</th></tr>";
     echo "<tr class='tab_bg_1'>" . "<td colspan='2'>" . __('Configuring the satisfaction survey') . "</td>";
     echo "<td colspan='2'>";
     /// no inquest case = rate 0
     $typeinquest = array(self::CONFIG_PARENT => __('Inheritance of the parent entity'), 1 => __('Internal survey'), 2 => __('External survey'));
     // No inherit from parent for root entity
     if ($ID == 0) {
         unset($typeinquest[self::CONFIG_PARENT]);
         if ($entity->fields['inquest_config'] == self::CONFIG_PARENT) {
             $entity->fields['inquest_config'] = 1;
         }
     }
     $rand = Dropdown::showFromArray('inquest_config', $typeinquest, $options = array('value' => $entity->fields['inquest_config']));
     echo "</td></tr>\n";
     // Do not display for root entity in inherit case
     if ($entity->fields['inquest_config'] == self::CONFIG_PARENT && $ID != 0) {
         $inquestconfig = self::getUsedConfig('inquest_config', $entity->fields['entities_id']);
         $inquestrate = self::getUsedConfig('inquest_config', $entity->fields['entities_id'], 'inquest_rate');
         echo "<tr class='tab_bg_1'><td colspan='4' class='green center'>";
         if ($inquestrate == 0) {
             _e('Disabled');
         } else {
             echo $typeinquest[$inquestconfig] . '<br>';
             $inqconf = self::getUsedConfig('inquest_config', $entity->fields['entities_id'], 'inquest_delay');
             printf(_n('%d day', '%d days', $inqconf), $inqconf);
             echo "<br>";
             //TRANS: %d is the percentage. %% to display %
             printf(__('%d%%'), $inquestrate);
             if ($inquestconfig == 2) {
                 echo "<br>";
                 echo self::getUsedConfig('inquest_config', $entity->fields['entities_id'], 'inquest_URL');
             }
         }
         echo "</td></tr>\n";
     }
     echo "<tr class='tab_bg_1'><td colspan='4'>";
     $_POST = array('inquest_config' => $entity->fields['inquest_config'], 'entities_id' => $ID);
     $params = array('inquest_config' => '__VALUE__', 'entities_id' => $ID);
     echo "<div id='inquestconfig'>";
     include GLPI_ROOT . '/ajax/ticketsatisfaction.php';
     echo "</div>\n";
     echo "</td></tr>";
     if ($canedit) {
         echo "<tr class='tab_bg_2'>";
         echo "<td class='center' colspan='4'>";
         echo "<input type='hidden' name='id' value='" . $entity->fields["id"] . "'>";
         echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n                  class='submit'>";
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
     } else {
         echo "</table>";
     }
     echo "</div>";
     Ajax::updateItemOnSelectEvent("dropdown_inquest_config{$rand}", "inquestconfig", $CFG_GLPI["root_doc"] . "/ajax/ticketsatisfaction.php", $params);
 }
 /**
  * Create a ticket based on ticket recurrent infos
  *
  * @param $data array data of a entry of glpi_ticketrecurrents
  *
  * @return boolean
  **/
 static function createTicket($data)
 {
     $result = false;
     $tt = new TicketTemplate();
     // Create ticket based on ticket template and entity information of ticketrecurrent
     if ($tt->getFromDB($data['tickettemplates_id'])) {
         // Get default values for ticket
         $input = Ticket::getDefaultValues($data['entities_id']);
         // Apply tickettemplates predefined values
         $ttp = new TicketTemplatePredefinedField();
         $predefined = $ttp->getPredefinedFields($data['tickettemplates_id'], true);
         if (count($predefined)) {
             foreach ($predefined as $predeffield => $predefvalue) {
                 $input[$predeffield] = $predefvalue;
             }
         }
         // Set date to creation date
         $createtime = strtotime($data['next_creation_date']) + $data['create_before'];
         $input['date'] = date('Y-m-d H:i:s', $createtime);
         if (isset($predefined['date'])) {
             $input['date'] = Html::computeGenericDateTimeSearch($predefined['date'], false, $createtime);
         }
         // Compute due_date if predefined based on create date
         if (isset($predefined['due_date'])) {
             $input['due_date'] = Html::computeGenericDateTimeSearch($predefined['due_date'], false, $createtime);
         }
         // Set entity
         $input['entities_id'] = $data['entities_id'];
         $input['_auto_import'] = true;
         $ticket = new Ticket();
         $input = Toolbox::addslashes_deep($input);
         if ($tid = $ticket->add($input)) {
             $msg = sprintf(__('Ticket %d successfully created'), $tid);
             $result = true;
         } else {
             $msg = __('Ticket creation failed (check mandatory fields)');
         }
     } else {
         $msg = __('Ticket creation failed (no template)');
     }
     $changes[0] = 0;
     $changes[1] = '';
     $changes[2] = addslashes($msg);
     Log::history($data['id'], __CLASS__, $changes, '', Log::HISTORY_LOG_SIMPLE_MESSAGE);
     // Compute next creation date
     $tr = new self();
     if ($tr->getFromDB($data['id'])) {
         $input = array();
         $input['id'] = $data['id'];
         $input['next_creation_date'] = $tr->computeNextCreationDate($data['begin_date'], $data['end_date'], $data['periodicity'], $data['create_before'], $data['calendars_id']);
         $tr->update($input);
     }
     return $result;
 }
Exemple #6
0
 public function generateNewItem($params)
 {
     global $DB;
     // Retrieve plugin configuration
     $config = new PluginOrderConfig();
     $reference = new PluginOrderReference();
     foreach ($params["id"] as $tmp => $values) {
         //If itemtype cannot be generated, go to the new occurence
         if (in_array($values['itemtype'], self::getTypesThanCannotBeGenerared())) {
             continue;
         }
         $entity = $values["entities_id"];
         //------------- Template management -----------------------//
         //Look for a template in the entity
         $templateID = $reference->checkIfTemplateExistsInEntity($values["id"], $values["itemtype"], $entity);
         $item = new $values["itemtype"]();
         if ($values['itemtype']) {
             $order = new PluginOrderOrder();
         }
         $order->getFromDB($values["plugin_order_orders_id"]);
         $reference->getFromDB($params["plugin_order_references_id"]);
         if ($templateID) {
             $item->getFromDB($templateID);
             unset($item->fields["is_template"]);
             unset($item->fields["date_mod"]);
             $fields = array();
             foreach ($item->fields as $key => $value) {
                 if ($value != '' && (!isset($fields[$key]) || $fields[$key] == '' || $fields[$key] == 0)) {
                     $input[$key] = $value;
                 }
             }
             if ($config->getGeneratedAssetState()) {
                 $input["states_id"] = $config->getGeneratedAssetState();
             }
             $input["entities_id"] = $entity;
             $input["serial"] = $values["serial"];
             if ($item->fields['name']) {
                 $input["name"] = autoName($item->fields["name"], "name", $templateID, $values["itemtype"], $entity);
             } else {
                 $input["name"] = $values["name"];
             }
             if ($item->getField('otherserial') != NOT_AVAILABLE) {
                 if ($item->fields['otherserial']) {
                     $input["otherserial"] = autoName($item->fields["otherserial"], "otherserial", $templateID, $values["itemtype"], $entity);
                 } else {
                     $input["otherserial"] = $values["otherserial"];
                 }
             }
             if ($config->canAddLocation()) {
                 $input['locations_id'] = $order->fields['locations_id'];
             }
         } elseif ($values["itemtype"] == 'Contract') {
             $input["name"] = $values["name"];
             $input["entities_id"] = $entity;
             $input['contracttypes_id'] = $reference->fields['types_id'];
         } else {
             if ($config->getGeneratedAssetState()) {
                 $input["states_id"] = $config->getGeneratedAssetState();
             } else {
                 $input["states_id"] = 0;
             }
             $input["entities_id"] = $entity;
             $input["serial"] = $values["serial"];
             $input["otherserial"] = $values["otherserial"];
             $input["name"] = $values["name"];
             // Get bill data
             if ($config->canAddLocation()) {
                 $input['locations_id'] = $order->fields['locations_id'];
             }
             $input["manufacturers_id"] = $reference->fields["manufacturers_id"];
             $typefield = getForeignKeyFieldForTable(getTableForItemType($values["itemtype"] . "Type"));
             $input[$typefield] = $reference->fields["types_id"];
             $modelfield = getForeignKeyFieldForTable(getTableForItemType($values["itemtype"] . "Model"));
             $input[$modelfield] = $reference->fields["models_id"];
         }
         $input = Toolbox::addslashes_deep($input);
         $newID = $item->add($input);
         // Attach new ticket if option is on
         if (isset($params['generate_ticket'])) {
             $tkt = new TicketTemplate();
             if ($tkt->getFromDB($params['generate_ticket']['tickettemplates_id'])) {
                 $input = array();
                 $input = Ticket::getDefaultValues($entity);
                 $ttp = new TicketTemplatePredefinedField();
                 $predefined = $ttp->getPredefinedFields($params['generate_ticket']['tickettemplates_id'], true);
                 if (count($predefined)) {
                     foreach ($predefined as $predeffield => $predefvalue) {
                         $input[$predeffield] = $predefvalue;
                     }
                 }
                 $input['entities_id'] = $entity;
                 $input['_users_id_requester'] = empty($order->fields['users_id']) ? Session::getLoginUserID() : $order->fields['users_id'];
                 $input['items_id'] = $newID;
                 $input['itemtype'] = $values["itemtype"];
                 $ticket = new Ticket();
                 $ticketID = $ticket->add($input);
             }
         }
         //-------------- End template management ---------------------------------//
         $result = $this->createLinkWithItem($values["id"], $newID, $values["itemtype"], $values["plugin_order_orders_id"], $entity, $templateID, false, false);
         //Add item's history
         $new_value = __("Item generated by using order", "order") . ' : ' . $order->fields["name"];
         $order->addHistory($values["itemtype"], '', $new_value, $newID);
         //Add order's history
         $new_value = __("Item generated by using order", "order") . ' : ';
         $new_value .= $item->getTypeName() . " -> " . $item->getField("name");
         $order->addHistory('PluginOrderOrder', '', $new_value, $values["plugin_order_orders_id"]);
         //Copy order documents if needed
         self::copyDocuments($values['itemtype'], $newID, $values["plugin_order_orders_id"], $entity);
         Session::addMessageAfterRedirect(__("Item successfully selected", "order"), true);
     }
 }
 /**
  * Print the hidden fields
  *
  * @since version 0.83
  *
  * @param $tt                       Ticket Template
  * @param $withtemplate    boolean  Template or basic item (default '')
  *
  * @return Nothing (call to classes members)
  **/
 static function showForTicketTemplate(TicketTemplate $tt, $withtemplate = '')
 {
     global $DB;
     $ID = $tt->fields['id'];
     if (!$tt->getFromDB($ID) || !$tt->can($ID, "r")) {
         return false;
     }
     $ttm = new self();
     $used = $ttm->getHiddenFields($ID);
     $canedit = $tt->can($ID, "w");
     $fields = $tt->getAllowedFieldsNames(false, isset($used['itemtype']));
     $rand = mt_rand();
     $query = "SELECT `glpi_tickettemplatehiddenfields`.*\n                FROM `glpi_tickettemplatehiddenfields`\n                WHERE (`tickettemplates_id` = '{$ID}')";
     if ($result = $DB->query($query)) {
         $hiddenfields = array();
         $used = array();
         if ($numrows = $DB->numrows($result)) {
             while ($data = $DB->fetch_assoc($result)) {
                 $hiddenfields[$data['id']] = $data;
                 $used[$data['num']] = $data['num'];
             }
         }
         if ($canedit) {
             echo "<div class='firstbloc'>";
             echo "<form name='changeproblem_form{$rand}' id='changeproblem_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL(__CLASS__) . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add a hidden field') . "</th></tr>";
             echo "<tr class='tab_bg_2'><td class='right'>";
             echo "<input type='hidden' name='tickettemplates_id' value='{$ID}'>";
             Dropdown::showFromArray('num', $fields, array('used' => $used));
             echo "</td><td class='center'>";
             echo "&nbsp;<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             echo "</td></tr>";
             echo "</table>";
             Html::closeForm();
             echo "</div>";
         }
         echo "<div class='spaced'>";
         if ($canedit && $numrows) {
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => $numrows);
             Html::showMassiveActions(__CLASS__, $massiveactionparams);
         }
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='2'>";
         echo self::getTypeName($DB->numrows($result));
         echo "</th></tr>";
         if ($numrows) {
             echo "<tr>";
             if ($canedit) {
                 echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
             }
             echo "<th>" . __('Name') . "</th>";
             echo "</tr>";
             foreach ($hiddenfields as $data) {
                 echo "<tr class='tab_bg_2'>";
                 if ($canedit) {
                     echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>";
                 }
                 echo "<td>" . $fields[$data['num']] . "</td>";
                 echo "</tr>";
             }
         } else {
             echo "<tr><th colspan='2'>" . __('No item found') . "</th></tr>";
         }
         echo "</table>";
         if ($canedit && $numrows) {
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions(__CLASS__, $massiveactionparams);
             Html::closeForm();
         }
         echo "</div>";
     }
 }
 function showTicketTemplate($items_id)
 {
     global $CFG_GLPI;
     $ticketTemplate = new TicketTemplate();
     echo "<form method='post' name='form_addquestion' action='" . $CFG_GLPI['root_doc'] . "/plugins/surveyticket/front/tickettemplate.form.php'>";
     echo "<table class='tab_cadre' width='700'>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Ticket template') . "&nbsp;:</td>";
     echo "<td>";
     $a_used = array();
     Dropdown::show("TicketTemplate", array("name" => "tickettemplates_id", "used" => $a_used));
     echo "</td>";
     echo "<td>" . __('Type') . "&nbsp;:</td>";
     echo "<td>";
     Ticket::dropdownType("type");
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Simplified interface') . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::showYesNo("is_helpdesk");
     echo "</td>";
     echo "<td>" . __('Standard interface') . "&nbsp;:</td>";
     echo "<td>";
     Dropdown::showYesNo("is_central");
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td class='tab_bg_2 top' colspan='4'>";
     echo "<input type='hidden' name='plugin_surveyticket_surveys_id' value='" . $items_id . "'>";
     echo "<div class='center'>";
     echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
     echo "</div></td></tr>";
     echo "</table>";
     Html::closeForm();
     // list templates
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>";
     echo __('Ticket template');
     echo "</th>";
     echo "<th>";
     echo __('Type');
     echo "</th>";
     echo "<th>";
     echo __('Simplified interface');
     echo "</th>";
     echo "<th>";
     echo __('Standard interface');
     echo "</th>";
     echo "<th>";
     echo "</th>";
     echo "</tr>";
     $_tickettempaltes = $this->find("`plugin_surveyticket_surveys_id`='" . $items_id . "'");
     foreach ($_tickettempaltes as $data) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>";
         $ticketTemplate->getFromDB($data['tickettemplates_id']);
         echo $ticketTemplate->getLink(1);
         echo "</td>";
         echo "<td>";
         echo Ticket::getTicketTypeName($data['type']);
         echo "</td>";
         echo "<td>";
         echo Dropdown::getYesNo($data['is_helpdesk']);
         echo "</td>";
         echo "<td>";
         echo Dropdown::getYesNo($data['is_central']);
         echo "</td>";
         echo "<td align='center'>";
         echo "<form method='post' name='form_delettickettemplate' action='" . $CFG_GLPI['root_doc'] . "/plugins/surveyticket/front/tickettemplate.form.php'>";
         echo "<input type='hidden' name='id' value='" . $data['id'] . "'>";
         echo "<input type='submit' name='delete' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>";
         Html::closeForm();
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }
 static function createTicket($data)
 {
     $result = false;
     $tt = new TicketTemplate();
     // Create ticket based on ticket template and entity informations of ticketrecurrent
     if ($tt->getFromDB($data['tickettemplates_id'])) {
         // Get default values for ticket
         $input = Ticket::getDefaultValues($data['entities_id']);
         // Apply tickettemplates predefined values
         $ttp = new TicketTemplatePredefinedField();
         $predefined = $ttp->getPredefinedFields($data['tickettemplates_id'], true);
         if (count($predefined)) {
             foreach ($predefined as $predeffield => $predefvalue) {
                 $input[$predeffield] = $predefvalue;
             }
         }
         // Set date to creation date
         $createtime = date('Y-m-d H:i:s');
         $input['date'] = $createtime;
         // Compute due_date if predefined based on create date
         if (isset($predefined['due_date'])) {
             $input['due_date'] = Html::computeGenericDateTimeSearch($predefined['due_date'], false, $createtime);
         }
         // Set entity
         $input['entities_id'] = $data['entities_id'];
         $input['actiontime'] = $data['actiontime'];
         $res = new PluginResourcesResource();
         if ($res->getFromDB($data['plugin_resources_resources_id'])) {
             $input['users_id_recipient'] = $res->fields['users_id_recipient'];
             $input['_users_id_requester'] = $res->fields['users_id_recipient'];
             if (isset($res->fields['users_id'])) {
                 $input['_users_id_observer'] = $res->fields['users_id'];
             }
             $input['_users_id_assign'] = Session::getLoginUserID();
             $input["itemtype"] = "PluginResourcesResource";
             $input["items_id"] = $data['plugin_resources_resources_id'];
             $input["name"] .= addslashes(" " . PluginResourcesResource::getResourceName($data['plugin_resources_resources_id']));
         }
         //TODO : ADD checklist lists or add config into plugin ?
         $input["content"] .= addslashes("\n\n");
         $input['status'] = Ticket::CLOSED;
         $ticket = new Ticket();
         $input = Toolbox::addslashes_deep($input);
         if ($tid = $ticket->add($input)) {
             $msg = __('Create a end treatment ticket', 'resources') . " OK - ({$tid})";
             // Success
             $result = true;
         } else {
             $msg = __('Failed operation');
             // Failure
         }
     } else {
         $msg = __('No selected element or badly defined operation');
         // Not defined
     }
     if ($tid) {
         $changes[0] = 0;
         $changes[1] = '';
         $changes[2] = addslashes($msg);
         Log::history($data['plugin_resources_resources_id'], "PluginResourcesResource", $changes, '', Log::HISTORY_LOG_SIMPLE_MESSAGE);
     }
     return $result;
 }