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
echo "hier: ".get_magic_quotes_gpc();
28
// Include the WB functions file
29
require_once(WB_PATH.'/framework/functions.php');
30

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

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

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

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

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

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

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

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

    
325
// Insert values into the add page form
326

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

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

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

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

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

    
539

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

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

    
547
?>
(4-4/20)