Project

General

Profile

1 1379 Luisehahne
<?php
2
/**
3
 *
4 1782 Luisehahne
 * @category        backend
5
 * @package         framework
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7 1908 Luisehahne
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 1379 Luisehahne
 * @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$
13 1908 Luisehahne
 * @filesource      $HeadURL$
14 1379 Luisehahne
 * @lastmodified    $Date$
15
 *
16
 */
17 1496 DarkViper
/* -------------------------------------------------------- */
18
// Must include code to stop this file being accessed directly
19 1499 DarkViper
if(!defined('WB_PATH')) {
20
	require_once(dirname(__FILE__).'/globalExceptionHandler.php');
21
	throw new IllegalFileException();
22
}
23 1496 DarkViper
/* -------------------------------------------------------- */
24 1379 Luisehahne
25 1805 Luisehahne
// 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 1379 Luisehahne
// Get WB version
29
require_once(ADMIN_PATH.'/interface/version.php');
30
31
// Include EditArea wrapper functions
32 1428 Luisehahne
// require_once(WB_PATH . '/include/editarea/wb_wrapper_edit_area.php');
33 1782 Luisehahne
// require_once(WB_PATH . '/framework/SecureForm.php');
34 1379 Luisehahne
35
36 1684 Luisehahne
/**
37
 * admin
38
 *
39
 * @package
40
 * @copyright
41
 * @version 2012
42
 * @access public
43
 */
44 1379 Luisehahne
class admin extends wb {
45
	// Authenticate user then auto print the header
46 1684 Luisehahne
	/**
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 1379 Luisehahne
	public function __construct($section_name= '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
56
	{
57
		parent::__construct(SecureForm::BACKEND);
58 1782 Luisehahne
    	if( $section_name != '##skip##' )
59
    	{
60 2094 darkviper
    		global $database;
61 1782 Luisehahne
    		// 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 1808 Luisehahne
//    				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 2094 darkviper
            			$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 1808 Luisehahne
            	 	    $oTpl->set_var( 'BACK_LINK', $sBackLink );
90 2094 darkviper
            	 	    $oTpl->set_var( 'TEXT_BACK', $this->_oTrans->TEXT_BACK);
91 1808 Luisehahne
                		$output = $oTpl->finish($oTpl->parse('output', 'page'));
92
        			}
93
        			throw new ErrorMsgException($output);
94
                }
95 1782 Luisehahne
    		}
96
97
			if( ($maintance==true) || $this->get_session('USER_ID')!= 1 )
98 1379 Luisehahne
			{
99 1782 Luisehahne
           	//  check for show maintenance screen and terminate if needed
100
        		$this->ShowMaintainScreen('locked');
101
            }
102 1379 Luisehahne
103 1782 Luisehahne
    		// Check if the backend language is also the selected language. If not, send headers again.
104 2094 darkviper
    		$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 1782 Luisehahne
    		// obtain the admin folder (e.g. /admin)
108
    		$admin_folder = str_replace(WB_PATH, '', ADMIN_PATH);
109 1379 Luisehahne
110 1782 Luisehahne
    		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 1379 Luisehahne
124 1782 Luisehahne
    		// Auto header code
125
    		if($auto_header == true) {
126
    			$this->print_header();
127
    		}
128
    	}
129 1379 Luisehahne
	}
130
131
	// Print the admin header
132 1684 Luisehahne
	/**
133
	 *
134
	 * @param string $body_tags
135
	 * @return void
136
	 */
137
	function print_header($body_tags = '')
138
	{
139 1457 Luisehahne
		// $GLOBALS['FTAN'] = $this->getFTAN();
140
		$this->createFTAN();
141 2094 darkviper
		$sql = 'SELECT `value` FROM `'.$this->_oDb->TablePrefix.'settings` '
142
             . 'WHERE `name`=\'website_title\'';
143
        $title = (string)$this->_oDb->getOne($sql);
144 1529 Luisehahne
		// Setup template object, parse vars to it, then parse it
145 1684 Luisehahne
		$header_template = new Template(dirname($this->correct_theme_source('header.htt')) );
146 1379 Luisehahne
		$header_template->set_file('page', 'header.htt');
147
		$header_template->set_block('page', 'header_block', 'header');
148 2094 darkviper
        $this->_oTrans->enableAddon('templates\\'.$this->_oReg->DefaultTheme);
149
        $header_template->set_var($this->_oTrans->getLangArray());
150 1379 Luisehahne
		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 2094 darkviper
			$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 1379 Luisehahne
		}
166 1782 Luisehahne
167
        $HelpUrl = ((strtolower(LANGUAGE)!='de') ? '/en/help.php' : '/de/hilfe.php');
168 1700 Luisehahne
		$sServerAdress = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
169 1379 Luisehahne
		$header_template->set_var(	array(
170 2094 darkviper
							'SECTION_FORGOT' => $this->_oTrans->MENU_FORGOT,
171
							'SECTION_NAME' => $this->_oTrans->MENU_LOGIN,
172 1402 Luisehahne
							'BODY_TAGS' => $body_tags,
173 2094 darkviper
							'WEBSITE_TITLE' => $title,
174
							'TEXT_ADMINISTRATION' => $this->_oTrans->TEXT_ADMINISTRATION,
175
							'CURRENT_USER' => $this->_oTrans->MESSAGE_START_CURRENT_USER,
176 1402 Luisehahne
							'DISPLAY_NAME' => $this->get_display_name(),
177
							'CHARSET' => $charset,
178 1730 Luisehahne
							//'LANGUAGE' => strtolower(LANGUAGE),
179
							'LANGUAGE' => LANGUAGE,
180 1402 Luisehahne
							'VERSION' => VERSION,
181 1532 Luisehahne
							'SP' => (defined('SP') ? SP : ''),
182 1402 Luisehahne
							'REVISION' => REVISION,
183 1700 Luisehahne
							'SERVER_ADDR' => ((int)$this->get_user_id()==1 ? $sServerAdress : ''),
184 1402 Luisehahne
							'WB_URL' => WB_URL,
185
							'ADMIN_URL' => ADMIN_URL,
186
							'THEME_URL' => THEME_URL,
187 1684 Luisehahne
							'START_URL' => ADMIN_URL.'/index.php',
188
							'START_CLASS' => 'start',
189 2094 darkviper
							'TITLE_START' => $this->_oTrans->TEXT_READ_MORE,
190
							'TITLE_VIEW' => $this->_oTrans->TEXT_WEBSITE,
191
							'TITLE_HELP' => 'WebsiteBaker '.$this->_oTrans->MENU_HELP,
192 1402 Luisehahne
							'URL_VIEW' => $view_url,
193 2094 darkviper
							'TITLE_LOGOUT' => $this->_oTrans->MENU_LOGIN,
194 1700 Luisehahne
							'LOGIN_DISPLAY_HIDDEN' => !$this->is_authenticated() ? 'hidden' : '',
195
							'LOGIN_DISPLAY_NONE' => !$this->is_authenticated() ? 'none' : '',
196 1684 Luisehahne
							'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'],
197
							'LOGIN_ICON' => 'login',
198
							'START_ICON' => 'blank',
199 1908 Luisehahne
							'URL_HELP' => 'http://www.websitebaker.org'.$HelpUrl,
200 1402 Luisehahne
							'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 1782 Luisehahne
		$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 2094 darkviper
			$header_template->set_var('MAINTENANCE_MODE', ($sys_locked ? $this->_oTrans->TEXT_MAINTENANCE_OFF : $this->_oTrans->TEXT_MAINTENANCE_ON));
209 1782 Luisehahne
			$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 1379 Luisehahne
217
		// Create the menu
218 1782 Luisehahne
        $UrlLang = ((strtolower(LANGUAGE)!='de') ? 'en' : strtolower(LANGUAGE));
219 1684 Luisehahne
		if(!$this->is_authenticated())
220
		{
221 1782 Luisehahne
    		$header_template->set_var('STYLE', 'login');
222
    		$menu = array(
223 1684 Luisehahne
//						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 1700 Luisehahne
			$header_template->set_var('STYLE', 'start');
229 1684 Luisehahne
			$header_template->set_var(	array(
230 2094 darkviper
                        'SECTION_NAME' => $this->_oTrans->{'MENU'.strtoupper($this->section_name)},
231
						'TITLE_LOGOUT' => $this->_oTrans->MENU_LOGOUT,
232 1684 Luisehahne
						'LOGIN_DISPLAY_NONE' => '',
233
						'START_ICON' => 'home',
234
						'LOGIN_ICON' => 'logout',
235
						'LOGIN_LINK' => ADMIN_URL.'/logout/index.php',
236 2094 darkviper
						'TITLE_START' => $this->_oTrans->MENU_START
237 1684 Luisehahne
						)
238
					);
239 1782 Luisehahne
240
			// @array ( $url, $target, $title, $page_permission, $permission_required )
241 1684 Luisehahne
			$menu = array(
242
//					array(ADMIN_URL.'/index.php', '', $MENU['START'], 'start', 1 ),
243 2094 darkviper
					array(ADMIN_URL.'/pages/index.php', '', $this->_oTrans->MENU_PAGES, 'pages', 1),
244 1684 Luisehahne
// 					array($view_url, '_blank', $MENU['FRONTEND'], 'pages', 1),
245 2094 darkviper
					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 1782 Luisehahne
//					array('http://addons.websitebaker2.org/', '', 'WB-Addons', 'preferences', 1),
252
//					array('http://template.websitebaker2.org/', '', 'WB-Template', 'preferences', 1),
253 1684 Luisehahne
//					array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', '', 0),
254
//					array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], '', 0)
255 1379 Luisehahne
					);
256 1684 Luisehahne
		}
257
258 1379 Luisehahne
		$header_template->set_block('header_block', 'linkBlock', 'link');
259 1700 Luisehahne
		foreach($menu AS $menu_item)
260
		{
261 1379 Luisehahne
			$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 1684 Luisehahne
			if($required == false || ($this->is_authenticated() && $this->get_link_permission($permission_title)) )
268
			{
269 1379 Luisehahne
				$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 1700 Luisehahne
					$header_template->set_var('STYLE', $menu_item[3] );
275 1379 Luisehahne
				} else {
276 1700 Luisehahne
					$header_template->set_var('CLASS', $menu_item[3] );
277 1379 Luisehahne
				}
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 1700 Luisehahne
		unset($header_template);
286 2094 darkviper
        $this->_oTrans->disableAddon();
287 1379 Luisehahne
	}
288 1684 Luisehahne
289 1379 Luisehahne
	// Print the admin footer
290 2094 darkviper
	function print_footer($activateJsAdmin = false) {
291
		global $starttime, $iPhpDeclaredClasses;
292 1379 Luisehahne
		// include the required file for Javascript admin
293 1808 Luisehahne
		if($activateJsAdmin == true) {
294 1443 Luisehahne
			if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){
295
				@include_once(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
296
			}
297 1379 Luisehahne
		}
298 1529 Luisehahne
		// Setup template object, parse vars to it, then parse it
299 1625 Luisehahne
		$footer_template = new Template(dirname($this->correct_theme_source('footer.htt')));
300 1379 Luisehahne
		$footer_template->set_file('page', 'footer.htt');
301
		$footer_template->set_block('page', 'footer_block', 'header');
302 2094 darkviper
        $this->_oTrans->enableAddon('templates\\'.$this->_oReg->DefaultTheme);
303
        $footer_template->set_var($this->_oTrans->getLangArray());
304 1379 Luisehahne
		$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 1668 Luisehahne
311
		$footer_template->set_block('footer_block', 'show_debug_block', 'show_debug');
312
313 1674 Luisehahne
		$bDebug = (defined('DEBUG') ? DEBUG : false);
314 1668 Luisehahne
		$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 1684 Luisehahne
319 1700 Luisehahne
			$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 2094 darkviper
			$footer_template->set_var('QUERIES', $this->_oDb->getQueryCount );
322 1668 Luisehahne
			// $footer_template->set_var('QUERIES', 'disabled' );
323
	        $included_files =  get_included_files();
324
			$footer_template->set_var('INCLUDES', sizeof($included_files) );
325 1700 Luisehahne
	        $included_classes =  get_declared_classes();
326
			$footer_template->set_var('CLASSES', sizeof($included_classes)-$iPhpDeclaredClasses );
327 1668 Luisehahne
328 1700 Luisehahne
			$sum_classes = 0;
329 1668 Luisehahne
			$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 1684 Luisehahne
			// $bDebug = true;  for testing
333 1668 Luisehahne
			foreach($included_files as $filename)
334
			{
335 1674 Luisehahne
				if(!is_readable($filename)) { continue; }
336 1668 Luisehahne
				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 1684 Luisehahne
			$endtime = array_sum(explode(" ",microtime()));
347
			$iEndTime = $endtime;
348
			$iStartTime = $starttime;
349 1678 Luisehahne
			if(!$bDebug)
350 1668 Luisehahne
			{
351 1684 Luisehahne
				$footer_template->parse('show_list', '');
352 1668 Luisehahne
				$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 1700 Luisehahne
			$footer_template->set_var('SUM_CLASSES', number_format($sum_classes, 0, ',', '.').'&nbsp;Byte');
359 1684 Luisehahne
			$footer_template->set_var('PAGE_LOAD_TIME', round($iEndTime-$iStartTime,3 ));
360 1700 Luisehahne
			$footer_template->set_var('DUMP_CLASSES', '<pre>'.var_export($included_classes,true).'</pre>');
361 1684 Luisehahne
362 1668 Luisehahne
			$footer_template->parse('show_debug', 'show_debug_block', true);
363
        } else {
364
			$footer_template->parse('show_debug', '');
365 1684 Luisehahne
			$footer_template->parse('show_list', '');
366
367 1668 Luisehahne
        }
368 1379 Luisehahne
		$footer_template->parse('header', 'footer_block', false);
369
		$footer_template->pparse('output', 'page');
370 1700 Luisehahne
		unset($footer_template);
371 2094 darkviper
372 1379 Luisehahne
	}
373 1684 Luisehahne
374 1379 Luisehahne
	// Return a system permission
375
	function get_permission($name, $type = 'system') {
376 1700 Luisehahne
377 1379 Luisehahne
		// 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 1700 Luisehahne
405 1379 Luisehahne
	}
406 1700 Luisehahne
407 1441 Luisehahne
 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 1486 DarkViper
  $sql .= 'WHERE `user_id`='.(int)$user_id;
413 1441 Luisehahne
  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 1486 DarkViper
		$sql .= 'WHERE `section_id`='.intval($section_id);
426 1441 Luisehahne
		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 1486 DarkViper
		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 1441 Luisehahne
		} else {
448 1486 DarkViper
			$this->print_header();
449
			$this->print_error($database->get_error(), $backLink, true);
450 1379 Luisehahne
		}
451 1486 DarkViper
		return $recPage;
452 1379 Luisehahne
	}
453
454 1441 Luisehahne
	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 1379 Luisehahne
	// 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 1441 Luisehahne
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js" type="text/javascript"></script>';
511 1379 Luisehahne
			$base_file = "backend_body.js";
512
		}
513 1811 Luisehahne
514
        $sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
515
        $sActionRequest = isset($_GET['tool'])  ? $_GET['tool']  : $sActionRequest;
516
517 1379 Luisehahne
		// check if backend_body.js files needs to be included to the <body></body> section of the backend
518 1811 Luisehahne
		if(isset($sActionRequest))
519 1379 Luisehahne
			{
520
			// check if displayed page contains a installed admin tool
521 1486 DarkViper
			$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
522 1811 Luisehahne
			$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
523 1486 DarkViper
			$result = $database->query($sql);
524 1379 Luisehahne
			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 1486 DarkViper
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
545
			$query_modules = $database->query($sql);
546 1379 Luisehahne
			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 1441 Luisehahne
			$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js" type="text/javascript"></script>';
580 1379 Luisehahne
			$base_file = "backend.js";
581
		}
582
583 1811 Luisehahne
        $sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
584
        $sActionRequest = isset($_GET['tool'])  ? $_GET['tool']  : $sActionRequest;
585
586 1379 Luisehahne
		// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend
587 1811 Luisehahne
		if(isset($sActionRequest)) {
588 1379 Luisehahne
			// check if displayed page contains a installed admin tool
589 1486 DarkViper
			$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
590 1811 Luisehahne
			$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
591 1486 DarkViper
			$result = $database->query($sql);
592 1379 Luisehahne
			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 1441 Luisehahne
		} elseif(isset($_GET['page_id']) || isset($_POST['page_id'])) {
601 1379 Luisehahne
			// 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 1486 DarkViper
			$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
610
			$query_modules = $database->query($sql);
611 1379 Luisehahne
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
}