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 |
1808
|
Luisehahne
|
global $database, $MESSAGE, $TEXT;
|
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 |
|
|
$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 |
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 |
|
|
$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 |
1379
|
Luisehahne
|
|
113 |
1782
|
Luisehahne
|
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 |
1379
|
Luisehahne
|
|
127 |
1782
|
Luisehahne
|
// Auto header code
|
128 |
|
|
if($auto_header == true) {
|
129 |
|
|
$this->print_header();
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
1379
|
Luisehahne
|
}
|
133 |
|
|
|
134 |
|
|
// Print the admin header
|
135 |
1684
|
Luisehahne
|
/**
|
136 |
|
|
*
|
137 |
|
|
* @param string $body_tags
|
138 |
|
|
* @return void
|
139 |
|
|
*/
|
140 |
|
|
function print_header($body_tags = '')
|
141 |
|
|
{
|
142 |
1379
|
Luisehahne
|
// Get vars from the language file
|
143 |
1678
|
Luisehahne
|
global $MENU, $MESSAGE, $TEXT;
|
144 |
1379
|
Luisehahne
|
// Connect to database and get website title
|
145 |
|
|
global $database;
|
146 |
1457
|
Luisehahne
|
// $GLOBALS['FTAN'] = $this->getFTAN();
|
147 |
|
|
$this->createFTAN();
|
148 |
1486
|
DarkViper
|
$sql = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` WHERE `name`=\'website_title\'';
|
149 |
|
|
$get_title = $database->query($sql);
|
150 |
1379
|
Luisehahne
|
$title = $get_title->fetchRow();
|
151 |
1529
|
Luisehahne
|
// Setup template object, parse vars to it, then parse it
|
152 |
1684
|
Luisehahne
|
$header_template = new Template(dirname($this->correct_theme_source('header.htt')) );
|
153 |
1379
|
Luisehahne
|
$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 |
1486
|
DarkViper
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` ';
|
167 |
|
|
$sql .= 'WHERE `page_id`='.intval($_GET['page_id']);
|
168 |
|
|
$result = @$database->query($sql);
|
169 |
1379
|
Luisehahne
|
$row = @$result->fetchRow();
|
170 |
|
|
if($row) $view_url .= PAGES_DIRECTORY .$row['link']. PAGE_EXTENSION;
|
171 |
|
|
}
|
172 |
1782
|
Luisehahne
|
|
173 |
|
|
$HelpUrl = ((strtolower(LANGUAGE)!='de') ? '/en/help.php' : '/de/hilfe.php');
|
174 |
1700
|
Luisehahne
|
$sServerAdress = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '127.0.0.1';
|
175 |
1379
|
Luisehahne
|
$header_template->set_var( array(
|
176 |
1684
|
Luisehahne
|
'SECTION_FORGOT' => $MENU['FORGOT'],
|
177 |
|
|
'SECTION_NAME' => $MENU['LOGIN'],
|
178 |
1402
|
Luisehahne
|
'BODY_TAGS' => $body_tags,
|
179 |
|
|
'WEBSITE_TITLE' => ($title['value']),
|
180 |
|
|
'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'],
|
181 |
1700
|
Luisehahne
|
'CURRENT_USER' => $MESSAGE['START_CURRENT_USER'],
|
182 |
1402
|
Luisehahne
|
'DISPLAY_NAME' => $this->get_display_name(),
|
183 |
|
|
'CHARSET' => $charset,
|
184 |
1730
|
Luisehahne
|
//'LANGUAGE' => strtolower(LANGUAGE),
|
185 |
|
|
'LANGUAGE' => LANGUAGE,
|
186 |
1402
|
Luisehahne
|
'VERSION' => VERSION,
|
187 |
1532
|
Luisehahne
|
'SP' => (defined('SP') ? SP : ''),
|
188 |
1402
|
Luisehahne
|
'REVISION' => REVISION,
|
189 |
1700
|
Luisehahne
|
'SERVER_ADDR' => ((int)$this->get_user_id()==1 ? $sServerAdress : ''),
|
190 |
1402
|
Luisehahne
|
'WB_URL' => WB_URL,
|
191 |
|
|
'ADMIN_URL' => ADMIN_URL,
|
192 |
|
|
'THEME_URL' => THEME_URL,
|
193 |
1684
|
Luisehahne
|
'START_URL' => ADMIN_URL.'/index.php',
|
194 |
|
|
'START_CLASS' => 'start',
|
195 |
|
|
'TITLE_START' => $TEXT['READ_MORE'],
|
196 |
|
|
'TITLE_VIEW' => $TEXT['WEBSITE'],
|
197 |
1782
|
Luisehahne
|
'TITLE_HELP' => 'WebsiteBaker '.$MENU['HELP'],
|
198 |
1402
|
Luisehahne
|
'URL_VIEW' => $view_url,
|
199 |
1684
|
Luisehahne
|
'TITLE_LOGOUT' => $MENU['LOGIN'],
|
200 |
1700
|
Luisehahne
|
'LOGIN_DISPLAY_HIDDEN' => !$this->is_authenticated() ? 'hidden' : '',
|
201 |
|
|
'LOGIN_DISPLAY_NONE' => !$this->is_authenticated() ? 'none' : '',
|
202 |
1684
|
Luisehahne
|
'LOGIN_LINK' => $_SERVER['SCRIPT_NAME'],
|
203 |
|
|
'LOGIN_ICON' => 'login',
|
204 |
|
|
'START_ICON' => 'blank',
|
205 |
1908
|
Luisehahne
|
'URL_HELP' => 'http://www.websitebaker.org'.$HelpUrl,
|
206 |
1402
|
Luisehahne
|
'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 |
1782
|
Luisehahne
|
$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 |
1379
|
Luisehahne
|
|
223 |
|
|
// Create the menu
|
224 |
1782
|
Luisehahne
|
$UrlLang = ((strtolower(LANGUAGE)!='de') ? 'en' : strtolower(LANGUAGE));
|
225 |
1684
|
Luisehahne
|
if(!$this->is_authenticated())
|
226 |
|
|
{
|
227 |
1782
|
Luisehahne
|
$header_template->set_var('STYLE', 'login');
|
228 |
|
|
$menu = array(
|
229 |
1684
|
Luisehahne
|
// 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 |
1700
|
Luisehahne
|
$header_template->set_var('STYLE', 'start');
|
235 |
1684
|
Luisehahne
|
$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 |
1782
|
Luisehahne
|
|
246 |
|
|
// @array ( $url, $target, $title, $page_permission, $permission_required )
|
247 |
1684
|
Luisehahne
|
$menu = array(
|
248 |
|
|
// array(ADMIN_URL.'/index.php', '', $MENU['START'], 'start', 1 ),
|
249 |
1379
|
Luisehahne
|
array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1),
|
250 |
1684
|
Luisehahne
|
// array($view_url, '_blank', $MENU['FRONTEND'], 'pages', 1),
|
251 |
1379
|
Luisehahne
|
array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1),
|
252 |
|
|
array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1),
|
253 |
1700
|
Luisehahne
|
array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 1),
|
254 |
1379
|
Luisehahne
|
array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1),
|
255 |
|
|
array(ADMIN_URL.'/admintools/index.php', '', $MENU['ADMINTOOLS'], 'admintools', 1),
|
256 |
1684
|
Luisehahne
|
array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1),
|
257 |
1782
|
Luisehahne
|
// array('http://addons.websitebaker2.org/', '', 'WB-Addons', 'preferences', 1),
|
258 |
|
|
// array('http://template.websitebaker2.org/', '', 'WB-Template', 'preferences', 1),
|
259 |
1684
|
Luisehahne
|
// array('http://www.websitebaker.org/', '_blank', 'WebsiteBaker Home', '', 0),
|
260 |
|
|
// array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], '', 0)
|
261 |
1379
|
Luisehahne
|
);
|
262 |
1684
|
Luisehahne
|
}
|
263 |
|
|
|
264 |
1379
|
Luisehahne
|
$header_template->set_block('header_block', 'linkBlock', 'link');
|
265 |
1700
|
Luisehahne
|
foreach($menu AS $menu_item)
|
266 |
|
|
{
|
267 |
1379
|
Luisehahne
|
$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 |
1684
|
Luisehahne
|
if($required == false || ($this->is_authenticated() && $this->get_link_permission($permission_title)) )
|
274 |
|
|
{
|
275 |
1379
|
Luisehahne
|
$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 |
1700
|
Luisehahne
|
$header_template->set_var('STYLE', $menu_item[3] );
|
281 |
1379
|
Luisehahne
|
} else {
|
282 |
1700
|
Luisehahne
|
$header_template->set_var('CLASS', $menu_item[3] );
|
283 |
1379
|
Luisehahne
|
}
|
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 |
1700
|
Luisehahne
|
unset($header_template);
|
292 |
1379
|
Luisehahne
|
}
|
293 |
1684
|
Luisehahne
|
|
294 |
1379
|
Luisehahne
|
// Print the admin footer
|
295 |
1443
|
Luisehahne
|
function print_footer($activateJsAdmin = false) {
|
296 |
1700
|
Luisehahne
|
global $database,$starttime,$iPhpDeclaredClasses;
|
297 |
1908
|
Luisehahne
|
$oTrans = Translate::getInstance();
|
298 |
|
|
$oTrans->disableAddon();
|
299 |
1379
|
Luisehahne
|
// include the required file for Javascript admin
|
300 |
1808
|
Luisehahne
|
if($activateJsAdmin == true) {
|
301 |
1443
|
Luisehahne
|
if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){
|
302 |
|
|
@include_once(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
|
303 |
|
|
}
|
304 |
1379
|
Luisehahne
|
}
|
305 |
1443
|
Luisehahne
|
|
306 |
1529
|
Luisehahne
|
// Setup template object, parse vars to it, then parse it
|
307 |
1625
|
Luisehahne
|
$footer_template = new Template(dirname($this->correct_theme_source('footer.htt')));
|
308 |
1379
|
Luisehahne
|
$footer_template->set_file('page', 'footer.htt');
|
309 |
|
|
$footer_template->set_block('page', 'footer_block', 'header');
|
310 |
|
|
$footer_template->set_var(array(
|
311 |
|
|
'BACKEND_BODY_MODULE_JS' => $this->register_backend_modfiles_body('js'),
|
312 |
|
|
'WB_URL' => WB_URL,
|
313 |
|
|
'ADMIN_URL' => ADMIN_URL,
|
314 |
|
|
'THEME_URL' => THEME_URL,
|
315 |
|
|
) );
|
316 |
1668
|
Luisehahne
|
|
317 |
|
|
$footer_template->set_block('footer_block', 'show_debug_block', 'show_debug');
|
318 |
|
|
|
319 |
1674
|
Luisehahne
|
$bDebug = (defined('DEBUG') ? DEBUG : false);
|
320 |
1668
|
Luisehahne
|
$bDevInfo = (defined('DEV_INFOS') && (DEV_INFOS == true) && (1 == $this->get_user_id()) ? true : false);
|
321 |
|
|
// if( $debug && (1 == $this->get_user_id()))
|
322 |
|
|
if( $bDevInfo )
|
323 |
|
|
{
|
324 |
1684
|
Luisehahne
|
|
325 |
1700
|
Luisehahne
|
$footer_template->set_var('MEMORY', number_format(memory_get_peak_usage(true), 0, ',', '.').' Byte' );
|
326 |
|
|
// $footer_template->set_var('MEMORY', number_format(memory_get_usage(true), 0, ',', '.').' Byte' );
|
327 |
1668
|
Luisehahne
|
$footer_template->set_var('QUERIES', $database->getQueryCount );
|
328 |
|
|
// $footer_template->set_var('QUERIES', 'disabled' );
|
329 |
|
|
$included_files = get_included_files();
|
330 |
|
|
$footer_template->set_var('INCLUDES', sizeof($included_files) );
|
331 |
1700
|
Luisehahne
|
$included_classes = get_declared_classes();
|
332 |
|
|
$footer_template->set_var('CLASSES', sizeof($included_classes)-$iPhpDeclaredClasses );
|
333 |
1668
|
Luisehahne
|
|
334 |
1700
|
Luisehahne
|
$sum_classes = 0;
|
335 |
1668
|
Luisehahne
|
$sum_filesize = 0;
|
336 |
|
|
$footer_template->set_block('show_debug_block', 'show_block_list', 'show_list');
|
337 |
|
|
$footer_template->set_block('show_block_list', 'include_block_list', 'include_list');
|
338 |
1684
|
Luisehahne
|
// $bDebug = true; for testing
|
339 |
1668
|
Luisehahne
|
foreach($included_files as $filename)
|
340 |
|
|
{
|
341 |
1674
|
Luisehahne
|
if(!is_readable($filename)) { continue; }
|
342 |
1668
|
Luisehahne
|
if($bDebug)
|
343 |
|
|
{
|
344 |
|
|
$footer_template->set_var('INCLUDES_ARRAY', str_replace(WB_PATH, '',$filename) );
|
345 |
|
|
$footer_template->set_var('FILESIZE', number_format(filesize($filename), 0, ',', '.').' Byte');
|
346 |
|
|
$footer_template->parse('include_list', 'include_block_list', true);
|
347 |
|
|
}
|
348 |
|
|
$sum_filesize += filesize($filename);
|
349 |
|
|
}
|
350 |
|
|
$footer_template->parse('show_list', 'show_block_list', true);
|
351 |
|
|
|
352 |
1684
|
Luisehahne
|
$endtime = array_sum(explode(" ",microtime()));
|
353 |
|
|
$iEndTime = $endtime;
|
354 |
|
|
$iStartTime = $starttime;
|
355 |
1678
|
Luisehahne
|
if(!$bDebug)
|
356 |
1668
|
Luisehahne
|
{
|
357 |
1684
|
Luisehahne
|
$footer_template->parse('show_list', '');
|
358 |
1668
|
Luisehahne
|
$footer_template->parse('include_list', '');
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
$footer_template->set_var('FILESIZE', ini_get('memory_limit'));
|
362 |
|
|
$footer_template->set_var('TXT_SUM_FILESIZE', 'Summary size of included files: ');
|
363 |
|
|
$footer_template->set_var('SUM_FILESIZE', number_format($sum_filesize, 0, ',', '.').' Byte');
|
364 |
1700
|
Luisehahne
|
$footer_template->set_var('SUM_CLASSES', number_format($sum_classes, 0, ',', '.').' Byte');
|
365 |
1684
|
Luisehahne
|
$footer_template->set_var('PAGE_LOAD_TIME', round($iEndTime-$iStartTime,3 ));
|
366 |
1700
|
Luisehahne
|
$footer_template->set_var('DUMP_CLASSES', '<pre>'.var_export($included_classes,true).'</pre>');
|
367 |
1684
|
Luisehahne
|
|
368 |
1668
|
Luisehahne
|
$footer_template->parse('show_debug', 'show_debug_block', true);
|
369 |
|
|
} else {
|
370 |
|
|
$footer_template->parse('show_debug', '');
|
371 |
1684
|
Luisehahne
|
$footer_template->parse('show_list', '');
|
372 |
|
|
|
373 |
1668
|
Luisehahne
|
}
|
374 |
1379
|
Luisehahne
|
$footer_template->parse('header', 'footer_block', false);
|
375 |
|
|
$footer_template->pparse('output', 'page');
|
376 |
1700
|
Luisehahne
|
unset($footer_template);
|
377 |
1379
|
Luisehahne
|
}
|
378 |
1684
|
Luisehahne
|
|
379 |
1379
|
Luisehahne
|
// Return a system permission
|
380 |
|
|
function get_permission($name, $type = 'system') {
|
381 |
1700
|
Luisehahne
|
|
382 |
1379
|
Luisehahne
|
// Append to permission type
|
383 |
|
|
$type .= '_permissions';
|
384 |
|
|
// Check if we have a section to check for
|
385 |
|
|
if($name == 'start') {
|
386 |
|
|
return true;
|
387 |
|
|
} else {
|
388 |
|
|
// Set system permissions var
|
389 |
|
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
390 |
|
|
// Set module permissions var
|
391 |
|
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
392 |
|
|
// Set template permissions var
|
393 |
|
|
$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
|
394 |
|
|
// Return true if system perm = 1
|
395 |
|
|
if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) {
|
396 |
|
|
if($type == 'system_permissions') {
|
397 |
|
|
return true;
|
398 |
|
|
} else {
|
399 |
|
|
return false;
|
400 |
|
|
}
|
401 |
|
|
} else {
|
402 |
|
|
if($type == 'system_permissions') {
|
403 |
|
|
return false;
|
404 |
|
|
} else {
|
405 |
|
|
return true;
|
406 |
|
|
}
|
407 |
|
|
}
|
408 |
|
|
}
|
409 |
1700
|
Luisehahne
|
|
410 |
1379
|
Luisehahne
|
}
|
411 |
1700
|
Luisehahne
|
|
412 |
1441
|
Luisehahne
|
function get_user_details($user_id) {
|
413 |
|
|
global $database;
|
414 |
|
|
$retval = array('username'=>'unknown','display_name'=>'Unknown','email'=>'');
|
415 |
|
|
$sql = 'SELECT `username`,`display_name`,`email` ';
|
416 |
|
|
$sql .= 'FROM `'.TABLE_PREFIX.'users` ';
|
417 |
1486
|
DarkViper
|
$sql .= 'WHERE `user_id`='.(int)$user_id;
|
418 |
1441
|
Luisehahne
|
if( ($resUsers = $database->query($sql)) ) {
|
419 |
|
|
if( ($recUser = $resUsers->fetchRow()) ) {
|
420 |
|
|
$retval = $recUser;
|
421 |
|
|
}
|
422 |
|
|
}
|
423 |
|
|
return $retval;
|
424 |
|
|
}
|
425 |
|
|
|
426 |
|
|
//
|
427 |
|
|
function get_section_details( $section_id, $backLink = 'index.php' ) {
|
428 |
|
|
global $database, $TEXT;
|
429 |
|
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'sections` ';
|
430 |
1486
|
DarkViper
|
$sql .= 'WHERE `section_id`='.intval($section_id);
|
431 |
1441
|
Luisehahne
|
if(($resSection = $database->query($sql))){
|
432 |
|
|
if(!($recSection = $resSection->fetchRow())) {
|
433 |
|
|
$this->print_header();
|
434 |
|
|
$this->print_error($TEXT['SECTION'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
435 |
|
|
}
|
436 |
|
|
} else {
|
437 |
|
|
$this->print_header();
|
438 |
|
|
$this->print_error($database->get_error(), $backLink, true);
|
439 |
|
|
}
|
440 |
|
|
return $recSection;
|
441 |
|
|
}
|
442 |
|
|
|
443 |
|
|
function get_page_details( $page_id, $backLink = 'index.php' ) {
|
444 |
1486
|
DarkViper
|
global $database, $TEXT;
|
445 |
|
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
|
446 |
|
|
$sql .= 'WHERE `page_id`='.intval($page_id);
|
447 |
|
|
if(($resPages = $database->query($sql))){
|
448 |
|
|
if(!($recPage = $resPages->fetchRow())) {
|
449 |
|
|
$this->print_header();
|
450 |
|
|
$this->print_error($TEXT['PAGE'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
451 |
|
|
}
|
452 |
1441
|
Luisehahne
|
} else {
|
453 |
1486
|
DarkViper
|
$this->print_header();
|
454 |
|
|
$this->print_error($database->get_error(), $backLink, true);
|
455 |
1379
|
Luisehahne
|
}
|
456 |
1486
|
DarkViper
|
return $recPage;
|
457 |
1379
|
Luisehahne
|
}
|
458 |
|
|
|
459 |
1441
|
Luisehahne
|
function get_page_permission($page,$action='admin') {
|
460 |
|
|
if($action != 'viewing') { $action = 'admin'; }
|
461 |
|
|
$action_groups = $action.'_groups';
|
462 |
|
|
$action_users = $action.'_users';
|
463 |
|
|
$groups = $users = '0';
|
464 |
|
|
if(is_array($page)) {
|
465 |
|
|
$groups = $page[$action_groups];
|
466 |
|
|
$users = $page[$action_users];
|
467 |
|
|
} else {
|
468 |
|
|
global $database;
|
469 |
|
|
$sql = 'SELECT `'.$action_groups.'`,`'.$action_users.'` ';
|
470 |
|
|
$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
|
471 |
|
|
$sql .= 'WHERE `page_id`='.(int)$page;
|
472 |
|
|
if( ($res = $database->query($sql)) ) {
|
473 |
|
|
if( ($rec = $res->fetchRow()) ) {
|
474 |
|
|
$groups = $rec[$action_groups];
|
475 |
|
|
$users = $rec[$action_users];
|
476 |
|
|
}
|
477 |
|
|
}
|
478 |
|
|
}
|
479 |
|
|
return ($this->ami_group_member($groups) || $this->is_group_match($this->get_user_id(), $users));
|
480 |
|
|
}
|
481 |
|
|
|
482 |
1379
|
Luisehahne
|
// Returns a system permission for a menu link
|
483 |
|
|
function get_link_permission($title) {
|
484 |
|
|
$title = str_replace('_blank', '', $title);
|
485 |
|
|
$title = strtolower($title);
|
486 |
|
|
// Set system permissions var
|
487 |
|
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
488 |
|
|
// Set module permissions var
|
489 |
|
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
490 |
|
|
if($title == 'start') {
|
491 |
|
|
return true;
|
492 |
|
|
} else {
|
493 |
|
|
// Return true if system perm = 1
|
494 |
|
|
if(is_numeric(array_search($title, $system_permissions))) {
|
495 |
|
|
return true;
|
496 |
|
|
} else {
|
497 |
|
|
return false;
|
498 |
|
|
}
|
499 |
|
|
}
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
// Function to add optional module Javascript or CSS stylesheets into the <body> section of the backend
|
503 |
|
|
function register_backend_modfiles_body($file_id="js")
|
504 |
|
|
{
|
505 |
|
|
// sanity check of parameter passed to the function
|
506 |
|
|
$file_id = strtolower($file_id);
|
507 |
|
|
if($file_id !== "javascript" && $file_id !== "js")
|
508 |
|
|
{
|
509 |
|
|
return;
|
510 |
|
|
}
|
511 |
|
|
global $database;
|
512 |
|
|
$body_links = "";
|
513 |
|
|
// define default baselink and filename for optional module javascript and stylesheet files
|
514 |
|
|
if($file_id == "js") {
|
515 |
1441
|
Luisehahne
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js" type="text/javascript"></script>';
|
516 |
1379
|
Luisehahne
|
$base_file = "backend_body.js";
|
517 |
|
|
}
|
518 |
1811
|
Luisehahne
|
|
519 |
|
|
$sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
|
520 |
|
|
$sActionRequest = isset($_GET['tool']) ? $_GET['tool'] : $sActionRequest;
|
521 |
|
|
|
522 |
1379
|
Luisehahne
|
// check if backend_body.js files needs to be included to the <body></body> section of the backend
|
523 |
1811
|
Luisehahne
|
if(isset($sActionRequest))
|
524 |
1379
|
Luisehahne
|
{
|
525 |
|
|
// check if displayed page contains a installed admin tool
|
526 |
1486
|
DarkViper
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
527 |
1811
|
Luisehahne
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
|
528 |
1486
|
DarkViper
|
$result = $database->query($sql);
|
529 |
1379
|
Luisehahne
|
if($result->numRows())
|
530 |
|
|
{
|
531 |
|
|
// check if admin tool directory contains a backend_body.js file to include
|
532 |
|
|
$tool = $result->fetchRow();
|
533 |
|
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file"))
|
534 |
|
|
{
|
535 |
|
|
// return link to the backend_body.js file
|
536 |
|
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
537 |
|
|
}
|
538 |
|
|
}
|
539 |
|
|
} elseif(isset($_GET['page_id']) or isset($_POST['page_id']))
|
540 |
|
|
{
|
541 |
|
|
// check if displayed page in the backend contains a page module
|
542 |
|
|
if (isset($_GET['page_id']))
|
543 |
|
|
{
|
544 |
|
|
$page_id = (int) addslashes($_GET['page_id']);
|
545 |
|
|
} else {
|
546 |
|
|
$page_id = (int) addslashes($_POST['page_id']);
|
547 |
|
|
}
|
548 |
|
|
// gather information for all models embedded on actual page
|
549 |
1486
|
DarkViper
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
550 |
|
|
$query_modules = $database->query($sql);
|
551 |
1379
|
Luisehahne
|
while($row = $query_modules->fetchRow()) {
|
552 |
|
|
// check if page module directory contains a backend_body.js file
|
553 |
|
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
554 |
|
|
// create link with backend_body.js source for the current module
|
555 |
|
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
556 |
|
|
// ensure that backend_body.js is only added once per module type
|
557 |
|
|
if(strpos($body_links, $tmp_link) === false) {
|
558 |
|
|
$body_links .= $tmp_link ."\n";
|
559 |
|
|
}
|
560 |
|
|
}
|
561 |
|
|
}
|
562 |
|
|
// write out links with all external module javascript/CSS files, remove last line feed
|
563 |
|
|
return rtrim($body_links);
|
564 |
|
|
}
|
565 |
|
|
}
|
566 |
|
|
|
567 |
|
|
|
568 |
|
|
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the backend
|
569 |
|
|
function register_backend_modfiles($file_id="css") {
|
570 |
|
|
// sanity check of parameter passed to the function
|
571 |
|
|
$file_id = strtolower($file_id);
|
572 |
|
|
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
|
573 |
|
|
return;
|
574 |
|
|
}
|
575 |
|
|
|
576 |
|
|
global $database;
|
577 |
|
|
// define default baselink and filename for optional module javascript and stylesheet files
|
578 |
|
|
$head_links = "";
|
579 |
|
|
if($file_id == "css") {
|
580 |
|
|
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.css"';
|
581 |
|
|
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
|
582 |
|
|
$base_file = "backend.css";
|
583 |
|
|
} else {
|
584 |
1441
|
Luisehahne
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js" type="text/javascript"></script>';
|
585 |
1379
|
Luisehahne
|
$base_file = "backend.js";
|
586 |
|
|
}
|
587 |
|
|
|
588 |
1811
|
Luisehahne
|
$sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
|
589 |
|
|
$sActionRequest = isset($_GET['tool']) ? $_GET['tool'] : $sActionRequest;
|
590 |
|
|
|
591 |
1379
|
Luisehahne
|
// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend
|
592 |
1811
|
Luisehahne
|
if(isset($sActionRequest)) {
|
593 |
1379
|
Luisehahne
|
// check if displayed page contains a installed admin tool
|
594 |
1486
|
DarkViper
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
595 |
1811
|
Luisehahne
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
|
596 |
1486
|
DarkViper
|
$result = $database->query($sql);
|
597 |
1379
|
Luisehahne
|
if($result->numRows()) {
|
598 |
|
|
// check if admin tool directory contains a backend.js or backend.css file to include
|
599 |
|
|
$tool = $result->fetchRow();
|
600 |
|
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) {
|
601 |
|
|
// return link to the backend.js or backend.css file
|
602 |
|
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
603 |
|
|
}
|
604 |
|
|
}
|
605 |
1441
|
Luisehahne
|
} elseif(isset($_GET['page_id']) || isset($_POST['page_id'])) {
|
606 |
1379
|
Luisehahne
|
// check if displayed page in the backend contains a page module
|
607 |
|
|
if (isset($_GET['page_id'])) {
|
608 |
|
|
$page_id = (int)$_GET['page_id'];
|
609 |
|
|
} else {
|
610 |
|
|
$page_id = (int)$_POST['page_id'];
|
611 |
|
|
}
|
612 |
|
|
|
613 |
|
|
// gather information for all models embedded on actual page
|
614 |
1486
|
DarkViper
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
615 |
|
|
$query_modules = $database->query($sql);
|
616 |
1379
|
Luisehahne
|
|
617 |
|
|
while($row = $query_modules->fetchRow()) {
|
618 |
|
|
// check if page module directory contains a backend.js or backend.css file
|
619 |
|
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
620 |
|
|
// create link with backend.js or backend.css source for the current module
|
621 |
|
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
622 |
|
|
// ensure that backend.js or backend.css is only added once per module type
|
623 |
|
|
if(strpos($head_links, $tmp_link) === false) {
|
624 |
|
|
$head_links .= $tmp_link ."\n";
|
625 |
|
|
}
|
626 |
|
|
}
|
627 |
|
|
}
|
628 |
|
|
// write out links with all external module javascript/CSS files, remove last line feed
|
629 |
|
|
return rtrim($head_links);
|
630 |
|
|
}
|
631 |
|
|
}
|
632 |
|
|
}
|