CMS  Version 3.9
permissions_checker.inc
Go to the documentation of this file.
1 <?php
2 Fakoli::using("developer_tools", "section");
3 Fakoli::usingFeature("grouped_data_view");
4 
5 $page_title = "Permission Map";
6 $menu_item = "Permission Map";
7 
8 $styles .= <<<ENDSTYLES
9 
10 <style>
11  tr.yay { background-color: #eeffee }
12  tr.nay { background-color: #ffeeee }
13 </style>
14 
15 ENDSTYLES;
16 
17 $site_id = checkNumeric($_GET["site_id"]);
18 
19 $sites = query(Site, "ORDER BY site_name");
20 
21 if (!$site_id) $site_id = $sites[0]->site_id;
22 
24 $userClass = $userMgr->getUserClass();
26 
27 $userPK = $subject->getPrimaryKey();
28 $user_id = checkNumeric($_GET[$userPK]);
29 $usernameField = $userMgr->getUsernameField();
30 
31 if (!$user_id) $user_id = $user->getPrimaryKeyValue();
32 
33 $subject->load($user_id);
34 
35 $tabs = new DataItemTabBar("tabs", $sites);
36 
37 $permissions = Query::create(Settings, "WHERE options='Permissions' ORDER BY component")->execute();
38 
39 $userPermissions = array();
40 foreach($permissions as $p)
41 {
42  if (Settings::checkPermission($p->component, $p->name, $subject))
43  {
44  $userPermissions[] = $p;
45  }
46 }
47 
48 $permissionsList = formatItems($userPermissions, "{component}:{name}", ", ");
49 
50 $sectionContent = GroupedQuery::create(SectionContent, "WHERE section_id IN (SELECT section_id FROM section WHERE site_id=:s) ORDER BY identifier", "section_id")
51  ->bind(":s", $site_id)
52  ->execute();
53 
54 $sections = Query::create(Section, "WHERE site_id=:s")
55  ->bind(":s", $site_id)
56  ->execute();
57 
59 
60 $table = new GroupedDataListView($sectionContent, "content_by_section");
61 $table->column("Identifier", "<strong>{identifier}</strong>", true, "width: 20%")
62  ->column("Roles", "{role:/,/, /}", true, "width: 30%")
63  ->column("Permissions", "{permissions:/,/, /}", true, "width:30%")
64  ->column("User Can Access?", array($helper, formatAccess), true, "text-align: center");
65 
66 $table->groupBy($sections, "{section}", "section_id");
67 
68 $table->mode = "tree";
69 $table->groupAsWorksheets = false;
70 $table->filter = true;
71 $table->sortable = true;
72 $table->excelFile = codify($config['sitename']."_permissions_{$subject->username}").".xls";
73 $table->onStartRow = array($helper, onStartRow);
74 
75 $script .= $table->writeScript();
76 
77 $tabs->writeHTML();
78 ?>
79 <div class='tab_border'>
80 <?
81 $users = Query::create($userClass, "ORDER BY {$usernameField}")->execute();
82 
83 echo "<p><label for='{$userPK}'>User:</label> <select name='{$userPK}' onchange=\"go('?{$userPK}=' + this.value);\">\n";
84 
85 foreach($users as $u)
86 {
87  option($u->getPrimaryKeyValue(),
88  $u->get($usernameField)." (".$userMgr->getUserFullName($u).")",
89  $subject->getPrimaryKeyValue());
90 }
91 
92 echo "</select></p>\n";
93 echo "<p><label>Roles:</label> {$subject->role}</p>\n";
94 echo "<p><label>Permissions:</label> {$permissionsList}</p>\n";
95 
96 $table->drawView();
97 ?>
98 </div>
$helpTree style
Definition: tree.inc:46
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
Section DataItem, defining the data model for sections within a site.
Definition: section.inc:45
The Settings class provides components with a common API for specifying application settings and conf...
Definition: settings.inc:49
static checkPermission($component, $name, $account=null)
Check whether a user has a specific permission.
Definition: settings.inc:241
Definition: site.inc:40
Provides the interface to the user model for the application.
global $user
background color
global $config
Definition: import.inc:4
foreach($permissions as $p) $permissionsList
$table onStartRow
$userPermissions