Project

General

Profile

1 238 stefan
<?php
2
3
/*
4
5
 Website Baker Project <http://www.websitebaker.org/>
6 310 ryan
 Copyright (C) 2004-2006, Ryan Djurovich
7 238 stefan
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 286 stefan
	exit(0);
28 238 stefan
} 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 319 stefan
$user=$admin->get_user_details($results_array['modified_by']);
63
64 238 stefan
// 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 396 Ruebenwurz
								'PAGE_TITLE' => (htmlentities($results_array['page_title'])),
78
								'MENU_TITLE' => (htmlentities($results_array['menu_title'])),
79 238 stefan
								'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 337 stefan
if($results_array['visibility'] == 'private' OR $results_array['visibility'] == 'registered') {
221
	$template->set_var('DISPLAY_VIEWERS', '');
222 238 stefan
} else {
223 337 stefan
	$template->set_var('DISPLAY_VIEWERS', 'none');
224 238 stefan
}
225 288 stefan
226 238 stefan
// Parent page list
227
$database = new database();
228
function parent_list($parent) {
229
	global $admin, $database, $template, $results_array;
230
	$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC";
231
	$get_pages = $database->query($query);
232
	while($page = $get_pages->fetchRow()) {
233
		// If the current page cannot be parent, then its children neither
234
		$list_next_level = true;
235
		// Stop users from adding pages with a level of more than the set page level limit
236
		if($page['level']+1 < PAGE_LEVEL_LIMIT) {
237
			// Get user perms
238
			$admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
239
			$admin_users = explode(',', str_replace('_', '', $page['admin_users']));
240
			if(is_numeric(array_search($admin->get_group_id(), $admin_groups)) OR is_numeric(array_search($admin->get_user_id(), $admin_users))) {
241
				$can_modify = true;
242
			} else {
243
				$can_modify = false;
244
			}
245
			// Title -'s prefix
246
			$title_prefix = '';
247
			for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - '; }
248
			$template->set_var(array(
249
											'ID' => $page['page_id'],
250 396 Ruebenwurz
											'TITLE' => ($title_prefix.htmlentities($page['page_title']))
251 238 stefan
											)
252
									);
253
			if($results_array['parent'] == $page['page_id']) {
254
				$template->set_var('SELECTED', ' selected');
255
			} elseif($results_array['page_id'] == $page['page_id']) {
256
				$template->set_var('SELECTED', ' disabled');
257
				$list_next_level=false;
258
			} elseif($can_modify != true) {
259
				$template->set_var('SELECTED', ' disabled');
260
			} else {
261
				$template->set_var('SELECTED', '');
262
			}
263
			$template->parse('page_list2', 'page_list_block2', true);
264
		}
265
		if ($list_next_level)
266
			parent_list($page['page_id']);
267
	}
268
}
269
$template->set_block('main_block', 'page_list_block2', 'page_list2');
270
if($admin->get_permission('pages_add_l0') == true OR $results_array['level'] == 0) {
271
	if($results_array['parent'] == 0) { $selected = ' selected'; } else { $selected = ''; }
272
	$template->set_var(array(
273
									'ID' => '0',
274
									'TITLE' => $TEXT['NONE'],
275
									'SELECTED' => $selected
276
									)
277
							);
278
	$template->parse('page_list2', 'page_list_block2', true);
279
}
280
parent_list(0);
281
282
if($modified_ts == 'Unknown') {
283
	$template->set_var('DISPLAY_MODIFIED', 'hide');
284
} else {
285
	$template->set_var('DISPLAY_MODIFIED', '');
286
}
287
// Templates list
288
$template->set_block('main_block', 'template_list_block', 'template_list');
289 384 Ruebenwurz
$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'template' order by name");
290 238 stefan
if($result->numRows() > 0) {
291
	while($addon = $result->fetchRow()) {
292
		// Check if the user has perms to use this template
293
		if($addon['directory'] == $results_array['template'] OR $admin->get_permission($addon['directory'], 'template') == true) {
294
			$template->set_var('VALUE', $addon['directory']);
295
			$template->set_var('NAME', $addon['name']);
296
			if($addon['directory'] == $results_array['template']) {
297
				$template->set_var('SELECTED', ' selected');
298
			} else {
299
				$template->set_var('SELECTED', '');
300
			}
301
			$template->parse('template_list', 'template_list_block', true);
302
		}
303
	}
304
}
305
306
// Menu list
307
if(MULTIPLE_MENUS == false) {
308
	$template->set_var('DISPLAY_MENU_LIST', 'none');
309
}
310
// Include template info file (if it exists)
311
if($results_array['template'] != '') {
312
	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
313
} else {
314
	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
315
}
316
if(file_exists($template_location)) {
317
	require($template_location);
318
}
319
// Check if $menu is set
320
if(!isset($menu[1]) OR $menu[1] == '') {
321
	// Make our own menu list
322
	$menu[1] = $TEXT['MAIN'];
323
}
324
// Add menu options to the list
325
$template->set_block('main_block', 'menu_list_block', 'menu_list');
326
foreach($menu AS $number => $name) {
327
	$template->set_var('NAME', $name);
328
	$template->set_var('VALUE', $number);
329
	if($results_array['menu'] == $number) {
330
		$template->set_var('SELECTED', 'selected');
331
	} else {
332
		$template->set_var('SELECTED', '');
333
	}
334
	$template->parse('menu_list', 'menu_list_block', true);
335
}
336
337
// Language list
338
if($handle = opendir(WB_PATH.'/languages/')) {
339
	$template->set_block('main_block', 'language_list_block', 'language_list');
340
	while (false !== ($file = readdir($handle))) {
341
		if($file != '.' AND $file != '..' AND $file != '.svn' AND $file != 'index.php') {
342
			// Include the languages info file
343
			require(WB_PATH.'/languages/'.$file);
344
			// Work-out if this language is selected
345
			if($language_code == $results_array['language']) { $selected = ' selected'; } else { $selected = ''; }
346
			// Set the language info
347
			$template->set_var(array('VALUE' => $language_code, 'SELECTED' => $selected, 'NAME' => $language_name));
348
			// Parse row
349
			$template->parse('language_list', 'language_list_block', true);
350
		}
351
	}
352
}
353
// Restore to original language
354
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
355
356
// Select disabled if searching is disabled
357
if($results_array['searching'] == 0) {
358
	$template->set_var('SEARCHING_DISABLED', ' selected');
359
}
360
// Select what the page target is
361 334 stefan
switch ($results_array['target']) {
362
	case '_top':
363
		$template->set_var('TOP_SELECTED', ' selected');
364
		break;
365
	case '_self':
366
		$template->set_var('SELF_SELECTED', ' selected');
367
		break;
368
	case '_blank':
369
		$template->set_var('BLANK_SELECTED', ' selected');
370
		break;
371 238 stefan
}
372 334 stefan
373 238 stefan
374
// Insert language text
375
$template->set_var(array(
376
								'HEADING_MODIFY_PAGE_SETTINGS' => $HEADING['MODIFY_PAGE_SETTINGS'],
377
								'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
378
								'TEXT_MODIFY' => $TEXT['MODIFY'],
379
								'TEXT_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
380
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
381
								'TEXT_PAGE_TITLE' => $TEXT['PAGE_TITLE'],
382
								'TEXT_MENU_TITLE' => $TEXT['MENU_TITLE'],
383
								'TEXT_TYPE' => $TEXT['TYPE'],
384
								'TEXT_MENU' => $TEXT['MENU'],
385
								'TEXT_PARENT' => $TEXT['PARENT'],
386
								'TEXT_VISIBILITY' => $TEXT['VISIBILITY'],
387
								'TEXT_PUBLIC' => $TEXT['PUBLIC'],
388
								'TEXT_PRIVATE' => $TEXT['PRIVATE'],
389
								'TEXT_REGISTERED' => $TEXT['REGISTERED'],
390
								'TEXT_NONE' => $TEXT['NONE'],
391
								'TEXT_HIDDEN' => $TEXT['HIDDEN'],
392
								'TEXT_TEMPLATE' => $TEXT['TEMPLATE'],
393
								'TEXT_TARGET' => $TEXT['TARGET'],
394
								'TEXT_SYSTEM_DEFAULT' => $TEXT['SYSTEM_DEFAULT'],
395
								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
396
								'TEXT_NEW_WINDOW' => $TEXT['NEW_WINDOW'],
397
								'TEXT_SAME_WINDOW' => $TEXT['SAME_WINDOW'],
398 334 stefan
								'TEXT_TOP_FRAME' => $TEXT['TOP_FRAME'],
399 238 stefan
								'TEXT_ADMINISTRATORS' => $TEXT['ADMINISTRATORS'],
400 337 stefan
								'TEXT_ALLOWED_VIEWERS' => $TEXT['ALLOWED_VIEWERS'],
401 238 stefan
								'TEXT_DESCRIPTION' => $TEXT['DESCRIPTION'],
402
								'TEXT_KEYWORDS' => $TEXT['KEYWORDS'],
403
								'TEXT_SEARCHING' => $TEXT['SEARCHING'],
404
								'TEXT_LANGUAGE' => $TEXT['LANGUAGE'],
405
								'TEXT_ENABLED' => $TEXT['ENABLED'],
406
								'TEXT_DISABLED' => $TEXT['DISABLED'],
407
								'TEXT_SAVE' => $TEXT['SAVE'],
408
								'TEXT_RESET' => $TEXT['RESET'],
409
								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
410
								'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
411
								)
412
						);
413
414
$template->parse('main', 'main_block', false);
415
$template->pparse('output', 'page');
416
417
// Print admin footer
418
$admin->print_footer();
419
420 239 stefan
?>