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 '
'; } else { // List view // Button to add print '