mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
Merge branch '2742-Cambiar_vista_manage_agent_group_tree' into 'develop'
add new tree view edition group See merge request artica/pandorafms!1773
This commit is contained in:
commit
3a15c5844d
@ -215,20 +215,57 @@ if (! check_acl($config['id_user'], 0, "PM")) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sec = defined('METACONSOLE') ? 'advanced' : 'gagente';
|
||||||
|
$url_tree = "index.php?sec=$sec&sec2=godmode/groups/group_list&tab=tree";
|
||||||
|
$url_groups = "index.php?sec=$sec&sec2=godmode/groups/group_list&tab=groups";
|
||||||
|
$buttons['tree'] = array(
|
||||||
|
'active' => false,
|
||||||
|
'text' => "<a href='$url_tree'>" .
|
||||||
|
html_print_image(
|
||||||
|
"images/gm_massive_operations.png",
|
||||||
|
true,
|
||||||
|
array (
|
||||||
|
"title" => __('Tree Group view')
|
||||||
|
)
|
||||||
|
) . "</a>"
|
||||||
|
);
|
||||||
|
|
||||||
|
$buttons['groups'] = array(
|
||||||
|
'active' => false,
|
||||||
|
'text' => "<a href='$url_groups'>" .
|
||||||
|
html_print_image(
|
||||||
|
"images/group.png",
|
||||||
|
true,
|
||||||
|
array(
|
||||||
|
"title" => __('Group view')
|
||||||
|
)
|
||||||
|
) . "</a>"
|
||||||
|
);
|
||||||
|
|
||||||
|
$tab = (string)get_parameter('tab', 'groups');
|
||||||
|
|
||||||
|
// Marks correct tab
|
||||||
|
switch ($tab) {
|
||||||
|
case 'tree':
|
||||||
|
$buttons['tree']['active'] = true;
|
||||||
|
break;
|
||||||
|
case 'groups':
|
||||||
|
default:
|
||||||
|
$buttons['groups']['active'] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
if (defined('METACONSOLE')) {
|
if (defined('METACONSOLE')) {
|
||||||
agents_meta_print_header();
|
agents_meta_print_header();
|
||||||
$sec = 'advanced';
|
|
||||||
echo '<div class="notify">';
|
echo '<div class="notify">';
|
||||||
echo __("Edit or delete groups can cause problems with synchronization");
|
echo __("Edit or delete groups can cause problems with synchronization");
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ui_print_page_header (
|
ui_print_page_header (
|
||||||
__("Groups defined in %s", get_product_name()),
|
__("Groups defined in %s", get_product_name()),
|
||||||
"images/group.png", false, "", true, ""
|
"images/group.png", false, "", true, $buttons
|
||||||
);
|
);
|
||||||
$sec = 'gagente';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$create_group = (bool) get_parameter ('create_group');
|
$create_group = (bool) get_parameter ('create_group');
|
||||||
@ -365,148 +402,158 @@ if (($delete_group) && (check_acl($config['id_user'], 0, "PM"))) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$acl='';
|
if($tab == 'tree'){
|
||||||
$search_name = '';
|
echo html_print_image('images/spinner.gif', true,
|
||||||
$offset = (int)get_parameter('offset', 0);
|
array('class' => "loading_tree",
|
||||||
$search = (string)get_parameter('search', '');
|
'style' => 'display: none;'));
|
||||||
$block_size = $config['block_size'];
|
echo "<div id='tree-controller-recipient'></div>";
|
||||||
|
|
||||||
if(!empty($search)){
|
|
||||||
$search_name = "AND t.nombre LIKE '%$search%'";
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
$acl='';
|
||||||
|
$search_name = '';
|
||||||
|
$offset = (int)get_parameter('offset', 0);
|
||||||
|
$search = (string)get_parameter('search', '');
|
||||||
|
$block_size = $config['block_size'];
|
||||||
|
|
||||||
if (!users_can_manage_group_all("AR")){
|
if(!empty($search)){
|
||||||
$user_groups_acl = users_get_groups(false, "AR");
|
$search_name = "AND t.nombre LIKE '%$search%'";
|
||||||
$groups_acl = implode(",", $user_groups_ACL);
|
}
|
||||||
if(empty($groups_acl)) return ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) );
|
|
||||||
|
|
||||||
$acl = "AND t.id_grupo IN ($groups_acl)";
|
if (!users_can_manage_group_all("AR")){
|
||||||
}
|
$user_groups_acl = users_get_groups(false, "AR");
|
||||||
|
$groups_acl = implode(",", $user_groups_ACL);
|
||||||
|
if(empty($groups_acl)) return ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) );
|
||||||
|
|
||||||
$form = "<form method='post' action=''>";
|
$acl = "AND t.id_grupo IN ($groups_acl)";
|
||||||
$form .= "<table class='databox filters' width='100%' style='font-weight: bold;'>";
|
}
|
||||||
$form .= "<tr><td>" . __('Search') . ' ';
|
|
||||||
$form .= html_print_input_text ("search", $search, '', 100, 100, true);
|
|
||||||
$form .= "</td><td>";
|
|
||||||
$form .= "<input name='find' type='submit' class='sub search' value='".__('Search')."'>";
|
|
||||||
$form .= "<td></tr>";
|
|
||||||
$form .= "</table>";
|
|
||||||
$form .= "</form>";
|
|
||||||
|
|
||||||
echo $form;
|
$form = "<form method='post' action=''>";
|
||||||
|
$form .= "<table class='databox filters' width='100%' style='font-weight: bold;'>";
|
||||||
|
$form .= "<tr><td>" . __('Search') . ' ';
|
||||||
|
$form .= html_print_input_text ("search", $search, '', 100, 100, true);
|
||||||
|
$form .= "</td><td>";
|
||||||
|
$form .= "<input name='find' type='submit' class='sub search' value='".__('Search')."'>";
|
||||||
|
$form .= "<td></tr>";
|
||||||
|
$form .= "</table>";
|
||||||
|
$form .= "</form>";
|
||||||
|
|
||||||
$groups_sql =
|
echo $form;
|
||||||
"SELECT t.*,
|
|
||||||
p.nombre AS parent_name,
|
|
||||||
IF(t.parent=p.id_grupo, 1, 0) AS has_child
|
|
||||||
FROM tgrupo t
|
|
||||||
LEFT JOIN tgrupo p
|
|
||||||
ON t.parent=p.id_grupo
|
|
||||||
WHERE 1=1
|
|
||||||
$acl
|
|
||||||
$search_name
|
|
||||||
ORDER BY nombre
|
|
||||||
LIMIT $offset, $block_size
|
|
||||||
";
|
|
||||||
|
|
||||||
$groups = db_get_all_rows_sql($groups_sql);
|
$groups_sql =
|
||||||
|
"SELECT t.*,
|
||||||
if (!empty($groups)) {
|
p.nombre AS parent_name,
|
||||||
//Count all groups for pagination only saw user and filters
|
IF(t.parent=p.id_grupo, 1, 0) AS has_child
|
||||||
$groups_sql_count = "SELECT count(*)
|
|
||||||
FROM tgrupo t
|
FROM tgrupo t
|
||||||
|
LEFT JOIN tgrupo p
|
||||||
|
ON t.parent=p.id_grupo
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
$acl
|
$acl
|
||||||
$search_name
|
$search_name
|
||||||
|
ORDER BY nombre
|
||||||
|
LIMIT $offset, $block_size
|
||||||
";
|
";
|
||||||
$groups_count = db_get_value_sql($groups_sql_count);
|
|
||||||
|
|
||||||
$table = new StdClass();
|
$groups = db_get_all_rows_sql($groups_sql);
|
||||||
$table->width = '100%';
|
|
||||||
$table->class = "databox data";
|
|
||||||
$table->head = array ();
|
|
||||||
$table->head[0] = __('ID');
|
|
||||||
$table->head[1] = __('Name');
|
|
||||||
$table->head[2] = __('Icon');
|
|
||||||
$table->head[3] = __('Alerts');
|
|
||||||
$table->head[4] = __('Parent');
|
|
||||||
$table->head[5] = __('Description');
|
|
||||||
$table->head[6] = __('Actions');
|
|
||||||
$table->align = array ();
|
|
||||||
$table->align[0] = 'right';
|
|
||||||
$table->align[2] = 'left';
|
|
||||||
$table->align[6] = 'left';
|
|
||||||
$table->size[5] = '30%';
|
|
||||||
$table->size[6] = '10%';
|
|
||||||
$table->data = array ();
|
|
||||||
|
|
||||||
foreach ($groups as $key => $group) {
|
if (!empty($groups)) {
|
||||||
$url = "index.php?sec=gagente&sec2=godmode/groups/configure_group&id_group=".$group['id_grupo'];
|
//Count all groups for pagination only saw user and filters
|
||||||
$url_delete = "index.php?sec=gagente&sec2=godmode/groups/group_list&delete_group=1&id_group=" . $group['id_grupo'];
|
$groups_sql_count = "SELECT count(*)
|
||||||
$table->data[$key][0] = $group['id_grupo'];
|
FROM tgrupo t
|
||||||
$table->data[$key][1] = "<a href='$url'>" . $group['nombre'] . "</a>";
|
WHERE 1=1
|
||||||
$table->data[$key][2] = html_print_image(
|
$acl
|
||||||
"images/groups_small/" . $group['icon'] . ".png",
|
$search_name
|
||||||
true,
|
";
|
||||||
array(
|
$groups_count = db_get_value_sql($groups_sql_count);
|
||||||
"style" => '',
|
|
||||||
"class" => "bot",
|
|
||||||
"alt" => $group['nombre'],
|
|
||||||
"title" => $group['nombre'],
|
|
||||||
false, false, false, true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
//reporting_get_group_stats
|
$table = new StdClass();
|
||||||
$table->data[$key][3] = $group['disabled'] ? __('Disabled') : __('Enabled');
|
$table->width = '100%';
|
||||||
$table->data[$key][4] = $group['parent_name'];
|
$table->class = "databox data";
|
||||||
$table->data[$key][5] = $group['description'];
|
$table->head = array ();
|
||||||
$table->data[$key][6] = "<a href='$url'>" .
|
$table->head[0] = __('ID');
|
||||||
html_print_image(
|
$table->head[1] = __('Name');
|
||||||
"images/config.png",
|
$table->head[2] = __('Icon');
|
||||||
|
$table->head[3] = __('Alerts');
|
||||||
|
$table->head[4] = __('Parent');
|
||||||
|
$table->head[5] = __('Description');
|
||||||
|
$table->head[6] = __('Actions');
|
||||||
|
$table->align = array ();
|
||||||
|
$table->align[0] = 'left';
|
||||||
|
$table->align[2] = 'left';
|
||||||
|
$table->align[6] = 'left';
|
||||||
|
$table->size[0] = '3%';
|
||||||
|
$table->size[5] = '30%';
|
||||||
|
$table->size[6] = '5%';
|
||||||
|
$table->data = array ();
|
||||||
|
|
||||||
|
foreach ($groups as $key => $group) {
|
||||||
|
$url = "index.php?sec=gagente&sec2=godmode/groups/configure_group&id_group=".$group['id_grupo'];
|
||||||
|
$url_delete = "index.php?sec=gagente&sec2=godmode/groups/group_list&delete_group=1&id_group=" . $group['id_grupo'];
|
||||||
|
$table->data[$key][0] = $group['id_grupo'];
|
||||||
|
$table->data[$key][1] = "<a href='$url'>" . $group['nombre'] . "</a>";
|
||||||
|
$table->data[$key][2] = html_print_image(
|
||||||
|
"images/groups_small/" . $group['icon'] . ".png",
|
||||||
true,
|
true,
|
||||||
array(
|
array(
|
||||||
"alt" => __('Edit'),
|
"style" => '',
|
||||||
"title" => __('Edit'),
|
"class" => "bot",
|
||||||
"border" => '0'
|
"alt" => $group['nombre'],
|
||||||
|
"title" => $group['nombre'],
|
||||||
|
false, false, false, true
|
||||||
)
|
)
|
||||||
) .
|
);
|
||||||
"</a>";
|
|
||||||
|
//reporting_get_group_stats
|
||||||
|
$table->data[$key][3] = $group['disabled'] ? __('Disabled') : __('Enabled');
|
||||||
|
$table->data[$key][4] = $group['parent_name'];
|
||||||
|
$table->data[$key][5] = $group['description'];
|
||||||
|
$table->data[$key][6] = "<a href='$url'>" .
|
||||||
|
html_print_image(
|
||||||
|
"images/config.png",
|
||||||
|
true,
|
||||||
|
array(
|
||||||
|
"alt" => __('Edit'),
|
||||||
|
"title" => __('Edit'),
|
||||||
|
"border" => '0'
|
||||||
|
)
|
||||||
|
) .
|
||||||
|
"</a>";
|
||||||
|
|
||||||
|
$confirm_message = __('Are you sure?');
|
||||||
|
if ($group['has_child']) {
|
||||||
|
$confirm_message = __('The child groups will be updated to use the parent id of the deleted group') . ". " . $confirm_message;
|
||||||
|
}
|
||||||
|
|
||||||
|
$table->data[$key][6] .= ' ' .
|
||||||
|
'<a href="'. $url_delete. '" onClick="if (!confirm(\' '.$confirm_message.'\')) return false;">' .
|
||||||
|
html_print_image(
|
||||||
|
"images/cross.png",
|
||||||
|
true,
|
||||||
|
array(
|
||||||
|
"alt" => __('Delete'),
|
||||||
|
"title" => __('Delete'),
|
||||||
|
"border" => '0'
|
||||||
|
)
|
||||||
|
) .
|
||||||
|
"</a>";
|
||||||
|
|
||||||
$confirm_message = __('Are you sure?');
|
|
||||||
if ($group['has_child']) {
|
|
||||||
$confirm_message = __('The child groups will be updated to use the parent id of the deleted group') . ". " . $confirm_message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->data[$key][6] .= ' ' .
|
echo ui_pagination(
|
||||||
'<a href="'. $url_delete. '" onClick="if (!confirm(\' '.$confirm_message.'\')) return false;">' .
|
$groups_count, false,
|
||||||
html_print_image(
|
$offset, $block_size,
|
||||||
"images/cross.png",
|
true, 'offset', false
|
||||||
true,
|
);
|
||||||
array(
|
html_print_table ($table);
|
||||||
"alt" => __('Delete'),
|
echo ui_pagination(
|
||||||
"title" => __('Delete'),
|
$groups_count, false,
|
||||||
"border" => '0'
|
$offset, $block_size,
|
||||||
)
|
true, 'offset', true
|
||||||
) .
|
);
|
||||||
"</a>";
|
}
|
||||||
|
else {
|
||||||
|
ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
echo ui_pagination(
|
|
||||||
$groups_count, false,
|
|
||||||
$offset, $block_size,
|
|
||||||
true, 'offset', false
|
|
||||||
);
|
|
||||||
html_print_table ($table);
|
|
||||||
echo ui_pagination(
|
|
||||||
$groups_count, false,
|
|
||||||
$offset, $block_size,
|
|
||||||
true, 'offset', true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ui_print_info_message ( array('no_close'=>true, 'message'=> __('There are no defined groups') ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_acl($config['id_user'], 0, "PM")) {
|
if (check_acl($config['id_user'], 0, "PM")) {
|
||||||
@ -517,5 +564,101 @@ if (check_acl($config['id_user'], 0, "PM")) {
|
|||||||
echo '</form>';
|
echo '</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui_require_javascript_file("TreeController", "include/javascript/tree/");
|
||||||
|
|
||||||
enterprise_hook('close_meta_frame');
|
enterprise_hook('close_meta_frame');
|
||||||
|
$tab = "group_edition";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<?php if (!is_metaconsole()){ ?>
|
||||||
|
<script type="text/javascript" src="include/javascript/fixed-bottom-box.js"></script>
|
||||||
|
<?php }else{ ?>
|
||||||
|
<script type="text/javascript" src="../../include/javascript/fixed-bottom-box.js"></script>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var treeController = TreeController.getController();
|
||||||
|
|
||||||
|
if (typeof treeController.recipient != 'undefined' && treeController.recipient.length > 0)
|
||||||
|
treeController.recipient.empty();
|
||||||
|
|
||||||
|
$(".loading_tree").show();
|
||||||
|
|
||||||
|
var parameters = {};
|
||||||
|
parameters['page'] = "include/ajax/tree.ajax";
|
||||||
|
parameters['getChildren'] = 1;
|
||||||
|
parameters['type'] = "<?php echo $tab; ?>";
|
||||||
|
parameters['filter'] = {};
|
||||||
|
parameters['filter']['searchGroup'] = '';
|
||||||
|
parameters['filter']['searchAgent'] = '';
|
||||||
|
parameters['filter']['statusAgent'] = '';
|
||||||
|
parameters['filter']['searchModule'] = '';
|
||||||
|
parameters['filter']['statusModule'] = '';
|
||||||
|
parameters['filter']['groupID'] = '';
|
||||||
|
parameters['filter']['tagID'] = '';
|
||||||
|
parameters['filter']['searchHirearchy'] = 1;
|
||||||
|
parameters['filter']['show_not_init_agents'] = 1;
|
||||||
|
parameters['filter']['show_not_init_modules'] = 1;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||||
|
data: parameters,
|
||||||
|
success: function(data) {
|
||||||
|
if (data.success) {
|
||||||
|
$(".loading_tree").hide();
|
||||||
|
|
||||||
|
treeController.init({
|
||||||
|
recipient: $("div#tree-controller-recipient"),
|
||||||
|
//detailRecipient: $.fixedBottomBox({ width: 400, height: window.innerHeight * 0.9 }),
|
||||||
|
page: parameters['page'],
|
||||||
|
emptyMessage: "<?php echo __('No data found'); ?>",
|
||||||
|
foundMessage: "<?php echo __('Found groups'); ?>",
|
||||||
|
tree: data.tree,
|
||||||
|
baseURL: "<?php echo ui_get_full_url(false, false, false, is_metaconsole()); ?>",
|
||||||
|
ajaxURL: "<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
|
||||||
|
filter: parameters['filter'],
|
||||||
|
counterTitles: {
|
||||||
|
total: {
|
||||||
|
agents: "<?php echo __('Total agents'); ?>",
|
||||||
|
modules: "<?php echo __('Total modules'); ?>",
|
||||||
|
none: "<?php echo __('Total'); ?>"
|
||||||
|
},
|
||||||
|
alerts: {
|
||||||
|
agents: "<?php echo __('Fired alerts'); ?>",
|
||||||
|
modules: "<?php echo __('Fired alerts'); ?>",
|
||||||
|
none: "<?php echo __('Fired alerts'); ?>"
|
||||||
|
},
|
||||||
|
critical: {
|
||||||
|
agents: "<?php echo __('Critical agents'); ?>",
|
||||||
|
modules: "<?php echo __('Critical modules'); ?>",
|
||||||
|
none: "<?php echo __('Critical'); ?>"
|
||||||
|
},
|
||||||
|
warning: {
|
||||||
|
agents: "<?php echo __('Warning agents'); ?>",
|
||||||
|
modules: "<?php echo __('Warning modules'); ?>",
|
||||||
|
none: "<?php echo __('Warning'); ?>"
|
||||||
|
},
|
||||||
|
unknown: {
|
||||||
|
agents: "<?php echo __('Unknown agents'); ?>",
|
||||||
|
modules: "<?php echo __('Unknown modules'); ?>",
|
||||||
|
none: "<?php echo __('Unknown'); ?>"
|
||||||
|
},
|
||||||
|
not_init: {
|
||||||
|
agents: "<?php echo __('Not init agents'); ?>",
|
||||||
|
modules: "<?php echo __('Not init modules'); ?>",
|
||||||
|
none: "<?php echo __('Not init'); ?>"
|
||||||
|
},
|
||||||
|
ok: {
|
||||||
|
agents: "<?php echo __('Normal agents'); ?>",
|
||||||
|
modules: "<?php echo __('Normal modules'); ?>",
|
||||||
|
none: "<?php echo __('Normal'); ?>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dataType: "json"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@ -43,6 +43,7 @@ if (is_ajax ()) {
|
|||||||
require_once($config['homedir'] . "/include/class/TreeModule.class.php");
|
require_once($config['homedir'] . "/include/class/TreeModule.class.php");
|
||||||
require_once($config['homedir'] . "/include/class/TreeTag.class.php");
|
require_once($config['homedir'] . "/include/class/TreeTag.class.php");
|
||||||
require_once($config['homedir'] . "/include/class/TreeGroup.class.php");
|
require_once($config['homedir'] . "/include/class/TreeGroup.class.php");
|
||||||
|
require_once($config['homedir'] . "/include/class/TreeGroupEdition.class.php");
|
||||||
enterprise_include_once("include/class/TreePolicies.class.php");
|
enterprise_include_once("include/class/TreePolicies.class.php");
|
||||||
enterprise_include_once("include/class/TreeGroupMeta.class.php");
|
enterprise_include_once("include/class/TreeGroupMeta.class.php");
|
||||||
require_once($config['homedir'] . "/include/functions_reporting.php");
|
require_once($config['homedir'] . "/include/functions_reporting.php");
|
||||||
@ -104,6 +105,9 @@ if (is_ajax ()) {
|
|||||||
if (!class_exists('TreePolicies')) break;
|
if (!class_exists('TreePolicies')) break;
|
||||||
$tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
$tree = new TreePolicies($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
break;
|
break;
|
||||||
|
case 'group_edition':
|
||||||
|
$tree = new TreeGroupEdition($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// FIXME. No error handler
|
// FIXME. No error handler
|
||||||
return;
|
return;
|
||||||
|
108
pandora_console/include/class/TreeGroupEdition.class.php
Normal file
108
pandora_console/include/class/TreeGroupEdition.class.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
//Pandora FMS- http://pandorafms.com
|
||||||
|
// ==================================================
|
||||||
|
// Copyright (c) 2005-2018 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 Lesser General Public License
|
||||||
|
// as published by the Free Software Foundation; 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.
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
require_once($config['homedir']."/include/class/Tree.class.php");
|
||||||
|
|
||||||
|
class TreeGroupEdition extends TreeGroup {
|
||||||
|
public function __construct($type, $rootType = '', $id = -1, $rootID = -1, $serverID = false, $childrenMethod = "on_demand", $access = 'AR') {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
parent::__construct($type, $rootType, $id, $rootID, $serverID, $childrenMethod, $access);
|
||||||
|
}
|
||||||
|
protected function getData() {
|
||||||
|
if ($this->id == -1) {
|
||||||
|
$this->getFirstLevel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getProcessedGroups () {
|
||||||
|
$processed_groups = array();
|
||||||
|
// Index and process the groups
|
||||||
|
$groups = $this->getGroupCounters();
|
||||||
|
|
||||||
|
// If user have not permissions in parent, set parent node to 0 (all)
|
||||||
|
// Avoid to do foreach for admins
|
||||||
|
if (!users_can_manage_group_all("AR")) {
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (!isset($this->userGroups[$groups[$id]['parent']])) {
|
||||||
|
$groups[$id]['parent'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Build the group hierarchy
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (isset($groups[$id]['parent']) && ($groups[$id]['parent'] != 0)) {
|
||||||
|
$parent = $groups[$id]['parent'];
|
||||||
|
// Parent exists
|
||||||
|
if (!isset($groups[$parent]['children'])) {
|
||||||
|
$groups[$parent]['children'] = array();
|
||||||
|
}
|
||||||
|
// Store a reference to the group into the parent
|
||||||
|
$groups[$parent]['children'][] = &$groups[$id];
|
||||||
|
// This group was introduced into a parent
|
||||||
|
$groups[$id]['have_parent'] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the children groups
|
||||||
|
foreach ($groups as $id => $group) {
|
||||||
|
if (isset($groups[$id]['children'])) {
|
||||||
|
usort($groups[$id]['children'], array("Tree", "cmpSortNames"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Filter groups and eliminates the reference to children groups out of her parent
|
||||||
|
$groups = array_filter($groups, function ($group) {
|
||||||
|
return !$group['have_parent'];
|
||||||
|
});
|
||||||
|
|
||||||
|
usort($groups, array("Tree", "cmpSortNames"));
|
||||||
|
return $groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function getGroupCounters() {
|
||||||
|
$messages = array(
|
||||||
|
'confirm' => __('Confirm'),
|
||||||
|
'cancel' => __('Cancel'),
|
||||||
|
'messg' => __('Are you sure?')
|
||||||
|
);
|
||||||
|
$sql = "SELECT id_grupo AS gid,
|
||||||
|
nombre as name, parent, icon
|
||||||
|
FROM tgrupo
|
||||||
|
";
|
||||||
|
|
||||||
|
$stats = db_get_all_rows_sql($sql);
|
||||||
|
$group_stats = array();
|
||||||
|
foreach ($stats as $group) {
|
||||||
|
$group_stats[$group['gid']]['name'] = $group['name'];
|
||||||
|
$group_stats[$group['gid']]['parent'] = $group['parent'];
|
||||||
|
$group_stats[$group['gid']]['icon'] = $group['icon'];
|
||||||
|
$group_stats[$group['gid']]['id'] = $group['gid'];
|
||||||
|
$group_stats[$group['gid']]['type'] = 'group';
|
||||||
|
|
||||||
|
$group_stats[$group['gid']] = $this->getProcessedItem($group_stats[$group['gid']]);
|
||||||
|
$group_stats[$group['gid']]['delete']['messages'] = $messages;
|
||||||
|
$group_stats[$group['gid']]['edit'] = 1;
|
||||||
|
$group_stats[$group['gid']]['alerts'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $group_stats;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -1585,6 +1585,10 @@ function display_confirm_dialog (message, ok_text, cancel_text, ok_function) {
|
|||||||
clean_function();
|
clean_function();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var buttons_obj = {};
|
||||||
|
buttons_obj[cancel_text] = clean_function;
|
||||||
|
buttons_obj[ok_text] = ok_function_clean;
|
||||||
|
|
||||||
// Display the dialog
|
// Display the dialog
|
||||||
$("body").append('<div id="pandora_confirm_dialog_text"><h3>' + message + '</h3></div>');
|
$("body").append('<div id="pandora_confirm_dialog_text"><h3>' + message + '</h3></div>');
|
||||||
$("#pandora_confirm_dialog_text").dialog({
|
$("#pandora_confirm_dialog_text").dialog({
|
||||||
@ -1598,10 +1602,7 @@ function display_confirm_dialog (message, ok_text, cancel_text, ok_function) {
|
|||||||
},
|
},
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
modal: true,
|
modal: true,
|
||||||
buttons: {
|
buttons: buttons_obj
|
||||||
Cancel: clean_function,
|
|
||||||
"Confirm": ok_function_clean
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +279,6 @@ var TreeController = {
|
|||||||
|
|
||||||
// Load leaf
|
// Load leaf
|
||||||
function _processNode (container, element) {
|
function _processNode (container, element) {
|
||||||
|
|
||||||
// type, [id], [serverID], callback
|
// type, [id], [serverID], callback
|
||||||
function _getTreeDetailData (type, id, serverID, callback) {
|
function _getTreeDetailData (type, id, serverID, callback) {
|
||||||
var lastParam = arguments[arguments.length - 1];
|
var lastParam = arguments[arguments.length - 1];
|
||||||
@ -346,6 +345,36 @@ var TreeController = {
|
|||||||
$content.append(element.iconHTML + " ");
|
$content.append(element.iconHTML + " ");
|
||||||
}
|
}
|
||||||
$content.append(element.name);
|
$content.append(element.name);
|
||||||
|
|
||||||
|
if(typeof element.edit != 'undefined'){
|
||||||
|
var url_edit = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/configure_group&tab=tree&id_group=" + element.id;
|
||||||
|
var $updateicon = $('<img src="' + (controller.baseURL.length > 0 ? controller.baseURL : '')+ 'images/config.png" style="width:18px; vertical-align: middle;"/>')
|
||||||
|
var $updatebtn = $('<a href = "' + url_edit + '"></a>')
|
||||||
|
.append($updateicon);
|
||||||
|
$content.append($updatebtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof element.delete != 'undefined'){
|
||||||
|
var url_delete = controller.baseURL + "index.php?sec=gagente&sec2=godmode/groups/group_list&tab=tree&delete_group=1&id_group=" + element.id;
|
||||||
|
var $deleteBtn = $('<a><img src="' + (controller.baseURL.length > 0 ? controller.baseURL : '') +'images/cross.png" style="width:18px; vertical-align: middle; cursor: pointer;"/></a>');
|
||||||
|
$deleteBtn.click(function (event){
|
||||||
|
var ok_function = function(){
|
||||||
|
window.location.replace(url_delete);
|
||||||
|
};
|
||||||
|
display_confirm_dialog(
|
||||||
|
element.delete.messages.messg,
|
||||||
|
element.delete.messages.confirm,
|
||||||
|
element.delete.messages.cancel,
|
||||||
|
ok_function
|
||||||
|
)
|
||||||
|
});
|
||||||
|
$content.append($deleteBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof element.alerts != 'undefined'){
|
||||||
|
$content.append(element.alerts);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'agent':
|
case 'agent':
|
||||||
// Is quiet
|
// Is quiet
|
||||||
@ -583,95 +612,99 @@ var TreeController = {
|
|||||||
if (typeof(public_user) === 'undefined') public_user = 0;
|
if (typeof(public_user) === 'undefined') public_user = 0;
|
||||||
|
|
||||||
if (typeof element.searchChildren != 'undefined' && element.searchChildren) {
|
if (typeof element.searchChildren != 'undefined' && element.searchChildren) {
|
||||||
$node
|
if(element.rootType == "group_edition"
|
||||||
.removeClass("leaf-empty")
|
&& typeof element.children == 'undefined'){
|
||||||
.addClass("leaf-closed");
|
$node.addClass("leaf-empty");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$node
|
||||||
|
.removeClass("leaf-empty")
|
||||||
|
.addClass("leaf-closed");
|
||||||
|
$leafIcon.click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
$leafIcon.click(function (e) {
|
if (!$node.hasClass("leaf-loading") && !$node.hasClass("children-loaded") && !$node.hasClass("leaf-empty")) {
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
if (!$node.hasClass("leaf-loading") && !$node.hasClass("children-loaded") && !$node.hasClass("leaf-empty")) {
|
|
||||||
$node
|
|
||||||
.removeClass("leaf-closed")
|
|
||||||
.removeClass("leaf-error")
|
|
||||||
.addClass("leaf-loading");
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: controller.ajaxURL,
|
|
||||||
type: 'POST',
|
|
||||||
dataType: 'json',
|
|
||||||
data: {
|
|
||||||
page: controller.ajaxPage,
|
|
||||||
getChildren: 1,
|
|
||||||
id: element.id,
|
|
||||||
type: element.type,
|
|
||||||
rootID: element.rootID,
|
|
||||||
serverID: element.serverID,
|
|
||||||
rootType: element.rootType,
|
|
||||||
filter: controller.filter,
|
|
||||||
hash: public_hash,
|
|
||||||
id_user: public_user
|
|
||||||
},
|
|
||||||
complete: function(xhr, textStatus) {
|
|
||||||
$node.removeClass("leaf-loading");
|
|
||||||
$node.addClass("children-loaded");
|
|
||||||
},
|
|
||||||
success: function(data, textStatus, xhr) {
|
|
||||||
if (data.success) {
|
|
||||||
var $group = $node.children("ul.tree-group");
|
|
||||||
|
|
||||||
if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) {
|
|
||||||
$node.addClass("leaf-open");
|
|
||||||
|
|
||||||
if ($group.length <= 0) {
|
|
||||||
$group = $("<ul></ul>");
|
|
||||||
$group
|
|
||||||
.addClass("tree-group")
|
|
||||||
.hide();
|
|
||||||
$node.append($group);
|
|
||||||
}
|
|
||||||
|
|
||||||
_.each(data.tree, function(element) {
|
|
||||||
element.jqObject = _processNode($group, element);
|
|
||||||
});
|
|
||||||
|
|
||||||
$group.slideDown();
|
|
||||||
|
|
||||||
$node.data('children', $group);
|
|
||||||
|
|
||||||
// Add again the hover event to the 'force_callback' elements
|
|
||||||
forced_title_callback();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$node.addClass("leaf-empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$node.addClass("leaf-error");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function(xhr, textStatus, errorThrown) {
|
|
||||||
$node.addClass("leaf-error");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (! $node.hasClass("leaf-empty")) {
|
|
||||||
if ($node.hasClass("leaf-open")) {
|
|
||||||
$node
|
|
||||||
.removeClass("leaf-open")
|
|
||||||
.addClass("leaf-closed")
|
|
||||||
.data('children')
|
|
||||||
.slideUp();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$node
|
$node
|
||||||
.removeClass("leaf-closed")
|
.removeClass("leaf-closed")
|
||||||
.addClass("leaf-open")
|
.removeClass("leaf-error")
|
||||||
.data('children')
|
.addClass("leaf-loading");
|
||||||
.slideDown();
|
|
||||||
|
$.ajax({
|
||||||
|
url: controller.ajaxURL,
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
page: controller.ajaxPage,
|
||||||
|
getChildren: 1,
|
||||||
|
id: element.id,
|
||||||
|
type: element.type,
|
||||||
|
rootID: element.rootID,
|
||||||
|
serverID: element.serverID,
|
||||||
|
rootType: element.rootType,
|
||||||
|
filter: controller.filter,
|
||||||
|
hash: public_hash,
|
||||||
|
id_user: public_user
|
||||||
|
},
|
||||||
|
complete: function(xhr, textStatus) {
|
||||||
|
$node.removeClass("leaf-loading");
|
||||||
|
$node.addClass("children-loaded");
|
||||||
|
},
|
||||||
|
success: function(data, textStatus, xhr) {
|
||||||
|
if (data.success) {
|
||||||
|
var $group = $node.children("ul.tree-group");
|
||||||
|
if ((typeof data.tree != 'undefined' && data.tree.length > 0) || $group.length > 0) {
|
||||||
|
$node.addClass("leaf-open");
|
||||||
|
|
||||||
|
if ($group.length <= 0) {
|
||||||
|
$group = $("<ul></ul>");
|
||||||
|
$group
|
||||||
|
.addClass("tree-group")
|
||||||
|
.hide();
|
||||||
|
$node.append($group);
|
||||||
|
}
|
||||||
|
|
||||||
|
_.each(data.tree, function(element) {
|
||||||
|
element.jqObject = _processNode($group, element);
|
||||||
|
});
|
||||||
|
|
||||||
|
$group.slideDown();
|
||||||
|
|
||||||
|
$node.data('children', $group);
|
||||||
|
|
||||||
|
// Add again the hover event to the 'force_callback' elements
|
||||||
|
forced_title_callback();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$node.addClass("leaf-empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$node.addClass("leaf-error");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(xhr, textStatus, errorThrown) {
|
||||||
|
$node.addClass("leaf-error");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
else if (! $node.hasClass("leaf-empty")) {
|
||||||
});
|
if ($node.hasClass("leaf-open")) {
|
||||||
|
$node
|
||||||
|
.removeClass("leaf-open")
|
||||||
|
.addClass("leaf-closed")
|
||||||
|
.data('children')
|
||||||
|
.slideUp();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$node
|
||||||
|
.removeClass("leaf-closed")
|
||||||
|
.addClass("leaf-open")
|
||||||
|
.data('children')
|
||||||
|
.slideDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user