1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category backend
|
5
|
* @package framework
|
6
|
* @author Ryan Djurovich (2004-2009), WebsiteBaker Project
|
7
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8
|
* @link http://www.websitebaker2.org/
|
9
|
* @license http://www.gnu.org/licenses/gpl.html
|
10
|
* @platform WebsiteBaker 2.8.x
|
11
|
* @requirements PHP 5.2.2 and higher
|
12
|
* @version $Id: class.admin.php 1808 2012-11-07 11:05:52Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.admin.php $
|
14
|
* @lastmodified $Date: 2012-11-07 12:05:52 +0100 (Wed, 07 Nov 2012) $
|
15
|
*
|
16
|
*/
|
17
|
/* -------------------------------------------------------- */
|
18
|
// Must include code to stop this file being accessed directly
|
19
|
if(!defined('WB_PATH')) {
|
20
|
require_once(dirname(__FILE__).'/globalExceptionHandler.php');
|
21
|
throw new IllegalFileException();
|
22
|
}
|
23
|
/* -------------------------------------------------------- */
|
24
|
|
25
|
// Load the other required class files if they are not already loaded
|
26
|
if(!class_exists('wb', false)){ include(WB_PATH.'/framework/class.wb.php'); }
|
27
|
|
28
|
// Get WB version
|
29
|
require_once(ADMIN_PATH.'/interface/version.php');
|
30
|
|
31
|
// Include EditArea wrapper functions
|
32
|
// require_once(WB_PATH . '/include/editarea/wb_wrapper_edit_area.php');
|
33
|
// require_once(WB_PATH . '/framework/SecureForm.php');
|
34
|
|
35
|
|
36
|
/**
|
37
|
* admin
|
38
|
*
|
39
|
* @package
|
40
|
* @copyright
|
41
|
* @version 2012
|
42
|
* @access public
|
43
|
*/
|
44
|
class admin extends wb {
|
45
|
// Authenticate user then auto print the header
|
46
|
/**
|
47
|
* admin::__construct()
|
48
|
*
|
49
|
* @param string $section_name
|
50
|
* @param string $section_permission
|
51
|
* @param bool $auto_header
|
52
|
* @param bool $auto_auth
|
53
|
* @return void
|
54
|
*/
|
55
|
public function __construct($section_name= '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
|
56
|
{
|
57
|
parent::__construct(SecureForm::BACKEND);
|
58
|
if( $section_name != '##skip##' )
|
59
|
{
|
60
|
global $database, $MESSAGE, $TEXT;
|
61
|
// Specify the current applications name
|
62
|
$this->section_name = $section_name;
|
63
|
$this->section_permission = $section_permission;
|
64
|
$maintance = ( defined('SYSTEM_LOCKED') && (SYSTEM_LOCKED==true) ? true : false );
|
65
|
// Authenticate the user for this application
|
66
|
if( ($auto_auth == true) )
|
67
|
{
|
68
|
// First check if the user is logged-in
|
69
|
if($this->is_authenticated() == false)
|
70
|
{
|
71
|
header('Location: '.ADMIN_URL.'/login/index.php');
|
72
|
exit(0);
|
73
|
}
|
74
|
// Now check if they are allowed in this section
|
75
|
if($this->get_permission($section_permission) == false) {
|
76
|
// die($MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES']);
|
77
|
$sErrorMsgFile = $this->correct_theme_source('ErrorMsgFile.htt');
|
78
|
if(file_exists($sErrorMsgFile))
|
79
|
{
|
80
|
$this->print_header();
|
81
|
$oTpl = new Template(dirname( $sErrorMsgFile ));
|
82
|
// $oTpl->debug = true;
|
83
|
$sBackLink = (isset($_SERVER['QUERY_STRING'])&& ($_SERVER['QUERY_STRING']!='')) ? $_SERVER['HTTP_REFERER'].'?'.$_SERVER['QUERY_STRING'] : $_SERVER['HTTP_REFERER'];
|
84
|
$oTpl->set_file( 'page', 'ErrorMsgFile.htt' );
|
85
|
$oTpl->set_var( 'THEME_URL', THEME_URL );
|
86
|
$oTpl->set_var( 'PAGE_ICON', 'negative');
|
87
|
$oTpl->set_var( 'ERROR_TITLE', $MESSAGE['MEDIA_DIR_ACCESS_DENIED']);
|
88
|
$oTpl->set_var( 'PAGE_TITLE', $MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES'] );
|
89
|
$oTpl->set_var( 'BACK_LINK', $sBackLink );
|
90
|
$oTpl->set_var( 'TEXT_BACK', $TEXT['BACK'] );
|
91
|
$output = $oTpl->finish($oTpl->parse('output', 'page'));
|
92
|
}
|
93
|
throw new ErrorMsgException($output);
|
94
|
}
|
95
|
}
|
96
|
|
97
|
if( ($maintance==true) || $this->get_session('USER_ID')!= 1 )
|
98
|
{
|
99
|
// check for show maintenance screen and terminate if needed
|
100
|
$this->ShowMaintainScreen('locked');
|
101
|
}
|
102
|
|
103
|
// Check if the backend language is also the selected language. If not, send headers again.
|
104
|
$sql = 'SELECT `language` FROM `'.TABLE_PREFIX.'users` ';
|
105
|
$sql .= 'WHERE `user_id`='.(int)$this->get_user_id();
|
106
|
$get_user_language = @$database->query($sql);
|
107
|
$user_language = ($get_user_language) ? $get_user_language->fetchRow() : '';
|
108
|
// prevent infinite loop if language file is not XX.php (e.g. DE_du.php)
|
109
|
$user_language = substr($user_language[0],0,2);
|
110
|
// obtain the admin folder (e.g. /admin)
|
111
|
$admin_folder = str_replace(WB_PATH, '', ADMIN_PATH);
|
112
|
|
113
|
if( (LANGUAGE != $user_language) && file_exists(WB_PATH .'/languages/' .$user_language .'.php')
|
114
|
&& strpos($_SERVER['SCRIPT_NAME'],$admin_folder.'/') !== false) {
|
115
|
// check if page_id is set
|
116
|
$page_id_url = (isset($_GET['page_id'])) ? '&page_id=' .(int) $_GET['page_id'] : '';
|
117
|
$section_id_url = (isset($_GET['section_id'])) ? '§ion_id=' .(int) $_GET['section_id'] : '';
|
118
|
// check if there is an query-string
|
119
|
if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
|
120
|
header('Location: '.$_SERVER['SCRIPT_NAME'] .'?lang='.$user_language .$page_id_url .$section_id_url.'&'.$_SERVER['QUERY_STRING']);
|
121
|
} else {
|
122
|
header('Location: '.$_SERVER['SCRIPT_NAME'] .'?lang='.$user_language .$page_id_url .$section_id_url);
|
123
|
}
|
124
|
exit();
|
125
|
}
|
126
|
|
127
|
// Auto header code
|
128
|
if($auto_header == true) {
|
129
|
$this->print_header();
|
130
|
}
|
131
|
}
|
132
|
}
|
133
|
|
134
|
// Print the admin header
|
135
|
/**
|
136
|
*
|
137
|
* @param string $body_tags
|
138
|
* @return void
|
139
|
*/
|
140
|
function print_header($body_tags = '')
|
141
|
{
|
142
|
// Get vars from the language file
|
143
|
global $MENU, $MESSAGE, $TEXT;
|
144
|
// Connect to database and get website title
|
145
|
global $database;
|
146
|
// $GLOBALS['FTAN'] = $this->getFTAN();
|
147
|
$this->createFTAN();
|
148
|
$sql = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` WHERE `name`=\'website_title\'';
|
149
|
$get_title = $database->query($sql);
|
150
|
$title = $get_title->fetchRow();
|
151
|
// Setup template object, parse vars to it, then parse it
|
152
|
$header_template = new Template(dirname($this->correct_theme_source('header.htt')) );
|
153
|
$header_template->set_file('page', 'header.htt');
|
154
|
$header_template->set_block('page', 'header_block', 'header');
|
155
|
if(defined('DEFAULT_CHARSET')) {
|
156
|
$charset=DEFAULT_CHARSET;
|
157
|
} else {
|
158
|
$charset='utf-8';
|
159
|
}
|
160
|
|
161
|
// work out the URL for the 'View menu' link in the WB backend
|
162
|
// if the page_id is set, show this page otherwise show the root directory of WB
|
163
|
$view_url = WB_URL;
|
164
|
if(isset($_GET['page_id'])) {
|
165
|
// extract page link from the database
|
166
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` ';
|
167
|
$sql .= 'WHERE `page_id`='.intval($_GET['page_id']);
|
168
|
$result = @$database->query($sql);
|
169
|
$row = @$result->fetchRow();
|
170
|
if($row) $view_url .= PAGES_DIRECTORY .$row['link']. PAGE_EXTENSION;
|
171
|
}
|
172
|
|
173
|
$HelpUrl = ((strtolower(LANGUAGE)!='de') ? '/en/help.php' : '/de/hilfe.php');
|
174
|
$sServerAdress = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
|
175
|
$header_template->set_var( array(
|
176
|
'SECTION_FORGOT' => $MENU['FORGOT'],
|
177
|
'SECTION_NAME' => $MENU['LOGIN'],
|
178
|
'BODY_TAGS' => $body_tags,
|
179
|
'WEBSITE_TITLE' => ($title['value']),
|
180
|
'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'],
|
181
|
'CURRENT_USER' => $MESSAGE['START_CURRENT_USER'],
|
182
|
'DISPLAY_NAME' => $this->get_display_name(),
|
183
|
'CHARSET' => $charset,
|
184
|
//'LANGUAGE' => strtolower(LANGUAGE),
|
185
|
'LANGUAGE' => LANGUAGE,
|
186
|
'VERSION' => VERSION,
|
187
|
'SP' => (defined('SP') ? SP : ''),
|
188
|
'REVISION' => REVISION,
|
189
|
'SERVER_ADDR' => ((int)$this->get_user_id()==1 ? $sServerAdress : ''),
|
190
|
'WB_URL' => WB_URL,
|
191
|
'ADMIN_URL' => ADMIN_URL,
|
192
|
'THEME_URL' => THEME_URL,
|
193
|
'START_URL' => ADMIN_URL.'/index.php',
|
194
|
'START_CLASS' => 'start',
|
195
|
'TITLE_START' => $TEXT['READ_MORE'],
|
196
|
'TITLE_VIEW' => $TEXT['WEBSITE'],
|
197
|
'TITLE_HELP' => 'WebsiteBaker '.$MENU['HELP'],
|
198
|
'URL_VIEW' => $view_url,
|
199
|
'TITLE_LOGOUT' => $MENU['LOGIN'],
|
200
|
'LOGIN_DISPLAY_HIDDEN' => !$this->is_authenticated() ? 'hidden' : '',
|
201
|
'LOGIN_DISPLAY_NONE' => !$this->is_authenticated() ? 'none' : '',
|
202
|
'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'],
|
203
|
'LOGIN_ICON' => 'login',
|
204
|
'START_ICON' => 'blank',
|
205
|
'URL_HELP' => 'http://www.websitebaker2.org'.$HelpUrl,
|
206
|
'BACKEND_MODULE_CSS' => $this->register_backend_modfiles('css'), // adds backend.css
|
207
|
'BACKEND_MODULE_JS' => $this->register_backend_modfiles('js') // adds backend.js
|
208
|
)
|
209
|
);
|
210
|
$header_template->set_block('header_block', 'maintenance_block', 'maintenance');
|
211
|
if($this->get_user_id() == 1)
|
212
|
{
|
213
|
$sys_locked = (((int)(defined('SYSTEM_LOCKED') ? SYSTEM_LOCKED : 0)) == 1);
|
214
|
$header_template->set_var('MAINTENANCE_MODE', ($sys_locked ? $TEXT['MAINTENANCE_OFF'] : $TEXT['MAINTENANCE_ON']));
|
215
|
$header_template->set_var('MAINTENANCE_ICON', THEME_URL.'/images/'.($sys_locked ? 'lock' : 'unlock').'.png');
|
216
|
$header_template->set_var('MAINTAINANCE_URL', ADMIN_URL.'/settings/locking.php');
|
217
|
$header_template->parse('maintenance', 'maintenance_block', true);
|
218
|
}else
|
219
|
{
|
220
|
$header_template->set_block('maintenance_block', '');
|
221
|
}
|
222
|
|
223
|
// Create the menu
|
224
|
$UrlLang = ((strtolower(LANGUAGE)!='de') ? 'en' : strtolower(LANGUAGE));
|
225
|
if(!$this->is_authenticated())
|
226
|
{
|
227
|
$header_template->set_var('STYLE', 'login');
|
228
|
$menu = array(
|
229
|
// array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', 'help', 0),
|
230
|
// array($view_url, '_blank', $TEXT['FRONTEND'], '', 0),
|
231
|
// array(ADMIN_URL.'/login/index.php', '', $MENU['LOGIN'], '', 0)
|
232
|
);
|
233
|
} else {
|
234
|
$header_template->set_var('STYLE', 'start');
|
235
|
$header_template->set_var( array(
|
236
|
'SECTION_NAME' => $MENU[strtoupper($this->section_name)],
|
237
|
'TITLE_LOGOUT' => $MENU['LOGOUT'],
|
238
|
'LOGIN_DISPLAY_NONE' => '',
|
239
|
'START_ICON' => 'home',
|
240
|
'LOGIN_ICON' => 'logout',
|
241
|
'LOGIN_LINK' => ADMIN_URL.'/logout/index.php',
|
242
|
'TITLE_START' => $MENU['START']
|
243
|
)
|
244
|
);
|
245
|
|
246
|
// @array ( $url, $target, $title, $page_permission, $permission_required )
|
247
|
$menu = array(
|
248
|
// array(ADMIN_URL.'/index.php', '', $MENU['START'], 'start', 1 ),
|
249
|
array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1),
|
250
|
// array($view_url, '_blank', $MENU['FRONTEND'], 'pages', 1),
|
251
|
array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1),
|
252
|
array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1),
|
253
|
array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 1),
|
254
|
array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1),
|
255
|
array(ADMIN_URL.'/admintools/index.php', '', $MENU['ADMINTOOLS'], 'admintools', 1),
|
256
|
array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1),
|
257
|
// array('http://addons.websitebaker2.org/', '', 'WB-Addons', 'preferences', 1),
|
258
|
// array('http://template.websitebaker2.org/', '', 'WB-Template', 'preferences', 1),
|
259
|
// array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', '', 0),
|
260
|
// array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], '', 0)
|
261
|
);
|
262
|
}
|
263
|
|
264
|
$header_template->set_block('header_block', 'linkBlock', 'link');
|
265
|
foreach($menu AS $menu_item)
|
266
|
{
|
267
|
$link = $menu_item[0];
|
268
|
$target = ($menu_item[1] == '') ? '_self' : $menu_item[1];
|
269
|
$title = $menu_item[2];
|
270
|
$permission_title = $menu_item[3];
|
271
|
$required = $menu_item[4];
|
272
|
$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php');
|
273
|
if($required == false || ($this->is_authenticated() && $this->get_link_permission($permission_title)) )
|
274
|
{
|
275
|
$header_template->set_var('LINK', $link);
|
276
|
$header_template->set_var('TARGET', $target);
|
277
|
// If link is the current section apply a class name
|
278
|
if($permission_title == strtolower($this->section_name)) {
|
279
|
$header_template->set_var('CLASS', $menu_item[3] . ' current');
|
280
|
$header_template->set_var('STYLE', $menu_item[3] );
|
281
|
} else {
|
282
|
$header_template->set_var('CLASS', $menu_item[3] );
|
283
|
}
|
284
|
$header_template->set_var('TITLE', $title);
|
285
|
// Print link
|
286
|
$header_template->parse('link', 'linkBlock', true);
|
287
|
}
|
288
|
}
|
289
|
$header_template->parse('header', 'header_block', false);
|
290
|
$header_template->pparse('output', 'page');
|
291
|
unset($header_template);
|
292
|
}
|
293
|
|
294
|
// Print the admin footer
|
295
|
function print_footer($activateJsAdmin = false) {
|
296
|
global $database,$starttime,$iPhpDeclaredClasses;
|
297
|
// include the required file for Javascript admin
|
298
|
if($activateJsAdmin == true) {
|
299
|
if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){
|
300
|
@include_once(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
|
301
|
}
|
302
|
}
|
303
|
|
304
|
// Setup template object, parse vars to it, then parse it
|
305
|
$footer_template = new Template(dirname($this->correct_theme_source('footer.htt')));
|
306
|
$footer_template->set_file('page', 'footer.htt');
|
307
|
$footer_template->set_block('page', 'footer_block', 'header');
|
308
|
$footer_template->set_var(array(
|
309
|
'BACKEND_BODY_MODULE_JS' => $this->register_backend_modfiles_body('js'),
|
310
|
'WB_URL' => WB_URL,
|
311
|
'ADMIN_URL' => ADMIN_URL,
|
312
|
'THEME_URL' => THEME_URL,
|
313
|
) );
|
314
|
|
315
|
$footer_template->set_block('footer_block', 'show_debug_block', 'show_debug');
|
316
|
|
317
|
$bDebug = (defined('DEBUG') ? DEBUG : false);
|
318
|
$bDevInfo = (defined('DEV_INFOS') && (DEV_INFOS == true) && (1 == $this->get_user_id()) ? true : false);
|
319
|
// if( $debug && (1 == $this->get_user_id()))
|
320
|
if( $bDevInfo )
|
321
|
{
|
322
|
|
323
|
$footer_template->set_var('MEMORY', number_format(memory_get_peak_usage(true), 0, ',', '.').' Byte' );
|
324
|
// $footer_template->set_var('MEMORY', number_format(memory_get_usage(true), 0, ',', '.').' Byte' );
|
325
|
$footer_template->set_var('QUERIES', $database->getQueryCount );
|
326
|
// $footer_template->set_var('QUERIES', 'disabled' );
|
327
|
$included_files = get_included_files();
|
328
|
$footer_template->set_var('INCLUDES', sizeof($included_files) );
|
329
|
$included_classes = get_declared_classes();
|
330
|
$footer_template->set_var('CLASSES', sizeof($included_classes)-$iPhpDeclaredClasses );
|
331
|
|
332
|
$sum_classes = 0;
|
333
|
$sum_filesize = 0;
|
334
|
$footer_template->set_block('show_debug_block', 'show_block_list', 'show_list');
|
335
|
$footer_template->set_block('show_block_list', 'include_block_list', 'include_list');
|
336
|
// $bDebug = true; for testing
|
337
|
foreach($included_files as $filename)
|
338
|
{
|
339
|
if(!is_readable($filename)) { continue; }
|
340
|
if($bDebug)
|
341
|
{
|
342
|
$footer_template->set_var('INCLUDES_ARRAY', str_replace(WB_PATH, '',$filename) );
|
343
|
$footer_template->set_var('FILESIZE', number_format(filesize($filename), 0, ',', '.').' Byte');
|
344
|
$footer_template->parse('include_list', 'include_block_list', true);
|
345
|
}
|
346
|
$sum_filesize += filesize($filename);
|
347
|
}
|
348
|
$footer_template->parse('show_list', 'show_block_list', true);
|
349
|
|
350
|
$endtime = array_sum(explode(" ",microtime()));
|
351
|
$iEndTime = $endtime;
|
352
|
$iStartTime = $starttime;
|
353
|
if(!$bDebug)
|
354
|
{
|
355
|
$footer_template->parse('show_list', '');
|
356
|
$footer_template->parse('include_list', '');
|
357
|
}
|
358
|
|
359
|
$footer_template->set_var('FILESIZE', ini_get('memory_limit'));
|
360
|
$footer_template->set_var('TXT_SUM_FILESIZE', 'Summary size of included files: ');
|
361
|
$footer_template->set_var('SUM_FILESIZE', number_format($sum_filesize, 0, ',', '.').' Byte');
|
362
|
$footer_template->set_var('SUM_CLASSES', number_format($sum_classes, 0, ',', '.').' Byte');
|
363
|
$footer_template->set_var('PAGE_LOAD_TIME', round($iEndTime-$iStartTime,3 ));
|
364
|
$footer_template->set_var('DUMP_CLASSES', '<pre>'.var_export($included_classes,true).'</pre>');
|
365
|
|
366
|
$footer_template->parse('show_debug', 'show_debug_block', true);
|
367
|
} else {
|
368
|
$footer_template->parse('show_debug', '');
|
369
|
$footer_template->parse('show_list', '');
|
370
|
|
371
|
}
|
372
|
$footer_template->parse('header', 'footer_block', false);
|
373
|
$footer_template->pparse('output', 'page');
|
374
|
unset($footer_template);
|
375
|
}
|
376
|
|
377
|
// Return a system permission
|
378
|
function get_permission($name, $type = 'system') {
|
379
|
|
380
|
// Append to permission type
|
381
|
$type .= '_permissions';
|
382
|
// Check if we have a section to check for
|
383
|
if($name == 'start') {
|
384
|
return true;
|
385
|
} else {
|
386
|
// Set system permissions var
|
387
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
388
|
// Set module permissions var
|
389
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
390
|
// Set template permissions var
|
391
|
$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
|
392
|
// Return true if system perm = 1
|
393
|
if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) {
|
394
|
if($type == 'system_permissions') {
|
395
|
return true;
|
396
|
} else {
|
397
|
return false;
|
398
|
}
|
399
|
} else {
|
400
|
if($type == 'system_permissions') {
|
401
|
return false;
|
402
|
} else {
|
403
|
return true;
|
404
|
}
|
405
|
}
|
406
|
}
|
407
|
|
408
|
}
|
409
|
|
410
|
function get_user_details($user_id) {
|
411
|
global $database;
|
412
|
$retval = array('username'=>'unknown','display_name'=>'Unknown','email'=>'');
|
413
|
$sql = 'SELECT `username`,`display_name`,`email` ';
|
414
|
$sql .= 'FROM `'.TABLE_PREFIX.'users` ';
|
415
|
$sql .= 'WHERE `user_id`='.(int)$user_id;
|
416
|
if( ($resUsers = $database->query($sql)) ) {
|
417
|
if( ($recUser = $resUsers->fetchRow()) ) {
|
418
|
$retval = $recUser;
|
419
|
}
|
420
|
}
|
421
|
return $retval;
|
422
|
}
|
423
|
|
424
|
//
|
425
|
function get_section_details( $section_id, $backLink = 'index.php' ) {
|
426
|
global $database, $TEXT;
|
427
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'sections` ';
|
428
|
$sql .= 'WHERE `section_id`='.intval($section_id);
|
429
|
if(($resSection = $database->query($sql))){
|
430
|
if(!($recSection = $resSection->fetchRow())) {
|
431
|
$this->print_header();
|
432
|
$this->print_error($TEXT['SECTION'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
433
|
}
|
434
|
} else {
|
435
|
$this->print_header();
|
436
|
$this->print_error($database->get_error(), $backLink, true);
|
437
|
}
|
438
|
return $recSection;
|
439
|
}
|
440
|
|
441
|
function get_page_details( $page_id, $backLink = 'index.php' ) {
|
442
|
global $database, $TEXT;
|
443
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
|
444
|
$sql .= 'WHERE `page_id`='.intval($page_id);
|
445
|
if(($resPages = $database->query($sql))){
|
446
|
if(!($recPage = $resPages->fetchRow())) {
|
447
|
$this->print_header();
|
448
|
$this->print_error($TEXT['PAGE'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
449
|
}
|
450
|
} else {
|
451
|
$this->print_header();
|
452
|
$this->print_error($database->get_error(), $backLink, true);
|
453
|
}
|
454
|
return $recPage;
|
455
|
}
|
456
|
|
457
|
function get_page_permission($page,$action='admin') {
|
458
|
if($action != 'viewing') { $action = 'admin'; }
|
459
|
$action_groups = $action.'_groups';
|
460
|
$action_users = $action.'_users';
|
461
|
$groups = $users = '0';
|
462
|
if(is_array($page)) {
|
463
|
$groups = $page[$action_groups];
|
464
|
$users = $page[$action_users];
|
465
|
} else {
|
466
|
global $database;
|
467
|
$sql = 'SELECT `'.$action_groups.'`,`'.$action_users.'` ';
|
468
|
$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
|
469
|
$sql .= 'WHERE `page_id`='.(int)$page;
|
470
|
if( ($res = $database->query($sql)) ) {
|
471
|
if( ($rec = $res->fetchRow()) ) {
|
472
|
$groups = $rec[$action_groups];
|
473
|
$users = $rec[$action_users];
|
474
|
}
|
475
|
}
|
476
|
}
|
477
|
return ($this->ami_group_member($groups) || $this->is_group_match($this->get_user_id(), $users));
|
478
|
}
|
479
|
|
480
|
// Returns a system permission for a menu link
|
481
|
function get_link_permission($title) {
|
482
|
$title = str_replace('_blank', '', $title);
|
483
|
$title = strtolower($title);
|
484
|
// Set system permissions var
|
485
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
486
|
// Set module permissions var
|
487
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
488
|
if($title == 'start') {
|
489
|
return true;
|
490
|
} else {
|
491
|
// Return true if system perm = 1
|
492
|
if(is_numeric(array_search($title, $system_permissions))) {
|
493
|
return true;
|
494
|
} else {
|
495
|
return false;
|
496
|
}
|
497
|
}
|
498
|
}
|
499
|
|
500
|
// Function to add optional module Javascript or CSS stylesheets into the <body> section of the backend
|
501
|
function register_backend_modfiles_body($file_id="js")
|
502
|
{
|
503
|
// sanity check of parameter passed to the function
|
504
|
$file_id = strtolower($file_id);
|
505
|
if($file_id !== "javascript" && $file_id !== "js")
|
506
|
{
|
507
|
return;
|
508
|
}
|
509
|
global $database;
|
510
|
$body_links = "";
|
511
|
// define default baselink and filename for optional module javascript and stylesheet files
|
512
|
if($file_id == "js") {
|
513
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js" type="text/javascript"></script>';
|
514
|
$base_file = "backend_body.js";
|
515
|
}
|
516
|
// check if backend_body.js files needs to be included to the <body></body> section of the backend
|
517
|
if(isset($_GET['tool']))
|
518
|
{
|
519
|
// check if displayed page contains a installed admin tool
|
520
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
521
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($_GET['tool']).'\'';
|
522
|
$result = $database->query($sql);
|
523
|
if($result->numRows())
|
524
|
{
|
525
|
// check if admin tool directory contains a backend_body.js file to include
|
526
|
$tool = $result->fetchRow();
|
527
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file"))
|
528
|
{
|
529
|
// return link to the backend_body.js file
|
530
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
531
|
}
|
532
|
}
|
533
|
} elseif(isset($_GET['page_id']) or isset($_POST['page_id']))
|
534
|
{
|
535
|
// check if displayed page in the backend contains a page module
|
536
|
if (isset($_GET['page_id']))
|
537
|
{
|
538
|
$page_id = (int) addslashes($_GET['page_id']);
|
539
|
} else {
|
540
|
$page_id = (int) addslashes($_POST['page_id']);
|
541
|
}
|
542
|
// gather information for all models embedded on actual page
|
543
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
544
|
$query_modules = $database->query($sql);
|
545
|
while($row = $query_modules->fetchRow()) {
|
546
|
// check if page module directory contains a backend_body.js file
|
547
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
548
|
// create link with backend_body.js source for the current module
|
549
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
550
|
// ensure that backend_body.js is only added once per module type
|
551
|
if(strpos($body_links, $tmp_link) === false) {
|
552
|
$body_links .= $tmp_link ."\n";
|
553
|
}
|
554
|
}
|
555
|
}
|
556
|
// write out links with all external module javascript/CSS files, remove last line feed
|
557
|
return rtrim($body_links);
|
558
|
}
|
559
|
}
|
560
|
|
561
|
|
562
|
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the backend
|
563
|
function register_backend_modfiles($file_id="css") {
|
564
|
// sanity check of parameter passed to the function
|
565
|
$file_id = strtolower($file_id);
|
566
|
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
|
567
|
return;
|
568
|
}
|
569
|
|
570
|
global $database;
|
571
|
// define default baselink and filename for optional module javascript and stylesheet files
|
572
|
$head_links = "";
|
573
|
if($file_id == "css") {
|
574
|
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.css"';
|
575
|
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
|
576
|
$base_file = "backend.css";
|
577
|
} else {
|
578
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js" type="text/javascript"></script>';
|
579
|
$base_file = "backend.js";
|
580
|
}
|
581
|
|
582
|
// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend
|
583
|
if(isset($_GET['tool'])) {
|
584
|
// check if displayed page contains a installed admin tool
|
585
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
586
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($_GET['tool']).'\'';
|
587
|
$result = $database->query($sql);
|
588
|
if($result->numRows()) {
|
589
|
// check if admin tool directory contains a backend.js or backend.css file to include
|
590
|
$tool = $result->fetchRow();
|
591
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) {
|
592
|
// return link to the backend.js or backend.css file
|
593
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
594
|
}
|
595
|
}
|
596
|
} elseif(isset($_GET['page_id']) || isset($_POST['page_id'])) {
|
597
|
// check if displayed page in the backend contains a page module
|
598
|
if (isset($_GET['page_id'])) {
|
599
|
$page_id = (int)$_GET['page_id'];
|
600
|
} else {
|
601
|
$page_id = (int)$_POST['page_id'];
|
602
|
}
|
603
|
|
604
|
// gather information for all models embedded on actual page
|
605
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
606
|
$query_modules = $database->query($sql);
|
607
|
|
608
|
while($row = $query_modules->fetchRow()) {
|
609
|
// check if page module directory contains a backend.js or backend.css file
|
610
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
611
|
// create link with backend.js or backend.css source for the current module
|
612
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
613
|
// ensure that backend.js or backend.css is only added once per module type
|
614
|
if(strpos($head_links, $tmp_link) === false) {
|
615
|
$head_links .= $tmp_link ."\n";
|
616
|
}
|
617
|
}
|
618
|
}
|
619
|
// write out links with all external module javascript/CSS files, remove last line feed
|
620
|
return rtrim($head_links);
|
621
|
}
|
622
|
}
|
623
|
}
|