Rewrote some parts the GIS to adapt from pandora v3 to newest versions. TICKET: #3170

This commit is contained in:
mdtrooper 2016-01-19 13:16:38 +01:00
parent 9cc979e69c
commit f253a16d9b
6 changed files with 388 additions and 384 deletions

View File

@ -17,12 +17,201 @@ global $config;
check_login ();
ui_print_page_header (__('GIS Maps builder'), "images/gm_gis.png", false, "configure_gis_map", true);
if (! check_acl ($config['id_user'], 0, "IW")) {
db_pandora_audit("ACL Violation", "Trying to access map builder");
require ("general/noaccess.php");
return;
}
require_once ('include/functions_gis.php');
$magicQuotesFlag = (boolean)ini_get('magic_quotes_gpc');
$idMap = (int)get_parameter('map_id', 0);
$action = get_parameter('action', 'new_map');
switch ($action) {
case 'save_new':
$map_name = get_parameter('map_name');
$map_initial_longitude = get_parameter('map_initial_longitude');
$map_initial_latitude = get_parameter('map_initial_latitude');
$map_initial_altitude = get_parameter('map_initial_altitude');
$map_zoom_level = get_parameter('map_zoom_level');
$map_background = ''; //TODO
$map_default_longitude = get_parameter('map_default_longitude');
$map_default_latitude = get_parameter('map_default_latitude');
$map_default_altitude = get_parameter('map_default_altitude');
$map_group_id = get_parameter('map_group_id');
$map_levels_zoom = get_parameter('map_levels_zoom');
$map_connection_list_temp = explode(",",get_parameter('map_connection_list'));
foreach ($map_connection_list_temp as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($map_connection_list_temp[$index]);
}
}
$layer_list = explode(",",get_parameter('layer_list'));
foreach ($layer_list as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($layer_list[$index]);
}
}
$map_connection_default = get_parameter('map_connection_default');
$map_connection_list = array();
foreach ($map_connection_list_temp as $idMapConnection) {
$default = 0;
if ($map_connection_default == $idMapConnection)
$default = 1;
$map_connection_list[] = array('id_conection' => $idMapConnection, 'default' => $default);
}
$arrayLayers = array();
foreach ($layer_list as $layerID) {
$layer = get_parameter('layer_values_' . $layerID);
$arrayLayers[] = JSON_decode($layer, true);
}
$invalidFields = 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);
if (empty($invalidFields) && get_parameter('map_connection_list') != "") {
$idMap = 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);
$mapCreatedOk = true;
}
else {
html_print_input_hidden('action', 'save_new');
$mapCreatedOk = false;
}
$layer_list = $arrayLayers;
ui_print_result_message ($mapCreatedOk, __('Map successfully created'),
__('Map could not be created'));
break;
case 'new_map':
html_print_input_hidden('action', 'save_new');
$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 = Array();
$layer_list = Array();
$map_levels_zoom = 0;
break;
case 'edit_map':
html_print_input_hidden('action', 'update_saved');
html_print_input_hidden('map_id', $idMap);
break;
case 'update_saved':
$map_name = get_parameter('map_name');
$map_initial_longitude = get_parameter('map_initial_longitude');
$map_initial_latitude = get_parameter('map_initial_latitude');
$map_initial_altitude = get_parameter('map_initial_altitude');
$map_zoom_level = get_parameter('map_zoom_level');
$map_background = ''; //TODO
$map_default_longitude = get_parameter('map_default_longitude');
$map_default_latitude = get_parameter('map_default_latitude');
$map_default_altitude = get_parameter('map_default_altitude');
$map_group_id = get_parameter('map_group_id');
$map_levels_zoom = get_parameter('map_levels_zoom');
$map_connection_list_temp = explode(",",get_parameter('map_connection_list'));
foreach ($map_connection_list_temp as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($map_connection_list_temp[$index]);
}
}
$layer_list = explode(",", get_parameter('layer_list'));
foreach ($layer_list as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($layer_list[$index]);
}
}
$map_connection_default = get_parameter('map_connection_default');
$map_connection_list = array();
foreach ($map_connection_list_temp as $idMapConnection) {
$default = 0;
if ($map_connection_default == $idMapConnection)
$default = 1;
$map_connection_list[] = array('id_conection' => $idMapConnection, 'default' => $default);
}
$arrayLayers = array();
foreach ($layer_list as $layerID) {
$layer = get_parameter('layer_values_' . $layerID);
$arrayLayers[] = JSON_decode($layer, true);
}
$invalidFields = 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);
if (empty($invalidFields) && get_parameter('map_connection_list') != "") {
//TODO
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);
$mapCreatedOk = true;
}
else {
html_print_input_hidden('action', 'update_saved');
$mapCreatedOk = false;
}
ui_print_result_message ($mapCreatedOk, __('Map successfully update'),
__('Map could not be updated'));
html_print_input_hidden('action', 'update_saved');
html_print_input_hidden('map_id', $idMap);
break;
}
$buttons['gis_maps_list'] = array('active' => true,
'text' => '<a href="index.php?sec=godgismaps&sec2=operation/gis_maps/gis_map">' .
html_print_image("images/list.png", true,
array("title" => __('GIS Maps list'))) .'</a>');
if ($idMap) {
$buttons['view_gis'] = array('active' => true,
'text' => '<a href="index.php?sec=gismaps&sec2=operation/gis_maps/render_view&map_id=' . $idMap . '">' .
html_print_image("images/op_gis.png", true,
array("title" => __('View GIS'))) .'</a>');
}
ui_print_page_header (__('GIS Maps builder'),
"images/gm_gis.png", false, "configure_gis_map", true, $buttons);
ui_require_javascript_file('openlayers.pandora');
//Global vars for javascript and scripts.
@ -78,195 +267,9 @@ function updateArrowLayers() {
</script>
<?php
if (! check_acl ($config['id_user'], 0, "IW")) {
db_pandora_audit("ACL Violation", "Trying to access map builder");
require ("general/noaccess.php");
return;
}
$action = get_parameter('action', 'new_map');
echo '<form id="form_setup" method="post" onSubmit="fillOrderField();">';
switch ($action) {
case 'save_new':
$map_name = get_parameter('map_name');
$map_initial_longitude = get_parameter('map_initial_longitude');
$map_initial_latitude = get_parameter('map_initial_latitude');
$map_initial_altitude = get_parameter('map_initial_altitude');
$map_zoom_level = get_parameter('map_zoom_level');
$map_background = ''; //TODO
$map_default_longitude = get_parameter('map_default_longitude');
$map_default_latitude = get_parameter('map_default_latitude');
$map_default_altitude = get_parameter('map_default_altitude');
$map_group_id = get_parameter('map_group_id');
$map_levels_zoom = get_parameter('map_levels_zoom');
$map_connection_list_temp = explode(",",get_parameter('map_connection_list'));
foreach ($map_connection_list_temp as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($map_connection_list_temp[$index]);
}
}
$layer_list = explode(",",get_parameter('layer_list'));
foreach ($layer_list as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($layer_list[$index]);
}
}
$map_connection_default = get_parameter('map_connection_default');
$map_connection_list = array();
foreach ($map_connection_list_temp as $idMapConnection) {
$default = 0;
if ($map_connection_default == $idMapConnection)
$default = 1;
$map_connection_list[] = array('id_conection' => $idMapConnection, 'default' => $default);
}
$arrayLayers = array();
foreach ($layer_list as $layerID) {
if ($magicQuotesFlag) {
$layer = stripslashes($_POST['layer_values_' . $layerID]);
}
else {
$layer = $_POST['layer_values_' . $layerID];
}
$arrayLayers[] = JSON_decode($layer, true);
}
$invalidFields = 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);
if (empty($invalidFields) && get_parameter('map_connection_list') != "") {
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);
$mapCreatedOk = true;
}
else {
html_print_input_hidden('action', 'save_new');
$mapCreatedOk = false;
}
$layer_list = $arrayLayers;
ui_print_result_message ($mapCreatedOk, __('Map successfully created'),
__('Map could not be created'));
break;
case 'new_map':
html_print_input_hidden('action', 'save_new');
$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 = Array();
$layer_list = Array();
$map_levels_zoom = 0;
break;
case 'edit_map':
$idMap = get_parameter('map_id');
html_print_input_hidden('action', 'update_saved');
html_print_input_hidden('map_id', $idMap);
break;
case 'update_saved':
$idMap = get_parameter('map_id');
$map_name = get_parameter('map_name');
$map_initial_longitude = get_parameter('map_initial_longitude');
$map_initial_latitude = get_parameter('map_initial_latitude');
$map_initial_altitude = get_parameter('map_initial_altitude');
$map_zoom_level = get_parameter('map_zoom_level');
$map_background = ''; //TODO
$map_default_longitude = get_parameter('map_default_longitude');
$map_default_latitude = get_parameter('map_default_latitude');
$map_default_altitude = get_parameter('map_default_altitude');
$map_group_id = get_parameter('map_group_id');
$map_levels_zoom = get_parameter('map_levels_zoom');
$map_connection_list_temp = explode(",",get_parameter('map_connection_list'));
foreach ($map_connection_list_temp as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($map_connection_list_temp[$index]);
}
}
$layer_list = explode(",", get_parameter('layer_list'));
foreach ($layer_list as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
unset($layer_list[$index]);
}
}
$map_connection_default = get_parameter('map_connection_default');
$map_connection_list = array();
foreach ($map_connection_list_temp as $idMapConnection) {
$default = 0;
if ($map_connection_default == $idMapConnection)
$default = 1;
$map_connection_list[] = array('id_conection' => $idMapConnection, 'default' => $default);
}
$arrayLayers = array();
foreach ($layer_list as $layerID) {
if ($magicQuotesFlag) {
$layer = stripslashes($_POST['layer_values_' . $layerID]);
}
else {
$layer = $_POST['layer_values_' . $layerID];
}
$arrayLayers[] = JSON_decode($layer, true);
}
$invalidFields = 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);
if (empty($invalidFields) && get_parameter('map_connection_list') != "") {
//TODO
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);
$mapCreatedOk = true;
}
else {
html_print_input_hidden('action', 'update_saved');
$mapCreatedOk = false;
}
ui_print_result_message ($mapCreatedOk, __('Map successfully update'),
__('Map could not be updated'));
html_print_input_hidden('action', 'update_saved');
html_print_input_hidden('map_id', $idMap);
break;
}
//Load the data in edit or reload in update.
switch ($action) {

View File

@ -1,166 +0,0 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
global $config;
check_login ();
require_once ('include/functions_gis.php');
ui_require_javascript_file('openlayers.pandora');
if (! check_acl ($config['id_user'], 0, "IW")) {
db_pandora_audit("ACL Violation", "Trying to access map builder");
require ("general/noaccess.php");
return;
}
if (is_ajax ()) {
$action = get_parameter('action');
$id_map = get_parameter('id_map');
// Set to not default the actual default map
$returnOperationDB = db_process_sql_update('tgis_map', array('default_map' => 0), array('default_map' => 1));
// Set default the new default map
$returnOperationDB = db_process_sql_update('tgis_map', array('default_map' => 1), array('id_tgis_map' => $id_map));
if ($returnOperationDB === false)
$data['correct'] = false;
else
$data['correct'] = true;
echo json_encode($data);
return;
}
$action = get_parameter('action');
$own_info = get_user_info($config['id_user']);
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
$display_default_column = true;
else
$display_default_column = false;
switch ($action) {
case 'delete_map':
$idMap = get_parameter('map_id');
gis_delete_map($idMap);
break;
}
ui_print_page_header (__('GIS Maps builder'), "images/gm_gis.png", false, "gis_map_builder", true);
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox data';
$table->head[0] = __('Map name');
$table->head[1] = __('Group');
$table->head[2] = __('View');
if ($display_default_column)
$table->head[3] = __('Default');
$table->head[4] = '<span title="Operations">' . __('Op.') . '</span>';
$table->align[1] = 'left';
$table->align[2] = 'left';
$table->align[3] = 'left';
$table->headstyle[4] = 'text-align:center';
$table->size = array();
$table->size[4] = '80px';
$maps = db_get_all_rows_in_table ('tgis_map','map_name');
$table->data = array();
$defaultMapId = null;
if ($maps) {
$own_info = get_user_info($config['id_user']);
foreach ($maps as $map) {
if (!check_acl ($config["id_user"], $map["group_id"], "IW")) {
continue;
}
$checked = false;
if ($map['default_map']) {
$checked = true;
$defaultMapId = $map['id_tgis_map'];
}
$table_info = array('<a href="index.php?sec=godgismaps&sec2=godmode/gis_maps/configure_gis_map&map_id='.$map['id_tgis_map'].'&amp;action=edit_map">' . $map['map_name'] . '</a>',
ui_print_group_icon ($map['group_id'], true),
'<a href="index.php?sec=gismaps&sec2=operation/gis_maps/render_view&map_id='.$map['id_tgis_map'].'">' . html_print_image ("images/eye.png", true).'</a>');
if ($display_default_column) {
$default_button = html_print_radio_button_extended('default_map', $map['id_tgis_map'], '', $checked, false, "setDefault(" . $map['id_tgis_map'] . ");", '', true);
array_push($table_info, $default_button);
}
$buttons = '<a href="index.php?sec=godgismaps&amp;sec2=godmode/gis_maps/configure_gis_map&map_id='.$map['id_tgis_map'].'&amp;action=edit_map">' . html_print_image ("images/config.png", true, array('title' => __('Edit'))).'</a>&nbsp;&nbsp;';
$buttons .= '<a href="index.php?sec=godgismaps&amp;sec2=godmode/gis_maps/index&amp;map_id='.$map['id_tgis_map'].'&amp;action=delete_map" onclick="return confirmDelete();">' . html_print_image ("images/cross.png", true, array('title' => __('Delete'))).'</a>';
array_push ($table_info, $buttons);
$table->data[] = $table_info;
}
}
if (!empty ($table->data)) {
html_print_table($table);
}
else {
echo '<div class="nf">'.('No maps defined').'</div>';
}
echo '<div class="action-buttons" style="width: '.$table->width.'">';
echo '<form action="index.php?sec=godgismaps&amp;sec2=godmode/gis_maps/configure_gis_map" method="post">';
html_print_input_hidden ('action','new_map');
html_print_submit_button (__('Create'), '', false, 'class="sub next"');
echo '</form>';
echo '</div>';
?>
<script type="text/javascript">
var defaultMapId = "<?php echo $defaultMapId; ?>";
function confirmDelete() {
if (confirm('<?php echo __('Caution: Do you want delete the map?');?>'))
return true;
return false;
}
function setDefault(id_tgis_map) {
if (confirm('<?php echo __('Do you want to set default the map?');?>')) {
jQuery.ajax ({
data: "page=godmode/gis_maps/index&action=set_default&id_map=" + id_tgis_map,
type: "POST",
dataType: 'json',
url: "ajax.php",
success: function (data) {
if (data.correct == 0) {
alert('<?php echo __('There was error on setup the default map.');?>');
}
}
});
}
else {
jQuery.each($("input[name=default_map]"), function() {
if ($(this).val() == defaultMapId) {
$(this).attr("checked", "checked");
}
else {
$(this).removeAttr("checked");
}
});
}
}
</script>

View File

@ -34,12 +34,12 @@ if (check_acl ($config['id_user'], 0, "AW") || check_acl ($config['id_user'], 0,
$sub['godmode/agentes/modificar_agente']['id'] = 'Manage agents';
$sub["godmode/agentes/modificar_agente"]["subsecs"] = array(
"godmode/agentes/configurar_agente");
if (check_acl ($config['id_user'], 0, "AW")) {
if (check_acl ($config["id_user"], 0, "PM")) {
$sub["godmode/agentes/fields_manager"]["text"] = __('Custom fields');
$sub["godmode/agentes/fields_manager"]["id"] = 'Custom fields';
$sub["godmode/modules/manage_nc_groups"]["text"] = __('Component groups');
$sub["godmode/modules/manage_nc_groups"]["id"] = 'Component groups';
// Category
@ -49,19 +49,11 @@ if (check_acl ($config['id_user'], 0, "AW") || check_acl ($config['id_user'], 0,
$sub["godmode/modules/module_list"]["text"] = __('Module types');
$sub["godmode/modules/module_list"]["id"] = 'Module types';
$sub["godmode/groups/modu_group_list"]["text"] = __('Module groups');
$sub["godmode/groups/modu_group_list"]["id"] = 'Module groups';
}
// GIS
if (check_acl ($config['id_user'], 0, "IW")) {
if ($config['activate_gis']) {
$sub["godmode/gis_maps/index"]["text"] = __('GIS Maps builder');
$sub["godmode/gis_maps/index"]["id"] = 'GIS Maps builder';
$sub["godmode/gis_maps/index"]["refr"] = (int)get_parameter('refr', 60);
}
}
if ($config['activate_netflow']) {
//Netflow
$sub["godmode/netflow/nf_edit"]["text"] = __('Netflow filters');
@ -75,7 +67,7 @@ if (check_acl ($config['id_user'], 0, "UM")) {
$menu_godmode["gusuarios"]["text"] = __('Profiles');
$menu_godmode["gusuarios"]["sec2"] = "godmode/users/user_list";
$menu_godmode["gusuarios"]["id"] = "god-users";
$sub = array ();
$sub['godmode/users/user_list']['text'] = __('Users management');
$sub['godmode/users/user_list']['id'] = 'Users management';
@ -265,8 +257,9 @@ if (check_acl ($config['id_user'], 0, "PM")) {
if ($config['activate_gis'])
if ($config['activate_gis']) {
$sub2["godmode/setup/gis"]["text"] = __('Map conections GIS');
}
$sub["general"]["sub2"] = $sub2;
$sub["godmode/setup/os"]["text"] = __('Edit OS');

12
pandora_console/godmode/setup/gis_step_2.php Executable file → Normal file
View File

@ -442,8 +442,16 @@ function refreshMapViewSecondStep() {
layer = js_makeLayer('temp_layer', true, null);
centerPoint = js_addPointExtent('temp_layer', '<?php echo __('Center'); ?>', $('input[name=center_longitude]').val(), $('input[name=center_latitude]').val(), 'images/gis_map/icons/circle.pink.png', 11, 11, 'center', '');
GISDefaultPositionPoint = js_addPointExtent('temp_layer', '<?php echo __('Default'); ?>', $('input[name=default_longitude]').val(), $('input[name=default_latitude]').val(), 'images/gis_map/icons/cross.pink.png', 11, 11, 'default', '');
centerPoint = js_addPointExtent('temp_layer',
'<?php echo __('Center'); ?>',
$('input[name=center_longitude]').val(),
$('input[name=center_latitude]').val(),
'images/gis_map/icons/circle.default.png', 11, 11, 'center', '');
GISDefaultPositionPoint = js_addPointExtent('temp_layer',
'<?php echo __('Default'); ?>',
$('input[name=default_longitude]').val(),
$('input[name=default_latitude]').val(),
'images/gis_map/icons/cross.default.png', 11, 11, 'default', '');
js_activateEvents(changePoints);
}

View File

@ -723,20 +723,34 @@ function gis_save_map_connection($mapConnection_name, $mapConnection_group,
* @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);
$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));
db_process_sql_delete('tgis_map_layer_has_tagente',
array('tgis_map_layer_id_tmap_layer' => $idLayer));
}
}
db_process_sql_delete('tgis_map_layer', array('tgis_map_id_tgis_map' => $idMap));
db_process_sql_delete('tgis_map_has_tgis_map_con', array('tgis_map_id_tgis_map' => $idMap));
db_process_sql_delete('tgis_map', array('id_tgis_map' => $idMap));
$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;
}
/**
@ -813,6 +827,8 @@ function gis_save_map($map_name, $map_initial_longitude, $map_initial_latitude,
}
}
}
return $idMap;
}
function gis_update_map($idMap, $map_name, $map_initial_longitude, $map_initial_latitude,

View File

@ -23,19 +23,105 @@ require_once ('include/functions_gis.php');
//ui_require_javascript_file('openlayers.pandora');
ui_print_page_header(__('GIS Maps')." &raquo; ".__('Summary'), "images/op_gis.png", false, "");
$buttons['gis_maps_list'] = array('active' => true,
'text' => '<a href="index.php?sec=godgismaps&sec2=operation/gis_maps/gis_map">' .
html_print_image("images/list.png", true,
array("title" => __('GIS Maps list'))) .'</a>');
ui_print_page_header(__('GIS Maps'), "images/op_gis.png", false,
"configure_gis_map", false, $buttons);
$own_info = get_user_info($config['id_user']);
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
$display_default_column = true;
else
$display_default_column = false;
$edit_gis_maps = false;
if (check_acl ($config['id_user'], 0, "IW")) {
$edit_gis_maps = true;
}
if (is_ajax ()) {
$action = get_parameter('action');
$id_map = get_parameter('id_map');
// Set to not default the actual default map
$returnOperationDB = db_process_sql_update('tgis_map', array('default_map' => 0), array('default_map' => 1));
// Set default the new default map
$returnOperationDB = db_process_sql_update('tgis_map', array('default_map' => 1), array('id_tgis_map' => $id_map));
if ($returnOperationDB === false)
$data['correct'] = false;
else
$data['correct'] = true;
echo json_encode($data);
return;
}
$action = get_parameter('action');
switch ($action) {
case 'delete_map':
$idMap = get_parameter('map_id');
$result = gis_delete_map($idMap);
ui_print_result_message($result,
__('Successfully deleted'),
__('Could not be deleted'));
break;
}
$maps = gis_get_maps();
$table = new stdClass();
$table->width = "100%";
$table->class = "databox data";
$table->data = array ();
$table->head = array ();
$table->head[0] = __('Name');
$table->head[1] = __('Group');
$table->head['name'] = __('Name');
$table->head['group'] = __('Group');
if ($edit_gis_maps) {
if ($display_default_column)
$table->head['default'] = __('Default');
$table->head['op'] = '<span title="Operations">' . __('Op.') . '</span>';
}
$table->headstyle = array();
$table->headstyle['name'] = 'text-align: left;';
$table->headstyle['group'] = 'text-align: center;';
if ($edit_gis_maps) {
if ($display_default_column)
$table->headstyle['default'] = 'text-align: center;';
$table->headstyle['op'] = 'text-align: center;';
}
$table->size = array();
$table->size['name'] = "80%";
$table->size['group'] = "30";
if ($edit_gis_maps) {
if ($display_default_column)
$table->size['default'] = "30";
$table->size['op'] = "60";
}
$table->align = array ();
$table->align[1] = 'left';
$table->align['name'] = 'left';
$table->align['group'] = 'center';
if ($edit_gis_maps) {
if ($display_default_column)
$table->align['default'] = 'center';
$table->align['op'] = 'center';
}
$table->data = array ();
$rowPair = true;
$iterator = 0;
@ -55,10 +141,27 @@ if ($maps !== false) {
$data = array ();
$data[0] = '<a href="index.php?sec=gismaps&amp;sec2=operation/gis_maps/render_view&amp;map_id='.
$map['id_tgis_map'] . '">' . $map['map_name'].'</a> ';
$data[1] = ui_print_group_icon ($map["group_id"], true);
$data['name'] = '<a href="index.php?sec=gismaps&amp;sec2=operation/gis_maps/render_view&amp;map_id='.
$map['id_tgis_map'] . '">' . $map['map_name'].'</a> ';
$data['group'] = ui_print_group_icon ($map["group_id"], true);
if ($edit_gis_maps) {
if ($display_default_column) {
$checked = false;
if ($map['default_map']) {
$checked = true;
$defaultMapId = $map['id_tgis_map'];
}
$data['default'] =
html_print_radio_button_extended('default_map', $map['id_tgis_map'], '', $checked, false, "setDefault(" . $map['id_tgis_map'] . ");", '', true);
}
$data['op'] = '<a href="index.php?sec=godgismaps&amp;sec2=godmode/gis_maps/configure_gis_map&map_id='.$map['id_tgis_map'].'&amp;action=edit_map">' .
html_print_image ("images/config.png", true, array('title' => __('Edit'))).'</a>&nbsp;&nbsp;' .
'<a href="index.php?sec=godgismaps&amp;sec2=operation/gis_maps/gis_map&amp;map_id='.$map['id_tgis_map'].'&amp;action=delete_map" onclick="return confirmDelete();">' .
html_print_image ("images/cross.png", true, array('title' => __('Delete'))).'</a>';
}
array_push ($table->data, $data);
}
}
@ -69,5 +172,52 @@ if (!empty ($table->data)) {
else {
echo '<div class="nf">' . __('No maps found') . '</div>';
}
if ($edit_gis_maps) {
echo '<div class="action-buttons" style="width: '.$table->width.'">';
echo '<form action="index.php?sec=godgismaps&amp;sec2=godmode/gis_maps/configure_gis_map" method="post">';
html_print_input_hidden ('action','new_map');
html_print_submit_button (__('Create'), '', false, 'class="sub next"');
echo '</form>';
echo '</div>';
}
unset ($table);
?>
<script type="text/javascript">
var defaultMapId = "<?php echo $defaultMapId; ?>";
function confirmDelete() {
if (confirm('<?php echo __('Caution: Do you want delete the map?');?>'))
return true;
return false;
}
function setDefault(id_tgis_map) {
if (confirm('<?php echo __('Do you want to set default the map?');?>')) {
jQuery.ajax ({
data: "page=operation/gis_maps/gis_map&action=set_default&id_map=" + id_tgis_map,
type: "POST",
dataType: 'json',
url: "ajax.php",
success: function (data) {
if (data.correct == 0) {
alert('<?php echo __('There was error on setup the default map.');?>');
}
}
});
}
else {
jQuery.each($("input[name=default_map]"), function() {
if ($(this).val() == defaultMapId) {
$(this).attr("checked", "checked");
}
else {
$(this).removeAttr("checked");
}
});
}
}
</script>