loadLangs(array('admin', 'kundenkarte@kundenkarte')); // Security check if (!$user->admin) { accessforbidden(); } $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $id = GETPOSTINT('id'); $levelFilter = GETPOST('level_filter', 'alpha'); $buildingType = new BuildingType($db); $error = 0; // Actions if ($action == 'add' && $user->admin) { $buildingType->ref = GETPOST('ref', 'alphanohtml'); $buildingType->label = GETPOST('label', 'alphanohtml'); $buildingType->label_short = GETPOST('label_short', 'alphanohtml'); $buildingType->description = GETPOST('description', 'restricthtml'); $buildingType->fk_parent = GETPOSTINT('fk_parent'); $buildingType->level_type = GETPOST('level_type', 'alpha'); $buildingType->icon = GETPOST('icon', 'alphanohtml'); $buildingType->color = GETPOST('color', 'alphanohtml'); $buildingType->can_have_children = GETPOSTINT('can_have_children'); $buildingType->position = GETPOSTINT('position'); $buildingType->active = GETPOSTINT('active'); if (empty($buildingType->ref)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesaliases('Ref')), null, 'errors'); $error++; } if (empty($buildingType->label)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesaliases('Label')), null, 'errors'); $error++; } if (!$error) { $result = $buildingType->create($user); if ($result > 0) { setEventMessages($langs->trans('RecordCreatedSuccessfully'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF']); exit; } else { setEventMessages($buildingType->error, $buildingType->errors, 'errors'); } } $action = 'create'; } if ($action == 'update' && $user->admin) { $result = $buildingType->fetch($id); if ($result > 0) { // Don't allow editing ref of system types if (!$buildingType->is_system) { $buildingType->ref = GETPOST('ref', 'alphanohtml'); } $buildingType->label = GETPOST('label', 'alphanohtml'); $buildingType->label_short = GETPOST('label_short', 'alphanohtml'); $buildingType->description = GETPOST('description', 'restricthtml'); $buildingType->fk_parent = GETPOSTINT('fk_parent'); $buildingType->level_type = GETPOST('level_type', 'alpha'); $buildingType->icon = GETPOST('icon', 'alphanohtml'); $buildingType->color = GETPOST('color', 'alphanohtml'); $buildingType->can_have_children = GETPOSTINT('can_have_children'); $buildingType->position = GETPOSTINT('position'); $buildingType->active = GETPOSTINT('active'); $result = $buildingType->update($user); if ($result > 0) { setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF']); exit; } else { setEventMessages($buildingType->error, $buildingType->errors, 'errors'); } } } if ($action == 'confirm_delete' && $confirm == 'yes' && $user->admin) { $result = $buildingType->fetch($id); if ($result > 0) { $result = $buildingType->delete($user); if ($result > 0) { setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); } else { setEventMessages($langs->trans($buildingType->error), $buildingType->errors, 'errors'); } } header('Location: '.$_SERVER['PHP_SELF']); exit; } // Load data for edit if (($action == 'edit' || $action == 'delete') && $id > 0) { $result = $buildingType->fetch($id); } /* * View */ $page_name = "BuildingTypesSetup"; llxHeader('', $langs->trans($page_name), '', '', 0, 0, '', '', '', 'mod-kundenkarte page-admin-building_types'); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans($page_name), $linkback, 'object_kundenkarte@kundenkarte'); print '
'; $head = kundenkarteAdminPrepareHead(); print dol_get_fiche_head($head, 'building_types', $langs->trans("Module500015Name"), -1, 'kundenkarte@kundenkarte'); // Delete confirmation if ($action == 'delete') { print $form->formconfirm( $_SERVER['PHP_SELF'].'?id='.$buildingType->id, $langs->trans('DeleteBuildingType'), $langs->trans('ConfirmDeleteBuildingType', $buildingType->label), 'confirm_delete', '', 0, 1 ); } // Level type filter $levelTypes = BuildingType::getLevelTypes(); print '
'; print '
'; print '
'; print ''; print ''; print '
'; print '
'; print '
'; // Add/Edit form if ($action == 'create' || $action == 'edit') { print '
'; print ''; print ''; if ($action == 'edit') { print ''; } print ''; // Ref print ''; // Label print ''; // Label Short print ''; // Level Type print ''; // Icon print ''; // Color print ''; // Can have children print ''; // Position print ''; // Active print ''; // Description print ''; print '
'.$langs->trans('Ref').''; if ($action == 'edit' && $buildingType->is_system) { print ''; print $buildingType->ref.' ('.$langs->trans('SystemType').')'; } else { print ''; } print '
'.$langs->trans('Label').''; print ''; print '
'.$langs->trans('LabelShort').''; print ''; print '
'.$langs->trans('LevelType').''; print ''; print '
'.$langs->trans('Icon').''; print ''; if ($buildingType->icon) { print ' '; } print ' (FontAwesome, z.B. fa-home, fa-building)'; print '
'.$langs->trans('Color').''; print ''; print ' '; print '
'.$langs->trans('CanHaveChildren').''; print 'can_have_children || $action != 'edit' ? ' checked' : '').'>'; print '
'.$langs->trans('Position').''; $defaultPos = $action == 'create' ? $buildingType->getNextPosition() : $buildingType->position; print ''; print '
'.$langs->trans('Active').''; print 'active || $action != 'edit' ? ' checked' : '').'>'; print '
'.$langs->trans('Description').''; print ''; print '
'; print '
'; print ''; print ' '.$langs->trans('Cancel').''; print '
'; print '
'; // Sync color inputs print ''; } else { // List of building types print '
'; print ''; // Header print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Fetch types $types = $buildingType->fetchAll(0, $levelFilter); if (count($types) > 0) { foreach ($types as $type) { print ''; // Ref print ''; // Label print ''; // Level Type print ''; // Icon print ''; // Color print ''; // Position print ''; // Active print ''; // Actions print ''; print ''; } } else { print ''; } print '
'.$langs->trans('Ref').''.$langs->trans('Label').''.$langs->trans('LevelType').''.$langs->trans('Icon').''.$langs->trans('Color').''.$langs->trans('Position').''.$langs->trans('Active').''.$langs->trans('Actions').'
'.$type->ref; if ($type->is_system) { print ' '.$langs->trans('System').''; } print ''; if ($type->icon) { print ' '; } print dol_escape_htmltag($type->label); if ($type->label_short) { print ' ('.$type->label_short.')'; } print ''.$type->getLevelTypeLabel().''; if ($type->icon) { print ' '.$type->icon; } print ''; if ($type->color) { print ' '.$type->color; } print ''.$type->position.''; print $type->active ? ''.$langs->trans('Yes').'' : ''.$langs->trans('No').''; print ''; print ''.img_edit().''; if (!$type->is_system) { print ' '.img_delete().''; } print '
'.$langs->trans('NoRecordFound').'
'; print '
'; // Add button print '
'; print ''.$langs->trans('AddBuildingType').''; print '
'; } print dol_get_fiche_end(); print '
'; llxFooter(); $db->close();