Project

General

Profile

1
<?php
2
/**
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: delete.php 1402 2011-01-22 04:41:07Z Luisehahne $
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

    
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

    
28
/*
29
if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
30
{
31
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
32
	exit();
33
}
34
*/
35

    
36
// 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

    
44
// Get perms
45
if (!$admin->get_page_permission($page_id,'admin')) {
46
	$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
47
}
48

    
49
// Find out more about the page
50
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
51
$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

    
59
$results_array = $results->fetchRow();
60

    
61
$visibility = $results_array['visibility'];
62

    
63
// Check if we should delete it or just set the visibility to 'deleted'
64
if(PAGE_TRASH != 'disabled' AND $visibility != 'deleted') {
65
	// Page trash is enabled and page has not yet been deleted
66
	// Function to change all child pages visibility to deleted
67
	function trash_subs($parent = 0) {
68
		global $database;
69
		// 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
} 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

    
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
?>
(2-2/21)