コード例 #1
0
 function index($page = 1)
 {
     $this->template->content = new View('admin/feedback');
     $this->template->content->title = Kohana::lang('ui_admin.feedback');
     // check, has the form been submitted?
     $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('feedback_id.*', 'required', 'numeric');
         if ($post->validate()) {
             if ($post->action == 'r') {
                 foreach ($post->feedback_id as $item) {
                     $update = new Feedback_Model($item);
                     if ($update->loaded == true) {
                         $update->feedback_status = '0';
                         $update->save();
                     }
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.read'));
             } elseif ($post->action == 'u') {
                 foreach ($post->feedback_id as $item) {
                     $update = new Feedback_Model($item);
                     if ($update->loaded == true) {
                         $update->feedback_status = '1';
                         $update->save();
                     }
                 }
                 //TODO write unread action code
                 $form_action = strtoupper(Kohana::lang('ui_admin.unread'));
             } elseif ($post->action == 'd') {
                 foreach ($post->feedback_id as $item) {
                     $update = new Feedback_Model($item);
                     if ($update->loaded == true) {
                         $feedback_id = $update->id;
                         $update->delete();
                     }
                     // Delete feedback_person
                     ORM::factory('feedback_person')->where('feedback_id', $feedback_id)->delete_all();
                 }
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             }
             $form_saved = TRUE;
         } else {
             $form_error = TRUE;
         }
     }
     $filter = "WHERE feedback.feedback_status=1";
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page_admin'), 'total_items' => ORM::factory('feedback')->count_all()));
     $all_feedback = ORM::factory('feedback')->select('feedback_person.person_ip,feedback.*')->join('feedback_person', array('feedback_person.feedback_id' => 'feedback.id'), $filter, 'LEFT JOIN')->orderby('feedback_dateadd', 'desc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $this->template->content->all_feedback = $all_feedback;
     $this->template->content->pagination = $pagination;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
     $this->template->content->form_action = $form_action;
     // Total feedback
     $this->template->content->total_items = $pagination->total_items;
     // Javascript Header
     $this->template->js = new View('admin/feedback_js');
 }