Project

General

Profile

1
<?php
2

    
3
/*
4

    
5
 Website Baker Project <http://www.websitebaker.org/>
6
 Copyright (C) 2004-2006, 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
	exit(0);
28
} else {
29
	$page_id = $_GET['page_id'];
30
}
31

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

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

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

    
61
// Get display name of person who last modified the page
62
$user=$admin->get_user_details($results_array['modified_by']);
63

    
64
// Convert the unix ts for modified_when to human a readable form
65
if($results_array['modified_when'] != 0) {
66
	$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
67
} else {
68
	$modified_ts = 'Unknown';
69
}
70

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

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

    
98
// Visibility
99
if($results_array['visibility'] == 'public') {
100
	$template->set_var('PUBLIC_SELECTED', ' selected');
101
} elseif($results_array['visibility'] == 'private') {
102
	$template->set_var('PRIVATE_SELECTED', ' selected');
103
} elseif($results_array['visibility'] == 'registered') {
104
	$template->set_var('REGISTERED_SELECTED', ' selected');
105
} elseif($results_array['visibility'] == 'hidden') {
106
	$template->set_var('HIDDEN_SELECTED', ' selected');
107
} elseif($results_array['visibility'] == 'none') {
108
	$template->set_var('NO_VIS_SELECTED', ' selected');
109
}
110
// Group list 1 (admin_groups)
111
	$admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
112
	if($admin->get_group_id() == 1) {
113
		$query = "SELECT * FROM ".TABLE_PREFIX."groups";
114
	} else {
115
		$query = "SELECT * FROM ".TABLE_PREFIX."groups WHERE group_id != '".$admin->get_group_id()."'";
116
	}
117
	$get_groups = $database->query($query);
118
	$template->set_block('main_block', 'group_list_block', 'group_list');
119
	// Insert admin group and current group first
120
	$admin_group_name = $get_groups->fetchRow();
121
	$template->set_var(array(
122
									'ID' => 1,
123
									'TOGGLE' => '',
124
									'DISABLED' => ' disabled',
125
									'LINK_COLOR' => '000000',
126
									'CURSOR' => 'default',
127
									'NAME' => $admin_group_name['name'],
128
									'CHECKED' => ' checked'
129
									)
130
							);
131
	$template->parse('group_list', 'group_list_block', true);
132
	if($admin->get_group_id() != 1) {
133
		$template->set_var(array(
134
										'ID' => $admin->get_group_id(),
135
										'TOGGLE' => '',
136
										'DISABLED' => ' disabled',
137
										'LINK_COLOR' => '000000',
138
										'CURSOR' => 'default',
139
										'NAME' => $admin->get_group_name(),
140
										'CHECKED' => ' checked'
141
										)
142
								);
143
		$template->parse('group_list', 'group_list_block', true);
144
	}
145
	while($group = $get_groups->fetchRow()) {
146
		// Check if the group is allowed to edit pages
147
		$system_permissions = explode(',', $group['system_permissions']);
148
		if(is_numeric(array_search('pages_modify', $system_permissions))) {
149
			$template->set_var(array(
150
											'ID' => $group['group_id'],
151
											'TOGGLE' => $group['group_id'],
152
											'DISABLED' => '',
153
											'LINK_COLOR' => '',
154
											'CURSOR' => 'pointer',
155
											'NAME' => $group['name'],
156
											'CHECKED' => ''
157
											)
158
									);
159
			if(is_numeric(array_search($group['group_id'], $admin_groups))) {
160
				$template->set_var('CHECKED', 'checked');
161
			} else {
162
				$template->set_var('CHECKED', '');
163
			}
164
			$template->parse('group_list', 'group_list_block', true);
165
		}
166
	}
167
// Group list 2 (viewing_groups)
168
	$viewing_groups = explode(',', str_replace('_', '', $results_array['viewing_groups']));
169
	if($admin->get_group_id() == 1) {
170
		$query = "SELECT * FROM ".TABLE_PREFIX."groups";
171
	} else {
172
		$query = "SELECT * FROM ".TABLE_PREFIX."groups WHERE group_id != '".$admin->get_group_id()."'";
173
	}
174
	$get_groups = $database->query($query);
175
	$template->set_block('main_block', 'group_list_block2', 'group_list2');
176
	// Insert admin group and current group first
177
	$admin_group_name = $get_groups->fetchRow();
178
	$template->set_var(array(
179
									'ID' => 1,
180
									'TOGGLE' => '',
181
									'DISABLED' => ' disabled',
182
									'LINK_COLOR' => '000000',
183
									'CURSOR' => 'default',
184
									'NAME' => $admin_group_name['name'],
185
									'CHECKED' => ' checked'
186
									)
187
							);
188
	$template->parse('group_list2', 'group_list_block2', true);
189
	if($admin->get_group_id() != 1) {
190
		$template->set_var(array(
191
										'ID' => $admin->get_group_id(),
192
										'TOGGLE' => '',
193
										'DISABLED' => ' disabled',
194
										'LINK_COLOR' => '000000',
195
										'CURSOR' => 'default',
196
										'NAME' => $admin->get_group_name(),
197
										'CHECKED' => ' checked'
198
										)
199
								);
200
		$template->parse('group_list2', 'group_list_block2', true);
201
	}
202
	while($group = $get_groups->fetchRow()) {
203
		$template->set_var(array(
204
										'ID' => $group['group_id'],
205
										'TOGGLE' => $group['group_id'],
206
										'DISABLED' => '',
207
										'LINK_COLOR' => '',
208
										'CURSOR' => 'pointer',
209
										'NAME' => $group['name'],
210
										)
211
								);
212
		if(is_numeric(array_search($group['group_id'], $viewing_groups))) {
213
			$template->set_var('CHECKED', 'checked');
214
		} else {
215
			$template->set_var('CHECKED', '');
216
		}
217
		$template->parse('group_list2', 'group_list_block2', true);
218
	}
219
// Show private viewers
220
if($results_array['visibility'] == 'private') {
221
	$template->set_var('DISPLAY_PRIVATE', '');
222
} else {
223
	$template->set_var('DISPLAY_PRIVATE', 'none');
224
}
225

    
226
if($results_array['visibility'] == 'registered') {
227
	$template->set_var('DISPLAY_REGISTERED', '');
228
} else {
229
	$template->set_var('DISPLAY_REGISTERED', 'none');
230
}
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' => ($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 OR $results_array['level'] == 0) {
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
$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
296
if($result->numRows() > 0) {
297
	while($addon = $result->fetchRow()) { 
298
		// Check if the user has perms to use this template
299
		if($addon['directory'] == $results_array['template'] OR $admin->get_permission($addon['directory'], 'template') == true) {
300
			$template->set_var('VALUE', $addon['directory']);
301
			$template->set_var('NAME', $addon['name']);
302
			if($addon['directory'] == $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

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

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

    
362
// Select disabled if searching is disabled
363
if($results_array['searching'] == 0) {
364
	$template->set_var('SEARCHING_DISABLED', ' selected');
365
}
366
// Select what the page target is
367
switch ($results_array['target']) {
368
	case '_top':
369
		$template->set_var('TOP_SELECTED', ' selected');
370
		break;
371
	case '_self':
372
		$template->set_var('SELF_SELECTED', ' selected');
373
		break;
374
	case '_blank':
375
		$template->set_var('BLANK_SELECTED', ' selected');
376
		break;
377
}
378
	
379

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

    
421
$template->parse('main', 'main_block', false);
422
$template->pparse('output', 'page');
423

    
424
// Print admin footer
425
$admin->print_footer();
426

    
427
?>
(16-16/19)