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