Beispiel #1
0
 public function index($service_id = 1)
 {
     $this->template->content = new View('admin/reporters');
     $this->template->content->title = Kohana::lang('ui_admin.reporters');
     $filter = "1=1";
     $search_type = "";
     $keyword = "";
     // Get Search Type (If Any)
     if ($service_id) {
         $search_type = $service_id;
         $filter .= " AND (service_id='" . $service_id . "')";
     } else {
         $search_type = "0";
     }
     // Get Search Keywords (If Any)
     if (isset($_GET['k']) and !empty($_GET['k'])) {
         $keyword = $_GET['k'];
         $filter .= " AND (service_account LIKE'%" . $_GET['k'] . "%')";
     }
     // setup and initialize form field names
     $form = array('reporter_id' => '', 'level_id' => '', 'service_name' => '', 'service_account' => '', 'location_id' => '', 'location_name' => '', 'latitude' => '', 'longitude' => '');
     //  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);
         // 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('reporter_id.*', 'required', 'numeric');
         if ($post->action == 'l') {
             $post->add_rules('level_id', 'required', 'numeric');
         } elseif ($post->action == 'a') {
             $post->add_rules('level_id', 'required', 'numeric');
             // If any location data is provided, require all location parameters
             if ($post->latitude or $post->longitude or $post->location_name) {
                 $post->add_rules('latitude', 'required', 'between[-90,90]');
                 // Validate for maximum and minimum latitude values
                 $post->add_rules('longitude', 'required', 'between[-180,180]');
                 // Validate for maximum and minimum longitude values
                 $post->add_rules('location_name', 'required', 'length[3,200]');
             }
         }
         // Test to see if things passed the rule checks
         if ($post->validate()) {
             if ($post->action == 'd') {
                 foreach ($post->reporter_id as $item) {
                     // Delete Reporters Messages
                     ORM::factory('message')->where('reporter_id', $item)->delete_all();
                     // Delete Reporter
                     $reporter = ORM::factory('reporter')->find($item);
                     $reporter->delete($item);
                 }
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.deleted'));
             } elseif ($post->action == 'l') {
                 foreach ($post->reporter_id as $item) {
                     // Update Reporter Level
                     $reporter = ORM::factory('reporter')->find($item);
                     if ($reporter->loaded) {
                         $reporter->level_id = $post->level_id;
                         $reporter->save();
                     }
                 }
                 $form_saved = TRUE;
                 $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
             } else {
                 if ($post->action == 'a') {
                     foreach ($post->reporter_id as $item) {
                         $reporter = ORM::factory('reporter')->find($item);
                         // SAVE Reporter only if loaded
                         if ($reporter->loaded) {
                             $reporter->level_id = $post->level_id;
                             // SAVE Location if available
                             if ($post->latitude and $post->longitude) {
                                 $location = new Location_Model($post->location_id);
                                 $location->location_name = $post->location_name;
                                 $location->latitude = $post->latitude;
                                 $location->longitude = $post->longitude;
                                 $location->location_date = date("Y-m-d H:i:s", time());
                                 $location->save();
                                 $reporter->location_id = $location->id;
                             }
                             $reporter->save();
                             $form_saved = TRUE;
                             $form_action = strtoupper(Kohana::lang('ui_admin.modified'));
                         }
                     }
                 }
             }
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('reporters'));
             $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')->where($filter)->count_all()));
     $reporters = ORM::factory('reporter')->where($filter)->orderby('service_account', '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;
     $this->template->content->service_id = $service_id;
     $this->template->content->search_type = $search_type;
     $search_type_array = Service_Model::get_array();
     $search_type_array[0] = "All";
     asort($search_type_array);
     $this->template->content->search_type_array = $search_type_array;
     $this->template->content->keyword = $keyword;
     $levels = ORM::factory('level')->orderby('level_weight')->find_all();
     $this->template->content->levels = $levels;
     // Level and Service Arrays
     $this->template->content->level_array = Level_Model::get_array();
     $this->template->content->service_array = Service_Model::get_array();
     // Javascript Header
     $this->template->map_enabled = TRUE;
     $this->template->js = new View('admin/reporters_js');
     $this->template->js->default_map = Kohana::config('settings.default_map');
     $this->template->js->default_zoom = Kohana::config('settings.default_zoom');
     $this->template->js->latitude = Kohana::config('settings.default_lat');
     $this->template->js->longitude = Kohana::config('settings.default_lon');
     $this->template->js->form_error = $form_error;
 }
Beispiel #2
0
 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' => '', 'service_userid' => '', 'service_account' => '', 'reporter_level' => '', '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') {
                 $level->delete($level_id);
                 $form_saved = TRUE;
                 $form_action = "DELETED";
             } else {
                 if ($post->action == 'a') {
                     // SAVE Reporter
                     $reporter->service_id = $post->service_id;
                     /*$reporter->service_userid = $post->service_userid;
                     		$reporter->service_account = $post->service_account;*/
                     $reporter->reporter_level = $post->reporter_level;
                     /*$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();
 }
Beispiel #3
0
 /**
  * Displays all reports.
  */
 public function index()
 {
     // Cacheable Controller
     $this->is_cachable = TRUE;
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports');
     $this->themes->js = new View('reports_js');
     // Store any exisitng URL parameters
     $this->themes->js->url_params = json_encode($_GET);
     // Enable the map
     $this->themes->map_enabled = TRUE;
     // Set the latitude and longitude
     $this->themes->js->latitude = Kohana::config('settings.default_lat');
     $this->themes->js->longitude = Kohana::config('settings.default_lon');
     $this->themes->js->default_map = Kohana::config('settings.default_map');
     $this->themes->js->default_zoom = Kohana::config('settings.default_zoom');
     // Load the alert radius view
     $alert_radius_view = new View('alert_radius_view');
     $alert_radius_view->show_usage_info = FALSE;
     $alert_radius_view->enable_find_location = FALSE;
     $alert_radius_view->css_class = "rb_location-radius";
     $this->template->content->alert_radius_view = $alert_radius_view;
     // Get locale
     $l = Kohana::config('locale.language.0');
     // Get the report listing view
     $report_listing_view = $this->_get_report_listing_view($l);
     // Set the view
     $this->template->content->report_listing_view = $report_listing_view;
     // Load the category
     $category_id = (isset($_GET['c']) and intval($_GET['c']) > 0) ? intval($_GET['c']) : 0;
     $category = ORM::factory('category', $category_id);
     if ($category->loaded) {
         $translated_title = Category_Lang_Model::category_title($category_id, $l);
         // Set the category title
         $this->template->content->category_title = $translated_title ? $translated_title : $category->category_title;
     } else {
         $this->template->content->category_title = "";
     }
     // Collect report stats
     $this->template->content->report_stats = new View('reports_stats');
     // Total Reports
     $total_reports = Incident_Model::get_total_reports(TRUE);
     // Get the date of the oldest report
     $oldest_timestamp = Incident_Model::get_oldest_report_timestamp();
     // Get the date of the latest report
     $latest_timestamp = Incident_Model::get_latest_report_timestamp();
     // Round the number of days up to the nearest full day
     $days_since = ceil((time() - $oldest_timestamp) / 86400);
     $avg_reports_per_day = $days_since < 1 ? $total_reports : round($total_reports / $days_since, 2);
     // Percent Verified
     $total_verified = Incident_Model::get_total_reports_by_verified(TRUE);
     $percent_verified = $total_reports == 0 ? '-' : round($total_verified / $total_reports * 100, 2) . '%';
     // Category tree view
     $this->template->content->category_tree_view = category::get_category_tree_view();
     // Additional view content
     $this->template->content->oldest_timestamp = $oldest_timestamp;
     $this->template->content->latest_timestamp = $latest_timestamp;
     $this->template->content->report_stats->total_reports = $total_reports;
     $this->template->content->report_stats->avg_reports_per_day = $avg_reports_per_day;
     $this->template->content->report_stats->percent_verified = $percent_verified;
     $this->template->content->services = Service_Model::get_array();
     $this->template->header->header_block = $this->themes->header_block();
 }
Beispiel #4
0
 /**
  * Displays all reports.
  */
 public function index()
 {
     // Cacheable Controller
     $this->is_cachable = TRUE;
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports/main');
     $this->themes->js = new View('reports/reports_js');
     $this->template->header->page_title .= Kohana::lang('ui_main.reports') . Kohana::config('settings.title_delimiter');
     // Store any exisitng URL parameters
     $this->themes->js->url_params = json_encode($_GET);
     // Enable the map
     $this->themes->map_enabled = TRUE;
     // Set the latitude and longitude
     $this->themes->js->latitude = Kohana::config('settings.default_lat');
     $this->themes->js->longitude = Kohana::config('settings.default_lon');
     $this->themes->js->default_map = Kohana::config('settings.default_map');
     $this->themes->js->default_zoom = Kohana::config('settings.default_zoom');
     // Get Default Color
     $this->themes->js->default_map_all = $this->template->content->default_map_all = Kohana::config('settings.default_map_all');
     // Get default icon
     $this->themes->js->default_map_all_icon = $this->template->content->default_map_all_icon = '';
     if (Kohana::config('settings.default_map_all_icon_id')) {
         $icon_object = ORM::factory('media')->find(Kohana::config('settings.default_map_all_icon_id'));
         $this->themes->js->default_map_all_icon = $this->template->content->default_map_all_icon = Kohana::config('upload.relative_directory') . "/" . $icon_object->media_thumb;
     }
     // Load the alert radius view
     $alert_radius_view = new View('alerts/radius');
     $alert_radius_view->show_usage_info = FALSE;
     $alert_radius_view->enable_find_location = TRUE;
     $alert_radius_view->css_class = "rb_location-radius";
     $this->template->content->alert_radius_view = $alert_radius_view;
     // Get locale
     $l = Kohana::config('locale.language.0');
     // Get the report listing view
     $report_listing_view = $this->_get_report_listing_view($l);
     // Set the view
     $this->template->content->report_listing_view = $report_listing_view;
     // Load the category
     $category_id = (isset($_GET['c']) and intval($_GET['c']) > 0) ? intval($_GET['c']) : 0;
     $category = ORM::factory('category', $category_id);
     if ($category->loaded) {
         // Set the category title
         $this->template->content->category_title = Category_Lang_Model::category_title($category_id, $l);
     } else {
         $this->template->content->category_title = "";
     }
     // Collect report stats
     $this->template->content->report_stats = new View('reports/stats');
     // Total Reports
     $total_reports = Incident_Model::get_total_reports(TRUE);
     // Get the date of the oldest report
     if (isset($_GET['s']) and !empty($_GET['s']) and intval($_GET['s']) > 0) {
         $oldest_timestamp = intval($_GET['s']);
     } else {
         $oldest_timestamp = Incident_Model::get_oldest_report_timestamp();
     }
     // Get the date of the latest report
     if (isset($_GET['e']) and !empty($_GET['e']) and intval($_GET['e']) > 0) {
         $latest_timestamp = intval($_GET['e']);
     } else {
         $latest_timestamp = Incident_Model::get_latest_report_timestamp();
     }
     // Round the number of days up to the nearest full day
     $days_since = ceil((time() - $oldest_timestamp) / 86400);
     $avg_reports_per_day = $days_since < 1 ? $total_reports : round($total_reports / $days_since, 2);
     // Percent Verified
     $total_verified = Incident_Model::get_total_reports_by_verified(TRUE);
     $percent_verified = $total_reports == 0 ? '-' : round($total_verified / $total_reports * 100, 2) . '%';
     // Category tree view
     $this->template->content->category_tree_view = category::get_category_tree_view();
     // Additional view content
     $this->template->content->custom_forms_filter = new View('reports/submit_custom_forms');
     $this->template->content->custom_forms_filter->disp_custom_fields = customforms::get_custom_form_fields();
     $this->template->content->custom_forms_filter->search_form = TRUE;
     $this->template->content->oldest_timestamp = $oldest_timestamp;
     $this->template->content->latest_timestamp = $latest_timestamp;
     $this->template->content->report_stats->total_reports = $total_reports;
     $this->template->content->report_stats->avg_reports_per_day = $avg_reports_per_day;
     $this->template->content->report_stats->percent_verified = $percent_verified;
     $this->template->content->services = Service_Model::get_array();
 }