Project

General

Profile

1
<?php
2

    
3
/*
4

    
5
 Website Baker Project <http://www.websitebaker.org/>
6
 Copyright (C) 2004-2005, Ryan Djurovich
7

    
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
require('../../config.php');
25
require_once(WB_PATH.'/framework/class.admin.php');
26
$admin = new admin('Pages', 'pages');
27
// Include the WB functions file
28
require_once(WB_PATH.'/framework/functions.php');
29

    
30
?>
31
<script type="text/javascript" language="javascript">
32
function toggle_viewers() {
33
	if(document.add.visibility.value == 'private') {
34
		document.getElementById('private_viewers').style.display = 'block';
35
		document.getElementById('registered_viewers').style.display = 'none';
36
	} else if(document.add.visibility.value == 'registered') {
37
		document.getElementById('private_viewers').style.display = 'none';
38
		document.getElementById('registered_viewers').style.display = 'block';
39
	} else {
40
		document.getElementById('private_viewers').style.display = 'none';
41
		document.getElementById('registered_viewers').style.display = 'none';
42
	}
43
}
44
function toggle_visibility(id){
45
	if(document.getElementById(id).style.display == "block") {
46
		document.getElementById(id).style.display = "none";
47
	} else {
48
		document.getElementById(id).style.display = "block";
49
	}
50
}
51
var plus = new Image;
52
plus.src = "<?php echo ADMIN_URL; ?>/images/plus_16.png";
53
var minus = new Image;
54
minus.src = "<?php echo ADMIN_URL; ?>/images/minus_16.png";
55
function toggle_plus_minus(id) {
56
	var img_src = document.images['plus_minus_' + id].src;
57
	if(img_src == plus.src) {
58
		document.images['plus_minus_' + id].src = minus.src;
59
	} else {
60
		document.images['plus_minus_' + id].src = plus.src;
61
	}
62
}
63
</script>
64

    
65
<style type="text/css">
66
.pages_list img {
67
	display: block;
68
}
69
ul, li {
70
	list-style: none;
71
	margin: 0;
72
	padding: 0;
73
}
74
.page_list {
75
	display: none;
76
}
77
</style>
78

    
79
<noscript>
80
	<style type="text/css">
81
	.page_list {
82
		display: block;
83
	}
84
	</style>
85
</noscript>
86
<?php
87

    
88
function make_list($parent, $editable_pages) {
89
	// Get objects and vars from outside this function
90
	global $admin, $template, $database, $TEXT, $MESSAGE;
91
	?>
92
	<ul id="p<?php echo $parent; ?>" <?php if($parent != 0) { echo 'class="page_list"'; } ?>>
93
	<?php	
94
	// Get page list from database
95
	$database = new database();
96
	if(PAGE_TRASH != 'inline') {
97
		$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' AND visibility != 'deleted' ORDER BY position ASC";
98
	} else {
99
		$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC";
100
	}
101
	$get_pages = $database->query($query);
102
	
103
	// Insert values into main page list
104
	if($get_pages->numRows() > 0)	{
105
		while($page = $get_pages->fetchRow()) {
106
			// Get user perms
107
			$admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
108
			$admin_users = explode(',', str_replace('_', '', $page['admin_users']));
109
			if(is_numeric(array_search($admin->get_group_id(), $admin_groups)) OR is_numeric(array_search($admin->get_user_id(), $admin_users))) {
110
				if($page['visibility'] == 'deleted') {
111
					if(PAGE_TRASH == 'inline') {
112
						$can_modify = true;
113
						$editable_pages = $editable_pages+1;
114
					} else {
115
						$can_modify = false;
116
					}
117
				} elseif($page['visibility'] != 'deleted') {
118
					$can_modify = true;
119
					$editable_pages = $editable_pages+1;
120
				}
121
			} else {
122
				$can_modify = false;
123
			}
124
						
125
			// Work out if we should show a plus or not
126
			$get_page_subs = $database->query("SELECT page_id,admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE parent = '".$page['page_id']."'");
127
			if($get_page_subs->numRows() > 0) {
128
				$display_plus = true;
129
			} else {
130
				$display_plus = false;
131
			}
132
			
133
			// Work out how many pages there are for this parent
134
			$num_pages = $get_pages->numRows();
135
			?>
136
			
137
			<li id="p<?php echo $page['parent']; ?>" style="padding: 2px 0px 2px 0px;">
138
			<table width="720" cellpadding="1" cellspacing="0" border="0" style="background-color: #F0F0F0;">
139
			<tr>
140
				<td width="20" style="padding-left: <?php echo $page['level']*20; ?>px;">
141
					<?php
142
					if($display_plus == true) {
143
					?>
144
					<a href="javascript: toggle_visibility('p<?php echo $page['page_id']; ?>');" title="<?php echo $TEXT['EXPAND'].'/'.$TEXT['COLLAPSE']; ?>">
145
						<img src="<?php echo ADMIN_URL; ?>/images/plus_16.png" onclick="toggle_plus_minus('<?php echo $page['page_id']; ?>');" name="plus_minus_<?php echo $page['page_id']; ?>" border="0" alt="+" />
146
					</a>
147
					<?php
148
					}
149
					?>
150
				</td>
151
				<?php if($admin->get_permission('pages_modify') == true AND $can_modify == true) { ?>
152
				<td>
153
					<a href="<?php echo ADMIN_URL; ?>/pages/modify.php?page_id=<?php echo $page['page_id']; ?>" title="<?php echo $TEXT['MODIFY']; ?>"><?php echo $admin->strip_slashes_dummy($page['page_title']); ?></a>
154
				</td>
155
				<?php } else { ?>
156
				<td>
157
					<?php	echo $admin->strip_slashes_dummy($page['page_title']); ?>
158
				</td>
159
				<?php } ?>
160
				<td align="left" width="232">
161
					<font color="#999999"><?php echo $admin->strip_slashes_dummy($page['menu_title']); ?></font>
162
				</td>
163
				<td align="center" valign="middle" width="90">
164
				<?php if($page['visibility'] == 'public') { ?>
165
					<img src="<?php echo ADMIN_URL; ?>/images/visible_16.png" alt="<?php echo $TEXT['VISIBILITY']; ?>: <?php echo $TEXT['PUBLIC']; ?>" border="0" />
166
				<?php } elseif($page['visibility'] == 'private') { ?>
167
					<img src="<?php echo ADMIN_URL; ?>/images/private_16.png" alt="<?php echo $TEXT['VISIBILITY']; ?>: <?php echo $TEXT['PRIVATE']; ?>" border="0" />
168
				<?php } elseif($page['visibility'] == 'registered') { ?>
169
					<img src="<?php echo ADMIN_URL; ?>/images/keys_16.png" alt="<?php echo $TEXT['VISIBILITY']; ?>: <?php echo $TEXT['REGISTERED']; ?>" border="0" />
170
				<?php } elseif($page['visibility'] == 'hidden') { ?>
171
					<img src="<?php echo ADMIN_URL; ?>/images/hidden_16.png" alt="<?php echo $TEXT['VISIBILITY']; ?>: <?php echo $TEXT['HIDDEN']; ?>" border="0" />
172
				<?php } elseif($page['visibility'] == 'none') { ?>
173
					<img src="<?php echo ADMIN_URL; ?>/images/none_16.png" alt="<?php echo $TEXT['VISIBILITY']; ?>: <?php echo $TEXT['NONE']; ?>" border="0" />
174
				<?php } elseif($page['visibility'] == 'deleted') { ?>
175
					<img src="<?php echo ADMIN_URL; ?>/images/deleted_16.png" alt="<?php echo $TEXT['VISIBILITY']; ?>: <?php echo $TEXT['DELETED']; ?>" border="0" />
176
				<?php } ?>
177
				</td>
178
				<td width="20">
179
					<?php if($page['visibility'] != 'deleted') { ?>
180
						<?php if($admin->get_permission('pages_settings') == true AND $can_modify == true) { ?>
181
						<a href="<?php echo ADMIN_URL; ?>/pages/settings.php?page_id=<?php echo $page['page_id']; ?>" title="<?php echo $TEXT['SETTINGS']; ?>">
182
							<img src="<?php echo ADMIN_URL; ?>/images/modify_16.png" border="0" alt="<?php echo $TEXT['SETTINGS']; ?>" />
183
						</a>
184
						<?php } ?>
185
					<?php } else { ?>
186
						<a href="<?php echo ADMIN_URL; ?>/pages/restore.php?page_id=<?php echo $page['page_id']; ?>" title="<?php echo $TEXT['RESTORE']; ?>">
187
							<img src="<?php echo ADMIN_URL; ?>/images/restore_16.png" border="0" alt="<?php echo $TEXT['RESTORE']; ?>" />
188
						</a>
189
					<?php } ?>
190
				</td>
191
				<td width="20">
192
				<?php if($page['position'] != 1) { ?>
193
					<?php if($page['visibility'] != 'deleted') { ?>
194
						<?php if($admin->get_permission('pages_settings') == true AND $can_modify == true) { ?>
195
						<a href="<?php echo ADMIN_URL; ?>/pages/move_up.php?page_id=<?php echo $page['page_id']; ?>" title="<?php echo $TEXT['MOVE_UP']; ?>">
196
							<img src="<?php echo ADMIN_URL; ?>/images/up_16.png" border="0" alt="^" />
197
						</a>
198
						<?php } ?>
199
					<?php } ?>
200
				<?php } ?>
201
				</td>
202
				<td width="20">
203
				<?php if($page['position'] != $num_pages) { ?>
204
					<?php if($page['visibility'] != 'deleted') { ?>
205
						<?php if($admin->get_permission('pages_settings') == true AND $can_modify == true) { ?>
206
						<a href="<?php echo ADMIN_URL; ?>/pages/move_down.php?page_id=<?php echo $page['page_id']; ?>" title="<?php echo $TEXT['MOVE_DOWN']; ?>">
207
							<img src="<?php echo ADMIN_URL; ?>/images/down_16.png" border="0" alt="v" />
208
						</a>
209
						<?php } ?>
210
					<?php } ?>
211
				<?php } ?>
212
				</td>
213
				<td width="20">
214
					<?php if($admin->get_permission('pages_delete') == true AND $can_modify == true) { ?>
215
					<a href="javascript: confirm_link('<?php echo $MESSAGE['PAGES']['DELETE_CONFIRM']; ?>?', '<?php echo ADMIN_URL; ?>/pages/delete.php?page_id=<?php echo $page['page_id']; ?>');" title="<?php echo $TEXT['DELETE']; ?>">
216
						<img src="<?php echo ADMIN_URL; ?>/images/delete_16.png" border="0" alt="X" />
217
					</a>
218
					<?php } ?>
219
				</td>
220
				<td width="20">
221
					<?php if($page['visibility'] != 'deleted' AND $page['visibility'] != 'none') { ?>
222
					<a href="<?php echo page_link($page['link']); ?>" target="_blank">
223
						<img src="<?php echo ADMIN_URL; ?>/images/view_16.png" border="0" alt="<?php echo $TEXT['VIEW']; ?>" />
224
					</a>
225
					<?php } ?>
226
				</td>
227
			</tr>
228
			</table>
229
			</li>
230
							
231
			<?php
232
			// Get subs
233
			$editable_pages=make_list($page['page_id'], $editable_pages);
234
		}
235

    
236
	}
237
	?>
238
	</ul>
239
	<?php
240
	return $editable_pages;
241
}
242

    
243
// Generate pages list
244
if($admin->get_permission('pages_view') == true) {
245
	?>
246
	<table cellpadding="0" cellspacing="0" width="100%" border="0">
247
	<tr>
248
		<td>
249
			<h2><?php echo $HEADING['MODIFY_DELETE_PAGE']; ?></h2>
250
		</td>
251
		<td align="right">
252
			<?php
253
				// Check if there are any pages that are in trash, and if we should show a link to the trash page
254
				if(PAGE_TRASH == 'separate') {
255
					$query_trash = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE visibility = 'deleted'");
256
					if($query_trash->numRows() > 0) {
257
						?>
258
						<a href="<?php echo ADMIN_URL; ?>/pages/trash.php">
259
						<img src="<?php echo ADMIN_URL; ?>/images/delete_16.png" alt="<?php echo $TEXT['PAGE_TRASH']; ?>" border="0" />
260
						<?php echo $TEXT['VIEW_DELETED_PAGES']; ?></a>
261
						<?php
262
					}
263
				}
264
			?>
265
		</td>
266
	</tr>
267
	</table>
268
	<div class="pages_list">
269
	<table cellpadding="1" cellspacing="0" width="720" border="0">
270
	<tr>
271
		<td width="20">
272
			&nbsp;
273
		</td>
274
		<td>
275
			<?php echo $TEXT['PAGE_TITLE']; ?>:
276
		</td>
277
		<td width="175" align="left">
278
			<?php echo $TEXT['MENU_TITLE']; ?>:
279
		</td>
280
		<td width="130" align="right">
281
			<?php echo $TEXT['VISIBILITY']; ?>:
282
		</td>
283
		<td width="125" align="center">
284
			<?php echo $TEXT['ACTIONS']; ?>:
285
		</td>		
286
	</tr>
287
	</table>
288
	<?php
289
	$editable_pages = make_list(0, 0);
290
	?>
291
	</div>
292
	<div class="empty_list">
293
		<?php echo $TEXT['NONE_FOUND']; ?>
294
	</div>
295
	<?php
296
} else {
297
	$editable_pages = 0;
298
}
299

    
300
// Setup template object
301
$template = new Template(ADMIN_PATH.'/pages');
302
$template->set_file('page', 'template.html');
303
$template->set_block('page', 'main_block', 'main');
304

    
305
// Figure out if the no pages found message should be shown or not
306
if($editable_pages == 0) {
307
	?>
308
	<style type="text/css">
309
	.pages_list {
310
		display: none;
311
	}
312
	</style>
313
	<?php
314
} else {
315
	?>
316
	<style type="text/css">
317
	.empty_list {
318
		display: none;
319
	}
320
	</style>
321
	<?php
322
}
323

    
324
// Insert values into the add page form
325

    
326
// Group list 1
327
	if($admin->get_group_id() == 1) {
328
		$query = "SELECT * FROM ".TABLE_PREFIX."groups";
329
	} else {
330
		$query = "SELECT * FROM ".TABLE_PREFIX."groups WHERE group_id != '".$admin->get_group_id()."'";
331
	}
332
	$get_groups = $database->query($query);
333
	$template->set_block('main_block', 'group_list_block', 'group_list');
334
	// Insert admin group and current group first
335
	$admin_group_name = $get_groups->fetchRow();
336
	$template->set_var(array(
337
									'ID' => 1,
338
									'TOGGLE' => '',
339
									'DISABLED' => ' disabled',
340
									'LINK_COLOR' => '000000',
341
									'CURSOR' => 'default',
342
									'NAME' => $admin_group_name['name'],
343
									'CHECKED' => ' checked'
344
									)
345
							);
346
	$template->parse('group_list', 'group_list_block', true);
347
	if($admin->get_group_id() != 1) {
348
		$template->set_var(array(
349
										'ID' => $admin->get_group_id(),
350
										'TOGGLE' => '',
351
										'DISABLED' => ' disabled',
352
										'LINK_COLOR' => '000000',
353
										'CURSOR' => 'default',
354
										'NAME' => $admin->get_group_name(),
355
										'CHECKED' => ' checked'
356
										)
357
								);
358
		$template->parse('group_list', 'group_list_block', true);
359
	}
360
	while($group = $get_groups->fetchRow()) {
361
		// Check if the group is allowed to edit pages
362
		$system_permissions = explode(',', $group['system_permissions']);
363
		if(is_numeric(array_search('pages_modify', $system_permissions))) {
364
			$template->set_var(array(
365
											'ID' => $group['group_id'],
366
											'TOGGLE' => $group['group_id'],
367
											'CHECKED' => '',
368
											'DISABLED' => '',
369
											'LINK_COLOR' => '',
370
											'CURSOR' => 'pointer',
371
											'NAME' => $group['name'],
372
											'CHECKED' => ''
373
											)
374
									);
375
			$template->parse('group_list', 'group_list_block', true);
376
		}
377
	}
378
// Group list 2
379
	if($admin->get_group_id() == 1) {
380
		$query = "SELECT * FROM ".TABLE_PREFIX."groups";
381
	} else {
382
		$query = "SELECT * FROM ".TABLE_PREFIX."groups WHERE group_id != '".$admin->get_group_id()."'";
383
	}
384
	$get_groups = $database->query($query);
385
	$template->set_block('main_block', 'group_list_block2', 'group_list2');
386
	// Insert admin group and current group first
387
	$admin_group_name = $get_groups->fetchRow();
388
	$template->set_var(array(
389
									'ID' => 1,
390
									'TOGGLE' => '',
391
									'DISABLED' => ' disabled',
392
									'LINK_COLOR' => '000000',
393
									'CURSOR' => 'default',
394
									'NAME' => $admin_group_name['name'],
395
									'CHECKED' => ' checked'
396
									)
397
							);
398
	$template->parse('group_list2', 'group_list_block2', true);
399
	if($admin->get_group_id() != 1) {
400
		$template->set_var(array(
401
										'ID' => $admin->get_group_id(),
402
										'TOGGLE' => '',
403
										'DISABLED' => ' disabled',
404
										'LINK_COLOR' => '000000',
405
										'CURSOR' => 'default',
406
										'NAME' => $admin->get_group_name(),
407
										'CHECKED' => ' checked'
408
										)
409
								);
410
		$template->parse('group_list2', 'group_list_block2', true);
411
	}
412
	while($group = $get_groups->fetchRow()) {
413
		$template->set_var(array(
414
										'ID' => $group['group_id'],
415
										'TOGGLE' => $group['group_id'],
416
										'CHECKED' => '',
417
										'DISABLED' => '',
418
										'LINK_COLOR' => '',
419
										'CURSOR' => 'pointer',
420
										'NAME' => $group['name'],
421
										'CHECKED' => ''
422
										)
423
								);
424
		$template->parse('group_list2', 'group_list_block2', true);
425
	}
426

    
427
// Parent page list
428
$database = new database();
429
function parent_list($parent) {
430
	global $admin, $database, $template;
431
	$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC";
432
	$get_pages = $database->query($query);
433
	while($page = $get_pages->fetchRow()) {
434
		// Stop users from adding pages with a level of more than the set page level limit
435
		if($page['level']+1 < PAGE_LEVEL_LIMIT) {
436
			// Get user perms
437
			$admin_groups = explode(',', str_replace('_', '', $page['admin_groups']));
438
			$admin_users = explode(',', str_replace('_', '', $page['admin_users']));
439
			if(is_numeric(array_search($admin->get_group_id(), $admin_groups)) OR is_numeric(array_search($admin->get_user_id(), $admin_users))) {
440
				$can_modify = true;
441
			} else {
442
				$can_modify = false;
443
			}
444
			// Title -'s prefix
445
			$title_prefix = '';
446
			for($i = 1; $i <= $page['level']; $i++) { $title_prefix .= ' - '; }
447
				$template->set_var(array(
448
												'ID' => $page['page_id'],
449
												'TITLE' => $admin->strip_slashes_dummy($title_prefix.$page['page_title'])
450
												)
451
										);
452
				if($can_modify == true) {
453
					$template->set_var('DISABLED', '');
454
				} else {
455
					$template->set_var('DISABLED', ' disabled');
456
				}
457
				$template->parse('page_list2', 'page_list_block2', true);
458
		}
459
		parent_list($page['page_id']);
460
	}
461
}
462
$template->set_block('main_block', 'page_list_block2', 'page_list2');
463
if($admin->get_permission('pages_add_l0') == true) {
464
	$template->set_var(array(
465
									'ID' => '0',
466
									'TITLE' => $TEXT['NONE'],
467
									'SELECTED' => ' selected',
468
									'DISABLED' => ''
469
									)
470
							);
471
	$template->parse('page_list2', 'page_list_block2', true);
472
}
473
parent_list(0);
474

    
475
// Explode module permissions
476
$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
477
// Modules list
478
$template->set_block('main_block', 'module_list_block', 'module_list');
479
if($handle = opendir(WB_PATH.'/modules/')) {
480
	while (false !== ($file = readdir($handle))) {
481
		if($file != '.' AND $file != '..' AND $file != '.svn' AND is_dir(WB_PATH."/modules/$file") AND file_exists(WB_PATH."/modules/$file/info.php")) {
482
			// Include the modules info file
483
			require(WB_PATH.'/modules/'.$file.'/info.php');
484
			// Check if user is allowed to use this module
485
			if(!isset($module_type)) { $module_type = 'unknown'; }
486
			if(!is_numeric(array_search($file, $module_permissions)) AND $module_type == 'page') {
487
				$template->set_var('VALUE', $file);
488
				$template->set_var('NAME', $module_name);
489
				if($file == 'wysiwyg') {
490
					$template->set_var('SELECTED', ' selected');
491
				} else {
492
					$template->set_var('SELECTED', '');
493
				}
494
				$template->parse('module_list', 'module_list_block', true);
495
			}
496
			if(isset($module_type)) { unset($module_type); } // Unset module type
497
		}
498
	}
499
}
500

    
501
// Insert language headings
502
$template->set_var(array(
503
								'HEADING_ADD_PAGE' => $HEADING['ADD_PAGE'],
504
								'HEADING_MODIFY_INTRO_PAGE' => $HEADING['MODIFY_INTRO_PAGE']
505
								)
506
						);
507
// Insert language text and messages
508
$template->set_var(array(
509
								'TEXT_TITLE' => $TEXT['TITLE'],
510
								'TEXT_TYPE' => $TEXT['TYPE'],
511
								'TEXT_PARENT' => $TEXT['PARENT'],
512
								'TEXT_VISIBILITY' => $TEXT['VISIBILITY'],
513
								'TEXT_PUBLIC' => $TEXT['PUBLIC'],
514
								'TEXT_PRIVATE' => $TEXT['PRIVATE'],
515
								'TEXT_REGISTERED' => $TEXT['REGISTERED'],
516
								'TEXT_HIDDEN' => $TEXT['HIDDEN'],
517
								'TEXT_NONE' => $TEXT['NONE'],
518
								'TEXT_NONE_FOUND' => $TEXT['NONE_FOUND'],
519
								'TEXT_ADD' => $TEXT['ADD'],
520
								'TEXT_RESET' => $TEXT['RESET'],
521
								'TEXT_ADMINISTRATORS' => $TEXT['ADMINISTRATORS'],								
522
								'TEXT_PRIVATE_VIEWERS' => $TEXT['PRIVATE_VIEWERS'],
523
								'TEXT_REGISTERED_VIEWERS' => $TEXT['REGISTERED_VIEWERS'],
524
								'INTRO_LINK' => $MESSAGE['PAGES']['INTRO_LINK'],
525
								)
526
						);
527

    
528
// Insert permissions values
529
if($admin->get_permission('pages_add') != true) {
530
	$template->set_var('DISPLAY_ADD', 'hide');
531
} elseif($admin->get_permission('pages_add_l0') != true AND $editable_pages == 0) {
532
	$template->set_var('DISPLAY_ADD', 'hide');
533
}
534
if($admin->get_permission('pages_intro') != true OR INTRO_PAGE != 'enabled') {
535
	$template->set_var('DISPLAY_INTRO', 'hide');
536
}
537

    
538

    
539
// Parse template object
540
$template->parse('main', 'main_block', false);
541
$template->pparse('output', 'page');
542

    
543
// Print admin 
544
$admin->print_footer();
545

    
546
?>
(4-4/20)