Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         framework
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.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 2094 2014-01-30 12:45:33Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/class.admin.php $
14
 * @lastmodified    $Date: 2014-01-30 13:45:33 +0100 (Thu, 30 Jan 2014) $
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;
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', $this->_oTrans->MESSAGE_MEDIA_DIR_ACCESS_DENIED);
88
            	 	    $oTpl->set_var( 'PAGE_TITLE', $this->_oTrans->MESSAGE_ADMIN_INSUFFICIENT_PRIVELLIGES);
89
            	 	    $oTpl->set_var( 'BACK_LINK', $sBackLink );
90
            	 	    $oTpl->set_var( 'TEXT_BACK', $this->_oTrans->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 `'.$this->_oDb->TablePrefix.'users` '
105
    		     . 'WHERE `user_id`='.(int)$this->get_user_id();
106
            $user_language = preg_replace('/([a-z]{2}).*/i', '\1', strtoupper((string)$this->_oDb->getOne($sql)));
107
    		// obtain the admin folder (e.g. /admin)
108
    		$admin_folder = str_replace(WB_PATH, '', ADMIN_PATH);
109

    
110
    		if( (LANGUAGE != $user_language) && file_exists(WB_PATH .'/languages/' .$user_language .'.php')
111
    			&& strpos($_SERVER['SCRIPT_NAME'],$admin_folder.'/') !== false) {
112
    			// check if page_id is set
113
    			$page_id_url = (isset($_GET['page_id'])) ? '&page_id=' .(int) $_GET['page_id'] : '';
114
    			$section_id_url = (isset($_GET['section_id'])) ? '&section_id=' .(int) $_GET['section_id'] : '';
115
    			 //  check if there is an query-string
116
    			if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
117
    				header('Location: '.$_SERVER['SCRIPT_NAME'] .'?lang='.$user_language .$page_id_url .$section_id_url.'&'.$_SERVER['QUERY_STRING']);
118
    			} else {
119
    				header('Location: '.$_SERVER['SCRIPT_NAME'] .'?lang='.$user_language .$page_id_url .$section_id_url);
120
    			}
121
    			exit();
122
    		}
123

    
124
    		// Auto header code
125
    		if($auto_header == true) {
126
    			$this->print_header();
127
    		}
128
    	}
129
	}
130

    
131
	// Print the admin header
132
	/**
133
	 *
134
	 * @param string $body_tags
135
	 * @return void
136
	 */
137
	function print_header($body_tags = '')
138
	{
139
		// $GLOBALS['FTAN'] = $this->getFTAN();
140
		$this->createFTAN();
141
		$sql = 'SELECT `value` FROM `'.$this->_oDb->TablePrefix.'settings` '
142
             . 'WHERE `name`=\'website_title\'';
143
        $title = (string)$this->_oDb->getOne($sql);
144
		// Setup template object, parse vars to it, then parse it
145
		$header_template = new Template(dirname($this->correct_theme_source('header.htt')) );
146
		$header_template->set_file('page', 'header.htt');
147
		$header_template->set_block('page', 'header_block', 'header');
148
        $this->_oTrans->enableAddon('templates\\'.$this->_oReg->DefaultTheme);
149
        $header_template->set_var($this->_oTrans->getLangArray());
150
		if(defined('DEFAULT_CHARSET')) {
151
			$charset=DEFAULT_CHARSET;
152
		} else {
153
			$charset='utf-8';
154
		}
155

    
156
		// work out the URL for the 'View menu' link in the WB backend
157
		// if the page_id is set, show this page otherwise show the root directory of WB
158
		$view_url = WB_URL;
159
		if(isset($_GET['page_id'])) {
160
			// extract page link from the database
161
			$sql = 'SELECT `link` FROM `'.$this->_oDb->TablePrefix.'pages` '
162
			     . 'WHERE `page_id`='.intval($_GET['page_id']);
163
            $row = (string)$this->_oDb->getOne($sql);
164
            if ($row) { $view_url .= PAGES_DIRECTORY .$row. PAGE_EXTENSION; }
165
		}
166

    
167
        $HelpUrl = ((strtolower(LANGUAGE)!='de') ? '/en/help.php' : '/de/hilfe.php');
168
		$sServerAdress = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
169
		$header_template->set_var(	array(
170
							'SECTION_FORGOT' => $this->_oTrans->MENU_FORGOT,
171
							'SECTION_NAME' => $this->_oTrans->MENU_LOGIN,
172
							'BODY_TAGS' => $body_tags,
173
							'WEBSITE_TITLE' => $title,
174
							'TEXT_ADMINISTRATION' => $this->_oTrans->TEXT_ADMINISTRATION,
175
							'CURRENT_USER' => $this->_oTrans->MESSAGE_START_CURRENT_USER,
176
							'DISPLAY_NAME' => $this->get_display_name(),
177
							'CHARSET' => $charset,
178
							//'LANGUAGE' => strtolower(LANGUAGE),
179
							'LANGUAGE' => LANGUAGE,
180
							'VERSION' => VERSION,
181
							'SP' => (defined('SP') ? SP : ''),
182
							'REVISION' => REVISION,
183
							'SERVER_ADDR' => ((int)$this->get_user_id()==1 ? $sServerAdress : ''),
184
							'WB_URL' => WB_URL,
185
							'ADMIN_URL' => ADMIN_URL,
186
							'THEME_URL' => THEME_URL,
187
							'START_URL' => ADMIN_URL.'/index.php',
188
							'START_CLASS' => 'start',
189
							'TITLE_START' => $this->_oTrans->TEXT_READ_MORE,
190
							'TITLE_VIEW' => $this->_oTrans->TEXT_WEBSITE,
191
							'TITLE_HELP' => 'WebsiteBaker '.$this->_oTrans->MENU_HELP,
192
							'URL_VIEW' => $view_url,
193
							'TITLE_LOGOUT' => $this->_oTrans->MENU_LOGIN,
194
							'LOGIN_DISPLAY_HIDDEN' => !$this->is_authenticated() ? 'hidden' : '',
195
							'LOGIN_DISPLAY_NONE' => !$this->is_authenticated() ? 'none' : '',
196
							'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'],
197
							'LOGIN_ICON' => 'login',
198
							'START_ICON' => 'blank',
199
							'URL_HELP' => 'http://www.websitebaker.org'.$HelpUrl,
200
							'BACKEND_MODULE_CSS' => $this->register_backend_modfiles('css'),	// adds backend.css
201
							'BACKEND_MODULE_JS'  => $this->register_backend_modfiles('js')		// adds backend.js
202
						)
203
					);
204
		$header_template->set_block('header_block', 'maintenance_block', 'maintenance');
205
		if($this->get_user_id() == 1)
206
		{
207
			$sys_locked = (((int)(defined('SYSTEM_LOCKED') ? SYSTEM_LOCKED : 0)) == 1);
208
			$header_template->set_var('MAINTENANCE_MODE', ($sys_locked ? $this->_oTrans->TEXT_MAINTENANCE_OFF : $this->_oTrans->TEXT_MAINTENANCE_ON));
209
			$header_template->set_var('MAINTENANCE_ICON', THEME_URL.'/images/'.($sys_locked ? 'lock' : 'unlock').'.png');
210
			$header_template->set_var('MAINTAINANCE_URL', ADMIN_URL.'/settings/locking.php');
211
			$header_template->parse('maintenance', 'maintenance_block', true);
212
		}else
213
		{
214
			$header_template->set_block('maintenance_block', '');
215
		}
216

    
217
		// Create the menu
218
        $UrlLang = ((strtolower(LANGUAGE)!='de') ? 'en' : strtolower(LANGUAGE));
219
		if(!$this->is_authenticated())
220
		{
221
    		$header_template->set_var('STYLE', 'login');
222
    		$menu = array(
223
//						array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', 'help', 0),
224
//						array($view_url, '_blank', $TEXT['FRONTEND'], '', 0),
225
//						array(ADMIN_URL.'/login/index.php', '', $MENU['LOGIN'], '', 0)
226
						);
227
		} else {
228
			$header_template->set_var('STYLE', 'start');
229
			$header_template->set_var(	array(
230
                        'SECTION_NAME' => $this->_oTrans->{'MENU'.strtoupper($this->section_name)},
231
						'TITLE_LOGOUT' => $this->_oTrans->MENU_LOGOUT,
232
						'LOGIN_DISPLAY_NONE' => '',
233
						'START_ICON' => 'home',
234
						'LOGIN_ICON' => 'logout',
235
						'LOGIN_LINK' => ADMIN_URL.'/logout/index.php',
236
						'TITLE_START' => $this->_oTrans->MENU_START
237
						)
238
					);
239

    
240
			// @array ( $url, $target, $title, $page_permission, $permission_required )
241
			$menu = array(
242
//					array(ADMIN_URL.'/index.php', '', $MENU['START'], 'start', 1 ),
243
					array(ADMIN_URL.'/pages/index.php', '', $this->_oTrans->MENU_PAGES, 'pages', 1),
244
// 					array($view_url, '_blank', $MENU['FRONTEND'], 'pages', 1),
245
					array(ADMIN_URL.'/media/index.php', '', $this->_oTrans->MENU_MEDIA, 'media', 1),
246
					array(ADMIN_URL.'/addons/index.php', '', $this->_oTrans->MENU_ADDONS, 'addons', 1),
247
					array(ADMIN_URL.'/preferences/index.php', '', $this->_oTrans->MENU_PREFERENCES, 'preferences', 1),
248
					array(ADMIN_URL.'/settings/index.php', '', $this->_oTrans->MENU_SETTINGS, 'settings', 1),
249
					array(ADMIN_URL.'/admintools/index.php', '', $this->_oTrans->MENU_ADMINTOOLS, 'admintools', 1),
250
					array(ADMIN_URL.'/access/index.php', '', $this->_oTrans->MENU_ACCESS, 'access', 1),
251
//					array('http://addons.websitebaker2.org/', '', 'WB-Addons', 'preferences', 1),
252
//					array('http://template.websitebaker2.org/', '', 'WB-Template', 'preferences', 1),
253
//					array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', '', 0),
254
//					array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], '', 0)
255
					);
256
		}
257

    
258
		$header_template->set_block('header_block', 'linkBlock', 'link');
259
		foreach($menu AS $menu_item)
260
		{
261
			$link = $menu_item[0];
262
			$target = ($menu_item[1] == '') ? '_self' : $menu_item[1];
263
			$title = $menu_item[2];
264
			$permission_title = $menu_item[3];
265
			$required = $menu_item[4];
266
			$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php');
267
			if($required == false || ($this->is_authenticated() && $this->get_link_permission($permission_title)) )
268
			{
269
				$header_template->set_var('LINK', $link);
270
				$header_template->set_var('TARGET', $target);
271
				// If link is the current section apply a class name
272
				if($permission_title == strtolower($this->section_name)) {
273
					$header_template->set_var('CLASS', $menu_item[3] . ' current');
274
					$header_template->set_var('STYLE', $menu_item[3] );
275
				} else {
276
					$header_template->set_var('CLASS', $menu_item[3] );
277
				}
278
				$header_template->set_var('TITLE', $title);
279
				// Print link
280
				$header_template->parse('link', 'linkBlock', true);
281
			}
282
		}
283
		$header_template->parse('header', 'header_block', false);
284
		$header_template->pparse('output', 'page');
285
		unset($header_template);
286
        $this->_oTrans->disableAddon();
287
	}
288

    
289
	// Print the admin footer
290
	function print_footer($activateJsAdmin = false) {
291
		global $starttime, $iPhpDeclaredClasses;
292
		// include the required file for Javascript admin
293
		if($activateJsAdmin == true) {
294
			if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){
295
				@include_once(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
296
			}
297
		}
298
		// Setup template object, parse vars to it, then parse it
299
		$footer_template = new Template(dirname($this->correct_theme_source('footer.htt')));
300
		$footer_template->set_file('page', 'footer.htt');
301
		$footer_template->set_block('page', 'footer_block', 'header');
302
        $this->_oTrans->enableAddon('templates\\'.$this->_oReg->DefaultTheme);
303
        $footer_template->set_var($this->_oTrans->getLangArray());
304
		$footer_template->set_var(array(
305
						'BACKEND_BODY_MODULE_JS' => $this->register_backend_modfiles_body('js'),
306
						'WB_URL' => WB_URL,
307
						'ADMIN_URL' => ADMIN_URL,
308
						'THEME_URL' => THEME_URL,
309
			 ) );
310

    
311
		$footer_template->set_block('footer_block', 'show_debug_block', 'show_debug');
312

    
313
		$bDebug = (defined('DEBUG') ? DEBUG : false);
314
		$bDevInfo = (defined('DEV_INFOS') && (DEV_INFOS == true) && (1 == $this->get_user_id()) ? true : false);
315
//         if( $debug && (1 == $this->get_user_id()))
316
        if( $bDevInfo )
317
		{
318

    
319
			$footer_template->set_var('MEMORY', number_format(memory_get_peak_usage(true), 0, ',', '.').'&nbsp;Byte' );
320
//			$footer_template->set_var('MEMORY', number_format(memory_get_usage(true), 0, ',', '.').'&nbsp;Byte' );
321
			$footer_template->set_var('QUERIES', $this->_oDb->getQueryCount );
322
			// $footer_template->set_var('QUERIES', 'disabled' );
323
	        $included_files =  get_included_files();
324
			$footer_template->set_var('INCLUDES', sizeof($included_files) );
325
	        $included_classes =  get_declared_classes();
326
			$footer_template->set_var('CLASSES', sizeof($included_classes)-$iPhpDeclaredClasses );
327

    
328
			$sum_classes = 0;
329
			$sum_filesize = 0;
330
			$footer_template->set_block('show_debug_block', 'show_block_list', 'show_list');
331
			$footer_template->set_block('show_block_list', 'include_block_list', 'include_list');
332
			// $bDebug = true;  for testing
333
			foreach($included_files as $filename)
334
			{
335
				if(!is_readable($filename)) { continue; }
336
				if($bDebug)
337
				{
338
					$footer_template->set_var('INCLUDES_ARRAY', str_replace(WB_PATH, '',$filename) );
339
					$footer_template->set_var('FILESIZE', number_format(filesize($filename), 0, ',', '.').'&nbsp;Byte');
340
					$footer_template->parse('include_list', 'include_block_list', true);
341
				}
342
				$sum_filesize += filesize($filename);
343
			}
344
			$footer_template->parse('show_list', 'show_block_list', true);
345

    
346
			$endtime = array_sum(explode(" ",microtime()));
347
			$iEndTime = $endtime;
348
			$iStartTime = $starttime;
349
			if(!$bDebug)
350
			{
351
				$footer_template->parse('show_list', '');
352
				$footer_template->parse('include_list', '');
353
			}
354

    
355
			$footer_template->set_var('FILESIZE', ini_get('memory_limit'));
356
			$footer_template->set_var('TXT_SUM_FILESIZE', 'Summary size of included files:&nbsp;');
357
			$footer_template->set_var('SUM_FILESIZE', number_format($sum_filesize, 0, ',', '.').'&nbsp;Byte');
358
			$footer_template->set_var('SUM_CLASSES', number_format($sum_classes, 0, ',', '.').'&nbsp;Byte');
359
			$footer_template->set_var('PAGE_LOAD_TIME', round($iEndTime-$iStartTime,3 ));
360
			$footer_template->set_var('DUMP_CLASSES', '<pre>'.var_export($included_classes,true).'</pre>');
361

    
362
			$footer_template->parse('show_debug', 'show_debug_block', true);
363
        } else {
364
			$footer_template->parse('show_debug', '');
365
			$footer_template->parse('show_list', '');
366

    
367
        }
368
		$footer_template->parse('header', 'footer_block', false);
369
		$footer_template->pparse('output', 'page');
370
		unset($footer_template);
371

    
372
	}
373

    
374
	// Return a system permission
375
	function get_permission($name, $type = 'system') {
376

    
377
		// Append to permission type
378
		$type .= '_permissions';
379
		// Check if we have a section to check for
380
		if($name == 'start') {
381
			return true;
382
		} else {
383
			// Set system permissions var
384
			$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
385
			// Set module permissions var
386
			$module_permissions = $this->get_session('MODULE_PERMISSIONS');
387
			// Set template permissions var
388
			$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
389
			// Return true if system perm = 1
390
			if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) {
391
				if($type == 'system_permissions') {
392
					return true;
393
				} else {
394
					return false;
395
				}
396
			} else {
397
				if($type == 'system_permissions') {
398
					return false;
399
				} else {
400
					return true;
401
				}
402
			}
403
		}
404

    
405
	}
406

    
407
 function get_user_details($user_id) {
408
  global $database;
409
  $retval = array('username'=>'unknown','display_name'=>'Unknown','email'=>'');
410
  $sql  = 'SELECT `username`,`display_name`,`email` ';
411
  $sql .= 'FROM `'.TABLE_PREFIX.'users` ';
412
  $sql .= 'WHERE `user_id`='.(int)$user_id;
413
  if( ($resUsers = $database->query($sql)) ) {
414
   if( ($recUser = $resUsers->fetchRow()) ) {
415
    $retval = $recUser;
416
   }
417
  }
418
  return $retval;
419
 }
420

    
421
    //
422
	function get_section_details( $section_id, $backLink = 'index.php' ) {
423
	global $database, $TEXT;
424
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'sections` ';
425
		$sql .= 'WHERE `section_id`='.intval($section_id);
426
		if(($resSection = $database->query($sql))){
427
			if(!($recSection = $resSection->fetchRow())) {
428
				$this->print_header();
429
				$this->print_error($TEXT['SECTION'].' '.$TEXT['NOT_FOUND'], $backLink, true);
430
			}
431
			} else {
432
				$this->print_header();
433
				$this->print_error($database->get_error(), $backLink, true);
434
			}
435
		return $recSection;
436
	}
437

    
438
	function get_page_details( $page_id, $backLink = 'index.php' ) {
439
		global $database, $TEXT;
440
		$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
441
		$sql .= 'WHERE `page_id`='.intval($page_id);
442
		if(($resPages = $database->query($sql))){
443
			if(!($recPage = $resPages->fetchRow())) {
444
			$this->print_header();
445
			$this->print_error($TEXT['PAGE'].' '.$TEXT['NOT_FOUND'], $backLink, true);
446
			}
447
		} else {
448
			$this->print_header();
449
			$this->print_error($database->get_error(), $backLink, true);
450
		}
451
		return $recPage;
452
	}
453

    
454
	function get_page_permission($page,$action='admin') {
455
		if($action != 'viewing') { $action = 'admin'; }
456
		$action_groups = $action.'_groups';
457
		$action_users  = $action.'_users';
458
		$groups = $users = '0';
459
		if(is_array($page)) {
460
			$groups = $page[$action_groups];
461
			$users  = $page[$action_users];
462
		} else {
463
			global $database;
464
			$sql  = 'SELECT `'.$action_groups.'`,`'.$action_users.'` ';
465
			$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
466
			$sql .= 'WHERE `page_id`='.(int)$page;
467
			if( ($res = $database->query($sql)) ) {
468
				if( ($rec = $res->fetchRow()) ) {
469
					$groups = $rec[$action_groups];
470
					$users  = $rec[$action_users];
471
				}
472
			}
473
		}
474
		return ($this->ami_group_member($groups) || $this->is_group_match($this->get_user_id(), $users));
475
	}
476

    
477
	// Returns a system permission for a menu link
478
	function get_link_permission($title) {
479
		$title = str_replace('_blank', '', $title);
480
		$title = strtolower($title);
481
		// Set system permissions var
482
		$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
483
		// Set module permissions var
484
		$module_permissions = $this->get_session('MODULE_PERMISSIONS');
485
		if($title == 'start') {
486
			return true;
487
		} else {
488
			// Return true if system perm = 1
489
			if(is_numeric(array_search($title, $system_permissions))) {
490
				return true;
491
			} else {
492
				return false;
493
			}
494
		}
495
	}
496

    
497
	// Function to add optional module Javascript or CSS stylesheets into the <body> section of the backend
498
	function register_backend_modfiles_body($file_id="js")
499
		{
500
		// sanity check of parameter passed to the function
501
		$file_id = strtolower($file_id);
502
		if($file_id !== "javascript" && $file_id !== "js")
503
		{
504
			return;
505
		}
506
		global $database;
507
        $body_links = "";
508
		// define default baselink and filename for optional module javascript and stylesheet files
509
		if($file_id == "js") {
510
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js" type="text/javascript"></script>';
511
			$base_file = "backend_body.js";
512
		}
513

    
514
        $sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
515
        $sActionRequest = isset($_GET['tool'])  ? $_GET['tool']  : $sActionRequest;
516

    
517
		// check if backend_body.js files needs to be included to the <body></body> section of the backend
518
		if(isset($sActionRequest))
519
			{
520
			// check if displayed page contains a installed admin tool
521
			$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
522
			$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
523
			$result = $database->query($sql);
524
			if($result->numRows())
525
				{
526
				// check if admin tool directory contains a backend_body.js file to include
527
				$tool = $result->fetchRow();
528
				if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file"))
529
				{
530
					// return link to the backend_body.js file
531
					return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
532
				}
533
			}
534
		} elseif(isset($_GET['page_id']) or isset($_POST['page_id']))
535
		{
536
			// check if displayed page in the backend contains a page module
537
			if (isset($_GET['page_id']))
538
			{
539
				$page_id = (int) addslashes($_GET['page_id']);
540
			} else {
541
				$page_id = (int) addslashes($_POST['page_id']);
542
			}
543
			// gather information for all models embedded on actual page
544
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
545
			$query_modules = $database->query($sql);
546
			while($row = $query_modules->fetchRow()) {
547
				// check if page module directory contains a backend_body.js file
548
				if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
549
					// create link with backend_body.js source for the current module
550
					$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
551
					// ensure that backend_body.js is only added once per module type
552
					if(strpos($body_links, $tmp_link) === false) {
553
						$body_links .= $tmp_link ."\n";
554
					}
555
				}
556
			}
557
			// write out links with all external module javascript/CSS files, remove last line feed
558
			return rtrim($body_links);
559
		}
560
	}
561

    
562

    
563
	// Function to add optional module Javascript or CSS stylesheets into the <head> section of the backend
564
	function register_backend_modfiles($file_id="css") {
565
		// sanity check of parameter passed to the function
566
		$file_id = strtolower($file_id);
567
		if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
568
			return;
569
		}
570

    
571
		global $database;
572
		// define default baselink and filename for optional module javascript and stylesheet files
573
		$head_links = "";
574
		if($file_id == "css") {
575
      	$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.css"';
576
			$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
577
			$base_file = "backend.css";
578
		} else {
579
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js" type="text/javascript"></script>';
580
			$base_file = "backend.js";
581
		}
582

    
583
        $sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
584
        $sActionRequest = isset($_GET['tool'])  ? $_GET['tool']  : $sActionRequest;
585

    
586
		// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend
587
		if(isset($sActionRequest)) {
588
			// check if displayed page contains a installed admin tool
589
			$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
590
			$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
591
			$result = $database->query($sql);
592
			if($result->numRows()) {
593
				// check if admin tool directory contains a backend.js or backend.css file to include
594
				$tool = $result->fetchRow();
595
				if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) {
596
        			// return link to the backend.js or backend.css file
597
					return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
598
				}
599
			}
600
		} elseif(isset($_GET['page_id']) || isset($_POST['page_id'])) {
601
			// check if displayed page in the backend contains a page module
602
			if (isset($_GET['page_id'])) {
603
				$page_id = (int)$_GET['page_id'];
604
			} else {
605
				$page_id = (int)$_POST['page_id'];
606
			}
607

    
608
    		// gather information for all models embedded on actual page
609
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
610
			$query_modules = $database->query($sql);
611

    
612
    		while($row = $query_modules->fetchRow()) {
613
				// check if page module directory contains a backend.js or backend.css file
614
      		if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
615
					// create link with backend.js or backend.css source for the current module
616
					$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
617
        			// ensure that backend.js or backend.css is only added once per module type
618
        			if(strpos($head_links, $tmp_link) === false) {
619
						$head_links .= $tmp_link ."\n";
620
					}
621
				}
622
    		}
623
    		// write out links with all external module javascript/CSS files, remove last line feed
624
			return rtrim($head_links);
625
		}
626
	}
627
}
(23-23/36)