Project

General

Profile

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