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 2098 2014-02-11 01:37:03Z darkviper $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/uninstall.php $
14
 * @lastmodified    $Date: 2014-02-11 02:37:03 +0100 (Tue, 11 Feb 2014) $
15
 *
16
 */
17

    
18
// Setup admin object
19
require('../../config.php');
20
//require_once(WB_PATH.'/framework/class.admin.php');
21
$oTrans = Translate::getInstance();
22
$oTrans->enableAddon('admin\\modules');
23

    
24
$admin = new admin('Addons', 'modules_uninstall', false);
25
if( !$admin->checkFTAN() )
26
{
27
	$admin->print_header();
28
	$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS);
29
}
30
// After check print the header
31
$admin->print_header();
32
if(!isset($_POST['file']) OR $_POST['file'] == "") {
33
	$admin->print_error($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS);
34
} else {
35
	$file = preg_replace('/[^a-z0-9_-]/i', "", $_POST['file']);  // fix secunia 2010-92-2
36
}
37

    
38
// Check if the template exists
39
if(!is_dir(WB_PATH.'/modules/'.$file)) {
40
	$admin->print_error($oTrans->MESSAGE_GENERIC_NOT_INSTALLED);
41
}
42

    
43
// Check if the template exists
44
if(!is_readable(WB_PATH.'/modules/'.$file)) {
45
	$admin->print_error($oTrans->MESSAGE_ADMIN_INSUFFICIENT_PRIVELLIGES);
46
}
47

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

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

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

    
69
// Include the WB functions file
70
require_once(WB_PATH.'/framework/functions.php');
71

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

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

    
81
if ( $info->numRows() > 0) {
82

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

    
100
	$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
101
	$msg = replace_all ( $msg_template_str,  $values );
102

    
103
	$page_names = "";
104

    
105
	while ($data = $info->fetchRow() ) {
106

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

    
110
		$page_info = array(
111
			'id'	=> $data['page_id'],
112
			'title' => $temp_title['page_title']
113
		);
114

    
115
		$page_names .= replace_all ( $page_template_str, $page_info );
116
	}
117

    
118
	/**
119
	*	Printing out the error-message and die().
120
	*/
121
	$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE).$msg.$page_names);
122
}
123

    
124
// Check if we have permissions on the directory
125
if(!is_writable(WB_PATH.'/modules/'.$file)) {
126
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL);
127
}
128

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

    
134
// Try to delete the module dir
135
if(!rm_full_dir(WB_PATH.'/modules/'.$file)) {
136
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL);
137
} else {
138
	// Remove entry from DB
139
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
140
}
141

    
142
// Print success message
143
$admin->print_success($oTrans->MESSAGE_GENERIC_UNINSTALLED);
144

    
145
// Print admin footer
146
$admin->print_footer();
(5-5/5)