/** * Displays a report. * @param boolean $id If id is supplied, a report with that id will be * retrieved. */ public function view($id = false) { $this->template->header->this_page = 'reports'; $this->template->content = new View('reports_view'); // Load Akismet API Key (Spam Blocker) $api_akismet = Kohana::config('settings.api_akismet'); if (!$id) { url::redirect('main'); } else { $incident = ORM::factory('incident', $id); if ($incident->id == 0) { url::redirect('main'); } // Comment Post? // Setup and initialize form field names $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => ''); $captcha = Captcha::factory(); $errors = $form; $form_error = FALSE; // 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('comment_author', 'required', 'length[3,100]'); $post->add_rules('comment_description', 'required'); $post->add_rules('comment_email', 'required', 'email', 'length[4,100]'); $post->add_rules('captcha', 'required', 'Captcha::valid'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid if ($api_akismet != "") { // Run Akismet Spam Checker $akismet = new Akismet(); // comment data $comment = array('author' => $post->comment_author, 'email' => $post->comment_email, 'website' => "", 'body' => $post->comment_description, 'user_ip' => $_SERVER['REMOTE_ADDR']); $config = array('blog_url' => url::site(), 'api_key' => $api_akismet, 'comment' => $comment); $akismet->init($config); if ($akismet->errors_exist()) { if ($akismet->is_error('AKISMET_INVALID_KEY')) { // throw new Kohana_Exception('akismet.api_key'); } elseif ($akismet->is_error('AKISMET_RESPONSE_FAILED')) { // throw new Kohana_Exception('akismet.server_failed'); } elseif ($akismet->is_error('AKISMET_SERVER_NOT_FOUND')) { // throw new Kohana_Exception('akismet.server_not_found'); } // If the server is down, we have to post // the comment :( // $this->_post_comment($comment); $comment_spam = 0; } else { if ($akismet->is_spam()) { $comment_spam = 1; } else { $comment_spam = 0; } } } else { // No API Key!! $comment_spam = 0; } $comment = new Comment_Model(); $comment->incident_id = $id; $comment->comment_author = strip_tags($post->comment_author); $comment->comment_description = strip_tags($post->comment_description); $comment->comment_email = strip_tags($post->comment_email); $comment->comment_ip = $_SERVER['REMOTE_ADDR']; $comment->comment_date = date("Y-m-d H:i:s", time()); // Activate comment for now if ($comment_spam == 1) { $comment->comment_spam = 1; $comment->comment_active = 0; } else { $comment->comment_spam = 0; $comment->comment_active = 1; } $comment->save(); // Notify Admin Of New Comment $send = notifications::notify_admins("[" . Kohana::config('settings.site_name') . "] " . Kohana::lang('notifications.admin_new_comment.subject'), Kohana::lang('notifications.admin_new_comment.message') . "\n\n'" . strtoupper($incident->incident_title) . "'" . "\n" . url::base() . 'reports/view/' . $id); // Redirect url::redirect('reports/view/' . $id); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('comments')); $form_error = TRUE; } } $this->template->content->incident_id = $incident->id; $this->template->content->incident_title = $incident->incident_title; $this->template->content->incident_description = nl2br($incident->incident_description); $this->template->content->incident_location = $incident->location->location_name; $this->template->content->incident_latitude = $incident->location->latitude; $this->template->content->incident_longitude = $incident->location->longitude; $this->template->content->incident_date = date('M j Y', strtotime($incident->incident_date)); $this->template->content->incident_time = date('H:i', strtotime($incident->incident_date)); $this->template->content->incident_category = $incident->incident_category; if ($incident->incident_rating == '') { $this->template->content->incident_rating = 0; } else { $this->template->content->incident_rating = $incident->incident_rating; } // Retrieve Media $incident_news = array(); $incident_video = array(); $incident_photo = array(); foreach ($incident->media as $media) { if ($media->media_type == 4) { $incident_news[] = $media->media_link; } elseif ($media->media_type == 2) { $incident_video[] = $media->media_link; } elseif ($media->media_type == 1) { $incident_photo[] = $media->media_link; } } $this->template->content->incident_verified = $incident->incident_verified; // Retrieve Comments (Additional Information) $incident_comments = array(); if ($id) { $incident_comments = ORM::factory('comment')->where('incident_id', $id)->where('comment_active', '1')->where('comment_spam', '0')->orderby('comment_date', 'asc')->find_all(); } $this->template->content->incident_comments = $incident_comments; } // Add Neighbors $this->template->content->incident_neighbors = $this->_get_neighbors($incident->location->latitude, $incident->location->longitude); // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->limit('5')->orderby('item_date', 'desc')->find_all(); // Video links $this->template->content->incident_videos = $incident_video; //images $this->template->content->incident_photos = $incident_photo; // Create object of the video embed class $video_embed = new VideoEmbed(); $this->template->content->videos_embed = $video_embed; // Javascript Header $this->template->header->map_enabled = TRUE; $this->template->header->photoslider_enabled = TRUE; $this->template->header->videoslider_enabled = TRUE; $this->template->header->js = new View('reports_view_js'); $this->template->header->js->incident_id = $incident->id; $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = $incident->location->latitude; $this->template->header->js->longitude = $incident->location->longitude; $this->template->header->js->incident_photos = $incident_photo; // Pack the javascript using the javascriptpacker helper $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false); $this->template->header->js = $myPacker->pack(); // initialize custom field array $form_field_names = $this->_get_custom_form_fields($id, $incident->form_id, false); // Retrieve Custom Form Fields Structure $disp_custom_fields = $this->_get_custom_form_fields($id, $incident->form_id, true); $this->template->content->disp_custom_fields = $disp_custom_fields; // Forms $this->template->content->form = $form; $this->template->content->form_field_names = $form_field_names; $this->template->content->captcha = $captcha; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; // If the Admin is Logged in - Allow for an edit link $this->template->content->logged_in = $this->logged_in; }
public function index() { $this->template->header->this_page = 'home'; $this->template->content = new View('main'); // Get all active top level categories $parent_categories = array(); foreach (ORM::factory('category')->where('category_visible', '1')->where('parent_id', '0')->find_all() as $category) { // Get The Children $children = array(); foreach ($category->children as $child) { $children[$child->id] = array($child->category_title, $child->category_color); } // Put it all together $parent_categories[$category->id] = array($category->category_title, $category->category_color, $children); } $this->template->content->categories = $parent_categories; // Get all active Layers (KMZ/KML) $layers = array(); $config_layers = Kohana::config('map.layers'); // use config/map layers if set if ($config_layers == $layers) { foreach (ORM::factory('layer')->where('layer_visible', 1)->find_all() as $layer) { $layers[$layer->id] = array($layer->layer_name, $layer->layer_color, $layer->layer_url, $layer->layer_file); } } else { $layers = $config_layers; } $this->template->content->layers = $layers; // Get all active Shares $shares = array(); foreach (ORM::factory('sharing')->where('sharing_active', 1)->where('sharing_type', 1)->find_all() as $share) { $shares[$share->id] = array($share->sharing_site_name, $share->sharing_color); } $this->template->content->shares = $shares; // Get Reports // XXX: Might need to replace magic no. 8 with a constant $this->template->content->total_items = ORM::factory('incident')->where('incident_active', '1')->limit('8')->count_all(); $this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_date', 'desc')->with('location')->find_all(); // Get Default Color $this->template->content->default_map_all = Kohana::config('settings.default_map_all'); // Get Twitter Hashtags $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags')))); // Get Report-To-Email $this->template->content->report_email = Kohana::config('settings.site_email'); // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->limit('10')->orderby('item_date', 'desc')->find_all(); // Get The START, END and most ACTIVE Incident Dates $startDate = ""; $endDate = ""; $active_month = 0; $active_startDate = 0; $active_endDate = 0; $db = new Database(); // First Get The Most Active Month $query = $db->query('SELECT incident_date, count(*) AS incident_count FROM ' . $this->table_prefix . 'incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y-%m\') ORDER BY incident_count DESC LIMIT 1'); foreach ($query as $query_active) { $active_month = date('n', strtotime($query_active->incident_date)); $active_year = date('Y', strtotime($query_active->incident_date)); $active_startDate = strtotime($active_year . "-" . $active_month . "-01"); $active_endDate = strtotime($active_year . "-" . $active_month . "-" . date('t', mktime(0, 0, 0, $active_month, 1)) . " 23:59:59"); } // Next, Get the Range of Years $query = $db->query('SELECT DATE_FORMAT(incident_date, \'%Y\') AS incident_date FROM ' . $this->table_prefix . 'incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y\') ORDER BY incident_date'); foreach ($query as $slider_date) { $years = $slider_date->incident_date; $startDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $startDate .= "<option value=\"" . strtotime($years . "-" . $i . "-01") . "\""; if ($active_month && (int) $i == $active_month - 1) { $startDate .= " selected=\"selected\" "; } $startDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $startDate .= "</optgroup>"; $endDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $endDate .= "<option value=\"" . strtotime($years . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59") . "\""; // Focus on the most active month or set December as month of endDate if ($active_month && (int) $i == $active_month + 1 || $i == 12 && preg_match('/selected/', $endDate) == 0) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $endDate .= "</optgroup>"; } $this->template->content->startDate = $startDate; $this->template->content->endDate = $endDate; // get graph data // could not use DB query builder. It does not support parentheses yet $graph_data = array(); $all_graphs = Incident_Model::get_incidents_by_interval('month'); $daily_graphs = Incident_Model::get_incidents_by_interval('day'); $weekly_graphs = Incident_Model::get_incidents_by_interval('week'); $hourly_graphs = Incident_Model::get_incidents_by_interval('hour'); $this->template->content->all_graphs = $all_graphs; $this->template->content->daily_graphs = $daily_graphs; // If we are looking at the standard street map set by user if (!isset($_GET['3dmap'])) { //echo 'STREET MAP'; // Javascript Header $this->template->header->map_enabled = 'streetmap'; $this->template->content->map_enabled = 'streetmap'; $this->template->content->map_container = 'map'; $this->template->header->main_page = TRUE; $this->template->header->validator_enabled = TRUE; // Map Settings $clustering = Kohana::config('settings.allow_clustering'); $marker_radius = Kohana::config('map.marker_radius'); $marker_opacity = Kohana::config('map.marker_opacity'); $marker_stroke_width = Kohana::config('map.marker_stroke_width'); $marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity'); // pdestefanis - allows to restrict the number of zoomlevels available $numZoomLevels = Kohana::config('map.numZoomLevels'); $minZoomLevel = Kohana::config('map.minZoomLevel'); $maxZoomLevel = Kohana::config('map.maxZoomLevel'); // pdestefanis - allows to limit the extents of the map $lonFrom = Kohana::config('map.lonFrom'); $latFrom = Kohana::config('map.latFrom'); $lonTo = Kohana::config('map.lonTo'); $latTo = Kohana::config('map.latTo'); $this->template->header->js = $clustering ? new View('main_cluster_js') : new View('main_cluster_js'); if ($clustering == 1) { //$this->template->header->js->cluster = "true"; // not used?? $this->template->header->js->default_json_url = "json_cluster"; } else { //$this->template->header->js->cluster = "false"; // not used?? $this->template->header->js->default_json_url = "json"; } $this->template->header->js->marker_radius = $marker_radius >= 1 && $marker_radius <= 10 ? $marker_radius : 5; $this->template->header->js->marker_opacity = $marker_opacity >= 1 && $marker_opacity <= 10 ? $marker_opacity * 0.1 : 0.9; $this->template->header->js->marker_stroke_width = $marker_stroke_width >= 1 && $marker_stroke_width <= 5 ? $marker_stroke_width : 2; $this->template->header->js->marker_stroke_opacity = $marker_stroke_opacity >= 1 && $marker_stroke_opacity <= 10 ? $marker_stroke_opacity * 0.1 : 0.9; // pdestefanis - allows to restrict the number of zoomlevels available $this->template->header->js->numZoomLevels = $numZoomLevels; $this->template->header->js->minZoomLevel = $minZoomLevel; $this->template->header->js->maxZoomLevel = $maxZoomLevel; // pdestefanis - allows to limit the extents of the map $this->template->header->js->lonFrom = $lonFrom; $this->template->header->js->latFrom = $latFrom; $this->template->header->js->lonTo = $lonTo; $this->template->header->js->latTo = $latTo; $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); $this->template->header->js->graph_data = $graph_data; $this->template->header->js->all_graphs = $all_graphs; $this->template->header->js->daily_graphs = $daily_graphs; $this->template->header->js->hourly_graphs = $hourly_graphs; $this->template->header->js->weekly_graphs = $weekly_graphs; $this->template->header->js->default_map_all = Kohana::config('settings.default_map_all'); // $this->template->header->js->active_startDate = $active_startDate; $this->template->header->js->active_endDate = $active_endDate; // If we are viewing the 3D map } else { //echo '3D MAP'; // Javascript Header $this->template->header->map_enabled = '3dmap'; $this->template->content->map_enabled = '3dmap'; $this->template->content->map_container = 'map3d'; $this->template->header->main_page = FALSE; // Setting to false because we don't want all the external controls that the street map has $this->template->header->js = new View('main_3d_js'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); // Override API URL $this->template->header->api_url = '<script src="http://www.google.com/jsapi?key=' . Kohana::config('settings.api_google') . '"> </script>'; } $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false); $this->template->header->js = $myPacker->pack(); }
public function index() { $this->template->header->this_page = 'home'; $this->template->content = new View('main'); // Get all active categories $categories = array(); foreach (ORM::factory('category')->where('category_visible', '1')->find_all() as $category) { // Create a list of all categories $categories[$category->id] = array($category->category_title, $category->category_color); } $this->template->content->categories = $categories; // Get Reports // XXX: Might need to replace magic no. 8 with a constant $this->template->content->total_items = ORM::factory('incident')->where('incident_active', '1')->limit('8')->count_all(); $this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_dateadd', 'desc')->find_all(); // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->limit('10')->orderby('item_date', 'desc')->find_all(); // Get Slider Dates By Year $startDate = ""; $endDate = ""; // We need to use the DB builder for a custom query $db = new Database(); $query = $db->query('SELECT DATE_FORMAT(incident_dateadd, \'%Y\') AS incident_dateadd FROM incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_dateadd, \'%Y\') ORDER BY incident_dateadd'); foreach ($query as $slider_date) { $startDate .= "<optgroup label=\"" . $slider_date->incident_dateadd . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $startDate .= "<option value=\"" . strtotime($slider_date->incident_dateadd . "-" . $i . "-01") . "\">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $slider_date->incident_dateadd . "</option>"; } $startDate .= "</optgroup>"; $endDate .= "<optgroup label=\"" . $slider_date->incident_dateadd . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $endDate .= "<option value=\"" . strtotime($slider_date->incident_dateadd . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1))) . "\""; if ($i == 12) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $slider_date->incident_dateadd . "</option>"; } $endDate .= "</optgroup>"; } $this->template->content->startDate = $startDate; $this->template->content->endDate = $endDate; // get graph data // could not use DB query builder. It does not support parentheses yet $graph_data = array(); $all_graphs = Incident_Model::get_incidents_by_interval('month'); $this->template->content->all_graphs = $all_graphs; // Javascript Header $this->template->header->map_enabled = TRUE; $this->template->header->main_page = TRUE; // Cluster Reports on Map? $clustering = Kohana::config('settings.allow_clustering'); if ($clustering == 1) { $this->template->header->js = new View('main_cluster_js'); } else { $this->template->header->js = new View('main_js'); } $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); $this->template->header->js->graph_data = $graph_data; $this->template->header->js->all_graphs = $all_graphs; $this->template->header->js->categories = $categories; // Pack the javascript using the javascriptpacker helper $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false); $this->template->header->js = $myPacker->pack(); }
/** * Edit a report * @param bool|int $id The id no. of the report * @param bool|string $saved */ public function edit($id = FALSE, $saved = FALSE) { $db = new Database(); $this->template->content = new View('members/reports_edit'); $this->template->content->title = Kohana::lang('ui_admin.create_report'); // Setup and initialize form field names $form = array('location_id' => '', 'form_id' => '1', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'geometry' => array(), 'location_name' => '', 'country_id' => '', 'country_name' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'custom_field' => array(), 'incident_zoom' => '', 'incident_source' => '', 'incident_information' => ''); // 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 = $saved == 'saved'; // Initialize Default Values $form['locale'] = Kohana::config('locale.language'); $form['latitude'] = Kohana::config('settings.default_lat'); $form['longitude'] = Kohana::config('settings.default_lon'); $form['country_id'] = Kohana::config('settings.default_country'); $form['incident_date'] = date("m/d/Y", time()); $form['incident_hour'] = date('h'); $form['incident_minute'] = date('i'); $form['incident_ampm'] = date('a'); // Initialize custom field array $form_id = $form['form_id']; $form['custom_field'] = customforms::get_custom_form_fields($id, $form_id, TRUE); // Locale (Language) Array $this->template->content->locale_array = Kohana::config('locale.all_languages'); // Time formatting $this->template->content->hour_array = $this->_hour_array(); $this->template->content->minute_array = $this->_minute_array(); $this->template->content->ampm_array = $this->_ampm_array(); $this->template->content->stroke_width_array = $this->_stroke_width_array(); // Get Countries $countries = array(); foreach (ORM::factory('country')->orderby('country')->find_all() as $country) { // Create a list of all categories $this_country = $country->country; if (strlen($this_country) > 35) { $this_country = substr($this_country, 0, 35) . "..."; } $countries[$country->id] = $this_country; } $this->template->content->countries = $countries; // Initialize Default Value for Hidden Field Country Name, just incase Reverse Geo coding yields no result $form['country_name'] = $countries[$form['country_id']]; //GET custom forms $forms = array(); foreach (ORM::factory('form')->where('form_active', 1)->find_all() as $custom_forms) { $forms[$custom_forms->id] = $custom_forms->form_title; } $this->template->content->forms = $forms; // Retrieve thumbnail photos (if edit); //XXX: fix _get_thumbnails $this->template->content->incident = $this->_get_thumbnails($id); // 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 = array_merge($_POST, $_FILES); if (reports::validate($post)) { // STEP 1: SAVE LOCATION $location = new Location_Model(); reports::save_location($post, $location); // STEP 2: SAVE INCIDENT $incident = new Incident_Model($id); reports::save_report($post, $incident, $location->id); // STEP 2b: SAVE INCIDENT GEOMETRIES reports::save_report_geometry($post, $incident); // STEP 3: SAVE CATEGORIES reports::save_category($post, $incident); // STEP 4: SAVE MEDIA reports::save_media($post, $incident); // STEP 5: SAVE CUSTOM FORM FIELDS reports::save_custom_fields($post, $incident); // STEP 6: SAVE PERSONAL INFORMATION reports::save_personal_info($post, $incident); // Action::report_add / report_submit_members - Added a New Report Event::run('ushahidi_action.report_submit_members', $post); Event::run('ushahidi_action.report_edit', $incident); // SAVE AND CLOSE? if ($post->save == 1) { // Save but don't close url::redirect('members/reports/edit/' . $incident->id . '/saved'); } else { // Save and close url::redirect('members/reports/'); } } else { // Repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // Populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('report')); $form_error = TRUE; } } else { if ($id) { // Retrieve Current Incident $incident = ORM::factory('incident')->where('user_id', $this->user->id)->find($id); if ($incident->loaded == true) { // Retrieve Categories $incident_category = array(); foreach ($incident->incident_category as $category) { $incident_category[] = $category->category_id; } // Retrieve Media $incident_news = array(); $incident_video = array(); $incident_photo = array(); foreach ($incident->media as $media) { if ($media->media_type == 4) { $incident_news[] = $media->media_link; } elseif ($media->media_type == 2) { $incident_video[] = $media->media_link; } elseif ($media->media_type == 1) { $incident_photo[] = $media->media_link; } } // Get Geometries via SQL query as ORM can't handle Spatial Data $sql = "SELECT AsText(geometry) as geometry, geometry_label, \n\t\t\t\t\t\tgeometry_comment, geometry_color, geometry_strokewidth \n\t\t\t\t\t\tFROM " . Kohana::config('database.default.table_prefix') . "geometry \n\t\t\t\t\t\tWHERE incident_id = ?"; $query = $db->query($sql, $id); foreach ($query as $item) { $geometry = array("geometry" => $item->geometry, "label" => $item->geometry_label, "comment" => $item->geometry_comment, "color" => $item->geometry_color, "strokewidth" => $item->geometry_strokewidth); $form['geometry'][] = json_encode($geometry); } // Combine Everything $incident_arr = array('location_id' => $incident->location->id, 'form_id' => $incident->form_id, 'locale' => $incident->locale, 'incident_title' => $incident->incident_title, 'incident_description' => $incident->incident_description, 'incident_date' => date('m/d/Y', strtotime($incident->incident_date)), 'incident_hour' => date('h', strtotime($incident->incident_date)), 'incident_minute' => date('i', strtotime($incident->incident_date)), 'incident_ampm' => date('a', strtotime($incident->incident_date)), 'latitude' => $incident->location->latitude, 'longitude' => $incident->location->longitude, 'location_name' => $incident->location->location_name, 'country_id' => $incident->location->country_id, 'incident_category' => $incident_category, 'incident_news' => $incident_news, 'incident_video' => $incident_video, 'incident_photo' => $incident_photo, 'person_first' => $incident->incident_person->person_first, 'person_last' => $incident->incident_person->person_last, 'person_email' => $incident->incident_person->person_email, 'incident_source' => '', 'incident_information' => '', 'custom_field' => customforms::get_custom_form_fields($id, $incident->form_id, TRUE), 'incident_zoom' => $incident->incident_zoom); // Merge To Form Array For Display $form = arr::overwrite($form, $incident_arr); } else { // Redirect url::redirect('members/reports/'); } } } $this->template->content->id = $id; $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; // Retrieve Custom Form Fields Structure $this->template->content->custom_forms = new View('reports/submit_custom_forms'); $disp_custom_fields = customforms::get_custom_form_fields($id, $form['form_id'], FALSE, "view"); $custom_field_mismatch = customforms::get_edit_mismatch($form['form_id']); // Quick hack to make sure view-only fields have data set foreach ($custom_field_mismatch as $id => $field) { $form['custom_field'][$id] = $disp_custom_fields[$id]['field_response']; } $this->template->content->custom_forms->disp_custom_fields = $disp_custom_fields; $this->template->content->custom_forms->custom_field_mismatch = $custom_field_mismatch; $this->template->content->custom_forms->form = $form; // Retrieve Previous & Next Records $previous = ORM::factory('incident')->where('id < ', $id)->orderby('id', 'desc')->find(); $previous_url = $previous->loaded ? url::site('members/reports/edit/' . $previous->id) : url::site() . 'members/reports/'; $next = ORM::factory('incident')->where('id > ', $id)->orderby('id', 'desc')->find(); $next_url = $next->loaded ? url::site('members/reports/edit/' . $next->id) : url::site('members/reports/'); $this->template->content->previous_url = $previous_url; $this->template->content->next_url = $next_url; // Javascript Header $this->themes->map_enabled = TRUE; $this->themes->colorpicker_enabled = TRUE; $this->themes->treeview_enabled = TRUE; $this->themes->json2_enabled = TRUE; $this->themes->js = new View('reports/submit_edit_js'); $this->themes->js->edit_mode = FALSE; $this->themes->js->default_map = Kohana::config('settings.default_map'); $this->themes->js->default_zoom = Kohana::config('settings.default_zoom'); if (!$form['latitude'] or !$form['longitude']) { $this->themes->js->latitude = Kohana::config('settings.default_lat'); $this->themes->js->longitude = Kohana::config('settings.default_lon'); } else { $this->themes->js->latitude = $form['latitude']; $this->themes->js->longitude = $form['longitude']; } $this->themes->js->incident_zoom = $form['incident_zoom']; $this->themes->js->geometries = $form['geometry']; // Inline Javascript $this->template->content->date_picker_js = $this->_date_picker_js(); $this->template->content->color_picker_js = $this->_color_picker_js(); // Pack Javascript $myPacker = new javascriptpacker($this->themes->js, 'Normal', FALSE, FALSE); $this->themes->js = $myPacker->pack(); }
public function index() { $this->template->header->this_page = 'Jobs Main'; $this->template->content = new View('jobsmain'); // Get all active top level categories $parent_categories = array(); foreach (ORM::factory('j_category')->where('job_category_visible', '1')->where('parent_id', '0')->find_all() as $category) { // Get The Children $children = array(); foreach ($category->children as $child) { $children[$child->id] = array($child->job_category_title, $child->job_category_color); } // Put it all together $parent_categories[$category->id] = array($category->job_category_title, $category->job_category_color, $children); } $this->template->content->categories = $parent_categories; // Get Reports // XXX: Might need to replace magic no. 8 with a constant $this->template->content->total_items = ORM::factory('job')->where('job_active', '1')->limit('8')->count_all(); $this->template->content->incidents = ORM::factory('job')->where('job_active', '1')->limit('10')->orderby('job_dateadd', 'desc')->with('location')->find_all(); // Get Default Color $this->template->content->default_map_all = Kohana::config('settings.default_map_all'); // Get Twitter Hashtags $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags')))); // Get Report-To-Email $this->template->content->report_email = Kohana::config('settings.site_email'); // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->limit('10')->orderby('item_date', 'desc')->find_all(); // Temp code. will remove it when I get sometime to digg into the js script for handling map // Get The START, END and most ACTIVE Incident Dates $startDate = ""; $endDate = ""; $active_month = 0; $active_startDate = 0; $active_endDate = 0; $db = new Database(); // First Get The Most Active Month $query = $db->query('SELECT job_dateadd, count(*) AS job_count FROM job WHERE job_active = 1 GROUP BY DATE_FORMAT(job_dateadd, \'%Y-%m\') ORDER BY job_count DESC LIMIT 1'); foreach ($query as $query_active) { $active_month = date('n', strtotime($query_active->job_dateadd)); $active_year = date('Y', strtotime($query_active->job_dateadd)); $active_startDate = strtotime($active_year . "-" . $active_month . "-01"); $active_endDate = strtotime($active_year . "-" . $active_month . "-" . date('t', mktime(0, 0, 0, $active_month, 1)) . " 23:59:59"); } // Next, Get the Range of Years $query = $db->query('SELECT DATE_FORMAT(job_dateadd, \'%Y\') AS job_dateadd FROM job WHERE job_active = 1 GROUP BY DATE_FORMAT(job_dateadd, \'%Y\') ORDER BY job_dateadd'); foreach ($query as $slider_date) { $years = $slider_date->job_dateadd; $startDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $startDate .= "<option value=\"" . strtotime($years . "-" . $i . "-01") . "\""; if ($active_month && (int) $i == $active_month - 1) { $startDate .= " selected=\"selected\" "; } $startDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $startDate .= "</optgroup>"; $endDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $endDate .= "<option value=\"" . strtotime($years . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59") . "\""; if ($active_month && (int) $i == $active_month + 1 || $i == 12) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $endDate .= "</optgroup>"; } $this->template->content->startDate = $startDate; $this->template->content->endDate = $endDate; // If we are looking at the standard street map set by user if (!isset($_GET['3dmap'])) { //echo 'STREET MAP'; // Javascript Header $this->template->header->map_enabled = 'streetmap'; $this->template->content->map_enabled = 'streetmap'; $this->template->content->map_container = 'map'; $this->template->header->main_page = TRUE; $this->template->header->validator_enabled = TRUE; // Map Settings $clustering = Kohana::config('settings.allow_clustering'); $marker_radius = Kohana::config('map.marker_radius'); $marker_opacity = Kohana::config('map.marker_opacity'); $marker_stroke_width = Kohana::config('map.marker_stroke_width'); $marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity'); $this->template->header->js = new View('jobsmain_cluster_js'); $this->template->header->js->cluster = $clustering == 1 ? "true" : "false"; $this->template->header->js->marker_radius = $marker_radius >= 1 && $marker_radius <= 10 ? $marker_radius : 5; $this->template->header->js->marker_opacity = $marker_opacity >= 1 && $marker_opacity <= 10 ? $marker_opacity * 0.1 : 0.9; $this->template->header->js->marker_stroke_width = $marker_stroke_width >= 1 && $marker_stroke_width <= 5 ? $marker_stroke_width : 2; $this->template->header->js->marker_stroke_opacity = $marker_stroke_opacity >= 1 && $marker_stroke_opacity <= 10 ? $marker_stroke_opacity * 0.1 : 0.9; $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); $this->template->header->js->default_map_all = Kohana::config('settings.default_map_all'); // If we are viewing the 3D map } else { //echo '3D MAP'; // Javascript Header $this->template->header->map_enabled = '3dmap'; $this->template->content->map_enabled = '3dmap'; $this->template->content->map_container = 'map3d'; $this->template->header->main_page = FALSE; // Setting to false because we don't want all the external controls that the street map has $this->template->header->js = new View('main_3d_js'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); // Override API URL $this->template->header->api_url = '<script src="http://www.google.com/jsapi?key=' . Kohana::config('settings.api_google') . '"> </script>'; } $footerjs = new View('footer_form_js'); // Pack the javascript using the javascriptpacker helper $this->template->header->js .= $footerjs; $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false); $this->template->header->js = $myPacker->pack(); }
public function index() { // Create new session $this->session->create(); $this->template->header->this_page = 'alerts'; $this->template->content = new View('alerts'); // Display news feeds? $this->template->content->allow_feed = Kohana::config('settings.allow_feed'); // Retrieve default country, latitude, longitude $default_country = Kohana::config('settings.default_country'); // Retrieve Country Cities $this->template->content->cities = $this->_get_cities($default_country); // Setup and initialize form field names $form = array('alert_email' => '', 'alert_email_yes' => '', 'alert_lat' => '', 'alert_lon' => '', 'alert_radius' => ''); // 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; // If there is a post and $_POST is not empty if ($post = $this->input->post()) { // Create a new alert $alert = ORM::factory('alert'); // Test to see if things passed the rule checks if ($alert->validate($post)) { // Yes! everything is valid // Save alert and send out confirmation code if (!empty($post->alert_email)) { $this->_send_email_alert($post->alert_email, $post->alert_lon, $post->alert_lat, $post->alert_radius); } //$this->session->set('alert_mobile', $post->alert_mobile); $this->session->set('alert_email', $post->alert_email); url::redirect('alerts/confirm'); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('alerts')); $form_error = TRUE; } } else { $form['alert_lat'] = Kohana::config('settings.default_lat'); $form['alert_lon'] = Kohana::config('settings.default_lon'); $form['alert_radius'] = 20; } $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; // Javascript Header $this->template->header->map_enabled = TRUE; $this->template->header->js = new View('alerts_js'); $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = $form['alert_lat']; $this->template->header->js->longitude = $form['alert_lon']; //include footer form js file $footerjs = new View('footer_form_js'); // Pack the javascript using the javascriptpacker helper $myPacker = new javascriptpacker($footerjs, 'Normal', false, false); $footerjs = $myPacker->pack(); $this->template->header->js .= $footerjs; }
/** * Edit a report * @param bool|int $id The id no. of the report * @param bool|string $saved */ public function edit($id = FALSE, $saved = FALSE) { $db = new Database(); // If user doesn't have access, redirect to dashboard if (!$this->auth->has_permission("reports_edit")) { url::redirect('admin/dashboard'); } $this->template->content = new View('admin/reports/edit'); $this->template->content->title = Kohana::lang('ui_admin.create_report'); // Setup and initialize form field names $form = array('location_id' => '', 'form_id' => '', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'geometry' => array(), 'location_name' => '', 'country_id' => '', 'country_name' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'custom_field' => array(), 'incident_active' => '', 'incident_verified' => '', 'incident_zoom' => ''); // 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 = $saved == 'saved'; // Initialize Default Values $form['locale'] = Kohana::config('locale.language'); //$form['latitude'] = Kohana::config('settings.default_lat'); //$form['longitude'] = Kohana::config('settings.default_lon'); $form['incident_date'] = date("m/d/Y", time()); $form['incident_hour'] = date('h'); $form['incident_minute'] = date('i'); $form['incident_ampm'] = date('a'); $form['country_id'] = Kohana::config('settings.default_country'); // get the form ID if relevant, kind of a hack // to just hit the database like this for one // tiny bit of info then throw away the DB model object, // but seems to be what everyone else does, so // why should I care. Just know that when your Ush system crashes // because you have 1000 concurrent users you'll need to do this // correctly. Etherton. $form['form_id'] = 1; $form_id = $form['form_id']; if ($id and Incident_Model::is_valid_incident($id, FALSE)) { $form_id = ORM::factory('incident', $id)->form_id; } // Initialize custom field array $form['custom_field'] = customforms::get_custom_form_fields($id, $form_id, TRUE); // Locale (Language) Array $this->template->content->locale_array = Kohana::config('locale.all_languages'); // Create Categories $this->template->content->new_categories_form = $this->_new_categories_form_arr(); // Time formatting $this->template->content->hour_array = $this->_hour_array(); $this->template->content->minute_array = $this->_minute_array(); $this->template->content->ampm_array = $this->_ampm_array(); $this->template->content->stroke_width_array = $this->_stroke_width_array(); // Get Countries $countries = array(); foreach (ORM::factory('country')->orderby('country')->find_all() as $country) { // Create a list of all countries $this_country = $country->country; if (strlen($this_country) > 35) { $this_country = substr($this_country, 0, 35) . "..."; } $countries[$country->id] = $this_country; } // Initialize Default Value for Hidden Field Country Name, // just incase Reverse Geo coding yields no result $form['country_name'] = $countries[$form['country_id']]; $this->template->content->countries = $countries; // GET custom forms $forms = array(); foreach (customforms::get_custom_forms(FALSE) as $custom_forms) { $forms[$custom_forms->id] = $custom_forms->form_title; } $this->template->content->forms = $forms; // Get the incident media $incident_media = Incident_Model::is_valid_incident($id, FALSE) ? ORM::factory('incident', $id)->media : FALSE; $this->template->content->incident_media = $incident_media; // Are we creating this report from SMS/Email/Twitter? // If so retrieve message if (isset($_GET['mid']) and intval($_GET['mid']) > 0) { $message_id = intval($_GET['mid']); $service_id = ""; $message = ORM::factory('message', $message_id); if ($message->loaded and $message->message_type == 1) { $service_id = $message->reporter->service_id; // Has a report already been created for this Message? if ($message->incident_id != 0) { // Redirect to report url::redirect('admin/reports/edit/' . $message->incident_id); } $this->template->content->show_messages = TRUE; $incident_description = $message->message; if (!empty($message->message_detail)) { $form['incident_title'] = $message->message; $incident_description = $message->message_detail; } $form['incident_description'] = $incident_description; $form['incident_date'] = date('m/d/Y', strtotime($message->message_date)); $form['incident_hour'] = date('h', strtotime($message->message_date)); $form['incident_minute'] = date('i', strtotime($message->message_date)); $form['incident_ampm'] = date('a', strtotime($message->message_date)); $form['person_first'] = $message->reporter->reporter_first; $form['person_last'] = $message->reporter->reporter_last; // Does the message itself have a location? if ($message->latitude != NULL and $message->longitude != NULL) { $form['latitude'] = $message->latitude; $form['longitude'] = $message->longitude; } elseif ($message->reporter->location->loaded) { $form['location_id'] = $message->reporter->location->id; $form['latitude'] = $message->reporter->location->latitude; $form['longitude'] = $message->reporter->location->longitude; $form['location_name'] = $message->reporter->location->location_name; } // Events to manipulate an already known location Event::run('ushahidi_action.location_from', $message_from = $message->message_from); // Filter location name Event::run('ushahidi_filter.location_name', $form['location_name']); // Filter //location find Event::run('ushahidi_filter.location_find', $form['location_find']); // Retrieve Last 5 Messages From this account $this->template->content->all_messages = ORM::factory('message')->where('reporter_id', $message->reporter_id)->orderby('message_date', 'desc')->limit(5)->find_all(); } else { $message_id = ""; $this->template->content->show_messages = FALSE; } } else { $this->template->content->show_messages = FALSE; } // Are we creating this report from a Newsfeed? if (isset($_GET['fid']) and intval($_GET['fid']) > 0) { $feed_item_id = intval($_GET['fid']); $feed_item = ORM::factory('feed_item', $feed_item_id); if ($feed_item->loaded) { // Has a report already been created for this Feed item? if ($feed_item->incident_id != 0) { // Redirect to report url::redirect('admin/reports/edit/' . $feed_item->incident_id); } $form['incident_title'] = $feed_item->item_title; $form['incident_description'] = $feed_item->item_description; $form['incident_date'] = date('m/d/Y', strtotime($feed_item->item_date)); $form['incident_hour'] = date('h', strtotime($feed_item->item_date)); $form['incident_minute'] = date('i', strtotime($feed_item->item_date)); $form['incident_ampm'] = date('a', strtotime($feed_item->item_date)); // News Link $form['incident_news'][0] = $feed_item->item_link; // Does this newsfeed have a geolocation? if ($feed_item->location_id) { $form['location_id'] = $feed_item->location_id; $form['latitude'] = $feed_item->location->latitude; $form['longitude'] = $feed_item->location->longitude; $form['location_name'] = $feed_item->location->location_name; } // HT: new code $feed_item_categories = ORM::factory('feed_item_category')->where('feed_item_id', $feed_item->id)->select_list('id', 'category_id'); if ($feed_item_categories) { foreach ($feed_item_categories as $feed_item_category) { $form['incident_category'][] = $feed_item_category; } } // HT: end of new code } else { $feed_item_id = ""; } } // 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 = array_merge($_POST, $_FILES); // Check if the service id exists if (isset($service_id) and intval($service_id) > 0) { $post = array_merge($post, array('service_id' => $service_id)); } // Check if the incident id is valid an add it to the post data if (Incident_Model::is_valid_incident($id, FALSE)) { $post = array_merge($post, array('incident_id' => $id)); } /** * NOTES - E.Kala July 27, 2011 * * Previously, the $post parameter for this event was a Validation * object. Now it's an array (i.e. the raw data without any validation rules applied to them). * As such, all plugins making use of this event shall have to be updated */ // Action::report_submit_admin - Report Posted Event::run('ushahidi_action.report_submit_admin', $post); // Validate if (reports::validate($post)) { // Yes! everything is valid $location_id = $post->location_id; // STEP 1: SAVE LOCATION $location = new Location_Model($location_id); reports::save_location($post, $location); // STEP 2: SAVE INCIDENT $incident = new Incident_Model($id); reports::save_report($post, $incident, $location->id); // STEP 2b: Record Approval/Verification Action reports::verify_approve($incident); // STEP 2c: SAVE INCIDENT GEOMETRIES reports::save_report_geometry($post, $incident); // STEP 3: SAVE CATEGORIES reports::save_category($post, $incident); // STEP 4: SAVE MEDIA reports::save_media($post, $incident); // STEP 5: SAVE PERSONAL INFORMATION reports::save_personal_info($post, $incident); // STEP 6a: SAVE LINK TO REPORTER MESSAGE // We're creating a report from a message with this option if (isset($message_id) and intval($message_id) > 0) { $savemessage = ORM::factory('message', $message_id); if ($savemessage->loaded) { $savemessage->incident_id = $incident->id; $savemessage->save(); // Does Message Have Attachments? // Add Attachments $attachments = ORM::factory("media")->where("message_id", $savemessage->id)->find_all(); foreach ($attachments as $attachment) { $attachment->incident_id = $incident->id; $attachment->save(); } } } // STEP 6b: SAVE LINK TO NEWS FEED // We're creating a report from a newsfeed with this option if (isset($feed_item_id) and intval($feed_item_id) > 0) { $savefeed = ORM::factory('feed_item', $feed_item_id); if ($savefeed->loaded) { $savefeed->incident_id = $incident->id; $savefeed->location_id = $location->id; $savefeed->save(); } } // STEP 7: SAVE CUSTOM FORM FIELDS reports::save_custom_fields($post, $incident); // Action::report_edit - Edited a Report Event::run('ushahidi_action.report_edit', $incident); // SAVE AND CLOSE? switch ($post->save) { case 1: case 'dontclose': // Save but don't close url::redirect('admin/reports/edit/' . $incident->id . '/saved'); break; case 'addnew': // Save and add new url::redirect('admin/reports/edit/0/saved'); break; default: // Save and close url::redirect('admin/reports/'); } } else { // Repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // Populate the error fields, if any $errors = arr::merge($errors, $post->errors('report')); $form_error = TRUE; } } else { if (Incident_Model::is_valid_incident($id, FALSE)) { // Retrieve Current Incident $incident = ORM::factory('incident', $id); if ($incident->loaded == TRUE) { // Retrieve Categories $incident_category = array(); foreach ($incident->incident_category as $category) { $incident_category[] = $category->category_id; } // Retrieve Media $incident_news = array(); $incident_video = array(); $incident_photo = array(); foreach ($incident->media as $media) { if ($media->media_type == 4) { $incident_news[] = $media->media_link; } elseif ($media->media_type == 2) { $incident_video[] = $media->media_link; } elseif ($media->media_type == 1) { $incident_photo[] = $media->media_link; } } // Get Geometries via SQL query as ORM can't handle Spatial Data $sql = "SELECT AsText(geometry) as geometry, geometry_label,\n\t\t\t\t\t\tgeometry_comment, geometry_color, geometry_strokewidth\n\t\t\t\t\t\tFROM " . Kohana::config('database.default.table_prefix') . "geometry\n\t\t\t\t\t\tWHERE incident_id = ?"; $query = $db->query($sql, $id); foreach ($query as $item) { $geometry = array("geometry" => $item->geometry, "label" => $item->geometry_label, "comment" => $item->geometry_comment, "color" => $item->geometry_color, "strokewidth" => $item->geometry_strokewidth); $form['geometry'][] = json_encode($geometry); } // Combine Everything $incident_arr = array('location_id' => $incident->location->id, 'form_id' => $incident->form_id, 'locale' => $incident->locale, 'incident_title' => $incident->incident_title, 'incident_description' => $incident->incident_description, 'incident_date' => date('m/d/Y', strtotime($incident->incident_date)), 'incident_hour' => date('h', strtotime($incident->incident_date)), 'incident_minute' => date('i', strtotime($incident->incident_date)), 'incident_ampm' => date('a', strtotime($incident->incident_date)), 'latitude' => $incident->location->latitude, 'longitude' => $incident->location->longitude, 'location_name' => $incident->location->location_name, 'country_id' => $incident->location->country_id, 'incident_category' => $incident_category, 'incident_news' => $incident_news, 'incident_video' => $incident_video, 'incident_photo' => $incident_photo, 'person_first' => $incident->incident_person->person_first, 'person_last' => $incident->incident_person->person_last, 'person_email' => $incident->incident_person->person_email, 'custom_field' => customforms::get_custom_form_fields($id, $incident->form_id, TRUE, 'submit'), 'incident_active' => $incident->incident_active, 'incident_verified' => $incident->incident_verified, 'incident_zoom' => $incident->incident_zoom); // Merge To Form Array For Display $form = arr::overwrite($form, $incident_arr); } else { // Redirect url::redirect('admin/reports/'); } } } $this->template->content->id = $id; $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; // Retrieve Custom Form Fields Structure $this->template->content->custom_forms = new View('reports/submit_custom_forms'); $disp_custom_fields = customforms::get_custom_form_fields($id, $form['form_id'], FALSE, "view"); $custom_field_mismatch = customforms::get_edit_mismatch($form['form_id']); // Quick hack to make sure view-only fields have data set foreach ($custom_field_mismatch as $id => $field) { $form['custom_field'][$id] = $disp_custom_fields[$id]['field_response']; } $this->template->content->custom_forms->disp_custom_fields = $disp_custom_fields; $this->template->content->custom_forms->custom_field_mismatch = $custom_field_mismatch; $this->template->content->custom_forms->form = $form; // Retrieve Previous & Next Records $previous = ORM::factory('incident')->where('id < ', $id)->orderby('id', 'desc')->find(); $previous_url = $previous->loaded ? url::site('admin/reports/edit/' . $previous->id) : url::site('admin/reports/'); $next = ORM::factory('incident')->where('id > ', $id)->orderby('id', 'desc')->find(); $next_url = $next->loaded ? url::site('admin/reports/edit/' . $next->id) : url::site('admin/reports/'); $this->template->content->previous_url = $previous_url; $this->template->content->next_url = $next_url; // Javascript Header $this->themes->map_enabled = TRUE; $this->themes->colorpicker_enabled = TRUE; $this->themes->treeview_enabled = TRUE; $this->themes->json2_enabled = TRUE; $this->themes->js = new View('reports/submit_edit_js'); $this->themes->js->edit_mode = TRUE; $this->themes->js->default_map = Kohana::config('settings.default_map'); $this->themes->js->default_zoom = Kohana::config('settings.default_zoom'); if (!$form['latitude'] or !$form['latitude']) { $this->themes->js->latitude = Kohana::config('settings.default_lat'); $this->themes->js->longitude = Kohana::config('settings.default_lon'); } else { $this->themes->js->latitude = $form['latitude']; $this->themes->js->longitude = $form['longitude']; } $this->themes->js->incident_zoom = $form['incident_zoom']; $this->themes->js->geometries = $form['geometry']; // Inline Javascript $this->template->content->date_picker_js = $this->_date_picker_js(); $this->template->content->color_picker_js = $this->_color_picker_js(); $this->template->content->new_category_toggle_js = $this->_new_category_toggle_js(); // Pack Javascript $myPacker = new javascriptpacker($this->themes->js, 'Normal', FALSE, FALSE); $this->themes->js = $myPacker->pack(); }
/** * Edit a report * @param bool|int $id The id no. of the report * @param bool|string $saved */ function edit($id = false, $saved = false) { $db = new Database(); $this->template->content = new View('members/reports_edit'); $this->template->content->title = Kohana::lang('ui_admin.create_report'); // setup and initialize form field names $form = array('location_id' => '', 'form_id' => '', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'geometry' => array(), 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'custom_field' => array(), 'incident_source' => '', 'incident_information' => '', 'incident_zoom' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; if ($saved == 'saved') { $form_saved = TRUE; } else { $form_saved = FALSE; } // Initialize Default Values $form['locale'] = Kohana::config('locale.language'); //$form['latitude'] = Kohana::config('settings.default_lat'); //$form['longitude'] = Kohana::config('settings.default_lon'); $form['country_id'] = Kohana::config('settings.default_country'); $form['incident_date'] = date("m/d/Y", time()); $form['incident_hour'] = date('h'); $form['incident_minute'] = date('i'); $form['incident_ampm'] = date('a'); // initialize custom field array $form['custom_field'] = $this->_get_custom_form_fields($id, '', true); // Locale (Language) Array $this->template->content->locale_array = Kohana::config('locale.all_languages'); // Create Categories $this->template->content->categories = $this->_get_categories(); // Time formatting $this->template->content->hour_array = $this->_hour_array(); $this->template->content->minute_array = $this->_minute_array(); $this->template->content->ampm_array = $this->_ampm_array(); $this->template->content->stroke_width_array = $this->_stroke_width_array(); // Get Countries $countries = array(); foreach (ORM::factory('country')->orderby('country')->find_all() as $country) { // Create a list of all categories $this_country = $country->country; if (strlen($this_country) > 35) { $this_country = substr($this_country, 0, 35) . "..."; } $countries[$country->id] = $this_country; } $this->template->content->countries = $countries; //GET custom forms $forms = array(); foreach (ORM::factory('form')->where('form_active', 1)->find_all() as $custom_forms) { $forms[$custom_forms->id] = $custom_forms->form_title; } $this->template->content->forms = $forms; // Retrieve thumbnail photos (if edit); //XXX: fix _get_thumbnails $this->template->content->incident = $this->_get_thumbnails($id); // Are we creating this report from a Checkin? if (isset($_GET['cid']) && !empty($_GET['cid'])) { $checkin_id = (int) $_GET['cid']; $checkin = ORM::factory('checkin', $checkin_id); if ($checkin->loaded) { // Has a report already been created for this Checkin? if ((int) $checkin->incident_id > 0) { // Redirect to report url::redirect('members/reports/edit/' . $checkin->incident_id); } $incident_description = $checkin->checkin_description; $incident_title = text::limit_chars(strip_tags($incident_description), 100, "...", true); $form['incident_title'] = $incident_title; $form['incident_description'] = $incident_description; $form['incident_date'] = date('m/d/Y', strtotime($checkin->checkin_date)); $form['incident_hour'] = date('h', strtotime($checkin->checkin_date)); $form['incident_minute'] = date('i', strtotime($checkin->checkin_date)); $form['incident_ampm'] = date('a', strtotime($checkin->checkin_date)); // Does the sender of this message have a location? if ($checkin->location->loaded) { $form['location_id'] = $checkin->location_id; $form['latitude'] = $checkin->location->latitude; $form['longitude'] = $checkin->location->longitude; $form['location_name'] = $checkin->location->location_name; } } } // 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(array_merge($_POST, $_FILES)); // 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('locale','required','alpha_dash','length[5]'); $post->add_rules('location_id', 'numeric'); $post->add_rules('message_id', 'numeric'); $post->add_rules('incident_title', 'required', 'length[3,200]'); $post->add_rules('incident_description', 'required'); $post->add_rules('incident_date', 'required', 'date_mmddyyyy'); $post->add_rules('incident_hour', 'required', 'between[1,12]'); $post->add_rules('incident_minute', 'required', 'between[0,59]'); if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") { $post->add_error('incident_ampm', 'values'); } $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]'); //XXX: Hack to validate for no checkboxes checked if (!isset($_POST['incident_category'])) { $post->incident_category = ""; $post->add_error('incident_category', 'required'); } else { $post->add_rules('incident_category.*', 'required', 'numeric'); } // Validate only the fields that are filled in if (!empty($_POST['incident_news'])) { foreach ($_POST['incident_news'] as $key => $url) { if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) { $post->add_error('incident_news', 'url'); } } } // Validate only the fields that are filled in if (!empty($_POST['incident_video'])) { foreach ($_POST['incident_video'] as $key => $url) { if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) { $post->add_error('incident_video', 'url'); } } } // Validate photo uploads $post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]'); // Validate Personal Information if (!empty($_POST['person_first'])) { $post->add_rules('person_first', 'length[3,100]'); } if (!empty($_POST['person_last'])) { $post->add_rules('person_last', 'length[3,100]'); } if (!empty($_POST['person_email'])) { $post->add_rules('person_email', 'email', 'length[3,100]'); } // Validate Custom Fields if (isset($post->custom_field) && !$this->_validate_custom_form_fields($post->custom_field)) { $post->add_error('custom_field', 'values'); } $post->add_rules('incident_source', 'numeric', 'length[1,1]'); $post->add_rules('incident_information', 'numeric', 'length[1,1]'); // Test to see if things passed the rule checks if ($post->validate()) { // STEP 1: SAVE LOCATION $location = new Location_Model(); reports::save_location($post, $location); // STEP 2: SAVE INCIDENT $incident = new Incident_Model(); reports::save_report($post, $incident, $location->id); // STEP 3: SAVE CATEGORIES reports::save_category($post, $incident); // STEP 4: SAVE MEDIA reports::save_media($post, $incident); // STEP 5: SAVE CUSTOM FORM FIELDS reports::save_custom_fields($post, $incident); // STEP 6: SAVE PERSONAL INFORMATION reports::save_personal_info($post, $incident); // If creating a report from a checkin if (isset($checkin_id) and $checkin_id != "") { $checkin = ORM::factory('checkin', $checkin_id); if ($checkin->loaded) { $checkin->incident_id = $incident->id; $checkin->save(); // Attach all the media items in this checkin to the report foreach ($checkin->media as $media) { $media->incident_id = $incident->id; $media->save(); } } } // Action::report_add / report_submit_members - Added a New Report //++ Do we need two events for this? Or will one suffice? Event::run('ushahidi_action.report_add', $incident); Event::run('ushahidi_action.report_submit_members', $post); // SAVE AND CLOSE? if ($post->save == 1) { url::redirect('members/reports/edit/' . $incident->id . '/saved'); } else { url::redirect('members/reports/'); } } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('report')); $form_error = TRUE; } } else { if ($id) { // Retrieve Current Incident $incident = ORM::factory('incident')->where('user_id', $this->user->id)->find($id); if ($incident->loaded == true) { // Retrieve Categories $incident_category = array(); foreach ($incident->incident_category as $category) { $incident_category[] = $category->category_id; } // Retrieve Media $incident_news = array(); $incident_video = array(); $incident_photo = array(); foreach ($incident->media as $media) { if ($media->media_type == 4) { $incident_news[] = $media->media_link; } elseif ($media->media_type == 2) { $incident_video[] = $media->media_link; } elseif ($media->media_type == 1) { $incident_photo[] = $media->media_link; } } // Get Geometries via SQL query as ORM can't handle Spatial Data $sql = "SELECT AsText(geometry) as geometry, geometry_label, \n\t\t\t\t\t\tgeometry_comment, geometry_color, geometry_strokewidth \n\t\t\t\t\t\tFROM " . Kohana::config('database.default.table_prefix') . "geometry \n\t\t\t\t\t\tWHERE incident_id=" . $id; $query = $db->query($sql); foreach ($query as $item) { $geometry = array("geometry" => $item->geometry, "label" => $item->geometry_label, "comment" => $item->geometry_comment, "color" => $item->geometry_color, "strokewidth" => $item->geometry_strokewidth); $form['geometry'][] = json_encode($geometry); } // Combine Everything $incident_arr = array('location_id' => $incident->location->id, 'form_id' => $incident->form_id, 'locale' => $incident->locale, 'incident_title' => $incident->incident_title, 'incident_description' => $incident->incident_description, 'incident_date' => date('m/d/Y', strtotime($incident->incident_date)), 'incident_hour' => date('h', strtotime($incident->incident_date)), 'incident_minute' => date('i', strtotime($incident->incident_date)), 'incident_ampm' => date('a', strtotime($incident->incident_date)), 'latitude' => $incident->location->latitude, 'longitude' => $incident->location->longitude, 'location_name' => $incident->location->location_name, 'country_id' => $incident->location->country_id, 'incident_category' => $incident_category, 'incident_news' => $incident_news, 'incident_video' => $incident_video, 'incident_photo' => $incident_photo, 'person_first' => $incident->incident_person->person_first, 'person_last' => $incident->incident_person->person_last, 'person_email' => $incident->incident_person->person_email, 'custom_field' => $this->_get_custom_form_fields($id, $incident->form_id, true), 'incident_source' => $incident->incident_source, 'incident_information' => $incident->incident_information, 'incident_zoom' => $incident->incident_zoom); // Merge To Form Array For Display $form = arr::overwrite($form, $incident_arr); } else { // Redirect url::redirect('members/reports/'); } } } $this->template->content->id = $id; $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; // Retrieve Custom Form Fields Structure $disp_custom_fields = $this->_get_custom_form_fields($id, $form['form_id'], false); $this->template->content->disp_custom_fields = $disp_custom_fields; // Retrieve Previous & Next Records $previous = ORM::factory('incident')->where('id < ', $id)->orderby('id', 'desc')->find(); $previous_url = $previous->loaded ? url::base() . 'members/reports/edit/' . $previous->id : url::base() . 'members/reports/'; $next = ORM::factory('incident')->where('id > ', $id)->orderby('id', 'desc')->find(); $next_url = $next->loaded ? url::base() . 'members/reports/edit/' . $next->id : url::base() . 'members/reports/'; $this->template->content->previous_url = $previous_url; $this->template->content->next_url = $next_url; // Javascript Header $this->template->map_enabled = TRUE; $this->template->colorpicker_enabled = TRUE; $this->template->treeview_enabled = TRUE; $this->template->json2_enabled = TRUE; $this->template->js = new View('admin/reports_edit_js'); $this->template->js->default_map = Kohana::config('settings.default_map'); $this->template->js->default_zoom = Kohana::config('settings.default_zoom'); if (!$form['latitude'] || !$form['latitude']) { $this->template->js->latitude = Kohana::config('settings.default_lat'); $this->template->js->longitude = Kohana::config('settings.default_lon'); } else { $this->template->js->latitude = $form['latitude']; $this->template->js->longitude = $form['longitude']; } $this->template->js->incident_zoom = $form['incident_zoom']; $this->template->js->geometries = $form['geometry']; // Inline Javascript $this->template->content->date_picker_js = $this->_date_picker_js(); $this->template->content->color_picker_js = $this->_color_picker_js(); // Pack Javascript $myPacker = new javascriptpacker($this->template->js, 'Normal', false, false); $this->template->js = $myPacker->pack(); }
public function index() { $this->template->header->this_page = 'home'; $this->template->content = new View('main'); //get images from flickr $flickr = new PhpFlickr('7ffd3c4b9d9f3a486b67124d5b530f11'); $haiti_photos = $flickr->photos_search(array('text' => 'earthquake in haiti', 'per_page' => 12)); $this->template->content->flickr = $flickr; $this->template->content->haiti_photos = $haiti_photos; // Get all active top level categories $parent_categories = array(); foreach (ORM::factory('category')->where('category_visible', '1')->where('parent_id', '0')->find_all() as $category) { // Get The Children $children = array(); foreach ($category->children as $child) { $children[$child->id] = array($child->category_title, $child->category_color, $child->category_image); } // Put it all together $parent_categories[$category->id] = array($category->category_title, $category->category_color, $category->category_image, $children); } $this->template->content->categories = $parent_categories; // Get all active Layers (KMZ/KML) $layers = array(); foreach (ORM::factory('layer')->where('layer_visible', 1)->find_all() as $layer) { $layers[$layer->id] = array($layer->layer_name, $layer->layer_color, $layer->layer_url, $layer->layer_file); } $this->template->content->layers = $layers; // Get all active Shares $shares = array(); foreach (ORM::factory('sharing')->where('sharing_active', 1)->where('sharing_type', 1)->find_all() as $share) { $shares[$share->id] = array($share->sharing_site_name, $share->sharing_color); } $this->template->content->shares = $shares; // Get Reports // XXX: Might need to replace magic no. 8 with a constant $this->template->content->total_items = ORM::factory('incident')->where('incident_active', '1')->limit('8')->count_all(); $this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('14')->orderby('incident_date', 'desc')->with('location')->find_all(); // Get quick stats for "Latest Activity" // note: Kohana ORM doesn't support these fancy date search features $this->template->content->latest_activity_today = count($this->db->query('SELECT id FROM incident WHERE incident_dateadd >= DATE_SUB(CURDATE(),INTERVAL 0 DAY);')); $this->template->content->latest_activity_yesterday = count($this->db->query('SELECT id FROM incident WHERE incident_dateadd >= DATE_SUB(CURDATE(),INTERVAL 1 DAY) AND incident_dateadd < DATE_SUB(CURDATE(),INTERVAL 0 DAY);')); $this->template->content->latest_activity_week = count($this->db->query('SELECT id FROM incident WHERE incident_dateadd >= DATE_SUB(CURDATE(),INTERVAL 1 WEEK);')); $this->template->content->latest_activity_total_from_sms = Incident_Model::num_incidents_by_sms(); // End getting of quick stats for "Latest Activity" // Get Default Color $this->template->content->default_map_all = Kohana::config('settings.default_map_all'); // Get Twitter Hashtags $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags')))); // Get Report-To-Email $this->template->content->report_email = Kohana::config('settings.site_email'); // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; $this->template->header->phone_array = $phone_array; // Because we need some custom language around these numbers, // I'm just sending them straight to the template for "hardcoding" $this->template->content->sms_no1 = $sms_no1; $this->template->content->sms_no2 = $sms_no2; $this->template->header->sms_no1 = $sms_no1; $this->template->header->sms_no2 = $sms_no2; // Get RSS News Feeds but don't include Global Voices (8) $this->template->content->feeds = ORM::factory('feed_item')->limit('10')->where('feed_id !=', '8')->orderby('item_date', 'desc')->find_all(); // Get Global Voices Feed $this->template->content->gvfeeds = ORM::factory('feed_item')->limit('10')->where('feed_id', '8')->orderby('item_date', 'desc')->find_all(); // Get The START, END and most ACTIVE Incident Dates $startDate = ""; $endDate = ""; $active_month = 0; $active_startDate = 0; $active_endDate = 0; $db = new Database(); // First Get The Most Active Month $query = $db->query('SELECT incident_date, count(*) AS incident_count FROM incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y-%m\') ORDER BY incident_count DESC LIMIT 1'); foreach ($query as $query_active) { $active_month = date('n', strtotime($query_active->incident_date)); $active_year = date('Y', strtotime($query_active->incident_date)); $active_startDate = strtotime($active_year . "-" . $active_month . "-01"); $active_endDate = strtotime($active_year . "-" . $active_month . "-" . date('t', mktime(0, 0, 0, $active_month, 1)) . " 23:59:59"); } /** HARDCODED SLIDER SET UP **/ // We'll Hardcode in the Start/End Dates $timeframe_start = strtotime("2010-01-12", 0); $timeframe_stop = strtotime(date("Y-m-d"), 0); $active_startDate = $timeframe_start; $active_endDate = $timeframe_stop + 86399; $days = floor(($timeframe_stop - $timeframe_start) / 86400); $startDate = "<optgroup label=\"2010\">"; $endDate = "<optgroup label=\"2010\">"; for ($i = 0; $i <= $days; $i++) { $startDate .= "<option value=\"" . $timeframe_start . "\""; if ($i == 0) { $startDate .= " selected=\"selected\" "; } $startDate .= ">" . date('M j', $timeframe_start) . " 2010</option>"; $timeframe_stop = $timeframe_start + 86399; $endDate .= "<option value=\"" . $timeframe_stop . "\""; if ($i == $days) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M j', $timeframe_stop) . " 2010</option>"; $timeframe_start = $timeframe_start + 86400; } $startDate .= "</optgroup>"; $endDate .= "</optgroup>"; /** OLD SLIDER SET UP **/ // Next, Get the Range of Years // $query = $db->query('SELECT DATE_FORMAT(incident_date, \'%Y\') AS incident_date FROM incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y\') ORDER BY incident_date'); $query = array(); foreach ($query as $slider_date) { $years = $slider_date->incident_date; $startDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $startDate .= "<option value=\"" . strtotime($years . "-" . $i . "-01") . "\""; if ($active_month && (int) $i == $active_month - 1) { $startDate .= " selected=\"selected\" "; } $startDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $startDate .= "</optgroup>"; $endDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $endDate .= "<option value=\"" . strtotime($years . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59") . "\""; if ($active_month && (int) $i == $active_month + 1 || $i == 12) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $endDate .= "</optgroup>"; } $this->template->content->startDate = $startDate; $this->template->content->endDate = $endDate; //$this->template->content->startDate = '<select name="startDate" id="startDate"><optgroup label="2010"><option value="1262325600">Jan 2010</option></optgroup></select>'; //$this->template->content->endDate = '<select name="endDate" id="endDate"><optgroup label="2010"><option value="1265003999">Jan 2010</option><option value="1267423199" selected="selected" >Feb 2010</option></optgroup></select>'; // get graph data // could not use DB query builder. It does not support parentheses yet $graph_data = array(); $all_graphs = Incident_Model::get_incidents_by_interval('month'); $daily_graphs = Incident_Model::get_incidents_by_interval('day'); $weekly_graphs = Incident_Model::get_incidents_by_interval('week'); $hourly_graphs = Incident_Model::get_incidents_by_interval('hour'); $this->template->content->all_graphs = $all_graphs; $this->template->content->daily_graphs = $daily_graphs; // If we are looking at the standard street map set by user if (!isset($_GET['3dmap'])) { //echo 'STREET MAP'; // Javascript Header $this->template->header->map_enabled = 'streetmap'; $this->template->content->map_enabled = 'streetmap'; $this->template->content->map_container = 'map'; $this->template->header->main_page = TRUE; $this->template->header->validator_enabled = TRUE; // Map Settings $clustering = Kohana::config('settings.allow_clustering'); $marker_radius = Kohana::config('map.marker_radius'); $marker_opacity = Kohana::config('map.marker_opacity'); $marker_stroke_width = Kohana::config('map.marker_stroke_width'); $marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity'); $this->template->header->js = $clustering ? new View('main_cluster_js') : new View('main_js'); $this->template->header->js->cluster = $clustering == 1 ? "true" : "false"; $this->template->header->js->marker_radius = $marker_radius >= 1 && $marker_radius <= 10 ? $marker_radius : 5; $this->template->header->js->marker_opacity = $marker_opacity >= 1 && $marker_opacity <= 10 ? $marker_opacity * 0.1 : 0.9; $this->template->header->js->marker_stroke_width = $marker_stroke_width >= 1 && $marker_stroke_width <= 5 ? $marker_stroke_width : 2; $this->template->header->js->marker_stroke_opacity = $marker_stroke_opacity >= 1 && $marker_stroke_opacity <= 10 ? $marker_stroke_opacity * 0.1 : 0.9; $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); $this->template->header->js->graph_data = $graph_data; $this->template->header->js->all_graphs = $all_graphs; $this->template->header->js->daily_graphs = $daily_graphs; $this->template->header->js->hourly_graphs = $hourly_graphs; $this->template->header->js->weekly_graphs = $weekly_graphs; $this->template->header->js->default_map_all = Kohana::config('settings.default_map_all'); // $this->template->header->js->active_startDate = $active_startDate; $this->template->header->js->active_endDate = $active_endDate; // If we are viewing the 3D map } else { //echo '3D MAP'; // Javascript Header $this->template->header->map_enabled = '3dmap'; $this->template->content->map_enabled = '3dmap'; $this->template->content->map_container = 'map3d'; $this->template->header->main_page = FALSE; // Setting to false because we don't want all the external controls that the street map has $this->template->header->js = new View('main_3d_js'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); // Override API URL $this->template->header->api_url = '<script src="http://www.google.com/jsapi?key=' . Kohana::config('settings.api_google') . '"> </script>'; } $footerjs = new View('footer_form_js'); // Pack the javascript using the javascriptpacker helper $this->template->header->js .= $footerjs; $myPacker = new javascriptpacker($this->template->header->js, 'Normal', true, false); $this->template->header->js = $myPacker->pack(); }
public function index() { $this->template->header->this_page = 'home'; $this->template->content = new View('main'); // Get all active categories $categories = array(); foreach (ORM::factory('category')->where('category_visible', '1')->find_all() as $category) { // Create a list of all categories $categories[$category->id] = array($category->category_title, $category->category_color); } $this->template->content->categories = $categories; // Get all active Shares $shares = array(); foreach (ORM::factory('sharing')->where('sharing_active', 1)->where('sharing_type', 1)->find_all() as $share) { $shares[$share->id] = array($share->sharing_site_name, $share->sharing_color); } $this->template->content->shares = $shares; // Get Reports // XXX: Might need to replace magic no. 8 with a constant $this->template->content->total_items = ORM::factory('incident')->where('incident_active', '1')->limit('8')->count_all(); $this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_date', 'desc')->find_all(); // Get Default Color $this->template->content->default_map_all = Kohana::config('settings.default_map_all'); // Get Twitter Hashtags $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags')))); // Get Report-To-Email $this->template->content->report_email = Kohana::config('email.username'); // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->limit('10')->orderby('item_date', 'desc')->find_all(); // Get Slider Dates By Year $startDate = ""; $endDate = ""; // We need to use the DB builder for a custom query $db = new Database(); $query = $db->query('SELECT DATE_FORMAT(incident_date, \'%Y\') AS incident_date FROM incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y\') ORDER BY incident_date'); foreach ($query as $slider_date) { $startDate .= "<optgroup label=\"" . $slider_date->incident_date . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $startDate .= "<option value=\"" . strtotime($slider_date->incident_date . "-" . $i . "-01") . "\">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $slider_date->incident_date . "</option>"; } $startDate .= "</optgroup>"; $endDate .= "<optgroup label=\"" . $slider_date->incident_date . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $endDate .= "<option value=\"" . strtotime($slider_date->incident_date . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1))) . "\""; if ($i == 12) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $slider_date->incident_date . "</option>"; } $endDate .= "</optgroup>"; } $this->template->content->startDate = $startDate; $this->template->content->endDate = $endDate; // get graph data // could not use DB query builder. It does not support parentheses yet $graph_data = array(); $all_graphs = Incident_Model::get_incidents_by_interval('month'); $daily_graphs = Incident_Model::get_incidents_by_interval('day'); $weekly_graphs = Incident_Model::get_incidents_by_interval('week'); $hourly_graphs = Incident_Model::get_incidents_by_interval('hour'); $this->template->content->all_graphs = $all_graphs; $this->template->content->daily_graphs = $daily_graphs; // Javascript Header $this->template->header->map_enabled = TRUE; $this->template->header->main_page = TRUE; // Map Settings $clustering = Kohana::config('settings.allow_clustering'); $marker_radius = Kohana::config('map.marker_radius'); $marker_opacity = Kohana::config('map.marker_opacity'); $marker_stroke_width = Kohana::config('map.marker_stroke_width'); $marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity'); $this->template->header->js = $clustering == 1 ? new View('main_cluster_js') : new View('main_js'); $this->template->header->js->marker_radius = $marker_radius >= 1 && $marker_radius <= 10 ? $marker_radius : 5; $this->template->header->js->marker_opacity = $marker_opacity >= 1 && $marker_opacity <= 10 ? $marker_opacity * 0.1 : 0.9; $this->template->header->js->marker_stroke_width = $marker_stroke_width >= 1 && $marker_stroke_width <= 5 ? $marker_stroke_width : 2; $this->template->header->js->marker_stroke_opacity = $marker_stroke_opacity >= 1 && $marker_stroke_opacity <= 10 ? $marker_stroke_opacity * 0.1 : 0.9; $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); $this->template->header->js->graph_data = $graph_data; $this->template->header->js->all_graphs = $all_graphs; $this->template->header->js->daily_graphs = $daily_graphs; $this->template->header->js->hourly_graphs = $hourly_graphs; $this->template->header->js->weekly_graphs = $weekly_graphs; $this->template->header->js->categories = $categories; $this->template->header->js->default_map_all = Kohana::config('settings.default_map_all'); //$this->template->header->footerjs = new View('footer_form_js'); $footerjs = new View('footer_form_js'); // Pack the javascript using the javascriptpacker helper $myPacker = new javascriptpacker($footerjs, 'Normal', false, false); $footerjs = $myPacker->pack(); $this->template->header->js .= $footerjs; }
/** * Displays a report. * @param boolean $id If id is supplied, a report with that id will be * retrieved. */ public function view($id = false) { $this->template->header->this_page = 'reports'; $this->template->content = new View('reports_view'); if (!$id) { url::redirect('main'); } else { $incident = ORM::factory('incident', $id); if ($incident->id == 0) { url::redirect('main'); } // Comment Post? // Setup and initialize form field names $form = array('comment_author' => '', 'comment_description' => '', 'comment_email' => '', 'comment_ip' => '', 'captcha' => ''); $captcha = Captcha::factory(); $errors = $form; $form_error = FALSE; // 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('comment_author', 'required', 'length[3,100]'); $post->add_rules('comment_description', 'required'); $post->add_rules('comment_email', 'required', 'email', 'length[4,100]'); $post->add_rules('captcha', 'required', 'Captcha::valid'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $comment = new Comment_Model(); $comment->incident_id = $id; $comment->comment_author = $post->comment_author; $comment->comment_description = $post->comment_description; $comment->comment_email = $post->comment_email; $comment->comment_ip = $_SERVER['REMOTE_ADDR']; $comment->comment_date = date("Y-m-d H:i:s", time()); // Activate comment for now $comment->comment_active = 1; $comment->save(); // Redirect url::redirect('reports/view/' . $id); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('comments')); $form_error = TRUE; } } $this->template->content->incident_id = $incident->id; $this->template->content->incident_title = $incident->incident_title; $this->template->content->incident_description = nl2br($incident->incident_description); $this->template->content->incident_location = $incident->location->location_name; $this->template->content->incident_latitude = $incident->location->latitude; $this->template->content->incident_longitude = $incident->location->longitude; $this->template->content->incident_date = date('M j Y', strtotime($incident->incident_date)); $this->template->content->incident_time = date('H:i', strtotime($incident->incident_date)); $this->template->content->incident_category = $incident->incident_category; if ($incident->incident_rating == '') { $this->template->content->incident_rating = 0; } else { $this->template->content->incident_rating = $incident->incident_rating; } // Retrieve Media $incident_news = array(); $incident_video = array(); $incident_photo = array(); foreach ($incident->media as $media) { if ($media->media_type == 4) { $incident_news[] = $media->media_link; } elseif ($media->media_type == 2) { $incident_video[] = $media->media_link; } elseif ($media->media_type == 1) { $incident_photo[] = $media->media_link; } } $this->template->content->incident_verified = $incident->incident_verified; // Retrieve Comments (Additional Information) $incident_comments = array(); if ($id) { $incident_comments = ORM::factory('comment')->where('incident_id', $id)->where('comment_active', '1')->orderby('comment_date', 'asc')->find_all(); } $this->template->content->incident_comments = $incident_comments; } // Add Neighbors $this->template->content->incident_neighbors = $this->_get_neighbors($incident->location->latitude, $incident->location->longitude); // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->limit('5')->orderby('item_date', 'desc')->find_all(); // Video links $this->template->content->incident_videos = $incident_video; // Create object of the video embed class $video_embed = new VideoEmbed(); $this->template->content->videos_embed = $video_embed; // Javascript Header $this->template->header->map_enabled = TRUE; $this->template->header->photoslider_enabled = TRUE; $this->template->header->videoslider_enabled = TRUE; $this->template->header->js = new View('reports_view_js'); $this->template->header->js->incident_id = $incident->id; $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = $incident->location->latitude; $this->template->header->js->longitude = $incident->location->longitude; $this->template->header->js->incident_photos = $incident_photo; // Pack the javascript using the javascriptpacker helper $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false); $this->template->header->js = $myPacker->pack(); // Forms $this->template->content->form = $form; $this->template->content->captcha = $captcha; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; }
public function index() { $this->template->header->this_page = 'home'; $this->template->content = new View('main'); $this->template->content->set("user", $this->user); // What instances to show? $db = new Database(); $dbs = array(); $show_user = $this->user ? " OR user_id = " . $this->user->id . " " : ""; $sites = $db->query("SELECT id,dbdatabase,sitename,subdomain,tagline FROM sites WHERE is_approved AND (is_public {$show_user})"); $this->template->content->set("sites", $sites); $shares = array(); // Get all active top level categories $parent_categories = array(); foreach ($sites as $category) { // Create a list of all sites $parent_categories[$category->id] = array($category->sitename, $this->_id2color($category->id)); $shares[$category->id] = array($category->sitename, $this->_id2color($category->id), $category->subdomain); array_push($dbs, $category->dbdatabase); } $this->template->content->categories = $parent_categories; // Get all active Layers (KMZ/KML) $layers = array(); foreach (ORM::factory('layer')->where('layer_visible', 1)->find_all() as $layer) { $layers[$layer->id] = array($layer->layer_name, $layer->layer_color, $layer->layer_url, $layer->layer_file); } $this->template->content->layers = $layers; // Get all active Shares $this->template->content->shares = $shares; // Get Reports // XXX: Might need to replace magic no. 8 with a constant $this->template->content->total_items = ORM::factory('incident')->where('incident_active', '1')->limit('8')->count_all(); $this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_date', 'desc')->with('location')->find_all(); // Get Default Color $this->template->content->default_map_all = Kohana::config('settings.default_map_all'); // Get Twitter Hashtags $this->template->content->twitter_hashtag_array = array_filter(array_map('trim', explode(',', Kohana::config('settings.twitter_hashtags')))); // Get Report-To-Email $this->template->content->report_email = Kohana::config('settings.site_email'); // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->limit('10')->orderby('item_date', 'desc')->find_all(); // Get The START, END and most ACTIVE Incident Dates $startDate = ""; $endDate = ""; $active_month = 0; $active_startDate = 0; $active_endDate = 0; // First Get The Most Active Month $query = $db->query('SELECT incident_date, count(*) AS incident_count FROM incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y-%m\') ORDER BY incident_count DESC LIMIT 1'); foreach ($query as $query_active) { $active_month = date('n', strtotime($query_active->incident_date)); $active_year = date('Y', strtotime($query_active->incident_date)); $active_startDate = strtotime($active_year . "-" . $active_month . "-01"); $active_endDate = strtotime($active_year . "-" . $active_month . "-" . date('t', mktime(0, 0, 0, $active_month, 1)) . " 23:59:59"); } // Next, Get the Range of Years $query = $db->query('SELECT DATE_FORMAT(incident_date, \'%Y\') AS incident_date FROM incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y\') ORDER BY incident_date'); foreach ($query as $slider_date) { $years = $slider_date->incident_date; $startDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $startDate .= "<option value=\"" . strtotime($years . "-" . $i . "-01") . "\""; if ($active_month && (int) $i == $active_month - 1) { $startDate .= " selected=\"selected\" "; } $startDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $startDate .= "</optgroup>"; $endDate .= "<optgroup label=\"" . $years . "\">"; for ($i = 1; $i <= 12; $i++) { if ($i < 10) { $i = "0" . $i; } $endDate .= "<option value=\"" . strtotime($years . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1)) . " 23:59:59") . "\""; if ($active_month && (int) $i == $active_month + 1 || $i == 12) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $years . "</option>"; } $endDate .= "</optgroup>"; } $this->template->content->startDate = $startDate; $this->template->content->endDate = $endDate; // get graph data // could not use DB query builder. It does not support parentheses yet $graph_data = array(); $all_graphs = Incident_Model::get_incidents_by_interval('month'); $daily_graphs = Incident_Model::get_incidents_by_interval('day'); $weekly_graphs = Incident_Model::get_incidents_by_interval('week'); $hourly_graphs = Incident_Model::get_incidents_by_interval('hour'); $this->template->content->all_graphs = $all_graphs; $this->template->content->daily_graphs = $daily_graphs; // If we are looking at the standard street map set by user if (!isset($_GET['3dmap'])) { //echo 'STREET MAP'; // Javascript Header $this->template->header->map_enabled = 'streetmap'; $this->template->content->map_enabled = 'streetmap'; $this->template->content->map_container = 'map'; $this->template->header->main_page = TRUE; $this->template->header->validator_enabled = TRUE; // Map Settings $clustering = Kohana::config('settings.allow_clustering'); $marker_radius = Kohana::config('map.marker_radius'); $marker_opacity = Kohana::config('map.marker_opacity'); $marker_stroke_width = Kohana::config('map.marker_stroke_width'); $marker_stroke_opacity = Kohana::config('map.marker_stroke_opacity'); $this->template->header->js = new View('main_cluster_js'); $this->template->header->js->cluster = $clustering == 1 ? "true" : "false"; $this->template->header->js->marker_radius = $marker_radius >= 1 && $marker_radius <= 10 ? $marker_radius : 5; $this->template->header->js->marker_opacity = $marker_opacity >= 1 && $marker_opacity <= 10 ? $marker_opacity * 0.1 : 0.9; $this->template->header->js->marker_stroke_width = $marker_stroke_width >= 1 && $marker_stroke_width <= 5 ? $marker_stroke_width : 2; $this->template->header->js->marker_stroke_opacity = $marker_stroke_opacity >= 1 && $marker_stroke_opacity <= 10 ? $marker_stroke_opacity * 0.1 : 0.9; $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); $this->template->header->js->graph_data = $graph_data; $this->template->header->js->all_graphs = $all_graphs; $this->template->header->js->daily_graphs = $daily_graphs; $this->template->header->js->hourly_graphs = $hourly_graphs; $this->template->header->js->weekly_graphs = $weekly_graphs; $this->template->header->js->default_map_all = Kohana::config('settings.default_map_all'); // $this->template->header->js->active_startDate = $active_startDate; $this->template->header->js->active_endDate = $active_endDate; // If we are viewing the 3D map } else { //echo '3D MAP'; // Javascript Header $this->template->header->map_enabled = '3dmap'; $this->template->content->map_enabled = '3dmap'; $this->template->content->map_container = 'map3d'; $this->template->header->main_page = FALSE; // Setting to false because we don't want all the external controls that the street map has $this->template->header->js = new View('main_3d_js'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); // Override API URL $this->template->header->api_url = '<script src="http://www.google.com/jsapi?key=' . Kohana::config('settings.api_google') . '"> </script>'; } $footerjs = new View('footer_form_js'); // Pack the javascript using the javascriptpacker helper $this->template->header->js .= $footerjs; $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false); $this->template->header->js = $myPacker->pack(); }
/** * Edit a report * @param bool|int $id The id no. of the report * @param bool|string $saved */ function edit($id = false, $saved = false) { $db = new Database(); // If user doesn't have access, redirect to dashboard if (!admin::permissions($this->user, "reports_edit")) { url::redirect(url::site() . 'admin/dashboard'); } $this->template->content = new View('admin/reports_edit'); $this->template->content->title = Kohana::lang('ui_admin.create_report'); // setup and initialize form field names $form = array('location_id' => '', 'form_id' => '', 'locale' => '', 'incident_title' => '', 'incident_description' => '', 'incident_date' => '', 'incident_hour' => '', 'incident_minute' => '', 'incident_ampm' => '', 'latitude' => '', 'longitude' => '', 'geometry' => array(), 'location_name' => '', 'country_id' => '', 'incident_category' => array(), 'incident_news' => array(), 'incident_video' => array(), 'incident_photo' => array(), 'person_first' => '', 'person_last' => '', 'person_email' => '', 'custom_field' => array(), 'incident_active' => '', 'incident_verified' => '', 'incident_source' => '', 'incident_information' => '', 'incident_zoom' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; if ($saved == 'saved') { $form_saved = TRUE; } else { $form_saved = FALSE; } // Initialize Default Values $form['locale'] = Kohana::config('locale.language'); //$form['latitude'] = Kohana::config('settings.default_lat'); //$form['longitude'] = Kohana::config('settings.default_lon'); $form['country_id'] = Kohana::config('settings.default_country'); $form['incident_date'] = date("m/d/Y", time()); $form['incident_hour'] = date('g'); $form['incident_minute'] = date('i'); $form['incident_ampm'] = date('a'); // initialize custom field array $form['custom_field'] = $this->_get_custom_form_fields($id, '', true); // Locale (Language) Array $this->template->content->locale_array = Kohana::config('locale.all_languages'); // Create Categories $this->template->content->categories = $this->_get_categories(); $this->template->content->new_categories_form = $this->_new_categories_form_arr(); // Time formatting $this->template->content->hour_array = $this->_hour_array(); $this->template->content->minute_array = $this->_minute_array(); $this->template->content->ampm_array = $this->_ampm_array(); $this->template->content->stroke_width_array = $this->_stroke_width_array(); // Get Countries $countries = array(); foreach (ORM::factory('country')->orderby('country')->find_all() as $country) { // Create a list of all categories $this_country = $country->country; if (strlen($this_country) > 35) { $this_country = substr($this_country, 0, 35) . "..."; } $countries[$country->id] = $this_country; } $this->template->content->countries = $countries; //GET custom forms $forms = array(); foreach (ORM::factory('form')->where('form_active', 1)->find_all() as $custom_forms) { $forms[$custom_forms->id] = $custom_forms->form_title; } $this->template->content->forms = $forms; // Retrieve thumbnail photos (if edit); //XXX: fix _get_thumbnails $this->template->content->incident = $this->_get_thumbnails($id); // Are we creating this report from SMS/Email/Twitter? // If so retrieve message if (isset($_GET['mid']) && !empty($_GET['mid'])) { $message_id = $_GET['mid']; $service_id = ""; $message = ORM::factory('message', $message_id); if ($message->loaded == true && $message->message_type == 1) { $service_id = $message->reporter->service_id; // Has a report already been created for this Message? if ($message->incident_id != 0) { // Redirect to report url::redirect('admin/reports/edit/' . $message->incident_id); } $this->template->content->show_messages = true; $incident_description = $message->message; if (!empty($message->message_detail)) { $form['incident_title'] = $message->message; $incident_description = $message->message_detail; } $form['incident_description'] = $incident_description; $form['incident_date'] = date('m/d/Y', strtotime($message->message_date)); $form['incident_hour'] = date('h', strtotime($message->message_date)); $form['incident_minute'] = date('i', strtotime($message->message_date)); $form['incident_ampm'] = date('a', strtotime($message->message_date)); $form['person_first'] = $message->reporter->reporter_first; $form['person_last'] = $message->reporter->reporter_last; // Does the sender of this message have a location? if ($message->reporter->location->loaded) { $form['latitude'] = $message->reporter->location->latitude; $form['longitude'] = $message->reporter->location->longitude; $form['location_name'] = $message->reporter->location->location_name; } // Retrieve Last 5 Messages From this account $this->template->content->all_messages = ORM::factory('message')->where('reporter_id', $message->reporter_id)->orderby('message_date', 'desc')->limit(5)->find_all(); } else { $message_id = ""; $this->template->content->show_messages = false; } } else { $this->template->content->show_messages = false; } // Are we creating this report from a Newsfeed? if (isset($_GET['fid']) && !empty($_GET['fid'])) { $feed_item_id = $_GET['fid']; $feed_item = ORM::factory('feed_item', $feed_item_id); if ($feed_item->loaded == true) { // Has a report already been created for this Feed item? if ($feed_item->incident_id != 0) { // Redirect to report url::redirect('admin/reports/edit/' . $feed_item->incident_id); } $form['incident_title'] = $feed_item->item_title; $form['incident_description'] = $feed_item->item_description; $form['incident_date'] = date('m/d/Y', strtotime($feed_item->item_date)); $form['incident_hour'] = date('h', strtotime($feed_item->item_date)); $form['incident_minute'] = date('i', strtotime($feed_item->item_date)); $form['incident_ampm'] = date('a', strtotime($feed_item->item_date)); // News Link $form['incident_news'][0] = $feed_item->item_link; // Does this newsfeed have a geolocation? if ($feed_item->location_id) { $form['location_id'] = $feed_item->location_id; $form['latitude'] = $feed_item->location->latitude; $form['longitude'] = $feed_item->location->longitude; $form['location_name'] = $feed_item->location->location_name; } } else { $feed_item_id = ""; } } // 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(array_merge($_POST, $_FILES)); // 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('locale','required','alpha_dash','length[5]'); $post->add_rules('location_id', 'numeric'); $post->add_rules('message_id', 'numeric'); $post->add_rules('incident_title', 'required', 'length[3,200]'); $post->add_rules('incident_description', 'required'); $post->add_rules('incident_date', 'required', 'date_mmddyyyy'); $post->add_rules('incident_hour', 'required', 'between[1,12]'); $post->add_rules('incident_minute', 'required', 'between[0,59]'); if ($_POST['incident_ampm'] != "am" && $_POST['incident_ampm'] != "pm") { $post->add_error('incident_ampm', 'values'); } $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]'); //XXX: Hack to validate for no checkboxes checked if (!isset($_POST['incident_category'])) { $post->incident_category = ""; $post->add_error('incident_category', 'required'); } else { $post->add_rules('incident_category.*', 'required', 'numeric'); } // Validate only the fields that are filled in if (!empty($_POST['incident_news'])) { foreach ($_POST['incident_news'] as $key => $url) { if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) { $post->add_error('incident_news', 'url'); } } } // Validate only the fields that are filled in if (!empty($_POST['incident_video'])) { foreach ($_POST['incident_video'] as $key => $url) { if (!empty($url) and !(bool) filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) { $post->add_error('incident_video', 'url'); } } } // Validate photo uploads $post->add_rules('incident_photo', 'upload::valid', 'upload::type[gif,jpg,png]', 'upload::size[2M]'); // Validate Personal Information if (!empty($_POST['person_first'])) { $post->add_rules('person_first', 'length[3,100]'); } if (!empty($_POST['person_last'])) { $post->add_rules('person_last', 'length[3,100]'); } if (!empty($_POST['person_email'])) { $post->add_rules('person_email', 'email', 'length[3,100]'); } // Validate Custom Fields if (isset($post->custom_field) && !$this->_validate_custom_form_fields($post->custom_field)) { $post->add_error('custom_field', 'values'); } $post->add_rules('incident_active', 'required', 'between[0,1]'); $post->add_rules('incident_verified', 'required', 'length[0,1]'); $post->add_rules('incident_source', 'numeric', 'length[1,1]'); $post->add_rules('incident_information', 'numeric', 'length[1,1]'); // Action::report_submit_admin - Report Posted Event::run('ushahidi_action.report_submit_admin', $post); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $location_id = $post->location_id; // STEP 1a: SAVE LOCATION $location = new Location_Model($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(); // STEP 2: SAVE INCIDENT $incident = new Incident_Model($id); $incident->location_id = $location->id; //$incident->locale = $post->locale; $incident->form_id = $post->form_id; $incident->user_id = $_SESSION['auth_user']->id; $incident->incident_title = $post->incident_title; $incident->incident_description = $post->incident_description; $incident_date = explode("/", $post->incident_date); // where the $_POST['date'] is a value posted by form in mm/dd/yyyy format $incident_date = $incident_date[2] . "-" . $incident_date[0] . "-" . $incident_date[1]; $incident_time = $post->incident_hour . ":" . $post->incident_minute . ":00 " . $post->incident_ampm; $incident->incident_date = date("Y-m-d H:i:s", strtotime($incident_date . " " . $incident_time)); // Is this new or edit? if ($id) { $incident->incident_datemodify = date("Y-m-d H:i:s", time()); } else { $incident->incident_dateadd = date("Y-m-d H:i:s", time()); } // Is this an Email, SMS, Twitter submitted report? //XXX: We may get rid of incident_mode altogether... ??? //$_POST if (!empty($service_id)) { if ($service_id == 1) { // SMS $incident->incident_mode = 2; } elseif ($service_id == 2) { // Email $incident->incident_mode = 3; } elseif ($service_id == 3) { // Twitter $incident->incident_mode = 4; } elseif ($service_id == 4) { // Laconica $incident->incident_mode = 5; } } // Incident Evaluation Info $incident->incident_active = $post->incident_active; $incident->incident_verified = $post->incident_verified; $incident->incident_source = $post->incident_source; $incident->incident_information = $post->incident_information; $incident->incident_zoom = (int) $post->incident_zoom; //Save $incident->save(); // Tag this as a report that needs to be sent out as an alert if ($incident->incident_active == '1' and $incident->incident_alert_status != '2') { // 2 = report that has had an alert sent $incident->incident_alert_status = '1'; $incident->save(); } // Remove alert if report is unactivated and alert hasn't yet been sent if ($incident->incident_active == '0' and $incident->incident_alert_status == '1') { $incident->incident_alert_status = '0'; $incident->save(); } // Record Approval/Verification Action $verify = new Verify_Model(); $verify->incident_id = $incident->id; $verify->user_id = $_SESSION['auth_user']->id; // Record 'Verified By' Action $verify->verified_date = date("Y-m-d H:i:s", time()); if ($post->incident_active == 1) { $verify->verified_status = '1'; } elseif ($post->incident_verified == 1) { $verify->verified_status = '2'; } elseif ($post->incident_active == 1 && $post->incident_verified == 1) { $verify->verified_status = '3'; } else { $verify->verified_status = '0'; } $verify->save(); // STEP 2b: SAVE INCIDENT GEOMETRIES ORM::factory('geometry')->where('incident_id', $incident->id)->delete_all(); if (isset($post->geometry)) { foreach ($post->geometry as $item) { if (!empty($item)) { //Decode JSON $item = json_decode($item); //++ TODO - validate geometry $geometry = isset($item->geometry) ? mysql_escape_string($item->geometry) : ""; $label = isset($item->label) ? mysql_escape_string(substr($item->label, 0, 150)) : ""; $comment = isset($item->comment) ? mysql_escape_string(substr($item->comment, 0, 255)) : ""; $color = isset($item->color) ? mysql_escape_string(substr($item->color, 0, 6)) : ""; $strokewidth = (isset($item->strokewidth) and (double) $item->strokewidth) ? (double) $item->strokewidth : "2.5"; if ($geometry) { //++ Can't Use ORM for this $sql = "INSERT INTO " . Kohana::config('database.default.table_prefix') . "geometry (\n\t\t\t\t\t\t\t\t\tincident_id, geometry, geometry_label, geometry_comment, geometry_color, geometry_strokewidth ) \n\t\t\t\t\t\t\t\t\tVALUES( " . $incident->id . ",\n\t\t\t\t\t\t\t\t\tGeomFromText( '" . $geometry . "' ),'" . $label . "','" . $comment . "','" . $color . "','" . $strokewidth . "')"; $db->query($sql); } } } } // STEP 3: SAVE CATEGORIES ORM::factory('Incident_Category')->where('incident_id', $incident->id)->delete_all(); // Delete Previous Entries foreach ($post->incident_category as $item) { $incident_category = new Incident_Category_Model(); $incident_category->incident_id = $incident->id; $incident_category->category_id = $item; $incident_category->save(); } // STEP 4: SAVE MEDIA ORM::factory('Media')->where('incident_id', $incident->id)->where('media_type <> 1')->delete_all(); // Delete Previous Entries // a. News foreach ($post->incident_news as $item) { if (!empty($item)) { $news = new Media_Model(); $news->location_id = $location->id; $news->incident_id = $incident->id; $news->media_type = 4; // News $news->media_link = $item; $news->media_date = date("Y-m-d H:i:s", time()); $news->save(); } } // b. Video foreach ($post->incident_video as $item) { if (!empty($item)) { $video = new Media_Model(); $video->location_id = $location->id; $video->incident_id = $incident->id; $video->media_type = 2; // Video $video->media_link = $item; $video->media_date = date("Y-m-d H:i:s", time()); $video->save(); } } // c. Photos $filenames = upload::save('incident_photo'); $i = 1; foreach ($filenames as $filename) { $new_filename = $incident->id . "_" . $i . "_" . time(); $file_type = strrev(substr(strrev($filename), 0, 4)); // IMAGE SIZES: 800X600, 400X300, 89X59 // Large size Image::factory($filename)->resize(800, 600, Image::AUTO)->save(Kohana::config('upload.directory', TRUE) . $new_filename . $file_type); // Medium size Image::factory($filename)->resize(400, 300, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_m" . $file_type); // Thumbnail Image::factory($filename)->resize(89, 59, Image::HEIGHT)->save(Kohana::config('upload.directory', TRUE) . $new_filename . "_t" . $file_type); // Remove the temporary file unlink($filename); // Save to DB $photo = new Media_Model(); $photo->location_id = $location->id; $photo->incident_id = $incident->id; $photo->media_type = 1; // Images $photo->media_link = $new_filename . $file_type; $photo->media_medium = $new_filename . "_m" . $file_type; $photo->media_thumb = $new_filename . "_t" . $file_type; $photo->media_date = date("Y-m-d H:i:s", time()); $photo->save(); $i++; } // STEP 5: SAVE PERSONAL INFORMATION ORM::factory('Incident_Person')->where('incident_id', $incident->id)->delete_all(); // Delete Previous Entries $person = new Incident_Person_Model(); $person->location_id = $location->id; $person->incident_id = $incident->id; $person->person_first = $post->person_first; $person->person_last = $post->person_last; $person->person_email = $post->person_email; $person->person_date = date("Y-m-d H:i:s", time()); $person->save(); // STEP 6a: SAVE LINK TO REPORTER MESSAGE // We're creating a report from a message with this option if (isset($message_id) && $message_id != "") { $savemessage = ORM::factory('message', $message_id); if ($savemessage->loaded == true) { $savemessage->incident_id = $incident->id; $savemessage->save(); // Does Message Have Attachments? // Add Attachments $attachments = ORM::factory("media")->where("message_id", $savemessage->id)->find_all(); foreach ($attachments as $attachment) { $attachment->incident_id = $incident->id; $attachment->save(); } } } // STEP 6b: SAVE LINK TO NEWS FEED // We're creating a report from a newsfeed with this option if (isset($feed_item_id) && $feed_item_id != "") { $savefeed = ORM::factory('feed_item', $feed_item_id); if ($savefeed->loaded == true) { $savefeed->incident_id = $incident->id; $savefeed->location_id = $location->id; $savefeed->save(); } } // STEP 7: SAVE CUSTOM FORM FIELDS if (isset($post->custom_field)) { foreach ($post->custom_field as $key => $value) { $form_response = ORM::factory('form_response')->where('form_field_id', $key)->where('incident_id', $incident->id)->find(); if ($form_response->loaded == true) { $form_response->form_field_id = $key; $form_response->form_response = $value; $form_response->save(); } else { $form_response = new Form_Response_Model(); $form_response->form_field_id = $key; $form_response->incident_id = $incident->id; $form_response->form_response = $value; $form_response->save(); } } } // Action::report_edit - Edited a Report Event::run('ushahidi_action.report_edit', $incident); // SAVE AND CLOSE? switch ($post->save) { // Save but don't close case 1: case 'dontclose': url::redirect('admin/reports/edit/' . $incident->id . '/saved'); break; // Save and add new // Save and add new case 'addnew': url::redirect('admin/reports/edit/0/saved'); break; // Save and close // Save and close default: url::redirect('admin/reports/'); } } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('report')); $form_error = TRUE; } } else { if ($id) { // Retrieve Current Incident $incident = ORM::factory('incident', $id); if ($incident->loaded == true) { // Retrieve Categories $incident_category = array(); foreach ($incident->incident_category as $category) { $incident_category[] = $category->category_id; } // Retrieve Media $incident_news = array(); $incident_video = array(); $incident_photo = array(); foreach ($incident->media as $media) { if ($media->media_type == 4) { $incident_news[] = $media->media_link; } elseif ($media->media_type == 2) { $incident_video[] = $media->media_link; } elseif ($media->media_type == 1) { $incident_photo[] = $media->media_link; } } // Get Geometries via SQL query as ORM can't handle Spatial Data $sql = "SELECT AsText(geometry) as geometry, geometry_label, \n\t\t\t\t\t\tgeometry_comment, geometry_color, geometry_strokewidth \n\t\t\t\t\t\tFROM " . Kohana::config('database.default.table_prefix') . "geometry \n\t\t\t\t\t\tWHERE incident_id=" . $id; $query = $db->query($sql); foreach ($query as $item) { $form['geometry'][] = $item; } // Combine Everything $incident_arr = array('location_id' => $incident->location->id, 'form_id' => $incident->form_id, 'locale' => $incident->locale, 'incident_title' => $incident->incident_title, 'incident_description' => $incident->incident_description, 'incident_date' => date('m/d/Y', strtotime($incident->incident_date)), 'incident_hour' => date('h', strtotime($incident->incident_date)), 'incident_minute' => date('i', strtotime($incident->incident_date)), 'incident_ampm' => date('a', strtotime($incident->incident_date)), 'latitude' => $incident->location->latitude, 'longitude' => $incident->location->longitude, 'location_name' => $incident->location->location_name, 'country_id' => $incident->location->country_id, 'incident_category' => $incident_category, 'incident_news' => $incident_news, 'incident_video' => $incident_video, 'incident_photo' => $incident_photo, 'person_first' => $incident->incident_person->person_first, 'person_last' => $incident->incident_person->person_last, 'person_email' => $incident->incident_person->person_email, 'custom_field' => $this->_get_custom_form_fields($id, $incident->form_id, true), 'incident_active' => $incident->incident_active, 'incident_verified' => $incident->incident_verified, 'incident_source' => $incident->incident_source, 'incident_information' => $incident->incident_information, 'incident_zoom' => $incident->incident_zoom); // Merge To Form Array For Display $form = arr::overwrite($form, $incident_arr); } else { // Redirect url::redirect('admin/reports/'); } } } $this->template->content->id = $id; $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; // Retrieve Custom Form Fields Structure $disp_custom_fields = $this->_get_custom_form_fields($id, $form['form_id'], false); $this->template->content->disp_custom_fields = $disp_custom_fields; // Retrieve Previous & Next Records $previous = ORM::factory('incident')->where('id < ', $id)->orderby('id', 'desc')->find(); $previous_url = $previous->loaded ? url::base() . 'admin/reports/edit/' . $previous->id : url::base() . 'admin/reports/'; $next = ORM::factory('incident')->where('id > ', $id)->orderby('id', 'desc')->find(); $next_url = $next->loaded ? url::base() . 'admin/reports/edit/' . $next->id : url::base() . 'admin/reports/'; $this->template->content->previous_url = $previous_url; $this->template->content->next_url = $next_url; // Javascript Header $this->template->map_enabled = TRUE; $this->template->colorpicker_enabled = TRUE; $this->template->treeview_enabled = TRUE; $this->template->js = new View('admin/reports_edit_js'); $this->template->js->default_map = Kohana::config('settings.default_map'); $this->template->js->default_zoom = Kohana::config('settings.default_zoom'); if (!$form['latitude'] || !$form['latitude']) { $this->template->js->latitude = Kohana::config('settings.default_lat'); $this->template->js->longitude = Kohana::config('settings.default_lon'); } else { $this->template->js->latitude = $form['latitude']; $this->template->js->longitude = $form['longitude']; } $this->template->js->incident_zoom = $form['incident_zoom']; $this->template->js->geometries = $form['geometry']; // Inline Javascript $this->template->content->date_picker_js = $this->_date_picker_js(); $this->template->content->color_picker_js = $this->_color_picker_js(); $this->template->content->new_category_toggle_js = $this->_new_category_toggle_js(); // Pack Javascript $myPacker = new javascriptpacker($this->template->js, 'Normal', false, false); $this->template->js = $myPacker->pack(); }
public function index() { $this->template->header->this_page = 'home'; $this->template->content = new View($this->view_lang . '/main'); // Get all active categories $categories = array(); foreach (ORM::factory('category')->where('category_visible', '1')->find_all() as $category) { // Create a list of all categories $categories[$category->id] = array($category->category_title, $category->category_color); } $this->template->content->categories = $categories; // See if we posted anything $post = $this->input->post(); $this->template->content->post = $post; $this->template->content->user_signup_good = false; // Save the user signup data, if availible if ($post) { $user_signup = ORM::factory('user_signup'); // If the post data validates using the rules setup in the model. if ($user_signup->validate($post)) { $this->template->content->user_signup_good = true; $user_signup->save(); } else { $this->template->content->post = $post; } } // Get Reports // XXX: Might need to replace magic no. 8 with a constant $this->template->content->total_items = ORM::factory('incident')->where('incident_active', '1')->limit('8')->count_all(); $this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_date', 'desc')->find_all(); // Get SMS Numbers $phone_array = array(); $sms_no1 = Kohana::config('settings.sms_no1'); $sms_no2 = Kohana::config('settings.sms_no2'); $sms_no3 = Kohana::config('settings.sms_no3'); if (!empty($sms_no1)) { $phone_array[] = $sms_no1; } if (!empty($sms_no2)) { $phone_array[] = $sms_no2; } if (!empty($sms_no3)) { $phone_array[] = $sms_no3; } $this->template->content->phone_array = $phone_array; // Get the RSS blog feed $this->template->content->blog_feed = fetch_rss(Kohana::config('settings.blog_rss_url')); // Get RSS News Feeds $this->template->content->feeds = ORM::factory('feed_item')->where('feed_type', FEED_TYPE_TEXT)->limit('10')->orderby('item_date', 'desc')->find_all(); // Get video RSS feeds $this->template->content->video_feeds = ORM::factory('feed_item')->where('feed_type', FEED_TYPE_VIDEO)->limit('3')->orderby('item_date', 'desc')->find_all(); // Get photo RSS feeds $this->template->content->photo_feeds = ORM::factory('feed_item')->where('feed_type', FEED_TYPE_PHOTO)->limit('4')->orderby('item_date', 'desc')->find_all(); // Get Slider Dates By Year $startDate = ""; $endDate = ""; // Get the ladeleb.org info $cache_name = MAGPIE_CACHE_DIR . "/lade_feed"; $mtime = 0; if (file_exists($cache_name)) { $mtime = filemtime($cache_name); } $lade_reps = array(); $ctx = stream_context_create(array('http' => array('timeout' => 10))); if (!$mtime || time() - $mtime > LADE_FEED_REFRESH) { $lade_raw = @file_get_contents(LADE_FEED_URL, 0, $ctx); if (!$lade_raw) { $lade_raw = ""; } $lade_reports; preg_match_all('/<div class="NewsPTitle"><a href="(.*?)">\\n(.*?)\\n<\\/div>/', $lade_raw, $lade_reports); for ($i = 0; $i < count($lade_reports[1]); $i++) { array_push($lade_reps, array('http://www.observe.ladeleb.org' . $lade_reports[1][$i], $lade_reports[2][$i])); if ($i >= MAX_LADE_FEED) { break; } } if ($lade_raw) { file_put_contents($cache_name, serialize($lade_reps)); } else { touch($cache_name); } } else { $lade_reps = unserialize(file_get_contents($cache_name)); } $this->template->content->lade_reports = $lade_reps; // We need to use the DB builder for a custom query $db = new Database(); // Query $query = $db->query('SELECT DATE_FORMAT(incident_date, \'%Y\') AS incident_date FROM incident WHERE incident_active = 1 GROUP BY DATE_FORMAT(incident_date, \'%Y\') ORDER BY incident_date'); foreach ($query as $slider_date) { $startDate .= "<optgroup label=\"" . $slider_date->incident_date . "\">"; for ($i = START_REPORTS_MONTH; $i <= END_REPORTS_MONTH; $i++) { if ($i < 10) { $i = "0" . $i; } $startDate .= "<option value=\"" . strtotime($slider_date->incident_date . "-" . $i . "-01") . "\">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $slider_date->incident_date . "</option>"; } $startDate .= "</optgroup>"; $endDate .= "<optgroup label=\"" . $slider_date->incident_date . "\">"; for ($i = START_REPORTS_MONTH; $i <= END_REPORTS_MONTH; $i++) { if ($i < 10) { $i = "0" . $i; } $endDate .= "<option value=\"" . strtotime($slider_date->incident_date . "-" . $i . "-" . date('t', mktime(0, 0, 0, $i, 1))) . "\""; if ($i == date("n", time())) { $endDate .= " selected=\"selected\" "; } $endDate .= ">" . date('M', mktime(0, 0, 0, $i, 1)) . " " . $slider_date->incident_date . "</option>"; } $endDate .= "</optgroup>"; } $this->template->content->startDate = $startDate; $this->template->content->endDate = $endDate; // get graph data // could not use DB query builder. It does not support parentheses yet $graph_data = array(); $all_graphs = Incident_Model::get_incidents_by_interval('month'); $this->template->content->all_graphs = $all_graphs; // Javascript Header $this->template->header->map_enabled = TRUE; $this->template->header->main_page = TRUE; // Cluster Reports on Map? $clustering = Kohana::config('settings.allow_clustering'); if ($clustering == 1) { $this->template->header->js = new View('main_cluster_js'); } else { $this->template->header->js = new View('main_js'); } $this->template->header->js->default_map = Kohana::config('settings.default_map'); $this->template->header->js->default_zoom = Kohana::config('settings.default_zoom'); $this->template->header->js->latitude = Kohana::config('settings.default_lat'); $this->template->header->js->longitude = Kohana::config('settings.default_lon'); $this->template->header->js->graph_data = $graph_data; $this->template->header->js->all_graphs = $all_graphs; $this->template->header->js->categories = $categories; // Pack the javascript using the javascriptpacker helper $myPacker = new javascriptpacker($this->template->header->js, 'Normal', false, false); $this->template->header->js = $myPacker->pack(); }