Skip to content

Commit b02dec7

Browse files
committed
start working on some shit
1 parent 986c22a commit b02dec7

File tree

5 files changed

+113
-140
lines changed

5 files changed

+113
-140
lines changed

lib/permissions.php

+84-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ function LoadGroups()
6464
$loguserGroup['id'], $secgroups, $loguserid);
6565
$loguserPermset = LoadPermset($res);
6666

67-
$maxrank = FetchResult("SELECT MAX(rank) FROM {usergroups}");
68-
6967
$loguser['banned'] = ($loguserGroup['id'] == Settings::get('bannedGroup'));
7068
$loguser['root'] = ($loguserGroup['id'] == Settings::get('rootGroup'));
7169
}
@@ -172,6 +170,90 @@ function ForumsWithPermission($perm, $guest=false)
172170
return $ret;
173171
}
174172

173+
// retrieves the given permissions for the given users
174+
// retrieves all possible permissions if $perms is left out
175+
function GetUserPermissions($users, $perms=null)
176+
{
177+
if (is_array($users))
178+
$userclause = 'IN ({0c})';
179+
else
180+
$userclause = '= {0}';
181+
182+
// retrieve all the groups those users belong to
183+
$allgroups = Query("
184+
SELECT primarygroup gid, id uid, 0 type FROM {users} WHERE id {$userclause}
185+
UNION SELECT groupid gid, userid uid, 1 type FROM {secondarygroups} WHERE userid {$userclause}",
186+
$users);
187+
188+
$primgroups = array(); // primary group IDs
189+
$secgroups = array(); // secondary group IDs
190+
$groupusers = array(); // array of user IDs for each group
191+
192+
while ($g = Fetch($allgroups))
193+
{
194+
if ($g['type'])
195+
$secgroups[] = $g['gid'];
196+
else
197+
$primgroups[] = $g['gid'];
198+
199+
$groupusers[$g['gid']][] = $g['uid'];
200+
}
201+
202+
// remove duplicate group IDs. This is faster than using array_unique.
203+
$primgroups = array_flip(array_flip($primgroups));
204+
$secgroups = array_flip(array_flip($secgroups));
205+
206+
if (is_array($perms))
207+
$permclause = 'AND perm IN ({3c})';
208+
else if ($perms)
209+
$permclause = 'AND perm = {3}';
210+
else
211+
$permclause = '';
212+
213+
// retrieve all the permissions related to those users and groups
214+
$res = Query("
215+
SELECT *, 1 ord FROM {permissions} WHERE applyto=0 AND id IN ({1c}) {$permclause}
216+
UNION SELECT *, 2 ord FROM {permissions} WHERE applyto=0 AND id IN ({2c}) {$permclause}
217+
UNION SELECT *, 3 ord FROM {permissions} WHERE applyto=1 AND id {$userclause} {$permclause}
218+
ORDER BY ord",
219+
$users, $primgroups, $secgroups, $perms);
220+
221+
$permdata = array();
222+
$permord = array();
223+
224+
// compile all the resulting permission lists for all the requested users
225+
while ($p = Fetch($res))
226+
{
227+
if ($p['value'] == 0) continue;
228+
229+
$k = $p['perm'];
230+
if ($p['arg']) $k .= '_'.$p['arg'];
231+
232+
if ($p['applyto'] == 0) // group perm -- apply it to all the matching users
233+
{
234+
foreach ($groupusers[$p['id']] as $uid)
235+
{
236+
if ($p['ord'] > $permord[$uid][$k] || $permdata[$uid][$k] != -1)
237+
$permdata[$uid][$k] = $p['value'];
238+
239+
$permord[$uid][$k] = $p['ord'];
240+
}
241+
}
242+
else // user perm
243+
{
244+
$uid = $p['id'];
245+
246+
if ($p['ord'] > $permord[$uid][$k] || $permdata[$uid][$k] != -1)
247+
$permdata[$uid][$k] = $p['value'];
248+
249+
$permord[$uid][$k] = $p['ord'];
250+
}
251+
}
252+
253+
unset($permord);
254+
return $permdata;
255+
}
256+
175257

176258
LoadGroups();
177259
$loguser['powerlevel'] = -1; // safety

pages/editgroups.php

+15-24
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<?php
22

3-
die('this sucks');
3+
CheckPermission('admin.editgroups');
44

5-
if (!$loguser['almighty'])
6-
Kill(__('You may not perform this action.'));
7-
8-
$title = 'Edit groups';
5+
$title = __('Edit groups');
6+
MakeCrumbs(array(actionLink('admin') => __('Admin'), '' => __('Edit groups')));
97

108
$gtypes = array(
11-
-1 => __('Group for banned users'),
12-
0 => __('Standard group'),
13-
1 => __('Group for normal users'),
14-
2 => __('Group for roots')
9+
0 => __('Primary'),
10+
1 => __('Secondary')
1511
);
1612

1713
$gdisplays = array(
@@ -22,24 +18,19 @@
2218

2319
if (!$_POST['saveaction'])
2420
{
25-
$groups = Query("SELECT * FROM {usergroups} WHERE rank<={0} ORDER BY rank", $loguserGroup['rank']);
21+
$groups = Query("SELECT * FROM {usergroups} WHERE rank<={0} ORDER BY type, rank", $loguserGroup['rank']);
22+
$gdata = array();
2623

27-
echo '
28-
<table class="outline margin">
29-
<tr class="header1"><th>Groups</th></tr>
30-
<tr class="cell1">
31-
<td class="center">';
32-
$i = 0;
3324
while ($group = Fetch($groups))
3425
{
35-
echo '
36-
'.($i==0?'':' - ').actionLinkTag('<span style="color:'.htmlspecialchars($group['color_unspec']).';">'.htmlspecialchars($group['title']).'</span>', 'editgroups', $group['id']);
37-
$i++;
26+
$gtitle = htmlspecialchars($group['title']);
27+
if (!$group['type'])
28+
$gtitle = '<span class="userlink" style="color:'.htmlspecialchars($group['color_unspec']).';">'.$gtitle.'</span>';
29+
30+
$gdata[] = actionLinkTag($gtitle, 'editgroups', $group['id']);
3831
}
39-
echo '
40-
</td>
41-
</tr>
42-
</table>';
32+
33+
RenderTemplate('grouplist', array('groups' => $gdata));
4334
}
4435

4536
if (isset($_GET['id']))
@@ -54,7 +45,7 @@
5445

5546
MakeCrumbs(array(actionLink('admin') => __('Admin'), actionLink('editgroups') => __('Edit groups'), '' => htmlspecialchars($group['title'])));
5647

57-
$canPromoteHigher = ($gid == $loguserGroup['id']);
48+
$canPromoteHigher = $loguser['root'] && ($gid == $loguserGroup['id']);
5849
}
5950
else
6051
{

pages/editsmilies.php

-113
This file was deleted.

pages/profile.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
if($title)
144144
$temp[__("Title")] = $title;
145145

146-
$glist = '<strong style="color: '.htmlspecialchars($ugroup['color_unspec']).';">'.htmlspecialchars($ugroup['name']).'</strong>';
146+
$glist = '<strong class="userlink" style="color: '.htmlspecialchars($ugroup['color_unspec']).';">'.htmlspecialchars($ugroup['name']).'</strong>';
147147
foreach ($usgroups as $sgroup)
148148
{
149149
if ($sgroup['display'] > -1)

templates/grouplist.tpl

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<table class="outline margin grouplist">
2+
<tr class="header1"><th>Groups</th></tr>
3+
<tr class="cell1">
4+
<td class="center">
5+
{foreach $groups as $g}
6+
{if !($g@first)}
7+
-
8+
{/if}
9+
{$g}
10+
{/foreach}
11+
</td>
12+
</td>
13+
</table>

0 commit comments

Comments
 (0)