loadLangs(array("admin", "kundenkarte@kundenkarte")); // Security check if (!$user->admin) { accessforbidden(); } $action = GETPOST('action', 'aZ09'); $typeId = GETPOSTINT('typeid'); $mediumType = new MediumType($db); // Load systems for dropdown $systems = array(); $sql = "SELECT rowid, code, label FROM ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system WHERE active = 1 ORDER BY position, label"; $resql = $db->query($sql); if ($resql) { while ($obj = $db->fetch_object($resql)) { $systems[$obj->rowid] = $obj; } } $error = 0; $message = ''; // Actions if ($action == 'add' && $user->admin) { $mediumType->ref = GETPOST('ref', 'alphanohtml'); $mediumType->label = GETPOST('label', 'alphanohtml'); $mediumType->label_short = GETPOST('label_short', 'alphanohtml'); $mediumType->description = GETPOST('description', 'restricthtml'); $mediumType->fk_system = GETPOSTINT('fk_system'); $mediumType->category = GETPOST('category', 'alphanohtml'); $mediumType->default_spec = GETPOST('default_spec', 'alphanohtml'); $mediumType->color = GETPOST('color', 'alphanohtml'); $mediumType->position = GETPOSTINT('position'); $mediumType->active = GETPOSTINT('active'); // Available specs as JSON array $specsText = GETPOST('available_specs', 'nohtml'); if ($specsText) { $specsArray = array_map('trim', explode(',', $specsText)); $mediumType->available_specs = json_encode($specsArray); } $result = $mediumType->create($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF']); exit; } else { setEventMessages($mediumType->error, $mediumType->errors, 'errors'); $action = 'create'; } } if ($action == 'update' && $user->admin) { if ($mediumType->fetch($typeId) > 0) { $mediumType->ref = GETPOST('ref', 'alphanohtml'); $mediumType->label = GETPOST('label', 'alphanohtml'); $mediumType->label_short = GETPOST('label_short', 'alphanohtml'); $mediumType->description = GETPOST('description', 'restricthtml'); $mediumType->fk_system = GETPOSTINT('fk_system'); $mediumType->category = GETPOST('category', 'alphanohtml'); $mediumType->default_spec = GETPOST('default_spec', 'alphanohtml'); $mediumType->color = GETPOST('color', 'alphanohtml'); $mediumType->position = GETPOSTINT('position'); $mediumType->active = GETPOSTINT('active'); $specsText = GETPOST('available_specs', 'nohtml'); if ($specsText) { $specsArray = array_map('trim', explode(',', $specsText)); $mediumType->available_specs = json_encode($specsArray); } else { $mediumType->available_specs = ''; } $result = $mediumType->update($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF']); exit; } else { setEventMessages($mediumType->error, $mediumType->errors, 'errors'); $action = 'edit'; } } } if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->admin) { if ($mediumType->fetch($typeId) > 0) { $result = $mediumType->delete($user); if ($result > 0) { setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); } else { setEventMessages($mediumType->error, $mediumType->errors, 'errors'); } } header('Location: '.$_SERVER['PHP_SELF']); exit; } /* * View */ $title = $langs->trans('MediumTypes'); llxHeader('', $title); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($title, $linkback, 'title_setup'); // Admin tabs $head = kundenkarteAdminPrepareHead(); print dol_get_fiche_head($head, 'medium_types', $langs->trans('KundenKarte'), -1, 'kundenkarte@kundenkarte'); // Delete confirmation if ($action == 'delete') { if ($mediumType->fetch($typeId) > 0) { print $form->formconfirm( $_SERVER['PHP_SELF'].'?typeid='.$typeId, $langs->trans('DeleteMediumType'), $langs->trans('ConfirmDeleteMediumType', $mediumType->label), 'confirm_delete', '', 0, 1 ); } } // Add/Edit form if (in_array($action, array('create', 'edit'))) { if ($action == 'edit' && $typeId > 0) { $mediumType->fetch($typeId); } print '
'; print ''; print ''; if ($action == 'edit') { print ''; } print ''; // Ref print ''; print ''; // Label print ''; print ''; // Label short print ''; print ''; // System print ''; print ''; // Category print ''; print ''; // Default spec print ''; print ''; // Available specs $specsText = ''; if ($mediumType->available_specs) { $specsArray = json_decode($mediumType->available_specs, true); if (is_array($specsArray)) { $specsText = implode(', ', $specsArray); } } print ''; print ''; // Color print ''; print ''; // Position print ''; print ''; // Status print ''; print ''; // Description print ''; print ''; print '
'.$langs->trans('Ref').'
'.$langs->trans('Label').'
'.$langs->trans('LabelShort').'
'.$langs->trans('System').'
'.$langs->trans('Category').'
'.$langs->trans('DefaultSpec').''; print '
'.$langs->trans('DefaultSpecHelp').'
'.$langs->trans('AvailableSpecs').''; print '
'.$langs->trans('AvailableSpecsHelp').'
'.$langs->trans('Color').''; print '
'.$langs->trans('Position').'
'.$langs->trans('Status').'
'.$langs->trans('Description').'
'; print '
'; print ''; print ' '.$langs->trans('Cancel').''; print '
'; print '
'; } else { // List view // Button to add print '
'; print ''.$langs->trans('AddMediumType').''; print '
'; // Filter by category $filterCategory = GETPOST('filter_category', 'alphanohtml'); print '
'; print ''; print ''; print '
'; // List $allTypes = $mediumType->fetchAllBySystem(0, 0); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (empty($allTypes)) { print ''; } else { $i = 0; foreach ($allTypes as $t) { // Filter if ($filterCategory && $t->category != $filterCategory) continue; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $i++; } } print '
'.$langs->trans('Ref').''.$langs->trans('Label').''.$langs->trans('Category').''.$langs->trans('System').''.$langs->trans('DefaultSpec').''.$langs->trans('Color').''.$langs->trans('Position').''.$langs->trans('Status').''.$langs->trans('Actions').'
'.$langs->trans('NoRecords').'
'.dol_escape_htmltag($t->ref).''.dol_escape_htmltag($t->label); if ($t->label_short) print ' ('.dol_escape_htmltag($t->label_short).')'; print ''.dol_escape_htmltag($t->getCategoryLabel()).''; if ($t->fk_system > 0 && $t->system_label) { print dol_escape_htmltag($t->system_label); } else { print ''.$langs->trans('AllSystems').''; } print ''.dol_escape_htmltag($t->default_spec).''.$t->position.''; print $t->active ? ''.$langs->trans('Enabled').'' : ''.$langs->trans('Disabled').''; print ''; print ''; if (!$t->is_system) { print ' '; } print '
'; } print dol_get_fiche_end(); // JavaScript for color picker sync print ''; llxFooter(); $db->close();