Project

General

Profile

1
<?php
2

    
3
// $Id: settings.php 944 2009-02-22 09:39:58Z 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
$template->set_var(array(
88
								'PAGE_ID' => $results_array['page_id'],
89
								'PAGE_TITLE' => ($results_array['page_title']),
90
								'MENU_TITLE' => ($results_array['menu_title']),
91
								'DESCRIPTION' => ($results_array['description']),
92
								'KEYWORDS' => ($results_array['keywords']),
93
								'MODIFIED_BY' => $user['display_name'],
94
								'MODIFIED_BY_USERNAME' => $user['username'],
95
								'MODIFIED_WHEN' => $modified_ts,
96
								'ADMIN_URL' => ADMIN_URL
97
								)
98
						);
99

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

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

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

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

    
197
	$query = "SELECT * FROM ".TABLE_PREFIX."groups";
198

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

    
215

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

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

    
253
// Parent page list
254
$database = new database();
255
function parent_list($parent) {
256
	global $admin, $database, $template, $results_array;
257
	$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC";
258
	$get_pages = $database->query($query);
259
	while($page = $get_pages->fetchRow()) {
260
		if($admin->page_is_visible($page)==false)
261
			continue;
262
		// If the current page cannot be parent, then its children neither
263
		$list_next_level = true;
264
		// Stop users from adding pages with a level of more than the set page level limit
265
		if($page['level']+1 < PAGE_LEVEL_LIMIT) {
266
			// Get user perms
267
			$admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
268
			$admin_users = explode(',', str_replace('_', '', $page['admin_users']));
269

    
270
			$in_group = FALSE;
271
			foreach($admin->get_groups_id() as $cur_gid){
272
			    if (in_array($cur_gid, $admin_groups)) {
273
			        $in_group = TRUE;
274
			    }
275
			}
276
			
277
			if(($in_group) OR is_numeric(array_search($admin->get_user_id(), $admin_users))) {
278
				$can_modify = true;
279
			} else {
280
				$can_modify = false;
281
			}
282
			// Title -'s prefix
283
			$title_prefix = '';
284
			for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - '; }
285
			$template->set_var(array(
286
											'ID' => $page['page_id'],
287
											'TITLE' => ($title_prefix.$page['page_title'])
288
											)
289
									);
290
			if($results_array['parent'] == $page['page_id']) {
291
				$template->set_var('SELECTED', ' selected');
292
			} elseif($results_array['page_id'] == $page['page_id']) {
293
				$template->set_var('SELECTED', ' disabled="disabled" class="disabled"');
294
				$list_next_level=false;
295
			} elseif($can_modify != true) {
296
				$template->set_var('SELECTED', ' disabled="disabled" class="disabled"');
297
			} else {
298
				$template->set_var('SELECTED', '');
299
			}
300
			$template->parse('page_list2', 'page_list_block2', true);
301
		}
302
		if ($list_next_level)
303
			parent_list($page['page_id']);
304
	}
305
}
306
$template->set_block('main_block', 'page_list_block2', 'page_list2');
307
if($admin->get_permission('pages_add_l0') == true OR $results_array['level'] == 0) {
308
	if($results_array['parent'] == 0) { $selected = ' selected'; } else { $selected = ''; }
309
	$template->set_var(array(
310
									'ID' => '0',
311
									'TITLE' => $TEXT['NONE'],
312
									'SELECTED' => $selected
313
									)
314
							);
315
	$template->parse('page_list2', 'page_list_block2', true);
316
}
317
parent_list(0);
318

    
319
if($modified_ts == 'Unknown') {
320
	$template->set_var('DISPLAY_MODIFIED', 'hide');
321
} else {
322
	$template->set_var('DISPLAY_MODIFIED', '');
323
}
324
// Templates list
325
$template->set_block('main_block', 'template_list_block', 'template_list');
326
$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'template' order by name");
327
if($result->numRows() > 0) {
328
	while($addon = $result->fetchRow()) { 
329
		// Check if the user has perms to use this template
330
		if($addon['directory'] == $results_array['template'] OR $admin->get_permission($addon['directory'], 'template') == true) {
331
			$template->set_var('VALUE', $addon['directory']);
332
			$template->set_var('NAME', $addon['name']);
333
			if($addon['directory'] == $results_array['template']) {
334
				$template->set_var('SELECTED', ' selected');
335
			} else {
336
				$template->set_var('SELECTED', '');
337
			}
338
			$template->parse('template_list', 'template_list_block', true);
339
		}
340
	}
341
}
342

    
343
// Menu list
344
if(MULTIPLE_MENUS == false) {
345
	$template->set_var('DISPLAY_MENU_LIST', 'none');
346
}
347
// Include template info file (if it exists)
348
if($results_array['template'] != '') {
349
	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
350
} else {
351
	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
352
}
353
if(file_exists($template_location)) {
354
	require($template_location);
355
}
356
// Check if $menu is set
357
if(!isset($menu[1]) OR $menu[1] == '') {
358
	// Make our own menu list
359
	$menu[1] = $TEXT['MAIN'];
360
}
361
// Add menu options to the list
362
$template->set_block('main_block', 'menu_list_block', 'menu_list');
363
foreach($menu AS $number => $name) {
364
	$template->set_var('NAME', $name);
365
	$template->set_var('VALUE', $number);
366
	if($results_array['menu'] == $number) {
367
		$template->set_var('SELECTED', 'selected');
368
	} else {
369
		$template->set_var('SELECTED', '');
370
	}
371
	$template->parse('menu_list', 'menu_list_block', true);
372
}
373

    
374
// Insert language values
375
$template->set_block('main_block', 'language_list_block', 'language_list');
376
$result = $database->query("SELECT * FROM ".TABLE_PREFIX."addons WHERE type = 'language' order by name");
377
if($result->numRows() > 0) {
378
	while($addon = $result->fetchRow()) {
379
		$l_codes[$addon['name']] = $addon['directory'];
380
		$l_names[$addon['name']] = entities_to_7bit($addon['name']); // sorting-problem workaround
381
	}
382
	asort($l_names);
383
	foreach($l_names as $l_name=>$v) {
384
		// Insert code and name
385
		$template->set_var(array(
386
								'VALUE' => $l_codes[$l_name],
387
								'NAME' => $l_name
388
								));
389
		// Check if it is selected
390
		if($results_array['language'] == $l_codes[$l_name]) {
391
			$template->set_var('SELECTED', ' selected');
392
		} else {
393
			$template->set_var('SELECTED', '');
394
		}
395
		$template->parse('language_list', 'language_list_block', true);
396
	}
397
}
398

    
399
// Select disabled if searching is disabled
400
if($results_array['searching'] == 0) {
401
	$template->set_var('SEARCHING_DISABLED', ' selected');
402
}
403
// Select what the page target is
404
switch ($results_array['target']) {
405
	case '_top':
406
		$template->set_var('TOP_SELECTED', ' selected');
407
		break;
408
	case '_self':
409
		$template->set_var('SELF_SELECTED', ' selected');
410
		break;
411
	case '_blank':
412
		$template->set_var('BLANK_SELECTED', ' selected');
413
		break;
414
}
415
	
416

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

    
457
$template->parse('main', 'main_block', false);
458
$template->pparse('output', 'page');
459

    
460
// Print admin footer
461
$admin->print_footer();
462

    
463
?>
(14-14/16)