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'); // System filter - save in session for persistence $sessionKey = 'kundenkarte_busbar_types_system_filter'; if (GETPOSTISSET('system')) { $systemFilter = GETPOSTINT('system'); $_SESSION[$sessionKey] = $systemFilter; } elseif (isset($_SESSION[$sessionKey])) { $systemFilter = $_SESSION[$sessionKey]; } else { $systemFilter = 0; } $form = new Form($db); $busbarType = new BusbarType($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; } } // Predefined channel configurations (system-independent) $channelPresets = array( // General presets 'A' => array('label' => 'Kanal A (1 Linie)', 'num_lines' => 1, 'colors' => '#e74c3c'), 'B' => array('label' => 'Kanal B (1 Linie)', 'num_lines' => 1, 'colors' => '#2ecc71'), 'C' => array('label' => 'Kanal C (1 Linie)', 'num_lines' => 1, 'colors' => '#9b59b6'), 'AB' => array('label' => 'Kanal A+B (2 Linien)', 'num_lines' => 2, 'colors' => '#e74c3c,#2ecc71'), 'ABC' => array('label' => 'Kanal A+B+C (3 Linien)', 'num_lines' => 3, 'colors' => '#e74c3c,#2ecc71,#9b59b6'), '4CH' => array('label' => '4 Kanaele', 'num_lines' => 4, 'colors' => '#e74c3c,#2ecc71,#9b59b6,#3498db'), '5CH' => array('label' => '5 Kanaele', 'num_lines' => 5, 'colors' => '#e74c3c,#2ecc71,#9b59b6,#3498db,#f1c40f'), // Electrical presets (for backward compatibility) 'L1' => array('label' => 'L1 (Strom)', 'num_lines' => 1, 'colors' => '#e74c3c'), '3P+N' => array('label' => '3P+N (Strom)', 'num_lines' => 4, 'colors' => '#e74c3c,#2ecc71,#9b59b6,#3498db'), ); /* * Actions */ if ($action == 'add') { $busbarType->ref = GETPOST('ref', 'aZ09'); $busbarType->label = GETPOST('label', 'alphanohtml'); $busbarType->label_short = GETPOST('label_short', 'alphanohtml'); $busbarType->description = GETPOST('description', 'restricthtml'); $busbarType->fk_system = GETPOSTINT('fk_system'); $busbarType->phases = GETPOST('phases', 'alphanohtml'); $busbarType->num_lines = GETPOSTINT('num_lines'); $busbarType->color = GETPOST('color', 'alphanohtml'); $busbarType->default_color = GETPOST('default_color', 'alphanohtml'); $busbarType->line_height = GETPOSTINT('line_height') ?: 3; $busbarType->line_spacing = GETPOSTINT('line_spacing') ?: 4; $busbarType->position_default = GETPOST('position_default', 'alphanohtml') ?: 'below'; $busbarType->fk_product = GETPOSTINT('fk_product'); $busbarType->picto = GETPOST('picto', 'alphanohtml'); $busbarType->position = GETPOSTINT('position'); $busbarType->active = 1; if (empty($busbarType->ref) || empty($busbarType->label) || empty($busbarType->phases)) { setEventMessages($langs->trans('ErrorFieldRequired'), null, 'errors'); $action = 'create'; } else { $result = $busbarType->create($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?system='.$busbarType->fk_system); exit; } else { setEventMessages($busbarType->error, $busbarType->errors, 'errors'); $action = 'create'; } } } if ($action == 'update') { $busbarType->fetch($typeId); $busbarType->ref = GETPOST('ref', 'aZ09'); $busbarType->label = GETPOST('label', 'alphanohtml'); $busbarType->label_short = GETPOST('label_short', 'alphanohtml'); $busbarType->description = GETPOST('description', 'restricthtml'); $busbarType->fk_system = GETPOSTINT('fk_system'); $busbarType->phases = GETPOST('phases', 'alphanohtml'); $busbarType->num_lines = GETPOSTINT('num_lines'); $busbarType->color = GETPOST('color', 'alphanohtml'); $busbarType->default_color = GETPOST('default_color', 'alphanohtml'); $busbarType->line_height = GETPOSTINT('line_height') ?: 3; $busbarType->line_spacing = GETPOSTINT('line_spacing') ?: 4; $busbarType->position_default = GETPOST('position_default', 'alphanohtml') ?: 'below'; $busbarType->fk_product = GETPOSTINT('fk_product'); $busbarType->picto = GETPOST('picto', 'alphanohtml'); $busbarType->position = GETPOSTINT('position'); $result = $busbarType->update($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?system='.$busbarType->fk_system); exit; } else { setEventMessages($busbarType->error, $busbarType->errors, 'errors'); $action = 'edit'; } } if ($action == 'confirm_delete' && $confirm == 'yes') { $busbarType->fetch($typeId); $result = $busbarType->delete($user); if ($result > 0) { setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); } else { setEventMessages($busbarType->error, $busbarType->errors, 'errors'); } $action = ''; } if ($action == 'activate') { $sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_busbar_type SET active = 1 WHERE rowid = ".((int) $typeId); $db->query($sql); $action = ''; } if ($action == 'deactivate') { $sql = "UPDATE ".MAIN_DB_PREFIX."kundenkarte_busbar_type SET active = 0 WHERE rowid = ".((int) $typeId); $db->query($sql); $action = ''; } /* * View */ llxHeader('', $langs->trans('BusbarTypes')); $head = kundenkarteAdminPrepareHead(); print dol_get_fiche_head($head, 'busbar_types', $langs->trans('KundenkarteSetup'), -1, 'kundenkarte@kundenkarte'); // System filter print '
'; print '
'; print $langs->trans('System').': '; print ''; print ' '; print ' '.$langs->trans('NewBusbarType').''; print '
'; print '
'; // Delete confirmation if ($action == 'delete') { $busbarType->fetch($typeId); print $form->formconfirm( $_SERVER['PHP_SELF'].'?typeid='.$typeId.'&system='.$systemFilter, $langs->trans('DeleteBusbarType'), $langs->trans('ConfirmDeleteBusbarType', $busbarType->label), 'confirm_delete', '', 0, 1 ); } // Create/Edit form if ($action == 'create' || $action == 'edit') { if ($action == 'edit') { $busbarType->fetch($typeId); } print '
'; print ''; print ''; if ($action == 'edit') { print ''; } print ''; // Ref print ''; print ''; // Label print ''; print ''; // Label Short print ''; print ''; // Description print ''; print ''; // System print ''; print ''; // Channel configuration print ''; print ''; // Number of lines print ''; print ''; // Colors print ''; print ''; // Default color print ''; print ''; // Line height print ''; print ''; // Line spacing print ''; print ''; // Default position print ''; print ''; // Product link print ''; print ''; // Position print ''; print ''; // Preview print ''; print ''; print '
'.$langs->trans('Ref').'
'.$langs->trans('Label').'
'.$langs->trans('LabelShort').'
'.$langs->trans('Description').'
'.$langs->trans('System').''; print '
'.$langs->trans('AllSystemsHint').'
'; print '
'.$langs->trans('Channels').''; print '
'; print ''.$langs->trans('QuickSelect').':
'; foreach ($channelPresets as $code => $preset) { $style = 'display:inline-block;margin:3px;padding:5px 10px;border:1px solid #ccc;border-radius:4px;cursor:pointer;background:#f8f8f8;'; print ''; print dol_escape_htmltag($preset['label']); print ''; } print '
'; print ''; print '
'.$langs->trans('ChannelsHint').'
'; print '
'.$langs->trans('NumLines').'
'.$langs->trans('Colors').''; print ''; print '
Kommagetrennte Farbcodes fuer jede Linie (z.B. #e74c3c,#2ecc71,#9b59b6)
'; print '
'.$langs->trans('DefaultColor').'
'.$langs->trans('LineHeight').' px
'.$langs->trans('LineSpacing').' px
'.$langs->trans('DefaultPosition').'
'.$langs->trans('LinkedProduct').'
'.$langs->trans('Position').'
'.$langs->trans('Preview').''; print '
'; print ''; print '
'; print '
'; print '
'; print ''; print ' '.$langs->trans('Cancel').''; print '
'; print '
'; // JavaScript for preset selection and preview print ''; } else { // List of busbar types $types = $busbarType->fetchAllBySystem($systemFilter, 0); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (empty($types)) { print ''; } else { foreach ($types as $type) { print ''; print ''; print ''; print ''; print ''; // Color preview print ''; print ''; print ''; // Status print ''; // Actions print ''; print ''; } } print '
'.$langs->trans('Ref').''.$langs->trans('Label').''.$langs->trans('Channels').''.$langs->trans('Lines').''.$langs->trans('Colors').''.$langs->trans('System').''.$langs->trans('Position').''.$langs->trans('Status').''.$langs->trans('Actions').'
'.$langs->trans('NoRecordFound').'
'.dol_escape_htmltag($type->ref).''.dol_escape_htmltag($type->label); if ($type->label_short) { print ' ('.dol_escape_htmltag($type->label_short).')'; } print ''.dol_escape_htmltag($type->phases).''.$type->num_lines.''; $colors = $type->color ? explode(',', $type->color) : array($type->default_color ?: '#e74c3c'); foreach ($colors as $c) { print ''; } print ''; if (empty($type->fk_system)) { print ''.$langs->trans('AllSystems').''; } else { print dol_escape_htmltag($type->system_label); } print ''.$type->position.''; if ($type->active) { print ''.$langs->trans('Enabled').''; } else { print ''.$langs->trans('Disabled').''; } print ''; print ''; print img_edit(); print ' '; if ($type->active) { print ''; print img_picto($langs->trans('Disable'), 'switch_on'); print ' '; } else { print ''; print img_picto($langs->trans('Enable'), 'switch_off'); print ' '; } if (!$type->is_system) { print ''; print img_delete(); print ''; } print '
'; print '
'; } print dol_get_fiche_end(); llxFooter(); $db->close();