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 " <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>";
}
}