Project

General

Profile

1 4 ryan
<?php
2 1386 Luisehahne
/**
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$
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 4 ryan
19 656 thorn
// 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 4 ryan
// Check if user selected module
25
if(!isset($_POST['file']) OR $_POST['file'] == "") {
26
	header("Location: index.php");
27 286 stefan
	exit(0);
28 4 ryan
} else {
29 656 thorn
	$file = $admin->add_slashes($_POST['file']);
30 4 ryan
}
31
32 268 ryan
// Extra protection
33
if(trim($file) == '') {
34
	header("Location: index.php");
35 286 stefan
	exit(0);
36 268 ryan
}
37
38 4 ryan
// 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 942 doc
	$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
44 4 ryan
}
45
46 863 aldus
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 4 ryan
}
52
53 863 aldus
$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 893 aldus
	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 863 aldus
	/**
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 893 aldus
	$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
75 863 aldus
	$msg = replace_all ( $msg_template_str,  $values );
76
77
	$page_names = "";
78
79 879 aldus
	while ($data = $info->fetchRow() ) {
80 863 aldus
81
		$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
82 896 Ruebenwurz
		$temp_title = $temp->fetchRow();
83 863 aldus
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 896 Ruebenwurz
	$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
96 863 aldus
}
97
98 4 ryan
// 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 942 doc
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
111 170 ryan
} else {
112
	// Remove entry from DB
113 210 stefan
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
114 4 ryan
}
115
116
// Print success message
117
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
118
119
// Print admin footer
120
$admin->print_footer();
121
122
?>