Project

General

Profile

1
<?php
2

    
3
// $Id: class.admin.php 275 2006-01-14 21:50:48Z 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
}
38

    
39
require_once(WB_PATH.'/framework/class.wb.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

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

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

    
200
?>
(1-1/11)