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