Project

General

Profile

1
<?php
2

    
3
// $Id: get_permissions.php 978 2009-04-27 20:09:22Z 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
	$system_permissions['admintools_settings'] = $system_permissions['admintools'];
81
} else {
82
	// Pages
83
	$system_permissions['pages_view'] = $admin->get_post('pages_view');
84
		$system_permissions['pages_add'] = $admin->get_post('pages_add');
85
	if($admin->get_post('pages_add') != 1 AND $admin->get_post('pages_add_l0') == 1) {
86
		$system_permissions['pages_add'] = $admin->get_post('pages_add_l0');
87
	}
88
	$system_permissions['pages_add_l0'] = $admin->get_post('pages_add_l0');
89
	$system_permissions['pages_settings'] = $admin->get_post('pages_settings');
90
	$system_permissions['pages_modify'] = $admin->get_post('pages_modify');
91
	$system_permissions['pages_intro'] = $admin->get_post('pages_intro');
92
	$system_permissions['pages_delete'] = $admin->get_post('pages_delete');
93
	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) {
94
		$system_permissions['pages'] = 1;
95
	} else {
96
		$system_permissions['pages'] = '';
97
	}
98
	// Media
99
	$system_permissions['media_view'] = $admin->get_post('media_view');
100
	$system_permissions['media_upload'] = $admin->get_post('media_upload');
101
	$system_permissions['media_rename'] = $admin->get_post('media_rename');
102
	$system_permissions['media_delete'] = $admin->get_post('media_delete');
103
	$system_permissions['media_create'] = $admin->get_post('media_create');
104
	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) {
105
		$system_permissions['media'] = 1;
106
	} else {
107
		$system_permissions['media'] = '';
108
	}
109
	// Add-ons
110
		// Modules
111
		$system_permissions['modules_view'] = $admin->get_post('modules_view');
112
		$system_permissions['modules_install'] = $admin->get_post('modules_install');
113
		$system_permissions['modules_uninstall'] = $admin->get_post('modules_uninstall');
114
		if($system_permissions['modules_view'] == 1 OR $system_permissions['modules_install'] == 1 OR $system_permissions['modules_uninstall'] == 1) {
115
			$system_permissions['modules'] = 1;
116
		} else {
117
			$system_permissions['modules'] = '';
118
		}
119
		// Templates
120
		$system_permissions['templates_view'] = $admin->get_post('templates_view');
121
		$system_permissions['templates_install'] = $admin->get_post('templates_install');
122
		$system_permissions['templates_uninstall'] = $admin->get_post('templates_uninstall');
123
		if($system_permissions['templates_view'] == 1 OR $system_permissions['templates_install'] == 1 OR $system_permissions['templates_uninstall'] == 1) {
124
			$system_permissions['templates'] = 1;
125
		} else {
126
			$system_permissions['templates'] = '';
127
		}
128
		// Languages
129
		$system_permissions['languages_view'] = $admin->get_post('languages_view');
130
		$system_permissions['languages_install'] = $admin->get_post('languages_install');
131
		$system_permissions['languages_uninstall'] = $admin->get_post('languages_uninstall');
132
		if($system_permissions['languages_install'] == 1 OR $system_permissions['languages_uninstall'] == 1) {
133
			$system_permissions['languages'] = 1;
134
		} else {
135
			$system_permissions['languages'] = '';
136
		}
137
		// Admintools
138
		$system_permissions['admintools_settings'] = $admin->get_post('admintools_settings');
139
		if($system_permissions['admintools_settings'] == 1) {
140
			$system_permissions['admintools'] = 1;
141
		} else {
142
			$system_permissions['admintools'] = '';
143
		}
144
	if($system_permissions['modules'] == 1 OR $system_permissions['templates'] == 1 OR $system_permissions['languages'] == 1) {
145
		$system_permissions['addons'] = 1;
146
	} else {
147
		$system_permissions['addons'] = '';
148
	}
149
	// Settings
150
	$system_permissions['settings_basic'] = $admin->get_post('settings_basic');
151
	$system_permissions['settings_advanced'] = $admin->get_post('settings_advanced');
152
	if($system_permissions['settings_basic'] == 1 OR $system_permissions['settings_advanced'] == 1) {
153
		$system_permissions['settings'] = 1;
154
	} else {
155
		$system_permissions['settings'] = '';
156
	}
157
	// Access
158
		// Users
159
		$system_permissions['users_view'] = $admin->get_post('users_view');
160
		$system_permissions['users_add'] = $admin->get_post('users_add');
161
		$system_permissions['users_modify'] = $admin->get_post('users_modify');
162
		$system_permissions['users_delete'] = $admin->get_post('users_delete');
163
		if($system_permissions['users_view'] == 1 OR $system_permissions['users_add'] == 1 OR $system_permissions['users_modify'] == 1 OR $system_permissions['users_delete'] == 1) {
164
			$system_permissions['users'] = 1;
165
		} else {
166
			$system_permissions['users'] = '';
167
		}
168
		// Groups
169
		$system_permissions['groups_view'] = $admin->get_post('groups_view');
170
		$system_permissions['groups_add'] = $admin->get_post('groups_add');
171
		$system_permissions['groups_modify'] = $admin->get_post('groups_modify');
172
		$system_permissions['groups_delete'] = $admin->get_post('groups_delete');
173
		if($system_permissions['groups_view'] == 1 OR $system_permissions['groups_add'] == 1 OR $system_permissions['groups_modify'] == 1 OR $system_permissions['groups_delete'] == 1) {
174
			$system_permissions['groups'] = 1;
175
		} else {
176
			$system_permissions['groups'] = '';
177
		}
178
	if($system_permissions['users'] == 1 OR $system_permissions['groups'] == 1) {
179
		$system_permissions['access'] = 1;
180
	} else {
181
		$system_permissions['access'] = '';
182
	}
183
}
184

    
185
// Implode system permissions
186
$imploded_system_permissions = '';
187
foreach($system_permissions AS $name => $value) {
188
	if($value == true) {
189
		if($imploded_system_permissions == '') {
190
			$imploded_system_permissions = $name;
191
		} else {
192
			$imploded_system_permissions .= ','.$name;
193
		}
194
	}
195
}
196

    
197
$system_permissions = $imploded_system_permissions;
198

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

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

    
255
?>
(2-2/5)