"; echo "$(document).ready (function () { var layer = map.getLayersByName('" . __('Hierarchy of agents') . "'); layer = layer[0]; map.setLayerIndex(layer, 0); js_refreshParentLines('" . __('Hierarchy of agents') . "'); });"; echo ""; } /** * Return the data of last position of agent from tgis_data_status. * * @param integer $idAgent The id of agent. * @param boolean $returnEmptyArrayInFail The set return a empty array when fail and true. * @return Array The row of agent in tgis_data_status, and it's a associative array. */ function gis_get_data_last_position_agent($idAgent, $returnEmptyArrayInFail = false) { $returnVar = db_get_row('tgis_data_status', 'tagente_id_agente', $idAgent); if (($returnVar === false) && ($returnEmptyArrayInFail)) { return array(); } return $returnVar; } /** * Write a javascript vars for to call the js_printMap. * * @param string $idDiv The id of div to paint the map. * @param integer $iniZoom The zoom to init the map. * @param float $latCenter The latitude center to init the map. * @param float $lonCenter The longitude center to init the map. * @param array $baselayers The list of baselayer with the connection data. * @param array $controls The string list of controls. * * @return None */ function gis_print_map($idDiv, $iniZoom, $latCenter, $lonCenter, $baselayers, $controls = null) { ui_require_javascript_file('OpenLayers/OpenLayers'); echo ""; ?> $agent) { $agents[$index] = $agent['nombre']; } } else { return array(); } return $agents; } function gis_add_point_path($layerName, $lat, $lon, $color, $manual = 1, $id) { ?> = FROM_UNIXTIME(UNIX_TIMESTAMP() - ' . $history_time . ')'; break; case "postgresql": $where = 'start_timestamp >= to_timestamp(ceil(date_part("epoch", CURRENT_TIMESTAMP)) - ' . $history_time . ')'; break; case "oracle": $where = 'start_timestamp >= to_timestamp(\'01-01-1970 00:00:00\', \'DD-MM-YYYY HH24:MI:SS\') + NUMTODSINTERVAL((ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (' . SECONDS_1DAY . ')) - ' . $history_time . '),\'SECOND\')'; break; } } $sql = "SELECT * FROM tgis_data_history WHERE tagente_id_agente = $idAgent AND $where ORDER BY end_timestamp ASC"; $listPoints = db_get_all_rows_sql($sql); //If the agent is empty the history if ($listPoints === false) { return; } $avaliableColors = array("#ff0000", "#00ff00", "#0000ff", "#000000"); $randomIndex = array_rand($avaliableColors); $color = $avaliableColors[$randomIndex]; ?> $idConectionMap)); //TODO DELETE IN OTHER TABLES } function gis_save_map_connection($mapConnection_name, $mapConnection_group, $mapConnection_numLevelsZoom, $mapConnection_defaultZoom, $mapConnection_defaultLatitude, $mapConnection_defaultLongitude, $mapConnection_defaultAltitude, $mapConnection_centerLatitude, $mapConnection_centerLongitude, $mapConnection_centerAltitude, $mapConnectionData, $idConnectionMap = null) { if ($idConnectionMap !== null) { $returnQuery = db_process_sql_update('tgis_map_connection', array( 'conection_name' => $mapConnection_name, 'connection_type' => $mapConnectionData['type'], 'conection_data' => json_encode($mapConnectionData), 'num_zoom_levels' => $mapConnection_numLevelsZoom, 'default_zoom_level' => $mapConnection_defaultZoom, 'default_longitude' => $mapConnection_defaultLongitude, 'default_latitude' => $mapConnection_defaultLatitude, 'default_altitude' => $mapConnection_defaultAltitude, 'initial_longitude' => $mapConnection_centerLongitude, 'initial_latitude' => $mapConnection_centerLatitude, 'initial_altitude' => $mapConnection_centerAltitude, 'group_id' => $mapConnection_group ), array('id_tmap_connection' => $idConnectionMap) ); } else { $returnQuery = db_process_sql_insert('tgis_map_connection', array( 'conection_name' => $mapConnection_name, 'connection_type' => $mapConnectionData['type'], 'conection_data' => json_encode($mapConnectionData), 'num_zoom_levels' => $mapConnection_numLevelsZoom, 'default_zoom_level' => $mapConnection_defaultZoom, 'default_longitude' => $mapConnection_defaultLongitude, 'default_latitude' => $mapConnection_defaultLatitude, 'default_altitude' => $mapConnection_defaultAltitude, 'initial_longitude' => $mapConnection_centerLongitude, 'initial_latitude' => $mapConnection_centerLatitude, 'initial_altitude' => $mapConnection_centerAltitude, 'group_id' => $mapConnection_group ) ); } return $returnQuery; } /** * Delete the map in the all tables are related. * * @param $idMap integer The id of map. * @return None */ function gis_delete_map($idMap) { $listIdLayers = db_get_all_rows_sql( "SELECT id_tmap_layer FROM tgis_map_layer WHERE tgis_map_id_tgis_map = " . $idMap); if ($listIdLayers !== false) { foreach ($listIdLayers as $idLayer) { db_process_sql_delete('tgis_map_layer_has_tagente', array('tgis_map_layer_id_tmap_layer' => $idLayer)); } } $correct = (bool)db_process_sql_delete('tgis_map_layer', array('tgis_map_id_tgis_map' => $idMap)); if ($correct) { $correct = db_process_sql_delete('tgis_map_has_tgis_map_con', array('tgis_map_id_tgis_map' => $idMap)); } if ($correct) { $correct = db_process_sql_delete('tgis_map', array('id_tgis_map' => $idMap)); } $numMaps = db_get_num_rows('SELECT * FROM tgis_map'); db_clean_cache(); return $correct; } /** * Save the map into DB, tgis_map and with id_map save the connetions in * tgis_map_has_tgis_map_con, and with id_map save the layers in * tgis_map_layer and witch each id_layer save the agent in this layer in * table tgis_map_layer_has_tagente. * * @param $map_name * @param $map_initial_longitude * @param $map_initial_latitude * @param $map_initial_altitude * @param $map_zoom_level * @param $map_background * @param $map_default_longitude * @param $map_default_latitude * @param $map_default_altitude * @param $map_group_id * @param $map_connection_list * @param $arrayLayers */ function gis_save_map($map_name, $map_initial_longitude, $map_initial_latitude, $map_initial_altitude, $map_zoom_level, $map_background, $map_default_longitude, $map_default_latitude, $map_default_altitude, $map_group_id, $map_connection_list, $arrayLayers) { $idMap = db_process_sql_insert('tgis_map', array('map_name' => $map_name, 'initial_longitude' => $map_initial_longitude, 'initial_latitude' => $map_initial_latitude, 'initial_altitude' => $map_initial_altitude, 'zoom_level' => $map_zoom_level, 'map_background' => $map_background, 'default_longitude' => $map_default_longitude, 'default_latitude' => $map_default_latitude, 'default_altitude' => $map_default_altitude, 'group_id' => $map_group_id ) ); $numMaps = db_get_num_rows('SELECT * FROM tgis_map'); if ($numMaps == 1) db_process_sql_update('tgis_map', array('default_map' => 1), array('id_tgis_map' => $idMap)); foreach ($map_connection_list as $map_connection) { db_process_sql_insert('tgis_map_has_tgis_map_con', array( 'tgis_map_id_tgis_map' => $idMap, 'tgis_map_con_id_tmap_con' => $map_connection['id_conection'], 'default_map_connection' => $map_connection['default'] ) ); } foreach ($arrayLayers as $index => $layer) { $idLayer = db_process_sql_insert('tgis_map_layer', array( 'layer_name' => $layer['layer_name'], 'view_layer' => $layer['layer_visible'], 'layer_stack_order' => $index, 'tgis_map_id_tgis_map' => $idMap, 'tgrupo_id_grupo' => $layer['layer_group'] ) ); if ((isset($layer['layer_agent_list'])) AND (count($layer['layer_agent_list']) > 0)) { foreach ($layer['layer_agent_list'] as $agent_name) { db_process_sql_insert('tgis_map_layer_has_tagente', array( 'tgis_map_layer_id_tmap_layer' => $idLayer, 'tagente_id_agente' => agents_get_agent_id(io_safe_input($agent_name)) ) ); } } } return $idMap; } function gis_update_map($idMap, $map_name, $map_initial_longitude, $map_initial_latitude, $map_initial_altitude, $map_zoom_level, $map_background, $map_default_longitude, $map_default_latitude, $map_default_altitude, $map_group_id, $map_connection_list, $arrayLayers) { db_process_sql_update('tgis_map', array('map_name' => $map_name, 'initial_longitude' => $map_initial_longitude, 'initial_latitude' => $map_initial_latitude, 'initial_altitude' => $map_initial_altitude, 'zoom_level' => $map_zoom_level, 'map_background' => $map_background, 'default_longitude' => $map_default_longitude, 'default_latitude' => $map_default_latitude, 'default_altitude' => $map_default_altitude, 'group_id' => $map_group_id ), array('id_tgis_map' => $idMap)); db_process_sql_delete('tgis_map_has_tgis_map_con', array('tgis_map_id_tgis_map' => $idMap)); foreach ($map_connection_list as $map_connection) { db_process_sql_insert('tgis_map_has_tgis_map_con', array( 'tgis_map_id_tgis_map' => $idMap, 'tgis_map_con_id_tmap_con' => $map_connection['id_conection'], 'default_map_connection' => $map_connection['default'] ) ); } $sql = 'SELECT id_tmap_layer FROM tgis_map_layer WHERE tgis_map_id_tgis_map = ' . $idMap; $listOldIdLayers = db_get_all_rows_sql($sql); if ($listOldIdLayers == false) $listOldIdLayers = array(); $list_onlyIDsLayers = array(); foreach ($listOldIdLayers as $idLayer) { db_process_sql_delete('tgis_map_layer_has_tagente', array('tgis_map_layer_id_tmap_layer' => $idLayer['id_tmap_layer'])); $list_onlyIDsLayers[$idLayer['id_tmap_layer']] = 0; } foreach ($arrayLayers as $index => $layer) { if ($layer['id'] != 0) { $idLayer = $layer['id']; unset($list_onlyIDsLayers[$idLayer]); db_process_sql_update('tgis_map_layer', array( 'layer_name' => $layer['layer_name'], 'view_layer' => $layer['layer_visible'], 'layer_stack_order' => $index, 'tgis_map_id_tgis_map' => $idMap, 'tgrupo_id_grupo' => $layer['layer_group'] ), array('id_tmap_layer' => $idLayer)); } else { $idLayer = db_process_sql_insert('tgis_map_layer', array( 'layer_name' => $layer['layer_name'], 'view_layer' => $layer['layer_visible'], 'layer_stack_order' => $index, 'tgis_map_id_tgis_map' => $idMap, 'tgrupo_id_grupo' => $layer['layer_group'] ) ); } if (array_key_exists('layer_agent_list', $layer)) { if (count($layer['layer_agent_list']) > 0) { foreach ($layer['layer_agent_list'] as $agent_name) { db_process_sql_insert('tgis_map_layer_has_tagente', array( 'tgis_map_layer_id_tmap_layer' => $idLayer, 'tagente_id_agente' => agents_get_agent_id( io_safe_input($agent_name)) ) ); } } } } //Delete layers that not carry the $arrayLayers foreach ($list_onlyIDsLayers as $idLayer => $trash) { db_process_sql_delete('tgis_map_layer', array('id_tmap_layer' => $idLayer)); } } /** * Get the configuration parameters of a map connection * * @param idConnection: connection identifier for the map * * @result: An array with all the configuration parameters */ function gis_get_conection_conf($idConnection) { $sql = 'SELECT * FROM tgis_map_connection WHERE id_tmap_connection = ' . $idConnection; $confParameters = db_get_row_sql($sql); return $confParameters; } /** * Shows the map of an agent in a div with the width and heigth given and the history if asked * * @param $agent_id: id of the agent as in the table tagente; * @param $height: heigth in a string in css format * @param $width: width in a string in css format * @param $show_history: by default or when this parameter is false in the map the path with the * @param $centerInAgent boolean Default is true, set the map center in the icon agent. * @param $history_time: Number of seconds in the past to show from where to start the history path. * * @return boolean True ok and false fail. */ function gis_get_agent_map($agent_id, $heigth, $width, $show_history = false, $centerInAgent = true, $history_time = SECONDS_1DAY) { $sql = "SELECT t1.*, t3.conection_name, t3.connection_type, t3.conection_data, t3.num_zoom_levels FROM tgis_map t1, tgis_map_has_tgis_map_con t2, tgis_map_connection t3 WHERE t1.default_map = 1 AND t2.tgis_map_id_tgis_map = t1.id_tgis_map AND t2.default_map_connection = 1 AND t3.id_tmap_connection = t2.tgis_map_con_id_tmap_con"; $defaultMap = db_get_all_rows_sql($sql); if ($defaultMap === false) { return false; } $defaultMap = $defaultMap[0]; $agent_position = gis_get_data_last_position_agent($agent_id); if ($agent_position === false) { $agentPositionLongitude = $defaultMap['default_longitude']; $agentPositionLatitude = $defaultMap['default_latitude']; $agentPositionAltitude = $defaultMap['default_altitude']; } else { $agentPositionLongitude = $agent_position['stored_longitude']; $agentPositionLatitude = $agent_position['stored_latitude']; $agentPositionAltitude = $agent_position['stored_altitude']; } $agent_name = agents_get_name($agent_id); $clean_agent_name = $agent_name; //Avoid the agents with characters that fails the div. $agent_name = md5($agent_name); $baselayers[0]['name'] = $defaultMap['conection_name']; $baselayers[0]['num_zoom_levels'] = $defaultMap['num_zoom_levels']; $conectionData = json_decode($defaultMap['conection_data'], true); $baselayers[0]['typeBaseLayer'] = $conectionData['type']; $controls = array('PanZoomBar', 'ScaleLine', 'Navigation', 'MousePosition'); $gmap_layer = false; switch ($conectionData['type']) { case 'OSM': $baselayers[0]['url'] = $conectionData['url']; break; case 'Gmap': $baselayers[0]['gmap_type'] = $conectionData['gmap_type']; $baselayers[0]['gmap_key'] = $conectionData['gmap_key']; $gmap_key = $conectionData['gmap_key']; // Onece a Gmap base layer is found we mark it to import the API $gmap_layer = true; break; case 'Static_Image': $baselayers[0]['url'] = $conectionData['url']; $baselayers[0]['bb_left'] = $conectionData['bb_left']; $baselayers[0]['bb_right'] = $conectionData['bb_right']; $baselayers[0]['bb_bottom'] = $conectionData['bb_bottom']; $baselayers[0]['bb_top'] = $conectionData['bb_top']; $baselayers[0]['image_width'] = $conectionData['image_width']; $baselayers[0]['image_height'] = $conectionData['image_height']; break; } if ($gmap_layer === true) { if (https_is_running()) { ?> $agentPositionLongitude, 'latitude' => $agentPositionLatitude); gis_add_path("layer_for_agent_" . $agent_name, $agent_id, $lastPosition, $history_time); } gis_add_agent_point("layer_for_agent_" . $agent_name, $clean_agent_name, $agentPositionLatitude, $agentPositionLongitude, $agent_icon, $agent_icon_width, $agent_icon_height, $agent_id, $status, 'point_agent_info'); if ($centerInAgent) { ?> $item) { $chunks = explode('.', $item); $extension = end($chunks); if (!in_array($extension, $validExtensions)) unset($dir[$index]); } foreach ($dir as $item) { $chunks = explode('.', $item); $extension = end($chunks); $nameWithoutExtension = str_replace("." . $extension, "", $item); $nameClean = str_replace(array('.bad', '.ok', '.warning', '.default'), "", $nameWithoutExtension); $return[$nameClean]['ok'] = $path . $nameClean . '.ok.png'; $return[$nameClean]['bad'] = $path . $nameClean . '.bad.png'; $return[$nameClean]['warning'] = $path . $nameClean . '.warning.png'; $return[$nameClean]['default'] = $path . $nameClean . '.default.png'; } return $return; } function gis_validate_map_data($map_name, $map_zoom_level, $map_initial_longitude, $map_initial_latitude, $map_initial_altitude, $map_default_longitude, $map_default_latitude, $map_default_altitude, $map_connection_list, $map_levels_zoom) { $invalidFields = array(); echo ""; return $invalidFields; } /** * Get all data (connections, layers with agents) of a map passed as id. * * @param integer $idMap The id of map in database. * * @return Array Return a asociative array whith the items 'map', 'connections' and 'layers'. And in 'layers' has data and item 'agents'. */ function gis_get_map_data($idMap) { global $config; $idMap = (int) $idMap; $returnVar = array(); $map = db_get_row('tgis_map', 'id_tgis_map', $idMap); if (empty($map)) return $returnVar; $connections = false; switch ($config["dbtype"]) { case "mysql": $sql = "SELECT t1.tgis_map_con_id_tmap_con AS id_conection, t1.default_map_connection AS `default`, SUM(t2.num_zoom_levels) AS num_zoom_levels FROM tgis_map_has_tgis_map_con t1 INNER JOIN tgis_map_connection t2 ON t1.tgis_map_con_id_tmap_con = t2.id_tmap_connection WHERE t1.tgis_map_id_tgis_map = $idMap GROUP BY t1.tgis_map_con_id_tmap_con, t1.default_map_connection"; $connections = db_get_all_rows_sql($sql); break; case "postgresql": case "oracle": $sql = "SELECT t1.tgis_map_con_id_tmap_con AS id_conection, t1.default_map_connection AS \"default\", SUM(t2.num_zoom_levels) AS num_zoom_levels FROM tgis_map_has_tgis_map_con t1 INNER JOIN tgis_map_connection t2 ON t1.tgis_map_con_id_tmap_con = t2.id_tmap_connection WHERE t1.tgis_map_id_tgis_map = $idMap GROUP BY t1.tgis_map_con_id_tmap_con, t1.default_map_connection"; $connections = db_get_all_rows_sql($sql); break; } $sql = "SELECT id_tmap_layer, layer_name, tgrupo_id_grupo AS layer_group, view_layer AS layer_visible FROM tgis_map_layer WHERE tgis_map_id_tgis_map = $idMap ORDER BY layer_stack_order ASC"; $layers = db_get_all_rows_sql($sql); if ($layers === false) $layers = array(); foreach ($layers as $index => $layer) { if (!isset($layer['id_tmap_layer'])) continue; $id_tmap_layer = (int) $layer['id_tmap_layer']; $sql = "SELECT nombre FROM tagente WHERE id_agente IN ( SELECT tagente_id_agente FROM tgis_map_layer_has_tagente WHERE tgis_map_layer_id_tmap_layer = $id_tmap_layer)"; $agents = db_get_all_rows_sql($sql); if ($agents === false) $agents = array(); $layers[$index]['layer_agent_list'] = $agents; } $returnVar['map'] = $map; $returnVar['connections'] = $connections; $returnVar['layers'] = $layers; return $returnVar; } /** * This function use in form the "pandora_console/godmode/gis_maps/configure_gis_map.php" * in the case of edit a map or when there are any error in save new map. Because this function * return a html code that it has the rows of connections. * * @param Array $map_connection_list The list of map connections for convert a html. * * @return String The html source code. */ function gis_add_conection_maps_in_form($map_connection_list) { $returnVar = ''; foreach ($map_connection_list as $mapConnection) { $mapConnectionRowDB = gis_get_map_connection($mapConnection['id_conection']); if ($mapConnection['default']) { $radioButton = html_print_radio_button_extended('map_connection_default', $mapConnection['id_conection'], '', $mapConnection['id_conection'], false, 'changeDefaultConection(this.value)', '', true); } else $radioButton = html_print_radio_button_extended('map_connection_default', $mapConnection['id_conection'], '', null, false, 'changeDefaultConection(this.value)', '', true); $returnVar .= '