1 |
6daefa8c
|
Petr Lukašík
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Manage groups in a database cluster
|
5 |
|
|
*
|
6 |
|
|
* $Id: groups.php,v 1.21 2005/10/18 03:45:16 chriskl Exp $
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
// Include application functions
|
10 |
|
|
include_once('./libraries/lib.inc.php');
|
11 |
|
|
|
12 |
|
|
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
|
13 |
|
|
if (!isset($msg)) $msg = '';
|
14 |
|
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
* Add user to a group
|
18 |
|
|
*/
|
19 |
|
|
function doAddMember() {
|
20 |
|
|
global $data, $misc;
|
21 |
|
|
global $PHP_SELF, $lang;
|
22 |
|
|
|
23 |
|
|
$status = $data->addGroupMember($_REQUEST['group'], $_REQUEST['user']);
|
24 |
|
|
if ($status == 0)
|
25 |
|
|
doProperties($lang['strmemberadded']);
|
26 |
|
|
else
|
27 |
|
|
doProperties($lang['strmemberaddedbad']);
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* Show confirmation of drop user from group and perform actual drop
|
32 |
|
|
*/
|
33 |
|
|
function doDropMember($confirm) {
|
34 |
|
|
global $data, $misc;
|
35 |
|
|
global $PHP_SELF, $lang;
|
36 |
|
|
|
37 |
|
|
if ($confirm) {
|
38 |
|
|
$misc->printTrail('group');
|
39 |
|
|
$misc->printTitle($lang['strdropmember'],'pg.group.alter');
|
40 |
|
|
|
41 |
|
|
echo "<p>", sprintf($lang['strconfdropmember'], $misc->printVal($_REQUEST['user']), $misc->printVal($_REQUEST['group'])), "</p>\n";
|
42 |
|
|
|
43 |
|
|
echo "<form action=\"{$PHP_SELF}\" method=\"post\">\n";
|
44 |
|
|
echo $misc->form;
|
45 |
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop_member\" />\n";
|
46 |
|
|
echo "<input type=\"hidden\" name=\"group\" value=\"", htmlspecialchars($_REQUEST['group']), "\" />\n";
|
47 |
|
|
echo "<input type=\"hidden\" name=\"user\" value=\"", htmlspecialchars($_REQUEST['user']), "\" />\n";
|
48 |
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
|
49 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
50 |
|
|
echo "</form>\n";
|
51 |
|
|
}
|
52 |
|
|
else {
|
53 |
|
|
$status = $data->dropGroupMember($_REQUEST['group'], $_REQUEST['user']);
|
54 |
|
|
if ($status == 0)
|
55 |
|
|
doProperties($lang['strmemberdropped']);
|
56 |
|
|
else
|
57 |
|
|
doDropMember(true, $lang['strmemberdroppedbad']);
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Show read only properties for a group
|
63 |
|
|
*/
|
64 |
|
|
function doProperties($msg = '') {
|
65 |
|
|
global $data, $misc;
|
66 |
|
|
global $PHP_SELF, $lang;
|
67 |
|
|
|
68 |
|
|
if (!isset($_POST['user'])) $_POST['user'] = '';
|
69 |
|
|
|
70 |
|
|
$misc->printTrail('group');
|
71 |
|
|
$misc->printTitle($lang['strproperties'],'pg.group');
|
72 |
|
|
$misc->printMsg($msg);
|
73 |
|
|
|
74 |
|
|
$groupdata = $data->getGroup($_REQUEST['group']);
|
75 |
|
|
$users = $data->getUsers();
|
76 |
|
|
|
77 |
|
|
if ($groupdata->recordCount() > 0) {
|
78 |
|
|
echo "<table>\n";
|
79 |
|
|
echo "<tr><th class=\"data\">{$lang['strmembers']}</th><th class=\"data\">{$lang['stractions']}</th></tr>\n";
|
80 |
|
|
$i = 0;
|
81 |
|
|
while (!$groupdata->EOF) {
|
82 |
|
|
$id = (($i % 2) == 0 ? '1' : '2');
|
83 |
|
|
echo "<tr><td class=\"data{$id}\">", $misc->printVal($groupdata->f['usename']), "</td>\n";
|
84 |
|
|
echo "<td class=\"opbutton{$id}\"><a href=\"$PHP_SELF?action=confirm_drop_member&{$misc->href}&group=",
|
85 |
|
|
urlencode($_REQUEST['group']), "&user=", urlencode($groupdata->f['usename']), "\">{$lang['strdrop']}</a></td>\n";
|
86 |
|
|
echo "</tr>\n";
|
87 |
|
|
$groupdata->moveNext();
|
88 |
|
|
}
|
89 |
|
|
echo "</table>\n";
|
90 |
|
|
}
|
91 |
|
|
else echo "<p>{$lang['strnousers']}</p>\n";
|
92 |
|
|
|
93 |
|
|
// Display form for adding a user to the group
|
94 |
|
|
echo "<form action=\"{$PHP_SELF}\" method=\"post\">\n";
|
95 |
|
|
echo "<select name=\"user\">";
|
96 |
|
|
while (!$users->EOF) {
|
97 |
|
|
$uname = $misc->printVal($users->f['usename']);
|
98 |
|
|
echo "<option value=\"{$uname}\"",
|
99 |
|
|
($uname == $_POST['user']) ? ' selected="selected"' : '', ">{$uname}</option>\n";
|
100 |
|
|
$users->moveNext();
|
101 |
|
|
}
|
102 |
|
|
echo "</select>\n";
|
103 |
|
|
echo "<input type=\"submit\" value=\"{$lang['straddmember']}\" />\n";
|
104 |
|
|
echo $misc->form;
|
105 |
|
|
echo "<input type=\"hidden\" name=\"group\" value=\"", htmlspecialchars($_REQUEST['group']), "\" />\n";
|
106 |
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"add_member\" />\n";
|
107 |
|
|
echo "</form>\n";
|
108 |
|
|
|
109 |
|
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?{$misc->href}\">{$lang['strshowallgroups']}</a></p>\n";
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* Show confirmation of drop and perform actual drop
|
114 |
|
|
*/
|
115 |
|
|
function doDrop($confirm) {
|
116 |
|
|
global $data, $misc;
|
117 |
|
|
global $PHP_SELF, $lang;
|
118 |
|
|
|
119 |
|
|
if ($confirm) {
|
120 |
|
|
$misc->printTrail('group');
|
121 |
|
|
$misc->printTitle($lang['strdrop'],'pg.group.drop');
|
122 |
|
|
|
123 |
|
|
echo "<p>", sprintf($lang['strconfdropgroup'], $misc->printVal($_REQUEST['group'])), "</p>\n";
|
124 |
|
|
|
125 |
|
|
echo "<form action=\"{$PHP_SELF}\" method=\"post\">\n";
|
126 |
|
|
echo $misc->form;
|
127 |
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
|
128 |
|
|
echo "<input type=\"hidden\" name=\"group\" value=\"", htmlspecialchars($_REQUEST['group']), "\" />\n";
|
129 |
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
|
130 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
131 |
|
|
echo "</form>\n";
|
132 |
|
|
}
|
133 |
|
|
else {
|
134 |
|
|
$status = $data->dropGroup($_REQUEST['group']);
|
135 |
|
|
if ($status == 0)
|
136 |
|
|
doDefault($lang['strgroupdropped']);
|
137 |
|
|
else
|
138 |
|
|
doDefault($lang['strgroupdroppedbad']);
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
/**
|
143 |
|
|
* Displays a screen where they can enter a new group
|
144 |
|
|
*/
|
145 |
|
|
function doCreate($msg = '') {
|
146 |
|
|
global $data, $misc;
|
147 |
|
|
global $PHP_SELF, $lang;
|
148 |
|
|
|
149 |
|
|
if (!isset($_POST['name'])) $_POST['name'] = '';
|
150 |
|
|
if (!isset($_POST['members'])) $_POST['members'] = array();
|
151 |
|
|
|
152 |
|
|
// Fetch a list of all users in the cluster
|
153 |
|
|
$users = $data->getUsers();
|
154 |
|
|
|
155 |
|
|
$misc->printTrail('server');
|
156 |
|
|
$misc->printTitle($lang['strcreategroup'],'pg.group.create');
|
157 |
|
|
$misc->printMsg($msg);
|
158 |
|
|
|
159 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
160 |
|
|
echo $misc->form;
|
161 |
|
|
echo "<table>\n";
|
162 |
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
|
163 |
|
|
echo "\t\t<td class=\"data\"><input size=\"32\" maxlength=\"{$data->_maxNameLen}\" name=\"name\" value=\"", htmlspecialchars($_POST['name']), "\" /></td>\n\t</tr>\n";
|
164 |
|
|
if ($users->recordCount() > 0) {
|
165 |
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strmembers']}</th>\n";
|
166 |
|
|
|
167 |
|
|
echo "\t\t<td class=\"data\">\n";
|
168 |
|
|
echo "\t\t\t<select name=\"members[]\" multiple=\"multiple\" size=\"", min(40, $users->recordCount()), "\">\n";
|
169 |
|
|
while (!$users->EOF) {
|
170 |
|
|
$username = $users->f['usename'];
|
171 |
|
|
echo "\t\t\t\t<option value=\"{$username}\"",
|
172 |
|
|
(in_array($username, $_POST['members']) ? ' selected="selected"' : ''), ">", $misc->printVal($username), "</option>\n";
|
173 |
|
|
$users->moveNext();
|
174 |
|
|
}
|
175 |
|
|
echo "\t\t\t</select>\n";
|
176 |
|
|
echo "\t\t</td>\n\t</tr>\n";
|
177 |
|
|
}
|
178 |
|
|
echo "</table>\n";
|
179 |
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
|
180 |
|
|
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
|
181 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
182 |
|
|
echo "</form>\n";
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
/**
|
186 |
|
|
* Actually creates the new group in the database
|
187 |
|
|
*/
|
188 |
|
|
function doSaveCreate() {
|
189 |
|
|
global $data;
|
190 |
|
|
global $lang;
|
191 |
|
|
|
192 |
|
|
if (!isset($_POST['members'])) $_POST['members'] = array();
|
193 |
|
|
|
194 |
|
|
// Check form vars
|
195 |
|
|
if (trim($_POST['name']) == '')
|
196 |
|
|
doCreate($lang['strgroupneedsname']);
|
197 |
|
|
else {
|
198 |
|
|
$status = $data->createGroup($_POST['name'], $_POST['members']);
|
199 |
|
|
if ($status == 0)
|
200 |
|
|
doDefault($lang['strgroupcreated']);
|
201 |
|
|
else
|
202 |
|
|
doCreate($lang['strgroupcreatedbad']);
|
203 |
|
|
}
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
/**
|
207 |
|
|
* Show default list of groups in the database
|
208 |
|
|
*/
|
209 |
|
|
function doDefault($msg = '') {
|
210 |
|
|
global $data, $misc;
|
211 |
|
|
global $PHP_SELF, $lang;
|
212 |
|
|
|
213 |
|
|
$misc->printTrail('server');
|
214 |
|
|
$misc->printTabs('server','groups');
|
215 |
|
|
$misc->printMsg($msg);
|
216 |
|
|
|
217 |
|
|
$groups = $data->getGroups();
|
218 |
|
|
|
219 |
|
|
$columns = array(
|
220 |
|
|
'group' => array(
|
221 |
|
|
'title' => $lang['strgroup'],
|
222 |
|
|
'field' => 'groname',
|
223 |
|
|
),
|
224 |
|
|
'actions' => array(
|
225 |
|
|
'title' => $lang['stractions'],
|
226 |
|
|
),
|
227 |
|
|
);
|
228 |
|
|
|
229 |
|
|
$actions = array(
|
230 |
|
|
'properties' => array(
|
231 |
|
|
'title' => $lang['strproperties'],
|
232 |
|
|
'url' => "{$PHP_SELF}?action=properties&{$misc->href}&",
|
233 |
|
|
'vars' => array('group' => 'groname'),
|
234 |
|
|
),
|
235 |
|
|
'drop' => array(
|
236 |
|
|
'title' => $lang['strdrop'],
|
237 |
|
|
'url' => "{$PHP_SELF}?action=confirm_drop&{$misc->href}&",
|
238 |
|
|
'vars' => array('group' => 'groname'),
|
239 |
|
|
),
|
240 |
|
|
);
|
241 |
|
|
|
242 |
|
|
$misc->printTable($groups, $columns, $actions, $lang['strnogroups']);
|
243 |
|
|
|
244 |
|
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=create&{$misc->href}\">{$lang['strcreategroup']}</a></p>\n";
|
245 |
|
|
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
$misc->printHeader($lang['strgroups']);
|
249 |
|
|
$misc->printBody();
|
250 |
|
|
|
251 |
|
|
switch ($action) {
|
252 |
|
|
case 'add_member':
|
253 |
|
|
doAddMember();
|
254 |
|
|
break;
|
255 |
|
|
case 'drop_member':
|
256 |
|
|
if (isset($_REQUEST['drop'])) doDropMember(false);
|
257 |
|
|
else doProperties();
|
258 |
|
|
break;
|
259 |
|
|
case 'confirm_drop_member':
|
260 |
|
|
doDropMember(true);
|
261 |
|
|
break;
|
262 |
|
|
case 'save_create':
|
263 |
|
|
if (isset($_REQUEST['cancel'])) doDefault();
|
264 |
|
|
else doSaveCreate();
|
265 |
|
|
break;
|
266 |
|
|
case 'create':
|
267 |
|
|
doCreate();
|
268 |
|
|
break;
|
269 |
|
|
case 'drop':
|
270 |
|
|
if (isset($_REQUEST['drop'])) doDrop(false);
|
271 |
|
|
else doDefault();
|
272 |
|
|
break;
|
273 |
|
|
case 'confirm_drop':
|
274 |
|
|
doDrop(true);
|
275 |
|
|
break;
|
276 |
|
|
case 'save_edit':
|
277 |
|
|
doSaveEdit();
|
278 |
|
|
break;
|
279 |
|
|
case 'edit':
|
280 |
|
|
doEdit();
|
281 |
|
|
break;
|
282 |
|
|
case 'properties':
|
283 |
|
|
doProperties();
|
284 |
|
|
break;
|
285 |
|
|
default:
|
286 |
|
|
doDefault();
|
287 |
|
|
break;
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
$misc->printFooter();
|
291 |
|
|
|
292 |
|
|
?>
|