/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); // group exists and id is not null? if ($this->id !== null && BackendGroupsModel::exists($this->id)) { parent::execute(); // get record $this->record = BackendGroupsModel::get($this->id); // delete group BackendGroupsModel::delete($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // item was deleted, so redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['name'])); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // email is present if ($this->frm->getField('email')->isFilled(BL::err('EmailIsRequired'))) { // is this an email-address if ($this->frm->getField('email')->isEmail(BL::err('EmailIsInvalid'))) { // was this emailaddress deleted before if (BackendUsersModel::emailDeletedBefore($this->frm->getField('email')->getValue())) { $this->frm->getField('email')->addError(sprintf(BL::err('EmailWasDeletedBefore'), BackendModel::createURLForAction('undo_delete', null, null, array('email' => $this->frm->getField('email')->getValue())))); } else { // email already exists if (BackendUsersModel::existsEmail($this->frm->getField('email')->getValue())) { $this->frm->getField('email')->addError(BL::err('EmailAlreadyExists')); } } } } // required fields $this->frm->getField('password')->isFilled(BL::err('PasswordIsRequired')); $this->frm->getField('nickname')->isFilled(BL::err('NicknameIsRequired')); $this->frm->getField('name')->isFilled(BL::err('NameIsRequired')); $this->frm->getField('surname')->isFilled(BL::err('SurnameIsRequired')); $this->frm->getField('interface_language')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('date_format')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('time_format')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('number_format')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('groups')->isFilled(BL::err('FieldIsRequired')); if ($this->frm->getField('password')->isFilled()) { if ($this->frm->getField('password')->getValue() !== $this->frm->getField('confirm_password')->getValue()) { $this->frm->getField('confirm_password')->addError(BL::err('ValuesDontMatch')); } } // validate avatar if ($this->frm->getField('avatar')->isFilled()) { // correct extension if ($this->frm->getField('avatar')->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $this->frm->getField('avatar')->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } // no errors? if ($this->frm->isCorrect()) { // build settings-array $settings['nickname'] = $this->frm->getField('nickname')->getValue(); $settings['name'] = $this->frm->getField('name')->getValue(); $settings['surname'] = $this->frm->getField('surname')->getValue(); $settings['interface_language'] = $this->frm->getField('interface_language')->getValue(); $settings['date_format'] = $this->frm->getField('date_format')->getValue(); $settings['time_format'] = $this->frm->getField('time_format')->getValue(); $settings['datetime_format'] = $settings['date_format'] . ' ' . $settings['time_format']; $settings['number_format'] = $this->frm->getField('number_format')->getValue(); $settings['csv_split_character'] = $this->frm->getField('csv_split_character')->getValue(); $settings['csv_line_ending'] = $this->frm->getField('csv_line_ending')->getValue(); $settings['password_key'] = uniqid(); $settings['current_password_change'] = time(); $settings['avatar'] = 'no-avatar.gif'; $settings['api_access'] = (bool) $this->frm->getField('api_access')->getChecked(); // get selected groups $groups = $this->frm->getField('groups')->getChecked(); // init var $newSequence = BackendGroupsModel::getSetting($groups[0], 'dashboard_sequence'); // loop through groups and collect all dashboard widget sequences foreach ($groups as $group) { $sequences[] = BackendGroupsModel::getSetting($group, 'dashboard_sequence'); } // loop through sequences foreach ($sequences as $sequence) { // loop through modules inside a sequence foreach ($sequence as $moduleKey => $module) { // loop through widgets inside a module foreach ($module as $widgetKey => $widget) { // if widget present set true if ($widget['present']) { $newSequence[$moduleKey][$widgetKey]['present'] = true; } } } } // add new sequence to settings $settings['dashboard_sequence'] = $newSequence; // build user-array $user['email'] = $this->frm->getField('email')->getValue(); $user['password'] = BackendAuthentication::getEncryptedString($this->frm->getField('password')->getValue(true), $settings['password_key']); // save the password strength $passwordStrength = BackendAuthentication::checkPassword($this->frm->getField('password')->getValue(true)); $settings['password_strength'] = $passwordStrength; // save changes $user['id'] = (int) BackendUsersModel::insert($user, $settings); // has the user submitted an avatar? if ($this->frm->getField('avatar')->isFilled()) { // create new filename $filename = rand(0, 3) . '_' . $user['id'] . '.' . $this->frm->getField('avatar')->getExtension(); // add into settings to update $settings['avatar'] = $filename; // resize (128x128) $this->frm->getField('avatar')->createThumbnail(FRONTEND_FILES_PATH . '/backend_users/avatars/128x128/' . $filename, 128, 128, true, false, 100); // resize (64x64) $this->frm->getField('avatar')->createThumbnail(FRONTEND_FILES_PATH . '/backend_users/avatars/64x64/' . $filename, 64, 64, true, false, 100); // resize (32x32) $this->frm->getField('avatar')->createThumbnail(FRONTEND_FILES_PATH . '/backend_users/avatars/32x32/' . $filename, 32, 32, true, false, 100); } // update settings (in this case the avatar) BackendUsersModel::update($user, $settings); // save groups BackendGroupsModel::insertMultipleGroups($user['id'], $groups); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $user)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . $settings['nickname'] . '&highlight=row-' . $user['id']); } } }
/** * Validate the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // init $bundledActionPermissions = array(); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // get fields $nameField = $this->frm->getField('name'); // loop through modules foreach ($this->modules as $module) { // loop through actions foreach ($this->actions[$module['value']] as $action) { // collect permissions if not bundled if (!array_key_exists('group', $action)) { $actionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . $action['label']); } } // loop through bundled actions foreach ($this->actionGroups as $key => $group) { // loop through all fields foreach ($this->frm->getFields() as $field) { // field exists? if ($field->getName() == 'actions_' . $module['label'] . '_' . 'Group_' . ucfirst($key)) { // add to bundled actions $bundledActionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . 'Group_' . ucfirst($key)); } } } } // loop through widgets and collect presets foreach ($this->widgets as $widget) { $widgetPresets[] = $this->frm->getField('widgets_' . $widget['label']); } // validate fields $nameField->isFilled(BL::err('NameIsRequired')); // group already exists? if (BackendGroupsModel::alreadyExists($nameField->getValue())) { $nameField->setError(BL::err('GroupAlreadyExists')); } // no errors? if ($this->frm->isCorrect()) { // insert widgets $group = $this->insertWidgets($widgetPresets); // assign id $this->id = $group['id']; // insert permissions $this->insertPermissions($actionPermissions, $bundledActionPermissions); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $group)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($group['name']) . '&highlight=row-' . $group['id']); } } }
/** * Load the data */ private function loadData() { // get all modules $modules = BackendModel::getModules(); // get user sequence $userSequence = BackendAuthentication::getUser()->getSetting('dashboard_sequence'); // user sequence does not exist? if (!isset($userSequence)) { // get group ID of user $groupId = BackendAuthentication::getUser()->getGroupId(); // get group preset $userSequence = BackendGroupsModel::getSetting($groupId, 'dashboard_sequence'); } // loop all modules foreach ($modules as $module) { // you have sufficient rights? if (BackendAuthentication::isAllowedModule($module)) { // build pathName $pathName = BACKEND_MODULES_PATH . '/' . $module; // check if the folder exists if (SpoonDirectory::exists($pathName . '/widgets')) { // get widgets $widgets = (array) SpoonFile::getList($pathName . '/widgets', '/(.*)\\.php/i'); // loop widgets foreach ($widgets as $widget) { // require the class require_once $pathName . '/widgets/' . $widget; // init var $widgetName = str_replace('.php', '', $widget); // build classname $className = 'Backend' . SpoonFilter::toCamelCase($module) . 'Widget' . SpoonFilter::toCamelCase($widgetName); // validate if the class exists if (!class_exists($className)) { throw new BackendException('The widgetfile is present, but the classname should be: ' . $className . '.'); } // check if model file exists if (SpoonFile::exists($pathName . '/engine/model.php')) { // require model require_once $pathName . '/engine/model.php'; } // present? $present = isset($userSequence[$module][$widgetName]['present']) ? $userSequence[$module][$widgetName]['present'] : false; // if not present, continue if (!$present) { continue; } // create instance $instance = new $className(); // has rights if (!$instance->isAllowed()) { continue; } // hidden? $hidden = isset($userSequence[$module][$widgetName]['hidden']) ? $userSequence[$module][$widgetName]['hidden'] : false; // execute instance if it is not hidden if (!$hidden) { $instance->execute(); } // user sequence provided? $column = isset($userSequence[$module][$widgetName]['column']) ? $userSequence[$module][$widgetName]['column'] : $instance->getColumn(); $position = isset($userSequence[$module][$widgetName]['position']) ? $userSequence[$module][$widgetName]['position'] : $instance->getPosition(); $title = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($module))) . ': ' . BL::lbl(SpoonFilter::toCamelCase($widgetName)); $templatePath = $instance->getTemplatePath(); // reset template path if ($templatePath == null) { $templatePath = BACKEND_PATH . '/modules/' . $module . '/layout/widgets/' . $widgetName . '.tpl'; } // build item $item = array('template' => $templatePath, 'module' => $module, 'widget' => $widgetName, 'title' => $title, 'hidden' => $hidden); // add on new position if no position is set or if the position is already used if ($position === null || isset($this->widgets[$column][$position])) { $this->widgets[$column][] = $item; } else { $this->widgets[$column][$position] = $item; } } } } } // sort the widgets foreach ($this->widgets as &$column) { ksort($column); } }