grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026. -------------------------------------------------------------------------- */ /** @file * @brief */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * TicketTemplatePredefinedField Class * * Predefined fields for ticket template class * * @since version 0.83 **/ class TicketTemplatePredefinedField extends CommonDBChild { // From CommonDBChild static public $itemtype = 'TicketTemplate'; static public $items_id = 'tickettemplates_id'; public $dohistory = true; /** * @since version 0.84 **/ function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); $forbidden[] = 'update'; return $forbidden; } static function getTypeName($nb=0) { return _n('Predefined field', 'Predefined fields', $nb); } /** * @see CommonDBTM::getRawName() * * @since version 0.85 **/ function getRawName() { $tt = new TicketTemplate(); $fields = $tt->getAllowedFieldsNames(true, true); if (isset($fields[$this->fields["num"]])) { return $fields[$this->fields["num"]]; } return ''; } function prepareInputForAdd($input) { // Use massiveaction system to manage add system. // Need to update data : value not set but if (!isset($input['value'])) { if (isset($input['field']) && isset($input[$input['field']])) { $input['value'] = $input[$input['field']]; unset($input[$input['field']]); unset($input['field']); } } return parent::prepareInputForAdd($input); } function post_purgeItem() { global $DB; parent::post_purgeItem(); $ticket = new Ticket(); $itemtype_id = $ticket->getSearchOptionIDByField('field', 'itemtype', 'glpi_tickets'); $items_id_id = $ticket->getSearchOptionIDByField('field', 'items_id', 'glpi_tickets'); // Try to delete itemtype -> delete items_id if ($this->fields['num'] == $itemtype_id) { $query = "SELECT `id` FROM `".$this->getTable()."` WHERE `".static::$items_id."` = '".$this->fields['tickettemplates_id']."' AND `num` = '$items_id_id'"; if ($result = $DB->query($query)) { if ($DB->numrows($result)) { $a = new self(); $a->delete(array('id'=>$DB->result($result,0,0))); } } } } function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { // can exists for template if (($item->getType() == 'TicketTemplate') && Session::haveRight("tickettemplate", READ)) { $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable($this->getTable(), "`tickettemplates_id` = '".$item->getID()."'"); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0) { self::showForTicketTemplate($item, $withtemplate); return true; } /** * Get predefined fields for a template * * @since version 0.83 * * @param $ID integer the template ID * @param $withtypeandcategory boolean with type and category (false by default) * * @return an array of predefined fields **/ function getPredefinedFields($ID, $withtypeandcategory=false) { global $DB; $sql = "SELECT * FROM `".$this->getTable()."` WHERE `".static::$items_id."` = '$ID' ORDER BY `id`"; $result = $DB->query($sql); $tt = new TicketTemplate(); $allowed_fields = $tt->getAllowedFields($withtypeandcategory, true); $fields = array(); $multiple = self::getMultiplePredefinedValues(); while ($rule = $DB->fetch_assoc($result)) { if (isset($allowed_fields[$rule['num']])) { if (in_array($rule['num'], $multiple)) { if ($allowed_fields[$rule['num']] == 'items_id') { $item_itemtype = explode("_", $rule['value']); $fields[$allowed_fields[$rule['num']]][$item_itemtype[0]][$item_itemtype[1]] = $item_itemtype[1]; } else { $fields[$allowed_fields[$rule['num']]][] = $rule['value']; } } else { $fields[$allowed_fields[$rule['num']]] = $rule['value']; } } } return $fields; } /** * @since version 0.85 **/ static function getMultiplePredefinedValues() { $ticket = new Ticket(); $fields = array($ticket->getSearchOptionIDByField('field', 'name', 'glpi_documents'), $ticket->getSearchOptionIDByField('field', 'items_id', 'glpi_items_tickets')); return $fields; } /** * 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`.* FROM `glpi_tickettemplatepredefinedfields` WHERE (`tickettemplates_id` = '$ID') 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 "
| "; echo self::getTypeName($DB->numrows($result)); echo " | |||
|---|---|---|---|
| "; $header_top .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)." | "; $header_bottom .= ""; $header_bottom .= Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)." | "; } $header_end .= "".__('Name')." | "; $header_end .= "".__('Value')." | "; $header_end .= "
| ".Html::getMassiveActionCheckBox(__CLASS__, $data["id"])." | "; } echo "".$fields[$data['num']]." | "; echo ""; $display_datas[$searchOption[$data['num']]['field']] = $data['value']; echo $ticket->getValueToDisplay($searchOption[$data['num']], $display_datas, $display_options); echo " | "; echo "|
| ".__('No item found')." | |||