| 1 |
<?php |
| 2 |
/** |
| 3 |
* UserGroupList.php |
| 4 |
* |
| 5 |
* Shows the user group edit list at the admin panel. |
| 6 |
* |
| 7 |
* PHP versions 5 |
| 8 |
* |
| 9 |
* @author Alexander Schneider <alexanderschneider85@gmail.com> |
| 10 |
* @copyright 2008-2017 Alexander Schneider |
| 11 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 12 |
* @version SVN: $id$ |
| 13 |
* @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* @var UserGroupController $controller |
| 18 |
*/ |
| 19 |
|
| 20 |
/** |
| 21 |
* @param string $name |
| 22 |
* @param string $sortingParameter |
| 23 |
* |
| 24 |
* @return string |
| 25 |
*/ |
| 26 |
|
| 27 |
use UserAccessManager\Controller\Backend\UserGroupController; |
| 28 |
use UserAccessManager\Object\ObjectHandler; |
| 29 |
|
| 30 |
$createHeaderColumn = function ($name, $sortingParameter) use ($controller) { |
| 31 |
$isSorted = $controller->getRequestParameter('orderby') === $sortingParameter; |
| 32 |
$class = $isSorted === true ? 'sorted' : 'sortable'; |
| 33 |
$sortOrder = $isSorted === true ? $controller->getRequestParameter('order') : 'asc'; |
| 34 |
|
| 35 |
$inner = "<span>{$name}</span><span class=\"sorting-indicator\"></span>"; |
| 36 |
$link = "<a href=\"{$controller->getSortUrl($sortingParameter)}\" >{$inner}</a>"; |
| 37 |
return "<th scope=\"col\" class=\"{$class} {$sortOrder}\">{$link}</th>"; |
| 38 |
} |
| 39 |
|
| 40 |
?> |
| 41 |
<form method="post" action="<?php echo $controller->getRequestUrl(); ?>"> |
| 42 |
<?php $controller->createNonceField('uamDeleteGroup'); ?> |
| 43 |
<input type="hidden" value="delete_user_group" name="uam_action"/> |
| 44 |
<div class="tablenav"> |
| 45 |
<div class="alignleft"> |
| 46 |
<input type="submit" class="button-secondary delete" name="deleteit" |
| 47 |
value="<?php echo TXT_UAM_DELETE; ?>"/> |
| 48 |
</div> |
| 49 |
<br class="clear"/> |
| 50 |
</div> |
| 51 |
<table class="widefat"> |
| 52 |
<thead> |
| 53 |
<tr class="thead"> |
| 54 |
<th scope="col"></th> |
| 55 |
<?php echo $createHeaderColumn(TXT_UAM_NAME, 'name'); ?> |
| 56 |
<?php echo $createHeaderColumn(TXT_UAM_DESCRIPTION, 'description'); ?> |
| 57 |
<?php echo $createHeaderColumn(TXT_UAM_READ_ACCESS, 'readAccess'); ?> |
| 58 |
<?php echo $createHeaderColumn(TXT_UAM_WRITE_ACCESS, 'writeAccess'); ?> |
| 59 |
<th scope="col"><?php echo TXT_UAM_GROUP_ROLE; ?></th> |
| 60 |
<?php echo $createHeaderColumn(TXT_UAM_IP_RANGE, 'ipRange'); ?> |
| 61 |
</tr> |
| 62 |
</thead> |
| 63 |
<tbody> |
| 64 |
<?php |
| 65 |
$currentAdminPage = $controller->getRequestParameter('page'); |
| 66 |
$userGroups = $controller->getUserGroups(); |
| 67 |
foreach ($userGroups as $userGroup) { |
| 68 |
?> |
| 69 |
<tr class="alternate" id="group-<?php echo $userGroup->getId(); ?>"> |
| 70 |
<th class="check-column"> |
| 71 |
<label> |
| 72 |
<input type="checkbox" value="<?php echo $userGroup->getId(); ?>" name="delete[]"/> |
| 73 |
</label> |
| 74 |
</th> |
| 75 |
<td> |
| 76 |
<strong> |
| 77 |
<?php |
| 78 |
$link = "?page={$currentAdminPage}&uam_action=edit_user_group" |
| 79 |
. "&userGroupId={$userGroup->getId()}"; |
| 80 |
?> |
| 81 |
<a href="<?php echo $link; ?>"> |
| 82 |
<?php echo htmlentities($userGroup->getName()); ?> |
| 83 |
</a> |
| 84 |
</strong> |
| 85 |
</td> |
| 86 |
<td><?php echo htmlentities($userGroup->getDescription()) ?></td> |
| 87 |
<td> |
| 88 |
<?php |
| 89 |
if ($userGroup->getReadAccess() === 'all') { |
| 90 |
echo TXT_UAM_ALL; |
| 91 |
} elseif ($userGroup->getReadAccess() === 'group') { |
| 92 |
echo TXT_UAM_ONLY_GROUP_USERS; |
| 93 |
} |
| 94 |
?> |
| 95 |
</td> |
| 96 |
<td> |
| 97 |
<?php |
| 98 |
if ($userGroup->getWriteAccess() === 'all') { |
| 99 |
echo TXT_UAM_ALL; |
| 100 |
} elseif ($userGroup->getWriteAccess() === 'group') { |
| 101 |
echo TXT_UAM_ONLY_GROUP_USERS; |
| 102 |
} elseif ($userGroup->getWriteAccess() === 'none') { |
| 103 |
echo TXT_UAM_NONE; |
| 104 |
} |
| 105 |
?> |
| 106 |
</td> |
| 107 |
<td> |
| 108 |
<?php |
| 109 |
$roleNames = $controller->getRoleNames(); |
| 110 |
$groupRoles = $userGroup->getAssignedObjectsByType( |
| 111 |
ObjectHandler::GENERAL_ROLE_OBJECT_TYPE |
| 112 |
); |
| 113 |
|
| 114 |
if (count($groupRoles) > 0) { |
| 115 |
?> |
| 116 |
<ul style="margin: 0;"> |
| 117 |
<?php |
| 118 |
foreach ($groupRoles as $key => $role) { |
| 119 |
?> |
| 120 |
<li><?php echo $roleNames[$key] ?? $key; ?></li> |
| 121 |
<?php |
| 122 |
} |
| 123 |
?> |
| 124 |
</ul> |
| 125 |
<?php |
| 126 |
} else { |
| 127 |
echo TXT_UAM_NONE; |
| 128 |
} |
| 129 |
?> |
| 130 |
</td> |
| 131 |
<td> |
| 132 |
<?php |
| 133 |
$ipRanges = $userGroup->getIpRangeArray(); |
| 134 |
|
| 135 |
if (count($ipRanges) > 0) { |
| 136 |
?> |
| 137 |
<ul> |
| 138 |
<?php |
| 139 |
foreach ($ipRanges as $ipRange) { |
| 140 |
?> |
| 141 |
<li><?php echo htmlentities($ipRange); ?></li> |
| 142 |
<?php |
| 143 |
} |
| 144 |
?> |
| 145 |
</ul> |
| 146 |
<?php |
| 147 |
} else { |
| 148 |
echo TXT_UAM_NONE; |
| 149 |
} |
| 150 |
?> |
| 151 |
</td> |
| 152 |
</tr> |
| 153 |
<?php |
| 154 |
} |
| 155 |
?> |
| 156 |
</tbody> |
| 157 |
</table> |
| 158 |
<div class="tablenav"> |
| 159 |
<div class="alignleft"> |
| 160 |
<input type="submit" |
| 161 |
class="button-secondary delete" |
| 162 |
name="deleteit" |
| 163 |
value="<?php echo TXT_UAM_DELETE; ?>"/> |
| 164 |
</div> |
| 165 |
<br class="clear"/> |
| 166 |
</div> |
| 167 |
</form> |
| 168 |
|