From a0c493b80c1d29434aa4bcd1a5b2241a70640896 Mon Sep 17 00:00:00 2001
From: mdtrooper <tres.14159@gmail.com>
Date: Thu, 18 Feb 2010 16:54:24 +0000
Subject: [PATCH] 2010-02-18  Miguel de Dios  <miguel.dedios@artica.es>

	* include/functions_gis.php: check in the function "addPath" if the agent
	haven't history data. And clean source code.

	* operation/agentes/gis_view.php: change to use new tables, and show
	messages when the agent haven't data GIS.

	* godmode/agentes/agent_conf_gis.php: change the message for agent without
	data GIS.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2376 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                          | 11 +++++++++++
 pandora_console/godmode/agentes/agent_conf_gis.php |  2 +-
 pandora_console/include/functions_gis.php          | 11 +++++++++--
 pandora_console/operation/agentes/gis_view.php     | 11 ++++++++---
 4 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 45794559d3..f09782e751 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,14 @@
+2010-02-18  Miguel de Dios  <miguel.dedios@artica.es>
+
+	* include/functions_gis.php: check in the function "addPath" if the agent
+	haven't history data. And clean source code.
+	
+	* operation/agentes/gis_view.php: change to use new tables, and show
+	messages when the agent haven't data GIS.
+	
+	* godmode/agentes/agent_conf_gis.php: change the message for agent without
+	data GIS.
+
 2010-02-18  Miguel de Dios  <miguel.dedios@artica.es>
 
 	* include/functions_html.php: hightlight that the parameter $script in
diff --git a/pandora_console/godmode/agentes/agent_conf_gis.php b/pandora_console/godmode/agentes/agent_conf_gis.php
index 509af2026b..bd14250f50 100644
--- a/pandora_console/godmode/agentes/agent_conf_gis.php
+++ b/pandora_console/godmode/agentes/agent_conf_gis.php
@@ -36,7 +36,7 @@ echo getAgentMap($id_agente, "500px", "98%", false);
 
 
 if ($agentData === false) {
-	echo "<p>" . __("There aren't any GIS data of agent, then it's positioned in default position of map.") . "</p>";
+	echo "<p>" . __("There is no GIS data for this agent, so it's positioned in default position of map.") . "</p>";
 }
 
 echo "<h4>" . __("Warning: When you change the position the agent automatily enabled ignore GIS Data") . "</h4>";
diff --git a/pandora_console/include/functions_gis.php b/pandora_console/include/functions_gis.php
index 8f0e35ca5d..7e7a43834c 100644
--- a/pandora_console/include/functions_gis.php
+++ b/pandora_console/include/functions_gis.php
@@ -448,7 +448,12 @@ function get_agent_icon_map($idAgent, $state = false) {
 
 function addPath($layerName, $idAgent) {
 	
-	$listPoints = get_db_all_rows_sql('SELECT * FROM tgis_data WHERE tagente_id_agente = ' . $idAgent . ' ORDER BY end_timestamp ASC');
+	$listPoints = get_db_all_rows_sql('SELECT * FROM tgis_data_history WHERE tagente_id_agente = ' . $idAgent . ' ORDER BY end_timestamp ASC');
+	
+	//If the agent is empty the history
+	if ($listPoints === false) {
+		return;
+	}
 	
 	$avaliableColors = array("#ff0000", "#00ff00", "#0000ff", "#000000");
 	
@@ -769,11 +774,13 @@ function getAgentMap($agent_id, $heigth, $width, $show_history = false, $centerI
 	makeLayer("layer_for_agent_".$agent_name);
 	
 	$agent_icon = get_agent_icon_map($agent_id);
-		/* If show_history is true, show the path of the agent */
+		
+	/* If show_history is true, show the path of the agent */
 	if ($show_history) {
 		/* TODO: only show the last history_time part of the path */
 		addPath("layer_for_agent_".$agent_name,$agent_id);
 	}
+	
 	addPoint("layer_for_agent_".$agent_name, $agent_name, $agentPositionLatitude, $agentPositionLongitude, $agent_icon, 20, 20, $agent_id, 'point_agent_info');
 	
 	if ($centerInAgent) {
diff --git a/pandora_console/operation/agentes/gis_view.php b/pandora_console/operation/agentes/gis_view.php
index aee18500b6..394ae9d578 100644
--- a/pandora_console/operation/agentes/gis_view.php
+++ b/pandora_console/operation/agentes/gis_view.php
@@ -33,6 +33,7 @@ require_javascript_file('openlayers.pandora');
 $period = get_parameter ("period", 86400);
 $agentId = get_parameter('id_agente');
 $agent_name = get_agent_name($agentId); 
+$agentData = getDataLastPositionAgent($id_agente);
 
 echo "<h2>".__('Received data from')." ". $agent_name . " </h2>";
 echo "<h3>" . __("Map with the last position/s") . " " . human_time_description ($period) ."</h3>";
@@ -41,13 +42,17 @@ echo "<h3>" . __("Map with the last position/s") . " " . human_time_description
 echo "<div id=\"".$agent_name."_agent_map\"  style=\"border:1px solid black; width:98%; height: 30em;\"></div>";
 echo getAgentMap($agentId, "500px", "98%", true);
 
+if ($agentData === false) {
+	echo "<p>" . __("There is no GIS data for this agent, so it's positioned in default position of map.") . "</p>";
+}
+
 echo "<h3>" . __("Positional data from the last") . " " . human_time_description ($period) ."</h3>";
 /* Get the total number of Elements for the pagination */ 
-$sqlCount = sprintf ("SELECT COUNT(*) FROM tgis_data WHERE tagente_id_agente = %d AND end_timestamp > %d ORDER BY end_timestamp DESC", $agentId, get_system_time () - $period);
+$sqlCount = sprintf ("SELECT COUNT(*) FROM tgis_data_history WHERE tagente_id_agente = %d AND end_timestamp > %d ORDER BY end_timestamp DESC", $agentId, get_system_time () - $period);
 $countData = get_db_value_sql($sqlCount);
 /* Get the elements to present in this page */
 $sql = sprintf ("SELECT longitude, latitude, altitude, start_timestamp, end_timestamp, description, number_of_packages, manual_placement
-        FROM tgis_data
+        FROM tgis_data_history
         WHERE tagente_id_agente = %d AND end_timestamp > %d 
         ORDER BY end_timestamp DESC
         LIMIT %d OFFSET %d", $agentId, get_system_time () - $period, $config['block_size'], get_parameter ('offset'));
@@ -55,7 +60,7 @@ $result = get_db_all_rows_sql ($sql, true);
 
 if ($result === false) {
 
-    echo '<h3 class="error">'.__('There was a problem locating the positional data').'</h3>';
+    echo '<h3 class="error">'.__('There was a problem locating the positional data or empty history.').'</h3>';
 }
 else {
     pagination ($countData, false) ;