/
phpgen_admin.php
122 lines (96 loc) · 3.81 KB
/
phpgen_admin.php
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
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ATTENTION!
* If you see this message in your browser (Internet Explorer, Mozilla Firefox, Google Chrome, etc.)
* this means that PHP is not properly installed on your web server. Please refer to the PHP manual
* for more details: http://php.net/manual/install.php
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
include_once dirname(__FILE__) . '/' . 'authorization.php';
include_once dirname(__FILE__) . '/' . 'components/application.php';
include_once dirname(__FILE__) . '/' . 'components/error_utils.php';
include_once dirname(__FILE__) . '/' . 'components/utils/system_utils.php';
include_once dirname(__FILE__) . '/' . 'components/utils/string_utils.php';
include_once dirname(__FILE__) . '/' . 'components/security/base_user_auth.php';
include_once dirname(__FILE__) . '/' . 'components/security/table_based_user_grants_manager.php';
SetUpUserAuthorization();
class AdminPage extends CommonPage
{
/** @var TableBasedUserGrantsManager */
private $tableBasedGrantsManager;
public function __construct($tableBasedGrantsManager)
{
parent::__construct($this->GetCaption(), 'UTF-8');
$this->tableBasedGrantsManager = $tableBasedGrantsManager;
$this->OnGetCustomTemplate = new Event();
}
public function GetAllUsersAsJson()
{
return $this->tableBasedGrantsManager->GetAllUsersAsJson();
}
public function GetAuthenticationViewData() {
return array(
'Enabled' => true,
'LoggedIn' => GetApplication()->IsCurrentUserLoggedIn(),
'CurrentUser' => array(
'Name' => GetApplication()->GetCurrentUser(),
'Id' => GetApplication()->GetCurrentUserId(),
),
'isAdminPanelVisible' => HasAdminPage() && GetApplication()->HasAdminGrantForCurrentUser(),
);
}
public function GetReadyPageList()
{
return PageList::createForPage($this);
}
public function Accept(Renderer $renderer)
{
$renderer->RenderAdminPage($this);
}
private function GetCurrentPageMode() {
switch (GetApplication()->GetOperation()) {
case OPERATION_VIEWALL:
return PageMode::ViewAll;
}
return null;
}
public function GetCustomTemplate($part, $mode, $defaultValue, &$params = null) {
$result = null;
if (!$mode) // for PageList
$mode = $this->GetCurrentPageMode();
if (!$params)
$params = array();
$this->OnGetCustomTemplate->Fire(array($part, $mode, &$result, &$params, $this));
if ($result)
return Path::Combine('custom_templates', $result);
else
return $defaultValue;
}
public function GetShowPageList()
{
return true;
}
public function GetShortCaption()
{
return $this->GetCaption();
}
public function GetCaption()
{
return $this->GetLocalizerCaptions()->GetMessageString('AdminPage');
}
public function GetPageFileName() {
return basename(__FILE__);
}
}
$tableBasedGrants = CreateTableBasedGrantsManager();
$page = new AdminPage($tableBasedGrants);
$page->setHeader(GetPagesHeader());
$page->setFooter(GetPagesFooter());
$page->OnGetCustomTemplate->AddListener('Global_GetCustomTemplateHandler');
if (!GetApplication()->GetUserAuthorizationStrategy()->HasAdminGrant(GetApplication()->GetCurrentUser()))
{
RaiseSecurityError($page, 'You do not have permission to access this page.');
}
$renderer = new ViewRenderer($page->GetLocalizerCaptions());
echo $renderer->Render($page);