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); $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 phase configurations $phasePresets = array( 'L1' => array('label' => 'L1 (Phase 1)', 'num_lines' => 1, 'colors' => '#e74c3c'), 'L2' => array('label' => 'L2 (Phase 2)', 'num_lines' => 1, 'colors' => '#2ecc71'), 'L3' => array('label' => 'L3 (Phase 3)', 'num_lines' => 1, 'colors' => '#9b59b6'), 'N' => array('label' => 'N (Neutralleiter)', 'num_lines' => 1, 'colors' => '#3498db'), 'PE' => array('label' => 'PE (Schutzleiter)', 'num_lines' => 1, 'colors' => '#f1c40f'), 'L1N' => array('label' => 'L1+N (Wechselstrom)', 'num_lines' => 2, 'colors' => '#e74c3c,#3498db'), '3P' => array('label' => '3P (Drehstrom)', 'num_lines' => 3, 'colors' => '#e74c3c,#2ecc71,#9b59b6'), '3P+N' => array('label' => '3P+N (Drehstrom+N)', 'num_lines' => 4, 'colors' => '#e74c3c,#2ecc71,#9b59b6,#3498db'), '3P+N+PE' => array('label' => '3P+N+PE (Vollausstattung)', 'num_lines' => 5, 'colors' => '#e74c3c,#2ecc71,#9b59b6,#3498db,#f1c40f'), ); /* * 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->fk_system) || 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 ''; // Phase 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').'
'.$langs->trans('Phases').''; print '
'; print 'Schnellauswahl:
'; foreach ($phasePresets 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 '
Phasen-Konfiguration: L1, L2, L3, N, PE oder Kombinationen wie L1N, 3P, 3P+N, 3P+N+PE
'; 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('Phases').''.$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 ''.dol_escape_htmltag($type->system_label).''.$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();