function index() { $this->template->content = new View('admin/blocks'); $this->template->content->title = Kohana::lang('ui_admin.blocks'); // Get Registered Blocks if (!is_array($this->_registered_blocks)) { $this->_registered_blocks = array(); } // Get Active Blocks $settings = ORM::factory('settings', 1); $active_blocks = $settings->blocks; $active_blocks = array_filter(explode("|", $active_blocks)); // setup and initialize form field names $form = array('action' => '', 'block' => ''); // 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 = ""; if ($_POST) { $post = Validation::factory($_POST); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('action', 'required', 'alpha', 'length[1,1]'); $post->add_rules('block', 'required', 'alpha_dash'); if (!array_key_exists($post->block, $this->_registered_blocks)) { $post->add_error('block', 'exists'); } if ($post->validate()) { // Activate a block if ($post->action == 'a') { array_push($active_blocks, $post->block); $settings->blocks = implode("|", $active_blocks); $settings->save(); } elseif ($post->action == 'd') { $active_blocks = array_diff($active_blocks, array($post->block)); $settings->blocks = implode("|", $active_blocks); $settings->save(); } } else { $errors = arr::overwrite($errors, $post->errors('blocks')); $form_error = TRUE; } } // Sort the Blocks $sorted_blocks = blocks::sort($active_blocks, array_keys($this->_registered_blocks)); $this->template->content->form = $form; $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->total_items = count($this->_registered_blocks); $this->template->content->registered_blocks = $this->_registered_blocks; $this->template->content->active_blocks = $active_blocks; $this->template->content->sorted_blocks = $sorted_blocks; // Javascript Header $this->template->tablerowsort_enabled = TRUE; $this->template->js = new View('admin/blocks_js'); }