Project

General

Profile

1 4 ryan
<?php
2
3 18 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, 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 18 stefan
if(!defined('WB_URL')) {
36
	header('Location: ../index.php');
37
}
38 4 ryan
39
40 5 stefan
require_once(WB_PATH.'/framework/class.wb.php');
41
42
require_once(WB_PATH.'/framework/initialize.php');
43
44 4 ryan
// Include PHPLIB template class
45
require_once(WB_PATH."/include/phplib/template.inc");
46
47
48
// Get WB version
49
require_once(ADMIN_PATH.'/interface/version.php');
50
51
/*
52
Begin user changeable settings
53
*/
54
55 5 stefan
class admin extends wb {
56 4 ryan
	// Authenticate user then auto print the header
57
	function admin($section_name, $section_permission = 'start', $auto_header = true, $auto_auth = true) {
58
		global $MESSAGE;
59
		// Specify the current applications name
60
		$this->section_name = $section_name;
61
		$this->section_permission = $section_permission;
62
		// Authenticate the user for this application
63
		if($auto_auth == true) {
64
			// First check if the user is logged-in
65
			if($this->is_authenticated() == false) {
66
				header('Location: '.ADMIN_URL.'/login/index.php');
67
			}
68
			// Now check if they are allowed in this section
69
			if($this->get_permission($section_permission) == false) {
70
				die($MESSAGE['ADMIN']['INSUFFICIENT_PRIVELLIGES']);
71
			}
72
		}
73
		// Auto header code
74
		if($auto_header == true) {
75
			$this->print_header();
76
		}
77
	}
78
79
	// Print the admin header
80
	function print_header($body_tags = '') {
81
		// Get vars from the language file
82
		global $MENU;
83
		global $MESSAGE;
84
		global $TEXT;
85
		// Connect to database and get website title
86
		$database = new database();
87
		$get_title = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'");
88
		$title = $get_title->fetchRow();
89
		$header_template = new Template(ADMIN_PATH."/interface");
90
		$header_template->set_file('page', 'header.html');
91
		$header_template->set_block('page', 'header_block', 'header');
92
		$header_template->set_var(	array(
93
													'SECTION_NAME' => $MENU[strtoupper($this->section_name)],
94
													'INTERFACE_DIR' => ADMIN_URL.'/interface',
95
													'BODY_TAGS' => $body_tags,
96
													'WEBSITE_TITLE' => stripslashes($title['value']),
97
													'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'],
98
													'VERSION' => VERSION
99
													)
100
											);
101
		// Create the menu
102
		$menu = array(
103
					array(ADMIN_URL.'/start/index.php', '', $MENU['START'], 'start', 0),
104
					array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1),
105
					array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1),
106
					array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1),
107
					array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 0),
108
					array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1),
109
					array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1),
110
					array('http://www.websitebaker.org/docs/', '_blank', $MENU['HELP'], 'help', 0),
111
					array(WB_URL.'/', '_blank', $MENU['VIEW'], 'view', 0),
112
					array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], 'logout', 0)
113
					);
114
		$header_template->set_block('header_block', 'linkBlock', 'link');
115
		foreach($menu AS $menu_item) {
116
			$link = $menu_item[0];
117
			$target = $menu_item[1];
118
			$title = $menu_item[2];
119
			$permission_title = $menu_item[3];
120
			$required = $menu_item[4];
121
			$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php');
122
			if($required == false OR $this->get_link_permission($permission_title)) {
123
				$header_template->set_var('LINK', $link);
124
				$header_template->set_var('TARGET', $target);
125
				// If link is the current section apply a class name
126
				if($permission_title == strtolower($this->section_name)) {
127
					$header_template->set_var('CLASS', 'current');
128
				} else {
129
					$header_template->set_var('CLASS', '');
130
				}
131
				$header_template->set_var('TITLE', $title);
132
				// Print link
133
				$header_template->parse('link', 'linkBlock', true);
134
			}
135
		}
136
		$header_template->parse('header', 'header_block', false);
137
		$header_template->pparse('output', 'page');
138
	}
139
140
	// Print the admin footer
141
	function print_footer() {
142
		$footer_template = new Template(ADMIN_PATH."/interface");
143
		$footer_template->set_file('page', 'footer.html');
144
		$footer_template->set_block('page', 'footer_block', 'header');
145
		$footer_template->parse('header', 'footer_block', false);
146
		$footer_template->pparse('output', 'page');
147
	}
148
149
	// Print a success message which then automatically redirects the user to another page
150
	function print_success($message, $redirect = 'index.php') {
151
		global $TEXT;
152
		$success_template = new Template(ADMIN_PATH.'/interface');
153
		$success_template->set_file('page', 'success.html');
154
		$success_template->set_block('page', 'main_block', 'main');
155
		$success_template->set_var('MESSAGE', $message);
156
		$success_template->set_var('REDIRECT', $redirect);
157
		$success_template->set_var('NEXT', $TEXT['NEXT']);
158
		$success_template->parse('main', 'main_block', false);
159
		$success_template->pparse('output', 'page');
160
	}
161
162
	// Print a error message
163
	function print_error($message, $link = 'index.php', $auto_footer = true) {
164
		global $TEXT;
165
		$success_template = new Template(ADMIN_PATH.'/interface');
166
		$success_template->set_file('page', 'error.html');
167
		$success_template->set_block('page', 'main_block', 'main');
168
		$success_template->set_var('MESSAGE', $message);
169
		$success_template->set_var('LINK', $link);
170
		$success_template->set_var('BACK', $TEXT['BACK']);
171
		$success_template->parse('main', 'main_block', false);
172
		$success_template->pparse('output', 'page');
173
		if($auto_footer == true) {
174
			$this->print_footer();
175
		}
176
		exit();
177
	}
178 5 stefan
179 4 ryan
	// Return a system permission
180
	function get_permission($name, $type = 'system') {
181
		// Append to permission type
182
		$type .= '_permissions';
183
		// Check if we have a section to check for
184
		if($name == 'start') {
185
			return true;
186
		} else {
187
			// Set system permissions var
188
			$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
189
			// Set module permissions var
190
			$module_permissions = $this->get_session('MODULE_PERMISSIONS');
191
			// Set template permissions var
192
			$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
193
			// Return true if system perm = 1
194
			if(is_numeric(array_search($name, $$type))) {
195
				if($type == 'system_permissions') {
196
					return true;
197
				} else {
198
					return false;
199
				}
200
			} else {
201
				if($type == 'system_permissions') {
202
					return false;
203
				} else {
204
					return true;
205
				}
206
			}
207
		}
208
	}
209 5 stefan
210 4 ryan
	// Returns a system permission for a menu link
211
	function get_link_permission($title) {
212
		$title = str_replace('_blank', '', $title);
213
		$title = strtolower($title);
214
		// Set system permissions var
215
		$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
216
		// Set module permissions var
217
		$module_permissions = $this->get_session('MODULE_PERMISSIONS');
218
		if($title == 'start') {
219
			return true;
220
		} else {
221
			// Return true if system perm = 1
222
			if(is_numeric(array_search($title, $system_permissions))) {
223
				return true;
224
			} else {
225
				return false;
226
			}
227
		}
228
	}
229
}
230
231 5 stefan
?>