PluginProbe
User Access Manager / 1.2.2
User Access Manager v1.2.2
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.2.2, at tpl/adminGroup.php

463 lines 12.6 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 (empty($_POST)
30 || !wp_verify_nonce($_POST['uamInsertUpdateGroupNonce'], 'uamInsertUpdateGroup')
31 ) {
32 wp_die(TXT_UAM_NONCE_FAILURE);
33 }
34
35 if ($userGroupId != null) {
36 $uamUserGroup
37 = $userAccessManager->getAccessHandler()->getUserGroups($userGroupId);
38 } else {
39 $uamUserGroup
40 = new UamUserGroup($userAccessManager->getAccessHandler(), null);
41 }
42
43 $uamUserGroup->setGroupName($_POST['userGroupName']);
44 $uamUserGroup->setGroupDesc($_POST['userGroupDescription']);
45 $uamUserGroup->setReadAccess($_POST['readAccess']);
46 $uamUserGroup->setWriteAccess($_POST['writeAccess']);
47 $uamUserGroup->setIpRange($_POST['ipRange']);
48
49 if (isset($_POST['roles'])) {
50 $roles = $_POST['roles'];
51 } else {
52 $roles = null;
53 }
54
55 $uamUserGroup->unsetObjects('role', true);
56
57 if ($roles) {
58 foreach ($roles as $role) {
59 $uamUserGroup->addObject('role', $role);
60 }
61 }
62
63 $uamUserGroup->save();
64
65 $userAccessManager->getAccessHandler()->addUserGroup($uamUserGroup);
66 }
67
68 /**
69 * Prints the group formular.
70 *
71 * @param integer $groupId The given group id.
72 *
73 * @return null
74 */
75 function getPrintEditGroup($groupId = null)
76 {
77 global $userAccessManager;
78 $uamUserGroup = $userAccessManager->getAccessHandler()->getUserGroups($groupId);
79 ?>
80 <form method="post" action="<?php
81 echo reset(
82 explode("?", $_SERVER["REQUEST_URI"])
83 ) . "?page=" . $_GET['page'];
84 ?>">
85 <?php
86 wp_nonce_field('uamInsertUpdateGroup', 'uamInsertUpdateGroupNonce');
87
88 if (isset($groupId)) {
89 ?>
90 <input type="hidden" value="updateGroup" name="action" />
91 <input type="hidden" value="<?php echo $groupId; ?>" name="userGroupId" />
92 <?php
93 } else {
94 ?>
95 <input type="hidden" value="addGroup" name="action" />
96 <?php
97 }
98 ?>
99 <table class="form-table">
100 <tbody>
101 <tr class="form-field form-required">
102 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_NAME; ?></th>
103 <td>
104 <input type="text" size="40" value="<?php
105 if (isset($groupId)) {
106 echo $uamUserGroup->getGroupName();
107 }
108 ?>" id="userGroupName" name="userGroupName" /><br />
109 <?php echo TXT_UAM_GROUP_NAME_DESC; ?>
110 </td>
111 </tr>
112 <tr class="form-field form-required">
113 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_DESC; ?></th>
114 <td>
115 <input type="text" size="40" value="<?php
116 if (isset($groupId)) {
117 echo $uamUserGroup->getGroupDesc();
118 }
119 ?>" id="userGroupDescription" name="userGroupDescription" /><br />
120 <?php echo TXT_UAM_GROUP_DESC_DESC; ?>
121 </td>
122 </tr>
123 <tr class="form-field form-required">
124 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_IP_RANGE; ?></th>
125 <td><input type="text" size="40" value="<?php
126 if (isset($groupId)) {
127 echo $uamUserGroup->getIpRange('string');
128 }
129 ?>" id="ipRange" name="ipRange" /><br />
130 <?php echo TXT_UAM_GROUP_IP_RANGE_DESC; ?>
131 </td>
132 </tr>
133 <tr class="form-field form-required">
134 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_READ_ACCESS; ?></th>
135 <td>
136 <select name="readAccess">
137 <option value="group"
138 <?php
139 if (isset($groupId)) {
140 if ($uamUserGroup->getReadAccess() == "group") {
141 echo 'selected="selected"';
142 }
143 }
144 ?>
145 >
146 <?php echo TXT_UAM_ONLY_GROUP_USERS ?>
147 </option>
148 <option value="all"
149 <?php
150 if (isset($groupId)) {
151 if ($uamUserGroup->getReadAccess() == "all") {
152 echo 'selected="selected"';
153 }
154 }
155 ?>
156 >
157 <?php echo TXT_UAM_ALL ?>
158 </option>
159 </select><br />
160 <?php echo TXT_UAM_GROUP_READ_ACCESS_DESC; ?>
161 </td>
162 </tr>
163 <tr class="form-field form-required">
164 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_WRITE_ACCESS; ?></th>
165 <td>
166 <select name="writeAccess">
167 <option value="group"
168 <?php
169 if (isset($groupId)) {
170 if ($uamUserGroup->getWriteAccess() == "group") {
171 echo 'selected="selected"';
172 }
173 }
174 ?>
175 >
176 <?php echo TXT_UAM_ONLY_GROUP_USERS ?>
177 </option>
178 <option value="all"
179 <?php
180 if (isset($groupId)) {
181 if ($uamUserGroup->getWriteAccess() == "all") {
182 echo 'selected="selected"';
183 }
184 }
185 ?>
186 >
187 <?php echo TXT_UAM_ALL ?>
188 </option>
189 </select><br />
190 <?php echo TXT_UAM_GROUP_WRITE_ACCESS_DESC; ?>
191 </td>
192 </tr>
193 <tr>
194 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_ROLE; ?></th>
195 <td>
196 <ul class='uam_role'>
197 <?php
198 global $wp_roles;
199
200 if (isset($groupId)) {
201 $groupRoles = $uamUserGroup->getObjectsFromType('role');
202 }
203
204 foreach ($wp_roles->role_names as $role => $name) {
205 if ($role != "administrator") {
206 ?>
207 <li class="selectit">
208 <input id="role-<?php echo $role; ?>" type="checkbox"
209 <?php
210
211 if (isset($groupRoles[$role])) {
212 echo 'checked="checked"';
213 }
214 ?>
215
216 value="<?php echo $role; ?> " name="roles[]" />
217 <label for="role-<?php echo $role; ?>">
218 <?php echo $role; ?>
219 </label>
220 </li>
221 <?php
222 }
223 }
224 ?>
225 </ul>
226 </td>
227 </tr>
228 </tbody>
229 </table>
230 <p class="submit">
231 <input type="submit" value="<?php
232 if (isset($groupId)) {
233 echo TXT_UAM_UPDATE_GROUP;
234 } else {
235 echo TXT_UAM_ADD_GROUP;
236 }
237 ?>" name="submit" class="button" />
238 </p>
239 </form>
240 <?php
241 }
242
243 if (isset($_GET['action'])) {
244 $action = $_GET['action'];
245 } else {
246 $action = null;
247 }
248
249 if ($action == 'editGroup' && isset($_GET['id'])) {
250 $editGroup = true;
251 } else {
252 $editGroup = false;
253 }
254
255 if (isset($_POST['action'])) {
256 $postAction = $_POST['action'];
257 } else {
258 $postAction = null;
259 }
260
261 if ($postAction == 'delgroup') {
262 if (empty($_POST)
263 || !wp_verify_nonce($_POST['uamDeleteGroupNonce'], 'uamDeleteGroup')
264 ) {
265 wp_die(TXT_UAM_NONCE_FAILURE);
266 }
267
268 if (isset($_POST['delete'])) {
269 $delIds = $_POST['delete'];
270 }
271
272 if (isset($delIds)) {
273 global $userAccessManager;
274
275 foreach ($delIds as $delId) {
276 $userAccessManager->getAccessHandler()->deleteUserGroup($delId);
277 }
278 ?>
279 <div class="updated">
280 <p><strong><?php echo TXT_UAM_DEL_GROUP; ?></strong></p>
281 </div>
282 <?php
283 }
284 }
285
286 if (($postAction == 'updateGroup' || $postAction == 'addGroup')
287 && !empty($_POST['userGroupName'])
288 ) {
289 if (!isset($_POST['userGroupId'])) {
290 $_POST['userGroupId'] = null;
291 }
292
293 insertUpdateGroup($_POST['userGroupId']);
294
295 if ($postAction == 'addGroup') {
296 ?>
297 <div class="updated">
298 <p><strong><?php echo TXT_UAM_GROUP_ADDED; ?></strong></p>
299 </div>
300 <?php
301 } elseif ($postAction == 'updateGroup') {
302 ?>
303 <div class="updated">
304 <p><strong><?php echo TXT_UAM_ACCESS_GROUP_EDIT_SUC; ?></strong></p>
305 </div>
306 <?php
307 }
308 } elseif (($postAction == 'updateGroup' || $postAction == 'addGroup')
309 && empty($_POST['userGroupName'])) {
310 ?>
311 <div class="error">
312 <p><strong><?php echo TXT_UAM_GROUP_NAME_ERROR; ?></strong></p>
313 </div>
314 <?php
315 }
316
317 if (!$editGroup) {
318 ?>
319 <div class="wrap">
320 <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
321 <?php wp_nonce_field('uamDeleteGroup', 'uamDeleteGroupNonce'); ?>
322 <input type="hidden" value="delgroup" name="action" />
323 <h2><?php echo TXT_UAM_MANAGE_GROUP; ?></h2>
324 <div class="tablenav">
325 <div class="alignleft">
326 <input type="submit" class="button-secondary delete" name="deleteit" value="<?php echo TXT_UAM_DELETE; ?>" />
327 </div>
328 <br class="clear" />
329 </div>
330 <br class="clear" />
331 <table class="widefat">
332 <thead>
333 <tr class="thead">
334 <th scope="col"></th>
335 <th scope="col"><?php echo TXT_UAM_NAME; ?></th>
336 <th scope="col"><?php echo TXT_UAM_DESCRIPTION; ?></th>
337 <th scope="col"><?php echo TXT_UAM_READ_ACCESS; ?></th>
338 <th scope="col"><?php echo TXT_UAM_WRITE_ACCESS; ?></th>
339 <th scope="col"><?php echo TXT_UAM_GROUP_ROLE; ?></th>
340 <th scope="col"><?php echo TXT_UAM_IP_RANGE; ?></th>
341 </tr>
342 </thead>
343 <tbody>
344 <?php
345 if (isset($_GET['page'])) {
346 $curAdminPage = $_GET['page'];
347 }
348
349 global $userAccessManager;
350 $uamUserGroups = $userAccessManager->getAccessHandler()->getUserGroups();
351
352 if (isset($uamUserGroups)) {
353 foreach ($uamUserGroups as $uamUserGroup) {
354 ?>
355 <tr class="alternate" id="group-<?php echo $uamUserGroup->getId(); ?>">
356 <th class="check-column" scope="row">
357 <input type="checkbox" value="<?php echo $uamUserGroup->getId(); ?>" name="delete[]" />
358 </th>
359 <td>
360 <strong>
361 <a href="?page=<?php echo $curAdminPage; ?>&amp;action=editGroup&amp;id=<?php echo $uamUserGroup->getId(); ?>">
362 <?php echo $uamUserGroup->getGroupName(); ?>
363 </a>
364 </strong>
365 </td>
366 <td><?php echo $uamUserGroup->getGroupDesc() ?></td>
367 <td>
368 <?php
369 if ($uamUserGroup->getReadAccess() == "all") {
370 echo TXT_UAM_ALL;
371 } elseif ($uamUserGroup->getReadAccess() == "group") {
372 echo TXT_UAM_ONLY_GROUP_USERS;
373 }
374 ?>
375 </td>
376 <td>
377 <?php
378 if ($uamUserGroup->getWriteAccess() == "all") {
379 echo TXT_UAM_ALL;
380 } elseif ($uamUserGroup->getWriteAccess() == "group") {
381 echo TXT_UAM_ONLY_GROUP_USERS;
382 }
383 ?>
384 </td>
385 <td>
386 <?php
387 if ($uamUserGroup->getObjectsFromType('role')) {
388 ?>
389 <ul>
390 <?php
391 foreach ($uamUserGroup->getObjectsFromType('role') as $key => $role) {
392 ?>
393 <li>
394 <?php
395 echo $key;
396 ?>
397 </li>
398 <?php
399 }
400 ?>
401 </ul>
402 <?php
403 } else {
404 echo TXT_UAM_NONE;
405 }
406 ?>
407 </td>
408 <td>
409 <?php
410 if ($uamUserGroup->getIpRange()) {
411 ?>
412 <ul>
413 <?php
414 foreach ($uamUserGroup->getIpRange() as $ipRange) {
415 ?>
416 <li>
417 <?php
418 echo $ipRange;
419 ?>
420 </li>
421 <?php
422 }
423 ?>
424 </ul>
425 <?php
426 } else {
427 echo TXT_UAM_NONE;
428 }
429 ?>
430 </td>
431 </tr>
432 <?php
433 }
434 }
435 ?>
436 </tbody>
437 </table>
438 </form>
439 </div>
440 <?php
441 }
442 ?>
443 <div class="wrap">
444 <h2>
445 <?php
446
447
448 if ($editGroup) {
449 echo TXT_UAM_EDIT_GROUP;
450 } else {
451 echo TXT_UAM_ADD_GROUP;
452 }
453 ?>
454 </h2>
455 <?php
456 if ($editGroup) {
457 $groupId = $_GET['id'];
458 getPrintEditGroup($groupId);
459 } else {
460 getPrintEditGroup();
461 }
462 ?>
463 </div>