Project

General

Profile

1
<?php
2

    
3
// $Id: get_permissions.php 915 2009-01-21 19:27:01Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, 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
if(!defined('WB_PATH')) { exit('Direct access to this file is not allowed'); }
27

    
28
// Get system permissions
29
if($admin->get_post('advanced') != 'yes') {
30
	$system_permissions['pages'] = $admin->get_post('pages');
31
		$system_permissions['pages_view'] = $system_permissions['pages'];
32
		$system_permissions['pages_add'] = $system_permissions['pages'];
33
		$system_permissions['pages_add_l0'] = $system_permissions['pages'];
34
		$system_permissions['pages_settings'] = $system_permissions['pages'];
35
		$system_permissions['pages_modify'] = $system_permissions['pages'];
36
		$system_permissions['pages_intro'] = $system_permissions['pages'];
37
		$system_permissions['pages_delete'] = $system_permissions['pages'];
38
	$system_permissions['media'] = $admin->get_post('media');
39
		$system_permissions['media_view'] = $system_permissions['media'];
40
		$system_permissions['media_upload'] = $system_permissions['media'];
41
		$system_permissions['media_rename'] = $system_permissions['media'];
42
		$system_permissions['media_delete'] = $system_permissions['media'];
43
		$system_permissions['media_create'] = $system_permissions['media'];
44
	if($admin->get_post('modules') != '' OR $admin->get_post('templates') != '' OR $admin->get_post('languages') != '') {
45
		$system_permissions['addons'] = 1;
46
	} else {
47
		$system_permissions['addons'] = 0;
48
	}
49
		$system_permissions['modules'] = $admin->get_post('modules');
50
			$system_permissions['modules_view'] = $system_permissions['modules'];
51
			$system_permissions['modules_install'] = $system_permissions['modules'];
52
			$system_permissions['modules_uninstall'] = $system_permissions['modules'];
53
		$system_permissions['templates'] = $admin->get_post('templates');
54
			$system_permissions['templates_view'] = $system_permissions['templates'];
55
			$system_permissions['templates_install'] = $system_permissions['templates'];
56
			$system_permissions['templates_uninstall'] = $system_permissions['templates'];
57
		$system_permissions['languages'] = $admin->get_post('languages');
58
			$system_permissions['languages_view'] = $system_permissions['languages'];
59
			$system_permissions['languages_install'] = $system_permissions['languages'];
60
			$system_permissions['languages_uninstall'] = $system_permissions['languages'];
61
	$system_permissions['settings'] = $admin->get_post('settings');
62
		$system_permissions['settings_basic'] = $system_permissions['settings'];
63
		$system_permissions['settings_advanced'] = $system_permissions['settings'];
64
	if($admin->get_post('users') != '' AND $admin->get_post('groups') != '') {
65
		$system_permissions['access'] = 1;
66
	} else {
67
		$system_permissions['access'] = 0;
68
	}
69
	$system_permissions['users'] = $admin->get_post('users');
70
	$system_permissions['users_view'] = $system_permissions['users'];
71
	$system_permissions['users_add'] = $system_permissions['users'];
72
	$system_permissions['users_modify'] = $system_permissions['users'];
73
	$system_permissions['users_delete'] = $system_permissions['users'];
74
	$system_permissions['groups'] = $admin->get_post('groups');
75
	$system_permissions['groups_view'] = $system_permissions['groups'];
76
	$system_permissions['groups_add'] = $system_permissions['groups'];
77
	$system_permissions['groups_modify'] = $system_permissions['groups'];
78
	$system_permissions['groups_delete'] = $system_permissions['groups'];
79
	$system_permissions['admintools'] = $admin->get_post('admintools');
80
} else {
81
	// Pages
82
	$system_permissions['pages_view'] = $admin->get_post('pages_view');
83
		$system_permissions['pages_add'] = $admin->get_post('pages_add');
84
	if($admin->get_post('pages_add') != 1 AND $admin->get_post('pages_add_l0') == 1) {
85
		$system_permissions['pages_add'] = $admin->get_post('pages_add_l0');
86
	}
87
	$system_permissions['pages_add_l0'] = $admin->get_post('pages_add_l0');
88
	$system_permissions['pages_settings'] = $admin->get_post('pages_settings');
89
	$system_permissions['pages_modify'] = $admin->get_post('pages_modify');
90
	$system_permissions['pages_intro'] = $admin->get_post('pages_intro');
91
	$system_permissions['pages_delete'] = $admin->get_post('pages_delete');
92
	if($system_permissions['pages_view'] == 1 OR $system_permissions['pages_add'] == 1 OR $system_permissions['pages_settings'] == 1 OR $system_permissions['pages_modify'] == 1 OR $system_permissions['pages_intro'] == 1 OR $system_permissions['pages_delete'] == 1) {
93
		$system_permissions['pages'] = 1;
94
	} else {
95
		$system_permissions['pages'] = '';
96
	}
97
	// Media
98
	$system_permissions['media_view'] = $admin->get_post('media_view');
99
	$system_permissions['media_upload'] = $admin->get_post('media_upload');
100
	$system_permissions['media_rename'] = $admin->get_post('media_rename');
101
	$system_permissions['media_delete'] = $admin->get_post('media_delete');
102
	$system_permissions['media_create'] = $admin->get_post('media_create');
103
	if($system_permissions['media_view'] == 1 OR $system_permissions['media_upload'] == 1 OR $system_permissions['media_rename'] == 1 OR $system_permissions['media_delete'] == 1 OR $system_permissions['media_create'] == 1) {
104
		$system_permissions['media'] = 1;
105
	} else {
106
		$system_permissions['media'] = '';
107
	}
108
	// Add-ons
109
		// Modules
110
		$system_permissions['modules_view'] = $admin->get_post('modules_view');
111
		$system_permissions['modules_install'] = $admin->get_post('modules_install');
112
		$system_permissions['modules_uninstall'] = $admin->get_post('modules_uninstall');
113
		if($system_permissions['modules_view'] == 1 OR $system_permissions['modules_install'] == 1 OR $system_permissions['modules_uninstall'] == 1) {
114
			$system_permissions['modules'] = 1;
115
		} else {
116
			$system_permissions['modules'] = '';
117
		}
118
		// Templates
119
		$system_permissions['templates_view'] = $admin->get_post('templates_view');
120
		$system_permissions['templates_install'] = $admin->get_post('templates_install');
121
		$system_permissions['templates_uninstall'] = $admin->get_post('templates_uninstall');
122
		if($system_permissions['templates_view'] == 1 OR $system_permissions['templates_install'] == 1 OR $system_permissions['templates_uninstall'] == 1) {
123
			$system_permissions['templates'] = 1;
124
		} else {
125
			$system_permissions['templates'] = '';
126
		}
127
		// Languages
128
		$system_permissions['languages_view'] = $admin->get_post('languages_view');
129
		$system_permissions['languages_install'] = $admin->get_post('languages_install');
130
		$system_permissions['languages_uninstall'] = $admin->get_post('languages_uninstall');
131
		if($system_permissions['languages_install'] == 1 OR $system_permissions['languages_uninstall'] == 1) {
132
			$system_permissions['languages'] = 1;
133
		} else {
134
			$system_permissions['languages'] = '';
135
		}
136
	if($system_permissions['modules'] == 1 OR $system_permissions['templates'] == 1 OR $system_permissions['languages'] == 1) {
137
		$system_permissions['addons'] = 1;
138
	} else {
139
		$system_permissions['addons'] = '';
140
	}
141
	// Settings
142
	$system_permissions['settings_basic'] = $admin->get_post('settings_basic');
143
	$system_permissions['settings_advanced'] = $admin->get_post('settings_advanced');
144
	if($system_permissions['settings_basic'] == 1 OR $system_permissions['settings_advanced'] == 1) {
145
		$system_permissions['settings'] = 1;
146
	} else {
147
		$system_permissions['settings'] = '';
148
	}
149
	// Access
150
		// Users
151
		$system_permissions['users_view'] = $admin->get_post('users_view');
152
		$system_permissions['users_add'] = $admin->get_post('users_add');
153
		$system_permissions['users_modify'] = $admin->get_post('users_modify');
154
		$system_permissions['users_delete'] = $admin->get_post('users_delete');
155
		if($system_permissions['users_view'] == 1 OR $system_permissions['users_add'] == 1 OR $system_permissions['users_modify'] == 1 OR $system_permissions['users_delete'] == 1) {
156
			$system_permissions['users'] = 1;
157
		} else {
158
			$system_permissions['users'] = '';
159
		}
160
		// Groups
161
		$system_permissions['groups_view'] = $admin->get_post('groups_view');
162
		$system_permissions['groups_add'] = $admin->get_post('groups_add');
163
		$system_permissions['groups_modify'] = $admin->get_post('groups_modify');
164
		$system_permissions['groups_delete'] = $admin->get_post('groups_delete');
165
		if($system_permissions['groups_view'] == 1 OR $system_permissions['groups_add'] == 1 OR $system_permissions['groups_modify'] == 1 OR $system_permissions['groups_delete'] == 1) {
166
			$system_permissions['groups'] = 1;
167
		} else {
168
			$system_permissions['groups'] = '';
169
		}
170
	if($system_permissions['users'] == 1 OR $system_permissions['groups'] == 1) {
171
		$system_permissions['access'] = 1;
172
	} else {
173
		$system_permissions['access'] = '';
174
	}
175
}
176

    
177
// Implode system permissions
178
$imploded_system_permissions = '';
179
foreach($system_permissions AS $name => $value) {
180
	if($value == true) {
181
		if($imploded_system_permissions == '') {
182
			$imploded_system_permissions = $name;
183
		} else {
184
			$imploded_system_permissions .= ','.$name;
185
		}
186
	}
187
}
188

    
189
$system_permissions = $imploded_system_permissions;
190

    
191
// Get module permissions
192
$module_permissions = '';
193
if($handle = opendir(WB_PATH.'/modules/')) {
194
	while (false !== ($file = readdir($handle))) {
195
		if($file != "." AND $file != ".." AND $file != ".svn" AND is_dir(WB_PATH."/modules/$file") AND file_exists(WB_PATH."/modules/$file/info.php")) {
196
			// Include the modules info file
197
			require(WB_PATH.'/modules/'.$file.'/info.php');
198
			// Check if it was selected to be used or not
199
			$count = 0;
200
			if(is_array($admin->get_post('module_permissions'))) {
201
				foreach($admin->get_post('module_permissions') AS $selected_name) {
202
					if($file == $selected_name) {
203
						$count = $count+1;
204
					}
205
				}
206
			}
207
			if($count == 0) {
208
				// Add unselected modules to list
209
				if($module_permissions == '') {
210
					$module_permissions = $file;
211
				} else {
212
					$module_permissions .= ','.$file;
213
				}
214
			}
215
		}
216
	}
217
}
218

    
219
// Get template permissions
220
$template_permissions = '';
221
if($handle = opendir(WB_PATH.'/templates/')) {
222
	while (false !== ($file = readdir($handle))) {
223
		if($file != "." AND $file != ".." AND $file != ".svn" AND is_dir(WB_PATH."/templates/$file") AND file_exists(WB_PATH."/templates/$file/info.php")) {
224
			// Include the modules info file
225
			require(WB_PATH.'/templates/'.$file.'/info.php');
226
			// Check if it was selected to be used or not
227
			$count = 0;
228
			if(is_array($admin->get_post('template_permissions'))) {
229
				foreach($admin->get_post('template_permissions') AS $selected_name) {
230
					if($file == $selected_name) {
231
						$count = $count+1;
232
					}
233
				}
234
			}
235
			if($count == 0) {
236
				// Add unselected modules to list
237
				if($template_permissions == '') {
238
					$template_permissions = $file;
239
				} else {
240
					$template_permissions .= ','.$file;
241
				}
242
			}
243
		}
244
	}
245
}
246

    
247
?>
(2-2/5)