Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         modules
6
 * @author          Ryan Djurovich,WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: uninstall.php 2070 2014-01-03 01:21:42Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/uninstall.php $
14
 * @lastmodified    $Date: 2014-01-03 02:21:42 +0100 (Fri, 03 Jan 2014) $
15
 *
16
 */
17

    
18
// Setup admin object
19
require('../../config.php');
20
require_once(WB_PATH.'/framework/class.admin.php');
21
$admin = new admin('Addons', 'modules_uninstall', false);
22
if( !$admin->checkFTAN() )
23
{
24
	$admin->print_header();
25
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
26
}
27
// After check print the header
28
$admin->print_header();
29
if(!isset($_POST['file']) OR $_POST['file'] == "") {
30
	$admin->print_error($MESSAGE['GENERIC_FORGOT_OPTIONS']);
31
} else {
32
	$file = preg_replace('/[^a-z0-9_-]/i', "", $_POST['file']);  // fix secunia 2010-92-2
33
}
34

    
35
// Check if the template exists
36
if(!is_dir(WB_PATH.'/modules/'.$file)) {
37
	$admin->print_error($MESSAGE['GENERIC_NOT_INSTALLED']);
38
}
39

    
40
// Check if the template exists
41
if(!is_readable(WB_PATH.'/modules/'.$file)) {
42
	$admin->print_error($MESSAGE['ADMIN_INSUFFICIENT_PRIVELLIGES']);
43
}
44

    
45
/*
46
// Check if user selected module
47
if(!isset($_POST['file']) OR $_POST['file'] == "") {
48
	header("Location: index.php");
49
	exit(0);
50
} else {
51
	$file = $admin->add_slashes($_POST['file']);
52
}
53

    
54
// Extra protection
55
if(trim($file) == '') {
56
	header("Location: index.php");
57
	exit(0);
58
}
59

    
60
// Check if the module exists
61
if(!is_dir(WB_PATH.'/modules/'.$file)) {
62
	$admin->print_error($MESSAGE['GENERIC_NOT_INSTALLED']);
63
}
64
*/
65

    
66
// Include the WB functions file
67
require_once(WB_PATH.'/framework/functions.php');
68

    
69
if (!function_exists("replace_all")) {
70
	function replace_all ($aStr = "", &$aArray ) {
71
		foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
72
		return $aStr;
73
	}
74
}
75

    
76
$info = $database->query("SELECT section_id, page_id FROM ".TABLE_PREFIX."sections WHERE module='".$_POST['file']."'" );
77

    
78
if ( $info->numRows() > 0) {
79

    
80
	/**
81
	*	Modul is in use, so we have to warn the user
82
	*/
83
	if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
84
		$add = $info->numRows() == 1 ? "this page" : "these pages";
85
		$msg_template_str  = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use on {{pages}}";
86
		$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
87
	} else {
88
		$msg_template_str = $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL'];
89
		$temp = explode(";",$MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
90
		$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
91
	}
92
	/**
93
	*	The template-string for displaying the Page-Titles ... in this case as a link
94
	*/
95
	$page_template_str = "- <b><a href='../pages/sections.php?page_id={{id}}'>{{title}}</a></b><br />";
96

    
97
	$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
98
	$msg = replace_all ( $msg_template_str,  $values );
99

    
100
	$page_names = "";
101

    
102
	while ($data = $info->fetchRow() ) {
103

    
104
		$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
105
		$temp_title = $temp->fetchRow();
106

    
107
		$page_info = array(
108
			'id'	=> $data['page_id'],
109
			'title' => $temp_title['page_title']
110
		);
111

    
112
		$page_names .= replace_all ( $page_template_str, $page_info );
113
	}
114

    
115
	/**
116
	*	Printing out the error-message and die().
117
	*/
118
	$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
119
}
120

    
121
// Check if we have permissions on the directory
122
if(!is_writable(WB_PATH.'/modules/'.$file)) {
123
	$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL']);
124
}
125

    
126
// Run the modules uninstall script if there is one
127
if(is_readable(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
128
	require(WB_PATH.'/modules/'.$file.'/uninstall.php');
129
}
130

    
131
// Try to delete the module dir
132
if(!rm_full_dir(WB_PATH.'/modules/'.$file)) {
133
	$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL']);
134
} else {
135
	// Remove entry from DB
136
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
137
}
138

    
139
// Print success message
140
$admin->print_success($MESSAGE['GENERIC_UNINSTALLED']);
141

    
142
// Print admin footer
143
$admin->print_footer();
(5-5/5)