Revision 1289
Added by kweitzel almost 15 years ago
class.admin.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, Ryan Djurovich |
|
9 |
|
|
10 |
Website Baker is free software; you can redistribute it and/or modify |
|
11 |
it under the terms of the GNU General Public License as published by |
|
12 |
the Free Software Foundation; either version 2 of the License, or |
|
13 |
(at your option) any later version. |
|
14 |
|
|
15 |
Website Baker is distributed in the hope that it will be useful, |
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
GNU General Public License for more details. |
|
19 |
|
|
20 |
You should have received a copy of the GNU General Public License |
|
21 |
along with Website Baker; if not, write to the Free Software |
|
22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
|
|
24 |
*/ |
|
25 |
|
|
26 |
/* |
|
27 |
|
|
28 |
Admin class |
|
29 |
|
|
30 |
This class will be used for every program that will be included |
|
31 |
in the administration section of Website Baker. |
|
32 |
|
|
33 |
*/ |
|
34 |
|
|
35 |
if(!defined('WB_URL')) { |
|
36 |
header('Location: ../index.php'); |
|
37 |
exit(0); |
|
38 |
} |
|
39 |
|
|
40 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
41 |
|
|
42 |
// Include PHPLIB template class |
|
43 |
require_once(WB_PATH."/include/phplib/template.inc"); |
|
44 |
|
|
45 |
// Get WB version |
|
46 |
require_once(ADMIN_PATH.'/interface/version.php'); |
|
47 |
|
|
48 |
// Include EditArea wrapper functions |
|
49 |
require_once(WB_PATH . '/include/editarea/wb_wrapper_edit_area.php'); |
|
50 |
|
|
51 |
/* |
|
52 |
Begin user changeable settings |
|
53 |
*/ |
|
54 |
|
|
55 |
|
|
56 |
class admin extends wb { |
|
57 |
// Authenticate user then auto print the header |
|
58 |
function admin($section_name, $section_permission = 'start', $auto_header = true, $auto_auth = true) { |
|
59 |
$this->wb(); |
|
60 |
global $MESSAGE; |
|
61 |
// Specify the current applications name |
|
62 |
$this->section_name = $section_name; |
|
63 |
$this->section_permission = $section_permission; |
|
64 |
// Authenticate the user for this application |
|
65 |
if($auto_auth == true) { |
|
66 |
// First check if the user is logged-in |
|
67 |
if($this->is_authenticated() == false) { |
|
68 |
header('Location: '.ADMIN_URL.'/login/index.php'); |
|
69 |
exit(0); |
|
70 |
} |
|
71 |
// Now check if they are allowed in this section |
|
72 |
if($this->get_permission($section_permission) == false) { |
|
73 |
die($MESSAGE['ADMIN']['INSUFFICIENT_PRIVELLIGES']); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
// Check if the backend language is also the selected language. If not, send headers again. |
|
78 |
global $database; |
|
79 |
$get_user_language = @$database->query("SELECT language FROM ".TABLE_PREFIX. |
|
80 |
"users WHERE user_id = '" .(int) $this->get_user_id() ."'"); |
|
81 |
$user_language = ($get_user_language) ? $get_user_language->fetchRow() : ''; |
|
82 |
// prevent infinite loop if language file is not XX.php (e.g. DE_du.php) |
|
83 |
$user_language = substr($user_language[0],0,2); |
|
84 |
// obtain the admin folder (e.g. /admin) |
|
85 |
$admin_folder = str_replace(WB_PATH, '', ADMIN_PATH); |
|
86 |
if((LANGUAGE != $user_language) && file_exists(WB_PATH .'/languages/' .$user_language .'.php') |
|
87 |
&& strpos($_SERVER['PHP_SELF'],$admin_folder.'/') !== false) { |
|
88 |
// check if page_id is set |
|
89 |
$page_id_url = (isset($_GET['page_id'])) ? '&page_id=' .(int) $_GET['page_id'] : ''; |
|
90 |
$section_id_url = (isset($_GET['section_id'])) ? '§ion_id=' .(int) $_GET['section_id'] : ''; |
|
91 |
if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string |
|
92 |
header('Location: '.$_SERVER['PHP_SELF'] .'?lang='.$user_language .$page_id_url .$section_id_url.'&'.$_SERVER['QUERY_STRING']); |
|
93 |
} else { |
|
94 |
header('Location: '.$_SERVER['PHP_SELF'] .'?lang='.$user_language .$page_id_url .$section_id_url); |
|
95 |
} |
|
96 |
exit(); |
|
97 |
} |
|
98 |
|
|
99 |
// Auto header code |
|
100 |
if($auto_header == true) { |
|
101 |
$this->print_header(); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
// Print the admin header |
|
106 |
function print_header($body_tags = '') { |
|
107 |
// Get vars from the language file |
|
108 |
global $MENU; |
|
109 |
global $MESSAGE; |
|
110 |
global $TEXT; |
|
111 |
// Connect to database and get website title |
|
112 |
global $database; |
|
113 |
$get_title = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'website_title'"); |
|
114 |
$title = $get_title->fetchRow(); |
|
115 |
$header_template = new Template(THEME_PATH.'/templates'); |
|
116 |
$header_template->set_file('page', 'header.htt'); |
|
117 |
$header_template->set_block('page', 'header_block', 'header'); |
|
118 |
if(defined('DEFAULT_CHARSET')) { |
|
119 |
$charset=DEFAULT_CHARSET; |
|
120 |
} else { |
|
121 |
$charset='utf-8'; |
|
122 |
} |
|
123 |
|
|
124 |
// work out the URL for the 'View menu' link in the WB backend |
|
125 |
// if the page_id is set, show this page otherwise show the root directory of WB |
|
126 |
$view_url = WB_URL; |
|
127 |
if(isset($_GET['page_id'])) { |
|
128 |
// extract page link from the database |
|
129 |
$result = @$database->query("SELECT link FROM " .TABLE_PREFIX ."pages WHERE page_id = '" .(int) addslashes($_GET['page_id']) ."'"); |
|
130 |
$row = @$result->fetchRow(); |
|
131 |
if($row) $view_url .= PAGES_DIRECTORY .$row['link']. PAGE_EXTENSION; |
|
132 |
} |
|
133 |
|
|
134 |
$header_template->set_var( array( |
|
135 |
'SECTION_NAME' => $MENU[strtoupper($this->section_name)], |
|
136 |
'BODY_TAGS' => $body_tags, |
|
137 |
'WEBSITE_TITLE' => ($title['value']), |
|
138 |
'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'], |
|
139 |
'CURRENT_USER' => $MESSAGE['START']['CURRENT_USER'], |
|
140 |
'DISPLAY_NAME' => $this->get_display_name(), |
|
141 |
'CHARSET' => $charset, |
|
142 |
'LANGUAGE' => strtolower(LANGUAGE), |
|
143 |
'VERSION' => VERSION, |
|
144 |
'WB_URL' => WB_URL, |
|
145 |
'ADMIN_URL' => ADMIN_URL, |
|
146 |
'THEME_URL' => THEME_URL, |
|
147 |
'TITLE_START' => $MENU['START'], |
|
148 |
'TITLE_VIEW' => $MENU['VIEW'], |
|
149 |
'TITLE_HELP' => $MENU['HELP'], |
|
150 |
'TITLE_LOGOUT' => $MENU['LOGOUT'], |
|
151 |
'URL_VIEW' => $view_url, |
|
152 |
'URL_HELP' => 'http://www.websitebaker.org/help/'.WB_VERSION, |
|
153 |
'BACKEND_MODULE_CSS' => $this->register_backend_modfiles('css'), // adds backend.css |
|
154 |
'BACKEND_MODULE_JS' => $this->register_backend_modfiles('js') // adds backend.js |
|
155 |
) |
|
156 |
); |
|
157 |
|
|
158 |
// Create the menu |
|
159 |
$menu = array( |
|
160 |
array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1), |
|
161 |
array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1), |
|
162 |
array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1), |
|
163 |
array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 0), |
|
164 |
array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1), |
|
165 |
array(ADMIN_URL.'/admintools/index.php', '', $MENU['ADMINTOOLS'], 'admintools', 1), |
|
166 |
array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1) |
|
167 |
); |
|
168 |
$header_template->set_block('header_block', 'linkBlock', 'link'); |
|
169 |
foreach($menu AS $menu_item) { |
|
170 |
$link = $menu_item[0]; |
|
171 |
$target = ($menu_item[1] == '') ? '_self' : $menu_item[1]; |
|
172 |
$title = $menu_item[2]; |
|
173 |
$permission_title = $menu_item[3]; |
|
174 |
$required = $menu_item[4]; |
|
175 |
$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php'); |
|
176 |
if($required == false OR $this->get_link_permission($permission_title)) { |
|
177 |
$header_template->set_var('LINK', $link); |
|
178 |
$header_template->set_var('TARGET', $target); |
|
179 |
// If link is the current section apply a class name |
|
180 |
if($permission_title == strtolower($this->section_name)) { |
|
181 |
$header_template->set_var('CLASS', $menu_item[3] . ' current'); |
|
182 |
} else { |
|
183 |
$header_template->set_var('CLASS', $menu_item[3]); |
|
184 |
} |
|
185 |
$header_template->set_var('TITLE', $title); |
|
186 |
// Print link |
|
187 |
$header_template->parse('link', 'linkBlock', true); |
|
188 |
} |
|
189 |
} |
|
190 |
$header_template->parse('header', 'header_block', false); |
|
191 |
$header_template->pparse('output', 'page'); |
|
192 |
} |
|
193 |
|
|
194 |
// Print the admin footer |
|
195 |
function print_footer() { |
|
196 |
// include the required file for Javascript admin |
|
197 |
if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){ |
|
198 |
@include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php'); |
|
199 |
} |
|
200 |
$footer_template = new Template(THEME_PATH.'/templates'); |
|
201 |
$footer_template->set_file('page', 'footer.htt'); |
|
202 |
$footer_template->set_block('page', 'footer_block', 'header'); |
|
203 |
$footer_template->set_var(array( |
|
204 |
'BACKEND_BODY_MODULE_JS' => $this->register_backend_modfiles_body('js'), |
|
205 |
'WB_URL' => WB_URL, |
|
206 |
'WB_PATH' => WB_PATH, |
|
207 |
'ADMIN_URL' => ADMIN_URL, |
|
208 |
'THEME_URL' => THEME_URL, |
|
209 |
) ); |
|
210 |
$footer_template->parse('header', 'footer_block', false); |
|
211 |
$footer_template->pparse('output', 'page'); |
|
212 |
} |
|
213 |
|
|
214 |
// Return a system permission |
|
215 |
function get_permission($name, $type = 'system') { |
|
216 |
// Append to permission type |
|
217 |
$type .= '_permissions'; |
|
218 |
// Check if we have a section to check for |
|
219 |
if($name == 'start') { |
|
220 |
return true; |
|
221 |
} else { |
|
222 |
// Set system permissions var |
|
223 |
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS'); |
|
224 |
// Set module permissions var |
|
225 |
$module_permissions = $this->get_session('MODULE_PERMISSIONS'); |
|
226 |
// Set template permissions var |
|
227 |
$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS'); |
|
228 |
// Return true if system perm = 1 |
|
229 |
if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) { |
|
230 |
if($type == 'system_permissions') { |
|
231 |
return true; |
|
232 |
} else { |
|
233 |
return false; |
|
234 |
} |
|
235 |
} else { |
|
236 |
if($type == 'system_permissions') { |
|
237 |
return false; |
|
238 |
} else { |
|
239 |
return true; |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
function get_user_details($user_id) { |
|
246 |
global $database; |
|
247 |
$query_user = "SELECT username,display_name FROM ".TABLE_PREFIX."users WHERE user_id = '$user_id'"; |
|
248 |
$get_user = $database->query($query_user); |
|
249 |
if($get_user->numRows() != 0) { |
|
250 |
$user = $get_user->fetchRow(); |
|
251 |
} else { |
|
252 |
$user['display_name'] = 'Unknown'; |
|
253 |
$user['username'] = 'unknown'; |
|
254 |
} |
|
255 |
return $user; |
|
256 |
} |
|
257 |
|
|
258 |
function get_page_details($page_id) { |
|
259 |
global $database; |
|
260 |
$query = "SELECT page_id,page_title,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'"; |
|
261 |
$results = $database->query($query); |
|
262 |
if($database->is_error()) { |
|
263 |
$this->print_header(); |
|
264 |
$this->print_error($database->get_error()); |
|
265 |
} |
|
266 |
if($results->numRows() == 0) { |
|
267 |
$this->print_header(); |
|
268 |
$this->print_error($MESSAGE['PAGES']['NOT_FOUND']); |
|
269 |
} |
|
270 |
$results_array = $results->fetchRow(); |
|
271 |
return $results_array; |
|
272 |
} |
|
273 |
|
|
274 |
/** Function get_page_permission takes either a numerical page_id, |
|
275 |
* upon which it looks up the permissions in the database, |
|
276 |
* or an array with keys admin_groups and admin_users |
|
277 |
*/ |
|
278 |
function get_page_permission($page,$action='admin') { |
|
279 |
if ($action!='viewing') $action='admin'; |
|
280 |
$action_groups=$action.'_groups'; |
|
281 |
$action_users=$action.'_users'; |
|
282 |
if (is_array($page)) { |
|
283 |
$groups=$page[$action_groups]; |
|
284 |
$users=$page[$action_users]; |
|
285 |
} else { |
|
286 |
global $database; |
|
287 |
$results = $database->query("SELECT $action_groups,$action_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page'"); |
|
288 |
$result = $results->fetchRow(); |
|
289 |
$groups = explode(',', str_replace('_', '', $result[$action_groups])); |
|
290 |
$users = explode(',', str_replace('_', '', $result[$action_users])); |
|
291 |
} |
|
292 |
|
|
293 |
$in_group = FALSE; |
|
294 |
foreach($this->get_groups_id() as $cur_gid){ |
|
295 |
if (in_array($cur_gid, $groups)) { |
|
296 |
$in_group = TRUE; |
|
297 |
} |
|
298 |
} |
|
299 |
if((!$in_group) AND !is_numeric(array_search($this->get_user_id(), $users))) { |
|
300 |
return false; |
|
301 |
} |
|
302 |
return true; |
|
303 |
} |
|
304 |
|
|
305 |
|
|
306 |
// Returns a system permission for a menu link |
|
307 |
function get_link_permission($title) { |
|
308 |
$title = str_replace('_blank', '', $title); |
|
309 |
$title = strtolower($title); |
|
310 |
// Set system permissions var |
|
311 |
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS'); |
|
312 |
// Set module permissions var |
|
313 |
$module_permissions = $this->get_session('MODULE_PERMISSIONS'); |
|
314 |
if($title == 'start') { |
|
315 |
return true; |
|
316 |
} else { |
|
317 |
// Return true if system perm = 1 |
|
318 |
if(is_numeric(array_search($title, $system_permissions))) { |
|
319 |
return true; |
|
320 |
} else { |
|
321 |
return false; |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
// Function to add optional module Javascript or CSS stylesheets into the <body> section of the backend |
|
327 |
function register_backend_modfiles_body($file_id="js") |
|
328 |
{ |
|
329 |
// sanity check of parameter passed to the function |
|
330 |
$file_id = strtolower($file_id); |
|
331 |
if($file_id !== "javascript" && $file_id !== "js") |
|
332 |
{ |
|
333 |
return; |
|
334 |
} |
|
335 |
global $database; |
|
336 |
$body_links = ""; |
|
337 |
// define default baselink and filename for optional module javascript and stylesheet files |
|
338 |
if($file_id == "js") { |
|
339 |
$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js"></script>'; |
|
340 |
$base_file = "backend_body.js"; |
|
341 |
} |
|
342 |
// check if backend_body.js files needs to be included to the <body></body> section of the backend |
|
343 |
if(isset($_GET['tool'])) |
|
344 |
{ |
|
345 |
// check if displayed page contains a installed admin tool |
|
346 |
$result = $database->query("SELECT * FROM " .TABLE_PREFIX ."addons |
|
347 |
WHERE type = 'module' AND function = 'tool' AND directory = '".addslashes($_GET['tool'])."'"); |
|
348 |
if($result->numRows()) |
|
349 |
{ |
|
350 |
// check if admin tool directory contains a backend_body.js file to include |
|
351 |
$tool = $result->fetchRow(); |
|
352 |
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) |
|
353 |
{ |
|
354 |
// return link to the backend_body.js file |
|
355 |
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link); |
|
356 |
} |
|
357 |
} |
|
358 |
} elseif(isset($_GET['page_id']) or isset($_POST['page_id'])) |
|
359 |
{ |
|
360 |
// check if displayed page in the backend contains a page module |
|
361 |
if (isset($_GET['page_id'])) |
|
362 |
{ |
|
363 |
$page_id = (int) addslashes($_GET['page_id']); |
|
364 |
} else { |
|
365 |
$page_id = (int) addslashes($_POST['page_id']); |
|
366 |
} |
|
367 |
// gather information for all models embedded on actual page |
|
368 |
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections |
|
369 |
WHERE page_id=$page_id"); |
|
370 |
while($row = $query_modules->fetchRow()) { |
|
371 |
// check if page module directory contains a backend_body.js file |
|
372 |
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) { |
|
373 |
// create link with backend_body.js source for the current module |
|
374 |
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link); |
|
375 |
// ensure that backend_body.js is only added once per module type |
|
376 |
if(strpos($body_links, $tmp_link) === false) { |
|
377 |
$body_links .= $tmp_link ."\n"; |
|
378 |
} |
|
379 |
} |
|
380 |
} |
|
381 |
// write out links with all external module javascript/CSS files, remove last line feed |
|
382 |
return rtrim($body_links); |
|
383 |
} |
|
384 |
} |
|
385 |
|
|
386 |
|
|
387 |
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the backend |
|
388 |
function register_backend_modfiles($file_id="css") { |
|
389 |
// sanity check of parameter passed to the function |
|
390 |
$file_id = strtolower($file_id); |
|
391 |
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { |
|
392 |
return; |
|
393 |
} |
|
394 |
|
|
395 |
global $database; |
|
396 |
// define default baselink and filename for optional module javascript and stylesheet files |
|
397 |
$head_links = ""; |
|
398 |
if($file_id == "css") { |
|
399 |
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.css"'; |
|
400 |
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />'; |
|
401 |
$base_file = "backend.css"; |
|
402 |
} else { |
|
403 |
$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js"></script>'; |
|
404 |
$base_file = "backend.js"; |
|
405 |
} |
|
406 |
|
|
407 |
// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend |
|
408 |
if(isset($_GET['tool'])) { |
|
409 |
// check if displayed page contains a installed admin tool |
|
410 |
$result = $database->query("SELECT * FROM " .TABLE_PREFIX ."addons |
|
411 |
WHERE type = 'module' AND function = 'tool' AND directory = '".addslashes($_GET['tool'])."'"); |
|
412 |
|
|
413 |
if($result->numRows()) { |
|
414 |
// check if admin tool directory contains a backend.js or backend.css file to include |
|
415 |
$tool = $result->fetchRow(); |
|
416 |
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) { |
|
417 |
// return link to the backend.js or backend.css file |
|
418 |
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link); |
|
419 |
} |
|
420 |
} |
|
421 |
} elseif(isset($_GET['page_id']) or isset($_POST['page_id'])) { |
|
422 |
// check if displayed page in the backend contains a page module |
|
423 |
if (isset($_GET['page_id'])) { |
|
424 |
$page_id = (int) addslashes($_GET['page_id']); |
|
425 |
} else { |
|
426 |
$page_id = (int) addslashes($_POST['page_id']); |
|
427 |
} |
|
428 |
|
|
429 |
// gather information for all models embedded on actual page |
|
430 |
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections |
|
431 |
WHERE page_id=$page_id"); |
|
432 |
|
|
433 |
while($row = $query_modules->fetchRow()) { |
|
434 |
// check if page module directory contains a backend.js or backend.css file |
|
435 |
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) { |
|
436 |
// create link with backend.js or backend.css source for the current module |
|
437 |
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link); |
|
438 |
// ensure that backend.js or backend.css is only added once per module type |
|
439 |
if(strpos($head_links, $tmp_link) === false) { |
|
440 |
$head_links .= $tmp_link ."\n"; |
|
441 |
} |
|
442 |
} |
|
443 |
} |
|
444 |
// write out links with all external module javascript/CSS files, remove last line feed |
|
445 |
return rtrim($head_links); |
|
446 |
} |
|
447 |
} |
|
448 |
} |
|
449 |
|
|
450 |
?> |
|
1 |
<?php |
|
2 |
/** |
|
3 |
* |
|
4 |
* @category frontend |
|
5 |
* @package account |
|
6 |
* @author WebsiteBaker Project |
|
7 |
* @copyright 2004-2009, Ryan Djurovich |
|
8 |
* @copyright 2009-2010, Website Baker Org. e.V. |
|
9 |
* @link http://www.websitebaker2.org/ |
|
10 |
* @license http://www.gnu.org/licenses/gpl.html |
|
11 |
* @platform WebsiteBaker 2.8.x |
|
12 |
* @requirements PHP 4.3.4 and higher |
|
13 |
* @version $Id$ |
|
14 |
* @filesource $HeadURL$ |
|
15 |
* @lastmodified $Date$ |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
if(!defined('WB_URL')) { |
|
20 |
header('Location: ../index.php'); |
|
21 |
exit(0); |
|
22 |
} |
|
23 |
|
|
24 |
require_once(WB_PATH.'/framework/class.wb.php'); |
|
25 |
|
|
26 |
// Include PHPLIB template class |
|
27 |
require_once(WB_PATH."/include/phplib/template.inc"); |
|
28 |
|
|
29 |
// Get WB version |
|
30 |
require_once(ADMIN_PATH.'/interface/version.php'); |
|
31 |
|
|
32 |
// Include EditArea wrapper functions |
|
33 |
require_once(WB_PATH . '/include/editarea/wb_wrapper_edit_area.php'); |
|
34 |
|
|
35 |
/* |
|
36 |
Begin user changeable settings |
|
37 |
*/ |
|
38 |
|
|
39 |
|
|
40 |
class admin extends wb { |
|
41 |
// Authenticate user then auto print the header |
|
42 |
function admin($section_name, $section_permission = 'start', $auto_header = true, $auto_auth = true) { |
|
43 |
$this->wb(); |
|
44 |
global $MESSAGE; |
|
45 |
// Specify the current applications name |
|
46 |
$this->section_name = $section_name; |
|
47 |
$this->section_permission = $section_permission; |
|
48 |
// Authenticate the user for this application |
|
49 |
if($auto_auth == true) { |
|
50 |
// First check if the user is logged-in |
|
51 |
if($this->is_authenticated() == false) { |
|
52 |
header('Location: '.ADMIN_URL.'/login/index.php'); |
|
53 |
exit(0); |
|
54 |
} |
|
55 |
// Now check if they are allowed in this section |
|
56 |
if($this->get_permission($section_permission) == false) { |
|
57 |
die($MESSAGE['ADMIN']['INSUFFICIENT_PRIVELLIGES']); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
// Check if the backend language is also the selected language. If not, send headers again. |
|
62 |
global $database; |
|
63 |
$get_user_language = @$database->query("SELECT language FROM ".TABLE_PREFIX. |
|
64 |
"users WHERE user_id = '" .(int) $this->get_user_id() ."'"); |
|
65 |
$user_language = ($get_user_language) ? $get_user_language->fetchRow() : ''; |
|
66 |
// prevent infinite loop if language file is not XX.php (e.g. DE_du.php) |
|
67 |
$user_language = substr($user_language[0],0,2); |
|
68 |
// obtain the admin folder (e.g. /admin) |
|
69 |
$admin_folder = str_replace(WB_PATH, '', ADMIN_PATH); |
|
70 |
if((LANGUAGE != $user_language) && file_exists(WB_PATH .'/languages/' .$user_language .'.php') |
|
71 |
&& strpos($_SERVER['PHP_SELF'],$admin_folder.'/') !== false) { |
|
72 |
// check if page_id is set |
|
73 |
$page_id_url = (isset($_GET['page_id'])) ? '&page_id=' .(int) $_GET['page_id'] : ''; |
|
74 |
$section_id_url = (isset($_GET['section_id'])) ? '§ion_id=' .(int) $_GET['section_id'] : ''; |
|
75 |
if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') { // check if there is an query-string |
|
76 |
header('Location: '.$_SERVER['PHP_SELF'] .'?lang='.$user_language .$page_id_url .$section_id_url.'&'.$_SERVER['QUERY_STRING']); |
|
77 |
} else { |
|
78 |
header('Location: '.$_SERVER['PHP_SELF'] .'?lang='.$user_language .$page_id_url .$section_id_url); |
|
79 |
} |
|
80 |
exit(); |
|
81 |
} |
|
82 |
|
|
83 |
// Auto header code |
|
84 |
if($auto_header == true) { |
|
85 |
$this->print_header(); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
// Print the admin header |
|
90 |
function print_header($body_tags = '') { |
|
91 |
// Get vars from the language file |
|
92 |
global $MENU; |
|
93 |
global $MESSAGE; |
|
94 |
global $TEXT; |
|
95 |
// Connect to database and get website title |
|
96 |
global $database; |
|
97 |
$get_title = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'website_title'"); |
|
98 |
$title = $get_title->fetchRow(); |
|
99 |
$header_template = new Template(THEME_PATH.'/templates'); |
|
100 |
$header_template->set_file('page', 'header.htt'); |
|
101 |
$header_template->set_block('page', 'header_block', 'header'); |
|
102 |
if(defined('DEFAULT_CHARSET')) { |
|
103 |
$charset=DEFAULT_CHARSET; |
|
104 |
} else { |
|
105 |
$charset='utf-8'; |
|
106 |
} |
|
107 |
|
|
108 |
// work out the URL for the 'View menu' link in the WB backend |
|
109 |
// if the page_id is set, show this page otherwise show the root directory of WB |
|
110 |
$view_url = WB_URL; |
|
111 |
if(isset($_GET['page_id'])) { |
|
112 |
// extract page link from the database |
|
113 |
$result = @$database->query("SELECT link FROM " .TABLE_PREFIX ."pages WHERE page_id = '" .(int) addslashes($_GET['page_id']) ."'"); |
|
114 |
$row = @$result->fetchRow(); |
|
115 |
if($row) $view_url .= PAGES_DIRECTORY .$row['link']. PAGE_EXTENSION; |
|
116 |
} |
|
117 |
|
|
118 |
$header_template->set_var( array( |
|
119 |
'SECTION_NAME' => $MENU[strtoupper($this->section_name)], |
|
120 |
'BODY_TAGS' => $body_tags, |
|
121 |
'WEBSITE_TITLE' => ($title['value']), |
|
122 |
'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'], |
|
123 |
'CURRENT_USER' => $MESSAGE['START']['CURRENT_USER'], |
|
124 |
'DISPLAY_NAME' => $this->get_display_name(), |
|
125 |
'CHARSET' => $charset, |
|
126 |
'LANGUAGE' => strtolower(LANGUAGE), |
|
127 |
'VERSION' => VERSION, |
|
128 |
'REVISION' => REVISION, |
|
129 |
'WB_URL' => WB_URL, |
|
130 |
'ADMIN_URL' => ADMIN_URL, |
|
131 |
'THEME_URL' => THEME_URL, |
|
132 |
'TITLE_START' => $MENU['START'], |
|
133 |
'TITLE_VIEW' => $MENU['VIEW'], |
|
134 |
'TITLE_HELP' => $MENU['HELP'], |
|
135 |
'TITLE_LOGOUT' => $MENU['LOGOUT'], |
|
136 |
'URL_VIEW' => $view_url, |
|
137 |
'URL_HELP' => 'http://www.websitebaker.org/', |
|
138 |
'BACKEND_MODULE_CSS' => $this->register_backend_modfiles('css'), // adds backend.css |
|
139 |
'BACKEND_MODULE_JS' => $this->register_backend_modfiles('js') // adds backend.js |
|
140 |
) |
|
141 |
); |
|
142 |
|
|
143 |
// Create the menu |
|
144 |
$menu = array( |
|
145 |
array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1), |
|
146 |
array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1), |
|
147 |
array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1), |
|
148 |
array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 0), |
|
149 |
array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1), |
|
150 |
array(ADMIN_URL.'/admintools/index.php', '', $MENU['ADMINTOOLS'], 'admintools', 1), |
|
151 |
array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1) |
|
152 |
); |
|
153 |
$header_template->set_block('header_block', 'linkBlock', 'link'); |
|
154 |
foreach($menu AS $menu_item) { |
|
155 |
$link = $menu_item[0]; |
|
156 |
$target = ($menu_item[1] == '') ? '_self' : $menu_item[1]; |
|
157 |
$title = $menu_item[2]; |
|
158 |
$permission_title = $menu_item[3]; |
|
159 |
$required = $menu_item[4]; |
|
160 |
$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php'); |
|
161 |
if($required == false OR $this->get_link_permission($permission_title)) { |
|
162 |
$header_template->set_var('LINK', $link); |
|
163 |
$header_template->set_var('TARGET', $target); |
|
164 |
// If link is the current section apply a class name |
|
165 |
if($permission_title == strtolower($this->section_name)) { |
|
166 |
$header_template->set_var('CLASS', $menu_item[3] . ' current'); |
|
167 |
} else { |
|
168 |
$header_template->set_var('CLASS', $menu_item[3]); |
|
169 |
} |
|
170 |
$header_template->set_var('TITLE', $title); |
|
171 |
// Print link |
|
172 |
$header_template->parse('link', 'linkBlock', true); |
|
173 |
} |
|
174 |
} |
|
175 |
$header_template->parse('header', 'header_block', false); |
|
176 |
$header_template->pparse('output', 'page'); |
|
177 |
} |
|
178 |
|
|
179 |
// Print the admin footer |
|
180 |
function print_footer() { |
|
181 |
// include the required file for Javascript admin |
|
182 |
if(file_exists(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php')){ |
|
183 |
@include(WB_PATH.'/modules/jsadmin/jsadmin_backend_include.php'); |
|
184 |
} |
|
185 |
$footer_template = new Template(THEME_PATH.'/templates'); |
|
186 |
$footer_template->set_file('page', 'footer.htt'); |
|
187 |
$footer_template->set_block('page', 'footer_block', 'header'); |
|
188 |
$footer_template->set_var(array( |
|
189 |
'BACKEND_BODY_MODULE_JS' => $this->register_backend_modfiles_body('js'), |
|
190 |
'WB_URL' => WB_URL, |
|
191 |
'WB_PATH' => WB_PATH, |
|
192 |
'ADMIN_URL' => ADMIN_URL, |
|
193 |
'THEME_URL' => THEME_URL, |
|
194 |
) ); |
|
195 |
$footer_template->parse('header', 'footer_block', false); |
|
196 |
$footer_template->pparse('output', 'page'); |
|
197 |
} |
|
198 |
|
|
199 |
// Return a system permission |
|
200 |
function get_permission($name, $type = 'system') { |
|
201 |
// Append to permission type |
|
202 |
$type .= '_permissions'; |
|
203 |
// Check if we have a section to check for |
|
204 |
if($name == 'start') { |
|
205 |
return true; |
|
206 |
} else { |
|
207 |
// Set system permissions var |
|
208 |
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS'); |
|
209 |
// Set module permissions var |
|
210 |
$module_permissions = $this->get_session('MODULE_PERMISSIONS'); |
|
211 |
// Set template permissions var |
|
212 |
$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS'); |
|
213 |
// Return true if system perm = 1 |
|
214 |
if (isset($$type) && is_array($$type) && is_numeric(array_search($name, $$type))) { |
|
215 |
if($type == 'system_permissions') { |
|
216 |
return true; |
|
217 |
} else { |
|
218 |
return false; |
|
219 |
} |
|
220 |
} else { |
|
221 |
if($type == 'system_permissions') { |
|
222 |
return false; |
|
223 |
} else { |
|
224 |
return true; |
|
225 |
} |
|
226 |
} |
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
function get_user_details($user_id) { |
|
231 |
global $database; |
|
232 |
$query_user = "SELECT username,display_name FROM ".TABLE_PREFIX."users WHERE user_id = '$user_id'"; |
|
233 |
$get_user = $database->query($query_user); |
|
234 |
if($get_user->numRows() != 0) { |
|
235 |
$user = $get_user->fetchRow(); |
|
236 |
} else { |
|
237 |
$user['display_name'] = 'Unknown'; |
|
238 |
$user['username'] = 'unknown'; |
|
239 |
} |
|
240 |
return $user; |
|
241 |
} |
|
242 |
|
|
243 |
function get_page_details($page_id) { |
|
244 |
global $database; |
|
245 |
$query = "SELECT page_id,page_title,menu_title,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'"; |
|
246 |
$results = $database->query($query); |
|
247 |
if($database->is_error()) { |
|
248 |
$this->print_header(); |
|
249 |
$this->print_error($database->get_error()); |
|
250 |
} |
|
251 |
if($results->numRows() == 0) { |
|
252 |
$this->print_header(); |
|
253 |
$this->print_error($MESSAGE['PAGES']['NOT_FOUND']); |
|
254 |
} |
|
255 |
$results_array = $results->fetchRow(); |
|
256 |
return $results_array; |
|
257 |
} |
|
258 |
|
|
259 |
/** Function get_page_permission takes either a numerical page_id, |
|
260 |
* upon which it looks up the permissions in the database, |
|
261 |
* or an array with keys admin_groups and admin_users |
|
262 |
*/ |
|
263 |
function get_page_permission($page,$action='admin') { |
|
264 |
if ($action!='viewing') $action='admin'; |
|
265 |
$action_groups=$action.'_groups'; |
|
266 |
$action_users=$action.'_users'; |
|
267 |
if (is_array($page)) { |
|
268 |
$groups=$page[$action_groups]; |
|
269 |
$users=$page[$action_users]; |
|
270 |
} else { |
|
271 |
global $database; |
|
272 |
$results = $database->query("SELECT $action_groups,$action_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page'"); |
|
273 |
$result = $results->fetchRow(); |
|
274 |
$groups = explode(',', str_replace('_', '', $result[$action_groups])); |
|
275 |
$users = explode(',', str_replace('_', '', $result[$action_users])); |
|
276 |
} |
|
277 |
|
|
278 |
$in_group = FALSE; |
|
279 |
foreach($this->get_groups_id() as $cur_gid){ |
|
280 |
if (in_array($cur_gid, $groups)) { |
|
281 |
$in_group = TRUE; |
|
282 |
} |
|
283 |
} |
|
284 |
if((!$in_group) AND !is_numeric(array_search($this->get_user_id(), $users))) { |
|
285 |
return false; |
|
286 |
} |
|
287 |
return true; |
|
288 |
} |
|
289 |
|
|
290 |
|
|
291 |
// Returns a system permission for a menu link |
|
292 |
function get_link_permission($title) { |
|
293 |
$title = str_replace('_blank', '', $title); |
|
294 |
$title = strtolower($title); |
|
295 |
// Set system permissions var |
|
296 |
$system_permissions = $this->get_session('SYSTEM_PERMISSIONS'); |
|
297 |
// Set module permissions var |
|
298 |
$module_permissions = $this->get_session('MODULE_PERMISSIONS'); |
|
299 |
if($title == 'start') { |
|
300 |
return true; |
|
301 |
} else { |
|
302 |
// Return true if system perm = 1 |
|
303 |
if(is_numeric(array_search($title, $system_permissions))) { |
|
304 |
return true; |
|
305 |
} else { |
|
306 |
return false; |
|
307 |
} |
|
308 |
} |
|
309 |
} |
|
310 |
|
|
311 |
// Function to add optional module Javascript or CSS stylesheets into the <body> section of the backend |
|
312 |
function register_backend_modfiles_body($file_id="js") |
|
313 |
{ |
|
314 |
// sanity check of parameter passed to the function |
|
315 |
$file_id = strtolower($file_id); |
|
316 |
if($file_id !== "javascript" && $file_id !== "js") |
|
317 |
{ |
|
318 |
return; |
|
319 |
} |
|
320 |
global $database; |
|
321 |
$body_links = ""; |
|
322 |
// define default baselink and filename for optional module javascript and stylesheet files |
|
323 |
if($file_id == "js") { |
|
324 |
$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend_body.js"></script>'; |
|
325 |
$base_file = "backend_body.js"; |
|
326 |
} |
|
327 |
// check if backend_body.js files needs to be included to the <body></body> section of the backend |
|
328 |
if(isset($_GET['tool'])) |
|
329 |
{ |
|
330 |
// check if displayed page contains a installed admin tool |
|
331 |
$result = $database->query("SELECT * FROM " .TABLE_PREFIX ."addons |
|
332 |
WHERE type = 'module' AND function = 'tool' AND directory = '".addslashes($_GET['tool'])."'"); |
|
333 |
if($result->numRows()) |
|
334 |
{ |
|
335 |
// check if admin tool directory contains a backend_body.js file to include |
|
336 |
$tool = $result->fetchRow(); |
|
337 |
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) |
|
338 |
{ |
|
339 |
// return link to the backend_body.js file |
|
340 |
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link); |
|
341 |
} |
|
342 |
} |
|
343 |
} elseif(isset($_GET['page_id']) or isset($_POST['page_id'])) |
|
344 |
{ |
|
345 |
// check if displayed page in the backend contains a page module |
|
346 |
if (isset($_GET['page_id'])) |
|
347 |
{ |
|
348 |
$page_id = (int) addslashes($_GET['page_id']); |
|
349 |
} else { |
|
350 |
$page_id = (int) addslashes($_POST['page_id']); |
|
351 |
} |
|
352 |
// gather information for all models embedded on actual page |
|
353 |
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections |
|
354 |
WHERE page_id=$page_id"); |
|
355 |
while($row = $query_modules->fetchRow()) { |
|
356 |
// check if page module directory contains a backend_body.js file |
|
357 |
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) { |
|
358 |
// create link with backend_body.js source for the current module |
|
359 |
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link); |
|
360 |
// ensure that backend_body.js is only added once per module type |
|
361 |
if(strpos($body_links, $tmp_link) === false) { |
|
362 |
$body_links .= $tmp_link ."\n"; |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
// write out links with all external module javascript/CSS files, remove last line feed |
|
367 |
return rtrim($body_links); |
|
368 |
} |
|
369 |
} |
|
370 |
|
|
371 |
|
|
372 |
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the backend |
|
373 |
function register_backend_modfiles($file_id="css") { |
|
374 |
// sanity check of parameter passed to the function |
|
375 |
$file_id = strtolower($file_id); |
|
376 |
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { |
|
377 |
return; |
|
378 |
} |
|
379 |
|
|
380 |
global $database; |
|
381 |
// define default baselink and filename for optional module javascript and stylesheet files |
|
382 |
$head_links = ""; |
|
383 |
if($file_id == "css") { |
|
384 |
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.css"'; |
|
385 |
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />'; |
|
386 |
$base_file = "backend.css"; |
|
387 |
} else { |
|
388 |
$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/backend.js"></script>'; |
|
389 |
$base_file = "backend.js"; |
|
390 |
} |
|
391 |
|
|
392 |
// check if backend.js or backend.css files needs to be included to the <head></head> section of the backend |
|
393 |
if(isset($_GET['tool'])) { |
|
394 |
// check if displayed page contains a installed admin tool |
|
395 |
$result = $database->query("SELECT * FROM " .TABLE_PREFIX ."addons |
|
396 |
WHERE type = 'module' AND function = 'tool' AND directory = '".addslashes($_GET['tool'])."'"); |
|
397 |
|
|
398 |
if($result->numRows()) { |
|
399 |
// check if admin tool directory contains a backend.js or backend.css file to include |
|
400 |
$tool = $result->fetchRow(); |
|
401 |
if(file_exists(WB_PATH ."/modules/" .$tool['directory'] ."/$base_file")) { |
|
402 |
// return link to the backend.js or backend.css file |
|
403 |
return str_replace("{MODULE_DIRECTORY}", $tool['directory'], $base_link); |
|
404 |
} |
|
405 |
} |
|
406 |
} elseif(isset($_GET['page_id']) or isset($_POST['page_id'])) { |
|
407 |
// check if displayed page in the backend contains a page module |
|
408 |
if (isset($_GET['page_id'])) { |
|
409 |
$page_id = (int) addslashes($_GET['page_id']); |
|
410 |
} else { |
|
411 |
$page_id = (int) addslashes($_POST['page_id']); |
|
412 |
} |
|
413 |
|
|
414 |
// gather information for all models embedded on actual page |
|
415 |
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections |
|
416 |
WHERE page_id=$page_id"); |
|
417 |
|
|
418 |
while($row = $query_modules->fetchRow()) { |
|
419 |
// check if page module directory contains a backend.js or backend.css file |
|
420 |
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) { |
|
421 |
// create link with backend.js or backend.css source for the current module |
|
422 |
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link); |
|
423 |
// ensure that backend.js or backend.css is only added once per module type |
|
424 |
if(strpos($head_links, $tmp_link) === false) { |
|
425 |
$head_links .= $tmp_link ."\n"; |
|
426 |
} |
|
427 |
} |
|
428 |
} |
|
429 |
// write out links with all external module javascript/CSS files, remove last line feed |
|
430 |
return rtrim($head_links); |
|
431 |
} |
|
432 |
} |
|
433 |
} |
|
434 |
|
|
435 |
?> |
|
451 | 436 |
Also available in: Unified diff
Branch 2.8.1 merged back into Trunk