Project

General

Profile

1
<?php
2

    
3
// $Id: settings.php,v 1.9 2005/04/08 07:36:58 rdjurovich Exp $
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
// Get page id
27
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
28
	header("Location: index.php");
29
} else {
30
	$page_id = $_GET['page_id'];
31
}
32

    
33
// Create new admin object
34
require('../../config.php');
35
require_once(WB_PATH.'/framework/class.admin.php');
36
$admin = new admin('Pages', 'pages_settings');
37

    
38
// Get perms
39
$database = new database();
40
$results = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
41
$results_array = $results->fetchRow();
42
$old_admin_groups = explode(',', $results_array['admin_groups']);
43
$old_admin_users = explode(',', $results_array['admin_users']);
44
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
45
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
46
}
47

    
48
// Get page details
49
$database = new database();
50
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
51
$results = $database->query($query);
52
if($database->is_error()) {
53
	$admin->print_header();
54
	$admin->print_error($database->get_error());
55
}
56
if($results->numRows() == 0) {
57
	$admin->print_header();
58
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
59
}
60
$results_array = $results->fetchRow();
61

    
62
// Get display name of person who last modified the page
63
$query_user = "SELECT username,display_name FROM ".TABLE_PREFIX."users WHERE user_id = '".$results_array['modified_by']."'";
64
$get_user = $database->query($query_user);
65
if($get_user->numRows() != 0) {
66
	$user = $get_user->fetchRow();
67
} else {
68
	$user['display_name'] = 'Unknown';
69
	$user['username'] = 'unknown';
70
}
71
// Convert the unix ts for modified_when to human a readable form
72
if($results_array['modified_when'] != 0) {
73
	$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
74
} else {
75
	$modified_ts = 'Unknown';
76
}
77

    
78
// Setup template object, parse vars to it, then parse it
79
$template = new Template(ADMIN_PATH.'/pages');
80
$template->set_file('page', 'settings.html');
81
$template->set_block('page', 'main_block', 'main');
82
$template->set_var(array(
83
								'PAGE_ID' => $results_array['page_id'],
84
								'PAGE_TITLE' => stripslashes($results_array['page_title']),
85
								'MENU_TITLE' => stripslashes($results_array['menu_title']),
86
								'DESCRIPTION' => stripslashes($results_array['description']),
87
								'KEYWORDS' => stripslashes($results_array['keywords']),
88
								'MODIFIED_BY' => $user['display_name'],
89
								'MODIFIED_BY_USERNAME' => $user['username'],
90
								'MODIFIED_WHEN' => $modified_ts,
91
								'ADMIN_URL' => ADMIN_URL
92
								)
93
						);
94

    
95
// Work-out if we should show the "manage sections" link
96
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
97
if($query_sections->numRows() > 0) {
98
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
99
} elseif(MANAGE_SECTIONS == 'enabled') {
100
	$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
101
} else {
102
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
103
}
104

    
105
// Visibility
106
if($results_array['visibility'] == 'public') {
107
	$template->set_var('PUBLIC_SELECTED', ' selected');
108
} elseif($results_array['visibility'] == 'private') {
109
	$template->set_var('PRIVATE_SELECTED', ' selected');
110
} elseif($results_array['visibility'] == 'registered') {
111
	$template->set_var('REGISTERED_SELECTED', ' registered');
112
} elseif($results_array['visibility'] == 'hidden') {
113
	$template->set_var('HIDDEN_SELECTED', ' selected');
114
} elseif($results_array['visibility'] == 'none') {
115
	$template->set_var('NO_VIS_SELECTED', ' selected');
116
}
117
// Group list 1 (admin_groups)
118
	$admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
119
	if($admin->get_group_id() == 1) {
120
		$query = "SELECT * FROM ".TABLE_PREFIX."groups";
121
	} else {
122
		$query = "SELECT * FROM ".TABLE_PREFIX."groups WHERE group_id != '".$admin->get_group_id()."'";
123
	}
124
	$get_groups = $database->query($query);
125
	$template->set_block('main_block', 'group_list_block', 'group_list');
126
	// Insert admin group and current group first
127
	$admin_group_name = $get_groups->fetchRow();
128
	$template->set_var(array(
129
									'ID' => 1,
130
									'TOGGLE' => '',
131
									'DISABLED' => ' disabled',
132
									'LINK_COLOR' => '000000',
133
									'CURSOR' => 'default',
134
									'NAME' => $admin_group_name['name'],
135
									'CHECKED' => ' checked'
136
									)
137
							);
138
	$template->parse('group_list', 'group_list_block', true);
139
	if($admin->get_group_id() != 1) {
140
		$template->set_var(array(
141
										'ID' => $admin->get_group_id(),
142
										'TOGGLE' => '',
143
										'DISABLED' => ' disabled',
144
										'LINK_COLOR' => '000000',
145
										'CURSOR' => 'default',
146
										'NAME' => $admin->get_group_name(),
147
										'CHECKED' => ' checked'
148
										)
149
								);
150
		$template->parse('group_list', 'group_list_block', true);
151
	}
152
	while($group = $get_groups->fetchRow()) {
153
		// Check if the group is allowed to edit pages
154
		$system_permissions = explode(',', $group['system_permissions']);
155
		if(is_numeric(array_search('pages_modify', $system_permissions))) {
156
			$template->set_var(array(
157
											'ID' => $group['group_id'],
158
											'TOGGLE' => $group['group_id'],
159
											'DISABLED' => '',
160
											'LINK_COLOR' => '',
161
											'CURSOR' => 'pointer',
162
											'NAME' => $group['name'],
163
											'CHECKED' => ''
164
											)
165
									);
166
			if(is_numeric(array_search($group['group_id'], $admin_groups))) {
167
				$template->set_var('CHECKED', 'checked');
168
			} else {
169
				$template->set_var('CHECKED', '');
170
			}
171
			$template->parse('group_list', 'group_list_block', true);
172
		}
173
	}
174
// Group list 2 (viewing_groups)
175
	$viewing_groups = explode(',', str_replace('_', '', $results_array['viewing_groups']));
176
	if($admin->get_group_id() == 1) {
177
		$query = "SELECT * FROM ".TABLE_PREFIX."groups";
178
	} else {
179
		$query = "SELECT * FROM ".TABLE_PREFIX."groups WHERE group_id != '".$admin->get_group_id()."'";
180
	}
181
	$get_groups = $database->query($query);
182
	$template->set_block('main_block', 'group_list_block2', 'group_list2');
183
	// Insert admin group and current group first
184
	$admin_group_name = $get_groups->fetchRow();
185
	$template->set_var(array(
186
									'ID' => 1,
187
									'TOGGLE' => '',
188
									'DISABLED' => ' disabled',
189
									'LINK_COLOR' => '000000',
190
									'CURSOR' => 'default',
191
									'NAME' => $admin_group_name['name'],
192
									'CHECKED' => ' checked'
193
									)
194
							);
195
	$template->parse('group_list2', 'group_list_block2', true);
196
	if($admin->get_group_id() != 1) {
197
		$template->set_var(array(
198
										'ID' => $admin->get_group_id(),
199
										'TOGGLE' => '',
200
										'DISABLED' => ' disabled',
201
										'LINK_COLOR' => '000000',
202
										'CURSOR' => 'default',
203
										'NAME' => $admin->get_group_name(),
204
										'CHECKED' => ' checked'
205
										)
206
								);
207
		$template->parse('group_list2', 'group_list_block2', true);
208
	}
209
	while($group = $get_groups->fetchRow()) {
210
		$template->set_var(array(
211
										'ID' => $group['group_id'],
212
										'TOGGLE' => $group['group_id'],
213
										'DISABLED' => '',
214
										'LINK_COLOR' => '',
215
										'CURSOR' => 'pointer',
216
										'NAME' => $group['name'],
217
										)
218
								);
219
		if(is_numeric(array_search($group['group_id'], $viewing_groups))) {
220
			$template->set_var('CHECKED', 'checked');
221
		} else {
222
			$template->set_var('CHECKED', '');
223
		}
224
		$template->parse('group_list2', 'group_list_block2', true);
225
	}
226
// Show private viewers
227
if($results_array['visibility'] == 'private') {
228
	$template->set_var('DISPLAY_PRIVATE', '');
229
} else {
230
	$template->set_var('DISPLAY_PRIVATE', 'none');
231
}
232
// Parent page list
233
$database = new database();
234
function parent_list($parent) {
235
	global $admin, $database, $template, $results_array;
236
	$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC";
237
	$get_pages = $database->query($query);
238
	while($page = $get_pages->fetchRow()) {
239
		// If the current page cannot be parent, then its children neither
240
		$list_next_level = true;
241
		// Stop users from adding pages with a level of more than the set page level limit
242
		if($page['level']+1 < PAGE_LEVEL_LIMIT) {
243
			// Get user perms
244
			$admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
245
			$admin_users = explode(',', str_replace('_', '', $page['admin_users']));
246
			if(is_numeric(array_search($admin->get_group_id(), $admin_groups)) OR is_numeric(array_search($admin->get_user_id(), $admin_users))) {
247
				$can_modify = true;
248
			} else {
249
				$can_modify = false;
250
			}
251
			// Title -'s prefix
252
			$title_prefix = '';
253
			for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - '; }
254
				$template->set_var(array(
255
												'ID' => $page['page_id'],
256
												'TITLE' => stripslashes($title_prefix.$page['page_title'])
257
												)
258
										);
259
				if($results_array['parent'] == $page['page_id']) {
260
					$template->set_var('SELECTED', ' selected');
261
				} elseif($results_array['page_id'] == $page['page_id']) {
262
					$template->set_var('SELECTED', ' disabled');
263
					$list_next_level=false;
264
				} elseif($can_modify != true) {
265
					$template->set_var('SELECTED', ' disabled');
266
				} else {
267
					$template->set_var('SELECTED', '');
268
				}
269
				$template->parse('page_list2', 'page_list_block2', true);
270
			}
271
		if ($list_next_level)
272
			parent_list($page['page_id']);
273
	}
274
}
275
$template->set_block('main_block', 'page_list_block2', 'page_list2');
276
if($admin->get_permission('pages_add_l0') == true) {
277
	if($results_array['parent'] == 0) { $selected = ' selected'; } else { $selected = ''; }
278
	$template->set_var(array(
279
									'ID' => '0',
280
									'TITLE' => $TEXT['NONE'],
281
									'SELECTED' => $selected
282
									)
283
							);
284
	$template->parse('page_list2', 'page_list_block2', true);
285
}
286
parent_list(0);
287

    
288
if($modified_ts == 'Unknown') {
289
	$template->set_var('DISPLAY_MODIFIED', 'hide');
290
} else {
291
	$template->set_var('DISPLAY_MODIFIED', '');
292
}
293
// Templates list
294
$template->set_block('main_block', 'template_list_block', 'template_list');
295
if($handle = opendir(WB_PATH.'/templates/')) {
296
	while(false !== ($file = readdir($handle))) {
297
		if($file != "." AND $file != ".." AND $file != "CVS" AND is_dir(WB_PATH."/templates/$file") AND file_exists(WB_PATH.'/templates/'.$file.'/info.php')) {
298
			// Include the templates info file
299
			require(WB_PATH.'/templates/'.$file.'/info.php');
300
			// Check if the user has perms to use this template
301
			if($file == $results_array['template'] OR $admin->get_permission($file, 'template') == true) {
302
				$template->set_var('VALUE', $file);
303
				$template->set_var('NAME', $template_name);
304
				if($file == $results_array['template']) {
305
					$template->set_var('SELECTED', ' selected');
306
				} else {
307
					$template->set_var('SELECTED', '');
308
				}
309
				$template->parse('template_list', 'template_list_block', true);
310
			}
311
		}
312
	}
313
	// Unset all menu arrays
314
	unset($menu);
315
}
316

    
317
// Menu list
318
if(MULTIPLE_MENUS == false) {
319
	$template->set_var('DISPLAY_MENU_LIST', 'none');
320
}
321
// Include template info file (if it exists)
322
if($results_array['template'] != '') {
323
	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
324
} else {
325
	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
326
}
327
if(file_exists($template_location)) {
328
	require($template_location);
329
}
330
// Check if $menu is set
331
if(!isset($menu[1]) OR $menu[1] == '') {
332
	// Make our own menu list
333
	$menu[1] = $TEXT['MAIN'];
334
}
335
// Add menu options to the list
336
$template->set_block('main_block', 'menu_list_block', 'menu_list');
337
foreach($menu AS $number => $name) {
338
	$template->set_var('NAME', $name);
339
	$template->set_var('VALUE', $number);
340
	if($results_array['menu'] == $number) {
341
		$template->set_var('SELECTED', 'selected');
342
	} else {
343
		$template->set_var('SELECTED', '');
344
	}
345
	$template->parse('menu_list', 'menu_list_block', true);
346
}
347

    
348
// Language list
349
if($handle = opendir(WB_PATH.'/languages/')) {
350
	$template->set_block('main_block', 'language_list_block', 'language_list');
351
	while (false !== ($file = readdir($handle))) {
352
		if($file != '.' AND $file != '..' AND $file != 'CVS' AND $file != 'index.php') {
353
			// Include the languages info file
354
			require(WB_PATH.'/languages/'.$file);
355
			// Work-out if this language is selected
356
			if($language_code == $results_array['language']) { $selected = ' selected'; } else { $selected = ''; }
357
			// Set the language info
358
			$template->set_var(array('VALUE' => $language_code, 'SELECTED' => $selected, 'NAME' => $language_name));
359
			// Parse row
360
			$template->parse('language_list', 'language_list_block', true);
361
		}
362
	}
363
}
364
// Restore to original language
365
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
366

    
367
// Select disabled if searching is disabled
368
if($results_array['searching'] == 0) {
369
	$template->set_var('SEARCHING_DISABLED', ' selected');
370
}
371
// Select what the page target is
372
if($results_array['target'] == '_top') {
373
	$template->set_var('TOP_SELECTED', ' selected');
374
} elseif($results_array['target'] == '_blank') {
375
	$template->set_var('BLANK_SELECTED', ' selected');
376
}
377

    
378
// Insert language text
379
$template->set_var(array(
380
								'HEADING_MODIFY_PAGE_SETTINGS' => $HEADING['MODIFY_PAGE_SETTINGS'],
381
								'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
382
								'TEXT_MODIFY' => $TEXT['MODIFY'],
383
								'TEXT_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
384
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
385
								'TEXT_PAGE_TITLE' => $TEXT['PAGE_TITLE'],
386
								'TEXT_MENU_TITLE' => $TEXT['MENU_TITLE'],
387
								'TEXT_TYPE' => $TEXT['TYPE'],
388
								'TEXT_MENU' => $TEXT['MENU'],
389
								'TEXT_PARENT' => $TEXT['PARENT'],
390
								'TEXT_VISIBILITY' => $TEXT['VISIBILITY'],
391
								'TEXT_PUBLIC' => $TEXT['PUBLIC'],
392
								'TEXT_PRIVATE' => $TEXT['PRIVATE'],
393
								'TEXT_REGISTERED' => $TEXT['REGISTERED'],
394
								'TEXT_NONE' => $TEXT['NONE'],
395
								'TEXT_HIDDEN' => $TEXT['HIDDEN'],
396
								'TEXT_TEMPLATE' => $TEXT['TEMPLATE'],
397
								'TEXT_TARGET' => $TEXT['TARGET'],
398
								'TEXT_SYSTEM_DEFAULT' => $TEXT['SYSTEM_DEFAULT'],
399
								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
400
								'TEXT_NEW_WINDOW' => $TEXT['NEW_WINDOW'],
401
								'TEXT_SAME_WINDOW' => $TEXT['SAME_WINDOW'],
402
								'TEXT_ADMINISTRATORS' => $TEXT['ADMINISTRATORS'],
403
								'TEXT_PRIVATE_VIEWERS' => $TEXT['PRIVATE_VIEWERS'],
404
								'TEXT_REGISTERED_VIEWERS' => $TEXT['REGISTERED_VIEWERS'],
405
								'TEXT_DESCRIPTION' => $TEXT['DESCRIPTION'],
406
								'TEXT_KEYWORDS' => $TEXT['KEYWORDS'],
407
								'TEXT_SEARCHING' => $TEXT['SEARCHING'],
408
								'TEXT_LANGUAGE' => $TEXT['LANGUAGE'],
409
								'TEXT_ENABLED' => $TEXT['ENABLED'],
410
								'TEXT_DISABLED' => $TEXT['DISABLED'],
411
								'TEXT_SAVE' => $TEXT['SAVE'],
412
								'TEXT_RESET' => $TEXT['RESET'],
413
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
414
								'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
415
								)
416
						);
417

    
418
$template->parse('main', 'main_block', false);
419
$template->pparse('output', 'page');
420

    
421
// Print admin footer
422
$admin->print_footer();
423

    
424
?>
(17-17/20)