Example #1
0
 function __construct()
 {
     parent::__construct();
     $session = Session::instance();
     // Load Header & Footer
     $this->template->header = new View('mhi/mhi_header');
     $this->template->footer = new View('mhi/mhi_footer');
     $this->template->footer->ushahidi_stats = Stats_Model::get_javascript();
     $this->template->header->site_name = Kohana::config('settings.site_name');
     // Initialize JS variables. js_files is an array of ex: html::script('media/js/jquery.validate.min');
     // Add the sign in box javascript
     $this->template->header->js = new View('mhi/mhi_js_signin');
     $this->template->header->js_files = array();
     // Google Analytics
     $google_analytics = Kohana::config('settings.google_analytics');
     $this->template->footer->google_analytics = $this->_google_analytics($google_analytics);
     // If we aren't at the top level MHI site or MHI isn't enabled, don't allow access to any of this jazz
     /*
     if (Kohana::config('config.enable_mhi') == FALSE OR Kohana::config('settings.subdomain') != '')
     	throw new Kohana_User_Exception('MHI Access Error', "MHI disabled for this site.");
     */
     // Login Form variables
     $this->template->header->errors = '';
     $this->template->header->form = array('username' => '');
     $this->template->header->form_error = '';
     $this->template->header->mhi_user_id = $session->get('mhi_user_id');
 }
Example #2
0
	public function __construct()
	{
		parent::__construct();

        // Load cache
		$this->cache = new Cache;

		// Load Session
		$this->session = Session::instance();

        // Load Header & Footer
		$this->template->header  = new View('tasukeaijapan/header');
		$this->template->footer  = new View('tasukeaijapan/footer');

		// Themes Helper
		$this->themes = new TasukeaijapanThemes;
		$this->themes->api_url = Kohana::config('settings.api_url');

		// Set Table Prefix
		$this->table_prefix = Kohana::config('database.default.table_prefix');

		// Retrieve Default Settings
		$site_name = Kohana::config('settings.site_name');

		$this->template->header->site_name = $site_name;
		$this->template->footer->site_name = $site_name;

		$this->template->header->this_page = "";

		// Google Analytics
		$google_analytics = Kohana::config('settings.google_analytics');
		$this->template->footer->google_analytics = $this->themes->google_analytics($google_analytics);

        // Load profiler
        // $profiler = new Profiler;

		// Get tracking javascript for stats
		if(Kohana::config('settings.allow_stat_sharing') == 1){
			$this->template->footer->ushahidi_stats = Stats_Model::get_javascript();
		}else{
			$this->template->footer->ushahidi_stats = '';
		}
		
		// add copyright info
		$this->template->footer->site_copyright_statement = '';
		$site_copyright_statement = trim(Kohana::config('settings.site_copyright_statement'));
		if($site_copyright_statement != '')
		{
			$this->template->footer->site_copyright_statement = $site_copyright_statement;
		}
		
	}
Example #3
0
 public function __construct()
 {
     parent::__construct();
     // Load cache
     $this->cache = new Cache();
     // Load Session
     $this->session = Session::instance();
     // Load Header & Footer
     $this->template->header = new View('empty_header');
     $this->template->footer = new View('empty_footer');
     // Themes Helper
     $this->themes = new Themes();
     $this->themes->api_url = Kohana::config('settings.api_url');
     $this->template->header->submit_btn = $this->themes->submit_btn();
     $this->template->header->languages = $this->themes->languages();
     $this->template->header->search = $this->themes->search();
     // Set Table Prefix
     $this->table_prefix = Kohana::config('database.default.table_prefix');
     // Retrieve Default Settings
     $site_name = Kohana::config('settings.site_name');
     // Prevent Site Name From Breaking up if its too long
     // by reducing the size of the font
     if (strlen($site_name) > 20) {
         $site_name_style = " style=\"font-size:21px;\"";
     } else {
         $site_name_style = "";
     }
     $this->template->header->site_name = $site_name;
     $this->template->header->site_name_style = $site_name_style;
     $this->template->header->site_tagline = Kohana::config('settings.site_tagline');
     // Display Contact Tab?
     $this->template->header->site_contact_page = Kohana::config('settings.site_contact_page');
     // Display Help Tab?
     $this->template->header->site_help_page = Kohana::config('settings.site_help_page');
     // Get Custom Pages
     $this->template->header->pages = ORM::factory('page')->where('page_active', '1')->find_all();
     $this->template->header->this_page = "";
     // Google Analytics
     $google_analytics = Kohana::config('settings.google_analytics');
     $this->template->footer->google_analytics = $this->themes->google_analytics($google_analytics);
     // Load profiler
     // $profiler = new Profiler;
     // Get tracking javascript for stats
     if (Kohana::config('settings.allow_stat_sharing') == 1) {
         $this->template->footer->ushahidi_stats = Stats_Model::get_javascript();
     } else {
         $this->template->footer->ushahidi_stats = '';
     }
 }
Example #4
0
 function country()
 {
     $this->template->content = new View('admin/stats/country');
     $this->template->content->title = Kohana::lang('ui_admin.statistics');
     // Javascript Header
     $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;
     $countries = Stats_Model::get_hit_countries($range, $dp1, $dp2);
     // If we failed to get country data, fail.
     if (!$countries) {
         $this->template->content->countries = array();
         $this->template->content->num_countries = 0;
         $this->template->content->dp1 = $dp1;
         $this->template->content->dp2 = $dp2;
         $this->template->content->visitor_map = '';
         $this->template->content->uniques = 0;
         $this->template->content->visits = 0;
         $this->template->content->pageviews = 0;
         $this->template->content->active_tab = 'uniques';
         $this->template->content->failure = Kohana::lang('ui_admin.stats_collection_error_short');
         return false;
     }
     //Set up country map and totals
     $country_total = array();
     $countries_reformatted = array();
     foreach ($countries as $country) {
         foreach ($country as $code => $arr) {
             if (!isset($country_total[$code])) {
                 $country_total[$code] = 0;
             }
             $country_total[$code] += $arr['uniques'];
             $name = $arr['label'];
             if (!isset($countries_reformatted[$name])) {
                 $countries_reformatted[$name] = array();
             }
             if (!isset($countries_reformatted[$name]['count'])) {
                 $countries_reformatted[$name]['count'] = 0;
             }
             $countries_reformatted[$name]['count'] += $arr['uniques'];
             $countries_reformatted[$name]['icon'] = $arr['logo'];
         }
     }
     arsort($countries_reformatted);
     $this->template->content->countries = $countries_reformatted;
     $this->template->content->num_countries = count($countries_reformatted);
     arsort($country_total);
     $codes = '';
     $values = '';
     $i = 0;
     foreach ($country_total as $code => $uniques) {
         if ($i == 0) {
             $highest = $uniques;
         }
         if ($i != 0) {
             $values .= ',';
         }
         $values .= $uniques / $highest * 100;
         $codes .= strtoupper($code);
         $i++;
     }
     $this->template->content->visitor_map = Kohana::config('core.site_protocol') . "://chart.googleapis.com/chart?chs=440x220&chf=bg,s,ffffff&cht=t&chtm=world&chco=cccccc,A07B7B,a20000&chld=" . $codes . "&chd=t:" . $values;
     // 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)
     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->dp1 = $dp1;
         $this->template->content->dp2 = $dp2;
         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;
         }
     }
     // 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);
 }
Example #5
0
 public function ushahidi_stats_js()
 {
     if (Kohana::config('settings.allow_stat_sharing') == 1) {
         return Stats_Model::get_javascript();
     }
     return '';
 }
Example #6
0
 /**
  * Creates a new site in centralized stat tracker
  * @param sitename - name of the instance
  * @param url - base url
  */
 public function create_site($sitename, $url)
 {
     $stat_url = 'https://tracker.ushahidi.com/px.php?task=cs&sitename=' . urlencode($sitename) . '&url=' . urlencode($url);
     // Ignore errors since we are error checking later
     $xml = simplexml_load_string(Stats_Model::_curl_req($stat_url));
     $stat_id = (string) $xml->id[0];
     $stat_key = (string) $xml->key[0];
     if ($stat_id > 0) {
         $settings = ORM::factory('settings', 1);
         $settings->stat_id = $stat_id;
         $settings->stat_key = $stat_key;
         $settings->save();
         return $stat_id;
     }
     return false;
 }
Example #7
0
 /**
  * Creates a new site in centralized stat tracker
  * @param sitename - name of the instance
  * @param url - base url
  */
 public function create_site($sitename, $url)
 {
     $stat_url = Kohana::config('config.external_site_protocol') . '://tracker.ushahidi.com/px.php?task=cs&sitename=' . urlencode($sitename) . '&url=' . urlencode($url);
     // Ignore errors since we are error checking later
     $xml = simplexml_load_string(Stats_Model::_curl_req($stat_url));
     if ($xml == false) {
         return false;
     }
     $stat_id = (string) $xml->id[0];
     $stat_key = (string) $xml->key[0];
     if ($stat_id > 0) {
         Settings_Model::save_setting('stat_id', $stat_id);
         Settings_Model::save_setting('stat_key', $stat_key);
         return $stat_id;
     }
     return false;
 }
Example #8
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);
 }
Example #9
0
 /**
  * Function: __construct
  *
  * Description: A default constructor that sets instance variables.
  *
  * Views:enhancedmap/print_map_header, enhancedmap/big_map_footer
  *
  * Results: Instance variables are set
  */
 public function __construct()
 {
     parent::__construct();
     // Load cache
     $this->cache = new Cache();
     // Load Session
     $this->session = Session::instance();
     $this->themes->map_enabled = TRUE;
     $this->themes->slider_enabled = TRUE;
     // Load Header & Footer
     $this->template->header = new View('enhancedmap/print_map_header');
     $this->template->footer = new View('enhancedmap/big_map_footer');
     // Set Table Prefix
     $this->table_prefix = Kohana::config('database.default.table_prefix');
     // Retrieve Default Settings
     $site_name = Kohana::config('settings.site_name');
     // Prevent Site Name From Breaking up if its too long
     // by reducing the size of the font
     if (strlen($site_name) > 20) {
         $site_name_style = " style=\"font-size:21px;\"";
     } else {
         $site_name_style = "";
     }
     $this->site_name = $site_name;
     $this->template->header->site_name = $site_name;
     $this->template->header->site_name_style = $site_name_style;
     $this->template->header->site_tagline = Kohana::config('settings.site_tagline');
     $this->template->header->this_page = "";
     // Google Analytics
     $google_analytics = Kohana::config('settings.google_analytics');
     $this->template->footer->google_analytics = $this->themes->google_analytics($google_analytics);
     // Load profiler
     // $profiler = new Profiler;
     // Get tracking javascript for stats
     if (Kohana::config('settings.allow_stat_sharing') == 1) {
         $this->template->footer->ushahidi_stats = Stats_Model::get_javascript();
     } else {
         $this->template->footer->ushahidi_stats = '';
     }
     $this->template->footer->footer_block = $this->themes->footer_block();
 }
Example #10
0
 public function __construct()
 {
     parent::__construct();
     $this->auth = new Auth();
     $this->auth->auto_login();
     // Load Session
     $this->session = Session::instance();
     if (Kohana::config('settings.private_deployment')) {
         if (!$this->auth->logged_in('login')) {
             url::redirect('login/front');
         }
     }
     // Load cache
     $this->cache = new Cache();
     // Load Header & Footer
     $this->template->header = new View('header');
     $this->template->footer = new View('footer');
     // Themes Helper
     $this->themes = new Themes();
     $this->themes->api_url = Kohana::config('settings.api_url');
     $this->template->header->submit_btn = $this->themes->submit_btn();
     $this->template->header->languages = $this->themes->languages();
     $this->template->header->search = $this->themes->search();
     // Set Table Prefix
     $this->table_prefix = Kohana::config('database.default.table_prefix');
     // Retrieve Default Settings
     $site_name = Kohana::config('settings.site_name');
     // Get banner image and pass to the header
     if (Kohana::config('settings.site_banner_id') != NULL) {
         $banner = ORM::factory('media')->find(Kohana::config('settings.site_banner_id'));
         $this->template->header->banner = url::convert_uploaded_to_abs($banner->media_link);
     } else {
         $this->template->header->banner = NULL;
     }
     // Prevent Site Name From Breaking up if its too long
     // by reducing the size of the font
     $site_name_style = strlen($site_name) > 20 ? " style=\"font-size:21px;\"" : "";
     $this->template->header->private_deployment = Kohana::config('settings.private_deployment');
     $this->template->header->loggedin_username = FALSE;
     $this->template->header->loggedin_userid = FALSE;
     if (isset(Auth::instance()->get_user()->username) and isset(Auth::instance()->get_user()->id)) {
         // Load User
         $this->user = Auth::instance()->get_user();
         $this->template->header->loggedin_username = html::specialchars(Auth::instance()->get_user()->username);
         $this->template->header->loggedin_userid = Auth::instance()->get_user()->id;
         $this->template->header->loggedin_role = Auth::instance()->logged_in('member') ? "members" : "admin";
     }
     $this->template->header->site_name = $site_name;
     $this->template->header->site_name_style = $site_name_style;
     $this->template->header->site_tagline = Kohana::config('settings.site_tagline');
     //pass the URI to the header so we can dynamically add css classes to the "body" tag
     $this->template->header->uri_segments = Router::$segments;
     $this->template->header->this_page = "";
     // Google Analytics
     $google_analytics = Kohana::config('settings.google_analytics');
     $this->template->footer->google_analytics = $this->themes->google_analytics($google_analytics);
     // Load profiler
     // $profiler = new Profiler;
     // Get tracking javascript for stats
     $this->template->footer->ushahidi_stats = Kohana::config('settings.allow_stat_sharing') == 1 ? Stats_Model::get_javascript() : '';
     // Enable CDN gradual upgrader
     $this->template->footer->cdn_gradual_upgrade = Kohana::config('cdn.cdn_gradual_upgrade') != false ? cdn::cdn_gradual_upgrade_js() : '';
     // add copyright info
     $this->template->footer->site_copyright_statement = '';
     $site_copyright_statement = trim(Kohana::config('settings.site_copyright_statement'));
     if ($site_copyright_statement != '') {
         $this->template->footer->site_copyright_statement = $site_copyright_statement;
     }
     // Display news feeds?
     $this->template->header->allow_feed = Kohana::config('settings.allow_feed');
 }
Example #11
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);
     }
 }
Example #12
0
 public static function populate_db($db_name, $user, $settings)
 {
     $mhi_db = Kohana::config('database.default');
     $table_prefix = $mhi_db['table_prefix'];
     $mhi_db_name = $mhi_db['connection']['database'];
     // Switch to new DB for a moment
     mysql_query('USE ' . $db_name);
     $db_schema = file_get_contents('sql/ushahidi.sql');
     // If a table prefix is specified, add it to sql
     if ($table_prefix) {
         $find = array('CREATE TABLE IF NOT EXISTS `', 'INSERT INTO `', 'ALTER TABLE `', 'UPDATE `');
         $replace = array('CREATE TABLE IF NOT EXISTS `' . $table_prefix . '_', 'INSERT INTO `' . $table_prefix . '_', 'ALTER TABLE `' . $table_prefix . '_', 'UPDATE `' . $table_prefix . '_');
         $db_schema = str_replace($find, $replace, $db_schema);
     }
     // Split by ; to get the sql statement for creating individual tables.
     $tables = explode(';', $db_schema);
     foreach ($tables as $query) {
         $result = mysql_query($query);
     }
     // Set up admin user on new site
     $usr = ORM::factory('user', '1');
     $usr->username = $user['username'];
     $usr->name = $user['name'];
     $usr->password = $user['password'];
     $usr->email = $user['email'];
     $usr->save();
     // Save site settings (name, tagline, etc)
     $setgs = new Settings_Model(1);
     $setgs->site_name = $settings['site_name'];
     $setgs->site_tagline = $settings['site_tagline'];
     $setgs->api_google = Kohana::config('settings.api_google');
     $setgs->date_modify = date("Y-m-d H:i:s", time());
     $setgs->save();
     // Set up stats
     $domain = str_ireplace(array('http://', 'https://'), '', url::base());
     Stats_Model::create_site($settings['site_name'], 'http://' . $settings['site_domain'] . '.' . $domain);
     // Switch back to the appropriate DB
     mysql_query('USE ' . $mhi_db_name);
     return true;
 }
Example #13
0
 public function __construct()
 {
     parent::__construct();
     if (Kohana::config('settings.private_deployment')) {
         $this->auth = new Auth();
         $this->session = Session::instance();
         $this->auth->auto_login();
         if (!$this->auth->logged_in('login')) {
             url::redirect('login/front');
         }
     }
     // Load cache
     $this->cache = new Cache();
     // Load Session
     $this->session = Session::instance();
     // Load Header & Footer
     $this->template->header = new View('header');
     $this->template->footer = new View('footer');
     // Themes Helper
     $this->themes = new Themes();
     $this->themes->api_url = Kohana::config('settings.api_url');
     $this->template->header->submit_btn = $this->themes->submit_btn();
     $this->template->header->languages = $this->themes->languages();
     $this->template->header->search = $this->themes->search();
     // Set Table Prefix
     $this->table_prefix = Kohana::config('database.default.table_prefix');
     // Retrieve Default Settings
     $site_name = Kohana::config('settings.site_name');
     // Prevent Site Name From Breaking up if its too long
     // by reducing the size of the font
     if (strlen($site_name) > 20) {
         $site_name_style = " style=\"font-size:21px;\"";
     } else {
         $site_name_style = "";
     }
     $this->template->header->private_deployment = Kohana::config('settings.private_deployment');
     $this->template->header->loggedin_username = FALSE;
     $this->template->header->loggedin_userid = FALSE;
     if (isset(Auth::instance()->get_user()->username) and isset(Auth::instance()->get_user()->id)) {
         $this->template->header->loggedin_username = html::specialchars(Auth::instance()->get_user()->username);
         $this->template->header->loggedin_userid = Auth::instance()->get_user()->id;
     }
     $this->template->header->site_name = $site_name;
     $this->template->header->site_name_style = $site_name_style;
     $this->template->header->site_tagline = Kohana::config('settings.site_tagline');
     $this->template->header->this_page = "";
     // Google Analytics
     $google_analytics = Kohana::config('settings.google_analytics');
     $this->template->footer->google_analytics = $this->themes->google_analytics($google_analytics);
     // Load profiler
     // $profiler = new Profiler;
     // Get tracking javascript for stats
     if (Kohana::config('settings.allow_stat_sharing') == 1) {
         $this->template->footer->ushahidi_stats = Stats_Model::get_javascript();
     } else {
         $this->template->footer->ushahidi_stats = '';
     }
     // add copyright info
     $this->template->footer->site_copyright_statement = '';
     $site_copyright_statement = trim(Kohana::config('settings.site_copyright_statement'));
     if ($site_copyright_statement != '') {
         $this->template->footer->site_copyright_statement = $site_copyright_statement;
     }
 }
Example #14
0
 public function __construct()
 {
     parent::__construct();
     // Load cache
     $this->cache = new Cache();
     // Load Session
     $this->session = Session::instance();
     // Load Header & Footer
     $this->template->header = new View('header');
     $this->template->footer = new View('footer');
     // In case js doesn't get set in the construct, initialize it here
     $this->template->header->js = '';
     // Set Table Prefix
     $this->table_prefix = Kohana::config('database.default.table_prefix');
     // Retrieve Default Settings
     $site_name = Kohana::config('settings.site_name');
     // Prevent Site Name From Breaking up if its too long
     // by reducing the size of the font
     if (strlen($site_name) > 20) {
         $site_name_style = " style=\"font-size:21px;\"";
     } else {
         $site_name_style = "";
     }
     $this->template->header->site_name = $site_name;
     $this->template->header->site_name_style = $site_name_style;
     $this->template->header->site_tagline = Kohana::config('settings.site_tagline');
     $this->template->header->api_url = Kohana::config('settings.api_url');
     // Display Contact Tab?
     $this->template->header->site_contact_page = Kohana::config('settings.site_contact_page');
     // Display Help Tab?
     $this->template->header->site_help_page = Kohana::config('settings.site_help_page');
     // Get Custom Pages
     $this->template->header->pages = ORM::factory('page')->where('page_active', '1')->find_all();
     // Get custom CSS file from settings
     $this->template->header->site_style = Kohana::config('settings.site_style');
     // Javascript Header
     $this->template->header->map_enabled = FALSE;
     $this->template->header->validator_enabled = TRUE;
     $this->template->header->treeview_enabled = FALSE;
     $this->template->header->datepicker_enabled = FALSE;
     $this->template->header->photoslider_enabled = FALSE;
     $this->template->header->videoslider_enabled = FALSE;
     $this->template->header->protochart_enabled = FALSE;
     $this->template->header->main_page = FALSE;
     $this->template->header->this_page = "";
     // Google Analytics
     $google_analytics = Kohana::config('settings.google_analytics');
     $this->template->footer->google_analytics = $this->_google_analytics($google_analytics);
     // *** Locales/Languages ***
     // First Get Available Locales
     $locales = $this->cache->get('locales');
     // If we didn't find any languages, we need to look them up and set the cache
     if (!$locales) {
         $locales = locale::get_i18n();
         $this->cache->set('locales', $locales, array('locales'), 604800);
     }
     $this->template->header->locales_array = $locales;
     // Locale form submitted?
     if (isset($_GET['l']) && !empty($_GET['l'])) {
         $this->session->set('locale', $_GET['l']);
     }
     // Has a locale session been set?
     if ($this->session->get('locale', FALSE)) {
         // Change current locale
         Kohana::config_set('locale.language', $_SESSION['locale']);
     }
     $this->template->header->l = Kohana::config('locale.language');
     // Load profiler
     // $profiler = new Profiler;
     // Get tracking javascript for stats
     $this->template->footer->ushahidi_stats = Stats_Model::get_javascript();
 }
Example #15
0
 function country()
 {
     $this->template->content = new View('admin/stats_country');
     $this->template->content->title = 'Country Breakdown';
     $this->template->content->countries = Stats_Model::get_hit_countries();
     //Set up country map
     $country_total = array();
     foreach ($this->template->content->countries as $country) {
         foreach ($country as $code => $arr) {
             if (!isset($country_total[$code])) {
                 $country_total[$code] = 0;
             }
             $country_total[$code] += $arr['uniques'];
         }
     }
     arsort($country_total);
     $codes = '';
     $values = '';
     $i = 0;
     foreach ($country_total as $code => $uniques) {
         if ($i == 0) {
             $highest = $uniques;
         }
         if ($i != 0) {
             $values .= ',';
         }
         $values .= $uniques / $highest * 100;
         $codes .= strtoupper($code);
         $i++;
     }
     $this->template->content->visitor_map = "http://chart.apis.google.com/chart?chs=440x220&chf=bg,s,ffffff&cht=t&chtm=world&chco=cccccc,A07B7B,a20000&chld=" . $codes . "&chd=t:" . $values;
 }
Example #16
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);
     }
 }
Example #17
0
 public function indexAction()
 {
     foreach ($this->app->config['database']['redis'] as $serverId => $server) {
         if (!empty($server['stats']['enable'])) {
             $time = time();
             $db = Db::factory($server);
             $info = $db->info();
             $statsModel = new Stats_Model($server);
             $statsModel->addKey('memory', $info['used_memory'], $time);
             $statsModel->addKey('connections', $info['total_connections_received'], $time);
             $statsModel->addKey('commands', $info['total_commands_processed'], $time);
             $statsModel->addKey('expired_keys', $info['expired_keys'], $time);
             $statsModel->addKey('hits', $info['keyspace_hits'], $time);
             $statsModel->addKey('misses', $info['keyspace_misses'], $time);
             $statsModel->addKey('clients', $info['connected_clients'], $time);
             $statsModel->addKey('user_cpu', $info['used_cpu_user'], $time);
             $statsModel->addKey('system_cpu', $info['used_cpu_sys'], $time);
             if ($info['aof_enabled']) {
                 $statsModel->addKey('aof_size', $info['aof_current_size'], $time);
                 $statsModel->addKey('aof_base', $info['aof_base_size'], $time);
             }
             foreach ($this->infoModel->getDbs($info) as $i) {
                 if (preg_match('/^keys=([0-9]+),expires=([0-9]+)$/', $info["db{$i}"], $matches)) {
                     $statsModel->addKey("db{$i}:keys", $matches[1], $time);
                     $statsModel->addKey("db{$i}:expired_keys", $matches[2], $time);
                 }
             }
         }
     }
 }