Example #1
0
 /**
  * Lists the forms.
  */
 public function index()
 {
     $this->template->content = new View('admin/forms');
     // setup and initialize form field names
     $form = array('action' => '', 'form_id' => '', 'form_title' => '', 'form_description' => '', 'form_active' => '', 'field_type' => '');
     //  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 = "";
     $form_id = "";
     if ($_POST) {
         $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('form_title', 'required', 'length[3,100]');
             $post->add_rules('form_description', 'required');
         } elseif ($post->action == 'd') {
             if ($_POST['form_id'] == 1) {
                 // Default Form Cannot Be Deleted
                 $post->add_error('form_id', 'default');
             }
         }
         if ($post->validate()) {
             $form_id = $post->form_id;
             $custom_form = new Form_Model($form_id);
             if ($post->action == 'd') {
                 // Delete Action
                 $custom_form->delete($form_id);
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } else {
                 if ($post->action == 'h') {
                     // Active/Inactive Action
                     if ($custom_form->loaded == true) {
                         if ($custom_form->form_active == 1) {
                             $custom_form->form_active = 0;
                         } else {
                             $custom_form->form_active = 1;
                         }
                         $custom_form->save();
                         $form_saved = TRUE;
                         $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                     }
                 } else {
                     // Save Action
                     $custom_form->form_title = $post->form_title;
                     $custom_form->form_description = $post->form_description;
                     $custom_form->save();
                     $form_saved = TRUE;
                     $form_action = strtoupper(Kohana::lang('ui_admin.created_edited'));
                 }
             }
             // Empty $form array
             array_fill_keys($form, '');
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('form'));
             $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('form')->count_all()));
     $forms = ORM::factory('form')->orderby('id', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     // Form Field Types
     $form_field_types = array('' => Kohana::lang('ui_admin.select_field_type'), 1 => Kohana::lang('ui_admin.text_field'), 2 => Kohana::lang('ui_admin.free_text_field'));
     $this->template->content->form = $form;
     $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->forms = $forms;
     $this->template->content->form_field_types = $form_field_types;
     $this->template->content->errors = $errors;
     // Javascript Header
     $this->template->js = new View('admin/forms_js');
     $this->template->js->form_id = $form_id;
     $this->template->form_error = $form_error;
 }
Example #2
0
 /**
  * Lists the forms.
  */
 public function index()
 {
     $this->template->content = new View('admin/manage/forms/main');
     // Setup and initialize form field names
     $form = array('action' => '', 'form_id' => '', 'form_title' => '', 'form_description' => '', 'form_active' => '', 'field_type' => '');
     // 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 = "";
     $form_id = "";
     if ($_POST) {
         $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('form_title', 'required', 'length[1,1000]');
             $post->add_rules('form_description', 'required');
         } elseif ($post->action == 'd') {
             if ($_POST['form_id'] == 1) {
                 // Default Form Cannot Be Deleted
                 $post->add_error('form_id', 'default');
             }
         }
         if ($post->validate()) {
             $form_id = $post->form_id;
             $custom_form = new Form_Model($form_id);
             if ($post->action == 'd') {
                 // Delete Action
                 $custom_form->delete($form_id);
                 $form_saved = TRUE;
                 $form_action = utf8::strtoupper(Kohana::lang('ui_admin.deleted'));
             } elseif ($post->action == 'h') {
                 // Active/Inactive Action
                 if ($custom_form->loaded) {
                     // @todo Doesn't make sense, find out what the logic for this is
                     // Customary values for active and inactive are 1 and 0 respectively
                     $custom_form->form_active = $custom_form->form_active == 1 ? 0 : 1;
                     $custom_form->save();
                     $form_saved = TRUE;
                     $form_action = utf8::strtoupper(Kohana::lang('ui_admin.modified'));
                 }
             } else {
                 // Save Action
                 $custom_form->form_title = $post->form_title;
                 $custom_form->form_description = $post->form_description;
                 $custom_form->save();
                 $form_saved = TRUE;
                 $form_action = utf8::strtoupper(Kohana::lang('ui_admin.created_edited'));
             }
             // Empty $form array
             array_fill_keys($form, '');
         } else {
             // Repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // Populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('form'));
             $form_error = TRUE;
         }
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('form')->count_all()));
     $forms = ORM::factory('form')->orderby('id', 'asc')->find_all($this->items_per_page, $pagination->sql_offset);
     // Form Field Types
     $form_field_types = array('' => Kohana::lang('ui_admin.select_field_type'), 1 => Kohana::lang('ui_admin.text_field'), 2 => Kohana::lang('ui_admin.free_text_field'), 3 => Kohana::lang('ui_admin.date_field'), 5 => Kohana::lang('ui_admin.radio_field'), 6 => Kohana::lang('ui_admin.checkbox_field'), 7 => Kohana::lang('ui_admin.dropdown_field'), 8 => Kohana::lang('ui_admin.divider_start_field'), 9 => Kohana::lang('ui_admin.divider_end_field'));
     $this->template->content->form = $form;
     $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->forms = $forms;
     $this->template->content->form_field_types = $form_field_types;
     $this->template->content->errors = $errors;
     // Javascript Header
     $this->template->js = new View('admin/manage/forms/forms_js');
     $this->template->js->form_id = $form_id;
     $this->template->form_error = $form_error;
 }