Project

General

Profile

1 4 ryan
<?php
2 1384 Luisehahne
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL: http://svn.websitebaker2.org/branches/2.8.x/wb/admin/pages/add.php $
15
 * @lastmodified    $Date: 2011-01-10 13:14:10 +0100 (Mo, 10. Jan 2011) $
16
 *
17
 */
18 4 ryan
19
// Get page id
20 1384 Luisehahne
if(!isset($_GET['page_id']) || !is_numeric($_GET['page_id'])) {
21 4 ryan
	header("Location: index.php");
22 286 stefan
	exit(0);
23 4 ryan
} else {
24
	$page_id = $_GET['page_id'];
25
}
26
27
// Create new admin object and print admin header
28
require('../../config.php');
29
require_once(WB_PATH.'/framework/class.admin.php');
30
$admin = new admin('Pages', 'pages_delete');
31
32
// Include the WB functions file
33
require_once(WB_PATH.'/framework/functions.php');
34 1384 Luisehahne
/*
35
if (!$admin->checkIDKEY('page_id', 0, 'GET'))
36
{
37
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
38
	exit();
39
}
40
*/
41 4 ryan
// Get perms
42 319 stefan
if (!$admin->get_page_permission($page_id,'admin')) {
43
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
44
}
45 4 ryan
46
// Find out more about the page
47 35 stefan
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
48 4 ryan
$results = $database->query($query);
49
if($database->is_error()) {
50
	$admin->print_error($database->get_error());
51
}
52
if($results->numRows() == 0) {
53
	$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
54
}
55 319 stefan
56 4 ryan
$results_array = $results->fetchRow();
57 35 stefan
58 4 ryan
$visibility = $results_array['visibility'];
59
60
// Check if we should delete it or just set the visibility to 'deleted'
61 35 stefan
if(PAGE_TRASH != 'disabled' AND $visibility != 'deleted') {
62
	// Page trash is enabled and page has not yet been deleted
63 4 ryan
	// Function to change all child pages visibility to deleted
64
	function trash_subs($parent = 0) {
65 35 stefan
		global $database;
66 4 ryan
		// Query pages
67
		$query_menu = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC");
68
		// Check if there are any pages to show
69
		if($query_menu->numRows() > 0) {
70
			// Loop through pages
71
			while($page = $query_menu->fetchRow()) {
72
				// Update the page visibility to 'deleted'
73
				$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '".$page['page_id']."' LIMIT 1");
74
				// Run this function again for all sub-pages
75
				trash_subs($page['page_id']);
76
			}
77
		}
78
	}
79
80
	// Update the page visibility to 'deleted'
81
	$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'deleted' WHERE page_id = '$page_id.' LIMIT 1");
82
83
	// Run trash subs for this page
84
	trash_subs($page_id);
85 35 stefan
} else {
86
	// Really dump the page
87
	// Delete page subs
88
	$sub_pages = get_subs($page_id, array());
89
	foreach($sub_pages AS $sub_page_id) {
90
		delete_page($sub_page_id);
91
	}
92
	// Delete page
93
	delete_page($page_id);
94
}
95 4 ryan
96
// Check if there is a db error, otherwise say successful
97
if($database->is_error()) {
98
	$admin->print_error($database->get_error());
99
} else {
100
	$admin->print_success($MESSAGE['PAGES']['DELETED']);
101
}
102
103
// Print admin footer
104
$admin->print_footer();
105
106
?>