|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Page |
|
4
|
|
|
* |
|
5
|
|
|
* @author Sune Jensen <[email protected]> |
|
6
|
|
|
* @author Lars Olesen <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
class Intraface_Page |
|
10
|
|
|
{ |
|
11
|
|
|
public $kernel; |
|
12
|
|
|
public $db; |
|
13
|
|
|
public $theme; |
|
14
|
|
|
public $usermenu; |
|
15
|
|
|
public $submenu; |
|
16
|
|
|
public $menu; |
|
17
|
|
|
public $javascript_path = array(); |
|
18
|
|
|
public $primary_module; |
|
19
|
|
|
|
|
20
|
|
|
function __construct(Intraface_Kernel $object_kernel, MDB2_Driver_Common $db = null) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->kernel = $object_kernel; |
|
23
|
|
|
if ($this->db == null) { |
|
24
|
|
|
$this->db = MDB2::singleton(DB_DSN); |
|
25
|
|
|
} else { |
|
26
|
|
|
$this->db = $db; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function start($title = '') |
|
31
|
|
|
{ |
|
32
|
|
|
$this->primary_module = $this->kernel->getPrimaryModule(); |
|
33
|
|
|
$name = ''; |
|
|
|
|
|
|
34
|
|
|
if (is_object($this->primary_module)) { |
|
35
|
|
|
$name = $this->primary_module->getName(); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/* |
|
|
|
|
|
|
39
|
|
|
// brugermenuen |
|
40
|
|
|
// Unforntunately the usermenuen has to be before the cache as it is printed in bottom.php. |
|
41
|
|
|
$this->usermenu = array(); |
|
42
|
|
|
$this->usermenu[0]['name'] = $this->t('logout', 'common'); |
|
43
|
|
|
$this->usermenu[0]['url'] = url('/core/logout'); |
|
44
|
|
|
if (method_exists('getIntranetList', $this->kernel->user)) { |
|
45
|
|
|
if (count($this->kernel->user->getIntranetList()) > 1) { |
|
46
|
|
|
$this->usermenu[1]['name'] = $this->t('change intranet', 'common'); |
|
47
|
|
|
$this->usermenu[1]['url'] = url('/main/change_intranet.php'); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
$this->usermenu[2]['name'] = $this->t('control panel', 'common');; |
|
51
|
|
|
$this->usermenu[2]['url'] = url('/core/restricted/module/controlpanel/'); |
|
52
|
|
|
*/ |
|
53
|
|
|
/* |
|
|
|
|
|
|
54
|
|
|
if (!is_dir(PATH_CACHE)) { |
|
55
|
|
|
if (!mkdir(PATH_CACHE)) { |
|
56
|
|
|
throw new Exception('Unable to create dir "'.PATH_CACHE.'" from constant PATH_CACHE'); |
|
57
|
|
|
exit; |
|
58
|
|
|
} |
|
59
|
|
|
chmod(PATH_CACHE, 644); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$options = array( |
|
63
|
|
|
'cacheDir' => PATH_CACHE, |
|
64
|
|
|
'lifeTime' => 3600 |
|
65
|
|
|
); |
|
66
|
|
|
$cache = new Cache_Lite_Output($options); |
|
67
|
|
|
|
|
68
|
|
|
// unfortunately cache has to be deactivated (true or) as there is problems with titel and javascript. solution: only caching of menu and nothing else. |
|
69
|
|
|
// If you activate again remeber to activate $cache->end() in the end of this method |
|
70
|
|
|
if (true or defined('USE_CACHE') AND !USE_CACHE OR !($cache->start('page_' . $this->kernel->user->get('id') . '_' . $name))) { |
|
71
|
|
|
if (!is_object($this->kernel->translation)) $this->kernel->getTranslation(); |
|
72
|
|
|
*/ |
|
73
|
|
|
$intranet_name = $this->kernel->intranet->get('name'); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
if (empty($title)) { |
|
76
|
|
|
$title = $intranet_name; |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// temaet |
|
80
|
|
|
$themes = self::themes(); |
|
|
|
|
|
|
81
|
|
|
$this->theme_key = $this->kernel->setting->get('user', 'theme'); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
// fontsize |
|
84
|
|
|
$this->fontsize = $this->kernel->setting->get('user', 'ptextsize'); |
|
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
// menuen |
|
88
|
|
|
$this->menu = array(); |
|
89
|
|
|
$i = 0; |
|
90
|
|
|
$this->menu[$i]['name'] = $this->t('dashboard', 'dashboard'); |
|
91
|
|
|
; |
|
92
|
|
|
$this->menu[$i]['url'] = url('/core/restricted/'); |
|
93
|
|
|
$i++; |
|
94
|
|
|
$res = $this->db->query("SELECT name, menu_label, name FROM module WHERE active = 1 AND show_menu = 1 ORDER BY menu_index"); |
|
95
|
|
|
foreach ($res->fetchAll() as $row) { |
|
96
|
|
|
if ($this->kernel->user->hasModuleAccess($row['name'])) { |
|
|
|
|
|
|
97
|
|
|
$this->menu[$i]['name'] = $this->t($row['name'], $row['name']); |
|
98
|
|
|
$this->menu[$i]['url'] = url('/core/restricted/module/' . $row["name"]); |
|
99
|
|
|
$i++; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$submenu = array(); |
|
|
|
|
|
|
104
|
|
|
if (is_object($this->primary_module)) { |
|
105
|
|
|
$all_submenu = $this->primary_module->getSubmenu(); |
|
106
|
|
|
if (count($all_submenu) > 0) { // added to avoid error messages |
|
107
|
|
|
$j = 0; |
|
108
|
|
|
for ($i = 0, $max = count($all_submenu); $i < $max; $i++) { |
|
109
|
|
|
$access = false; |
|
110
|
|
|
|
|
111
|
|
View Code Duplication |
if ($all_submenu[$i]['sub_access'] != '') { |
|
112
|
|
|
$sub = explode(":", $all_submenu[$i]['sub_access']); |
|
113
|
|
|
|
|
114
|
|
|
switch ($sub[0]) { |
|
115
|
|
|
case 'sub_access': |
|
116
|
|
|
if ($this->kernel->user->hasSubAccess($this->primary_module->module_name, $sub[1])) { |
|
|
|
|
|
|
117
|
|
|
$access = true; |
|
118
|
|
|
} |
|
119
|
|
|
break; |
|
120
|
|
|
|
|
121
|
|
|
case 'module': |
|
122
|
|
|
if ($this->kernel->user->hasModuleAccess($sub[1])) { |
|
|
|
|
|
|
123
|
|
|
$access = true; |
|
124
|
|
|
} |
|
125
|
|
|
break; |
|
126
|
|
|
|
|
127
|
|
|
default: |
|
128
|
|
|
throw new Exception('Der er ikke angivet om submenu skal tjekke efter sub_access eller module adgang, for undermenupunktet i Page->start();'); |
|
129
|
|
|
break; |
|
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
} else { |
|
132
|
|
|
$access = true; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
View Code Duplication |
if ($access) { |
|
136
|
|
|
$this->submenu[$j]['name'] = $this->t($all_submenu[$i]['label'], $this->primary_module->getName()); |
|
137
|
|
|
$this->submenu[$j]['url'] = $this->primary_module->getPath(). $all_submenu[$i]['url']; |
|
138
|
|
|
$j++; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
$javascript = ''; |
|
145
|
|
|
if (!empty($this->javascript_path) and count($this->javascript_path) > 0) { |
|
|
|
|
|
|
146
|
|
|
for ($i = 0, $max = count($this->javascript_path); $i < $max; $i++) { |
|
147
|
|
|
$javascript .= '<script type="text/javascript" src="'.$this->javascript_path[$i].'"></script>' . "\n"; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
/* |
|
|
|
|
|
|
151
|
|
|
$systemdisturbance = new SystemDisturbance($this->kernel); |
|
152
|
|
|
$now = $systemdisturbance->getActual(); |
|
153
|
|
|
|
|
154
|
|
|
if (!empty($now) AND count($now) > 0 && $now['important'] == 1) { |
|
155
|
|
|
$system_message = $now['description']; |
|
156
|
|
|
} |
|
157
|
|
|
*/ |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
//header('Vary: Accept'); |
|
161
|
|
|
// setting headers to prevent browser to cache page |
|
162
|
|
|
// jf. http://dk.php.net/header/ |
|
163
|
|
|
|
|
164
|
|
|
//header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past |
|
|
|
|
|
|
165
|
|
|
//header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified |
|
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
// HTTP/1.1 |
|
168
|
|
|
//header('Cache-Control: no-store, no-cache, must-revalidate'); |
|
169
|
|
|
//header('Cache-Control: post-check=0, pre-check=0', false); |
|
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
// HTTP/1.0 |
|
172
|
|
|
//header('Pragma: no-cache'); |
|
173
|
|
|
|
|
174
|
|
|
/* |
|
|
|
|
|
|
175
|
|
|
if (defined('OB_START') AND OB_START == 'use') { |
|
176
|
|
|
ob_start(); // OB_HANDLER |
|
177
|
|
|
} |
|
178
|
|
|
*/ |
|
179
|
|
|
|
|
180
|
|
|
//contentNegotiation(CONTENTNEGOTIATION); |
|
181
|
|
|
|
|
182
|
|
|
//include(PATH_INCLUDE_IHTML.'/intraface/top.php'); |
|
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
// $cache->end(); |
|
|
|
|
|
|
185
|
|
|
//} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
function end() |
|
189
|
|
|
{ |
|
190
|
|
|
$this->usermenu = array(); |
|
191
|
|
|
$this->usermenu[0]['name'] = $this->t('logout', 'common'); |
|
192
|
|
|
$this->usermenu[0]['url'] = url('/core/logout'); |
|
193
|
|
|
|
|
194
|
|
|
if (method_exists($this->kernel->user, 'getIntranetList')) { |
|
195
|
|
View Code Duplication |
if (count($this->kernel->user->getIntranetList()) > 1) { |
|
|
|
|
|
|
196
|
|
|
$this->usermenu[1]['name'] = $this->t('change intranet', 'common'); |
|
197
|
|
|
$this->usermenu[1]['url'] = url('/core/restricted/switchintranet'); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
$this->usermenu[2]['name'] = $this->t('control panel', 'common'); |
|
201
|
|
|
; |
|
202
|
|
|
$this->usermenu[2]['url'] = url('/core/restricted/module/controlpanel'); |
|
203
|
|
|
|
|
204
|
|
|
//include(PATH_INCLUDE_IHTML.'/intraface/bottom.php'); |
|
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
function includeJavascript($scope, $filename) |
|
208
|
|
|
{ |
|
209
|
|
|
if (!in_array($scope, array('global', 'module'), true)) { |
|
210
|
|
|
throw new Exception("F�rste parameter er ikke enten 'global' eller 'module' i Page->includeJavascript"); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
if ($scope == 'global') { |
|
214
|
|
|
$this->javascript_path[] = url('/javascript/'.$filename); |
|
215
|
|
|
} else { |
|
216
|
|
|
$this->javascript_path[] = 'javascript/'.$filename; |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
function addJavascript($url) |
|
221
|
|
|
{ |
|
222
|
|
|
$this->javascript_path[] = $url; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
public static function themes() |
|
226
|
|
|
{ |
|
227
|
|
|
return array( |
|
228
|
|
|
1 => array( |
|
229
|
|
|
'label' => 'system', |
|
230
|
|
|
'dir' => '/system/', |
|
231
|
|
|
'name' => 'Web 2.0', |
|
232
|
|
|
'description' => 'Spr�lsk, vildt og pastel.' |
|
233
|
|
|
), |
|
234
|
|
|
2 => array( |
|
235
|
|
|
'label' => 'newsystem', |
|
236
|
|
|
'dir' => '/newsystem/', |
|
237
|
|
|
'name' => 'Standard', |
|
238
|
|
|
'description' => 'Standard.' |
|
239
|
|
|
), |
|
240
|
|
|
3 => array( |
|
241
|
|
|
'label' => 'black', |
|
242
|
|
|
'dir' => '/black/', |
|
243
|
|
|
'name' => 'Den sorte ridder', |
|
244
|
|
|
'description' => 'Det gamle tema. Nydeligt og kedeligt.' |
|
245
|
|
|
) |
|
246
|
|
|
); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
function t($phrase, $page_id = null) |
|
250
|
|
|
{ |
|
251
|
|
|
return $this->kernel->translation->get($phrase, $page_id); |
|
252
|
|
|
} |
|
253
|
|
|
} |
|
254
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.