Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         pages
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id: delete.php 2 2017-07-02 15:14:29Z Manuela $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/pages/delete.php $
15
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
16
 *
17
 */
18

    
19

    
20
// Create new admin object and print admin header
21
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
22
if ( !class_exists('admin', false) ) { require(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'], ADMIN_URL );
32
    exit();
33
}
34

    
35
// Get perms
36
if (!$admin->get_page_permission($page_id,'admin')) {
37
    $admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
38
}
39

    
40
// Find out more about the page
41
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
42
$results = $database->query($query);
43
if($database->is_error()) {
44
    $admin->print_error($database->get_error());
45
}
46
if($results->numRows() == 0) {
47
    $admin->print_error($MESSAGE['PAGES_NOT_FOUND']);
48
}
49

    
50
$results_array = $results->fetchRow();
51

    
52
$visibility = $results_array['visibility'];
53

    
54
// Check if we should delete it or just set the visibility to 'deleted'
55
if(PAGE_TRASH != 'disabled' AND $visibility != 'deleted') {
56
    // Page trash is enabled and page has not yet been deleted
57
    // Function to change all child pages visibility to deleted
58
    function trash_subs($parent = 0) {
59
        global $database;
60
        // Query pages
61

    
62
        $sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` '
63
              .'WHERE `parent` = '.$parent.' '
64
              .'ORDER BY `position` ASC';
65
        if($oRes = $database->query($sql)) {
66
            // Check if there are any pages to show
67
            if($oRes->numRows() > 0) {
68
                // Loop through pages
69
                while($page = $oRes->fetchRow(MYSQLI_ASSOC)) {
70
                    // Update the page visibility to 'deleted'
71
                    $sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET '
72
                          .'`visibility` = \'deleted\' '
73
                          .'WHERE `page_id` = '.$page['page_id'].' '
74
                          .'';
75
                    $database->query($sql);
76

    
77
                    if($database->is_error()) {
78
                        $admin->print_error($database->get_error());
79
                    }
80
                    // Run this function again for all sub-pages
81
                    trash_subs($page['page_id']);
82
                }
83
            }
84
        }
85
    }
86
    // Update the page visibility to 'deleted'
87
    $sql = 'UPDATE `'.TABLE_PREFIX.'pages` SET '
88
                      .'`visibility` = \'deleted\' '
89
                      .'WHERE `page_id` = '.$page_id.' '
90
                      .'';
91
                $database->query($sql);
92

    
93
                if($database->is_error()) {
94
                    $admin->print_error($database->get_error());
95
                }
96
    //
97
    // Run trash subs for this page
98
    trash_subs($page_id);
99
} else {
100
    // Really dump the page
101
    // Delete page subs
102
    $sub_pages = get_subs($page_id, array());
103
    foreach($sub_pages AS $sub_page_id) {
104
        delete_page($sub_page_id);
105
    }
106
    // Delete page
107
    delete_page($page_id);
108
}
109

    
110
// Check if there is a db error, otherwise say successful
111
if($database->is_error()) {
112
    $admin->print_error($database->get_error());
113
} else {
114
    $admin->print_success($MESSAGE['PAGES_DELETED']);
115
}
116

    
117
// Print admin footer
118
$admin->print_footer();
(2-2/25)