Repository navigation
Expand file tree
/
Copy pathlayouts.php
More file actions
149 lines (124 loc) · 5.46 KB
/
Copy pathlayouts.php
File metadata and controls
149 lines (124 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| 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. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
require('./include/auth.php');
// Saved-layout create/rename/delete/publish requests (posted here or to any
// other filter page) are handled by filter_layouts_handle_request(), which is
// invoked from include/auth.php before this point. Only the management view
// remains here.
set_default_action();
switch (get_nfilter_request_var('action')) {
default:
top_header();
layouts_manage();
bottom_footer();
break;
}
/**
* Render the filter-layout management page. Administrators holding the
* Settings/Utilities realm manage every user's layouts and may publish them
* globally; other users manage only their own saved layouts.
*
* @return void
*/
function layouts_manage() : void {
$is_admin = filter_layouts_can_manage_global();
$user_id = isset($_SESSION['sess_user_id']) ? (int) $_SESSION['sess_user_id'] : 0;
if ($is_admin) {
$layouts = db_fetch_assoc('SELECT ul.id, ul.user_id, ul.page, ul.name, ul.data, ua.username
FROM user_layouts AS ul
LEFT JOIN user_auth AS ua
ON ua.id = ul.user_id
ORDER BY ul.page, (ul.user_id = 0), ul.name');
} else {
$layouts = db_fetch_assoc_prepared('SELECT ul.id, ul.user_id, ul.page, ul.name, ul.data, ua.username
FROM user_layouts AS ul
LEFT JOIN user_auth AS ua
ON ua.id = ul.user_id
WHERE ul.user_id = ?
ORDER BY ul.page, ul.name', [$user_id]);
}
html_start_box(__('Filter Layouts'), '100%', true, 3, 'center', '');
$display_text = [
'name' => ['display' => __('Name')],
'page' => ['display' => __('Page')],
'owner' => ['display' => __('Owner')],
'url' => ['display' => __('Filter')],
'nosort' => ['display' => __('Actions'), 'align' => 'right'],
];
html_header($display_text, 1);
if (cacti_sizeof($layouts)) {
foreach ($layouts as $layout) {
if ($layout['user_id'] == 0) {
$owner = '<em>' . __('Global') . '</em>';
} elseif (!empty($layout['username'])) {
$owner = html_escape($layout['username']);
} else {
$owner = __('User %d', $layout['user_id']);
}
form_alternate_row('line' . $layout['id'], true);
$document = filter_layouts_decode($layout['data']);
$summary = $document !== false ? filter_layouts_document_url($document) : '';
form_selectable_cell(filter_value($layout['name'], ''), $layout['id']);
form_selectable_cell(html_escape($layout['page']), $layout['id']);
form_selectable_cell($owner, $layout['id']);
form_selectable_cell(html_escape($summary), $layout['id']);
$actions = "<a class='pic layoutAction' href='#' data-action='layout_delete' data-id='" . $layout['id'] . "' title='" . __esc('Delete') . "'><i class='fa fa-times deviceDown'></i></a>";
if ($is_admin) {
if ($layout['user_id'] == 0) {
$actions = "<span title='" . __esc('Published to all users') . "'><i class='fa fa-globe'></i></span> " . $actions;
} else {
$actions = "<a class='pic layoutAction' href='#' data-action='layout_publish' data-id='" . $layout['id'] . "' title='" . __esc('Publish to all users') . "'><i class='fa fa-upload'></i></a> " . $actions;
}
}
form_selectable_cell($actions, $layout['id'], '', 'right');
form_end_row();
}
} else {
print "<tr class='tableRow'><td colspan='5'><em>" . __('No Filter Layouts Found') . '</em></td></tr>';
}
html_end_box(false);
?>
<script type='text/javascript'>
$(function() {
$('.layoutAction').click(function(event) {
event.preventDefault();
var action = $(this).attr('data-action');
var id = $(this).attr('data-id');
if (action == 'layout_delete' && !confirm(<?php print json_encode(__('Delete the selected layout?')); ?>)) {
return;
}
$.post('layouts.php', { action: action, id: id, __csrf_magic: csrfMagicToken }, function(result) {
if (result && result.ok) {
document.location.reload();
} else {
alert(<?php print json_encode(__('The layout operation failed.')); ?>);
}
}, 'json').fail(function() {
alert(<?php print json_encode(__('The layout operation failed.')); ?>);
});
});
});
</script>
<?php
}