$idConectionMap)); //TODO DELETE IN OTHER TABLES } function saveMapConnection($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 = 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 = 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 deleteMap($idMap) { $listIdLayers = get_db_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) { process_sql_delete('tgis_map_layer_has_tagente', array('tgis_map_layer_id_tmap_layer' => $idLayer)); } } process_sql_delete('tgis_map_layer', array('tgis_map_id_tgis_map' => $idMap)); process_sql_delete('tgis_map_has_tgis_map_connection', array('tgis_map_id_tgis_map' => $idMap)); process_sql_delete('tgis_map', array('id_tgis_map' => $idMap)); $numMaps = get_db_num_rows('SELECT * FROM tgis_map'); clean_cache(); } /** * Save the map into DB, tgis_map and with id_map save the connetions in * tgis_map_has_tgis_map_connection, 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 saveMap($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 = 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 = get_db_num_rows('SELECT * FROM tgis_map'); if ($numMaps == 1) process_sql_update('tgis_map', array('default_map' => 1), array('id_tgis_map' => $idMap)); foreach ($map_connection_list as $map_connection) { process_sql_insert('tgis_map_has_tgis_map_connection', array( 'tgis_map_id_tgis_map' => $idMap, 'tgis_map_connection_id_tmap_connection' => $map_connection['id_conection'], 'default_map_connection' => $map_connection['default'] ) ); } foreach ($arrayLayers as $index => $layer) { $idLayer = 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 (count($layer['layer_agent_list']) > 0) { foreach ($layer['layer_agent_list'] as $agent_name) { process_sql_insert('tgis_map_layer_has_tagente', array( 'tgis_map_layer_id_tmap_layer' => $idLayer, 'tagente_id_agente' => get_agent_id($agent_name) ) ); } } } } function updateMap($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) { 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)); process_sql_delete('tgis_map_has_tgis_map_connection', array('tgis_map_id_tgis_map' => $idMap)); foreach ($map_connection_list as $map_connection) { process_sql_insert('tgis_map_has_tgis_map_connection', array( 'tgis_map_id_tgis_map' => $idMap, 'tgis_map_connection_id_tmap_connection' => $map_connection['id_conection'], 'default_map_connection' => $map_connection['default'] ) ); } $listOldIdLayers = get_db_all_rows_sql('SELECT id_tmap_layer FROM tgis_map_layer WHERE tgis_map_id_tgis_map = ' . $idMap); if ($listOldIdLayers == false) $listOldIdLayers = array(); foreach($listOldIdLayers as $idLayer) { process_sql_delete('tgis_map_layer_has_tagente', array('tgis_map_layer_id_tmap_layer' => $idLayer['id_tmap_layer'])); } process_sql_delete('tgis_map_layer', array('tgis_map_id_tgis_map' => $idMap)); foreach ($arrayLayers as $index => $layer) { $idLayer = 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) { process_sql_insert('tgis_map_layer_has_tagente', array( 'tgis_map_layer_id_tmap_layer' => $idLayer, 'tagente_id_agente' => get_agent_id($agent_name) ) ); } } } } } /** * Get the configuration parameters of a map connection * * @param idConnection: connection identifier for the map * * @result: An array with all the configuration parameters */ function getConectionConf($idConnection) { $confParameters = get_db_row_sql('SELECT * FROM tgis_map_connection WHERE id_tmap_connection = ' . $idConnection); 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 A div tag with the map and the agent and the history path if asked. */ function getAgentMap($agent_id, $heigth, $width, $show_history = false, $centerInAgent = true, $history_time = 86400) { $defaultMap = get_db_all_rows_sql(" SELECT t1.*, t3.conection_name, t3.connection_type, t3.conection_data, t3.num_zoom_levels FROM tgis_map AS t1, tgis_map_has_tgis_map_connection AS t2, tgis_map_connection AS 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_connection_id_tmap_connection"); $defaultMap = $defaultMap[0]; $agent_position = getDataLastPositionAgent($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 = get_agent_name($agent_id); $conectionData = json_decode($defaultMap['conection_data'], true); $baselayers[0]['url'] = $conectionData['url']; $baselayers[0]['name'] = $defaultMap['conection_name']; $baselayers[0]['typeBaseLayer'] = $conectionData['type']; $controls = array('PanZoom', 'ScaleLine', 'Navigation', 'MousePosition', 'OverviewMap'); printMap($agent_name."_agent_map", $defaultMap['zoom_level'], $defaultMap['num_zoom_levels'], $defaultMap['initial_latitude'], $defaultMap['initial_longitude'], $baselayers, $controls); 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) { /* 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) { ?> $item) { $chunks = explode('.', $item); $extension = end($chunks); if (!in_array($extension, $validExtensions)) unset($dir[$index]); } $baseImages = array(); $stateImages = array(); foreach ($dir as $item) { if (strstr($item, "_") !== false) $stateImages[] = $item; else $baseImages[] = $item; } foreach ($baseImages as $item) { $chunks = explode('.', $item); $extension = end($chunks); $nameWithoutExtension = str_replace("." . $extension, "", $item); $return[$nameWithoutExtension]['ok'] = null; $return[$nameWithoutExtension]['bad'] = null; $return[$nameWithoutExtension]['warning'] = null; $return[$nameWithoutExtension]['default'] = $path . $item; if (in_array($nameWithoutExtension.'_bad.' . $extension, $stateImages)) $return[$nameWithoutExtension]['bad'] = $path . $nameWithoutExtension.'_bad.' . $extension; if (in_array($nameWithoutExtension.'_ok.' . $extension, $stateImages)) $return[$nameWithoutExtension]['ok'] = $path . $nameWithoutExtension.'_ok.' . $extension; $return[$nameWithoutExtension]['bad'] = $path . $nameWithoutExtension.'_bad.' . $extension; if (in_array($nameWithoutExtension.'_warning.' . $extension, $stateImages)) $return[$nameWithoutExtension]['warning'] = $path . $nameWithoutExtension.'_warning.' . $extension; } return $return; } function validateMapData($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) { $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 getMapData($idMap) { $returnVar = array(); $map = get_db_row('tgis_map', 'id_tgis_map', $idMap); $connections = get_db_all_rows_sql('SELECT tgis_map_connection_id_tmap_connection AS id_conection, default_map_connection AS `default` FROM tgis_map_has_tgis_map_connection WHERE tgis_map_id_tgis_map = '. $map['id_tgis_map']); $layers = get_db_all_rows_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 = ' . $map['id_tgis_map']); if ($layers === false) $layers = array(); foreach ($layers as $index => $layer) { $agents = get_db_all_rows_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 = ' . $layer['id_tmap_layer'] . ')'); if ($agents !== false) $layers[$index]['layer_agent_list'] = $agents; else $layers[$index]['layer_agent_list'] = array(); } $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 addConectionMapsInForm($map_connection_list) { $returnVar = ''; foreach ($map_connection_list as $mapConnection) { $mapConnectionRowDB = getMapConnection($mapConnection['id_conection']); if ($mapConnection['default']) { $radioButton = print_radio_button_extended('map_connection_default', $mapConnection['id_conection'], '', $mapConnection['id_conection'], false, 'changeDefaultConection(this.value)', '', true); } else $radioButton = print_radio_button_extended('map_connection_default', $mapConnection['id_conection'], '', null, false, 'changeDefaultConection(this.value)', '', true); $returnVar .= ' ' . print_input_text ('map_connection_name_' . $mapConnection['id_conection'], $mapConnectionRowDB['conection_name'], '', 20, 40, true, true) . ' ' . $radioButton . ' '; } 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 layers of map. * * @param Array $layer_list The list of layers for convert a html. * * @return String The html source code. */ function addLayerList($layer_list) { $returnVar = ''; $count = 0; foreach ($layer_list as $layer) { //Create the layer temp form as it was in the form $layerTempForm = array(); $layerTempForm['layer_name'] = $layer['layer_name']; $layerTempForm['layer_group'] = $layer['layer_group']; $layerTempForm['layer_visible'] = $layer['layer_visible']; if (array_key_exists('layer_agent_list', $layer)) { foreach($layer['layer_agent_list'] as $agent) { $layerTempForm['layer_agent_list'][] = $agent; } } $layerDataJSON = json_encode($layerTempForm); $returnVar .= ' ' . $layer['layer_name'] . ' '; $count ++; } return $returnVar; } ?>