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

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