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