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 '
| '.$langs->trans('Ref').' | '; print ''.$langs->trans('Label').' | '; print ''.$langs->trans('Phases').' | '; print ''.$langs->trans('Lines').' | '; print ''.$langs->trans('Colors').' | '; print ''.$langs->trans('System').' | '; print ''.$langs->trans('Position').' | '; print ''.$langs->trans('Status').' | '; print ''.$langs->trans('Actions').' | '; print '
|---|---|---|---|---|---|---|---|---|
| '.$langs->trans('NoRecordFound').' | ||||||||
| '.dol_escape_htmltag($type->ref).' | '; print ''.dol_escape_htmltag($type->label); if ($type->label_short) { print ' ('.dol_escape_htmltag($type->label_short).')'; } print ' | '; print ''.dol_escape_htmltag($type->phases).' | '; print ''.$type->num_lines.' | '; // Color preview print ''; $colors = $type->color ? explode(',', $type->color) : array($type->default_color ?: '#e74c3c'); foreach ($colors as $c) { print ''; } print ' | '; print ''.dol_escape_htmltag($type->system_label).' | '; print ''.$type->position.' | '; // Status print ''; if ($type->active) { print ''.$langs->trans('Enabled').''; } else { print ''.$langs->trans('Disabled').''; } print ' | '; // Actions 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 '