Project

General

Profile

1
<?php
2

    
3
// $Id: class.admin.php 10 2005-09-04 08:59:31Z ryan $
4

    
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

    
36

    
37
require_once(WB_PATH.'/framework/class.wb.php');
38

    
39
require_once(WB_PATH.'/framework/initialize.php');
40

    
41
// Include PHPLIB template class
42
require_once(WB_PATH."/include/phplib/template.inc");
43

    
44

    
45
// Get WB version
46
require_once(ADMIN_PATH.'/interface/version.php');
47

    
48
/*
49
Begin user changeable settings
50
*/
51

    
52
class admin extends wb {
53
	// Authenticate user then auto print the header
54
	function admin($section_name, $section_permission = 'start', $auto_header = true, $auto_auth = true) {
55
		global $MESSAGE;
56
		// Specify the current applications name
57
		$this->section_name = $section_name;
58
		$this->section_permission = $section_permission;
59
		// Authenticate the user for this application
60
		if($auto_auth == true) {
61
			// First check if the user is logged-in
62
			if($this->is_authenticated() == false) {
63
				header('Location: '.ADMIN_URL.'/login/index.php');
64
			}
65
			// Now check if they are allowed in this section
66
			if($this->get_permission($section_permission) == false) {
67
				die($MESSAGE['ADMIN']['INSUFFICIENT_PRIVELLIGES']);
68
			}
69
		}
70
		// Auto header code
71
		if($auto_header == true) {
72
			$this->print_header();
73
		}
74
	}
75
	
76
	// Print the admin header
77
	function print_header($body_tags = '') {
78
		// Get vars from the language file
79
		global $MENU;
80
		global $MESSAGE;
81
		global $TEXT;
82
		// Connect to database and get website title
83
		$database = new database();
84
		$get_title = $database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name = 'title'");
85
		$title = $get_title->fetchRow();
86
		$header_template = new Template(ADMIN_PATH."/interface");
87
		$header_template->set_file('page', 'header.html');
88
		$header_template->set_block('page', 'header_block', 'header');
89
		$header_template->set_var(	array(
90
													'SECTION_NAME' => $MENU[strtoupper($this->section_name)],
91
													'INTERFACE_DIR' => ADMIN_URL.'/interface',
92
													'BODY_TAGS' => $body_tags,
93
													'WEBSITE_TITLE' => stripslashes($title['value']),
94
													'TEXT_ADMINISTRATION' => $TEXT['ADMINISTRATION'],
95
													'VERSION' => VERSION
96
													)
97
											);
98
		// Create the menu
99
		$menu = array(
100
					array(ADMIN_URL.'/start/index.php', '', $MENU['START'], 'start', 0),
101
					array(ADMIN_URL.'/pages/index.php', '', $MENU['PAGES'], 'pages', 1),
102
					array(ADMIN_URL.'/media/index.php', '', $MENU['MEDIA'], 'media', 1),
103
					array(ADMIN_URL.'/addons/index.php', '', $MENU['ADDONS'], 'addons', 1),
104
					array(ADMIN_URL.'/preferences/index.php', '', $MENU['PREFERENCES'], 'preferences', 0),
105
					array(ADMIN_URL.'/settings/index.php', '', $MENU['SETTINGS'], 'settings', 1),
106
					array(ADMIN_URL.'/access/index.php', '', $MENU['ACCESS'], 'access', 1),
107
					array('http://www.websitebaker.org/docs/', '_blank', $MENU['HELP'], 'help', 0),
108
					array(WB_URL.'/', '_blank', $MENU['VIEW'], 'view', 0),
109
					array(ADMIN_URL.'/logout/index.php', '', $MENU['LOGOUT'], 'logout', 0)
110
					);
111
		$header_template->set_block('header_block', 'linkBlock', 'link');
112
		foreach($menu AS $menu_item) {
113
			$link = $menu_item[0];
114
			$target = $menu_item[1];
115
			$title = $menu_item[2];
116
			$permission_title = $menu_item[3];
117
			$required = $menu_item[4];
118
			$replace_old = array(ADMIN_URL, WB_URL, '/', 'index.php');
119
			if($required == false OR $this->get_link_permission($permission_title)) {
120
				$header_template->set_var('LINK', $link);
121
				$header_template->set_var('TARGET', $target);
122
				// If link is the current section apply a class name
123
				if($permission_title == strtolower($this->section_name)) {
124
					$header_template->set_var('CLASS', 'current');
125
				} else {
126
					$header_template->set_var('CLASS', '');
127
				}
128
				$header_template->set_var('TITLE', $title);
129
				// Print link
130
				$header_template->parse('link', 'linkBlock', true);
131
			}
132
		}
133
		$header_template->parse('header', 'header_block', false);
134
		$header_template->pparse('output', 'page');
135
	}
136
	
137
	// Print the admin footer
138
	function print_footer() {
139
		$footer_template = new Template(ADMIN_PATH."/interface");
140
		$footer_template->set_file('page', 'footer.html');
141
		$footer_template->set_block('page', 'footer_block', 'header');
142
		$footer_template->parse('header', 'footer_block', false);
143
		$footer_template->pparse('output', 'page');
144
	}
145
	
146
	// Print a success message which then automatically redirects the user to another page
147
	function print_success($message, $redirect = 'index.php') {
148
		global $TEXT;
149
		$success_template = new Template(ADMIN_PATH.'/interface');
150
		$success_template->set_file('page', 'success.html');
151
		$success_template->set_block('page', 'main_block', 'main');
152
		$success_template->set_var('MESSAGE', $message);
153
		$success_template->set_var('REDIRECT', $redirect);
154
		$success_template->set_var('NEXT', $TEXT['NEXT']);
155
		$success_template->parse('main', 'main_block', false);
156
		$success_template->pparse('output', 'page');
157
	}
158
	
159
	// Print a error message
160
	function print_error($message, $link = 'index.php', $auto_footer = true) {
161
		global $TEXT;
162
		$success_template = new Template(ADMIN_PATH.'/interface');
163
		$success_template->set_file('page', 'error.html');
164
		$success_template->set_block('page', 'main_block', 'main');
165
		$success_template->set_var('MESSAGE', $message);
166
		$success_template->set_var('LINK', $link);
167
		$success_template->set_var('BACK', $TEXT['BACK']);
168
		$success_template->parse('main', 'main_block', false);
169
		$success_template->pparse('output', 'page');
170
		if($auto_footer == true) {
171
			$this->print_footer();
172
		}
173
		exit();
174
	}
175

    
176
	// Return a system permission
177
	function get_permission($name, $type = 'system') {
178
		// Append to permission type
179
		$type .= '_permissions';
180
		// Check if we have a section to check for
181
		if($name == 'start') {
182
			return true;
183
		} else {
184
			// Set system permissions var
185
			$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
186
			// Set module permissions var
187
			$module_permissions = $this->get_session('MODULE_PERMISSIONS');
188
			// Set template permissions var
189
			$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
190
			// Return true if system perm = 1
191
			if(is_numeric(array_search($name, $$type))) {
192
				if($type == 'system_permissions') {
193
					return true;
194
				} else {
195
					return false;
196
				}
197
			} else {
198
				if($type == 'system_permissions') {
199
					return false;
200
				} else {
201
					return true;
202
				}
203
			}
204
		}
205
	}
206

    
207
	// Returns a system permission for a menu link
208
	function get_link_permission($title) {
209
		$title = str_replace('_blank', '', $title);
210
		$title = strtolower($title);
211
		// Set system permissions var
212
		$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
213
		// Set module permissions var
214
		$module_permissions = $this->get_session('MODULE_PERMISSIONS');
215
		if($title == 'start') {
216
			return true;
217
		} else {
218
			// Return true if system perm = 1
219
			if(is_numeric(array_search($title, $system_permissions))) {
220
				return true;
221
			} else {
222
				return false;
223
			}
224
		}
225
	}
226
}
227

    
228
?>
(1-1/11)