Esempio n. 1
0
 function index()
 {
     $this->template->content = new View('admin/dashboard');
     $this->template->content->title = Kohana::lang('ui_admin.dashboard');
     $this->template->this_page = 'dashboard';
     // Retrieve Dashboard Count...
     // Total Reports
     $this->template->content->reports_total = ORM::factory('incident')->count_all();
     // Total Unapproved Reports
     $this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->count_all();
     // Total Unverified Reports
     $this->template->content->reports_unverified = ORM::factory('incident')->where('incident_verified', '0')->count_all();
     // Total Categories
     $this->template->content->categories = ORM::factory('category')->count_all();
     // Total Locations
     $this->template->content->locations = ORM::factory('location')->count_all();
     // Total Incoming Media
     $this->template->content->incoming_media = ORM::factory('feed_item')->count_all();
     // Messages By Service
     $total_message_count = 0;
     $message_services = array();
     $services = ORM::factory('service')->find_all();
     foreach ($services as $service) {
         $message_count = ORM::factory('message')->join('reporter', 'message.reporter_id', 'reporter.id')->where('service_id', $service->id)->where('message_type', '1')->count_all();
         $message_services[] = array('id' => $service->id, 'name' => $service->service_name, 'count' => $message_count);
         $total_message_count += $message_count;
     }
     $this->template->content->message_services = $message_services;
     // Total Messages
     $this->template->content->message_count = $total_message_count;
     // Get reports for display
     $incidents = ORM::factory('incident')->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
     $this->template->content->incidents = $incidents;
     // Get Incoming Media (We'll Use NewsFeeds for now)
     $this->template->content->feeds = ORM::factory('feed_item')->limit('3')->orderby('item_date', 'desc')->find_all();
     /*
     // Javascript Header
     $this->template->flot_enabled = TRUE;
     $this->template->js = new View('admin/dashboard_js');
     // Graph
     $this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all');
     $this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
     */
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     $this->template->js = new View('admin/stats_js');
     $this->template->content->failure = '';
     // Build dashboard chart
     // Set the date range (how many days in the past from today?)
     //    default to one year
     $range = isset($_GET['range']) ? $_GET['range'] : 365;
     if (isset($_GET['range']) and $_GET['range'] == 0) {
         $range = NULL;
     }
     $this->template->content->range = $range;
     $incident_data = Incident_Model::get_number_reports_by_date($range);
     $data = array('Reports' => $incident_data);
     $options = array('xaxis' => array('mode' => '"time"'));
     $this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310);
 }
Esempio n. 2
0
 function index()
 {
     $this->template->content = new View('members/dashboard');
     $this->template->content->title = Kohana::lang('ui_admin.dashboard');
     $this->template->this_page = 'dashboard';
     // User
     $this->template->content->user = $this->user;
     // User Reputation Score
     $this->template->content->reputation = reputation::calculate($this->user->id);
     // Get Badges
     $this->template->content->badges = Badge_Model::users_badges($this->user->id);
     // Retrieve Dashboard Counts...
     // Total Reports
     $this->template->content->reports_total = ORM::factory('incident')->where("user_id", $this->user->id)->count_all();
     // Total Unapproved Reports
     $this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->where("user_id", $this->user->id)->count_all();
     // Total Checkins
     $this->template->content->checkins = ORM::factory('checkin')->where("user_id", $this->user->id)->count_all();
     // Total Alerts
     $this->template->content->alerts = ORM::factory('alert')->where("user_id", $this->user->id)->count_all();
     // Total Votes
     $this->template->content->votes = ORM::factory('rating')->where("user_id", $this->user->id)->count_all();
     // Total Votes Positive
     $this->template->content->votes_up = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "1")->count_all();
     // Total Votes Negative
     $this->template->content->votes_down = ORM::factory('rating')->where("user_id", $this->user->id)->where("rating", "-1")->count_all();
     // Get reports for display
     $this->template->content->incidents = ORM::factory('incident')->where("user_id", $this->user->id)->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
     // To support the "welcome" or "not enough info on user" form
     if ($this->user->public_profile == 1) {
         $this->template->content->profile_public = TRUE;
         $this->template->content->profile_private = FALSE;
     } else {
         $this->template->content->profile_public = FALSE;
         $this->template->content->profile_private = TRUE;
     }
     $this->template->content->hidden_welcome_fields = array('email' => $this->user->email, 'notify' => $this->user->notify, 'color' => $this->user->color, 'password' => '', 'needinfo' => 0);
     /*
     // Javascript Header
     $this->template->flot_enabled = TRUE;
     $this->template->js = new View('admin/dashboard_js');
     // Graph
     $this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all');
     $this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
     */
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     $this->template->js = new View('admin/stats_js');
     $this->template->content->failure = '';
     // Build dashboard chart
     // Set the date range (how many days in the past from today?)
     // Default to one year if invalid or not set
     $range = (isset($_GET['range']) and preg_match('/^\\d+$/', $_GET['range']) > 0) ? (int) $_GET['range'] : 365;
     // Phase 3 - Invoke Kohana's XSS cleaning mechanism just incase an outlier wasn't caught
     $range = $this->input->xss_clean($range);
     $incident_data = Incident_Model::get_number_reports_by_date($range, $this->user->id);
     $data = array('Reports' => $incident_data);
     $options = array('xaxis' => array('mode' => '"time"'));
     $this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310);
 }
Esempio n. 3
0
 /**
  * Displays all reports.
  */
 public function index()
 {
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports');
     // Filter By Category
     $category_filter = isset($_GET['c']) && !empty($_GET['c']) ? "category_id = " . $_GET['c'] : " 1=1 ";
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => ORM::factory('incident')->join('incident_category', 'incident.id', 'incident_category.incident_id')->where('incident_active', '1')->where($category_filter)->count_all()));
     $incidents = ORM::factory('incident')->select('DISTINCT incident.*')->join('incident_category', 'incident.id', 'incident_category.incident_id')->where('incident_active', '1')->where($category_filter)->groupby('incident.id')->orderby('incident_date', 'desc')->find_all((int) Kohana::config('settings.items_per_page'), $pagination->sql_offset);
     $this->template->content->incidents = $incidents;
     //Set default as not showing pagination. Will change below if necessary.
     $this->template->content->pagination = '';
     // Pagination and Total Num of Report Stats
     if ($pagination->total_items == 1) {
         $plural = '';
     } else {
         $plural = 's';
     }
     if ($pagination->total_items > 0) {
         $current_page = $pagination->sql_offset / (int) Kohana::config('settings.items_per_page') + 1;
         $total_pages = ceil($pagination->total_items / (int) Kohana::config('settings.items_per_page'));
         if ($total_pages > 1) {
             // If we want to show pagination
             $this->template->content->pagination_stats = '(Showing ' . $current_page . ' of ' . $total_pages . ' pages of ' . $pagination->total_items . ' report' . $plural . ')';
             $this->template->content->pagination = $pagination;
         } else {
             // If we don't want to show pagination
             $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')';
         }
     } else {
         $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')';
     }
     $icon_html = array();
     $icon_html[1] = "<img src=\"" . url::base() . "media/img/image.png\">";
     //image
     $icon_html[2] = "<img src=\"" . url::base() . "media/img/video.png\">";
     //video
     $icon_html[3] = "";
     //audio
     $icon_html[4] = "";
     //news
     $icon_html[5] = "";
     //podcast
     //Populate media icon array
     $this->template->content->media_icons = array();
     foreach ($incidents as $incident) {
         $incident_id = $incident->id;
         if (ORM::factory('media')->where('incident_id', $incident_id)->count_all() > 0) {
             $medias = ORM::factory('media')->where('incident_id', $incident_id)->find_all();
             //Modifying a tmp var prevents Kohona from throwing an error
             $tmp = $this->template->content->media_icons;
             $tmp[$incident_id] = '';
             foreach ($medias as $media) {
                 $tmp[$incident_id] .= $icon_html[$media->media_type];
                 $this->template->content->media_icons = $tmp;
             }
         }
     }
     // Category Title, if Category ID available
     $category_id = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'] : "0";
     $category = ORM::factory('category')->find($category_id);
     $this->template->content->category_title = $category->loaded ? $category->category_title : "";
     // BEGIN CHART CREATION
     //   Note: The reason this code block is so long is because protochart
     //         doesn't seem to handle bar charts in time mode so well. The
     //         bars show up as skinny lines because it uses the timestamp
     //         to determine location on the graph, which doesn't give the
     //         bar much wiggle room in just a few hundred pixels.
     // Create protochart
     $this->template->header->protochart_enabled = TRUE;
     $report_chart = new protochart();
     // FIXME: Perhaps instead of grabbing the report stats again, we can
     //        get what we need from above so we can cut down on database
     //        calls. It will take playing with the incident model to get
     //        all of the data we need, though.
     // Report Data
     $data = Stats_Model::get_report_stats(true);
     // Grab category data
     $cats = Category_Model::categories();
     $highest_count = 1;
     $report_data = array();
     $tick_string_array = array();
     foreach ($data['category_counts'] as $category_id => $count_array) {
         // Does this category exist locally any more?
         if (isset($cats[$category_id])) {
             $category_name = $cats[$category_id]['category_title'];
             $colors[$category_name] = $cats[$category_id]['category_color'];
             $i = 1;
             foreach ($count_array as $time => $count) {
                 $report_data[$category_name][$i] = $count;
                 // The highest count will determine the number of ticks on the y-axis
                 if ($count > $highest_count) {
                     $highest_count = $count;
                 }
                 // This statement sets us up so we can convert the key to a date
                 if (!isset($tick_represents[$i])) {
                     $tick_represents[$i] = $time;
                     // Save name
                     $tick_string_array[$i] = date('M d', $time);
                 }
                 $i++;
             }
         }
     }
     $highest_count += 1;
     // This javascript function will take the integer index and convert it to a readable date
     $tickFormatter = "function (val, axis)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t    switch(val){";
     foreach ($tick_string_array as $i => $date_string) {
         $tickFormatter .= "case {$i}:\n\t\t\t\t\t\t    \t\treturn '{$date_string}';";
     }
     $tickFormatter .= "default:\n\t\t\t\t\t\t    \t\treturn '';\n\t\t\t\t\t\t    }\n\t\t\t\t\t\t    return 'sup';\n\t\t\t\t\t\t  }";
     $options = array('bars' => array('show' => 'true'), 'xaxis' => array('min' => 0, 'max' => count($tick_string_array) + 1, 'tickFormatter' => $tickFormatter), 'yaxis' => array('tickSize' => 1, 'max' => $highest_count, 'tickDecimals' => 0), 'legend' => array('show' => 'true', 'noColumns' => 3), 'grid' => array('drawXAxis' => 'false'));
     if (count($report_data) == 0) {
         // Don't show a chart if there's no data
         $this->template->content->report_chart = '';
     } else {
         // Show chart
         $width = 900;
         $height = 100;
         $this->template->content->report_chart = $report_chart->chart('reports', $report_data, $options, $colors, $width, $height);
     }
 }
Esempio n. 4
0
 public function hits()
 {
     $this->template->content = new View('admin/stats/hits');
     $this->template->content->title = Kohana::lang('ui_admin.statistics');
     // Javascript Header
     $this->themes->protochart_enabled = TRUE;
     $this->themes->js = new View('admin/stats/stats_js');
     $this->template->content->failure = '';
     // Set the date range (how many days in the past from today?)
     $range = isset($_GET['range']) ? $_GET['range'] : 30;
     $this->template->content->range = $range;
     // Get an arbitrary date range
     $dp1 = isset($_GET['dp1']) ? $_GET['dp1'] : null;
     $dp2 = isset($_GET['dp2']) ? $_GET['dp2'] : null;
     // Hit Data
     $data = Stats_Model::get_hit_stats($range, $dp1, $dp2);
     $this->template->content->uniques = 0;
     $this->template->content->visits = 0;
     $this->template->content->pageviews = 0;
     $this->template->content->active_tab = 'uniques';
     // Lazy tab switcher (not using javascript, just refreshing the page)
     if (isset($_GET['active_tab'])) {
         $this->template->content->active_tab = $_GET['active_tab'];
     }
     // If we failed to get hit data, fail.
     if (!$data) {
         $this->template->content->traffic_chart = Kohana::lang('ui_admin.chart_display_error');
         $this->template->content->raw_data = array();
         $this->template->content->dp1 = $dp1;
         $this->template->content->dp2 = $dp2;
         $this->template->content->failure = 'Stat Collection Failed! Either your stat_id or stat_key in the settings table in the database are incorrect or our stat server is down. Try back in a bit to see if the server is up and running. If you are really in a pinch, you can always modify stat_id (set to null) and stat_key (set to 0) in the settings table of your database to get your stats back up and running. Keep in mind you will lose access to your stats currently on the stats server.';
         return false;
     }
     $counts = array();
     foreach ($data as $label => $data_array) {
         if (!isset($this->template->content->{$label})) {
             $this->template->content->{$label} = 0;
         }
         foreach ($data_array as $timestamp => $count) {
             $this->template->content->{$label} += $count;
         }
     }
     $traffic_chart = new protochart();
     $options = array('xaxis' => array('mode' => '"time"'), 'legend' => array('show' => 'true'));
     $this->template->content->traffic_chart = $traffic_chart->chart('traffic', $data, $options, null, 884, 300);
     $this->template->content->raw_data = $data;
     // Set the date
     reset($data['visits']);
     $this->template->content->dp1 = date('Y-m-d', key($data['visits']) / 1000);
     end($data['visits']);
     $this->template->content->dp2 = date('Y-m-d', key($data['visits']) / 1000);
 }
Esempio n. 5
0
 function index()
 {
     $this->template->content = new View('admin/dashboard');
     $this->template->content->title = 'Dashboard';
     $this->template->this_page = 'dashboard';
     // Retrieve Dashboard Count...
     // Total Reports
     $this->template->content->reports_total = ORM::factory('incident')->count_all();
     // Total Unapproved Reports
     $this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->count_all();
     // Total Unverified Reports
     $this->template->content->reports_unverified = ORM::factory('incident')->where('incident_verified', '0')->count_all();
     // Total Categories
     $this->template->content->categories = ORM::factory('category')->count_all();
     // Total Locations
     $this->template->content->locations = ORM::factory('location')->count_all();
     // Total Incoming Media
     $this->template->content->incoming_media = ORM::factory('feed_item')->count_all();
     // Messages By Service
     $total_message_count = 0;
     $message_services = array();
     $services = ORM::factory('service')->find_all();
     foreach ($services as $service) {
         $message_count = ORM::factory('message')->join('reporter', 'message.reporter_id', 'reporter.id')->where('service_id', $service->id)->where('message_type', '1')->count_all();
         $message_services[] = array('id' => $service->id, 'name' => $service->service_name, 'count' => $message_count);
         $total_message_count += $message_count;
     }
     $this->template->content->message_services = $message_services;
     // Total Messages
     $this->template->content->message_count = $total_message_count;
     // Get reports for display
     $incidents = ORM::factory('incident')->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
     $this->template->content->incidents = $incidents;
     // Get Incoming Media (We'll Use NewsFeeds for now)
     $this->template->content->feeds = ORM::factory('feed_item')->limit('3')->orderby('item_date', 'desc')->find_all();
     /*
     // Javascript Header
     $this->template->flot_enabled = TRUE;
     $this->template->js = new View('admin/dashboard_js');
     // Graph
     $this->template->js->all_graphs = Incident_Model::get_incidents_by_interval('ALL',NULL,NULL,'all');
     $this->template->js->current_date = date('Y') . '/' . date('m') . '/01';
     */
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     $this->template->js = new View('admin/stats_js');
     // Set the date range (how many days in the past from today?)
     //    default to one year
     $range = 365;
     if (isset($_GET['range'])) {
         $range = $_GET['range'];
     }
     $this->template->content->range = $range;
     // Report Data
     $data = Stats_Model::get_report_stats(false, true, $range, null, null, true);
     $this->template->content->failure = '';
     // If we failed to get hit data, fail.
     if (!$data) {
         $now = time() * 1000;
         $data['all'][$now] = 0;
         /*
         $this->template->content->report_chart = '';
         $this->template->content->failure = 'No report data for chart.';
         return false;
         */
     }
     $report_chart = new protochart();
     $options = array('xaxis' => array('mode' => '"time"'), 'legend' => array('show' => 'true'));
     $pass_data['Reports'] = $data['all'];
     $this->template->content->report_chart = $report_chart->chart('report_chart', $pass_data, $options, array('Reports' => 'CC0000'), 410, 310);
 }
Esempio n. 6
0
 function hits()
 {
     $this->template->content = new View('admin/stats_hits');
     $this->template->content->title = 'Hit Summary';
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     // Hit Data
     $data = Stats_Model::get_hit_stats();
     $traffic_chart = new protochart();
     $options = array('xaxis' => array('mode' => '"time"'), 'legend' => array('show' => 'true'));
     $this->template->content->traffic_chart = $traffic_chart->chart('traffic', $data, $options);
     $this->template->content->raw_data = $data;
 }
Esempio n. 7
0
 public function index()
 {
     $this->template->content = new View('admin/dashboard');
     $this->template->content->title = Kohana::lang('ui_admin.dashboard');
     $this->template->this_page = 'dashboard';
     // Retrieve Dashboard Count...
     // Total Reports
     $this->template->content->reports_total = ORM::factory('incident')->count_all();
     // Total Unapproved Reports
     $this->template->content->reports_unapproved = ORM::factory('incident')->where('incident_active', '0')->count_all();
     // Total Unverified Reports
     $this->template->content->reports_unverified = ORM::factory('incident')->where('incident_verified', '0')->count_all();
     // Total Categories
     $this->template->content->categories = ORM::factory('category')->count_all();
     // Total Locations
     $this->template->content->locations = ORM::factory('location')->count_all();
     // Total Incoming Media
     $this->template->content->incoming_media = ORM::factory('feed_item')->count_all();
     // Messages By Service
     $total_message_count = 0;
     $message_services = array();
     $services = ORM::factory('service')->find_all();
     foreach ($services as $service) {
         $message_count = ORM::factory('message')->join('reporter', 'message.reporter_id', 'reporter.id')->where('service_id', $service->id)->where('message_type', '1')->count_all();
         $message_services[] = array('id' => $service->id, 'name' => $service->service_name, 'count' => $message_count);
         $total_message_count += $message_count;
     }
     $this->template->content->message_services = $message_services;
     // Total Messages
     $this->template->content->message_count = $total_message_count;
     // Get reports for display
     $incidents = ORM::factory('incident')->limit(5)->orderby('incident_dateadd', 'desc')->find_all();
     $this->template->content->incidents = $incidents;
     // Get Incoming Media (We'll Use NewsFeeds for now)
     $this->template->content->feeds = ORM::factory('feed_item')->limit('3')->orderby('item_date', 'desc')->find_all();
     // Javascript Header
     $this->template->protochart_enabled = TRUE;
     $this->template->js = new View('admin/stats_js');
     $this->template->content->failure = '';
     // Build dashboard chart
     // Set the date range (how many days in the past from today?)
     // Default to one year if invalid or not set
     $range = 0;
     if (isset($_GET['range'])) {
         // Sanitize the range parameter
         $range = $this->input->xss_clean($_GET['range']);
         $range = intval($range) > 0 ? intval($range) : 0;
     }
     $incident_data = Incident_Model::get_number_reports_by_date($range);
     $data = array('Reports' => $incident_data);
     $options = array('xaxis' => array('mode' => '"time"'));
     $this->template->content->report_chart = protochart::chart('report_chart', $data, $options, array('Reports' => 'CC0000'), 410, 310);
     // Render version sync checks if enabled
     $this->template->content->version_sync = NULL;
     if (Kohana::config('config.enable_ver_sync_warning') == TRUE) {
         $this->template->content->version_sync = View::factory('admin/version_sync');
     }
     // Render security checks if enabled
     $this->template->content->security_info = NULL;
     if (Kohana::config('config.enable_security_info') == TRUE) {
         $this->template->content->security_info = View::factory('admin/security_info');
     }
 }
Esempio n. 8
0
 /**
  * Displays all reports.
  */
 public function index()
 {
     $db = new Database();
     $this->template->header->this_page = 'reports';
     $this->template->content = new View('reports');
     $filter = isset($_GET['c']) && !empty($_GET['c']) && $_GET['c'] != 0 ? " AND ( category.id='" . $_GET['c'] . "' OR \n\t\t\t\tcategory.parent_id='" . $_GET['c'] . "' )  " : " AND 1 = 1";
     if (isset($_GET['sw']) && !empty($_GET['sw']) && count($southwest = explode(",", $_GET['sw'])) > 1 && isset($_GET['ne']) && !empty($_GET['ne']) && count($northeast = explode(",", $_GET['ne'])) > 1) {
         list($longitude_min, $latitude_min) = $southwest;
         list($longitude_max, $latitude_max) = $northeast;
         $filter .= " AND location.latitude >=" . $latitude_min . " AND location.latitude <=" . $latitude_max;
         $filter .= " AND location.longitude >=" . $longitude_min . " AND location.longitude <=" . $longitude_max;
     }
     // Pagination
     $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => (int) Kohana::config('settings.items_per_page'), 'total_items' => $db->query("SELECT DISTINCT `incident`.* FROM `incident` JOIN `incident_category` ON (`incident`.`id` = `incident_category`.`incident_id`) JOIN `category` ON (`category`.`id` = `incident_category`.`category_id`) JOIN `location` ON (`incident`.`location_id` = `location`.`id`) WHERE `incident_active` = '1' {$filter}")->count()));
     $incidents = $db->query("SELECT DISTINCT `incident`.*, `location`.`location_name` FROM `incident` JOIN `incident_category` ON (`incident`.`id` = `incident_category`.`incident_id`) JOIN `category` ON (`category`.`id` = `incident_category`.`category_id`) JOIN `location` ON (`incident`.`location_id` = `location`.`id`) WHERE `incident_active` = '1' {$filter} ORDER BY incident_date DESC LIMIT " . (int) Kohana::config('settings.items_per_page') . " OFFSET " . $pagination->sql_offset);
     $this->template->content->incidents = $incidents;
     //Set default as not showing pagination. Will change below if necessary.
     $this->template->content->pagination = '';
     // Pagination and Total Num of Report Stats
     if ($pagination->total_items == 1) {
         $plural = '';
     } else {
         $plural = 's';
     }
     if ($pagination->total_items > 0) {
         $current_page = $pagination->sql_offset / (int) Kohana::config('settings.items_per_page') + 1;
         $total_pages = ceil($pagination->total_items / (int) Kohana::config('settings.items_per_page'));
         if ($total_pages > 1) {
             // If we want to show pagination
             $this->template->content->pagination_stats = '(Showing ' . $current_page . ' of ' . $total_pages . ' pages of ' . $pagination->total_items . ' report' . $plural . ')';
             $this->template->content->pagination = $pagination;
         } else {
             // If we don't want to show pagination
             $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')';
         }
     } else {
         $this->template->content->pagination_stats = '(' . $pagination->total_items . ' report' . $plural . ')';
     }
     //Declare icon_type array
     $icon_type = array();
     $icon_type[1] = "image";
     //image
     $icon_type[2] = "video";
     //video
     $icon_type[3] = "audio";
     //audio
     $icon_type[4] = "news";
     //news
     $icon_type[5] = "podcast";
     //podcast
     // Declare incident mode array
     $incident_mode = array();
     $incident_mode[1] = "Web";
     //Web
     $incident_mode[2] = "Sms";
     //Sms
     $incident_mode[3] = "Email";
     //Email
     $incident_mode[4] = "Twitter";
     //Twitter
     //Populate media icon array
     $this->template->content->media_icons = array();
     $this->template->content->incident_mode = array();
     foreach ($incidents as $incident) {
         $incident_id = $incident->id;
         //Set the incident mode to SMS if it contians a custom phone.
         if ($incident->incident_custom_phone !== '') {
             $this->template->content->incident_mode[$incident->id] = $incident_mode[2];
         } else {
             $this->template->content->incident_mode[$incident->id] = $incident_mode[$incident->incident_mode];
         }
         if (ORM::factory('media')->where('incident_id', $incident_id)->count_all() > 0) {
             $medias = ORM::factory('media')->where('incident_id', $incident_id)->find_all();
             //Modifying a tmp var prevents Kohona from throwing an error
             $tmp = $this->template->content->media_icons;
             $tmp[$incident_id] = '';
             //Build the media_icons array also adding anchor to link to media_link
             //If the media type is an image. Append the /media/uploads/ path.
             foreach ($medias as $media) {
                 $tmp[$incident_id] .= "<li class='" . $icon_type[$media->media_type] . "'>\n\t\t\t\t\t<a href='" . ($icon_type[$media->media_type] === 'image' ? '/media/uploads/' : '') . $media->media_link . "' title='" . $icon_type[$media->media_type] . "' target='_blank'></a>\n\t\t\t\t\t</li>";
                 $this->template->content->media_icons = $tmp;
             }
         }
     }
     // Category Title, if Category ID available
     $category_id = isset($_GET['c']) && !empty($_GET['c']) ? $_GET['c'] : "0";
     $category = ORM::factory('category')->find($category_id);
     $this->template->content->category_title = $category->loaded ? $category->category_title : "";
     // BEGIN CHART CREATION
     //   Note: The reason this code block is so long is because protochart
     //         doesn't seem to handle bar charts in time mode so well. The
     //         bars show up as skinny lines because it uses the timestamp
     //         to determine location on the graph, which doesn't give the
     //         bar much wiggle room in just a few hundred pixels.
     // Create protochart
     $this->template->header->protochart_enabled = TRUE;
     $report_chart = new protochart();
     // FIXME: Perhaps instead of grabbing the report stats again, we can
     //        get what we need from above so we can cut down on database
     //        calls. It will take playing with the incident model to get
     //        all of the data we need, though.
     // Report Data
     $data = Stats_Model::get_report_stats(true);
     // Grab category data
     $cats = Category_Model::categories();
     $highest_count = 1;
     $report_data = array();
     $tick_string_array = array();
     foreach ($data['category_counts'] as $category_id => $count_array) {
         // Does this category exist locally any more?
         if (isset($cats[$category_id])) {
             $category_name = $cats[$category_id]['category_title'];
             $colors[$category_name] = $cats[$category_id]['category_color'];
             $i = 1;
             foreach ($count_array as $time => $count) {
                 $report_data[$category_name][$i] = $count;
                 // The highest count will determine the number of ticks on the y-axis
                 if ($count > $highest_count) {
                     $highest_count = $count;
                 }
                 // This statement sets us up so we can convert the key to a date
                 if (!isset($tick_represents[$i])) {
                     $tick_represents[$i] = $time;
                     // Save name
                     $tick_string_array[$i] = date('M d', $time);
                 }
                 $i++;
             }
         }
     }
     $highest_count += 1;
     // This javascript function will take the integer index and convert it to a readable date
     $tickFormatter = "function (val, axis)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t    switch(val){";
     foreach ($tick_string_array as $i => $date_string) {
         $tickFormatter .= "case {$i}:\n\t\t\t\t\t\t    \t\treturn '{$date_string}';";
     }
     $tickFormatter .= "default:\n\t\t\t\t\t\t    \t\treturn '';\n\t\t\t\t\t\t    }\n\t\t\t\t\t\t    return 'sup';\n\t\t\t\t\t\t  }";
     $options = array('bars' => array('show' => 'true'), 'xaxis' => array('min' => 0, 'max' => count($tick_string_array) + 1, 'tickFormatter' => $tickFormatter), 'yaxis' => array('tickSize' => 1, 'max' => $highest_count, 'tickDecimals' => 0), 'legend' => array('show' => 'true', 'noColumns' => 3), 'grid' => array('drawXAxis' => 'false'));
     if (count($report_data) == 0) {
         // Don't show a chart if there's no data
         $this->template->content->report_chart = '';
     } else {
         // Show chart
         $width = 900;
         $height = 100;
         $this->template->content->report_chart = $report_chart->chart('reports', $report_data, $options, $colors, $width, $height);
     }
 }