Project

General

Profile

1
<?php
2

    
3
/*
4

    
5
 Website Baker Project <http://www.websitebaker.org/>
6
 Copyright (C) 2004-2005, Ryan Djurovich
7

    
8
 Website Baker is free software; you can redistribute it and/or modify
9
 it under the terms of the GNU General Public License as published by
10
 the Free Software Foundation; either version 2 of the License, or
11
 (at your option) any later version.
12

    
13
 Website Baker is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 GNU General Public License for more details.
17

    
18
 You should have received a copy of the GNU General Public License
19
 along with Website Baker; if not, write to the Free Software
20
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21

    
22
*/
23

    
24
// Get page id
25
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
26
	header("Location: index.php");
27
} else {
28
	$page_id = $_GET['page_id'];
29
}
30

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

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

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

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

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

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

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

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

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

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

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

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

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

    
419
// Print admin footer
420
$admin->print_footer();
421

    
422
?>
(17-17/20)