Project

General

Profile

1
<?php
2

    
3
// $Id: class.admin.php 286 2006-01-23 21:15:10Z stefan $
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
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

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

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

    
53

    
54
class admin extends wb {
55
	// Authenticate user then auto print the header
56
	function admin($section_name, $section_permission = 'start', $auto_header = true, $auto_auth = true) {
57
		$this->wb();
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
				exit(0);
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
		global $database;
88
		$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
													'WEBSITE_TITLE' => ($title['value']),
98
													'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/2/help/', '_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
	// Return a system permission
151
	function get_permission($name, $type = 'system') {
152
		// Append to permission type
153
		$type .= '_permissions';
154
		// Check if we have a section to check for
155
		if($name == 'start') {
156
			return true;
157
		} else {
158
			// Set system permissions var
159
			$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
160
			// Set module permissions var
161
			$module_permissions = $this->get_session('MODULE_PERMISSIONS');
162
			// Set template permissions var
163
			$template_permissions = $this->get_session('TEMPLATE_PERMISSIONS');
164
			// Return true if system perm = 1
165
			if(is_numeric(array_search($name, $$type))) {
166
				if($type == 'system_permissions') {
167
					return true;
168
				} else {
169
					return false;
170
				}
171
			} else {
172
				if($type == 'system_permissions') {
173
					return false;
174
				} else {
175
					return true;
176
				}
177
			}
178
		}
179
	}
180

    
181
	// Returns a system permission for a menu link
182
	function get_link_permission($title) {
183
		$title = str_replace('_blank', '', $title);
184
		$title = strtolower($title);
185
		// Set system permissions var
186
		$system_permissions = $this->get_session('SYSTEM_PERMISSIONS');
187
		// Set module permissions var
188
		$module_permissions = $this->get_session('MODULE_PERMISSIONS');
189
		if($title == 'start') {
190
			return true;
191
		} else {
192
			// Return true if system perm = 1
193
			if(is_numeric(array_search($title, $system_permissions))) {
194
				return true;
195
			} else {
196
				return false;
197
			}
198
		}
199
	}
200
}
201

    
202
?>
(1-1/11)