Merge branch 'ent-2335-gis-group-items' into 'develop'

Grupos como elementos de mapa GIS

See merge request artica/pandorafms!1693
This commit is contained in:
vgilc 2018-08-17 11:22:35 +02:00
commit e78fc93f17
9 changed files with 993 additions and 597 deletions

View File

@ -62,4 +62,17 @@ ALTER TABLE `tusuario_perfil` DROP COLUMN `is_secondary`;
UPDATE `talert_commands` SET name='Monitoring Event' WHERE name='Pandora FMS Event';
-- -----------------------------------------------------
-- Table `tgis_map_layer_groups`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tgis_map_layer_groups` (
`layer_id` INT NOT NULL,
`group_id` MEDIUMINT(4) UNSIGNED NOT NULL,
`agent_id` INT(10) UNSIGNED NOT NULL COMMENT 'Used to link the position to the group',
PRIMARY KEY (`layer_id`, `group_id`),
FOREIGN KEY (`layer_id`) REFERENCES `tgis_map_layer` (`id_tmap_layer`) ON DELETE CASCADE,
FOREIGN KEY (`group_id`) REFERENCES `tgrupo` (`id_grupo`) ON DELETE CASCADE,
FOREIGN KEY (`agent_id`) REFERENCES `tagente` (`id_agente`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
COMMIT;

File diff suppressed because it is too large Load Diff

View File

@ -91,7 +91,8 @@ function alerts_get_alerts($id_group = 0, $free_search = "", $status = "all", $s
}
else {
$sql = 'SELECT *, t2.nombre AS module_name,
t3.nombre AS agent_name, t1.name AS template_name,
t3.nombre AS agent_name, t3.alias AS agent_alias,
t1.name AS template_name,
t0.disabled AS alert_disabled ';
}
$sql .= '

View File

@ -172,6 +172,10 @@ function gis_make_layer($name, $visible = true, $dot = null, $idLayer = null, $p
}
$visible = (bool)$visible;
$ajax_url = $public_console
? ui_get_full_url('operation/gis_maps/ajax.php', false, false, false, false)
: ui_get_full_url('ajax.php', false, false, false, false);
?>
<script type="text/javascript">
$(document).ready (
@ -210,7 +214,9 @@ function gis_make_layer($name, $visible = true, $dot = null, $idLayer = null, $p
.css("text-align", "center")
.html('<img src="' + img_src + '" />')
.dialog({
title: "<?php echo __('Agent'); ?> #" + featureData.id,
title: featureData.type == "point_group_info"
? "<?php echo __('Group'); ?> #" + featureData.id_parent
: "<?php echo __('Agent'); ?> #" + featureData.id,
resizable: true,
draggable: true,
modal: true,
@ -224,11 +230,12 @@ function gis_make_layer($name, $visible = true, $dot = null, $idLayer = null, $p
});
jQuery.ajax ({
url: "<?php echo ui_get_full_url('ajax.php', false, false, false, false); ?>",
url: "<?php echo $ajax_url; ?>",
data: {
page: "operation/gis_maps/ajax",
opt: featureData.type,
id: featureData.id,
id_parent: featureData.id_parent,
hash: "<?php echo $hash; ?>",
id_user: "<?php echo $config['id_user']; ?>",
map_id: <?php echo (int)$id_map; ?>
@ -469,6 +476,38 @@ function gis_get_agents_layer($idLayer) {
return $returned_agents;
}
/**
* Get the groups into the layer by agent Id.
*
* @param integer $idLayer Layer Id.
*
* @return array.
*/
function gis_get_groups_layer_by_agent_id ($idLayer) {
$sql = sprintf(
"SELECT
tg.id_grupo AS id,
tg.nombre AS name,
ta.id_agente AS agent_id,
ta.alias AS agent_alias,
ta.nombre AS agent_name
FROM tgis_map_layer_groups tgmlg
INNER JOIN tgrupo tg
ON tgmlg.group_id = tg.id_grupo
INNER JOIN tagente ta
ON tgmlg.agent_id = ta.id_agente
WHERE tgmlg.layer_id = %d",
$idLayer
);
$groups = db_get_all_rows_sql($sql);
if ($groups === false) $groups = array();
return array_reduce($groups, function ($all, $item) {
$all[$item["agent_id"]] = $item;
return $all;
}, array());
}
function gis_add_point_path($layerName, $lat, $lon, $color, $manual = 1, $id) {
?>
<script type="text/javascript">
@ -823,12 +862,25 @@ function gis_save_map($map_name, $map_initial_longitude, $map_initial_latitude,
'tgrupo_id_grupo' => $layer['layer_group']
)
);
// Angent
if ((isset($layer['layer_agent_list'])) AND (count($layer['layer_agent_list']) > 0)) {
foreach ($layer['layer_agent_list'] as $agent_name) {
foreach ($layer['layer_agent_list'] as $agent) {
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))
'tagente_id_agente' => $agent["id"]
)
);
}
}
// Group
if ((isset($layer['layer_group_list'])) AND (count($layer['layer_group_list']) > 0)) {
foreach ($layer['layer_group_list'] as $group) {
db_process_sql_insert('tgis_map_layer_groups',
array(
"layer_id" => $idLayer,
"group_id" => $group["id"],
"agent_id" => $group["agent_id"]
)
);
}
@ -880,11 +932,12 @@ function gis_update_map($idMap, $map_name, $map_initial_longitude, $map_initial_
foreach ($listOldIdLayers as $idLayer) {
db_process_sql_delete('tgis_map_layer_has_tagente',
array('tgis_map_layer_id_tmap_layer' => $idLayer['id_tmap_layer']));
db_process_sql_delete('tgis_map_layer_groups',
array('layer_id' => $idLayer['id_tmap_layer']));
$list_onlyIDsLayers[$idLayer['id_tmap_layer']] = 0;
}
foreach ($arrayLayers as $index => $layer) {
if ($layer['id'] != 0) {
@ -915,18 +968,28 @@ function gis_update_map($idMap, $map_name, $map_initial_longitude, $map_initial_
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',
foreach ($layer['layer_agent_list'] as $agent) {
$id = 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))
'tagente_id_agente' => $agent["id"]
)
);
}
}
}
if (array_key_exists('layer_group_list', $layer)) {
if (count($layer['layer_group_list']) > 0) {
foreach ($layer['layer_group_list'] as $group) {
$id = db_process_sql_insert('tgis_map_layer_groups', array(
"layer_id" => $idLayer,
"group_id" => $group["id"],
"agent_id" => $group["agent_id"]
));
}
}
}
}
//Delete layers that not carry the $arrayLayers
@ -1244,7 +1307,8 @@ function gis_get_map_data($idMap) {
break;
}
$sql = "SELECT id_tmap_layer, layer_name,
$sql = "SELECT id_tmap_layer AS id,
layer_name,
tgrupo_id_grupo AS layer_group,
view_layer AS layer_visible
FROM tgis_map_layer
@ -1254,12 +1318,12 @@ function gis_get_map_data($idMap) {
if ($layers === false) $layers = array();
foreach ($layers as $index => $layer) {
if (!isset($layer['id_tmap_layer']))
continue;
if (!isset($layer['id'])) continue;
$id_tmap_layer = (int) $layer['id_tmap_layer'];
$id_tmap_layer = (int) $layer['id'];
$sql = "SELECT nombre
// Agent list
$sql = "SELECT id_agente AS id, alias
FROM tagente
WHERE id_agente IN (
SELECT tagente_id_agente
@ -1269,6 +1333,26 @@ function gis_get_map_data($idMap) {
if ($agents === false) $agents = array();
$layers[$index]['layer_agent_list'] = $agents;
// Group list
$sql = sprintf(
"SELECT
tg.id_grupo AS id,
tg.nombre AS name,
ta.id_agente AS agent_id,
ta.alias AS agent_alias
FROM tgis_map_layer_groups tgmlg
INNER JOIN tgrupo tg
ON tgmlg.group_id = tg.id_grupo
INNER JOIN tagente ta
ON tgmlg.agent_id = ta.id_agente
WHERE tgmlg.layer_id = %d",
$id_tmap_layer
);
$groups = db_get_all_rows_sql($sql);
if ($groups === false) $groups = array();
$layers[$index]['layer_group_list'] = $groups;
}
$returnVar['map'] = $map;
@ -1331,63 +1415,6 @@ function gis_get_num_zoom_levels_connection_default($map_connection_list) {
}
}
/**
* 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 gis_add_layer_list($layer_list) {
$returnVar = '';
$count = 0;
foreach ($layer_list as $layer) {
//Create the layer temp form as it was in the form
$layerTempForm = array();
$layerTempForm['id'] = $layer['id'];
$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 .= '
<tbody id="layer_item_' . $count . '">
<tr>
<td class="col1">' .
$layer['layer_name'] .
'</td>
<td class="up_arrow"><a id="up_arrow" href="javascript: upLayer(' . $count . ');">' . html_print_image("images/up.png", true, array("alt" => "")) . '</a></td>
<td class="down_arrow"><a id="down_arrow" href="javascript: downLayer(' . $count . ');">' . html_print_image("images/down.png", true, array("alt" => "")) . '</a></td>
<td class="col3">
<a id="edit_layer" href="javascript: editLayer(' . $count . ');">' . html_print_image("images/config.png", true, array("alt" => "")) . '</a>
</td>
<td class="col4">
<input type="hidden" name="layer_values_' . $count . '" value=\'' . $layerDataJSON . '\' id="layer_values_' . $count . '" />
<a id="delete_row" href="javascript: deleteLayer(' . $count . ')">' . html_print_image("images/cross.png", true, array("alt" => "")) . '</a>
</td>
</tr>
</tbody>
<script type="text/javascript">
layerList.push(countLayer);
countLayer++;
updateArrowLayers();
</script>';
$count ++;
}
return $returnVar;
}
function gis_calculate_distance($lat_start, $lon_start, $lat_end, $lon_end) {
//Use 3958.9=miles, 6371.0=Km;
$earthRadius = 6371;

View File

@ -4658,3 +4658,20 @@ form ul.form_flex li ul li{
.dialog-grayed .ui-dialog-buttonpane {
background: #373737 !important;
}
a.down_arrow {
content: url("../../images/down.png");
max-width: 21px;
max-height: 21px;
}
a.up_arrow {
content: url("../../images/down.png");
transform: rotate(180deg);
max-width: 21px;
max-height: 21px;
}
tr:last-child > td > a.down_arrow, tr:first-child > td > a.up_arrow {
visibility: hidden;
}

View File

@ -384,6 +384,123 @@ switch ($opt) {
// Save table
$returnJSON['content'] = html_print_table($table, true);
echo json_encode($returnJSON);
break;
case 'point_group_info':
$agent_id = (int) get_parameter('id');
$group_id = (int) get_parameter('id_parent');
$group = db_get_row_sql('SELECT * FROM tgrupo WHERE id_grupo = ' . $group_id);
$agent = db_get_row_sql('SELECT * FROM tagente WHERE id_agente = ' . $agent_id);
$agentDataGIS = gis_get_data_last_position_agent($agent['id_agente']);
$returnJSON = array();
$returnJSON['correct'] = 1;
$returnJSON['content'] = '';
$content = '';
$table = new StdClass();
$table->class = 'blank';
$table->style = array();
$table->style[0] = 'font-weight: bold';
$table->rowstyle = array();
$table->data = array();
// Group name
$row = array();
$row[] = __('Group');
$row[] = '<a style="font-weight: bolder;" href="?sec=estado&sec2=operation/agentes/estado_agente&group_id=' . $group_id . '">' . $group['nombre'] . '</a>';
$table->data[] = $row;
// Position
$row = array();
$row[] = __('Position (Lat, Long, Alt)');
//it's positioned in default position of map.
if ($agentDataGIS === false) {
$row[] = __("Default position of map.");
}
else {
$row[] = '(' . $agentDataGIS['stored_latitude'] . ', ' . $agentDataGIS['stored_longitude'] . ', ' . $agentDataGIS['stored_altitude'] . ')';
}
$table->data[] = $row;
// Description
$group_description = $group['description'];
if ($group_description || $group_description != '') {
$row = array();
$row[] = __('Description');
$row[] = $group_description;
$table->data[] = $row;
}
// Last contact
$row = array();
$row[] = __('Last contact');
if ($agent["ultimo_contacto"] == "01-01-1970 00:00:00") {
$row[] = __('Never');
}
else {
$row[] = date_w_fixed_tz($agent["ultimo_contacto"]);
}
$table->data[] = $row;
// Last remote contact
$row = array();
$row[] = __('Remote');
if ($agent["ultimo_contacto_remoto"] == "01-01-1970 00:00:00") {
$row[] = __('Never');
}
else {
$row[] = date_w_fixed_tz($agent["ultimo_contacto_remoto"]);
}
$table->data[] = $row;
// Critical && not validated events
$filter = array(
"id_grupo" => $group_id,
"criticity" => EVENT_CRIT_CRITICAL,
"estado" => array(EVENT_STATUS_NEW, EVENT_STATUS_INPROCESS)
);
$result = events_get_events($filter, "COUNT(*) as num");
if (!empty($result)) {
$number = (int) $result[0]["num"];
if ($number > 0) {
$row = array();
$row[] = __("Number of non-validated critical events");
$row[] = '<a href="?sec=estado&sec2=operation/events/events&status=3&severity=' . EVENT_CRIT_CRITICAL
. '&id_group=' . $group_id . '">' . $number . '</a>';
$table->data[] = $row;
}
}
// Alerts fired
$alerts_fired = alerts_get_alerts($group_id, "", "fired", -1, $true);
if (!empty($alerts_fired)) {
$row = array();
$row[] = __("Alert(s) fired");
$alerts_detail = "";
foreach ($alerts_fired as $alert) {
$alerts_detail .= "<p>"
. $alert['agent_alias'] . " - "
. $alert['module_name'] . " - "
. $alert['template_name'] . " - "
. date($config["date_format"], $alert['last_fired'])
. "</p>";
}
$row[] = $alerts_detail;
$table->data[] = $row;
}
// To remove the grey background color of the classes datos and datos2
for ($i = 0; $i < count($table->data); $i++)
$table->rowstyle[] = 'background-color: inherit;';
// Save table
$returnJSON['content'] = html_print_table($table, true);
echo json_encode($returnJSON);
break;
case 'get_map_connection_data':

View File

@ -148,7 +148,13 @@ if ($layers != false) {
}
$agentNamesByLayer = gis_get_agents_layer($layer['id_tmap_layer']);
$agentNames = array_unique($agentNamesByGroup + $agentNamesByLayer);
$groupsByAgentId = gis_get_groups_layer_by_agent_id($layer['id_tmap_layer']);
$agentNamesOfGroupItems = array();
foreach ($groupsByAgentId as $agentId => $groupInfo) {
$agentNamesOfGroupItems[$agentId] = $groupInfo["agent_name"];
}
$agentNames = array_unique($agentNamesByGroup + $agentNamesByLayer + $agentNamesOfGroupItems);
foreach ($agentNames as $agentName) {
$idAgent = agents_get_agent_id($agentName);
@ -165,19 +171,33 @@ if ($layers != false) {
}
}
$icon = gis_get_agent_icon_map($idAgent, true);
$status = agents_get_status($idAgent);
$icon = gis_get_agent_icon_map($idAgent, true, $status);
$icon = ui_get_full_url($icon);
$icon_size = getimagesize($icon);
$icon_width = $icon_size[0];
$icon_height = $icon_size[1];
$icon = ui_get_full_url($icon);
$status = agents_get_status($idAgent);
$parent = db_get_value('id_parent', 'tagente', 'id_agente', $idAgent);
gis_add_agent_point($layer['layer_name'],
io_safe_output($agentName), $coords['stored_latitude'],
$coords['stored_longitude'], $icon, $icon_width,
$icon_height, $idAgent, $status, 'point_agent_info',
$parent);
// Is a group item
if (!empty($groupsByAgentId[$idAgent])) {
$groupId = (int) $groupsByAgentId[$idAgent]["id"];
$groupName = $groupsByAgentId[$idAgent]["name"];
gis_add_agent_point($layer['layer_name'],
io_safe_output($groupName), $coords['stored_latitude'],
$coords['stored_longitude'], $icon, $icon_width,
$icon_height, $idAgent, $status, 'point_group_info',
$groupId);
}
else {
$parent = db_get_value('id_parent', 'tagente', 'id_agente', $idAgent);
gis_add_agent_point($layer['layer_name'],
io_safe_output($agentName), $coords['stored_latitude'],
$coords['stored_longitude'], $icon, $icon_width,
$icon_height, $idAgent, $status, 'point_agent_info',
$parent);
}
}
}
gis_add_parent_lines();

View File

@ -184,7 +184,13 @@ if ($layers != false) {
}
$agentNamesByLayer = gis_get_agents_layer($layer['id_tmap_layer']);
$agentNames = array_unique($agentNamesByGroup + $agentNamesByLayer);
$groupsByAgentId = gis_get_groups_layer_by_agent_id($layer['id_tmap_layer']);
$agentNamesOfGroupItems = array();
foreach ($groupsByAgentId as $agentId => $groupInfo) {
$agentNamesOfGroupItems[$agentId] = $groupInfo["agent_name"];
}
$agentNames = array_unique($agentNamesByGroup + $agentNamesByLayer + $agentNamesOfGroupItems);
foreach ($agentNames as $key => $agentName) {
$idAgent = $key;
@ -200,19 +206,33 @@ if ($layers != false) {
gis_add_path($layer['layer_name'], $idAgent, $lastPosition);
}
}
$icon = gis_get_agent_icon_map($idAgent, true);
$status = agents_get_status($idAgent, true);
$icon = gis_get_agent_icon_map($idAgent, true, $status);
$icon_size = getimagesize($icon);
$icon_width = $icon_size[0];
$icon_height = $icon_size[1];
$status = agents_get_status($idAgent,true);
$parent = db_get_value('id_parent', 'tagente', 'id_agente', $idAgent);
gis_add_agent_point($layer['layer_name'],
io_safe_output($agentName), $coords['stored_latitude'],
$coords['stored_longitude'], $icon, $icon_width,
$icon_height, $idAgent, $status, 'point_agent_info',
$parent);
// Is a group item
if (!empty($groupsByAgentId[$idAgent])) {
$groupId = (int) $groupsByAgentId[$idAgent]["id"];
$groupName = $groupsByAgentId[$idAgent]["name"];
gis_add_agent_point($layer['layer_name'],
io_safe_output($groupName), $coords['stored_latitude'],
$coords['stored_longitude'], $icon, $icon_width,
$icon_height, $idAgent, $status, 'point_group_info',
$groupId);
}
else {
$parent = db_get_value('id_parent', 'tagente', 'id_agente', $idAgent);
gis_add_agent_point($layer['layer_name'],
io_safe_output($agentName), $coords['stored_latitude'],
$coords['stored_longitude'], $icon, $icon_width,
$icon_height, $idAgent, $status, 'point_agent_info',
$parent);
}
}
}
gis_add_parent_lines();

View File

@ -1669,6 +1669,25 @@ CREATE TABLE IF NOT EXISTS `tgis_map_layer_has_tagente` (
ENGINE = InnoDB
COMMENT = 'Table to define wich agents are shown in a layer';
-- -----------------------------------------------------
-- Table `tgis_map_layer_groups`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tgis_map_layer_groups` (
`layer_id` INT NOT NULL,
`group_id` MEDIUMINT(4) UNSIGNED NOT NULL,
`agent_id` INT(10) UNSIGNED NOT NULL COMMENT 'Used to link the position to the group',
PRIMARY KEY (`layer_id`, `group_id`),
FOREIGN KEY (`layer_id`)
REFERENCES `tgis_map_layer` (`id_tmap_layer`)
ON DELETE CASCADE,
FOREIGN KEY (`group_id`)
REFERENCES `tgrupo` (`id_grupo`)
ON DELETE CASCADE,
FOREIGN KEY (`agent_id`)
REFERENCES `tagente` (`id_agente`)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- Table `tgroup_stat`
-- ----------------------------------------------------------------------