Project

General

Profile

1
<?php
2

    
3
// $Id: settings.php 1009 2009-06-23 21:42:33Z 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
// Get page id
27
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
28
	header("Location: index.php");
29
	exit(0);
30
} else {
31
	$page_id = $_GET['page_id'];
32
}
33

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

    
39
// Include the WB functions file
40
require_once(WB_PATH.'/framework/functions-utf8.php');
41

    
42
// Get perms
43
$database = new database();
44
$results = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
45
$results_array = $results->fetchRow();
46
$old_admin_groups = explode(',', $results_array['admin_groups']);
47
$old_admin_users = explode(',', $results_array['admin_users']);
48

    
49
$in_old_group = FALSE;
50
foreach($admin->get_groups_id() as $cur_gid){
51
	if (in_array($cur_gid, $old_admin_groups)) {
52
		$in_old_group = TRUE;
53
	}
54
}
55
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
56
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
57
}
58

    
59
// Get page details
60
$database = new database();
61
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
62
$results = $database->query($query);
63
if($database->is_error()) {
64
	$admin->print_header();
65
	$admin->print_error($database->get_error());
66
}
67
if($results->numRows() == 0) {
68
	$admin->print_header();
69
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
70
}
71
$results_array = $results->fetchRow();
72

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

    
76
// Convert the unix ts for modified_when to human a readable form
77
if($results_array['modified_when'] != 0) {
78
	$modified_ts = gmdate(TIME_FORMAT.', '.DATE_FORMAT, $results_array['modified_when']+TIMEZONE);
79
} else {
80
	$modified_ts = 'Unknown';
81
}
82

    
83
// Setup template object, parse vars to it, then parse it
84
$template = new Template(THEME_PATH.'/templates');
85
$template->set_file('page', 'pages_settings.htt');
86
$template->set_block('page', 'main_block', 'main');
87

    
88
$template->set_var(array(
89
				'PAGE_ID' => $results_array['page_id'],
90
				'PAGE_TITLE' => ($results_array['page_title']),
91
				'MENU_TITLE' => ($results_array['menu_title']),
92
				'DESCRIPTION' => ($results_array['description']),
93
				'KEYWORDS' => ($results_array['keywords']),
94
				'MODIFIED_BY' => $user['display_name'],
95
				'MODIFIED_BY_USERNAME' => $user['username'],
96
				'MODIFIED_WHEN' => $modified_ts,
97
				'ADMIN_URL' => ADMIN_URL,
98
				'WB_URL' => WB_URL,
99
				'WB_PATH' => WB_PATH,
100
				'THEME_URL' => THEME_URL,
101
			) );
102

    
103
// Work-out if we should show the "manage sections" link
104
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
105
if($query_sections->numRows() > 0) {
106
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
107
} elseif(MANAGE_SECTIONS == 'enabled') {
108
	$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
109
} else {
110
	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
111
}
112

    
113
// Visibility
114
if($results_array['visibility'] == 'public') {
115
	$template->set_var('PUBLIC_SELECTED', ' selected="selected"');
116
} elseif($results_array['visibility'] == 'private') {
117
	$template->set_var('PRIVATE_SELECTED', ' selected="selected"');
118
} elseif($results_array['visibility'] == 'registered') {
119
	$template->set_var('REGISTERED_SELECTED', ' selected="selected"');
120
} elseif($results_array['visibility'] == 'hidden') {
121
	$template->set_var('HIDDEN_SELECTED', ' selected="selected"');
122
} elseif($results_array['visibility'] == 'none') {
123
	$template->set_var('NO_VIS_SELECTED', ' selected="selected"');
124
}
125
// Group list 1 (admin_groups)
126
	$admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
127

    
128
	$query = "SELECT * FROM ".TABLE_PREFIX."groups";
129
	
130
	$get_groups = $database->query($query);
131
	$template->set_block('main_block', 'group_list_block', 'group_list');
132
	// Insert admin group and current group first
133
	$admin_group_name = $get_groups->fetchRow();
134
	$template->set_var(array(
135
									'ID' => 1,
136
									'TOGGLE' => '',
137
									'DISABLED' => ' disabled="disabled"',
138
									'LINK_COLOR' => '000000',
139
									'CURSOR' => 'default',
140
									'NAME' => $admin_group_name['name'],
141
									'CHECKED' => ' checked="checked"'
142
									)
143
							);
144
	$template->parse('group_list', 'group_list_block', true);
145
	/*
146
	if(!in_array(1, $admin->get_groups_id())) {
147
		$users_groups = $admin->get_groups_name();
148
		foreach ($admin->get_groups_id() as $users_group_id) {
149
			$template->set_var(array(
150
										'ID' => $users_group_id,
151
										'TOGGLE' => '',
152
										'DISABLED' => ' disabled',
153
										'LINK_COLOR' => '000000',
154
										'CURSOR' => 'default',
155
										'NAME' => $users_groups[$users_group_id],
156
										'CHECKED' => ' checked'
157
										)
158
								);
159
			$template->parse('group_list', 'group_list_block', true);
160
		}
161
	}
162
	*/
163
	while($group = $get_groups->fetchRow()) {
164
		// check if the user is a member of this group
165
		$flag_disabled = '';
166
		$flag_checked =  '';
167
		$flag_cursor =   'pointer';
168
		$flag_color =    '';
169
		if (in_array($group["group_id"], $admin->get_groups_id())) {
170
			$flag_disabled = ''; //' disabled';
171
			$flag_checked =  ''; //' checked';
172
			$flag_cursor =   'default';
173
			$flag_color =    '000000';
174
		}
175

    
176
		// Check if the group is allowed to edit pages
177
		$system_permissions = explode(',', $group['system_permissions']);
178
		if(is_numeric(array_search('pages_modify', $system_permissions))) {
179
			$template->set_var(array(
180
											'ID' => $group['group_id'],
181
											'TOGGLE' => $group['group_id'],
182
											'DISABLED' => $flag_disabled,
183
											'LINK_COLOR' => $flag_color,
184
											'CURSOR' => $flag_cursor,
185
											'NAME' => $group['name'],
186
											'CHECKED' => $flag_checked
187
											)
188
									);
189
			if(is_numeric(array_search($group['group_id'], $admin_groups))) {
190
				$template->set_var('CHECKED', ' checked="checked"');
191
			} else {
192
				if (!$flag_checked) $template->set_var('CHECKED', '');
193
			}
194
			$template->parse('group_list', 'group_list_block', true);
195
		}
196
	}
197
// Group list 2 (viewing_groups)
198
	$viewing_groups = explode(',', str_replace('_', '', $results_array['viewing_groups']));
199

    
200
	$query = "SELECT * FROM ".TABLE_PREFIX."groups";
201

    
202
	$get_groups = $database->query($query);
203
	$template->set_block('main_block', 'group_list_block2', 'group_list2');
204
	// Insert admin group and current group first
205
	$admin_group_name = $get_groups->fetchRow();
206
	$template->set_var(array(
207
									'ID' => 1,
208
									'TOGGLE' => '',
209
									'DISABLED' => ' disabled="disabled"',
210
									'LINK_COLOR' => '000000',
211
									'CURSOR' => 'default',
212
									'NAME' => $admin_group_name['name'],
213
									'CHECKED' => ' checked="checked"'
214
									)
215
							);
216
	$template->parse('group_list2', 'group_list_block2', true);
217

    
218

    
219
	while($group = $get_groups->fetchRow()) {
220
		// check if the user is a member of this group
221
		$flag_disabled = '';
222
		$flag_checked =  '';
223
		$flag_cursor =   'pointer';
224
		$flag_color =    '';
225
		if (in_array($group["group_id"], $admin->get_groups_id())) {
226
			$flag_disabled = ''; //' disabled';
227
			$flag_checked =  ''; //' checked';
228
			$flag_cursor =   'default';
229
			$flag_color =    '000000';
230
		}
231

    
232
		$template->set_var(array(
233
										'ID' => $group['group_id'],
234
										'TOGGLE' => $group['group_id'],
235
										'DISABLED' => $flag_disabled,
236
										'LINK_COLOR' => $flag_color,
237
										'CURSOR' => $flag_cursor,
238
										'NAME' => $group['name'],
239
										'CHECKED' => $flag_checked
240
										)
241
								);
242
		if(is_numeric(array_search($group['group_id'], $viewing_groups))) {
243
			$template->set_var('CHECKED', 'checked="checked"');
244
		} else {
245
			if (!$flag_checked) $template->set_var('CHECKED', '');
246
		}
247
		$template->parse('group_list2', 'group_list_block2', true);
248
	}
249
// Show private viewers
250
if($results_array['visibility'] == 'private' OR $results_array['visibility'] == 'registered') {
251
	$template->set_var('DISPLAY_VIEWERS', '');
252
} else {
253
	$template->set_var('DISPLAY_VIEWERS', 'none');
254
}
255

    
256
// Parent page list
257
$database = new database();
258
function parent_list($parent) {
259
	global $admin, $database, $template, $results_array;
260
	$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC";
261
	$get_pages = $database->query($query);
262
	while($page = $get_pages->fetchRow()) {
263
		if($admin->page_is_visible($page)==false)
264
			continue;
265
		// if psrent = 0 set flag_icon
266
		$template->set_var('FLAG_ROOT_ICON',' none ');
267
		if( $page['parent'] == 0 ) {
268
			$template->set_var('FLAG_ROOT_ICON','url('.THEME_URL.'/images/flags/'.strtolower($page['language']).'.png)');
269
		}
270
		// If the current page cannot be parent, then its children neither
271
		$list_next_level = true;
272
		// Stop users from adding pages with a level of more than the set page level limit
273
		if($page['level']+1 < PAGE_LEVEL_LIMIT) {
274
			// Get user perms
275
			$admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
276
			$admin_users = explode(',', str_replace('_', '', $page['admin_users']));
277
			$in_group = FALSE;
278
			foreach($admin->get_groups_id() as $cur_gid){
279
				if (in_array($cur_gid, $admin_groups)) {
280
					$in_group = TRUE;
281
				}
282
			}
283
			if(($in_group) OR is_numeric(array_search($admin->get_user_id(), $admin_users))) {
284
				$can_modify = true;
285
			} else {
286
				$can_modify = false;
287
			}
288
			// Title -'s prefix
289
			$title_prefix = '';
290
			for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - '; }
291
			$template->set_var(array(
292
											'ID' => $page['page_id'],
293
											'TITLE' => ($title_prefix.$page['page_title']),
294
											'FLAG_ICON' => 'none',
295
											));
296

    
297
			if($results_array['parent'] == $page['page_id']) {
298
				$template->set_var('SELECTED', ' selected="selected"');
299
			} elseif($results_array['page_id'] == $page['page_id']) {
300
				$template->set_var('SELECTED', ' disabled="disabled" class="disabled"');
301
				$list_next_level=false;
302
			} elseif($can_modify != true) {
303
				$template->set_var('SELECTED', ' disabled="disabled" class="disabled"');
304
			} else {
305
				$template->set_var('SELECTED', '');
306
			}
307
			$template->parse('page_list2', 'page_list_block2', true);
308
		}
309
		if ($list_next_level)
310
			parent_list($page['page_id']);
311
	}
312
}
313

    
314
$template->set_block('main_block', 'page_list_block2', 'page_list2');
315
if($admin->get_permission('pages_add_l0') == true OR $results_array['level'] == 0) {
316
	if($results_array['parent'] == 0) {
317
		$selected = ' selected';
318
	} else { 
319
		$selected = '';
320
	}
321
	$template->set_var(array(
322
									'ID' => '0',
323
									'TITLE' => $TEXT['NONE'],
324
									'SELECTED' => $selected
325
									)
326
							);
327
	$template->parse('page_list2', 'page_list_block2', true);
328
}
329
parent_list(0);
330

    
331
if($modified_ts == 'Unknown') {
332
	$template->set_var('DISPLAY_MODIFIED', 'hide');
333
} else {
334
	$template->set_var('DISPLAY_MODIFIED', '');
335
}
336
// Templates list
337
$template->set_block('main_block', 'template_list_block', 'template_list');
338
$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'template' and function = 'template' order by name");
339
if($result->numRows() > 0) {
340
	while($addon = $result->fetchRow()) { 
341
		// Check if the user has perms to use this template
342
		if($addon['directory'] == $results_array['template'] OR $admin->get_permission($addon['directory'], 'template') == true) {
343
			$template->set_var('VALUE', $addon['directory']);
344
			$template->set_var('NAME', $addon['name']);
345
			if($addon['directory'] == $results_array['template']) {
346
				$template->set_var('SELECTED', ' selected="selected"');
347
			} else {
348
				$template->set_var('SELECTED', '');
349
			}
350
			$template->parse('template_list', 'template_list_block', true);
351
		}
352
	}
353
}
354

    
355
// Menu list
356
if(MULTIPLE_MENUS == false) {
357
	$template->set_var('DISPLAY_MENU_LIST', 'none');
358
}
359
// Include template info file (if it exists)
360
if($results_array['template'] != '') {
361
	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
362
} else {
363
	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
364
}
365
if(file_exists($template_location)) {
366
	require($template_location);
367
}
368
// Check if $menu is set
369
if(!isset($menu[1]) OR $menu[1] == '') {
370
	// Make our own menu list
371
	$menu[1] = $TEXT['MAIN'];
372
}
373
// Add menu options to the list
374
$template->set_block('main_block', 'menu_list_block', 'menu_list');
375
foreach($menu AS $number => $name) {
376
	$template->set_var('NAME', $name);
377
	$template->set_var('VALUE', $number);
378
	if($results_array['menu'] == $number) {
379
		$template->set_var('SELECTED', ' selected="selected"');
380
	} else {
381
		$template->set_var('SELECTED', '');
382
	}
383
	$template->parse('menu_list', 'menu_list_block', true);
384
}
385

    
386
// Insert language values
387
$template->set_block('main_block', 'language_list_block', 'language_list');
388
$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'language' order by name");
389
if($result->numRows() > 0) {
390
	while($addon = $result->fetchRow()) {
391
		$l_codes[$addon['name']] = $addon['directory'];
392
		$l_names[$addon['name']] = entities_to_7bit($addon['name']); // sorting-problem workaround
393
	}
394
	asort($l_names);
395
	foreach($l_names as $l_name=>$v) {
396
		// Insert code and name
397
		$template->set_var(array(
398
								'VALUE' => $l_codes[$l_name],
399
								'NAME' => $l_name,
400
								'FLAG_LANG_ICONS' => 'url('.THEME_URL.'/images/flags/'.strtolower($l_codes[$l_name]).'.png)',
401
								));
402
		// Check if it is selected
403
		if($results_array['language'] == $l_codes[$l_name]) {
404
			$template->set_var('SELECTED', ' selected="selected"');
405
		} else {
406
			$template->set_var('SELECTED', '');
407
		}
408
		$template->parse('language_list', 'language_list_block', true);
409
	}
410
}
411

    
412
// Select disabled if searching is disabled
413
if($results_array['searching'] == 0) {
414
	$template->set_var('SEARCHING_DISABLED', ' selected="selected"');
415
}
416
// Select what the page target is
417
switch ($results_array['target']) {
418
	case '_top':
419
		$template->set_var('TOP_SELECTED', ' selected="selected"');
420
		break;
421
	case '_self':
422
		$template->set_var('SELF_SELECTED', ' selected="selected"');
423
		break;
424
	case '_blank':
425
		$template->set_var('BLANK_SELECTED', ' selected="selected"');
426
		break;
427
}
428
	
429

    
430
// Insert language text
431
$template->set_var(array(
432
				'HEADING_MODIFY_PAGE_SETTINGS' => $HEADING['MODIFY_PAGE_SETTINGS'],
433
				'TEXT_CURRENT_PAGE' => $TEXT['CURRENT_PAGE'],
434
				'TEXT_MODIFY' => $TEXT['MODIFY'],
435
				'TEXT_MODIFY_PAGE' => $HEADING['MODIFY_PAGE'],
436
				'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
437
				'TEXT_PAGE_TITLE' => $TEXT['PAGE_TITLE'],
438
				'TEXT_MENU_TITLE' => $TEXT['MENU_TITLE'],
439
				'TEXT_TYPE' => $TEXT['TYPE'],
440
				'TEXT_MENU' => $TEXT['MENU'],
441
				'TEXT_PARENT' => $TEXT['PARENT'],
442
				'TEXT_VISIBILITY' => $TEXT['VISIBILITY'],
443
				'TEXT_PUBLIC' => $TEXT['PUBLIC'],
444
				'TEXT_PRIVATE' => $TEXT['PRIVATE'],
445
				'TEXT_REGISTERED' => $TEXT['REGISTERED'],
446
				'TEXT_NONE' => $TEXT['NONE'],
447
				'TEXT_HIDDEN' => $TEXT['HIDDEN'],
448
				'TEXT_TEMPLATE' => $TEXT['TEMPLATE'],
449
				'TEXT_TARGET' => $TEXT['TARGET'],
450
				'TEXT_SYSTEM_DEFAULT' => $TEXT['SYSTEM_DEFAULT'],
451
				'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT'],
452
				'TEXT_NEW_WINDOW' => $TEXT['NEW_WINDOW'],
453
				'TEXT_SAME_WINDOW' => $TEXT['SAME_WINDOW'],
454
				'TEXT_TOP_FRAME' => $TEXT['TOP_FRAME'],
455
				'TEXT_ADMINISTRATORS' => $TEXT['ADMINISTRATORS'],
456
				'TEXT_ALLOWED_VIEWERS' => $TEXT['ALLOWED_VIEWERS'],
457
				'TEXT_DESCRIPTION' => $TEXT['DESCRIPTION'],
458
				'TEXT_KEYWORDS' => $TEXT['KEYWORDS'],
459
				'TEXT_SEARCHING' => $TEXT['SEARCHING'],
460
				'TEXT_LANGUAGE' => $TEXT['LANGUAGE'],
461
				'TEXT_ENABLED' => $TEXT['ENABLED'],
462
				'TEXT_DISABLED' => $TEXT['DISABLED'],
463
				'TEXT_SAVE' => $TEXT['SAVE'],
464
				'TEXT_RESET' => $TEXT['RESET'],
465
				'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
466
				'HEADING_MODIFY_PAGE' => $HEADING['MODIFY_PAGE']
467
			) );
468

    
469
$template->parse('main', 'main_block', false);
470
$template->pparse('output', 'page');
471

    
472
// Print admin footer
473
$admin->print_footer();
474

    
475
?>
(18-18/20)