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