Project

General

Profile

1
<?php
2

    
3
// $Id: settings.php 651 2008-01-31 17:10:32Z thorn $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, 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
// Get perms
40
$database = new database();
41
$results = $database->query("SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
42
$results_array = $results->fetchRow();
43
$old_admin_groups = explode(',', $results_array['admin_groups']);
44
$old_admin_users = explode(',', $results_array['admin_users']);
45

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

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

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

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

    
80
// Setup template object, parse vars to it, then parse it
81
$template = new Template(ADMIN_PATH.'/pages');
82
$template->set_file('page', 'settings.html');
83
$template->set_block('page', 'main_block', 'main');
84
$template->set_var(array(
85
								'PAGE_ID' => $results_array['page_id'],
86
								'PAGE_TITLE' => ($results_array['page_title']),
87
								'MENU_TITLE' => ($results_array['menu_title']),
88
								'DESCRIPTION' => ($results_array['description']),
89
								'KEYWORDS' => ($results_array['keywords']),
90
								'MODIFIED_BY' => $user['display_name'],
91
								'MODIFIED_BY_USERNAME' => $user['username'],
92
								'MODIFIED_WHEN' => $modified_ts,
93
								'ADMIN_URL' => ADMIN_URL
94
								)
95
						);
96

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

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

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

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

    
194
	$query = "SELECT * FROM ".TABLE_PREFIX."groups";
195

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

    
212

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

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

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

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

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

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

    
371
// Language list
372
if($handle = opendir(WB_PATH.'/languages/')) {
373
	$template->set_block('main_block', 'language_list_block', 'language_list');
374
	while (false !== ($file = readdir($handle))) {
375
		if($file != '.' AND $file != '..' AND $file != '.svn' AND $file != 'index.php') {
376
			// Include the languages info file
377
			require(WB_PATH.'/languages/'.$file);
378
			// Work-out if this language is selected
379
			if($language_code == $results_array['language']) { $selected = ' selected'; } else { $selected = ''; }
380
			// Set the language info
381
			$template->set_var(array('VALUE' => $language_code, 'SELECTED' => $selected, 'NAME' => $language_name));
382
			// Parse row
383
			$template->parse('language_list', 'language_list_block', true);
384
		}
385
	}
386
}
387
// Restore to original language
388
require(WB_PATH.'/languages/'.LANGUAGE.'.php');
389

    
390
// Select disabled if searching is disabled
391
if($results_array['searching'] == 0) {
392
	$template->set_var('SEARCHING_DISABLED', ' selected');
393
}
394
// Select what the page target is
395
switch ($results_array['target']) {
396
	case '_top':
397
		$template->set_var('TOP_SELECTED', ' selected');
398
		break;
399
	case '_self':
400
		$template->set_var('SELF_SELECTED', ' selected');
401
		break;
402
	case '_blank':
403
		$template->set_var('BLANK_SELECTED', ' selected');
404
		break;
405
}
406
	
407

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

    
448
$template->parse('main', 'main_block', false);
449
$template->pparse('output', 'page');
450

    
451
// Print admin footer
452
$admin->print_footer();
453

    
454
?>
(16-16/19)