kundenkarte/admin/anlage_types.php
2026-01-31 08:18:54 +01:00

647 lines
26 KiB
PHP
Executable file

<?php
/* Copyright (C) 2026 Alles Watt lauft
*
* Admin page to manage installation element types
*/
$res = 0;
if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
if (!$res) die("Include of main fails");
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
dol_include_once('/kundenkarte/lib/kundenkarte.lib.php');
dol_include_once('/kundenkarte/class/anlagetype.class.php');
$langs->loadLangs(array('admin', 'kundenkarte@kundenkarte'));
// Security check
if (!$user->admin && !$user->hasRight('kundenkarte', 'admin')) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$typeId = GETPOSTINT('typeid');
$systemFilter = GETPOSTINT('system');
$form = new Form($db);
$anlageType = new AnlageType($db);
// Load systems
$systems = array();
$sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system WHERE active = 1 ORDER BY position ASC";
$resql = $db->query($sql);
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$systems[$obj->rowid] = $obj;
}
}
/*
* Actions
*/
if ($action == 'add') {
$anlageType->ref = GETPOST('ref', 'aZ09');
$anlageType->label = GETPOST('label', 'alphanohtml');
$anlageType->label_short = GETPOST('label_short', 'alphanohtml');
$anlageType->description = GETPOST('description', 'restricthtml');
$anlageType->fk_system = GETPOSTINT('fk_system');
$anlageType->can_have_children = GETPOSTINT('can_have_children');
$anlageType->can_be_nested = GETPOSTINT('can_be_nested');
$anlageType->allowed_parent_types = GETPOST('allowed_parent_types', 'alphanohtml');
$anlageType->picto = GETPOST('picto', 'alphanohtml');
$anlageType->color = GETPOST('color', 'alphanohtml');
$anlageType->position = GETPOSTINT('position');
$anlageType->active = 1;
if (empty($anlageType->ref) || empty($anlageType->label) || empty($anlageType->fk_system)) {
setEventMessages($langs->trans('ErrorFieldRequired'), null, 'errors');
$action = 'create';
} else {
$result = $anlageType->create($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
header('Location: '.$_SERVER['PHP_SELF'].'?system='.$anlageType->fk_system);
exit;
} else {
setEventMessages($anlageType->error, $anlageType->errors, 'errors');
$action = 'create';
}
}
}
if ($action == 'update') {
$anlageType->fetch($typeId);
$anlageType->ref = GETPOST('ref', 'aZ09');
$anlageType->label = GETPOST('label', 'alphanohtml');
$anlageType->label_short = GETPOST('label_short', 'alphanohtml');
$anlageType->description = GETPOST('description', 'restricthtml');
$anlageType->fk_system = GETPOSTINT('fk_system');
$anlageType->can_have_children = GETPOSTINT('can_have_children');
$anlageType->can_be_nested = GETPOSTINT('can_be_nested');
$anlageType->allowed_parent_types = GETPOST('allowed_parent_types', 'alphanohtml');
$anlageType->picto = GETPOST('picto', 'alphanohtml');
$anlageType->color = GETPOST('color', 'alphanohtml');
$anlageType->position = GETPOSTINT('position');
$result = $anlageType->update($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
header('Location: '.$_SERVER['PHP_SELF'].'?system='.$anlageType->fk_system);
exit;
} else {
setEventMessages($anlageType->error, $anlageType->errors, 'errors');
$action = 'edit';
}
}
if ($action == 'confirm_delete' && $confirm == 'yes') {
$anlageType->fetch($typeId);
$result = $anlageType->delete($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
} else {
setEventMessages($anlageType->error, $anlageType->errors, 'errors');
}
$action = '';
}
if ($action == 'activate') {
$sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_anlage_type SET active = 1 WHERE rowid = ".((int) $typeId);
$db->query($sql);
$action = '';
}
if ($action == 'deactivate') {
$sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_anlage_type SET active = 0 WHERE rowid = ".((int) $typeId);
$db->query($sql);
$action = '';
}
// Field actions
$fieldId = GETPOSTINT('fieldid');
if ($action == 'add_field') {
$fieldCode = GETPOST('field_code', 'aZ09');
$fieldLabel = GETPOST('field_label', 'alphanohtml');
$fieldType = GETPOST('field_type', 'aZ09');
$fieldOptions = GETPOST('field_options', 'restricthtml');
$showInTree = GETPOSTINT('show_in_tree');
$showInHover = GETPOSTINT('show_in_hover');
$isRequired = GETPOSTINT('is_required');
$fieldPosition = GETPOSTINT('field_position');
if (empty($fieldCode) || empty($fieldLabel) || empty($fieldType)) {
setEventMessages($langs->trans('ErrorFieldRequired'), null, 'errors');
} else {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."kundenkarte_anlage_type_field";
$sql .= " (fk_anlage_type, field_code, field_label, field_type, field_options, show_in_tree, show_in_hover, required, position, active)";
$sql .= " VALUES (".((int) $typeId).", '".$db->escape($fieldCode)."', '".$db->escape($fieldLabel)."',";
$sql .= " '".$db->escape($fieldType)."', '".$db->escape($fieldOptions)."',";
$sql .= " ".((int) $showInTree).", ".((int) $showInHover).", ".((int) $isRequired).", ".((int) $fieldPosition).", 1)";
if ($db->query($sql)) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
} else {
setEventMessages($db->lasterror(), null, 'errors');
}
}
$action = 'edit';
}
if ($action == 'update_field') {
$fieldCode = GETPOST('field_code', 'aZ09');
$fieldLabel = GETPOST('field_label', 'alphanohtml');
$fieldType = GETPOST('field_type', 'aZ09');
$fieldOptions = GETPOST('field_options', 'restricthtml');
$showInTree = GETPOSTINT('show_in_tree');
$showInHover = GETPOSTINT('show_in_hover');
$isRequired = GETPOSTINT('is_required');
$fieldPosition = GETPOSTINT('field_position');
$sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_anlage_type_field SET";
$sql .= " field_code = '".$db->escape($fieldCode)."',";
$sql .= " field_label = '".$db->escape($fieldLabel)."',";
$sql .= " field_type = '".$db->escape($fieldType)."',";
$sql .= " field_options = '".$db->escape($fieldOptions)."',";
$sql .= " show_in_tree = ".((int) $showInTree).",";
$sql .= " show_in_hover = ".((int) $showInHover).",";
$sql .= " required = ".((int) $isRequired).",";
$sql .= " position = ".((int) $fieldPosition);
$sql .= " WHERE rowid = ".((int) $fieldId);
if ($db->query($sql)) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
} else {
setEventMessages($db->lasterror(), null, 'errors');
}
$action = 'edit';
}
if ($action == 'confirm_delete_field' && $confirm == 'yes') {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."kundenkarte_anlage_type_field WHERE rowid = ".((int) $fieldId);
if ($db->query($sql)) {
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
} else {
setEventMessages($db->lasterror(), null, 'errors');
}
$action = 'edit';
}
if ($action == 'activate_field') {
$sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_anlage_type_field SET active = 1 WHERE rowid = ".((int) $fieldId);
$db->query($sql);
$action = 'edit';
}
if ($action == 'deactivate_field') {
$sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_anlage_type_field SET active = 0 WHERE rowid = ".((int) $fieldId);
$db->query($sql);
$action = 'edit';
}
/*
* View
*/
$title = $langs->trans('AnlagenTypes');
// Include CSS and JS
$morejs = array('/kundenkarte/js/kundenkarte.js');
$morecss = array('/kundenkarte/css/kundenkarte.css');
llxHeader('', $title, '', '', 0, 0, $morejs, $morecss);
$head = kundenkarteAdminPrepareHead();
print dol_get_fiche_head($head, 'types', $langs->trans('ModuleKundenKarteName'), -1, 'fa-file');
// Confirmation
if ($action == 'delete') {
print $form->formconfirm(
$_SERVER['PHP_SELF'].'?typeid='.$typeId.'&system='.$systemFilter,
$langs->trans('Delete'),
$langs->trans('ConfirmDeleteType'),
'confirm_delete',
'',
'yes',
1
);
}
// Add/Edit form
if (in_array($action, array('create', 'edit'))) {
if ($action == 'edit' && $typeId > 0) {
$anlageType->fetch($typeId);
}
// Get all types for parent selection
$allTypes = $anlageType->fetchAllBySystem(0, 0);
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'add').'">';
if ($action == 'edit') {
print '<input type="hidden" name="typeid" value="'.$typeId.'">';
}
print '<table class="border centpercent">';
// System
print '<tr><td class="titlefield fieldrequired">'.$langs->trans('System').'</td>';
print '<td><select name="fk_system" class="flat minwidth200" required>';
print '<option value="">'.$langs->trans('SelectSystem').'</option>';
foreach ($systems as $sys) {
$sel = ($anlageType->fk_system == $sys->rowid) ? ' selected' : '';
print '<option value="'.$sys->rowid.'"'.$sel.'>'.dol_escape_htmltag($sys->label).'</option>';
}
print '</select></td></tr>';
// Reference
print '<tr><td class="fieldrequired">'.$langs->trans('TypeRef').'</td>';
print '<td><input type="text" name="ref" class="flat minwidth200" value="'.dol_escape_htmltag($anlageType->ref).'" maxlength="64" required>';
print ' <span class="opacitymedium">(UPPERCASE, no spaces)</span></td></tr>';
// Label
print '<tr><td class="fieldrequired">'.$langs->trans('TypeLabel').'</td>';
print '<td><input type="text" name="label" class="flat minwidth300" value="'.dol_escape_htmltag($anlageType->label).'" required></td></tr>';
// Short label
print '<tr><td>'.$langs->trans('TypeShortLabel').'</td>';
print '<td><input type="text" name="label_short" class="flat" value="'.dol_escape_htmltag($anlageType->label_short).'" maxlength="64"></td></tr>';
// Description
print '<tr><td>'.$langs->trans('Description').'</td>';
print '<td><textarea name="description" class="flat minwidth300" rows="2">'.dol_escape_htmltag($anlageType->description).'</textarea></td></tr>';
// Can have children
print '<tr><td>'.$langs->trans('CanHaveChildren').'</td>';
print '<td><input type="checkbox" name="can_have_children" value="1"'.($anlageType->can_have_children ? ' checked' : '').'></td></tr>';
// Can be nested
print '<tr><td>'.$langs->trans('CanBeNested').'</td>';
print '<td><input type="checkbox" name="can_be_nested" value="1"'.($anlageType->can_be_nested ? ' checked' : '').'>';
print ' <span class="opacitymedium">('.$langs->trans('SameTypeUnderItself').')</span></td></tr>';
// Allowed parent types - with multi-select UI
print '<tr><td>'.$langs->trans('AllowedParentTypes').'</td>';
print '<td>';
// Hidden field to store the actual value
print '<input type="hidden" name="allowed_parent_types" id="allowed_parent_types" value="'.dol_escape_htmltag($anlageType->allowed_parent_types).'">';
// Selection UI
print '<div class="kundenkarte-parent-types-selector">';
// Select dropdown with add button
print '<div style="display:flex;gap:5px;margin-bottom:10px;align-items:center;">';
print '<select id="parent_type_select" class="flat" style="height:30px;">';
print '<option value="">'.$langs->trans('SelectType').'</option>';
foreach ($allTypes as $t) {
// Don't show current type in list (can't be parent of itself unless can_be_nested)
if ($action == 'edit' && $t->id == $typeId) continue;
print '<option value="'.dol_escape_htmltag($t->ref).'" data-label="'.dol_escape_htmltag($t->label).'">'.dol_escape_htmltag($t->ref).' - '.dol_escape_htmltag($t->label).'</option>';
}
print '</select>';
print '<button type="button" class="button" id="add_parent_type_btn"><i class="fa fa-plus"></i> '.$langs->trans('Add').'</button>';
print '</div>';
// List of selected parent types
print '<div id="selected_parent_types" class="kundenkarte-selected-items">';
// Will be filled by JavaScript
print '</div>';
print '</div>';
print '<span class="opacitymedium">('.$langs->trans('AllowedParentTypesHelp').')</span>';
print '</td></tr>';
// Icon
print '<tr><td>'.$langs->trans('SystemPicto').'</td>';
print '<td><div class="kundenkarte-icon-picker-wrapper">';
print '<span class="kundenkarte-icon-preview">';
if ($anlageType->picto) {
print kundenkarte_render_icon($anlageType->picto);
}
print '</span>';
print '<input type="text" name="picto" class="flat minwidth200" value="'.dol_escape_htmltag($anlageType->picto).'" placeholder="fa-cube">';
print '<button type="button" class="kundenkarte-icon-picker-btn" data-input="picto"><i class="fa fa-th"></i> '.$langs->trans('SelectIcon').'</button>';
print '</div></td></tr>';
// Position
print '<tr><td>'.$langs->trans('Position').'</td>';
print '<td><input type="number" name="position" class="flat" value="'.($anlageType->position ?: 0).'" min="0"></td></tr>';
print '</table>';
print '<div class="center" style="margin-top:20px;">';
print '<button type="submit" class="button">'.$langs->trans('Save').'</button>';
print ' <a class="button button-cancel" href="'.$_SERVER['PHP_SELF'].'?system='.$systemFilter.'">'.$langs->trans('Cancel').'</a>';
print '</div>';
print '</form>';
// Fields management for existing type
if ($action == 'edit' && $typeId > 0) {
$editFieldId = GETPOSTINT('editfield');
// Confirmation for field deletion
if ($action == 'delete_field') {
print $form->formconfirm(
$_SERVER['PHP_SELF'].'?action=edit&typeid='.$typeId.'&fieldid='.$fieldId.'&system='.$systemFilter,
$langs->trans('Delete'),
$langs->trans('ConfirmDeleteField'),
'confirm_delete_field',
'',
'yes',
1
);
}
print '<br><br>';
print '<h3>'.$langs->trans('AnlagenTypeFields').'</h3>';
$fields = $anlageType->fetchFields(0);
// Field types available
$fieldTypes = array(
'text' => 'Textfeld (einzeilig)',
'textarea' => 'Textfeld (mehrzeilig)',
'number' => 'Zahlenfeld',
'select' => 'Dropdown-Auswahl',
'date' => 'Datumsfeld',
'checkbox' => 'Checkbox (Ja/Nein)',
);
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans('FieldCode').'</th>';
print '<th>'.$langs->trans('FieldLabel').'</th>';
print '<th>'.$langs->trans('FieldType').'</th>';
print '<th>'.$langs->trans('FieldOptions').'</th>';
print '<th class="center">'.$langs->trans('ShowInTree').'</th>';
print '<th class="center">'.$langs->trans('ShowInHover').'</th>';
print '<th class="center">'.$langs->trans('IsRequired').'</th>';
print '<th class="center">'.$langs->trans('Position').'</th>';
print '<th class="center">'.$langs->trans('Status').'</th>';
print '<th class="center">'.$langs->trans('Actions').'</th>';
print '</tr>';
foreach ($fields as $field) {
// Check if we're editing this field
if ($editFieldId == $field->id) {
// Edit row
print '<tr class="oddeven">';
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="update_field">';
print '<input type="hidden" name="typeid" value="'.$typeId.'">';
print '<input type="hidden" name="fieldid" value="'.$field->id.'">';
print '<input type="hidden" name="system" value="'.$systemFilter.'">';
print '<td><input type="text" name="field_code" class="flat minwidth100" value="'.dol_escape_htmltag($field->field_code).'" required></td>';
print '<td><input type="text" name="field_label" class="flat minwidth150" value="'.dol_escape_htmltag($field->field_label).'" required></td>';
print '<td><select name="field_type" class="flat">';
foreach ($fieldTypes as $ftype => $flabel) {
$sel = ($field->field_type == $ftype) ? ' selected' : '';
print '<option value="'.$ftype.'"'.$sel.'>'.$flabel.'</option>';
}
print '</select></td>';
print '<td><input type="text" name="field_options" class="flat minwidth100" value="'.dol_escape_htmltag($field->field_options).'" placeholder="opt1|opt2|opt3"></td>';
print '<td class="center"><input type="checkbox" name="show_in_tree" value="1"'.($field->show_in_tree ? ' checked' : '').'></td>';
print '<td class="center"><input type="checkbox" name="show_in_hover" value="1"'.($field->show_in_hover ? ' checked' : '').'></td>';
print '<td class="center"><input type="checkbox" name="is_required" value="1"'.($field->required ? ' checked' : '').'></td>';
print '<td class="center"><input type="number" name="field_position" class="flat" style="width:50px;" value="'.$field->position.'" min="0"></td>';
print '<td></td>';
print '<td class="center nowraponall">';
print '<button type="submit" class="button buttongen marginrightonly" title="'.$langs->trans('Save').'"><i class="fa fa-save"></i></button>';
print '<a class="button buttongen" href="'.$_SERVER['PHP_SELF'].'?action=edit&typeid='.$typeId.'&system='.$systemFilter.'" title="'.$langs->trans('Cancel').'"><i class="fa fa-times"></i></a>';
print '</td>';
print '</form>';
print '</tr>';
} else {
// Display row
print '<tr class="oddeven">';
print '<td>'.dol_escape_htmltag($field->field_code).'</td>';
print '<td>'.dol_escape_htmltag($field->field_label).'</td>';
print '<td>'.dol_escape_htmltag($fieldTypes[$field->field_type] ?? $field->field_type).'</td>';
print '<td class="small opacitymedium">'.dol_escape_htmltag(dol_trunc($field->field_options, 20)).'</td>';
print '<td class="center">'.($field->show_in_tree ? img_picto('', 'tick') : '').'</td>';
print '<td class="center">'.($field->show_in_hover ? img_picto('', 'tick') : '').'</td>';
print '<td class="center">'.($field->required ? img_picto('', 'tick') : '').'</td>';
print '<td class="center">'.$field->position.'</td>';
print '<td class="center">';
if ($field->active) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=deactivate_field&typeid='.$typeId.'&fieldid='.$field->id.'&system='.$systemFilter.'&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=activate_field&typeid='.$typeId.'&fieldid='.$field->id.'&system='.$systemFilter.'&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
}
print '</td>';
print '<td class="center nowraponall">';
print '<a href="'.$_SERVER['PHP_SELF'].'?action=edit&typeid='.$typeId.'&editfield='.$field->id.'&system='.$systemFilter.'">'.img_edit().'</a>';
print ' <a href="'.$_SERVER['PHP_SELF'].'?action=delete_field&typeid='.$typeId.'&fieldid='.$field->id.'&system='.$systemFilter.'" class="deletelink">'.img_delete().'</a>';
print '</td>';
print '</tr>';
}
}
if (empty($fields)) {
print '<tr class="oddeven"><td colspan="10" class="opacitymedium">'.$langs->trans('NoFieldsDefined').'</td></tr>';
}
// Add new field row
print '<tr class="oddeven liste_titre_add">';
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add_field">';
print '<input type="hidden" name="typeid" value="'.$typeId.'">';
print '<input type="hidden" name="system" value="'.$systemFilter.'">';
print '<td><input type="text" name="field_code" class="flat minwidth100" placeholder="CODE" required></td>';
print '<td><input type="text" name="field_label" class="flat minwidth150" placeholder="'.$langs->trans('FieldLabel').'" required></td>';
print '<td><select name="field_type" class="flat" required>';
print '<option value="">'.$langs->trans('Select').'</option>';
foreach ($fieldTypes as $ftype => $flabel) {
print '<option value="'.$ftype.'">'.$flabel.'</option>';
}
print '</select></td>';
print '<td><input type="text" name="field_options" class="flat minwidth100" placeholder="opt1|opt2"></td>';
print '<td class="center"><input type="checkbox" name="show_in_tree" value="1"></td>';
print '<td class="center"><input type="checkbox" name="show_in_hover" value="1" checked></td>';
print '<td class="center"><input type="checkbox" name="is_required" value="1"></td>';
print '<td class="center"><input type="number" name="field_position" class="flat" style="width:50px;" value="0" min="0"></td>';
print '<td></td>';
print '<td class="center"><button type="submit" class="button buttongen"><i class="fa fa-plus"></i> '.$langs->trans('Add').'</button></td>';
print '</form>';
print '</tr>';
print '</table>';
// Help box for field options
print '<div class="info" style="margin-top:15px;">';
print '<p><strong><i class="fa fa-info-circle"></i> Hilfe: Feld-Optionen nach Feldtyp</strong></p>';
print '<table class="noborder" style="margin-top:10px;">';
print '<tr><td style="width:200px;"><strong>Textfeld (einzeilig)</strong></td><td>Keine Optionen nötig</td></tr>';
print '<tr><td><strong>Textfeld (mehrzeilig)</strong></td><td>Keine Optionen nötig</td></tr>';
print '<tr><td><strong>Zahlenfeld</strong></td><td>Optional: <code>min:0|max:100|step:0.1</code></td></tr>';
print '<tr><td><strong>Dropdown-Auswahl</strong></td><td><span style="color:#c00;">Pflicht!</span> Optionen mit <code>|</code> trennen, z.B.: <code>Option A|Option B|Option C</code></td></tr>';
print '<tr><td><strong>Datumsfeld</strong></td><td>Keine Optionen nötig</td></tr>';
print '<tr><td><strong>Checkbox (Ja/Nein)</strong></td><td>Keine Optionen nötig</td></tr>';
print '</table>';
print '</div>';
}
} else {
// System filter
print '<form method="GET" action="'.$_SERVER['PHP_SELF'].'" style="margin-bottom:15px;">';
print $langs->trans('FilterBySystem').': ';
print '<select name="system" class="flat" onchange="this.form.submit();">';
print '<option value="0">'.$langs->trans('All').'</option>';
foreach ($systems as $sys) {
$sel = ($systemFilter == $sys->rowid) ? ' selected' : '';
print '<option value="'.$sys->rowid.'"'.$sel.'>'.dol_escape_htmltag($sys->label).'</option>';
}
print '</select>';
print '</form>';
// Add button
print '<div style="margin-bottom:15px;">';
print '<a class="button" href="'.$_SERVER['PHP_SELF'].'?action=create&system='.$systemFilter.'">';
print '<i class="fa fa-plus"></i> '.$langs->trans('AddType');
print '</a>';
print '</div>';
// List
$types = $anlageType->fetchAllBySystem($systemFilter, 0);
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<th>'.$langs->trans('TypeRef').'</th>';
print '<th>'.$langs->trans('TypeLabel').'</th>';
print '<th>'.$langs->trans('System').'</th>';
print '<th class="center">'.$langs->trans('CanHaveChildren').'</th>';
print '<th class="center">'.$langs->trans('Position').'</th>';
print '<th class="center">'.$langs->trans('Status').'</th>';
print '<th class="center">'.$langs->trans('Actions').'</th>';
print '</tr>';
foreach ($types as $type) {
print '<tr class="oddeven">';
print '<td>';
if ($type->picto) {
print kundenkarte_render_icon($type->picto).' ';
}
print dol_escape_htmltag($type->ref).'</td>';
print '<td>'.dol_escape_htmltag($type->label);
if ($type->label_short) {
print ' <span class="opacitymedium">('.$type->label_short.')</span>';
}
print '</td>';
print '<td>'.dol_escape_htmltag($type->system_label).'</td>';
print '<td class="center">'.($type->can_have_children ? img_picto('', 'tick') : '').'</td>';
print '<td class="center">'.$type->position.'</td>';
print '<td class="center">';
if ($type->active) {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=deactivate&typeid='.$type->id.'&system='.$systemFilter.'&token='.newToken().'">'.img_picto($langs->trans('Enabled'), 'switch_on').'</a>';
} else {
print '<a href="'.$_SERVER['PHP_SELF'].'?action=activate&typeid='.$type->id.'&system='.$systemFilter.'&token='.newToken().'">'.img_picto($langs->trans('Disabled'), 'switch_off').'</a>';
}
print '</td>';
print '<td class="center nowraponall">';
print '<a href="'.$_SERVER['PHP_SELF'].'?action=edit&typeid='.$type->id.'&system='.$systemFilter.'">'.img_edit().'</a>';
if (!$type->is_system) {
print ' <a href="'.$_SERVER['PHP_SELF'].'?action=delete&typeid='.$type->id.'&system='.$systemFilter.'" class="deletelink">'.img_delete().'</a>';
}
print '</td>';
print '</tr>';
}
if (empty($types)) {
print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans('NoRecords').'</td></tr>';
}
print '</table>';
}
print dol_get_fiche_end();
// JavaScript for parent type selector
print '<script>
$(document).ready(function() {
var $hidden = $("#allowed_parent_types");
var $select = $("#parent_type_select");
var $container = $("#selected_parent_types");
// Initialize from existing value
function initSelected() {
var val = $hidden.val();
$container.empty();
if (val) {
var types = val.split(",");
types.forEach(function(ref) {
ref = ref.trim();
if (ref) {
var $opt = $select.find("option[value=\"" + ref + "\"]");
var label = $opt.length ? $opt.data("label") : ref;
addTag(ref, label);
}
});
}
}
// Add a tag to the list
function addTag(ref, label) {
var $tag = $("<span class=\"kundenkarte-tag\">");
$tag.text(ref + (label ? " (" + label + ")" : ""));
var $remove = $("<span class=\"kundenkarte-tag-remove\">&times;</span>");
$remove.on("click", function() {
$tag.remove();
updateHidden();
});
$tag.append($remove);
$container.append($tag);
}
// Update hidden field from tags
function updateHidden() {
var refs = [];
$container.find(".kundenkarte-tag").each(function() {
var text = $(this).text();
var ref = text.split(" (")[0].trim();
refs.push(ref);
});
$hidden.val(refs.join(","));
}
// Add button click
$("#add_parent_type_btn").on("click", function() {
var ref = $select.val();
if (!ref) return;
// Check if already added
var current = $hidden.val();
if (current && current.split(",").indexOf(ref) >= 0) {
return;
}
var label = $select.find("option:selected").data("label");
addTag(ref, label);
updateHidden();
$select.val("");
});
initSelected();
});
</script>';
llxFooter();
$db->close();