From 09b0491aa607460f812472c7663e32e5db569383 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 4 Oct 2012 10:57:08 +1300 Subject: [PATCH 1/2] Add reports search form #220 Adding reports search form to admin/reports pages. Searching by: * Category * Approved * Verified * Keyword * Location * Media type * Mode (SMS/Web/Twitter) * Date --- application/controllers/admin/reports.php | 94 +++++++++++- application/helpers/reports.php | 2 +- application/views/admin/reports/main.php | 13 +- .../views/admin/reports/reports_js.php | 136 ++++++++++++++++++ .../views/admin/reports/search_form.php | 82 +++++++++++ media/css/admin/all.css | 57 ++++++++ 6 files changed, 380 insertions(+), 4 deletions(-) create mode 100644 application/views/admin/reports/search_form.php diff --git a/application/controllers/admin/reports.php b/application/controllers/admin/reports.php index c3d4725dee..1b8d93326c 100755 --- a/application/controllers/admin/reports.php +++ b/application/controllers/admin/reports.php @@ -66,7 +66,7 @@ public function index($page = 1) { array_push($this->params, '(ic.category_id IS NULL)'); } - else + elseif (strtolower($status) != 'search') { $status = "0"; } @@ -95,6 +95,10 @@ public function index($page = 1) $keyword_raw = ""; } + $this->template->content->search_form = $this->_search_form(); + $this->template->content->search_form->keywords = $keyword_raw; + + // Handler sort/order fields $order_field = 'date'; $sort = 'DESC'; if (isset($_GET['order'])) { @@ -296,6 +300,9 @@ public function index($page = 1) $this->template->content->order_field = $order_field; $this->template->content->sort = $sort; + $this->template->map_enabled = TRUE; + $this->template->json2_enabled = TRUE; + $this->template->treeview_enabled = TRUE; // Javascript Header $this->template->js = new View('admin/reports/reports_js'); @@ -1496,5 +1503,90 @@ public function deletePhoto ($id) Media_Model::delete_photo($id); } } + + private function _search_form() + { + $search_form = View::factory('admin/reports/search_form'); + + // Handling location filter + $location_filter = isset($_GET['location_filter']); + if (! $location_filter) + { + if ( isset($_GET['start_loc']) ) + { + unset($_GET['start_loc']); + } + if ( isset($_GET['alert_radius']) ) + { + unset($_GET['alert_radius']); + } + } + else + { + $_GET['radius'] = $_GET['alert_radius']; + } + $search_form->location_filter = $location_filter; + $search_form->start_loc = isset($_GET['start_loc']) ? $_GET['start_loc'] : array(0,0); + + // Get the date of the oldest report + if (! empty($_GET['from'])) + { + $date_from = strtotime($_GET['from']); + } + else + { + $date_from = Incident_Model::get_oldest_report_timestamp(); + } + + // Get the date of the latest report + if (! empty($_GET['to'])) + { + $date_to = strtotime($_GET['to']); + } + else + { + $date_to = Incident_Model::get_latest_report_timestamp(); + } + + $search_form->date_from = $date_from; + $search_form->date_to = $date_to; + + // Categories + if (! isset($_GET['c']) OR ! is_array($_GET['c'])) + { + $_GET['c'] = isset($_GET['c']) ? array($_GET['c']) : array(); + } + $search_form->categories = $_GET['c']; + + // Media + if (! isset($_GET['m']) OR ! is_array($_GET['m'])) + { + $_GET['m'] = isset($_GET['m']) ? array($_GET['m']) : array(); + } + $search_form->media = $_GET['m']; + + // Mode + if (! isset($_GET['mode']) OR ! is_array($_GET['mode'])) + { + $_GET['mode'] = isset($_GET['mode']) ? array($_GET['mode']) : array(); + } + $search_form->mode = $_GET['mode']; + + // Approved + $search_form->approved = $_GET['a'] = isset($_GET['a']) ? $_GET['a'] : 'all'; + if ($_GET['a'] == 'all') unset($_GET['a']); + // Verified + $search_form->verified = $_GET['v'] = isset($_GET['v']) ? $_GET['v'] : 'all'; + if ($_GET['v'] == 'all') unset($_GET['v']); + + // Load the alert radius view + $alert_radius_view = new View('alerts/radius'); + $alert_radius_view->show_usage_info = FALSE; + $alert_radius_view->enable_find_location = TRUE; + $alert_radius_view->css_class = "map_holder_reports"; + $search_form->alert_radius_view = $alert_radius_view; + + return $search_form; + } } diff --git a/application/helpers/reports.php b/application/helpers/reports.php index 9e91436df7..b2b812bdfc 100644 --- a/application/helpers/reports.php +++ b/application/helpers/reports.php @@ -720,7 +720,7 @@ public static function fetch_incidents($paginate = FALSE, $items_per_page = 0) //if $url_data['start_loc'] is just comma delimited strings, then make it into an array if (intval($url_data['radius']) > 0 AND is_array($url_data['start_loc'])) { - $bounds = $url_data['start_loc']; + $bounds = $url_data['start_loc']; if (count($bounds) == 2 AND is_numeric($bounds[0]) AND is_numeric($bounds[1])) { self::$params['radius'] = array( diff --git a/application/views/admin/reports/main.php b/application/views/admin/reports/main.php index f765a537e9..9b27e62a03 100644 --- a/application/views/admin/reports/main.php +++ b/application/views/admin/reports/main.php @@ -22,7 +22,7 @@ -
+
+ +
+ +
diff --git a/application/views/admin/reports/reports_js.php b/application/views/admin/reports/reports_js.php index 95ae7f11de..685843cfe9 100644 --- a/application/views/admin/reports/reports_js.php +++ b/application/views/admin/reports/reports_js.php @@ -57,6 +57,7 @@ function showLog(id) } $(function () { + // Handle sort/order fields $("select#order").change(function() { $('.sort-form').submit(); }); $(".sort-ASC").click(function() { $('.sort-field').val('DESC'); @@ -68,5 +69,140 @@ function showLog(id) $('.sort-form').submit(); return false; }); + + // Handle search tab + $(".tabset .search").click(function() { + if ($('.search-tab').hasClass('active')) + { + $(".search-tab").removeClass('active').slideUp(300, function() { $(".action-tab").slideDown().addClass('active'); }); + $(".tabset .search").removeClass('active'); + } + else + { + $(".action-tab").removeClass('active').slideUp(300, function() { + $(".search-tab").slideDown().addClass('active'); + + // Check if the map has already been created + if (mapLoaded == false) + { + initMap(); + } + }); + $(".tabset .search").addClass('active'); + } + + return false; + }); + + // Category treeview + $(".category-column").treeview({ + persist: "location", + collapsed: true, + unique: false + }); +}); + + +// Map reference +var map = null; +var latitude = ; +var longitude = ; +var zoom = 8; + +var mapLoaded = false; + +var initMap = function(){ + // OpenLayers uses IE's VML for vector graphics + // We need to wait for IE's engine to finish loading all namespaces (document.namespaces) for VML. + // jQuery.ready is executing too soon for IE to complete it's loading process. + + + var mapConfig = { + + // Map center + center: { + latitude: latitude, + longitude: longitude, + }, + + // Zoom level + zoom: zoom, + + // Base layers + baseLayers: + }; + + map = new Ushahidi.Map('divMap', mapConfig); + map.addRadiusLayer({ + latitude: latitude, + longitude: longitude + }); + + // Subscribe to makerpositionchanged event + map.register("markerpositionchanged", function(coords){ + $(".search_lat").val(coords.latitude); + $(".search_lon").val(coords.longitude); + }); + + // Alerts Slider + $("select#alert_radius").change( + function(e, ui) { + var newRadius = $("#alert_radius").val(); + + // Convert to Meters + radius = newRadius * 1000; + + // Redraw Circle + map.updateRadius({radius: radius}); + } + ); + + mapLoaded = true; +}; + +$(function () { + $('.btn_find').on('click', function () { + geoCode(); + }); + + $('#location_find').bind('keypress', function(e) { + var code = (e.keyCode ? e.keyCode : e.which); + if(code == 13) { //Enter keycode + geoCode(); + return false; + } + }); }); + +/** + * Google GeoCoder + */ +function geoCode() { + $('#find_loading').html('">'); + address = $("#location_find").val(); + $.post("reports/geocode/", { address: address }, + function(data){ + if (data.status == 'success') { + + map.updateRadius({ + longitude: data.longitude, + latitude: data.latitude + }); + + // Update form values + $("#alert_lat").val(data.latitude); + $("#alert_lon").val(data.longitude); + } else { + // Alert message to be displayed + var alertMessage = address + " not found!\n\n***************************\n" + + "Enter more details like city, town, country\nor find a city or town " + + "close by and zoom in\nto find your precise location"; + + alert(alertMessage) + } + $('#find_loading').html(''); + }, "json"); + return false; +} + diff --git a/application/views/admin/reports/search_form.php b/application/views/admin/reports/search_form.php new file mode 100644 index 0000000000..fdb7fbcfa2 --- /dev/null +++ b/application/views/admin/reports/search_form.php @@ -0,0 +1,82 @@ + 'get', 'class' => 'report-search-form')); ?> +

+ +
+ +
+
+ +
+
+ +
+
+".form::checkbox('mode[]',1, in_array(1, $mode)) . Kohana::lang('ui_main.web') . ""; + echo ""; + echo ""; + echo ""; +?> +
+
+".form::checkbox('m[]',1, in_array(1, $media)) . Kohana::lang('ui_main.photos') . ""; + echo ""; + echo ""; +?> +
+
+".form::radio('a',1, $approved == 1) . Kohana::lang('ui_main.yes') . ""; + echo ""; + echo ""; +?> +
+
+".form::radio('v',1, $verified == 1) . Kohana::lang('ui_main.yes') . ""; + echo ""; + echo ""; +?> +
+
+ +
+
+ 'hidden', 'name' => 'start_loc[0]', 'value' => floatval($start_loc[0]), 'class' => 'search_lat')); + echo form::input(array('type' => 'hidden', 'name' => 'start_loc[1]', 'value' => floatval($start_loc[1]), 'class' => 'search_lon')); + echo form::submit('submit', Kohana::lang('ui_main.search')); +?> +
+ \ No newline at end of file diff --git a/media/css/admin/all.css b/media/css/admin/all.css index 8c16df8d2f..6e4d038ae7 100755 --- a/media/css/admin/all.css +++ b/media/css/admin/all.css @@ -2563,3 +2563,60 @@ div.dp-popup td.disabled { .sort-DESC { background: url(../../img/admin/drag.gif) 0 -8px no-repeat; } + +/* Report search form */ +.search-tab { + padding: 1.2em; + display: none; +} + .search-tab .row { + margin-bottom: 1em; + } + .search-tab .category-row, .search-tab .location-row { + float: left; + clear: none; + padding-right: 0.5em; + } + .search-tab .category-row { width: 300px; } + .search-tab .location-row { width: 515px; } + .search-tab label.fixw { + width: 100px; + float: left; + } + .search-tab label.wrapped { + padding-right: 5px; + } + .search-tab .map { + overflow: hidden; + padding: 10px; + margin: 10px 0 0 0; + } + .search-tab .report-find-location { + padding: 9px 18px 18px 18px; + font-size: 80%; + } + +.report-find-location { + margin-right:1px; + padding:0 9px 9px 9px; + background-color:#eee; + font-size:90%; + color:#666; +} +.report-find-location input.findtext { + margin-top:9px; + padding:5px 3px 0 3px; + height:24px; + float:left; + font-size:14px; + font-weight:bold; + color:#666; + width:250px; + border:1px #ccc solid; +} +.report-find-loading { + float:left; + height:31px; + margin:9px 0 0 3px; +} + From 03d324e41c8a435805886c40bb5ea48168c77b69 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Thu, 25 Oct 2012 10:33:13 +1300 Subject: [PATCH 2/2] Make fetch_incidents() date search from beginning till end of day #220 This makes sure we still get results if from and to dates are the same. Also more closely matches what a user would expect --- application/helpers/reports.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/helpers/reports.php b/application/helpers/reports.php index b2b812bdfc..01a412ed6b 100644 --- a/application/helpers/reports.php +++ b/application/helpers/reports.php @@ -737,8 +737,9 @@ public static function fetch_incidents($paginate = FALSE, $items_per_page = 0) // if (isset($url_data['from']) AND isset($url_data['to'])) { - $date_from = date('Y-m-d', strtotime($url_data['from'])); - $date_to = date('Y-m-d', strtotime($url_data['to'])); + // Add hours/mins/seconds so we still get reports if from and to are the same day + $date_from = date('Y-m-d 00:00:00', strtotime($url_data['from'])); + $date_to = date('Y-m-d 23:59:59', strtotime($url_data['to'])); array_push(self::$params, 'i.incident_date >= "'.$date_from.'"',