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

449 lines 14.1 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-2016 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 $iUserGroupId The _iId of the user group.
22 */
23 function insertUpdateGroup($iUserGroupId)
24 {
25 global $oUserAccessManager;
26
27 if (empty($_POST) || !wp_verify_nonce($_POST['uamInsertUpdateGroupNonce'], 'uamInsertUpdateGroup')) {
28 wp_die(TXT_UAM_NONCE_FAILURE);
29 }
30
31 if ($iUserGroupId != null) {
32 $oUamUserGroup = $oUserAccessManager->getAccessHandler()->getUserGroups($iUserGroupId);
33 } else {
34 $oUamUserGroup = new UamUserGroup($oUserAccessManager->getAccessHandler(), null);
35 }
36
37 $oUamUserGroup->setGroupName($_POST['userGroupName']);
38 $oUamUserGroup->setGroupDesc($_POST['userGroupDescription']);
39 $oUamUserGroup->setReadAccess($_POST['readAccess']);
40 $oUamUserGroup->setWriteAccess($_POST['writeAccess']);
41 $oUamUserGroup->setIpRange($_POST['ipRange']);
42
43 if (isset($_POST['roles'])) {
44 $aRoles = $_POST['roles'];
45 } else {
46 $aRoles = null;
47 }
48
49 $oUamUserGroup->unsetObjects(UserAccessManager::ROLE_OBJECT_TYPE, true);
50
51 if ($aRoles && is_array($aRoles)) {
52 foreach ($aRoles as $sRole) {
53 $oUamUserGroup->addObject(UserAccessManager::ROLE_OBJECT_TYPE, htmlentities($sRole));
54 }
55 }
56
57 $oUamUserGroup->save();
58
59 $oUserAccessManager->getAccessHandler()->addUserGroup($oUamUserGroup);
60 }
61
62 /**
63 * Prints the group form.
64 *
65 * @param integer $sGroupId The given group id.
66 */
67 function getPrintEditGroup($sGroupId = null)
68 {
69 global $oUserAccessManager;
70 $oUamUserGroup = $oUserAccessManager->getAccessHandler()->getUserGroups($sGroupId);
71 ?>
72 <form method="post" action="<?php
73 $aUri = explode("?", $_SERVER["REQUEST_URI"]);
74 $sUri = reset($aUri);
75 echo htmlspecialchars($sUri) . "?page=" . $_GET['page'];
76 ?>">
77 <?php
78 wp_nonce_field('uamInsertUpdateGroup', 'uamInsertUpdateGroupNonce');
79
80 if (isset($sGroupId)) {
81 ?>
82 <input type="hidden" value="updateGroup" name="action" />
83 <input type="hidden" value="<?php echo $sGroupId; ?>" 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_UAM_GROUP_NAME; ?></th>
95 <td>
96 <input type="text" size="40" value="<?php
97 if (isset($sGroupId)) {
98 echo htmlentities($oUamUserGroup->getGroupName());
99 }
100 ?>" id="userGroupName" name="userGroupName" /><br />
101 <?php echo TXT_UAM_GROUP_NAME_DESC; ?>
102 </td>
103 </tr>
104 <tr class="form-field form-required">
105 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_DESC; ?></th>
106 <td>
107 <input type="text" size="40" value="<?php
108 if (isset($sGroupId)) {
109 echo htmlentities($oUamUserGroup->getGroupDesc());
110 }
111 ?>" id="userGroupDescription" name="userGroupDescription" /><br />
112 <?php echo TXT_UAM_GROUP_DESC_DESC; ?>
113 </td>
114 </tr>
115 <tr class="form-field form-required">
116 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_IP_RANGE; ?></th>
117 <td><input type="text" size="40" value="<?php
118 if (isset($sGroupId)) {
119 echo htmlentities($oUamUserGroup->getIpRange('string'));
120 }
121 ?>" id="ipRange" name="ipRange" /><br />
122 <?php echo TXT_UAM_GROUP_IP_RANGE_DESC; ?>
123 </td>
124 </tr>
125 <tr class="form-field form-required">
126 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_READ_ACCESS; ?></th>
127 <td>
128 <select name="readAccess">
129 <option value="group"
130 <?php
131 if (isset($sGroupId)) {
132 if ($oUamUserGroup->getReadAccess() == "group") {
133 echo 'selected="selected"';
134 }
135 }
136 ?>
137 >
138 <?php echo TXT_UAM_ONLY_GROUP_USERS ?>
139 </option>
140 <option value="all"
141 <?php
142 if (isset($sGroupId)) {
143 if ($oUamUserGroup->getReadAccess() == "all") {
144 echo 'selected="selected"';
145 }
146 }
147 ?>
148 >
149 <?php echo TXT_UAM_ALL ?>
150 </option>
151 </select><br />
152 <?php echo TXT_UAM_GROUP_READ_ACCESS_DESC; ?>
153 </td>
154 </tr>
155 <tr class="form-field form-required">
156 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_WRITE_ACCESS; ?></th>
157 <td>
158 <select name="writeAccess">
159 <option value="group"
160 <?php
161 if (isset($sGroupId)) {
162 if ($oUamUserGroup->getWriteAccess() == "group") {
163 echo 'selected="selected"';
164 }
165 }
166 ?>
167 >
168 <?php echo TXT_UAM_ONLY_GROUP_USERS ?>
169 </option>
170 <option value="all"
171 <?php
172 if (isset($sGroupId)) {
173 if ($oUamUserGroup->getWriteAccess() == "all") {
174 echo 'selected="selected"';
175 }
176 }
177 ?>
178 >
179 <?php echo TXT_UAM_ALL ?>
180 </option>
181 </select><br />
182 <?php echo TXT_UAM_GROUP_WRITE_ACCESS_DESC; ?>
183 </td>
184 </tr>
185 <tr>
186 <th valign="top" scope="row"><?php echo TXT_UAM_GROUP_ROLE; ?></th>
187 <td>
188 <ul class='uam_role'>
189 <?php
190 global $wp_roles;
191
192 if (isset($sGroupId)) {
193 $aGroupRoles = $oUamUserGroup->getObjectsFromType(UserAccessManager::ROLE_OBJECT_TYPE);
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($aGroupRoles[$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($sGroupId)) {
225 echo TXT_UAM_UPDATE_GROUP;
226 } else {
227 echo TXT_UAM_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 (empty($_POST)
255 || !wp_verify_nonce($_POST['uamDeleteGroupNonce'], 'uamDeleteGroup')
256 ) {
257 wp_die(TXT_UAM_NONCE_FAILURE);
258 }
259
260 if (isset($_POST['delete']) && is_array($_POST['delete'])) {
261 global $oUserAccessManager;
262
263 foreach ($_POST['delete'] as $delId) {
264 $oUserAccessManager->getAccessHandler()->deleteUserGroup($delId);
265 }
266 ?>
267 <div class="updated">
268 <p><strong><?php echo TXT_UAM_DEL_GROUP; ?></strong></p>
269 </div>
270 <?php
271 }
272 }
273
274 if (($postAction == 'updateGroup' || $postAction == 'addGroup')
275 && !empty($_POST['userGroupName'])
276 ) {
277 if (!isset($_POST['userGroupId'])) {
278 $_POST['userGroupId'] = null;
279 }
280
281 insertUpdateGroup($_POST['userGroupId']);
282
283 if ($postAction == 'addGroup') {
284 ?>
285 <div class="updated">
286 <p><strong><?php echo TXT_UAM_GROUP_ADDED; ?></strong></p>
287 </div>
288 <?php
289 } elseif ($postAction == 'updateGroup') {
290 ?>
291 <div class="updated">
292 <p><strong><?php echo TXT_UAM_ACCESS_GROUP_EDIT_SUC; ?></strong></p>
293 </div>
294 <?php
295 }
296 } elseif (($postAction == 'updateGroup' || $postAction == 'addGroup')
297 && empty($_POST['userGroupName'])) {
298 ?>
299 <div class="error">
300 <p><strong><?php echo TXT_UAM_GROUP_NAME_ERROR; ?></strong></p>
301 </div>
302 <?php
303 }
304
305 if (!$editGroup) {
306 ?>
307 <div class="wrap">
308 <form method="post" action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]); ?>">
309 <?php wp_nonce_field('uamDeleteGroup', 'uamDeleteGroupNonce'); ?>
310 <input type="hidden" value="delgroup" name="action" />
311 <h2><?php echo TXT_UAM_MANAGE_GROUP; ?></h2>
312 <div class="tablenav">
313 <div class="alignleft">
314 <input type="submit" class="button-secondary delete" name="deleteit" value="<?php echo TXT_UAM_DELETE; ?>" />
315 </div>
316 <br class="clear" />
317 </div>
318 <br class="clear" />
319 <table class="widefat">
320 <thead>
321 <tr class="thead">
322 <th scope="col"></th>
323 <th scope="col"><?php echo TXT_UAM_NAME; ?></th>
324 <th scope="col"><?php echo TXT_UAM_DESCRIPTION; ?></th>
325 <th scope="col"><?php echo TXT_UAM_READ_ACCESS; ?></th>
326 <th scope="col"><?php echo TXT_UAM_WRITE_ACCESS; ?></th>
327 <th scope="col"><?php echo TXT_UAM_GROUP_ROLE; ?></th>
328 <th scope="col"><?php echo TXT_UAM_IP_RANGE; ?></th>
329 </tr>
330 </thead>
331 <tbody>
332 <?php
333 $sCurAdminPage = isset($_GET['page']) ? $_GET['page'] : '';
334
335 global $oUserAccessManager;
336 $aUamUserGroups = $oUserAccessManager->getAccessHandler()->getUserGroups();
337
338 if (isset($aUamUserGroups)) {
339 foreach ($aUamUserGroups as $oUamUserGroup) {
340 ?>
341 <tr class="alternate" id="group-<?php echo $oUamUserGroup->getId(); ?>">
342 <th class="check-column" scope="row">
343 <input type="checkbox" value="<?php echo $oUamUserGroup->getId(); ?>" name="delete[]" />
344 </th>
345 <td>
346 <strong>
347 <a href="?page=<?php echo $sCurAdminPage; ?>&amp;action=editGroup&amp;id=<?php echo $oUamUserGroup->getId(); ?>">
348 <?php echo htmlentities($oUamUserGroup->getGroupName()); ?>
349 </a>
350 </strong>
351 </td>
352 <td><?php echo htmlentities($oUamUserGroup->getGroupDesc()) ?></td>
353 <td>
354 <?php
355 if ($oUamUserGroup->getReadAccess() == "all") {
356 echo TXT_UAM_ALL;
357 } elseif ($oUamUserGroup->getReadAccess() == "group") {
358 echo TXT_UAM_ONLY_GROUP_USERS;
359 }
360 ?>
361 </td>
362 <td>
363 <?php
364 if ($oUamUserGroup->getWriteAccess() == "all") {
365 echo TXT_UAM_ALL;
366 } elseif ($oUamUserGroup->getWriteAccess() == "group") {
367 echo TXT_UAM_ONLY_GROUP_USERS;
368 }
369 ?>
370 </td>
371 <td>
372 <?php
373 if ($oUamUserGroup->getObjectsFromType(UserAccessManager::ROLE_OBJECT_TYPE)) {
374 ?>
375 <ul>
376 <?php
377 foreach ($oUamUserGroup->getObjectsFromType(UserAccessManager::ROLE_OBJECT_TYPE) as $sKey => $sRole) {
378 ?>
379 <li>
380 <?php
381 echo $sKey;
382 ?>
383 </li>
384 <?php
385 }
386 ?>
387 </ul>
388 <?php
389 } else {
390 echo TXT_UAM_NONE;
391 }
392 ?>
393 </td>
394 <td>
395 <?php
396 if ($oUamUserGroup->getIpRange()) {
397 ?>
398 <ul>
399 <?php
400 foreach ($oUamUserGroup->getIpRange() as $sIpRange) {
401 ?>
402 <li>
403 <?php
404 echo htmlentities($sIpRange);
405 ?>
406 </li>
407 <?php
408 }
409 ?>
410 </ul>
411 <?php
412 } else {
413 echo TXT_UAM_NONE;
414 }
415 ?>
416 </td>
417 </tr>
418 <?php
419 }
420 }
421 ?>
422 </tbody>
423 </table>
424 </form>
425 </div>
426 <?php
427 }
428 ?>
429 <div class="wrap">
430 <h2>
431 <?php
432
433
434 if ($editGroup) {
435 echo TXT_UAM_EDIT_GROUP;
436 } else {
437 echo TXT_UAM_ADD_GROUP;
438 }
439 ?>
440 </h2>
441 <?php
442 if ($editGroup) {
443 $groupId = $_GET['id'];
444 getPrintEditGroup($groupId);
445 } else {
446 getPrintEditGroup();
447 }
448 ?>
449 </div>