1
|
<?php
|
2
|
|
3
|
// $Id: restore.php 546 2008-01-17 18:10:50Z doc $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, 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
|
$results = $database->query("SELECT admin_groups,admin_users FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
44
|
$results_array = $results->fetchRow();
|
45
|
|
46
|
// Find out more about the page
|
47
|
$query = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
48
|
$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
|
$results_array = $results->fetchRow();
|
56
|
$old_admin_groups = explode(',', str_replace('_', '', $results_array['admin_groups']));
|
57
|
$old_admin_users = explode(',', str_replace('_', '', $results_array['admin_users']));
|
58
|
|
59
|
$in_old_group = FALSE;
|
60
|
foreach($admin->get_groups_id() as $cur_gid){
|
61
|
if (in_array($cur_gid, $old_admin_groups)) {
|
62
|
$in_old_group = TRUE;
|
63
|
}
|
64
|
}
|
65
|
if((!$in_old_group) AND !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
|
66
|
$admin->print_error($MESSAGE['PAGES']['INSUFFICIENT_PERMISSIONS']);
|
67
|
}
|
68
|
|
69
|
$visibility = $results_array['visibility'];
|
70
|
|
71
|
if(PAGE_TRASH) {
|
72
|
if($visibility == 'deleted') {
|
73
|
// Function to change all child pages visibility to deleted
|
74
|
function restore_subs($parent = 0) {
|
75
|
global $database;
|
76
|
// Query pages
|
77
|
$query_menu = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' ORDER BY position ASC");
|
78
|
// Check if there are any pages to show
|
79
|
if($query_menu->numRows() > 0) {
|
80
|
// Loop through pages
|
81
|
while($page = $query_menu->fetchRow()) {
|
82
|
// Update the page visibility to 'deleted'
|
83
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'public' WHERE page_id = '".$page['page_id']."' LIMIT 1");
|
84
|
// Run this function again for all sub-pages
|
85
|
restore_subs($page['page_id']);
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
|
90
|
// Update the page visibility to 'deleted'
|
91
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET visibility = 'public' WHERE page_id = '$page_id.' LIMIT 1");
|
92
|
|
93
|
// Run trash subs for this page
|
94
|
restore_subs($page_id);
|
95
|
|
96
|
}
|
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']['RESTORED']);
|
104
|
}
|
105
|
|
106
|
// Print admin footer
|
107
|
$admin->print_footer();
|
108
|
|
109
|
?>
|