array_keys(users_get_groups()),
'order' => 'parent, name',
]
)
);
$ordered_folders = [];
foreach ($folders as $folder) {
$ordered_folders[$folder['id_container']] = $folder;
}
return $ordered_folders;
}
function folder_get_folders_tree_recursive($folders)
{
$return = [];
$tree = $folders;
foreach ($folders as $key => $folder) {
if ($folder['id_container'] == 0) {
continue;
}
if (!in_array($folder['parent'], array_keys($folders))) {
$folder['parent'] = 0;
}
$tree[$folder['parent']]['hash_branch'] = 1;
$tree[$folder['parent']]['branch'][$key] = &$tree[$key];
}
if (isset($folders[0])) {
$tree = [$tree[0]];
} else {
$tree = $tree[0]['branch'];
}
return $tree;
}
function folder_flatten_tree_folders($tree, $deep)
{
foreach ($tree as $key => $folder) {
$return[$key] = $folder;
unset($return[$key]['branch']);
$return[$key]['deep'] = $deep;
if (!empty($folder['branch'])) {
$return = ($return + folder_flatten_tree_folders($folder['branch'], ($deep + 1)));
}
}
return $return;
}
function folder_get_select($folders_tree)
{
$fields = [];
foreach ($folders_tree as $folder_tree) {
$folderName = ui_print_truncate_text($folder_tree['name'], GENERIC_SIZE_TEXT, false, true, false);
$fields[$folder_tree['id_container']] = str_repeat(' ', $folder_tree['deep']).$folderName;
}
return $fields;
}
function folder_togge_tree_folders($tree)
{
$return = [];
foreach ($tree as $key => $folder) {
$folderName = ui_print_truncate_text($folder['name'], GENERIC_SIZE_TEXT, false, true, false);
$table = '';
if (!empty($folder['branch'])) {
$togge = $table.folder_togge_tree_folders($folder['branch']);
if ($folder['parent'] === '0') {
$return[$key] .= "
".ui_toggle_container($togge, $folderName, '', true, true, $folder['id_group'], $folder['id_container'], $folder['parent']).'
';
} else {
$return[$key] .= "".ui_toggle_container($togge, $folderName, '', true, true, $folder['id_group'], $folder['id_container'], $folder['parent']).'
';
}
} else {
if ($folder['parent'] === '0') {
$return[$key] = "";
} else {
$return[$key] = "
";
}
$return[$key] .= ui_toggle_container($table, $folderName, '', true, true, $folder['id_group'], $folder['id_container'], $folder['parent']);
$return[$key] .= '
';
}
}
$retorno = implode('', $return);
return $retorno;
}
function folder_table($graphs)
{
global $config;
$report_r = check_acl($config['id_user'], 0, 'RR');
$report_w = check_acl($config['id_user'], 0, 'RW');
$report_m = check_acl($config['id_user'], 0, 'RM');
$access = ($report_r == true) ? 'RR' : (($report_w == true) ? 'RW' : (($report_m == true) ? 'RM' : 'RR'));
$table = new stdClass();
$table->width = '100%';
$table->class = 'databox data';
$table->align = [];
$table->head = [];
$table->head[0] = __('Graph name');
$table->head[1] = __('Description');
$table->head[2] = __('Number of Graphs');
$table->head[3] = __('Group');
$table->size[0] = '30%';
$table->size[2] = '200px';
$table->size[3] = '200px';
$table->align[2] = 'left';
$table->align[3] = 'left';
if ($report_w || $report_m) {
$table->align[4] = 'left';
$table->head[4] = __('Op.').html_print_checkbox(
'all_delete',
0,
false,
true,
false,
'check_all_checkboxes();'
);
$table->size[4] = '90px';
}
$table->data = [];
// $result_graphs = array_slice($graphs, $offset, $config['block_size']);
foreach ($graphs as $graph) {
$data = [];
$data[0] = '
'.ui_print_truncate_text($graph['name'], 70).'';
$data[1] = ui_print_truncate_text($graph['description'], 70);
$data[2] = $graph['graphs_count'];
$data[3] = ui_print_group_icon($graph['id_group'], true);
if (($report_w || $report_m) && users_can_manage_group_all($access)) {
$data[4] = '
'.html_print_image(
'images/config.png',
true,
['class' => 'invert_filter']
).'';
$data[4] .= ' ';
$data[4] .= '
'.html_print_image('images/cross.png', true, ['alt' => __('Delete'), 'title' => __('Delete'), 'class' => 'invert_filter']).''.html_print_checkbox_extended('delete_multiple[]', $graph['id_graph'], false, false, '', 'class="check_delete mrgn_lft_2px"', true);
}
array_push($table->data, $data);
}
return $table;
}
function folder_get_all_child_container($parent)
{
$child_folders = db_get_all_rows_filter(
'tcontainer',
['parent' => $parent]
);
return $child_folders;
}
/**
* Get parent id
*/
function folder_get_parent_id($child)
{
$child_folders = db_get_all_rows_filter(
'tcontainer',
['id_container' => $child]
);
return $child_folders[0]['parent'];
}
/**
* Get all si
*/
function folder_get_sibling($sibling)
{
$parent_folders = db_get_all_rows_filter(
'tcontainer',
['id_container' => $sibling]
);
$sibling_folders = db_get_all_rows_filter(
'tcontainer',
['parent' => $parent_folders[0]['parent']]
);
return $sibling_folders;
}
function ui_toggle_container($code, $name, $title='', $hidden_default=true, $return=false, $group, $id_container, $parent=false)
{
global $config;
$report_r = check_acl($config['id_user'], 0, 'RR');
$report_w = check_acl($config['id_user'], 0, 'RW');
$report_m = check_acl($config['id_user'], 0, 'RM');
$access = ($report_r == true) ? 'RR' : (($report_w == true) ? 'RW' : (($report_m == true) ? 'RM' : 'RR'));
// Generate unique Id
$uniqid = uniqid('');
// Options
if ($hidden_default) {
$style = 'display:none';
$image_a = html_print_image('images/down.png', true, ['class' => 'invert_filter'], true);
$image_b = html_print_image('images/go.png', true, ['class' => 'invert_filter'], true);
$original = 'images/go.png';
} else {
$style = '';
$image_a = html_print_image('images/down.png', true, ['class' => 'invert_filter'], true);
$image_b = html_print_image('images/go.png', true, ['class' => 'invert_filter'], true);
$original = 'images/down.png';
}
// Link to toggle
$table = new stdClass();
$table->id = 'container_table';
$table->width = '100%';
$table->cellspacing = 4;
$table->cellpadding = 4;
$table->class = 'dat';
if (!$parent) {
$table->class = 'default_container ';
} else {
$table->class = 'default_container_parent';
}
$table->style[0] = 'width: 30%';
$table->style[1] = 'width: 30%';
if (!$parent) {
$table->style[0] = 'width: 30%';
$table->style[1] = 'width: 30%';
if ($id_container === '1') {
$table->style[2] = 'padding-right: 34px';
}
$table->align[1] = 'center';
$table->align[2] = 'center';
} else {
$id = folder_get_parent_id($id_container);
$i = 0;
while ($id !== '0') {
$id = folder_get_parent_id($id);
$i++;
}
$padding_group = (28 * $i);
$padding_icon = (10 * $i);
$table->style[0] = 'width: 30%';
$table->style[1] = 'width: 30%;padding-right: '.$padding_group.'px';
$table->style[2] = 'padding-right: '.$padding_icon.'px';
$table->align[1] = 'center';
$table->align[2] = 'center';
}
$table->data = [];
$data = [];
$data[0] = '
'.html_print_image($original, true, ['title' => $title, 'id' => 'image_'.$uniqid, 'class' => 'invert_filter']).' '.$name.'';
$data[1] = ui_print_group_icon($group, true);
if ($report_r && $report_w) {
$data[2] = '
'.html_print_image('images/config.png', true, ['class' => 'invert_filter']).'';
}
if ($report_r && $report_w && $report_m) {
if ($id_container !== '1') {
$data[2] .= '  '.'
'.html_print_image('images/cross.png', true, ['alt' => __('Delete'), 'title' => __('Delete'), 'class' => 'invert_filter']).'';
}
}
$table->data[] = $data;
$table->rowclass[] = '';
$output .= html_print_table($table, true);
// Code into a div
$output .= "
\n";
$output .= html_print_input_hidden($uniqid, $id_container);
$output .= $code;
$output .= '
';
// JQuery Toggle
$output .= '';
if (!$return) {
echo $output;
} else {
return $output;
}
}