/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('add'); // get the groups $groups = BackendGroupsModel::getAll(); // if there is only one group we can check it so the user isn't bothered with an error for not selecting one $checkedGroups = count($groups) == 1 ? $groups[0]['value'] : null; // create elements // profile $this->frm->addText('email', null, 255); $this->frm->addPassword('password', null, 75, 'inputText inputPassword passwordGenerator', 'inputTextError inputPasswordError passwordGenerator')->setAttributes(array('autocomplete' => 'off')); $this->frm->addPassword('confirm_password', null, 75)->setAttributes(array('autocomplete' => 'off')); $this->frm->addText('name', null, 255); $this->frm->addText('surname', null, 255); $this->frm->addText('nickname', null, 24); $this->frm->addImage('avatar'); $this->frm->addDropdown('interface_language', BackendLanguage::getInterfaceLanguages(), BackendModel::getModuleSetting('core', 'default_interface_language')); $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), BackendAuthentication::getUser()->getSetting('date_format')); $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), BackendAuthentication::getUser()->getSetting('time_format')); $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), BackendAuthentication::getUser()->getSetting('number_format', 'dot_nothing')); $this->frm->addDropDown('csv_split_character', BackendUsersModel::getCSVSplitCharacters()); $this->frm->addDropDown('csv_line_ending', BackendUsersModel::getCSVLineEndings()); // permissons $this->frm->addCheckbox('active', true); $this->frm->addCheckbox('api_access', false); $this->frm->addMultiCheckbox('groups', $groups, $checkedGroups); }
/** * Load the form */ private function loadForm() { // create user objects $this->user = new BackendUser($this->id); $this->authenticatedUser = BackendAuthentication::getUser(); // create form $this->frm = new BackendForm('edit'); // get active groups $groups = BackendGroupsModel::getGroupsByUser($this->id); // loop through groups and set checked foreach ($groups as $group) { $checkedGroups[] = $group['id']; } // create elements // profile $this->frm->addText('email', $this->record['email'], 255); if ($this->user->isGod()) { $this->frm->getField('email')->setAttributes(array('disabled' => 'disabled')); } $this->frm->addText('name', $this->record['settings']['name'], 255); $this->frm->addText('surname', $this->record['settings']['surname'], 255); $this->frm->addText('nickname', $this->record['settings']['nickname'], 24); $this->frm->addImage('avatar'); // password // check if we're god or same user if ($this->authenticatedUser->getUserId() == $this->id || $this->authenticatedUser->isGod()) { // allow to set new password $this->frm->addPassword('new_password', null, 75); $this->frm->addPassword('confirm_password', null, 75); // disable autocomplete $this->frm->getField('new_password')->setAttributes(array('autocomplete' => 'off')); $this->frm->getField('confirm_password')->setAttributes(array('autocomplete' => 'off')); } // settings $this->frm->addDropdown('interface_language', BackendLanguage::getInterfaceLanguages(), $this->record['settings']['interface_language']); $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), $this->user->getSetting('date_format')); $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), $this->user->getSetting('time_format')); $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), $this->user->getSetting('number_format', 'dot_nothing')); $this->frm->addDropDown('csv_split_character', BackendUsersModel::getCSVSplitCharacters(), $this->user->getSetting('csv_split_character')); $this->frm->addDropDown('csv_line_ending', BackendUsersModel::getCSVLineEndings(), $this->user->getSetting('csv_line_ending')); // permissions $this->frm->addCheckbox('active', $this->record['active'] == 'Y'); // disable active field for current users if ($this->authenticatedUser->getUserId() == $this->record['id']) { $this->frm->getField('active')->setAttribute('disabled', 'disabled'); } $this->frm->addCheckbox('api_access', isset($this->record['settings']['api_access']) && $this->record['settings']['api_access'] == 'Y'); $this->frm->addMultiCheckbox('groups', BackendGroupsModel::getAll(), $checkedGroups); }
/** * Load the form * * @return void */ private function loadForm() { // create form $this->frm = new BackendForm('add'); // create elements $this->frm->addText('email', null, 255); $this->frm->addPassword('password', null, 75, 'inputText inputPassword passwordGenerator', 'inputTextError inputPasswordError passwordGenerator'); $this->frm->addPassword('confirm_password', null, 75); $this->frm->addText('nickname', null, 24); $this->frm->addText('name', null, 255); $this->frm->addText('surname', null, 255); $this->frm->addDropdown('interface_language', BackendLanguage::getInterfaceLanguages()); $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), BackendAuthentication::getUser()->getSetting('date_format')); $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), BackendAuthentication::getUser()->getSetting('time_format')); $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), BackendAuthentication::getUser()->getSetting('number_format', 'dot_nothing')); $this->frm->addImage('avatar'); $this->frm->addCheckbox('active', true); $this->frm->addCheckbox('api_access', false); $this->frm->addMultiCheckbox('groups', BackendGroupsModel::getAll()); // disable autocomplete $this->frm->getField('password')->setAttributes(array('autocomplete' => 'off')); $this->frm->getField('confirm_password')->setAttributes(array('autocomplete' => 'off')); }
/** * Process the querystring * * @return void */ private function processQueryString() { // store the querystring local, so we don't alter it. $queryString = $this->getQueryString(); // find the position of ? (which seperates real URL and GET-parameters) $positionQuestionMark = strpos($queryString, '?'); // remove the GET-chunk from the parameters $processedQueryString = $positionQuestionMark === false ? $queryString : substr($queryString, 0, $positionQuestionMark); // split into chunks, a Backend URL will always look like /<lang>/<module>/<action>(?GET) $chunks = (array) explode('/', trim($processedQueryString, '/')); // check if this is a request for a JS-file $isJS = isset($chunks[1]) && $chunks[1] == 'js.php'; // check if this is a request for a AJAX-file $isAJAX = isset($chunks[1]) && $chunks[1] == 'ajax.php'; // get the language, this will always be in front $language = isset($chunks[1]) && $chunks[1] != '' ? SpoonFilter::getValue($chunks[1], array_keys(BackendLanguage::getWorkingLanguages()), '') : ''; // no language provided? if ($language == '' && !$isJS && !$isAJAX) { // remove first element array_shift($chunks); // redirect to login SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . SITE_DEFAULT_LANGUAGE . '/' . implode('/', $chunks)); } // get the module, null will be the default $module = isset($chunks[2]) && $chunks[2] != '' ? $chunks[2] : 'dashboard'; // get the requested action, if it is passed if (isset($chunks[3]) && $chunks[3] != '') { $action = $chunks[3]; } elseif (!$isJS && !$isAJAX) { // build path to the module and define it. This is a constant because we can use this in templates. if (!defined('BACKEND_MODULE_PATH')) { define('BACKEND_MODULE_PATH', BACKEND_MODULES_PATH . '/' . $module); } // check if the config is present? If it isn't present there is a huge problem, so we will stop our code by throwing an error if (!SpoonFile::exists(BACKEND_MODULE_PATH . '/config.php')) { throw new BackendException('The configfile for the module (' . $module . ') can\'t be found.'); } // build config-object-name $configClassName = 'Backend' . SpoonFilter::toCamelCase($module . '_config'); // require the config file, we validated before for existence. require_once BACKEND_MODULE_PATH . '/config.php'; // validate if class exists (aka has correct name) if (!class_exists($configClassName)) { throw new BackendException('The config file is present, but the classname should be: ' . $configClassName . '.'); } // create config-object, the constructor will do some magic $config = new $configClassName($module); // set action $action = $config->getDefaultAction() !== null ? $config->getDefaultAction() : 'index'; } // if it is an request for a JS-file or an AJAX-file we only need the module if ($isJS || $isAJAX) { // set the working language, this is not the interface language BackendLanguage::setWorkingLanguage(SpoonFilter::getGetValue('language', null, SITE_DEFAULT_LANGUAGE)); // set current module $this->setModule(SpoonFilter::getGetValue('module', null, null)); // set action $this->setAction('index'); } else { // the person isn't logged in? or the module doesn't require authentication if (!BackendAuthentication::isLoggedIn() && !BackendAuthentication::isAllowedModule($module)) { // redirect to login SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/authentication/?querystring=' . urlencode('/' . $this->getQueryString())); } else { // does our user has access to this module? if (!BackendAuthentication::isAllowedModule($module)) { // the user doesn't have access, redirect to error page SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/error?type=module-not-allowed&querystring=' . urlencode('/' . $this->getQueryString())); } else { // can our user execute the requested action? if (!BackendAuthentication::isAllowedAction($action, $module)) { // the user hasn't access, redirect to error page SpoonHTTP::redirect('/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed&querystring=' . urlencode('/' . $this->getQueryString())); } else { // set the working language, this is not the interface language BackendLanguage::setWorkingLanguage($language); // is the user authenticated if (BackendAuthentication::getUser()->isAuthenticated()) { // set interface language based on the user preferences BackendLanguage::setLocale(BackendAuthentication::getUser()->getSetting('interface_language', 'nl')); } else { // init var $interfaceLanguage = BackendModel::getModuleSetting('core', 'default_interface_language'); // override with cookie value if that exists if (SpoonCookie::exists('interface_language') && in_array(SpoonCookie::get('interface_language'), array_keys(BackendLanguage::getInterfaceLanguages()))) { // set interface language based on the perons' cookies $interfaceLanguage = SpoonCookie::get('interface_language'); } // set interface language BackendLanguage::setLocale($interfaceLanguage); } // set current module $this->setModule($module); $this->setAction($action); } } } } }
/** * Set the locale */ private function setLocale() { $default = BackendModel::getModuleSetting('core', 'default_interface_language'); $locale = $default; $possibleLocale = array_keys(BackendLanguage::getInterfaceLanguages()); // is the user authenticated if (BackendAuthentication::getUser()->isAuthenticated()) { $locale = BackendAuthentication::getUser()->getSetting('interface_language', $default); } elseif (SpoonCookie::exists('interface_language')) { $locale = SpoonCookie::get('interface_language'); } // validate if the requested locale is possible if (!in_array($locale, $possibleLocale)) { $locale = $default; } BackendLanguage::setLocale($locale); }