1
|
|
|
<?php |
|
|
|
|
2
|
|
|
$userConfig = $this->loadUserConfig(); |
3
|
|
|
$authconfig = $userConfig['authentication']; |
4
|
|
|
|
5
|
|
|
if( !function_exists("grantsArrayToString") ) { |
6
|
|
|
function grantsArrayToString($grants) { |
7
|
|
|
$grantstring = ""; |
8
|
|
|
if (is_array($grants)) { |
9
|
|
|
foreach ($grants as $grant => $granttype) { |
10
|
|
|
if (is_array($granttype)) { |
11
|
|
|
$grantstring .= " $grant ( "; |
12
|
|
|
reset($granttype); |
13
|
|
|
while (list($class, $modifierId)=each($granttype)) { |
14
|
|
View Code Duplication |
if( $granttype > 0 ) { |
15
|
|
|
switch($modifierId) { |
16
|
|
|
case ARGRANTLOCAL: |
17
|
|
|
$modifier = "="; |
18
|
|
|
break; |
19
|
|
|
case ARGRANTCHILDREN: |
20
|
|
|
$modifier = ">"; |
21
|
|
|
break; |
22
|
|
|
default: |
23
|
|
|
$modifier = ""; |
24
|
|
|
} |
25
|
|
|
$grantstring .= " $modifier$class "; |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
$grantstring .= " ) "; |
29
|
|
View Code Duplication |
} elseif( $granttype > 0 ) { |
30
|
|
|
switch($granttype) { |
31
|
|
|
case ARGRANTLOCAL: |
32
|
|
|
$modifier = "="; |
33
|
|
|
break; |
34
|
|
|
case ARGRANTCHILDREN: |
35
|
|
|
$modifier = ">"; |
36
|
|
|
break; |
37
|
|
|
default: |
38
|
|
|
$modifier = ""; |
39
|
|
|
} |
40
|
|
|
$grantstring .= " $modifier$grant "; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
return $grantstring; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if( !function_exists("arGetGrantType") ) { |
49
|
|
|
function arGetGrantType($value) { |
50
|
|
|
if (($value & ARMASKLOCAL) && ($value & ARMASKCHILDREN)) { |
51
|
|
|
$result=""; |
52
|
|
|
} else if ($value & ARMASKLOCAL) { |
53
|
|
|
$result="="; |
54
|
|
|
} else { |
55
|
|
|
$result=">"; |
56
|
|
|
} |
57
|
|
|
return $result; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if( !function_exists("array_compare") ) { |
62
|
|
|
function array_compare(&$ar1, &$ar2) { |
63
|
|
|
if (count($ar1) != count($ar2)) { |
64
|
|
|
return false; |
65
|
|
|
} else { |
66
|
|
|
foreach ($ar1 as $key => $value) { |
67
|
|
|
if (is_array($value) && is_array($ar2[$key])) { |
68
|
|
|
return array_compare($ar1[$key], $ar2[$key]); |
69
|
|
|
} else |
70
|
|
|
if ($value !== $ar2[$key]) { |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
return true; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if( !function_exists("getClass") ) { |
80
|
|
|
function getClass($grey=false) { |
81
|
|
|
global $ARCurrent; |
82
|
|
|
if ($ARCurrent->oddline=($ARCurrent->oddline+1)%2) { |
83
|
|
|
$class='odd'; |
84
|
|
|
} else { |
85
|
|
|
$class='even'; |
86
|
|
|
} |
87
|
|
|
if ($grey) { |
88
|
|
|
$class .= '-grey'; |
89
|
|
|
} |
90
|
|
|
return $class; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if( !function_exists("getPathByType") ) { |
95
|
|
|
function getPathByType($type, $id) { |
96
|
|
|
global $AR; |
97
|
|
|
switch ($type) { |
98
|
|
|
case 'pgroup': |
99
|
|
View Code Duplication |
foreach ($authconfig['groupdirs'] as $groupdir) { |
|
|
|
|
100
|
|
|
$path = current($AR->user->find($groupdir, 'login.value=\''.$id.'\'', 'system.get.path.phtml')); |
101
|
|
|
if ($path) { |
102
|
|
|
break; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
break; |
106
|
|
|
case 'puser': |
107
|
|
View Code Duplication |
foreach ($authconfig['userdirs'] as $userdir) { |
108
|
|
|
$path = current($AR->user->find($userdir, 'login.value=\''.$id.'\'', 'system.get.path.phtml')); |
109
|
|
|
if ($path) { |
110
|
|
|
break; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
break; |
114
|
|
|
} |
115
|
|
|
return $path; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if( !function_exists("removeSimilarGrants") ) { |
120
|
|
|
function removeSimilarGrants($grants) { |
121
|
|
|
// first check for similar grants (same modifiers) |
122
|
|
|
$grants_check = $grants; |
123
|
|
|
foreach ($grants as $grant => $grant_ar) { |
124
|
|
|
// loop $grants for each entry in $grants_check (which is a copy) |
125
|
|
|
array_shift($grants_check); |
126
|
|
|
if (is_array($grant_ar)) { |
127
|
|
|
foreach ($grants_check as $grant_c => $grant_ar_c) { |
128
|
|
|
if (is_array($grant_ar_c) && array_compare($grant_ar, $grant_ar_c)) { |
129
|
|
|
unset($grants[$grant_c]); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
reset($grants); |
135
|
|
|
ksort($grants); |
136
|
|
|
return $grants; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
if( !function_exists("getGrantString") ) { |
141
|
|
|
function getGrantString($id, $type, $grants, $grey) { |
142
|
|
|
if ($grants && is_array($grants)) { |
143
|
|
|
$grants = removeSimilarGrants($grants); |
144
|
|
|
$grant_display = ''; |
145
|
|
|
$grant_string = ''; |
146
|
|
|
|
147
|
|
|
foreach ($grants as $grant => $modifiers) { |
148
|
|
|
if (!is_array($modifiers)) { |
149
|
|
|
$grant_type=arGetGrantType($modifiers); |
150
|
|
|
$grant_display .= htmlspecialchars($grant_type); // echo |
151
|
|
|
} else { |
152
|
|
|
$grant_type=''; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
if (!$grey) { |
156
|
|
|
$grant_display .= "<a href=\"javascript:selectGrant('$type', '$id', '$grant');\">"; |
157
|
|
|
} else { |
158
|
|
|
$grant_display .= "<span class='grey'>"; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
$grant_display .= $grant; |
162
|
|
|
if (is_array($grants_eq[$grant])) { |
|
|
|
|
163
|
|
|
foreach ($grants_eq[$grant] as $g_add) { |
|
|
|
|
164
|
|
|
$grant .= ", ".$grant_type."$g_add"; |
165
|
|
|
} |
166
|
|
|
$grant_display .= "[$grant]"; |
167
|
|
|
$grant_string .= "[$grant]"; |
168
|
|
|
} else { |
169
|
|
|
$grant_string .= "$grant_type$grant "; |
170
|
|
|
} |
171
|
|
|
if (is_array($modifiers)) { |
172
|
|
|
$grant_string .= "( "; |
173
|
|
|
$grant_display .= "( "; |
174
|
|
|
foreach ($modifiers as $modifier => $value) { |
175
|
|
|
$grant_type=arGetGrantType($value); |
176
|
|
|
$grant_display .= htmlspecialchars($grant_type); |
177
|
|
|
$grant_display .= $modifier." "; |
178
|
|
|
$grant_string .= $grant_type.$modifier." "; |
179
|
|
|
} |
180
|
|
|
$grant_display .= ") "; |
181
|
|
|
$grant_string .= ") "; |
182
|
|
|
} |
183
|
|
|
if (!$grey) { |
184
|
|
|
$grant_display .= "</a>"; |
185
|
|
|
} else { |
186
|
|
|
$grant_display .= "</span>"; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
$grant_display .= " "; |
190
|
|
|
$grant_string .= " "; |
191
|
|
|
} |
192
|
|
|
return array($grant_string, $grant_display); |
|
|
|
|
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
if( !function_exists("DisplayGrants") ) { |
197
|
|
|
function DisplayGrants(&$grantslist, $type, $grey=false) { |
198
|
|
|
global $AR, $ARCurrent; |
199
|
|
|
if ($grantslist[$type] && is_array($grantslist[$type])) { |
200
|
|
|
ksort($grantslist[$type]); |
201
|
|
|
while (list($id, $grants)=each($grantslist[$type])) { // path was login en is weer login |
202
|
|
|
$grant_string = ""; |
|
|
|
|
203
|
|
|
if (!$ARCurrent->donelist[$type][$id]) { |
204
|
|
|
$ARCurrent->donelist[$type][$id]=true; |
205
|
|
|
$row_id = "grants-$type-$id"; |
206
|
|
|
$row_class = getClass($grey); |
207
|
|
|
$path = getPathByType($type, $id); |
208
|
|
|
$grant_strings = getGrantString($id, $type, $grants, $grey); |
209
|
|
|
$grant_string = $grant_strings[0]; |
210
|
|
|
$grant_html = $grant_strings[1]; |
211
|
|
|
$icon = $AR->dir->images . "icons/small/" . $type . ".png"; |
212
|
|
|
|
213
|
|
|
?> |
214
|
|
|
<script type="text/javascript"> |
215
|
|
|
id2path['<?php echo $type; ?>']['<?php echo $id; ?>'] = '<?php echo $path; ?>'; |
216
|
|
|
grant_strings['<?php echo $type; ?>']['<?php echo $id; ?>']='<?php echo $grant_string; ?>'; |
217
|
|
|
</script> |
218
|
|
|
<tr class='<?php echo $row_class; ?>' id="<?php echo $row_id; ?>"> |
219
|
|
|
<td> |
220
|
|
|
<img alt="<?php echo $type; ?>" src="<?php echo $icon; ?>"> |
221
|
|
|
</td> |
222
|
|
|
<td> |
223
|
|
|
<a href="javascript:loadUser('<?php echo $type; ?>', '<?php echo $id; ?>');"><?php echo $id; ?></a> |
224
|
|
|
</td> |
225
|
|
|
<td> |
226
|
|
|
<?php echo $grant_html; ?> |
227
|
|
|
</td> |
228
|
|
|
</tr> |
229
|
|
|
<?php |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
?> |
236
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.