Project

General

Profile

1
<?php
2

    
3
// $Id: settings.php 1112 2009-08-08 14:28:54Z 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

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

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

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

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

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

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

    
219

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

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

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

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

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

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

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

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

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

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

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

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

    
476
?>
(19-19/21)