Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reports search form #220 #872

Merged
merged 2 commits into from
Nov 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion application/controllers/admin/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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']))
{
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}

}
7 changes: 4 additions & 3 deletions application/helpers/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.'"',
Expand Down
13 changes: 11 additions & 2 deletions application/views/admin/reports/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<!-- tabset -->
<ul class="tabset">
<li>
<a href="?status=0" <?php if ($status != 'a' AND $status !='v' AND $status != 'o') echo "class=\"active\""; ?>><?php echo Kohana::lang('ui_main.show_all');?></a>
<a href="?status=0" <?php if ($status != 'a' AND $status !='v' AND $status != 'o' AND $status != 'search') echo "class=\"active\""; ?>><?php echo Kohana::lang('ui_main.show_all');?></a>
</li>
<li><a href="?status=a" <?php if ($status == 'a') echo "class=\"active\""; ?>><?php echo Kohana::lang('ui_main.awaiting_approval');?></a></li>
<li><a href="?status=v" <?php if ($status == 'v') echo "class=\"active\""; ?>><?php echo Kohana::lang('ui_main.awaiting_verification');?></a></li>
Expand All @@ -31,9 +31,14 @@
<?php echo Kohana::lang('ui_main.uncategorized_reports'); ?>
</a>
</li>
<li class="right">
<a href="?status=search" class="search <?php if ($status == 'search') echo "active"; ?>">
<?php echo Kohana::lang('ui_main.search'); ?>
</a>
</li>
</ul>
<!-- tab -->
<div class="tab">
<div class="tab action-tab active">
<ul>
<?php if (Auth::instance()->has_permission('reports_approve')): ?>
<li><a href="#" onclick="reportAction('a','<?php echo utf8::strtoupper(Kohana::lang('ui_main.approve')); ?>', '');">
Expand Down Expand Up @@ -75,6 +80,10 @@
echo form::close(); ?>
</div>
</div>

<div class="content-tab search-tab">
<?php echo $search_form; ?>
</div>
</div>
<?php if ($form_error): ?>
<!-- red-box -->
Expand Down
136 changes: 136 additions & 0 deletions application/views/admin/reports/reports_js.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 = <?php echo isset($_GET['start_loc'][0]) ? floatval($_GET['start_loc'][0]) : Kohana::config('settings.default_lat') ?>;
var longitude = <?php echo isset($_GET['start_loc'][1]) ? floatval($_GET['start_loc'][1]) : Kohana::config('settings.default_lon'); ?>;
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.

<?php echo map::layers_js(FALSE); ?>
var mapConfig = {

// Map center
center: {
latitude: latitude,
longitude: longitude,
},

// Zoom level
zoom: zoom,

// Base layers
baseLayers: <?php echo map::layers_array(FALSE); ?>
};

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('<img src="<?php echo url::file_loc('img')."media/img/loading_g.gif"; ?>">');
address = $("#location_find").val();
$.post("<?php echo url::site(); ?>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;
}

Loading