Project

General

Profile

1
<?php
2

    
3
// $Id: index.php,v 1.9 2005/04/08 07:36:58 rdjurovich Exp $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, 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
require('../../config.php');
27
require_once(WB_PATH.'/framework/class.admin.php');
28
$admin = new admin('Pages', 'pages');
29

    
30
// Include the WB functions file
31
require_once(WB_PATH.'/framework/functions.php');
32

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

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

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

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

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

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

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

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

    
327
// Insert values into the add page form
328

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

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

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

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

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

    
541

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

    
546
// Print admin 
547
$admin->print_footer();
548

    
549
?>
(4-4/20)