1
|
<?php
|
2
|
|
3
|
// $Id: uninstall.php 286 2006-01-23 21:15:10Z stefan $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2005, 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
|
// Check if user selected template
|
27
|
if(!isset($_POST['file']) OR $_POST['file'] == "") {
|
28
|
header("Location: index.php");
|
29
|
exit(0);
|
30
|
} else {
|
31
|
$file = $_POST['file'];
|
32
|
}
|
33
|
|
34
|
// Extra protection
|
35
|
if(trim($file) == '') {
|
36
|
header("Location: index.php");
|
37
|
exit(0);
|
38
|
}
|
39
|
|
40
|
// Setup admin object
|
41
|
require('../../config.php');
|
42
|
require_once(WB_PATH.'/framework/class.admin.php');
|
43
|
$admin = new admin('Addons', 'templates_uninstall');
|
44
|
|
45
|
// Include the WB functions file
|
46
|
require_once(WB_PATH.'/framework/functions.php');
|
47
|
|
48
|
// Check if the template exists
|
49
|
if(!is_dir(WB_PATH.'/templates/'.$file)) {
|
50
|
$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
|
51
|
}
|
52
|
|
53
|
// Check if the template is in use
|
54
|
if($_POST['file'] == DEFAULT_TEMPLATE) {
|
55
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']);
|
56
|
} else {
|
57
|
$query_templates = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE template = '".$admin->add_slashes($_POST['file'])."' LIMIT 1");
|
58
|
if($query_templates->numRows() > 0) {
|
59
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
// Check if we have permissions on the directory
|
64
|
if(!is_writable(WB_PATH.'/templates/'.$file)) {
|
65
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL'].WB_PATH.'/templates/'.$file);
|
66
|
}
|
67
|
|
68
|
// Try to delete the template dir
|
69
|
if(!rm_full_dir(WB_PATH.'/templates/'.$file)) {
|
70
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
71
|
} else {
|
72
|
// Remove entry from DB
|
73
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'template'");
|
74
|
}
|
75
|
|
76
|
// Update pages that use this template with default template
|
77
|
$database = new database();
|
78
|
$database->query("UPDATE ".TABLE_PREFIX."pages SET template = '".DEFAULT_TEMPLATE."' WHERE template = '$file'");
|
79
|
|
80
|
// Print success message
|
81
|
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
|
82
|
|
83
|
// Print admin footer
|
84
|
$admin->print_footer();
|
85
|
|
86
|
?>
|