Project

General

Profile

1 4 ryan
<?php
2 1386 Luisehahne
/**
3
 *
4
 * @category        admin
5
 * @package         modules
6 1712 Luisehahne
 * @author          Ryan Djurovich,WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1386 Luisehahne
 * @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$
13 1457 Luisehahne
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15 1386 Luisehahne
 *
16
 */
17 4 ryan
18 656 thorn
// Setup admin object
19
require('../../config.php');
20 2098 darkviper
//require_once(WB_PATH.'/framework/class.admin.php');
21
$oTrans = Translate::getInstance();
22
$oTrans->enableAddon('admin\\modules');
23
24 1457 Luisehahne
$admin = new admin('Addons', 'modules_uninstall', false);
25
if( !$admin->checkFTAN() )
26
{
27 1467 Luisehahne
	$admin->print_header();
28 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_SECURITY_ACCESS);
29 1457 Luisehahne
}
30
// After check print the header
31
$admin->print_header();
32 1712 Luisehahne
if(!isset($_POST['file']) OR $_POST['file'] == "") {
33 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_FORGOT_OPTIONS);
34 1712 Luisehahne
} else {
35
	$file = preg_replace('/[^a-z0-9_-]/i', "", $_POST['file']);  // fix secunia 2010-92-2
36
}
37 656 thorn
38 1712 Luisehahne
// Check if the template exists
39
if(!is_dir(WB_PATH.'/modules/'.$file)) {
40 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_NOT_INSTALLED);
41 1712 Luisehahne
}
42
43
// Check if the template exists
44
if(!is_readable(WB_PATH.'/modules/'.$file)) {
45 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_ADMIN_INSUFFICIENT_PRIVELLIGES);
46 1712 Luisehahne
}
47
48
/*
49 4 ryan
// Check if user selected module
50
if(!isset($_POST['file']) OR $_POST['file'] == "") {
51
	header("Location: index.php");
52 286 stefan
	exit(0);
53 4 ryan
} else {
54 656 thorn
	$file = $admin->add_slashes($_POST['file']);
55 4 ryan
}
56
57 268 ryan
// Extra protection
58
if(trim($file) == '') {
59
	header("Location: index.php");
60 286 stefan
	exit(0);
61 268 ryan
}
62
63 4 ryan
// Check if the module exists
64
if(!is_dir(WB_PATH.'/modules/'.$file)) {
65 1712 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_NOT_INSTALLED']);
66 4 ryan
}
67 1712 Luisehahne
*/
68 4 ryan
69 1712 Luisehahne
// Include the WB functions file
70
require_once(WB_PATH.'/framework/functions.php');
71
72 863 aldus
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 4 ryan
}
78
79 863 aldus
$info = $database->query("SELECT section_id, page_id FROM ".TABLE_PREFIX."sections WHERE module='".$_POST['file']."'" );
80
81
if ( $info->numRows() > 0) {
82 1712 Luisehahne
83 863 aldus
	/**
84
	*	Modul is in use, so we have to warn the user
85
	*/
86 2098 darkviper
    if (!isset($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL)) {
87 893 aldus
		$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 2098 darkviper
		$msg_template_str = $oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL;
92
		$temp = explode(";",$oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL_PAGES);
93 893 aldus
		$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
94
	}
95 863 aldus
	/**
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 1712 Luisehahne
100 893 aldus
	$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
101 863 aldus
	$msg = replace_all ( $msg_template_str,  $values );
102 1712 Luisehahne
103 863 aldus
	$page_names = "";
104 1712 Luisehahne
105 879 aldus
	while ($data = $info->fetchRow() ) {
106 1712 Luisehahne
107 863 aldus
		$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
108 896 Ruebenwurz
		$temp_title = $temp->fetchRow();
109 1712 Luisehahne
110 863 aldus
		$page_info = array(
111 1712 Luisehahne
			'id'	=> $data['page_id'],
112 863 aldus
			'title' => $temp_title['page_title']
113
		);
114 1712 Luisehahne
115 863 aldus
		$page_names .= replace_all ( $page_template_str, $page_info );
116
	}
117 1712 Luisehahne
118 863 aldus
	/**
119
	*	Printing out the error-message and die().
120
	*/
121 2098 darkviper
	$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE).$msg.$page_names);
122 863 aldus
}
123
124 4 ryan
// Check if we have permissions on the directory
125
if(!is_writable(WB_PATH.'/modules/'.$file)) {
126 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL);
127 4 ryan
}
128
129
// Run the modules uninstall script if there is one
130 1712 Luisehahne
if(is_readable(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
131 4 ryan
	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 2098 darkviper
	$admin->print_error($oTrans->MESSAGE_GENERIC_CANNOT_UNINSTALL);
137 170 ryan
} else {
138
	// Remove entry from DB
139 210 stefan
	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
140 4 ryan
}
141
142
// Print success message
143 2098 darkviper
$admin->print_success($oTrans->MESSAGE_GENERIC_UNINSTALLED);
144 4 ryan
145
// Print admin footer
146
$admin->print_footer();