PluginProbe
User Access Manager / 1.0.1
User Access Manager v1.0.1
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / tpl / adminGroup.php

adminGroup.php in User Access Manager 1.0.1, at tpl/adminGroup.php

447 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * adminGroup.php
4 *
5 * Shows the group management page at the admin panel.
6 *
7 * PHP versions 5
8 *
9 * @category UserAccessManager
10 * @package UserAccessManager
11 * @author Alexander Schneider <alexanderschneider85@googlemail.com>
12 * @copyright 2008-2010 Alexander Schneider
13 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
14 * @version SVN: $Id$
15 * @link http://wordpress.org/extend/plugins/user-access-manager/
16 */
17
18 /**
19 * Inserts or update a user group.
20 *
21 * @param integer $userGroupId The id of the user group.
22 *
23 * @return null
24 */
25 function insertUpdateGroup($userGroupId)
26 {
27 global $userAccessManager;
28
29 if ($userGroupId != null) {
30 $uamUserGroup
31 = &$userAccessManager->getAccessHandler()->getUserGroups($userGroupId);
32 } else {
33 $uamUserGroup
34 = new UamUserGroup($userAccessManager->getAccessHandler(), null);
35 }
36
37 $uamUserGroup->setGroupName($_POST['userGroupName']);
38 $uamUserGroup->setGroupDesc($_POST['userGroupDescription']);
39 $uamUserGroup->setReadAccess($_POST['readAccess']);
40 $uamUserGroup->setWriteAccess($_POST['writeAccess']);
41 $uamUserGroup->setIpRange($_POST['ipRange']);
42
43 if (isset($_POST['roles'])) {
44 $roles = $_POST['roles'];
45 } else {
46 $roles = null;
47 }
48
49 $uamUserGroup->unsetRoles(true);
50
51 if ($roles) {
52 foreach ($roles as $role) {
53 $uamUserGroup->addRole($role);
54 }
55 }
56
57 $uamUserGroup->save();
58
59 $userAccessManager->getAccessHandler()->addUserGroup($uamUserGroup);
60 }
61
62 /**
63 * Prints the group formular.
64 *
65 * @param integer $groupId The given group id.
66 *
67 * @return null
68 */
69 function getPrintEditGroup($groupId = null)
70 {
71 global $userAccessManager;
72 $uamUserGroup = &$userAccessManager->getAccessHandler()->getUserGroups($groupId);
73 ?>
74 <form method="post" action="<?php
75 echo reset(
76 explode("?", $_SERVER["REQUEST_URI"])
77 ) . "?page=" . $_GET['page'];
78 ?>">
79 <?php
80 if (isset($groupId)) {
81 ?>
82 <input type="hidden" value="updateGroup" name="action" />
83 <input type="hidden" value="<?php echo $groupId; ?>" name="userGroupId" />
84 <?php
85 } else {
86 ?>
87 <input type="hidden" value="addGroup" name="action" />
88 <?php
89 }
90 ?>
91 <table class="form-table">
92 <tbody>
93 <tr class="form-field form-required">
94 <th valign="top" scope="row"><?php echo TXT_GROUP_NAME; ?></th>
95 <td>
96 <input type="text" size="40" value="<?php
97 if (isset($groupId)) {
98 echo $uamUserGroup->getGroupName();
99 }
100 ?>" id="userGroupName" name="userGroupName" /><br />
101 <?php echo TXT_GROUP_NAME_DESC; ?>
102 </td>
103 </tr>
104 <tr class="form-field form-required">
105 <th valign="top" scope="row"><?php echo TXT_GROUP_DESC; ?></th>
106 <td>
107 <input type="text" size="40" value="<?php
108 if (isset($groupId)) {
109 echo $uamUserGroup->getGroupDesc();
110 }
111 ?>" id="userGroupDescription" name="userGroupDescription" /><br />
112 <?php echo TXT_GROUP_DESC_DESC; ?>
113 </td>
114 </tr>
115 <tr class="form-field form-required">
116 <th valign="top" scope="row"><?php echo TXT_GROUP_IP_RANGE; ?></th>
117 <td><input type="text" size="40" value="<?php
118 if (isset($groupId)) {
119 echo $uamUserGroup->getIpRange('string');
120 }
121 ?>" id="ipRange" name="ipRange" /><br />
122 <?php echo TXT_GROUP_IP_RANGE_DESC; ?>
123 </td>
124 </tr>
125 <tr class="form-field form-required">
126 <th valign="top" scope="row"><?php echo TXT_GROUP_READ_ACCESS; ?></th>
127 <td>
128 <select name="readAccess">
129 <option value="group"
130 <?php
131 if (isset($groupId)) {
132 if ($uamUserGroup->getReadAccess() == "group") {
133 echo 'selected="selected"';
134 }
135 }
136 ?>
137 >
138 <?php echo TXT_ONLY_GROUP_USERS ?>
139 </option>
140 <option value="all"
141 <?php
142 if (isset($groupId)) {
143 if ($uamUserGroup->getReadAccess() == "all") {
144 echo 'selected="selected"';
145 }
146 }
147 ?>
148 >
149 <?php echo TXT_ALL ?>
150 </option>
151 </select><br />
152 <?php echo TXT_GROUP_READ_ACCESS_DESC; ?>
153 </td>
154 </tr>
155 <tr class="form-field form-required">
156 <th valign="top" scope="row"><?php echo TXT_GROUP_WRITE_ACCESS; ?></th>
157 <td>
158 <select name="writeAccess">
159 <option value="group"
160 <?php
161 if (isset($groupId)) {
162 if ($uamUserGroup->getWriteAccess() == "group") {
163 echo 'selected="selected"';
164 }
165 }
166 ?>
167 >
168 <?php echo TXT_ONLY_GROUP_USERS ?>
169 </option>
170 <option value="all"
171 <?php
172 if (isset($groupId)) {
173 if ($uamUserGroup->getWriteAccess() == "all") {
174 echo 'selected="selected"';
175 }
176 }
177 ?>
178 >
179 <?php echo TXT_ALL ?>
180 </option>
181 </select><br />
182 <?php echo TXT_GROUP_WRITE_ACCESS_DESC; ?>
183 </td>
184 </tr>
185 <tr>
186 <th valign="top" scope="row"><?php echo TXT_GROUP_ROLE; ?></th>
187 <td>
188 <ul class='uam_role'>
189 <?php
190 global $wp_roles;
191
192 if (isset($groupId)) {
193 $groupRoles = $uamUserGroup->getRoles();
194 }
195
196 foreach ($wp_roles->role_names as $role => $name) {
197 if ($role != "administrator") {
198 ?>
199 <li class="selectit">
200 <input id="role-<?php echo $role; ?>" type="checkbox"
201 <?php
202
203 if (isset($groupRoles[$role])) {
204 echo 'checked="checked"';
205 }
206 ?>
207
208 value="<?php echo $role; ?> " name="roles[]" />
209 <label for="role-<?php echo $role; ?>">
210 <?php echo $role; ?>
211 </label>
212 </li>
213 <?php
214 }
215 }
216 ?>
217 </ul>
218 </td>
219 </tr>
220 </tbody>
221 </table>
222 <p class="submit">
223 <input type="submit" value="<?php
224 if (isset($groupId)) {
225 echo TXT_UPDATE_GROUP;
226 } else {
227 echo TXT_ADD_GROUP;
228 }
229 ?>" name="submit" class="button" />
230 </p>
231 </form>
232 <?php
233 }
234
235 if (isset($_GET['action'])) {
236 $action = $_GET['action'];
237 } else {
238 $action = null;
239 }
240
241 if ($action == 'editGroup' && isset($_GET['id'])) {
242 $editGroup = true;
243 } else {
244 $editGroup = false;
245 }
246
247 if (isset($_POST['action'])) {
248 $postAction = $_POST['action'];
249 } else {
250 $postAction = null;
251 }
252
253 if ($postAction == 'delgroup') {
254 if (isset($_POST['delete'])) {
255 $delIds = $_POST['delete'];
256 }
257 if (isset($delIds)) {
258 global $userAccessManager;
259
260 foreach ($delIds as $delId) {
261 $userAccessManager->getAccessHandler()->deleteUserGroup($delId);
262 }
263 ?>
264 <div class="updated">
265 <p><strong><?php echo TXT_DEL_GROUP; ?></strong></p>
266 </div>
267 <?php
268 }
269 }
270
271 if (($postAction == 'updateGroup' || $postAction == 'addGroup')
272 && !empty($_POST['userGroupName'])
273 ) {
274 if (!isset($_POST['userGroupId'])) {
275 $_POST['userGroupId'] = null;
276 }
277
278 insertUpdateGroup($_POST['userGroupId']);
279
280 if ($postAction == 'addGroup') {
281 ?>
282 <div class="updated">
283 <p><strong><?php echo TXT_GROUP_ADDED; ?></strong></p>
284 </div>
285 <?php
286 } elseif ($postAction == 'updateGroup') {
287 ?>
288 <div class="updated">
289 <p><strong><?php echo TXT_ACCESS_GROUP_EDIT_SUC; ?></strong></p>
290 </div>
291 <?php
292 }
293 } elseif (($postAction == 'updateGroup' || $postAction == 'addGroup')
294 && empty($_POST['userGroupName'])) {
295 ?>
296 <div class="error">
297 <p><strong><?php echo TXT_GROUP_NAME_ERROR; ?></strong></p>
298 </div>
299 <?php
300 }
301
302 if (!$editGroup) {
303 ?>
304 <div class="wrap">
305 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
306 <input type="hidden" value="delgroup" name="action" />
307 <h2><?php echo TXT_MANAGE_GROUP; ?></h2>
308 <div class="tablenav">
309 <div class="alignleft">
310 <input type="submit" class="button-secondary delete" name="deleteit" value="<?php echo TXT_DELETE; ?>" />
311 </div>
312 <br class="clear" />
313 </div>
314 <br class="clear" />
315 <table class="widefat">
316 <thead>
317 <tr class="thead">
318 <th scope="col"></th>
319 <th scope="col"><?php echo TXT_NAME; ?></th>
320 <th scope="col"><?php echo TXT_DESCRIPTION; ?></th>
321 <th scope="col"><?php echo TXT_READ_ACCESS; ?></th>
322 <th scope="col"><?php echo TXT_WRITE_ACCESS; ?></th>
323 <th scope="col"><?php echo TXT_GROUP_ROLE; ?></th>
324 <th scope="col"><?php echo TXT_IP_RANGE; ?></th>
325 </tr>
326 </thead>
327 <tbody>
328 <?php
329 if (isset($_GET['page'])) {
330 $curAdminPage = $_GET['page'];
331 }
332
333 global $userAccessManager;
334 $uamUserGroups = &$userAccessManager->getAccessHandler()->getUserGroups();
335
336 if (isset($uamUserGroups)) {
337 foreach ($uamUserGroups as $uamUserGroup) {
338 ?>
339 <tr class="alternate" id="group-<?php echo $uamUserGroup->getId(); ?>">
340 <th class="check-column" scope="row">
341 <input type="checkbox" value="<?php echo $uamUserGroup->getId(); ?>" name="delete[]" />
342 </th>
343 <td>
344 <strong>
345 <a href="?page=<?php echo $curAdminPage; ?>&amp;action=editGroup&amp;id=<?php echo $uamUserGroup->getId(); ?>">
346 <?php echo $uamUserGroup->getGroupName(); ?>
347 </a>
348 </strong>
349 </td>
350 <td><?php echo $uamUserGroup->getGroupDesc() ?></td>
351 <td>
352 <?php
353 if ($uamUserGroup->getReadAccess() == "all") {
354 echo TXT_ALL;
355 } elseif ($uamUserGroup->getReadAccess() == "group") {
356 echo TXT_ONLY_GROUP_USERS;
357 }
358 ?>
359 </td>
360 <td>
361 <?php
362 if ($uamUserGroup->getWriteAccess() == "all") {
363 echo TXT_ALL;
364 } elseif ($uamUserGroup->getWriteAccess() == "group") {
365 echo TXT_ONLY_GROUP_USERS;
366 }
367 ?>
368 </td>
369 <td>
370 <?php
371 if ($uamUserGroup->getRoles()) {
372 ?>
373 <ul>
374 <?php
375 foreach ($uamUserGroup->getRoles() as $role) {
376 ?>
377 <li>
378 <?php
379 echo $role['role_name'];
380 ?>
381 </li>
382 <?php
383 }
384 ?>
385 </ul>
386 <?php
387 } else {
388 echo TXT_NONE;
389 }
390 ?>
391 </td>
392 <td>
393 <?php
394 if ($uamUserGroup->getIpRange()) {
395 ?>
396 <ul>
397 <?php
398 foreach ($uamUserGroup->getIpRange() as $ipRange) {
399 ?>
400 <li>
401 <?php
402 echo $ipRange;
403 ?>
404 </li>
405 <?php
406 }
407 ?>
408 </ul>
409 <?php
410 } else {
411 echo TXT_NONE;
412 }
413 ?>
414 </td>
415 </tr>
416 <?php
417 }
418 }
419 ?>
420 </tbody>
421 </table>
422 </form>
423 </div>
424 <?php
425 }
426 ?>
427 <div class="wrap">
428 <h2>
429 <?php
430
431
432 if ($editGroup) {
433 echo TXT_EDIT_GROUP;
434 } else {
435 echo TXT_ADD_GROUP;
436 }
437 ?>
438 </h2>
439 <?php
440 if ($editGroup) {
441 $groupId = $_GET['id'];
442 getPrintEditGroup($groupId);
443 } else {
444 getPrintEditGroup();
445 }
446 ?>
447 </div>