function levels() { $this->template->content = new View('admin/levels'); $this->template->content->title = Kohana::lang('ui_admin.reporter_levels'); // setup and initialize form field names $form = array('level_id' => '', 'level_title' => '', 'level_description' => '', 'level_weight' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; // check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things $post = Validation::factory($_POST); // Add some filters $post->pre_filter('trim', TRUE); if ($post->action == 'a') { // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('level_title', 'required', 'length[3,80]'); $post->add_rules('level_description', 'required'); $post->add_rules('level_weight', 'required'); } // Test to see if things passed the rule checks if ($post->validate()) { $level_id = $post->level_id; $level = new Level_Model($level_id); if ($post->action == 'd') { $level->delete($level_id); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.deleted')); } else { if ($post->action == 'a') { // SAVE Category $level->level_title = $post->level_title; $level->level_description = $post->level_description; $level->level_weight = $post->level_weight; $level->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.added_edited')); } } } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('level')); $form_error = TRUE; } } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('level')->count_all())); $levels = ORM::factory('level')->orderby('level_weight', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset); $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->pagination = $pagination; $this->template->content->total_items = $pagination->total_items; $this->template->content->levels = $levels; }