loadLangs(array('admin', 'kundenkarte@kundenkarte', 'products')); // 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); $equipmentType = new EquipmentType($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; } } // Load products for dropdown $products = array(); $sql = "SELECT rowid, ref, label FROM ".MAIN_DB_PREFIX."product WHERE tosell = 1 ORDER BY ref ASC"; $resql = $db->query($sql); if ($resql) { while ($obj = $db->fetch_object($resql)) { $products[$obj->rowid] = $obj; } } /* * Actions */ if ($action == 'add') { $equipmentType->ref = GETPOST('ref', 'aZ09'); $equipmentType->label = GETPOST('label', 'alphanohtml'); $equipmentType->label_short = GETPOST('label_short', 'alphanohtml'); $equipmentType->description = GETPOST('description', 'restricthtml'); $equipmentType->fk_system = GETPOSTINT('fk_system'); $equipmentType->width_te = GETPOSTINT('width_te'); $equipmentType->color = GETPOST('color', 'alphanohtml'); $equipmentType->fk_product = GETPOSTINT('fk_product'); $equipmentType->terminals_config = GETPOST('terminals_config', 'nohtml'); $equipmentType->flow_direction = GETPOST('flow_direction', 'alphanohtml'); $equipmentType->terminal_position = GETPOST('terminal_position', 'alphanohtml') ?: 'both'; $equipmentType->picto = GETPOST('picto', 'alphanohtml'); $equipmentType->position = GETPOSTINT('position'); $equipmentType->active = 1; if (empty($equipmentType->ref) || empty($equipmentType->label) || empty($equipmentType->fk_system)) { setEventMessages($langs->trans('ErrorFieldRequired'), null, 'errors'); $action = 'create'; } else { $result = $equipmentType->create($user); if ($result > 0) { // Create default fields for common equipment $defaultFields = array( array('code' => 'characteristic', 'label' => 'Charakteristik', 'type' => 'select', 'options' => 'B|C|D|K|Z', 'position' => 10, 'show_in_hover' => 1, 'show_on_block' => 1), array('code' => 'ampere', 'label' => 'Nennstrom (A)', 'type' => 'select', 'options' => '6|10|13|16|20|25|32|40|50|63', 'position' => 20, 'show_in_hover' => 1, 'show_on_block' => 1), array('code' => 'pole', 'label' => 'Polzahl', 'type' => 'select', 'options' => '1|2|3|3+N', 'position' => 30, 'show_in_hover' => 1, 'show_on_block' => 0), array('code' => 'circuit', 'label' => 'Stromkreis', 'type' => 'text', 'options' => '', 'position' => 40, 'show_in_hover' => 1, 'show_on_block' => 0), ); foreach ($defaultFields as $field) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."kundenkarte_equipment_type_field"; $sql .= " (fk_equipment_type, field_code, field_label, field_type, field_options, show_in_hover, show_on_block, required, position, active)"; $sql .= " VALUES (".((int) $equipmentType->id).", '".$db->escape($field['code'])."', '".$db->escape($field['label'])."',"; $sql .= " '".$db->escape($field['type'])."', '".$db->escape($field['options'])."', ".((int) $field['show_in_hover']).", ".((int) $field['show_on_block']).", 0, ".((int) $field['position']).", 1)"; $db->query($sql); } setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?action=edit&typeid='.$equipmentType->id.'&system='.$equipmentType->fk_system); exit; } else { setEventMessages($equipmentType->error, $equipmentType->errors, 'errors'); $action = 'create'; } } } if ($action == 'update') { $equipmentType->fetch($typeId); $equipmentType->ref = GETPOST('ref', 'aZ09'); $equipmentType->label = GETPOST('label', 'alphanohtml'); $equipmentType->label_short = GETPOST('label_short', 'alphanohtml'); $equipmentType->description = GETPOST('description', 'restricthtml'); $equipmentType->fk_system = GETPOSTINT('fk_system'); $equipmentType->width_te = GETPOSTINT('width_te'); $equipmentType->color = GETPOST('color', 'alphanohtml'); $equipmentType->fk_product = GETPOSTINT('fk_product'); $equipmentType->terminals_config = GETPOST('terminals_config', 'nohtml'); $equipmentType->flow_direction = GETPOST('flow_direction', 'alphanohtml'); $equipmentType->terminal_position = GETPOST('terminal_position', 'alphanohtml') ?: 'both'; $equipmentType->picto = GETPOST('picto', 'alphanohtml'); $equipmentType->position = GETPOSTINT('position'); $result = $equipmentType->update($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?system='.$equipmentType->fk_system); exit; } else { setEventMessages($equipmentType->error, $equipmentType->errors, 'errors'); $action = 'edit'; } } if ($action == 'confirm_delete' && $confirm == 'yes') { $equipmentType->fetch($typeId); $result = $equipmentType->delete($user); if ($result > 0) { setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); } else { setEventMessages($equipmentType->error, $equipmentType->errors, 'errors'); } $action = ''; } if ($action == 'activate') { $sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_equipment_type SET active = 1 WHERE rowid = ".((int) $typeId); $db->query($sql); $action = ''; } if ($action == 'deactivate') { $sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_equipment_type SET active = 0 WHERE rowid = ".((int) $typeId); $db->query($sql); $action = ''; } // Copy type with all fields if ($action == 'copy' && $typeId > 0) { $sourceType = new EquipmentType($db); if ($sourceType->fetch($typeId) > 0) { $newType = new EquipmentType($db); $newType->ref = $sourceType->ref.'_COPY'; $newType->label = $sourceType->label.' (Kopie)'; $newType->label_short = $sourceType->label_short; $newType->description = $sourceType->description; $newType->fk_system = $sourceType->fk_system; $newType->width_te = $sourceType->width_te; $newType->color = $sourceType->color; $newType->fk_product = $sourceType->fk_product; $newType->picto = $sourceType->picto; $newType->position = $sourceType->position + 1; $newType->active = 1; $result = $newType->create($user); if ($result > 0) { // Copy all fields from source type $sourceFields = $sourceType->fetchFields(0); foreach ($sourceFields as $field) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."kundenkarte_equipment_type_field"; $sql .= " (fk_equipment_type, field_code, field_label, field_type, field_options, show_in_hover, show_on_block, required, position, active)"; $sql .= " VALUES (".((int) $newType->id).", '".$db->escape($field->field_code)."', '".$db->escape($field->field_label)."',"; $sql .= " '".$db->escape($field->field_type)."', '".$db->escape($field->field_options)."', ".((int) $field->show_in_hover).","; $sql .= " ".((int) $field->show_on_block).", ".((int) $field->required).", ".((int) $field->position).", ".((int) $field->active).")"; $db->query($sql); } setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?action=edit&typeid='.$newType->id.'&system='.$newType->fk_system); exit; } else { setEventMessages($newType->error, $newType->errors, 'errors'); } } $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', 'nohtml'); $showInHover = GETPOSTINT('show_in_hover'); $showOnBlock = GETPOSTINT('show_on_block'); $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_equipment_type_field"; $sql .= " (fk_equipment_type, field_code, field_label, field_type, field_options, show_in_hover, show_on_block, required, position, active)"; $sql .= " VALUES (".((int) $typeId).", '".$db->escape($fieldCode)."', '".$db->escape($fieldLabel)."',"; $sql .= " '".$db->escape($fieldType)."', '".$db->escape($fieldOptions)."',"; $sql .= " ".((int) $showInHover).", ".((int) $showOnBlock).", ".((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', 'nohtml'); $showInHover = GETPOSTINT('show_in_hover'); $showOnBlock = GETPOSTINT('show_on_block'); $isRequired = GETPOSTINT('is_required'); $fieldPosition = GETPOSTINT('field_position'); $sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_equipment_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_hover = ".((int) $showInHover).","; $sql .= " show_on_block = ".((int) $showOnBlock).","; $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_equipment_type_field WHERE rowid = ".((int) $fieldId); if ($db->query($sql)) { setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); } else { setEventMessages($db->lasterror(), null, 'errors'); } header('Location: '.$_SERVER['PHP_SELF'].'?action=edit&typeid='.$typeId.'&system='.$systemFilter); exit; } if ($action == 'activate_field') { $sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_equipment_type_field SET active = 1 WHERE rowid = ".((int) $fieldId); $db->query($sql); $action = 'edit'; } if ($action == 'deactivate_field') { $sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_equipment_type_field SET active = 0 WHERE rowid = ".((int) $fieldId); $db->query($sql); $action = 'edit'; } /* * View */ $title = $langs->trans('EquipmentTypes'); $morejs = array('/kundenkarte/js/kundenkarte.js?v='.time()); $morecss = array('/kundenkarte/css/kundenkarte.css?v='.time()); llxHeader('', $title, '', '', 0, 0, $morejs, $morecss); $head = kundenkarteAdminPrepareHead(); print dol_get_fiche_head($head, 'equipment_types', $langs->trans('ModuleKundenKarteName'), -1, 'fa-file'); // Confirmation for type deletion if ($action == 'delete') { print $form->formconfirm( $_SERVER['PHP_SELF'].'?typeid='.$typeId.'&system='.$systemFilter, $langs->trans('Delete'), $langs->trans('ConfirmDeleteType'), 'confirm_delete', '', 'yes', 1 ); } // Confirmation for field deletion if ($action == 'delete_field') { print $form->formconfirm( $_SERVER['PHP_SELF'].'?typeid='.$typeId.'&fieldid='.$fieldId.'&system='.$systemFilter, $langs->trans('Delete'), $langs->trans('ConfirmDeleteField'), 'confirm_delete_field', '', 'yes', 1 ); $action = 'edit'; } // Add/Edit form if (in_array($action, array('create', 'edit'))) { if ($action == 'edit' && $typeId > 0) { $equipmentType->fetch($typeId); } print '
'; print ''; print ''; if ($action == 'edit') { print ''; } print ''; // System print ''; print ''; // Reference print ''; print ''; // Label print ''; print ''; // Short label print ''; print ''; // Description print ''; print ''; // Width in TE print ''; print ''; // Color print ''; print ''; // Product print ''; print ''; // FontAwesome Icon (fallback) print ''; print ''; // Schaltzeichen Upload (SVG/PNG) print ''; print ''; // Block Image Upload (for SchematicEditor display) print ''; print ''; // Position print ''; print ''; // Terminal configuration print ''; print ''; // Terminal Position print ''; print ''; // Flow Direction print ''; print ''; print '
'.$langs->trans('System').'
'.$langs->trans('TypeRef').''; print ' (UPPERCASE, no spaces)
'.$langs->trans('TypeLabel').'
'.$langs->trans('TypeShortLabel').''; print ' (z.B. LS, FI, FI/LS)
'.$langs->trans('Description').'
'.$langs->trans('WidthTE').''; print ' '.$langs->trans('WidthTEHelp').'
'.$langs->trans('Color').''; print ' '.$langs->trans('ColorForSVG').'
'.$langs->trans('LinkedProduct').'
'.$langs->trans('SystemPicto').'
'; print ''; if ($equipmentType->picto) { print kundenkarte_render_icon($equipmentType->picto); } print ''; print ''; print ''; print '
'; print 'Fallback-Icon wenn kein Schaltzeichen hochgeladen'; print '
'.$langs->trans('SchematicSymbol').''; print '
'; // Preview area print '
'; if ($action == 'edit' && $equipmentType->icon_file) { $iconUrl = DOL_URL_ROOT.'/document.php?modulepart=kundenkarte&file=equipment_icons/'.urlencode($equipmentType->icon_file); print 'Icon'; } else { print 'Kein
Symbol
'; } print '
'; // Upload controls print '
'; print ''; print ''; if ($action == 'edit' && $equipmentType->icon_file) { print ' '; } print '
Normgerechte Symbole nach IEC 60617 / DIN EN 60617
'; print '
'; print '
'; print '
'.$langs->trans('BlockImage').''; print '
'; // Preview area print '
'; if ($action == 'edit' && $equipmentType->block_image) { $blockImageUrl = DOL_URL_ROOT.'/document.php?modulepart=kundenkarte&file=block_images/'.urlencode($equipmentType->block_image); print 'Block Image'; } else { print 'Kein
Bild
'; } print '
'; // Upload controls print '
'; print ''; print ''; if ($action == 'edit' && $equipmentType->block_image) { print ' '; } // Dropdown to select existing images $blockImagesDir = DOL_DATA_ROOT.'/kundenkarte/block_images/'; $existingImages = array(); if (is_dir($blockImagesDir)) { $files = scandir($blockImagesDir); foreach ($files as $file) { if ($file != '.' && $file != '..' && preg_match('/\.(png|jpg|jpeg|gif|svg|webp)$/i', $file)) { $existingImages[] = $file; } } sort($existingImages); } if (!empty($existingImages)) { print '
'; print ''; print ' '; print '
'; } print '
Bild wird im SchematicEditor als Block-Hintergrund angezeigt
'; print '
'; print '
'; print '
'.$langs->trans('Position').'
'.$langs->trans('TerminalConfig').''; print '
'; print ''; print ' '; print ' '; print ' '; print ''; print '
'; print ''; print '
'; print 'JSON-Format: {"terminals":[{"id":"t1","label":"L","pos":"top"},...]} - pos: "top" oder "bottom"'; print '
'; print '
Anschlusspunkt-Position'; print ''; print '
Wo sollen die Anschlusspunkte angezeigt werden?
'; print '
Richtung (Pfeil)'; print ''; print '
Zeigt einen Richtungspfeil im Block an (z.B. für Typ B FI-Schalter)
'; print '
'; // JavaScript for terminal presets and icon upload $typeIdJs = $action == 'edit' ? $typeId : 0; print ''; print '
'; print ''; print ' '.$langs->trans('Cancel').''; print '
'; print '
'; // Fields management for existing type if ($action == 'edit' && $typeId > 0) { $editFieldId = GETPOSTINT('editfield'); print '

'; print '

'.$langs->trans('EquipmentTypeFields').'

'; $fields = $equipmentType->fetchFields(0); // Field types available $fieldTypes = array( 'text' => 'Textfeld (einzeilig)', 'textarea' => 'Textfeld (mehrzeilig)', 'number' => 'Zahlenfeld', 'select' => 'Dropdown-Auswahl', 'date' => 'Datumsfeld', 'checkbox' => 'Checkbox (Ja/Nein)', ); // Output edit forms BEFORE the table foreach ($fields as $field) { if ($editFieldId == $field->rowid) { $formId = 'editfield_'.$field->rowid; print '
'; print ''; print ''; print ''; print ''; print ''; print '
'; } } print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; foreach ($fields as $field) { if ($editFieldId == $field->rowid) { $formId = 'editfield_'.$field->rowid; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } else { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } } if (empty($fields)) { print ''; } print '
'.$langs->trans('FieldCode').''.$langs->trans('FieldLabel').''.$langs->trans('FieldType').''.$langs->trans('FieldOptions').''.$langs->trans('ShowInHover').''.$langs->trans('ShowOnBlock').''.$langs->trans('IsRequired').''.$langs->trans('Position').''.$langs->trans('Status').''.$langs->trans('Actions').'
show_in_hover ? ' checked' : '').'>show_on_block ? ' checked' : '').'>required ? ' checked' : '').'>'; print '
'; print ''; print ''; print '
'; print '
'.dol_escape_htmltag($field->field_code).''.dol_escape_htmltag($field->field_label).''.dol_escape_htmltag($fieldTypes[$field->field_type] ?? $field->field_type).''.dol_escape_htmltag(dol_trunc($field->field_options, 20)).''.($field->show_in_hover ? img_picto('', 'tick') : '').''.($field->show_on_block ? img_picto('', 'tick') : '').''.($field->required ? img_picto('', 'tick') : '').''.$field->position.''; if ($field->active) { print ''.img_picto($langs->trans('Enabled'), 'switch_on').''; } else { print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; } print ''; print '
'; print ''; print ''; print '
'; print '
'.$langs->trans('NoFieldsDefined').'
'; // Add new field form print '
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('Add').' '.$langs->trans('Field').'
'; print '
'; print '
'; // Help box print '
'; print '

Hilfe: Equipment-Felder

'; print ''; print ''; print ''; print ''; print '
Show in HoverFeld wird im Tooltip angezeigt
Show on BlockFeld wird direkt auf dem SVG-Block angezeigt (z.B. "B16")
Dropdown-AuswahlOptionen mit | trennen, z.B.: B|C|D oder 6|10|16|20|25|32
'; print '
'; } } else { // System filter print '
'; print $langs->trans('FilterBySystem').': '; print ''; print '
'; // Add button print '
'; print ''; print ' '.$langs->trans('AddEquipmentType'); print ''; print '
'; // List $types = $equipmentType->fetchAllBySystem($systemFilter, 0); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; foreach ($types as $type) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } if (empty($types)) { print ''; } print '
'.$langs->trans('TypeRef').''.$langs->trans('TypeLabel').''.$langs->trans('System').''.$langs->trans('WidthTE').''.$langs->trans('Color').''.$langs->trans('Position').''.$langs->trans('Status').''.$langs->trans('Actions').'
'; if ($type->picto) { print kundenkarte_render_icon($type->picto).' '; } print dol_escape_htmltag($type->ref).''.dol_escape_htmltag($type->label); if ($type->label_short) { print ' ('.$type->label_short.')'; } print ''.dol_escape_htmltag($type->system_label).''.$type->width_te.' TE'.$type->position.''; if ($type->active) { print ''.img_picto($langs->trans('Enabled'), 'switch_on').''; } else { print ''.img_picto($langs->trans('Disabled'), 'switch_off').''; } print ''; print '
'; print ''; print ''; if (!$type->is_system) { print ''; } print '
'; print '
'.$langs->trans('NoRecords').'
'; } print dol_get_fiche_end(); llxFooter(); $db->close();