Merge branch 'ent-7377-fallos-en-gis-maps' into 'develop'

fixed error with creation and updating gis maps

See merge request artica/pandorafms!4072
This commit is contained in:
Daniel Rodriguez 2021-04-27 11:44:55 +00:00
commit 55c38dfc03
4 changed files with 238 additions and 169 deletions

View File

@ -44,7 +44,7 @@ $sec2 = safe_url_extraclean($sec2);
$sec = get_parameter_get('sec');
$sec = safe_url_extraclean($sec);
// Layers
// Layers.
$layer_ids = get_parameter('layer_ids', []);
$layers = get_parameter('layers', []);
$layer_list = [];
@ -84,9 +84,10 @@ switch ($action) {
$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_levels_zoom = get_parameter('map_levels_zoom', 16);
$map_connection_list_temp = explode(',', get_parameter('map_connection_list'));
$listConnectionTemp = db_get_all_rows_sql('SELECT id_tmap_connection, conection_name, group_id FROM tgis_map_connection');
foreach ($map_connection_list_temp as $index => $value) {
@ -99,14 +100,14 @@ switch ($action) {
$map_connection_default = get_parameter('map_connection_default');
$map_connection_list = [];
foreach ($map_connection_list_temp as $idMapConnection) {
foreach ($listConnectionTemp as $idMapConnection) {
$default = 0;
if ($map_connection_default == $idMapConnection) {
if ($map_connection_default == $idMapConnection['id_tmap_connection']) {
$default = 1;
}
$map_connection_list[] = [
'id_conection' => $idMapConnection,
'id_conection' => $idMapConnection['id_tmap_connection'],
'default' => $default,
];
}
@ -124,7 +125,7 @@ switch ($action) {
$map_levels_zoom
);
if (empty($invalidFields) && get_parameter('map_connection_list') != '') {
if (empty($invalidFields)) {
$idMap = gis_save_map(
$map_name,
$map_initial_longitude,
@ -139,12 +140,17 @@ switch ($action) {
$map_connection_list,
$layer_list
);
if ($idMap) {
$mapCreatedOk = true;
$next_action = 'update_saved';
} else {
$next_action = 'save_new';
$mapCreatedOk = false;
}
} else {
$next_action = 'save_new';
$mapCreatedOk = false;
}
ui_print_result_message(
$mapCreatedOk,
@ -168,7 +174,7 @@ switch ($action) {
$map_group_id = '';
$map_connection_list = [];
$layer_list = [];
$map_levels_zoom = 0;
$map_levels_zoom = 16;
break;
case 'edit_map':
@ -188,9 +194,12 @@ switch ($action) {
$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_levels_zoom = get_parameter('map_levels_zoom', 16);
$map_connection_list_temp = explode(',', get_parameter('map_connection_list'));
$listConnectionTemp = db_get_all_rows_sql('SELECT id_tmap_connection, conection_name, group_id FROM tgis_map_connection');
foreach ($map_connection_list_temp as $index => $value) {
$cleanValue = trim($value);
if ($cleanValue == '') {
@ -201,14 +210,14 @@ switch ($action) {
$map_connection_default = get_parameter('map_connection_default');
$map_connection_list = [];
foreach ($map_connection_list_temp as $idMapConnection) {
foreach ($listConnectionTemp as $idMapConnection) {
$default = 0;
if ($map_connection_default == $idMapConnection) {
if ($map_connection_default == $idMapConnection['id_tmap_connection']) {
$default = 1;
}
$map_connection_list[] = [
'id_conection' => $idMapConnection,
'id_conection' => $idMapConnection['id_tmap_connection'],
'default' => $default,
];
}
@ -226,7 +235,7 @@ switch ($action) {
$map_levels_zoom
);
if (empty($invalidFields) && get_parameter('map_connection_list') != '') {
if (empty($invalidFields)) {
// TODO
gis_update_map(
$idMap,
@ -263,7 +272,7 @@ switch ($action) {
$url = 'index.php?sec='.$sec.'&sec2='.$sec2.'&map_id='.$idMap.'&action='.$next_action;
$buttons['gis_maps_list'] = [
'active' => true,
'active' => false,
'text' => '<a href="index.php?sec=godgismaps&sec2=operation/gis_maps/gis_map">'.html_print_image(
'images/list.png',
true,
@ -275,7 +284,7 @@ $buttons['gis_maps_list'] = [
];
if ($idMap) {
$buttons['view_gis'] = [
'active' => true,
'active' => false,
'text' => '<a href="index.php?sec=gismaps&sec2=operation/gis_maps/render_view&map_id='.$idMap.'">'.html_print_image(
'images/op_gis.png',
true,
@ -457,7 +466,7 @@ $table->data[1][0] = __('Add Map connection').$iconError;
$table->data[1][1] = "<table class='no-class' border='0' id='map_connection'>
<tr>
<td >
".html_print_select($listConnection, 'map_connection', '', '', '', '0', true)."
".html_print_select($listConnection, 'map_connection_list', '', '', '', '0', true)."
</td>
<td >
<a href='javascript: addConnectionMap();'>".html_print_image(
@ -504,7 +513,11 @@ $table->data[2][1] = html_print_select_groups(
);
$table->data[3][0] = __('Default zoom');
$table->data[3][1] = html_print_input_text('map_zoom_level', $map_zoom_level, '', 2, 4, true).html_print_input_hidden('map_levels_zoom', $map_levels_zoom, true);
$table->data[3][1] = html_print_input_text('map_zoom_level', $map_zoom_level, '', 2, 4, true).html_print_input_hidden(
'map_levels_zoom',
$map_levels_zoom,
true
);
$table->data[4][0] = __('Center Latitude').':';
$table->data[4][1] = html_print_input_text('map_initial_latitude', $map_initial_latitude, '', 8, 8, true);
@ -571,6 +584,9 @@ $params['hidden_input_idagent_name'] = 'agent_id';
$params['input_name'] = 'agent_alias';
$params['value'] = '';
$params['javascript_function_action_after_select'] = 'active_button_add_agent';
$params['javascript_is_function_select'] = true;
$params['disabled_javascript_on_blur_function'] = false;
$table->data[1][1] .= ui_print_agent_autocomplete_input($params);
@ -585,7 +601,7 @@ $table->data[1][1] .= '</td>
</td>
</tr>';
// Group items
// Group items.
$group_select = html_print_select_groups($config['id_user'], 'AR', false, 'layer_group_id', '', '', '', 0, true);
$params = [];
$params['return'] = true;
@ -597,8 +613,10 @@ $params['input_name'] = 'agent_alias_for_data';
$params['value'] = '';
$params['javascript_function_action_after_select'] = 'toggleAddGroupBtn';
$params['selectbox_group'] = 'layer_group_id';
// Filter by group
$params['disabled_javascript_on_blur_function'] = true;
$params['javascript_is_function_select'] = true;
// Filter by group.
$params['disabled_javascript_on_blur_function'] = false;
$agent_for_group_input = ui_print_agent_autocomplete_input($params);
$add_group_btn = html_print_button(__('Add'), 'add_group', true, '', 'class="sub add"', true);

View File

@ -279,25 +279,25 @@ if ($mapConnectionData != null) {
}
// Open Street Map Connection.
$optionsConnectionOSMTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="50%">'.'<tr class="row_0">'.'<td>'.htmlentities(
$optionsConnectionOSMTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="50%"><tr class="row_0"><td>'.htmlentities(
__('Tile Server URL'),
ENT_QUOTES,
'UTF-8'
).':</td>'.'<td><input id="type" type="hidden" name="type" value="OSM" />'.html_print_input_text(
).':</td><td><input id="type" type="hidden" name="type" value="OSM" />'.html_print_input_text(
'url',
$mapConnectionDataUrl,
'',
45,
90,
true
).'</td>'.'</tr>'.'</table>';
).'</td></tr></table>';
// Google Maps Connection.
$gmaps_types['G_PHYSICAL_MAP'] = __('Google Physical');
$gmaps_types['G_HYBRID_MAP'] = __('Google Hybrid');
$gmaps_types['G_SATELITE_MAP'] = __('Google Satelite');
// TODO: Use label tags for the forms.
$optionsConnectionGmapTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="90%">'.'<tr class="row_0">'.'<td>'.__('Google Map Type').':</td>'.'<td><input id="type" type="hidden" name="type" value="Gmap" />'.trim(
$optionsConnectionGmapTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="90%"><tr class="row_0"><td>'.__('Google Map Type').':</td><td><input id="type" type="hidden" name="type" value="Gmap" />'.trim(
html_print_select(
$gmaps_types,
'gmap_type',
@ -305,56 +305,98 @@ $optionsConnectionOSMTable = '<table class="databox" border="0" cellpadding="4"
'',
'',
0,
true
true,
false,
true,
'',
false,
false,
false,
false,
false,
'',
false,
false,
false,
false,
false
)
).'</td>'.'</tr>'.'<tr class="row_2">'.'<td>'.__('Google Maps Key').':</td>'.'</tr>'.'<tr class="row_3">'.'<td colspan="2">'.html_print_input_text(
).'</td></tr><tr class="row_2"><td>'.__('Google Maps Key').':</td></tr><tr class="row_3"><td colspan="2">'.html_print_input_text(
'gmap_key',
$gmap_key,
'',
90,
128,
true
).'</td>'.'</tr>'.'</table>';
).'</td></tr></table>';
// Image Map Connection.
$optionsConnectionImageTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="50%">'.'<tr class="row_0">'.'<td>'.__('Image URL').':</td>'.'<td colspan="3"><input id="type" type="hidden" name="type" value="Static_Image" />'.html_print_input_text(
$optionsConnectionImageTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="50%"><tr class="row_0"><td>'.__('Image URL').':</td><td colspan="3"><input id="type" type="hidden" name="type" value="Static_Image" />'.html_print_input_text(
'url',
$mapConnectionDataUrl,
'',
45,
90,
true
).'</td>'.'</tr>'.'<tr class="row_1">'.'<td colspan="4"><strong>'.__('Corners of the area of the image').':</strong></td>'.'</tr>'.'<tr class="row_2">'.'<td>'.__('Left').':</td>'.'<td>'.html_print_input_text(
).'</td></tr><tr class="row_1"><td colspan="4"><strong>'.__('Corners of the area of the image').':</strong></td></tr><tr class="row_2"><td>'.__('Left').':</td><td>'.html_print_input_text(
'bb_left',
$bb_left,
'',
25,
25,
true
).'</td>'.'<td>'.__('Bottom').':</td>'.'<td>'.html_print_input_text(
).'</td><td>'.__('Bottom').':</td><td>'.html_print_input_text(
'bb_bottom',
$bb_bottom,
'',
25,
25,
true
).'</td>'.'</tr>'.'<tr class="row_3">'.'<td>'.__('Right').':</td>'.'<td>'.html_print_input_text(
).'</td></tr><tr class="row_3"><td>'.__('Right').':</td><td>'.html_print_input_text(
'bb_right',
$bb_right,
'',
25,
25,
true
).'</td>'.'<td>'.__('Top').':</td>'.'<td>'.html_print_input_text(
).'</td><td>'.__('Top').':</td><td>'.html_print_input_text(
'bb_top',
$bb_top,
'',
25,
25,
true
).'</td>'.'</tr>'.'<tr class="row_4">'.'<td colspan="4"><strong>'.__('Image Size').':</strong></td>'.'</tr>'.'<tr class="row_5">'.'<td>'.__('Width').':</td>'.'<td>'.html_print_input_text('image_width', $image_width, '', 25, 25, true).'</td>'.'<td>'.__('Height').':</td>'.'<td>'.html_print_input_text('image_height', $image_height, '', 25, 25, true).'</td>'.'</tr>'.'</table>';
).'</td></tr><tr class="row_4"><td colspan="4"><strong>'.__('Image Size').':</strong></td></tr><tr class="row_5"><td>'.__('Width').':</td><td>'.html_print_input_text(
'image_width',
$image_width,
'',
25,
25,
true
).'</td><td>'.__('Height').':</td><td>'.html_print_input_text(
'image_height',
$image_height,
'',
25,
25,
true
).'</td></tr></table>';
// WMS Server Connection.
$optionsConnectionWMSTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="50%">'.'<tr class="row_0">'.'<td>'.__('WMS Server URL').'</td>'.'<td>'.'<input id="type" type="hidden" name="type" value="WMS" />'.html_print_input_text('url', $mapConnectionDataUrl, '', 90, 255, true).'</td>'.'</tr>'.'<tr class="row_1">'.'<td>'.__('Layers').'</td>'.'<td>'.html_print_input_text('layers', $layers, '', 90, 255, true).'</td>'.'</tr>'.'</table>';
$optionsConnectionWMSTable = '<table class="databox" border="0" cellpadding="4" cellspacing="4" width="50%"><tr class="row_0"><td>'.__('WMS Server URL').'</td><td><input id="type" type="hidden" name="type" value="WMS" />'.html_print_input_text(
'url',
$mapConnectionDataUrl,
'',
90,
255,
true
).'</td></tr><tr class="row_1"><td>'.__('Layers').'</td><td>'.html_print_input_text(
'layers',
$layers,
'',
90,
255,
true
).'</td></tr></table>';
if ($mapConnectionData != null) {
switch ($mapConnection_type) {
@ -383,7 +425,7 @@ $optionsConnectionOSMTable = '<table class="databox" border="0" cellpadding="4"
echo "<div id='form_map_connection_type'>".$optionsConnectionTypeTable.'</div>';
echo '<h4>'.__('Preview to select the center of the map and the default position of an agent without gis data').'</h4><br>';
html_print_button(__('Load preview map'), 'button_refresh', false, 'refreshMapView();', 'class="sub"');
html_print_button(__('Load preview map'), 'button_refresh', false, 'refreshMapView();', 'class="sub next"');
echo '<br /><br />';
echo "<div id='map' class='map_gis_step2'></div>";
@ -472,7 +514,7 @@ $optionsConnectionOSMTable = '<table class="databox" border="0" cellpadding="4"
);
html_print_table($table);
echo '<div class="action-buttons w90p left">';
echo '<div class="action-buttons w90p float-left">';
html_print_submit_button(__('Save'), '', false, 'class="sub save wand"');
echo '</div>';
echo '</form>';
@ -649,7 +691,6 @@ function selMapConnectionType() {
$('#form_map_connection_type').html('<?php echo $optionsConnectionOSMTable; ?>').hide();
break;
case 'Gmap':
// TODO: Validate there is a key, and use it
$('#form_map_connection_type').html('<?php echo $optionsConnectionGmapTable; ?>').hide();
break;
case 'Static_Image':

View File

@ -971,7 +971,7 @@ function gis_save_map(
]
);
// Angent
if ((isset($layer['layer_agent_list'])) and (count($layer['layer_agent_list']) > 0)) {
if ((isset($layer['layer_agent_list'])) && (count($layer['layer_agent_list']) > 0)) {
foreach ($layer['layer_agent_list'] as $agent) {
db_process_sql_insert(
'tgis_map_layer_has_tagente',
@ -984,7 +984,7 @@ function gis_save_map(
}
// Group
if ((isset($layer['layer_group_list'])) and (count($layer['layer_group_list']) > 0)) {
if ((isset($layer['layer_group_list'])) && (count($layer['layer_group_list']) > 0)) {
foreach ($layer['layer_group_list'] as $group) {
db_process_sql_insert(
'tgis_map_layer_groups',
@ -1386,55 +1386,55 @@ function gis_validate_map_data(
echo "<style type='text/css'>";
// validateMap
// ValidateMap.
if ($map_name == '') {
echo 'input[name=map_name] {background: #FF5050;}';
$invalidFields['map_name'] = true;
}
// validate zoom level
// Validate zoom level.
if (($map_zoom_level == '') || ($map_zoom_level > $map_levels_zoom)) {
echo 'input[name=map_zoom_level] {background: #FF5050;}';
$invalidFields['map_zoom_level'] = true;
}
// validate map_initial_longitude
// Validate map_initial_longitude.
if ($map_initial_longitude == '') {
echo 'input[name=map_initial_longitude] {background: #FF5050;}';
$invalidFields['map_initial_longitude'] = true;
}
// validate map_initial_latitude
// Validate map_initial_latitude.
if ($map_initial_latitude == '') {
echo 'input[name=map_initial_latitude] {background: #FF5050;}';
$invalidFields['map_initial_latitude'] = true;
}
// validate map_initial_altitude
// Validate map_initial_altitude.
if ($map_initial_altitude == '') {
echo 'input[name=map_initial_altitude] {background: #FF5050;}';
$invalidFields['map_initial_altitude'] = true;
}
// validate map_default_longitude
// Validate map_default_longitude.
if ($map_default_longitude == '') {
echo 'input[name=map_default_longitude] {background: #FF5050;}';
$invalidFields['map_default_longitude'] = true;
}
// validate map_default_latitude
// Validate map_default_latitude.
if ($map_default_latitude == '') {
echo 'input[name=map_default_latitude] {background: #FF5050;}';
$invalidFields['map_default_latitude'] = true;
}
// validate map_default_altitude
// Validate map_default_altitude.
if ($map_default_altitude == '') {
echo 'input[name=map_default_altitude] {background: #FF5050;}';
$invalidFields['map_default_altitude'] = true;
}
// validate map_default_altitude
// Validate map_default_altitude.
if ($map_connection_list == '') {
$invalidFields['map_connection_list'] = true;
}

View File

@ -119,6 +119,16 @@ $has_management_acl = check_acl_restricted_all($config['id_user'], $map['group_i
$buttons = [];
$buttons['gis_maps_list'] = [
'text' => '<a href="index.php?sec=godgismaps&sec2=operation/gis_maps/gis_map">'.html_print_image(
'images/list.png',
true,
[
'title' => __('GIS Maps list'),
'class' => 'invert_filter',
]
).'</a>',
];
if ($config['pure'] == 0) {
$buttons[]['text'] = '<a href="index.php?sec=gismaps&amp;sec2=operation/gis_maps/render_view&amp;map_id='.$idMap.'&amp;refr='.((int) get_parameter('refr', 0)).'&amp;pure=1">'.html_print_image('images/full_screen.png', true, ['title' => __('Full screen mode'), 'class' => 'invert_filter']).'</a>';
} else {
@ -193,7 +203,7 @@ if ($layers != false) {
$layer['id_tmap_layer']
);
// calling agents_get_group_agents with none to obtain the names in the same case as they are in the DB.
// Calling agents_get_group_agents with none to obtain the names in the same case as they are in the DB.
$agentNamesByGroup = [];
if ($layer['tgrupo_id_grupo'] >= 0) {
$agentNamesByGroup = agents_get_group_agents(
@ -239,7 +249,7 @@ if ($layers != false) {
$icon_width = $icon_size[0];
$icon_height = $icon_size[1];
// Is a group item
// Is a group item.
if (!empty($groupsByAgentId[$idAgent])) {
$groupId = (int) $groupsByAgentId[$idAgent]['id'];
$groupName = $groupsByAgentId[$idAgent]['name'];