コード例 #1
0
ファイル: manage.php プロジェクト: kamaulynder/Ushahidi_Chile
 function reporters()
 {
     $this->template->content = new View('admin/reporters');
     $this->template->content->title = 'Reporters';
     // setup and initialize form field names
     $form = array('reporter_id' => '', 'service_id' => '', 'level_id' => '', 'service_userid' => '', 'service_account' => '', 'reporter_first' => '', 'reporter_last' => '', 'reporter_email' => '', 'reporter_phone' => '', 'reporter_ip' => '', 'reporter_date' => '');
     //  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('service_id', 'required');
             // we also require either service_userid or service_account, not necessarily both
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             $reporter_id = $post->reporter_id;
             $reporter = new Reporter_Model($reporter_id);
             if ($post->action == 'd') {
                 $reporter->delete($reporter_id);
                 $form_saved = TRUE;
                 $form_action = "DELETED";
             } else {
                 if ($post->action == 'a') {
                     // SAVE Reporter
                     $reporter->service_id = $post->service_id;
                     $reporter->level_id = $post->level_id;
                     /*$reporter->service_userid = $post->service_userid;
                     		$reporter->service_account = $post->service_account;*/
                     /*$reporter->reporter_first = $post->reporter_first;
                     		$reporter->reporter_last = $post->reporter_last;
                     		$reporter->reporter_email = $post->reporter_email;
                     		$reporter->reporter_phone = $post->reporter_phone;
                     		$reporter->reporter_ip = $post->reporter_ip;
                     		$reporter->reporter_date = $post->reporter_date;*/
                     $reporter->save();
                     $form_saved = TRUE;
                     $form_action = "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('reporter')->count_all()));
     $reporters = ORM::factory('reporter')->orderby('reporter_first', 'asc')->find_all((int) Kohana::config('settings.items_per_page_admin'), $pagination->sql_offset);
     $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->pagination = $pagination;
     $this->template->content->total_items = $pagination->total_items;
     $this->template->content->reporters = $reporters;
     // Level and Service Arrays
     $this->template->content->level_array = Level_Model::get_array();
     $this->template->content->service_array = Service_Model::get_array();
 }