1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category admin
|
5
|
* @package modules
|
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: uninstall.php 1386 2011-01-16 09:56:53Z Luisehahne $
|
14
|
* @filesource $HeadURL: http://svn.websitebaker2.org/branches/2.8.x/wb/admin/users/save.php $
|
15
|
* @lastmodified $Date: 2011-01-10 13:21:47 +0100 (Mo, 10. Jan 2011) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
// Setup admin object
|
20
|
require('../../config.php');
|
21
|
require_once(WB_PATH.'/framework/class.admin.php');
|
22
|
$admin = new admin('Addons', 'modules_uninstall');
|
23
|
|
24
|
// Check if user selected module
|
25
|
if(!isset($_POST['file']) OR $_POST['file'] == "") {
|
26
|
header("Location: index.php");
|
27
|
exit(0);
|
28
|
} else {
|
29
|
$file = $admin->add_slashes($_POST['file']);
|
30
|
}
|
31
|
|
32
|
// Extra protection
|
33
|
if(trim($file) == '') {
|
34
|
header("Location: index.php");
|
35
|
exit(0);
|
36
|
}
|
37
|
|
38
|
// Include the WB functions file
|
39
|
require_once(WB_PATH.'/framework/functions.php');
|
40
|
|
41
|
// Check if the module exists
|
42
|
if(!is_dir(WB_PATH.'/modules/'.$file)) {
|
43
|
$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
|
44
|
}
|
45
|
|
46
|
if (!function_exists("replace_all")) {
|
47
|
function replace_all ($aStr = "", &$aArray ) {
|
48
|
foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
|
49
|
return $aStr;
|
50
|
}
|
51
|
}
|
52
|
|
53
|
$info = $database->query("SELECT section_id, page_id FROM ".TABLE_PREFIX."sections WHERE module='".$_POST['file']."'" );
|
54
|
|
55
|
if ( $info->numRows() > 0) {
|
56
|
|
57
|
/**
|
58
|
* Modul is in use, so we have to warn the user
|
59
|
*/
|
60
|
if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
|
61
|
$add = $info->numRows() == 1 ? "this page" : "these pages";
|
62
|
$msg_template_str = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use on {{pages}}";
|
63
|
$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
|
64
|
} else {
|
65
|
$msg_template_str = $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL'];
|
66
|
$temp = explode(";",$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
|
67
|
$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
|
68
|
}
|
69
|
/**
|
70
|
* The template-string for displaying the Page-Titles ... in this case as a link
|
71
|
*/
|
72
|
$page_template_str = "- <b><a href='../pages/sections.php?page_id={{id}}'>{{title}}</a></b><br />";
|
73
|
|
74
|
$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
|
75
|
$msg = replace_all ( $msg_template_str, $values );
|
76
|
|
77
|
$page_names = "";
|
78
|
|
79
|
while ($data = $info->fetchRow() ) {
|
80
|
|
81
|
$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
|
82
|
$temp_title = $temp->fetchRow();
|
83
|
|
84
|
$page_info = array(
|
85
|
'id' => $data['page_id'],
|
86
|
'title' => $temp_title['page_title']
|
87
|
);
|
88
|
|
89
|
$page_names .= replace_all ( $page_template_str, $page_info );
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Printing out the error-message and die().
|
94
|
*/
|
95
|
$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
|
96
|
}
|
97
|
|
98
|
// Check if we have permissions on the directory
|
99
|
if(!is_writable(WB_PATH.'/modules/'.$file)) {
|
100
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
101
|
}
|
102
|
|
103
|
// Run the modules uninstall script if there is one
|
104
|
if(file_exists(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
|
105
|
require(WB_PATH.'/modules/'.$file.'/uninstall.php');
|
106
|
}
|
107
|
|
108
|
// Try to delete the module dir
|
109
|
if(!rm_full_dir(WB_PATH.'/modules/'.$file)) {
|
110
|
$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
|
111
|
} else {
|
112
|
// Remove entry from DB
|
113
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
|
114
|
}
|
115
|
|
116
|
// Print success message
|
117
|
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
|
118
|
|
119
|
// Print admin footer
|
120
|
$admin->print_footer();
|
121
|
|
122
|
?>
|