/** * @ignore */ public static function edit($uAction, $uSlug) { Auth::checkRedirect('editor'); $tModule = AutoModels::get(Panel::$module); $tViewbag = array('module' => $tModule, 'fields' => array()); if (Request::$method === 'post') { //! todo: validations Validation::addRule('name')->isRequired()->errorMessage('Name shouldn\'t be blank.'); // Validation::addRule('slug')->isRequired()->errorMessage('Slug shouldn\'t be blank.'); if (Validation::validate($_POST)) { $tSlug = Request::post('slug', ""); if (strlen(rtrim($tSlug)) === 0) { $tSlug = Request::post('name', ""); } $tInput = array('type' => Request::post('type'), 'name' => Request::post('name'), 'slug' => String::slug(String::removeAccent($tSlug))); $tAutoModel = new AutoModel('categories'); $tAutoModel->update($uSlug, $tInput); Session::set('notification', array('info', 'ok-sign', 'Record modified.')); Http::redirect('panel/categories'); return; } Session::set('notification', array('error', 'remove-sign', Validation::getErrorMessages(true))); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, Request::post($tField['name'], null))) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => Request::post($tField['name'], ""), 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); return; } $tAutoModel = new AutoModel('categories'); $tCategory = $tAutoModel->getBySlug($tModule['name'], $uSlug); foreach ($tModule['fieldList'] as $tField) { $tIsView = array_key_exists('view', $tField['methods']); $tIsEdit = array_key_exists('edit', $tField['methods']); if ($tIsView || $tIsEdit) { if ($tField['type'] === 'enum') { $tTypes = array(); foreach ($tField['valueList'] as $tValue) { $tTypes[$tValue['name']] = $tValue['title']; } $tAttributes = array('name' => $tField['name'], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('select', $tAttributes, Html::selectOptions($tTypes, $tCategory[$tField['name']])) . '</p>'; } else { $tAttributes = array('type' => 'text', 'name' => $tField['name'], 'value' => $tCategory[$tField['name']], 'class' => 'input-block-level input_' . $tField['type']); if (!$tIsEdit) { $tAttributes['readonly'] = 'readonly'; } $tTag = '<p>' . I18n::_($tField['title']) . ': ' . Html::tag('input', $tAttributes) . '</p>'; } } $tViewbag['fields'][] = array('data' => $tField, 'html' => $tTag); } Views::viewFile('{core}views/panel/models/form.php', $tViewbag); }
/** * @ignore */ public function login() { if (Request::$method !== 'post') { Auth::clear(); $this->viewFile('{core}views/panel/login.php'); return; } // validations Validation::addRule('username')->isRequired()->errorMessage('Username shouldn\'t be blank.'); // Validation::addRule('username')->isEmail()->errorMessage('Please consider your e-mail address once again.'); Validation::addRule('password')->isRequired()->errorMessage('Password shouldn\'t be blank.'); Validation::addRule('password')->lengthMinimum(4)->errorMessage('Password should be longer than 4 characters at least.'); if (!Validation::validate($_POST)) { Session::set('notification', array('error', 'remove-sign', Validation::getErrorMessages(true))); $this->viewFile('{core}views/panel/login.php'); return; } $username = Request::post('username'); $password = Request::post('password'); // user not found if (!Auth::login($username, $password)) { Session::set('notification', array('error', 'remove-sign', 'User not found')); $this->viewFile('{core}views/panel/login.php'); return; } Http::redirect('panel'); }