Project

General

Profile

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 1457 2011-06-25 17:18:50Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/modules/uninstall.php $
15
 * @lastmodified    $Date: 2011-06-25 19:18:50 +0200 (Sat, 25 Jun 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', false);
23
if( !$admin->checkFTAN() )
24
{
25
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
26
}
27
// After check print the header
28
$admin->print_header();
29

    
30
// Check if user selected module
31
if(!isset($_POST['file']) OR $_POST['file'] == "") {
32
	header("Location: index.php");
33
	exit(0);
34
} else {
35
	$file = $admin->add_slashes($_POST['file']);
36
}
37

    
38
// Extra protection
39
if(trim($file) == '') {
40
	header("Location: index.php");
41
	exit(0);
42
}
43

    
44
// Include the WB functions file
45
require_once(WB_PATH.'/framework/functions.php');
46

    
47
// Check if the module exists
48
if(!is_dir(WB_PATH.'/modules/'.$file)) {
49
	$admin->print_error($MESSAGE['GENERIC']['NOT_INSTALLED']);
50
}
51

    
52
if (!function_exists("replace_all")) {
53
	function replace_all ($aStr = "", &$aArray ) {
54
		foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
55
		return $aStr;
56
	}
57
}
58

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

    
61
if ( $info->numRows() > 0) {
62
	
63
	/**
64
	*	Modul is in use, so we have to warn the user
65
	*/
66
	if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
67
		$add = $info->numRows() == 1 ? "this page" : "these pages";
68
		$msg_template_str  = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use on {{pages}}";
69
		$msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
70
	} else {
71
		$msg_template_str = $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL'];
72
		$temp = explode(";",$MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
73
		$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
74
	}
75
	/**
76
	*	The template-string for displaying the Page-Titles ... in this case as a link
77
	*/
78
	$page_template_str = "- <b><a href='../pages/sections.php?page_id={{id}}'>{{title}}</a></b><br />";
79
	
80
	$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
81
	$msg = replace_all ( $msg_template_str,  $values );
82
		
83
	$page_names = "";
84
	
85
	while ($data = $info->fetchRow() ) {
86
	
87
		$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
88
		$temp_title = $temp->fetchRow();
89
		
90
		$page_info = array(
91
			'id'	=> $data['page_id'], 
92
			'title' => $temp_title['page_title']
93
		);
94
			
95
		$page_names .= replace_all ( $page_template_str, $page_info );
96
	}
97
	
98
	/**
99
	*	Printing out the error-message and die().
100
	*/
101
	$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
102
}
103

    
104
// Check if we have permissions on the directory
105
if(!is_writable(WB_PATH.'/modules/'.$file)) {
106
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
107
}
108

    
109
// Run the modules uninstall script if there is one
110
if(file_exists(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
111
	require(WB_PATH.'/modules/'.$file.'/uninstall.php');
112
}
113

    
114
// Try to delete the module dir
115
if(!rm_full_dir(WB_PATH.'/modules/'.$file)) {
116
	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
117
} else {
118
	// Remove entry from DB
119
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
120
}
121

    
122
// Print success message
123
$admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
124

    
125
// Print admin footer
126
$admin->print_footer();
127

    
128
?>
(5-5/5)