KTPermissions.php
23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
<?php
/**
* $Id$
*
* Copyright (c) 2006 Jam Warehouse http://www.jamwarehouse.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; using version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* -------------------------------------------------------------------------
*
* You can contact the copyright owner regarding licensing via the contact
* details that can be found on the KnowledgeTree web site:
*
* http://www.ktdms.com/
*/
require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
require_once(KT_LIB_DIR . '/actions/documentaction.inc.php');
require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
require_once(KT_LIB_DIR . "/foldermanagement/Folder.inc");
require_once(KT_LIB_DIR . "/groups/Group.inc");
require_once(KT_LIB_DIR . "/users/User.inc");
require_once(KT_LIB_DIR . "/roles/Role.inc");
require_once(KT_LIB_DIR . "/roles/roleallocation.inc.php");
require_once(KT_LIB_DIR . "/roles/documentroleallocation.inc.php");
require_once(KT_LIB_DIR . "/permissions/permission.inc.php");
require_once(KT_LIB_DIR . "/permissions/permissionobject.inc.php");
require_once(KT_LIB_DIR . "/permissions/permissionlookup.inc.php");
require_once(KT_LIB_DIR . "/permissions/permissionassignment.inc.php");
require_once(KT_LIB_DIR . "/permissions/permissiondescriptor.inc.php");
require_once(KT_LIB_DIR . "/permissions/permissionutil.inc.php");
class KTDocumentPermissionsAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.permissions';
var $_bAdminAlwaysAvailable = true;
function getDisplayName() {
return _('Permissions');
}
function do_main() {
$this->oPage->setBreadcrumbDetails("Document Permissions");
$oTemplate = $this->oValidator->validateTemplate("ktcore/document/document_permissions");
$oPL = KTPermissionLookup::get($this->oDocument->getPermissionLookupID());
$aPermissions = KTPermission::getList();
$aMapPermissionGroup = array();
$aMapPermissionRole = array();
$aMapPermissionUser = array();
$aAllGroups = Group::getList(); // probably small enough
$aAllRoles = Role::getList(); // probably small enough.
// users are _not_ fetched this way.
$aActiveGroups = array();
$aActiveUsers = array();
$aActiveRoles = array();
foreach ($aPermissions as $oPermission) {
$oPLA = KTPermissionLookupAssignment::getByPermissionAndLookup($oPermission, $oPL);
if (PEAR::isError($oPLA)) {
continue;
}
$oDescriptor = KTPermissionDescriptor::get($oPLA->getPermissionDescriptorID());
$iPermissionID = $oPermission->getID();
$aIDs = $oDescriptor->getGroups();
$aMapPermissionGroup[$iPermissionID] = array();
foreach ($aIDs as $iID) {
$aMapPermissionGroup[$iPermissionID][$iID] = true;
$aActiveGroups[$iID] = true;
}
$aIds = $oDescriptor->getRoles();
$aMapPermissionRole[$iPermissionID] = array();
foreach ($aIds as $iId) {
$aMapPermissionRole[$iPermissionID][$iId] = true;
$aActiveRoles[$iId] = true;
}
$aIds = $oDescriptor->getUsers();
$aMapPermissionUser[$iPermissionID] = array();
foreach ($aIds as $iId) {
$aMapPermissionUser[$iPermissionID][$iId] = true;
$aActiveUsers[$iId] = true;
}
}
// now we constitute the actual sets.
$users = array();
$groups = array();
$roles = array(); // should _always_ be empty, barring a bug in permissions::updatePermissionLookup
// this should be quite limited - direct role -> user assignment is typically rare.
foreach ($aActiveUsers as $id => $marker) {
$oUser = User::get($id);
$users[$oUser->getName()] = $oUser;
}
asort($users); // ascending, per convention.
foreach ($aActiveGroups as $id => $marker) {
$oGroup = Group::get($id);
$groups[$oGroup->getName()] = $oGroup;
}
asort($groups);
foreach ($aActiveRoles as $id => $marker) {
$oRole = Role::get($id);
$roles[$oRole->getName()] = $oRole;
}
asort($roles);
$bEdit = false;
$sInherited = '';
$aTemplateData = array(
"context" => $this,
"permissions" => $aPermissions,
"groups" => $groups,
"users" => $users,
"roles" => $roles,
"iDocumentID" => $_REQUEST['fDocumentID'],
"aMapPermissionGroup" => $aMapPermissionGroup,
"aMapPermissionRole" => $aMapPermissionRole,
"aMapPermissionUser" => $aMapPermissionUser,
"edit" => $bEdit,
"inherited" => $sInherited,
);
return $oTemplate->render($aTemplateData);
}
}
class KTRoleAllocationPlugin extends KTFolderAction {
var $sName = 'ktcore.actions.folder.roles';
var $_sShowPermission = "ktcore.permissions.security";
var $bAutomaticTransaction = true;
var $_bAdminAlwaysAvailable = true;
function getDisplayName() {
return _('Allocate Roles');
}
function do_main() {
$this->oPage->setTitle(_("Allocate Roles"));
$this->oPage->setBreadcrumbDetails(_("Allocate Roles"));
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/folder/roles");
// we need to have:
// - a list of roles
// - with their users / groups
// - and that allocation id
$aRoles = array(); // stores data for display.
$aRoleList = Role::getList();
foreach ($aRoleList as $oRole) {
$iRoleId = $oRole->getId();
$aRoles[$iRoleId] = array("name" => $oRole->getName());
$oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($this->oFolder->getId(), $iRoleId);
$u = array();
$g = array();
$aid = null;
$raid = null;
if ($oRoleAllocation == null) {
; // nothing.
} else {
$raid = $oRoleAllocation->getId(); // real_alloc_id
if ($oRoleAllocation->getFolderId() == $this->oFolder->getId()) {
$aid = $oRoleAllocation->getid(); // alloc_id
}
$oPermDesc = KTPermissionDescriptor::get($oRoleAllocation->getPermissionDescriptorId());
if (!PEAR::isError($oPermDesc)) {
$aAllowed = $oPermDesc->getAllowed();
if (!empty($aAllowed['user'])) {
$u = $aAllowed['user'];
}
if (!empty($aAllowed['group'])) {
$g = $aAllowed['group'];
}
}
}
$aRoles[$iRoleId]['users'] = $u;
$aRoles[$iRoleId]['groups'] = $g;
$aRoles[$iRoleId]['allocation_id'] = $aid;
$aRoles[$iRoleId]['real_allocation_id'] = $raid;
}
/*
print '<pre>';
var_dump($aRoles);
print '</pre>';
*/
// FIXME this is test data.
/*
$aRoles = array(
1 => array('name' => 'Manager', 'users' => array(1), 'groups' => array(1), 'allocation_id' => 1),
2 => array('name' => 'Peasant', 'users' => array(1), 'groups' => array(), 'allocation_id' => 2),
3 => array('name' => 'Inherited', 'users' => array(), 'groups' => array(1), 'allocation_id' => null),
);
*/
// final step.
// map to users, groups.
foreach ($aRoles as $key => $role) {
/*
$_users = array();
foreach ($aRoles[$key]['users'] as $iUserId) {
$oUser = User::get($iUserId);
if (!(PEAR::isError($oUser) || ($oUser == false))) {
$_users[] = $oUser->getName();
}
}
if (empty($_users)) {
$aRoles[$key]['users'] = '<span class="descriptiveText"> ' . _('no users') . '</span>';
} else {
$aRoles[$key]['users'] = join(', ',$_users);
}
*/
$_groups = array();
foreach ($aRoles[$key]['groups'] as $iGroupId) {
$oGroup = Group::get($iGroupId);
if (!(PEAR::isError($oGroup) || ($oGroup == false))) {
$_groups[] = $oGroup->getName();
}
}
if (empty($_groups)) {
$aRoles[$key]['groups'] = '<span class="descriptiveText"> ' . _('no groups') . '</span>';
} else {
$aRoles[$key]['groups'] = join(', ',$_groups);
}
}
$aTemplateData = array(
'context' => &$this,
'roles' => $aRoles,
);
return $oTemplate->render($aTemplateData);
}
function do_overrideParent() {
$role_id = KTUtil::arrayGet($_REQUEST, 'role_id', null);
$oRole = Role::get($role_id);
if (PEAR::isError($oRole)) {
$this->errorRedirectToMain(_('Invalid Role.'));
}
// FIXME do we need to check that this role _isn't_ allocated?
$oRoleAllocation = new RoleAllocation();
$oRoleAllocation->setFolderId($this->oFolder->getId());
$oRoleAllocation->setRoleId($role_id);
// create a new permission descriptor.
// FIXME we really want to duplicate the original (if it exists)
$aAllowed = array(); // no-op, for now.
$this->startTransaction();
$oRoleAllocation->setAllowed($aAllowed);
$res = $oRoleAllocation->create();
if (PEAR::isError($res) || ($res == false)) {
$this->errorRedirectToMain(_('Failed to create the role allocation.') . print_r($res, true), sprintf('fFolderId=%d', $this->oFolder->getId()));
}
$this->renegeratePermissionsForRole($oRoleAllocation->getRoleId());
$this->successRedirectToMain(_('Role allocation created.'), sprintf('fFolderId=%d', $this->oFolder->getId()));
}
function do_useParent() {
$role_id = KTUtil::arrayGet($_REQUEST, 'role_id', null);
$oRole = Role::get($role_id);
if (PEAR::isError($oRole)) {
$this->errorRedirectToMain(_('Invalid Role.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
$role_id = $oRole->getId(); // numeric, for various testing purposes.
$oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($this->oFolder->getId(), $role_id);
if ($oRoleAllocation->getFolderId() != $this->oFolder->getId()) {
$this->errorRedirectToMain(_('Already using a different descriptor.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
$this->startTransaction();
$res = $oRoleAllocation->delete();
if (PEAR::isError($res) || ($res == false)) {
$this->errorRedirectToMain(_('Unable to change role allocation.') . print_r($res, true), sprintf('fFolderId=%d',$this->oFolder->getId()));
exit(0);
}
$this->renegeratePermissionsForRole($oRoleAllocation->getRoleId());
$this->successRedirectToMain(_('Role now uses parent.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
function do_editRoleUsers() {
$role_allocation_id = KTUtil::arrayGet($_REQUEST, 'alloc_id');
$oRoleAllocation = RoleAllocation::get($role_allocation_id);
if ((PEAR::isError($oRoleAllocation)) || ($oRoleAllocation=== false)) {
$this->errorRedirectToMain(_('No such role allocation.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
$this->oPage->setBreadcrumbDetails(_('Manage Users for Role'));
$this->oPage->setTitle(sprintf(_('Manage Users for Role')));
$initJS = 'var optGroup = new OptionTransfer("userSelect","chosenUsers"); ' .
'function startTrans() { var f = getElement("userroleform"); ' .
' optGroup.saveNewRightOptions("userFinal"); ' .
' optGroup.init(f); }; ' .
' addLoadEvent(startTrans); ';
$this->oPage->requireJSStandalone($initJS);
$aInitialUsers = $oRoleAllocation->getUsers();
$aAllUsers = User::getList();
// FIXME this is massively non-performant for large userbases..
$aRoleUsers = array();
$aFreeUsers = array();
foreach ($aInitialUsers as $oUser) {
$aRoleUsers[$oUser->getId()] = $oUser;
}
foreach ($aAllUsers as $oUser) {
if (!array_key_exists($oUser->getId(), $aRoleUsers)) {
$aFreeUsers[$oUser->getId()] = $oUser;
}
}
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/folder/roles_manageusers");
$aTemplateData = array(
"context" => $this,
"edit_rolealloc" => $oRoleAllocation,
'unused_users' => $aFreeUsers,
'role_users' => $aRoleUsers,
);
return $oTemplate->render($aTemplateData);
}
function do_editRoleGroups() {
$role_allocation_id = KTUtil::arrayGet($_REQUEST, 'alloc_id');
$oRoleAllocation = RoleAllocation::get($role_allocation_id);
if ((PEAR::isError($oRoleAllocation)) || ($oRoleAllocation=== false)) {
$this->errorRedirectToMain(_('No such role allocation.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
$this->oPage->setBreadcrumbDetails(_('Manage Groups for Role'));
$this->oPage->setTitle(sprintf(_('Manage Groups for Role')));
$initJS = 'var optGroup = new OptionTransfer("groupSelect","chosenGroups"); ' .
'function startTrans() { var f = getElement("grouproleform"); ' .
' optGroup.saveNewRightOptions("groupFinal"); ' .
' optGroup.init(f); }; ' .
' addLoadEvent(startTrans); ';
$this->oPage->requireJSStandalone($initJS);
$aInitialUsers = $oRoleAllocation->getGroups();
$aAllUsers = Group::getList();
// FIXME this is massively non-performant for large userbases..
$aRoleUsers = array();
$aFreeUsers = array();
foreach ($aInitialUsers as $oGroup) {
$aRoleUsers[$oGroup->getId()] = $oGroup;
}
foreach ($aAllUsers as $oGroup) {
if (!array_key_exists($oGroup->getId(), $aRoleUsers)) {
$aFreeUsers[$oGroup->getId()] = $oGroup;
}
}
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/folder/roles_managegroups");
$aTemplateData = array(
"context" => $this,
"edit_rolealloc" => $oRoleAllocation,
'unused_groups' => $aFreeUsers,
'role_groups' => $aRoleUsers,
);
return $oTemplate->render($aTemplateData);
}
function do_setRoleUsers() {
$role_allocation_id = KTUtil::arrayGet($_REQUEST, 'allocation_id');
$oRoleAllocation = RoleAllocation::get($role_allocation_id);
if ((PEAR::isError($oRoleAllocation)) || ($oRoleAllocation=== false)) {
$this->errorRedirectToMain(_('No such role allocation.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
$users = KTUtil::arrayGet($_REQUEST, 'userFinal', '');
$aUserIds = explode(',', $users);
// check that its not corrupt..
$aFinalUserIds = array();
foreach ($aUserIds as $iUserId) {
$oUser =& User::get($iUserId);
if (!(PEAR::isError($oUser) || ($oUser == false))) {
$aFinalUserIds[] = $iUserId;
}
}
if (empty($aFinalUserIds)) { $aFinalUserIds = null; }
// hack straight in.
$oPD = $oRoleAllocation->getPermissionDescriptor();
$aAllowed = $oPD->getAllowed();
// now, grab the existing allowed and modify.
$aAllowed['user'] = $aFinalUserIds;
$oRoleAllocation->setAllowed($aAllowed);
$res = $oRoleAllocation->update();
if (PEAR::isError($res) || ($res == false)) {
$this->errorRedirectToMain(_('Failed to change the role allocation.') . print_r($res, true), sprintf('fFolderId=%d', $this->oFolder->getId()));
}
$this->renegeratePermissionsForRole($oRoleAllocation->getRoleId());
$this->successRedirectToMain(_('Allocation changed.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
function do_setRoleGroups() {
$role_allocation_id = KTUtil::arrayGet($_REQUEST, 'allocation_id');
$oRoleAllocation = RoleAllocation::get($role_allocation_id);
if ((PEAR::isError($oRoleAllocation)) || ($oRoleAllocation=== false)) {
$this->errorRedirectToMain(_('No such role allocation.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
$groups = KTUtil::arrayGet($_REQUEST, 'groupFinal', '');
$aGroupIds = explode(',', $groups);
// check that its not corrupt..
$aFinalGroupIds = array();
foreach ($aGroupIds as $iGroupId) {
$oGroup =& Group::get($iGroupId);
if (!(PEAR::isError($oGroup) || ($oGroup == false))) {
$aFinalGroupIds[] = $iGroupId;
}
}
if (empty($aFinalGroupIds)) { $aFinalGroupIds = null; }
// hack straight in.
$oPD = $oRoleAllocation->getPermissionDescriptor();
$aAllowed = $oPD->getAllowed();
// now, grab the existing allowed and modify.
$aAllowed['group'] = $aFinalGroupIds;
$oRoleAllocation->setAllowed($aAllowed);
$res = $oRoleAllocation->update();
if (PEAR::isError($res) || ($res == false)) {
$this->errorRedirectToMain(_('Failed to change the role allocation.') . print_r($res, true), sprintf('fFolderId=%d', $this->oFolder->getId()));
}
$this->renegeratePermissionsForRole($oRoleAllocation->getRoleId());
$this->successRedirectToMain(_('Allocation changed.'), sprintf('fFolderId=%d',$this->oFolder->getId()));
}
function renegeratePermissionsForRole($iRoleId) {
$iStartFolderId = $this->oFolder->getId();
/*
* 1. find all folders & documents "below" this one which use the role
* definition _active_ (not necessarily present) at this point.
* 2. tell permissionutil to regen their permissions.
*
* The find algorithm is:
*
* folder_queue <- (iStartFolderId)
* while folder_queue is not empty:
* active_folder =
* for each folder in the active_folder:
* find folders in _this_ folder without a role-allocation on the iRoleId
* add them to the folder_queue
* update the folder's permissions.
* find documents in this folder:
* update their permissions.
*/
$sRoleAllocTable = KTUtil::getTableName('role_allocations');
$sFolderTable = KTUtil::getTableName('folders');
$sQuery = sprintf('SELECT f.id as id FROM %s AS f LEFT JOIN %s AS ra ON (f.id = ra.folder_id) WHERE ra.id IS NULL AND f.parent_id = ?', $sFolderTable, $sRoleAllocTable);
$folder_queue = array($iStartFolderId);
while (!empty($folder_queue)) {
$active_folder = array_pop($folder_queue);
$aParams = array($active_folder);
$aNewFolders = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id');
if (PEAR::isError($aNewFolders)) {
$this->errorRedirectToMain(_('Failure to generate folderlisting.'));
}
$folder_queue = array_merge ($folder_queue, (array) $aNewFolders); // push.
// update the folder.
$oFolder =& Folder::get($active_folder);
if (PEAR::isError($oFolder) || ($oFolder == false)) {
$this->errorRedirectToMain(_('Unable to locate folder: ') . $active_folder);
}
KTPermissionUtil::updatePermissionLookup($oFolder);
$aDocList =& Document::getList(array('folder_id = ?', $active_folder));
if (PEAR::isError($aDocList) || ($aDocList === false)) {
$this->errorRedirectToMain(sprintf(_('Unable to get documents in folder %s: %s'), $active_folder, $aDocList->getMessage()));
}
foreach ($aDocList as $oDoc) {
KTPermissionUtil::updatePermissionLookup($oDoc);
}
}
}
}
class KTDocumentRolesAction extends KTDocumentAction {
var $sDisplayName = 'View Roles';
var $sName = 'ktcore.actions.document.roles';
var $_sShowPermission = "ktcore.permissions.write";
var $bAutomaticTransaction = true;
function do_main() {
$this->oPage->setTitle(_("View Roles"));
$this->oPage->setBreadcrumbDetails(_("View Roles"));
$oTemplating = new KTTemplating;
$oTemplate = $oTemplating->loadTemplate("ktcore/action/view_roles");
// we need to have:
// - a list of roles
// - with their users / groups
// - and that allocation id
$aRoles = array(); // stores data for display.
$aRoleList = Role::getList();
foreach ($aRoleList as $oRole) {
$iRoleId = $oRole->getId();
$aRoles[$iRoleId] = array("name" => $oRole->getName());
$oRoleAllocation = DocumentRoleAllocation::getAllocationsForDocumentAndRole($this->oDocument->getId(), $iRoleId);
if (is_null($oRoleAllocation)) {
$oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($this->oDocument->getFolderID(), $iRoleId);
}
$u = array();
$g = array();
$aid = null;
$raid = null;
if (is_null($oRoleAllocation)) {
; // nothing.
} else {
//var_dump($oRoleAllocation);
$raid = $oRoleAllocation->getId(); // real_alloc_id
$aAllowed = $oRoleAllocation->getAllowed();
if (!empty($aAllowed['user'])) {
$u = $aAllowed['user'];
}
if (!empty($aAllowed['group'])) {
$g = $aAllowed['group'];
}
}
$aRoles[$iRoleId]['users'] = $u;
$aRoles[$iRoleId]['groups'] = $g;
$aRoles[$iRoleId]['real_allocation_id'] = $raid;
}
// final step.
// map to users, groups.
foreach ($aRoles as $key => $role) {
$_users = array();
foreach ($aRoles[$key]['users'] as $iUserId) {
$oUser = User::get($iUserId);
if (!(PEAR::isError($oUser) || ($oUser == false))) {
$_users[] = $oUser->getName();
}
}
if (empty($_users)) {
$aRoles[$key]['users'] = '<span class="descriptiveText"> ' . _('no users') . '</span>';
} else {
$aRoles[$key]['users'] = implode(', ',$_users);
}
$_groups = array();
foreach ($aRoles[$key]['groups'] as $iGroupId) {
$oGroup = Group::get($iGroupId);
if (!(PEAR::isError($oGroup) || ($oGroup == false))) {
$_groups[] = $oGroup->getName();
}
}
if (empty($_groups)) {
$aRoles[$key]['groups'] = '<span class="descriptiveText"> ' . _('no groups') . '</span>';
} else {
$aRoles[$key]['groups'] = implode(', ',$_groups);
}
}
$aTemplateData = array(
'context' => &$this,
'roles' => $aRoles,
);
return $oTemplate->render($aTemplateData);
}
}