Project

General

Profile

1
<?php
2

    
3
// $Id: delete.php 915 2009-01-21 19:27:01Z Ruebenwurzel $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, 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
	exit(0);
30
} 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
if (!$admin->get_page_permission($page_id,'admin')) {
44
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
45
}
46

    
47
// Find out more about the page
48
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
49
$results = $database->query($query);
50
if($database->is_error()) {
51
	$admin->print_error($database->get_error());
52
}
53
if($results->numRows() == 0) {
54
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
55
}
56

    
57
$results_array = $results->fetchRow();
58

    
59
$visibility = $results_array['visibility'];
60

    
61
// Check if we should delete it or just set the visibility to 'deleted'
62
if(PAGE_TRASH != 'disabled' AND $visibility != 'deleted') {
63
	// Page trash is enabled and page has not yet been deleted
64
	// Function to change all child pages visibility to deleted
65
	function trash_subs($parent = 0) {
66
		global $database;
67
		// Query pages
68
		$query_menu = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC");
69
		// Check if there are any pages to show
70
		if($query_menu->numRows() > 0) {
71
			// Loop through pages
72
			while($page = $query_menu->fetchRow()) {
73
				// Update the page visibility to 'deleted'
74
				$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '".$page['page_id']."' LIMIT 1");
75
				// Run this function again for all sub-pages
76
				trash_subs($page['page_id']);
77
			}
78
		}
79
	}
80
	
81
	// Update the page visibility to 'deleted'
82
	$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '$page_id.' LIMIT 1");
83
	
84
	// Run trash subs for this page
85
	trash_subs($page_id);
86
} else {
87
	// Really dump the page
88
	// Delete page subs
89
	$sub_pages = get_subs($page_id, array());
90
	foreach($sub_pages AS $sub_page_id) {
91
		delete_page($sub_page_id);
92
	}
93
	// Delete page
94
	delete_page($page_id);
95
}	
96

    
97
// Check if there is a db error, otherwise say successful
98
if($database->is_error()) {
99
	$admin->print_error($database->get_error());
100
} else {
101
	$admin->print_success($MESSAGE['PAGES']['DELETED']);
102
}
103

    
104
// Print admin footer
105
$admin->print_footer();
106

    
107
?>
(2-2/21)