| 1 |
1379
|
Luisehahne
|
<?php
|
| 2 |
|
|
/**
|
| 3 |
|
|
*
|
| 4 |
1782
|
Luisehahne
|
* @category backend
|
| 5 |
|
|
* @package framework
|
| 6 |
|
|
* @author Ryan Djurovich (2004-2009), WebsiteBaker Project
|
| 7 |
1700
|
Luisehahne
|
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
| 8 |
1379
|
Luisehahne
|
* @link http://www.websitebaker2.org/
|
| 9 |
|
|
* @license http://www.gnu.org/licenses/gpl.html
|
| 10 |
|
|
* @platform WebsiteBaker 2.8.x
|
| 11 |
|
|
* @requirements PHP 5.2.2 and higher
|
| 12 |
|
|
* @version $Id$
|
| 13 |
|
|
* @filesource $HeadURL$
|
| 14 |
|
|
* @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 |
1782
|
Luisehahne
|
'URL_HELP' => 'http://www.websitebaker2.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 |
1379
|
Luisehahne
|
// include the required file for Javascript admin
|
| 298 |
1808
|
Luisehahne
|
if($activateJsAdmin == true) {
|
| 299 |
1443
|
Luisehahne
|
if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){
|
| 300 |
|
|
@include_once(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php');
|
| 301 |
|
|
}
|
| 302 |
1379
|
Luisehahne
|
}
|
| 303 |
1443
|
Luisehahne
|
|
| 304 |
1529
|
Luisehahne
|
// Setup template object, parse vars to it, then parse it
|
| 305 |
1625
|
Luisehahne
|
$footer_template = new Template(dirname($this->correct_theme_source('footer.htt')));
|
| 306 |
1379
|
Luisehahne
|
$footer_template->set_file('page', 'footer.htt');
|
| 307 |
|
|
$footer_template->set_block('page', 'footer_block', 'header');
|
| 308 |
|
|
$footer_template->set_var(array(
|
| 309 |
|
|
'BACKEND_BODY_MODULE_JS' => $this->register_backend_modfiles_body('js'),
|
| 310 |
|
|
'WB_URL' => WB_URL,
|
| 311 |
|
|
'ADMIN_URL' => ADMIN_URL,
|
| 312 |
|
|
'THEME_URL' => THEME_URL,
|
| 313 |
|
|
) );
|
| 314 |
1668
|
Luisehahne
|
|
| 315 |
|
|
$footer_template->set_block('footer_block', 'show_debug_block', 'show_debug');
|
| 316 |
|
|
|
| 317 |
1674
|
Luisehahne
|
$bDebug = (defined('DEBUG') ? DEBUG : false);
|
| 318 |
1668
|
Luisehahne
|
$bDevInfo = (defined('DEV_INFOS') && (DEV_INFOS == true) && (1 == $this->get_user_id()) ? true : false);
|
| 319 |
|
|
// if( $debug && (1 == $this->get_user_id()))
|
| 320 |
|
|
if( $bDevInfo )
|
| 321 |
|
|
{
|
| 322 |
1684
|
Luisehahne
|
|
| 323 |
1700
|
Luisehahne
|
$footer_template->set_var('MEMORY', number_format(memory_get_peak_usage(true), 0, ',', '.').' Byte' );
|
| 324 |
|
|
// $footer_template->set_var('MEMORY', number_format(memory_get_usage(true), 0, ',', '.').' Byte' );
|
| 325 |
1668
|
Luisehahne
|
$footer_template->set_var('QUERIES', $database->getQueryCount );
|
| 326 |
|
|
// $footer_template->set_var('QUERIES', 'disabled' );
|
| 327 |
|
|
$included_files = get_included_files();
|
| 328 |
|
|
$footer_template->set_var('INCLUDES', sizeof($included_files) );
|
| 329 |
1700
|
Luisehahne
|
$included_classes = get_declared_classes();
|
| 330 |
|
|
$footer_template->set_var('CLASSES', sizeof($included_classes)-$iPhpDeclaredClasses );
|
| 331 |
1668
|
Luisehahne
|
|
| 332 |
1700
|
Luisehahne
|
$sum_classes = 0;
|
| 333 |
1668
|
Luisehahne
|
$sum_filesize = 0;
|
| 334 |
|
|
$footer_template->set_block('show_debug_block', 'show_block_list', 'show_list');
|
| 335 |
|
|
$footer_template->set_block('show_block_list', 'include_block_list', 'include_list');
|
| 336 |
1684
|
Luisehahne
|
// $bDebug = true; for testing
|
| 337 |
1668
|
Luisehahne
|
foreach($included_files as $filename)
|
| 338 |
|
|
{
|
| 339 |
1674
|
Luisehahne
|
if(!is_readable($filename)) { continue; }
|
| 340 |
1668
|
Luisehahne
|
if($bDebug)
|
| 341 |
|
|
{
|
| 342 |
|
|
$footer_template->set_var('INCLUDES_ARRAY', str_replace(WB_PATH, '',$filename) );
|
| 343 |
|
|
$footer_template->set_var('FILESIZE', number_format(filesize($filename), 0, ',', '.').' Byte');
|
| 344 |
|
|
$footer_template->parse('include_list', 'include_block_list', true);
|
| 345 |
|
|
}
|
| 346 |
|
|
$sum_filesize += filesize($filename);
|
| 347 |
|
|
}
|
| 348 |
|
|
$footer_template->parse('show_list', 'show_block_list', true);
|
| 349 |
|
|
|
| 350 |
1684
|
Luisehahne
|
$endtime = array_sum(explode(" ",microtime()));
|
| 351 |
|
|
$iEndTime = $endtime;
|
| 352 |
|
|
$iStartTime = $starttime;
|
| 353 |
1678
|
Luisehahne
|
if(!$bDebug)
|
| 354 |
1668
|
Luisehahne
|
{
|
| 355 |
1684
|
Luisehahne
|
$footer_template->parse('show_list', '');
|
| 356 |
1668
|
Luisehahne
|
$footer_template->parse('include_list', '');
|
| 357 |
|
|
}
|
| 358 |
|
|
|
| 359 |
|
|
$footer_template->set_var('FILESIZE', ini_get('memory_limit'));
|
| 360 |
|
|
$footer_template->set_var('TXT_SUM_FILESIZE', 'Summary size of included files: ');
|
| 361 |
|
|
$footer_template->set_var('SUM_FILESIZE', number_format($sum_filesize, 0, ',', '.').' Byte');
|
| 362 |
1700
|
Luisehahne
|
$footer_template->set_var('SUM_CLASSES', number_format($sum_classes, 0, ',', '.').' Byte');
|
| 363 |
1684
|
Luisehahne
|
$footer_template->set_var('PAGE_LOAD_TIME', round($iEndTime-$iStartTime,3 ));
|
| 364 |
1700
|
Luisehahne
|
$footer_template->set_var('DUMP_CLASSES', '<pre>'.var_export($included_classes,true).'</pre>');
|
| 365 |
1684
|
Luisehahne
|
|
| 366 |
1668
|
Luisehahne
|
$footer_template->parse('show_debug', 'show_debug_block', true);
|
| 367 |
|
|
} else {
|
| 368 |
|
|
$footer_template->parse('show_debug', '');
|
| 369 |
1684
|
Luisehahne
|
$footer_template->parse('show_list', '');
|
| 370 |
|
|
|
| 371 |
1668
|
Luisehahne
|
}
|
| 372 |
1379
|
Luisehahne
|
$footer_template->parse('header', 'footer_block', false);
|
| 373 |
|
|
$footer_template->pparse('output', 'page');
|
| 374 |
1700
|
Luisehahne
|
unset($footer_template);
|
| 375 |
1379
|
Luisehahne
|
}
|
| 376 |
1684
|
Luisehahne
|
|
| 377 |
1379
|
Luisehahne
|
// Return a system permission
|
| 378 |
|
|
function get_permission($name, $type = 'system') {
|
| 379 |
1700
|
Luisehahne
|
|
| 380 |
1379
|
Luisehahne
|
// Append to permission type
|
| 381 |
|
|
$type .= '_permissions';
|
| 382 |
|
|
// Check if we have a section to check for
|
| 383 |
|
|
if($name == 'start') {
|
| 384 |
|
|
return true;
|
| 385 |
|
|
} else {
|
| 386 |
|
|
// Set system permissions var
|
| 387 |
|
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
| 388 |
|
|
// Set module permissions var
|
| 389 |
|
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
| 390 |
|
|
// Set template permissions var
|
| 391 |
|
|
$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
|
| 392 |
|
|
// Return true if system perm = 1
|
| 393 |
|
|
if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) {
|
| 394 |
|
|
if($type == 'system_permissions') {
|
| 395 |
|
|
return true;
|
| 396 |
|
|
} else {
|
| 397 |
|
|
return false;
|
| 398 |
|
|
}
|
| 399 |
|
|
} else {
|
| 400 |
|
|
if($type == 'system_permissions') {
|
| 401 |
|
|
return false;
|
| 402 |
|
|
} else {
|
| 403 |
|
|
return true;
|
| 404 |
|
|
}
|
| 405 |
|
|
}
|
| 406 |
|
|
}
|
| 407 |
1700
|
Luisehahne
|
|
| 408 |
1379
|
Luisehahne
|
}
|
| 409 |
1700
|
Luisehahne
|
|
| 410 |
1441
|
Luisehahne
|
function get_user_details($user_id) {
|
| 411 |
|
|
global $database;
|
| 412 |
|
|
$retval = array('username'=>'unknown','display_name'=>'Unknown','email'=>'');
|
| 413 |
|
|
$sql = 'SELECT `username`,`display_name`,`email` ';
|
| 414 |
|
|
$sql .= 'FROM `'.TABLE_PREFIX.'users` ';
|
| 415 |
1486
|
DarkViper
|
$sql .= 'WHERE `user_id`='.(int)$user_id;
|
| 416 |
1441
|
Luisehahne
|
if( ($resUsers = $database->query($sql)) ) {
|
| 417 |
|
|
if( ($recUser = $resUsers->fetchRow()) ) {
|
| 418 |
|
|
$retval = $recUser;
|
| 419 |
|
|
}
|
| 420 |
|
|
}
|
| 421 |
|
|
return $retval;
|
| 422 |
|
|
}
|
| 423 |
|
|
|
| 424 |
|
|
//
|
| 425 |
|
|
function get_section_details( $section_id, $backLink = 'index.php' ) {
|
| 426 |
|
|
global $database, $TEXT;
|
| 427 |
|
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'sections` ';
|
| 428 |
1486
|
DarkViper
|
$sql .= 'WHERE `section_id`='.intval($section_id);
|
| 429 |
1441
|
Luisehahne
|
if(($resSection = $database->query($sql))){
|
| 430 |
|
|
if(!($recSection = $resSection->fetchRow())) {
|
| 431 |
|
|
$this->print_header();
|
| 432 |
|
|
$this->print_error($TEXT['SECTION'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
| 433 |
|
|
}
|
| 434 |
|
|
} else {
|
| 435 |
|
|
$this->print_header();
|
| 436 |
|
|
$this->print_error($database->get_error(), $backLink, true);
|
| 437 |
|
|
}
|
| 438 |
|
|
return $recSection;
|
| 439 |
|
|
}
|
| 440 |
|
|
|
| 441 |
|
|
function get_page_details( $page_id, $backLink = 'index.php' ) {
|
| 442 |
1486
|
DarkViper
|
global $database, $TEXT;
|
| 443 |
|
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
|
| 444 |
|
|
$sql .= 'WHERE `page_id`='.intval($page_id);
|
| 445 |
|
|
if(($resPages = $database->query($sql))){
|
| 446 |
|
|
if(!($recPage = $resPages->fetchRow())) {
|
| 447 |
|
|
$this->print_header();
|
| 448 |
|
|
$this->print_error($TEXT['PAGE'].' '.$TEXT['NOT_FOUND'], $backLink, true);
|
| 449 |
|
|
}
|
| 450 |
1441
|
Luisehahne
|
} else {
|
| 451 |
1486
|
DarkViper
|
$this->print_header();
|
| 452 |
|
|
$this->print_error($database->get_error(), $backLink, true);
|
| 453 |
1379
|
Luisehahne
|
}
|
| 454 |
1486
|
DarkViper
|
return $recPage;
|
| 455 |
1379
|
Luisehahne
|
}
|
| 456 |
|
|
|
| 457 |
1441
|
Luisehahne
|
function get_page_permission($page,$action='admin') {
|
| 458 |
|
|
if($action != 'viewing') { $action = 'admin'; }
|
| 459 |
|
|
$action_groups = $action.'_groups';
|
| 460 |
|
|
$action_users = $action.'_users';
|
| 461 |
|
|
$groups = $users = '0';
|
| 462 |
|
|
if(is_array($page)) {
|
| 463 |
|
|
$groups = $page[$action_groups];
|
| 464 |
|
|
$users = $page[$action_users];
|
| 465 |
|
|
} else {
|
| 466 |
|
|
global $database;
|
| 467 |
|
|
$sql = 'SELECT `'.$action_groups.'`,`'.$action_users.'` ';
|
| 468 |
|
|
$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
|
| 469 |
|
|
$sql .= 'WHERE `page_id`='.(int)$page;
|
| 470 |
|
|
if( ($res = $database->query($sql)) ) {
|
| 471 |
|
|
if( ($rec = $res->fetchRow()) ) {
|
| 472 |
|
|
$groups = $rec[$action_groups];
|
| 473 |
|
|
$users = $rec[$action_users];
|
| 474 |
|
|
}
|
| 475 |
|
|
}
|
| 476 |
|
|
}
|
| 477 |
|
|
return ($this->ami_group_member($groups) || $this->is_group_match($this->get_user_id(), $users));
|
| 478 |
|
|
}
|
| 479 |
|
|
|
| 480 |
1379
|
Luisehahne
|
// Returns a system permission for a menu link
|
| 481 |
|
|
function get_link_permission($title) {
|
| 482 |
|
|
$title = str_replace('_blank', '', $title);
|
| 483 |
|
|
$title = strtolower($title);
|
| 484 |
|
|
// Set system permissions var
|
| 485 |
|
|
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
|
| 486 |
|
|
// Set module permissions var
|
| 487 |
|
|
$module_permissions = $this->get_session('MODULE_PERMISSIONS');
|
| 488 |
|
|
if($title == 'start') {
|
| 489 |
|
|
return true;
|
| 490 |
|
|
} else {
|
| 491 |
|
|
// Return true if system perm = 1
|
| 492 |
|
|
if(is_numeric(array_search($title, $system_permissions))) {
|
| 493 |
|
|
return true;
|
| 494 |
|
|
} else {
|
| 495 |
|
|
return false;
|
| 496 |
|
|
}
|
| 497 |
|
|
}
|
| 498 |
|
|
}
|
| 499 |
|
|
|
| 500 |
|
|
// Function to add optional module Javascript or CSS stylesheets into the <body> section of the backend
|
| 501 |
|
|
function register_backend_modfiles_body($file_id="js")
|
| 502 |
|
|
{
|
| 503 |
|
|
// sanity check of parameter passed to the function
|
| 504 |
|
|
$file_id = strtolower($file_id);
|
| 505 |
|
|
if($file_id !== "javascript" && $file_id !== "js")
|
| 506 |
|
|
{
|
| 507 |
|
|
return;
|
| 508 |
|
|
}
|
| 509 |
|
|
global $database;
|
| 510 |
|
|
$body_links = "";
|
| 511 |
|
|
// define default baselink and filename for optional module javascript and stylesheet files
|
| 512 |
|
|
if($file_id == "js") {
|
| 513 |
1441
|
Luisehahne
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js" type="text/javascript"></script>';
|
| 514 |
1379
|
Luisehahne
|
$base_file = "backend_body.js";
|
| 515 |
|
|
}
|
| 516 |
1811
|
Luisehahne
|
|
| 517 |
|
|
$sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
|
| 518 |
|
|
$sActionRequest = isset($_GET['tool']) ? $_GET['tool'] : $sActionRequest;
|
| 519 |
|
|
|
| 520 |
1379
|
Luisehahne
|
// check if backend_body.js files needs to be included to the <body></body> section of the backend
|
| 521 |
1811
|
Luisehahne
|
if(isset($sActionRequest))
|
| 522 |
1379
|
Luisehahne
|
{
|
| 523 |
|
|
// check if displayed page contains a installed admin tool
|
| 524 |
1486
|
DarkViper
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
| 525 |
1811
|
Luisehahne
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
|
| 526 |
1486
|
DarkViper
|
$result = $database->query($sql);
|
| 527 |
1379
|
Luisehahne
|
if($result->numRows())
|
| 528 |
|
|
{
|
| 529 |
|
|
// check if admin tool directory contains a backend_body.js file to include
|
| 530 |
|
|
$tool = $result->fetchRow();
|
| 531 |
|
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file"))
|
| 532 |
|
|
{
|
| 533 |
|
|
// return link to the backend_body.js file
|
| 534 |
|
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
| 535 |
|
|
}
|
| 536 |
|
|
}
|
| 537 |
|
|
} elseif(isset($_GET['page_id']) or isset($_POST['page_id']))
|
| 538 |
|
|
{
|
| 539 |
|
|
// check if displayed page in the backend contains a page module
|
| 540 |
|
|
if (isset($_GET['page_id']))
|
| 541 |
|
|
{
|
| 542 |
|
|
$page_id = (int) addslashes($_GET['page_id']);
|
| 543 |
|
|
} else {
|
| 544 |
|
|
$page_id = (int) addslashes($_POST['page_id']);
|
| 545 |
|
|
}
|
| 546 |
|
|
// gather information for all models embedded on actual page
|
| 547 |
1486
|
DarkViper
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
| 548 |
|
|
$query_modules = $database->query($sql);
|
| 549 |
1379
|
Luisehahne
|
while($row = $query_modules->fetchRow()) {
|
| 550 |
|
|
// check if page module directory contains a backend_body.js file
|
| 551 |
|
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
| 552 |
|
|
// create link with backend_body.js source for the current module
|
| 553 |
|
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
| 554 |
|
|
// ensure that backend_body.js is only added once per module type
|
| 555 |
|
|
if(strpos($body_links, $tmp_link) === false) {
|
| 556 |
|
|
$body_links .= $tmp_link ."\n";
|
| 557 |
|
|
}
|
| 558 |
|
|
}
|
| 559 |
|
|
}
|
| 560 |
|
|
// write out links with all external module javascript/CSS files, remove last line feed
|
| 561 |
|
|
return rtrim($body_links);
|
| 562 |
|
|
}
|
| 563 |
|
|
}
|
| 564 |
|
|
|
| 565 |
|
|
|
| 566 |
|
|
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the backend
|
| 567 |
|
|
function register_backend_modfiles($file_id="css") {
|
| 568 |
|
|
// sanity check of parameter passed to the function
|
| 569 |
|
|
$file_id = strtolower($file_id);
|
| 570 |
|
|
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
|
| 571 |
|
|
return;
|
| 572 |
|
|
}
|
| 573 |
|
|
|
| 574 |
|
|
global $database;
|
| 575 |
|
|
// define default baselink and filename for optional module javascript and stylesheet files
|
| 576 |
|
|
$head_links = "";
|
| 577 |
|
|
if($file_id == "css") {
|
| 578 |
|
|
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.css"';
|
| 579 |
|
|
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />';
|
| 580 |
|
|
$base_file = "backend.css";
|
| 581 |
|
|
} else {
|
| 582 |
1441
|
Luisehahne
|
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js" type="text/javascript"></script>';
|
| 583 |
1379
|
Luisehahne
|
$base_file = "backend.js";
|
| 584 |
|
|
}
|
| 585 |
|
|
|
| 586 |
1811
|
Luisehahne
|
$sActionRequest = isset($_POST['tool']) ? $_POST['tool'] : null;
|
| 587 |
|
|
$sActionRequest = isset($_GET['tool']) ? $_GET['tool'] : $sActionRequest;
|
| 588 |
|
|
|
| 589 |
1379
|
Luisehahne
|
// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend
|
| 590 |
1811
|
Luisehahne
|
if(isset($sActionRequest)) {
|
| 591 |
1379
|
Luisehahne
|
// check if displayed page contains a installed admin tool
|
| 592 |
1486
|
DarkViper
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'addons` ';
|
| 593 |
1811
|
Luisehahne
|
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\''.addslashes($sActionRequest).'\'';
|
| 594 |
1486
|
DarkViper
|
$result = $database->query($sql);
|
| 595 |
1379
|
Luisehahne
|
if($result->numRows()) {
|
| 596 |
|
|
// check if admin tool directory contains a backend.js or backend.css file to include
|
| 597 |
|
|
$tool = $result->fetchRow();
|
| 598 |
|
|
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) {
|
| 599 |
|
|
// return link to the backend.js or backend.css file
|
| 600 |
|
|
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link);
|
| 601 |
|
|
}
|
| 602 |
|
|
}
|
| 603 |
1441
|
Luisehahne
|
} elseif(isset($_GET['page_id']) || isset($_POST['page_id'])) {
|
| 604 |
1379
|
Luisehahne
|
// check if displayed page in the backend contains a page module
|
| 605 |
|
|
if (isset($_GET['page_id'])) {
|
| 606 |
|
|
$page_id = (int)$_GET['page_id'];
|
| 607 |
|
|
} else {
|
| 608 |
|
|
$page_id = (int)$_POST['page_id'];
|
| 609 |
|
|
}
|
| 610 |
|
|
|
| 611 |
|
|
// gather information for all models embedded on actual page
|
| 612 |
1486
|
DarkViper
|
$sql = 'SELECT `module` FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
| 613 |
|
|
$query_modules = $database->query($sql);
|
| 614 |
1379
|
Luisehahne
|
|
| 615 |
|
|
while($row = $query_modules->fetchRow()) {
|
| 616 |
|
|
// check if page module directory contains a backend.js or backend.css file
|
| 617 |
|
|
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) {
|
| 618 |
|
|
// create link with backend.js or backend.css source for the current module
|
| 619 |
|
|
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link);
|
| 620 |
|
|
// ensure that backend.js or backend.css is only added once per module type
|
| 621 |
|
|
if(strpos($head_links, $tmp_link) === false) {
|
| 622 |
|
|
$head_links .= $tmp_link ."\n";
|
| 623 |
|
|
}
|
| 624 |
|
|
}
|
| 625 |
|
|
}
|
| 626 |
|
|
// write out links with all external module javascript/CSS files, remove last line feed
|
| 627 |
|
|
return rtrim($head_links);
|
| 628 |
|
|
}
|
| 629 |
|
|
}
|
| 630 |
|
|
}
|