Project

General

Profile

1 4 ryan
<?php
2
3 35 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8 915 Ruebenwurz
 Copyright (C) 2004-2009, Ryan Djurovich
9 4 ryan
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 286 stefan
	exit(0);
30 4 ryan
} else {
31
	$page_id = $_GET['page_id'];
32
}
33
34
// Create new admin object and print admin header
35
require('../../config.php');
36
require_once(WB_PATH.'/framework/class.admin.php');
37
$admin = new admin('Pages', 'pages_delete');
38
39
// Include the WB functions file
40
require_once(WB_PATH.'/framework/functions.php');
41
42
// Get perms
43 319 stefan
if (!$admin->get_page_permission($page_id,'admin')) {
44
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
45
}
46 4 ryan
47 1357 FrankH
if (!$admin->checkFTAN('get'))
48
{
49
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
50
	exit();
51
}
52
53 4 ryan
// Find out more about the page
54 35 stefan
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
55 4 ryan
$results = $database->query($query);
56
if($database->is_error()) {
57
	$admin->print_error($database->get_error());
58
}
59
if($results->numRows() == 0) {
60
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
61
}
62 319 stefan
63 4 ryan
$results_array = $results->fetchRow();
64 35 stefan
65 4 ryan
$visibility = $results_array['visibility'];
66
67
// Check if we should delete it or just set the visibility to 'deleted'
68 35 stefan
if(PAGE_TRASH != 'disabled' AND $visibility != 'deleted') {
69
	// Page trash is enabled and page has not yet been deleted
70 4 ryan
	// Function to change all child pages visibility to deleted
71
	function trash_subs($parent = 0) {
72 35 stefan
		global $database;
73 4 ryan
		// Query pages
74
		$query_menu = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC");
75
		// Check if there are any pages to show
76
		if($query_menu->numRows() > 0) {
77
			// Loop through pages
78
			while($page = $query_menu->fetchRow()) {
79
				// Update the page visibility to 'deleted'
80
				$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '".$page['page_id']."' LIMIT 1");
81
				// Run this function again for all sub-pages
82
				trash_subs($page['page_id']);
83
			}
84
		}
85
	}
86
87
	// Update the page visibility to 'deleted'
88
	$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '$page_id.' LIMIT 1");
89
90
	// Run trash subs for this page
91
	trash_subs($page_id);
92 35 stefan
} else {
93
	// Really dump the page
94
	// Delete page subs
95
	$sub_pages = get_subs($page_id, array());
96
	foreach($sub_pages AS $sub_page_id) {
97
		delete_page($sub_page_id);
98
	}
99
	// Delete page
100
	delete_page($page_id);
101
}
102 4 ryan
103
// Check if there is a db error, otherwise say successful
104
if($database->is_error()) {
105
	$admin->print_error($database->get_error());
106
} else {
107
	$admin->print_success($MESSAGE['PAGES']['DELETED']);
108
}
109
110
// Print admin footer
111
$admin->print_footer();
112
113
?>