Project

General

Profile

1
<?php
2

    
3
// $Id: delete.php 10 2005-09-04 08:59:31Z ryan $
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
// Get page id
27
if(!isset($_GET['page_id']) OR !is_numeric($_GET['page_id'])) {
28
	header("Location: index.php");
29
} else {
30
	$page_id = $_GET['page_id'];
31
}
32

    
33
// Create new admin object and print admin header
34
require('../../config.php');
35
require_once(WB_PATH.'/framework/class.admin.php');
36
$admin = new admin('Pages', 'pages_delete');
37

    
38
// Include the WB functions file
39
require_once(WB_PATH.'/framework/functions.php');
40

    
41
// Get perms
42
$database = new database();
43
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
44
$results_array = $results->fetchRow();
45
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
46
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
47
if(!is_numeric(array_search($admin->get_group_id(), $old_admin_groups)) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
48
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
49
}
50

    
51
// Find out more about the page
52
$database = new database();
53
$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when,visibility FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
54
$results = $database->query($query);
55
if($database->is_error()) {
56
	$admin->print_error($database->get_error());
57
}
58
if($results->numRows() == 0) {
59
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
60
}
61
$results_array = $results->fetchRow();
62
$parent = $results_array['parent'];
63
$level = $results_array['level'];
64
$link = $results_array['link'];
65
$visibility = $results_array['visibility'];
66
$page_title = stripslashes($results_array['page_title']);
67
$menu_title = stripslashes($results_array['menu_title']);
68

    
69
// Check if we should delete it or just set the visibility to 'deleted'
70
if(PAGE_TRASH != 'disabled') {
71
	if($visibility == 'deleted') {
72
		$delete_method = 'actual';
73
	} else {
74
		$delete_method = 'visibility';
75
	}
76
} else {
77
	$delete_method = 'actual';
78
}
79

    
80
if($delete_method == 'actual') {
81
	
82
	// Delete page subs
83
	$sub_pages = get_subs($page_id, array());
84
	foreach($sub_pages AS $sub_page_id) {
85
		delete_page($sub_page_id);
86
	}
87
	// Delete page
88
	delete_page($page_id);
89
	
90
} else {
91
	
92
	// Function to change all child pages visibility to deleted
93
	function trash_subs($parent = 0) {
94
		global $database, $admin, $page_id, $page_trail, $private_sql, $private_where_sql;
95
		// Query pages
96
		$query_menu = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC");
97
		// Check if there are any pages to show
98
		if($query_menu->numRows() > 0) {
99
			// Loop through pages
100
			while($page = $query_menu->fetchRow()) {
101
				// Update the page visibility to 'deleted'
102
				$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '".$page['page_id']."' LIMIT 1");
103
				// Run this function again for all sub-pages
104
				trash_subs($page['page_id']);
105
			}
106
		}
107
	}
108
	
109
	// Update the page visibility to 'deleted'
110
	$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '$page_id.' LIMIT 1");
111
	
112
	// Run trash subs for this page
113
	trash_subs($page_id);
114
	
115
}
116

    
117
// Check if there is a db error, otherwise say successful
118
if($database->is_error()) {
119
	$admin->print_error($database->get_error());
120
} else {
121
	$admin->print_success($MESSAGE['PAGES']['DELETED']);
122
}
123

    
124
// Print admin footer
125
$admin->print_footer();
126

    
127
?>
(2-2/20)