Added the feature of the new map items (groups) and fixed more bugs
This commit is contained in:
parent
dd6b9aed81
commit
7da4557abc
|
@ -60,4 +60,17 @@ ALTER TABLE `tusuario_perfil` ADD COLUMN `no_hierarchy` tinyint(1) NOT NULL DEFA
|
|||
UPDATE `tusuario_perfil` SET `is_secondary` = `no_hierarchy`;
|
||||
ALTER TABLE `tusuario_perfil` DROP COLUMN `is_secondary`;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- 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;
|
|
@ -53,7 +53,8 @@ foreach ($layer_ids as $layer_id) {
|
|||
"layer_name" => $trimmed_name,
|
||||
"layer_visible" => ((int) $layers[$layer_id]["visible"] === 1),
|
||||
"layer_group" => (int) $layers[$layer_id]["agents_from_group"],
|
||||
"layer_agent_list" => $layers[$layer_id]["agents"]
|
||||
"layer_agent_list" => $layers[$layer_id]["agents"],
|
||||
"layer_group_list" => $layers[$layer_id]["groups"]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -469,8 +470,44 @@ $table->data[1][1] .= '</td>
|
|||
<table class="databox" border="0" cellpadding="4" cellspacing="4" id="list_agents">
|
||||
</table>
|
||||
</td>
|
||||
</tr>';
|
||||
|
||||
// Group items
|
||||
$group_select = html_print_select_groups($config["id_user"], "AR", false, "layer_group_id", "", "", "", 0, true);
|
||||
$params = array();
|
||||
$params['return'] = true;
|
||||
$params['show_helptip'] = true;
|
||||
$params['print_hidden_input_idagent'] = true;
|
||||
$params['hidden_input_idagent_id'] = 'hidden-agent_id_for_data';
|
||||
$params['hidden_input_idagent_name'] = 'agent_id_for_data';
|
||||
$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
|
||||
$agent_for_group_input = ui_print_agent_autocomplete_input($params);
|
||||
$add_group_btn = html_print_button(__('Add'), 'add_group', true, '', 'class="sub add"', true);
|
||||
|
||||
$table->data[1][1] .= '<tr><td colspan="4"><hr /></td></tr>
|
||||
<tr>
|
||||
<td>' . __('Group') . ':</td>
|
||||
<td colspan="3">' . $group_select . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>' . __('Use the data of this agent') . ':</td>
|
||||
<td colspan="3">' . $agent_for_group_input . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4" align="right">' . $add_group_btn . '</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<h4>' . __('List of groups to be shown in the layer') . '</h4>
|
||||
<table class="databox" border="0" cellpadding="4" cellspacing="4" id="list_groups">
|
||||
</table>
|
||||
</td>
|
||||
</tr>';
|
||||
|
||||
$table->data[1][1] .= '<tr>
|
||||
<td align="right" colspan="4">' .
|
||||
html_print_button(__('Save Layer'), 'save_layer', false, 'javascript:saveNewLayer();', 'class="sub wand"', true) . '
|
||||
' . html_print_input_hidden('current_edit_layer_id', '', true) . '
|
||||
|
@ -549,6 +586,54 @@ function addAgentClick (event) {
|
|||
$("#button-add_agent").prop("disabled", true);
|
||||
}
|
||||
|
||||
function toggleAddGroupBtn () {
|
||||
var groupId = Number.parseInt($("select#layer_group_id").val());
|
||||
var agentId = Number.parseInt($("input#hidden-agent_id_for_data").val());
|
||||
var agentAlias = $("input#text-agent_alias_for_data").val();
|
||||
|
||||
var enabled = (
|
||||
!Number.isNaN(groupId)
|
||||
&& groupId > 0
|
||||
&& !Number.isNaN(agentId)
|
||||
&& agentId > 0
|
||||
&& agentAlias.length > 0
|
||||
);
|
||||
|
||||
$("#button-add_group").prop("disabled", !enabled);
|
||||
}
|
||||
|
||||
function addGroupClick (event) {
|
||||
var $layerFormGroupIdInput = $("select#layer_group_id");
|
||||
var $layerFormAgentIdInput = $("input#hidden-agent_id_for_data");
|
||||
var $layerFormAgentAliasInput = $("input#text-agent_alias_for_data");
|
||||
|
||||
var layerId = Number.parseInt($("input#hidden-current_edit_layer_id").val());
|
||||
var groupId = Number.parseInt($layerFormGroupIdInput.val());
|
||||
var groupName = $layerFormGroupIdInput.find(":selected").text();
|
||||
var agentId = Number.parseInt($layerFormAgentIdInput.val());
|
||||
var agentAlias = $layerFormAgentAliasInput.val();
|
||||
|
||||
var valid = (
|
||||
!Number.isNaN(groupId)
|
||||
&& groupId > 0
|
||||
&& groupName.length > 0
|
||||
&& !Number.isNaN(agentId)
|
||||
&& agentId > 0
|
||||
&& agentAlias.length > 0
|
||||
);
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
addGroupRow(layerId, groupId, groupName, agentId, agentAlias);
|
||||
|
||||
// Clear inputs
|
||||
// $layerFormGroupIdInput.val(0);
|
||||
$layerFormAgentIdInput.val("");
|
||||
$layerFormAgentAliasInput.val("");
|
||||
|
||||
$("#button-add_group").prop("disabled", true);
|
||||
}
|
||||
|
||||
function moveLayerRowUpOnClick (event) {
|
||||
var $row = $(event.currentTarget).parent().parent();
|
||||
$row.insertBefore($row.prev());
|
||||
|
@ -602,13 +687,27 @@ function getLayerData (layerId) {
|
|||
"alias": $(this).val()
|
||||
};
|
||||
}).get();
|
||||
var layerGroups = $layerRow.find("input.layer_group_id").map(function () {
|
||||
var groupId = $(this).val();
|
||||
var groupName = $(this).siblings("input.layer_group_name[data-group-id='" + groupId + "']").val();
|
||||
var agentId = $(this).siblings("input.layer_agent_id_for_data[data-group-id='" + groupId + "']").val();
|
||||
var agentAlias = $(this).siblings("input.layer_agent_alias_for_data[data-group-id='" + groupId + "']").val();
|
||||
|
||||
return {
|
||||
"id": groupId,
|
||||
"name": groupName,
|
||||
"agentId": agentId,
|
||||
"agentAlias": agentAlias
|
||||
};
|
||||
}).get();
|
||||
|
||||
return {
|
||||
id: layerId,
|
||||
name: layerName,
|
||||
visible: layerVisible,
|
||||
agentsFromGroup: layerAgentsFromGroup,
|
||||
agents: layerAgents
|
||||
agents: layerAgents,
|
||||
groups: layerGroups
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -618,9 +717,10 @@ function setLayerEditorData (data) {
|
|||
data = {
|
||||
id: data.id || 0,
|
||||
name: data.name || "",
|
||||
visible: data.visible != null ? data.visible : true,
|
||||
visible: data.visible != null ? !!data.visible : true,
|
||||
agentsFromGroup: data.agentsFromGroup || -1,
|
||||
agents: data.agents || []
|
||||
agents: data.agents || [],
|
||||
groups: data.groups || []
|
||||
}
|
||||
|
||||
var $layerFormIdInput = $("input#hidden-current_edit_layer_id");
|
||||
|
@ -630,6 +730,7 @@ function setLayerEditorData (data) {
|
|||
var $layerFormAgentInput = $("input#text-agent_alias");
|
||||
var $layerFormAgentButton = $("input#button-add_agent");
|
||||
var $layerFormAgentsListItems = $("tr.agents_list_item");
|
||||
var $layerFormGroupsListItems = $("tr.groups_list_item");
|
||||
|
||||
$layerFormIdInput.val(data.id);
|
||||
$layerFormNameInput.val(data.name);
|
||||
|
@ -638,11 +739,17 @@ function setLayerEditorData (data) {
|
|||
$layerFormAgentInput.val("");
|
||||
$layerFormAgentButton.prop("disabled", true);
|
||||
$layerFormAgentsListItems.remove();
|
||||
$layerFormGroupsListItems.remove();
|
||||
|
||||
var $tableAgents = $("table#list_agents");
|
||||
data.agents.forEach(function (agent) {
|
||||
addAgentRow(data.id, agent.id, agent.alias);
|
||||
});
|
||||
|
||||
var $tableGroups = $("table#list_groups");
|
||||
data.groups.forEach(function (group) {
|
||||
addGroupRow(data.id, group.id, group.name, group.agentId, group.agentAlias);
|
||||
});
|
||||
}
|
||||
|
||||
function newLayer () {
|
||||
|
@ -654,7 +761,8 @@ function saveNewLayer () {
|
|||
var $layerFormVisibleCheckbox = $("input#checkbox-layer_visible_form");
|
||||
var $layerFormAgentsFromGroupSelect = $("select#layer_group_form");
|
||||
var $layerFormAgentsListItems = $("tr.agents_list_item > td > span.agent_alias");
|
||||
var newLayerId = "new_" . $("tr.layer_row").length + 1;
|
||||
var $layerFormGroupsListItems = $("tr.groups_list_item");
|
||||
var newLayerId = "new_" + ($("tr.layer_row").length + 1);
|
||||
|
||||
addLayerRow(newLayerId, {
|
||||
id: newLayerId,
|
||||
|
@ -666,6 +774,14 @@ function saveNewLayer () {
|
|||
"id": $(this).data("agent-id"),
|
||||
"alias": $(this).text()
|
||||
};
|
||||
}).get(),
|
||||
groups: $layerFormGroupsListItems.map(function () {
|
||||
return {
|
||||
"id": $(this).data("group-id"),
|
||||
"name": $(this).data("group-name"),
|
||||
"agentId": $(this).data("agent-id"),
|
||||
"agentAlias": $(this).data("agent-alias")
|
||||
};
|
||||
}).get()
|
||||
});
|
||||
}
|
||||
|
@ -681,7 +797,6 @@ function bindLayerEditorEvents (layerId) {
|
|||
var $layerFormNameInput = $("input#text-layer_name_form");
|
||||
var $layerFormVisibleCheckbox = $("input#checkbox-layer_visible_form");
|
||||
var $layerFormAgentsFromGroupSelect = $("select#layer_group_form");
|
||||
var $layerFormAgentButton = $("input#button-add_agent");
|
||||
|
||||
var $layerRow = $("tr#layer_row_" + layerId);
|
||||
|
||||
|
@ -700,27 +815,24 @@ function bindLayerEditorEvents (layerId) {
|
|||
var group = event.currentTarget.value;
|
||||
$layerRow.find("input.layer_agents_from_group").val(group);
|
||||
});
|
||||
$layerFormAgentButton.bind("click", addAgentClick);
|
||||
}
|
||||
|
||||
function unbindLayerEditorEvents () {
|
||||
var $layerFormNameInput = $("input#text-layer_name_form");
|
||||
var $layerFormVisibleCheckbox = $("input#checkbox-layer_visible_form");
|
||||
var $layerFormAgentsFromGroupSelect = $("select#layer_group_form");
|
||||
var $layerFormAgentButton = $("input#button-add_agent");
|
||||
|
||||
$layerFormNameInput.unbind("change");
|
||||
$layerFormVisibleCheckbox.unbind("click");
|
||||
$layerFormAgentsFromGroupSelect.unbind("change");
|
||||
$layerFormAgentButton.unbind("click");
|
||||
}
|
||||
|
||||
function getAgentRow (layerId, agentId, angentAlias) {
|
||||
function getAgentRow (layerId, agentId, agentAlias) {
|
||||
var $row = $("<tr class=\"agents_list_item\" />");
|
||||
var $nameCol = $("<td />");
|
||||
var $deleteCol = $("<td />");
|
||||
|
||||
var $agentName = $("<span class=\"agent_alias\" data-agent-id=\"" + agentId + "\">" + angentAlias + "</span>");
|
||||
var $agentAlias = $("<span class=\"agent_alias\" data-agent-id=\"" + agentId + "\">" + agentAlias + "</span>");
|
||||
var $removeBtn = $('<a class="delete_row" href="javascript:;"><?php echo html_print_image("images/cross.png", true) ?></a>');
|
||||
|
||||
$removeBtn.click(function (event) {
|
||||
|
@ -734,7 +846,7 @@ function getAgentRow (layerId, agentId, angentAlias) {
|
|||
$agentListItemRow.remove();
|
||||
});
|
||||
|
||||
$nameCol.append($agentName);
|
||||
$nameCol.append($agentAlias);
|
||||
$deleteCol.append($removeBtn);
|
||||
|
||||
$row.append($nameCol).append($deleteCol);
|
||||
|
@ -764,6 +876,80 @@ function getLayerAgentAliasInput (layerId, agentId, agentAlias) {
|
|||
return $("<input class=\"layer_agent_alias\" type=\"hidden\" data-agent-id=\"" + agentId + "\" name=\"layers[" + layerId + "][agents][" + agentId + "][alias]\" value=\"" + agentAlias + "\">");
|
||||
}
|
||||
|
||||
function getGroupRow (layerId, groupId, groupName, agentId, agentAlias) {
|
||||
var $row = $("<tr class=\"groups_list_item\" data-group-id=\"" + groupId + "\" data-group-name=\"" + groupName + "\" data-agent-id=\"" + agentId + "\" data-agent-alias=\"" + agentAlias + "\" />");
|
||||
var $nameCol = $("<td />");
|
||||
var $deleteCol = $("<td />");
|
||||
|
||||
var $groupName = $("<span class=\"group_desc\">"
|
||||
+ groupName
|
||||
+ " ("
|
||||
+ "<?php echo __('Using data from'); ?> "
|
||||
+ "<i>" + agentAlias + "</i>"
|
||||
+ ")"
|
||||
+ "</span>");
|
||||
var $removeBtn = $('<a class="delete_row" href="javascript:;"><?php echo html_print_image("images/cross.png", true) ?></a>');
|
||||
|
||||
$removeBtn.click(function (event) {
|
||||
var $layerRow = $("tr#layer_row_" + layerId);
|
||||
|
||||
if ($layerRow.length === 0) return;
|
||||
|
||||
var $groupListItemRow = $(event.currentTarget).parent().parent();
|
||||
$layerRow.find("input.layer_group_id[data-group-id='" + groupId + "']").remove();
|
||||
$layerRow.find("input.layer_group_name[data-group-id='" + groupId + "']").remove();
|
||||
$layerRow.find("input.layer_agent_id_for_data[data-group-id='" + groupId + "']").remove();
|
||||
$layerRow.find("input.layer_agent_alias_for_data[data-group-id='" + groupId + "']").remove();
|
||||
$groupListItemRow.remove();
|
||||
});
|
||||
|
||||
$nameCol.append($groupName);
|
||||
$deleteCol.append($removeBtn);
|
||||
|
||||
$row.append($nameCol).append($deleteCol);
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
function addGroupRow (layerId, groupId, groupName, agentId, agentAlias) {
|
||||
if (
|
||||
groupId == null ||
|
||||
groupId == 0 ||
|
||||
groupName.length === 0 ||
|
||||
agentId == null ||
|
||||
agentId == 0 ||
|
||||
agentAlias.length === 0
|
||||
) return;
|
||||
|
||||
var $layerRow = $("tr#layer_row_" + layerId);
|
||||
if ($layerRow && $layerRow.find("input.layer_group_id[value='" + groupId + "']").length === 0) {
|
||||
$layerRow
|
||||
.find("td:first-child")
|
||||
.append(getLayerGroupIdInput(layerId, groupId))
|
||||
.append(getLayerGroupNameInput(layerId, groupId, groupName))
|
||||
.append(getLayerAgentIdForDataInput(layerId, groupId, agentId))
|
||||
.append(getLayerAgentAliasForDataInput(layerId, groupId, agentAlias));
|
||||
}
|
||||
|
||||
$("table#list_groups").append(getGroupRow(layerId, groupId, groupName, agentId, agentAlias));
|
||||
}
|
||||
|
||||
function getLayerGroupIdInput (layerId, groupId) {
|
||||
return $("<input class=\"layer_group_id\" type=\"hidden\" data-group-id=\"" + groupId + "\" name=\"layers[" + layerId + "][groups][" + groupId + "][id]\" value=\"" + groupId + "\">");
|
||||
}
|
||||
|
||||
function getLayerGroupNameInput (layerId, groupId, groupName) {
|
||||
return $("<input class=\"layer_group_name\" type=\"hidden\" data-group-id=\"" + groupId + "\" name=\"layers[" + layerId + "][groups][" + groupId + "][name]\" value=\"" + groupName + "\">");
|
||||
}
|
||||
|
||||
function getLayerAgentIdForDataInput (layerId, groupId, agentId) {
|
||||
return $("<input class=\"layer_agent_id_for_data\" type=\"hidden\" data-group-id=\"" + groupId + "\" name=\"layers[" + layerId + "][groups][" + groupId + "][agent_id]\" value=\"" + agentId + "\">");
|
||||
}
|
||||
|
||||
function getLayerAgentAliasForDataInput (layerId, groupId, agentAlias) {
|
||||
return $("<input class=\"layer_agent_alias_for_data\" type=\"hidden\" data-group-id=\"" + groupId + "\" name=\"layers[" + layerId + "][groups][" + groupId + "][agent_alias]\" value=\"" + agentAlias + "\">");
|
||||
}
|
||||
|
||||
function getLayerRow (layerId, layerData) {
|
||||
var $row = $("<tr id=\"layer_row_" + layerId + "\" class=\"layer_row\" />");
|
||||
var $nameCol = $("<td />");
|
||||
|
@ -773,7 +959,7 @@ function getLayerRow (layerId, layerData) {
|
|||
|
||||
var $layerIdInput = $("<input class=\"layer_id\" type=\"hidden\" name=\"layer_ids[]\" value=\"" + layerId + "\">");
|
||||
var $layerNameInput = $("<input class=\"layer_name\" type=\"hidden\" name=\"layers[" + layerId + "][name]\" value=\"" + layerData.name + "\">");
|
||||
var $layerVisibleInput = $("<input class=\"layer_visible\" type=\"hidden\" name=\"layers[" + layerId + "][visible]\" value=\"" + layerData.visible + "\">");
|
||||
var $layerVisibleInput = $("<input class=\"layer_visible\" type=\"hidden\" name=\"layers[" + layerId + "][visible]\" value=\"" + (layerData.visible ? 1 : 0) + "\">");
|
||||
var $layerAgentsFromGroupInput = $("<input class=\"layer_agents_from_group\" type=\"hidden\" name=\"layers[" + layerId + "][agents_from_group]\" value=\"" + layerData.agentsFromGroup + "\">");
|
||||
|
||||
var $layerName = $("<span class=\"layer_name\">" + layerData.name + "</span>");
|
||||
|
@ -801,6 +987,15 @@ function getLayerRow (layerId, layerData) {
|
|||
});
|
||||
}
|
||||
|
||||
if (layerData.groups && layerData.groups.length > 0) {
|
||||
layerData.groups.forEach(function (group) {
|
||||
$nameCol.append(getLayerGroupIdInput(layerId, group.id));
|
||||
$nameCol.append(getLayerGroupNameInput(layerId, group.id, group.name));
|
||||
$nameCol.append(getLayerAgentIdForDataInput(layerId, group.id, group.agentId));
|
||||
$nameCol.append(getLayerAgentAliasForDataInput(layerId, group.id, group.agentAlias));
|
||||
});
|
||||
}
|
||||
|
||||
$sortCol
|
||||
.append($sortUpBtn)
|
||||
.append($sortDownBtn);
|
||||
|
@ -853,8 +1048,18 @@ function onFormSubmit (event) {
|
|||
$('#map_connection_list').val(connectionMaps.toString());
|
||||
}
|
||||
|
||||
function onLayerGroupIdChange (event) {
|
||||
// Clear agent inputs
|
||||
$("input#hidden-agent_id_for_data").val("");
|
||||
$("input#text-agent_alias_for_data").val("");
|
||||
toggleAddGroupBtn();
|
||||
}
|
||||
|
||||
// Bind events
|
||||
$("form#form_setup").submit(onFormSubmit);
|
||||
$("input#button-add_agent").click(addAgentClick);
|
||||
$("select#layer_group_id").change(onLayerGroupIdChange);
|
||||
$("input#button-add_group").click(addGroupClick);
|
||||
|
||||
// Populate layer list
|
||||
var layers = <?php echo json_encode($layer_list); ?>;
|
||||
|
@ -862,9 +1067,14 @@ layers.forEach(function (layer) {
|
|||
$("table#list_layers").append(
|
||||
getLayerRow(layer["id"], {
|
||||
name: layer["layer_name"],
|
||||
visible: layer["layer_visible"],
|
||||
visible: Number.parseInt(layer["layer_visible"]),
|
||||
agentsFromGroup: layer["layer_group"],
|
||||
agents: layer["layer_agent_list"]
|
||||
agents: layer["layer_agent_list"],
|
||||
groups: (layer["layer_group_list"] || []).map(function (group) {
|
||||
group.agentId = group["agent_id"];
|
||||
group.agentAlias = group["agent_alias"];
|
||||
return group;
|
||||
})
|
||||
})
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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 .= '
|
||||
|
|
|
@ -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,6 +862,7 @@ 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) {
|
||||
db_process_sql_insert('tgis_map_layer_has_tagente',
|
||||
|
@ -833,6 +873,18 @@ function gis_save_map($map_name, $map_initial_longitude, $map_initial_latitude,
|
|||
);
|
||||
}
|
||||
}
|
||||
// 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"]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $idMap;
|
||||
|
@ -880,6 +932,8 @@ 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;
|
||||
}
|
||||
|
@ -924,6 +978,18 @@ function gis_update_map($idMap, $map_name, $map_initial_longitude, $map_initial_
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -1252,11 +1318,11 @@ function gis_get_map_data($idMap) {
|
|||
if ($layers === false) $layers = array();
|
||||
|
||||
foreach ($layers as $index => $layer) {
|
||||
if (!isset($layer['id']))
|
||||
continue;
|
||||
if (!isset($layer['id'])) continue;
|
||||
|
||||
$id_tmap_layer = (int) $layer['id'];
|
||||
|
||||
// Agent list
|
||||
$sql = "SELECT id_agente AS id, alias
|
||||
FROM tagente
|
||||
WHERE id_agente IN (
|
||||
|
@ -1267,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;
|
||||
|
|
|
@ -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':
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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`
|
||||
-- ----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue