| 1 | 4 | ryan | <?php
 | 
      
        | 2 |  |  | 
 | 
      
        | 3 | 40 | stefan | // $Id$
 | 
      
        | 4 | 4 | ryan | 
 | 
      
        | 5 |  |  | /*
 | 
      
        | 6 |  |  | 
 | 
      
        | 7 |  |  |  Website Baker Project <http://www.websitebaker.org/>
 | 
      
        | 8 | 519 | Ruebenwurz |  Copyright (C) 2004-2008, Ryan Djurovich
 | 
      
        | 9 | 4 | ryan | 
 | 
      
        | 10 |  |  |  Website Baker is free software; you can redistribute it and/or modify
 | 
      
        | 11 |  |  |  it under the terms of the GNU General Public License as published by
 | 
      
        | 12 |  |  |  the Free Software Foundation; either version 2 of the License, or
 | 
      
        | 13 |  |  |  (at your option) any later version.
 | 
      
        | 14 |  |  | 
 | 
      
        | 15 |  |  |  Website Baker is distributed in the hope that it will be useful,
 | 
      
        | 16 |  |  |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
      
        | 17 |  |  |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
      
        | 18 |  |  |  GNU General Public License for more details.
 | 
      
        | 19 |  |  | 
 | 
      
        | 20 |  |  |  You should have received a copy of the GNU General Public License
 | 
      
        | 21 |  |  |  along with Website Baker; if not, write to the Free Software
 | 
      
        | 22 |  |  |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
      
        | 23 |  |  | 
 | 
      
        | 24 |  |  | */
 | 
      
        | 25 |  |  | 
 | 
      
        | 26 | 656 | thorn | // Setup admin object
 | 
      
        | 27 |  |  | require('../../config.php');
 | 
      
        | 28 |  |  | require_once(WB_PATH.'/framework/class.admin.php');
 | 
      
        | 29 |  |  | $admin = new admin('Addons', 'modules_uninstall');
 | 
      
        | 30 |  |  | 
 | 
      
        | 31 | 4 | ryan | // Check if user selected module
 | 
      
        | 32 |  |  | if(!isset($_POST['file']) OR $_POST['file'] == "") {
 | 
      
        | 33 |  |  | 	header("Location: index.php");
 | 
      
        | 34 | 286 | stefan | 	exit(0);
 | 
      
        | 35 | 4 | ryan | } else {
 | 
      
        | 36 | 656 | thorn | 	$file = $admin->add_slashes($_POST['file']);
 | 
      
        | 37 | 4 | ryan | }
 | 
      
        | 38 |  |  | 
 | 
      
        | 39 | 268 | ryan | // Extra protection
 | 
      
        | 40 |  |  | if(trim($file) == '') {
 | 
      
        | 41 |  |  | 	header("Location: index.php");
 | 
      
        | 42 | 286 | stefan | 	exit(0);
 | 
      
        | 43 | 268 | ryan | }
 | 
      
        | 44 |  |  | 
 | 
      
        | 45 | 4 | ryan | // Include the WB functions file
 | 
      
        | 46 |  |  | require_once(WB_PATH.'/framework/functions.php');
 | 
      
        | 47 |  |  | 
 | 
      
        | 48 |  |  | // Check if the module exists
 | 
      
        | 49 |  |  | if(!is_dir(WB_PATH.'/modules/'.$file)) {
 | 
      
        | 50 |  |  | 	$admin->print_error($MESSAGE['MODULES']['NOT_INSTALLED']);
 | 
      
        | 51 |  |  | }
 | 
      
        | 52 |  |  | 
 | 
      
        | 53 |  |  | // Check if the module is in use
 | 
      
        | 54 | 40 | stefan | $query_modules = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE module = '".$admin->add_slashes($_POST['file'])."' LIMIT 1");
 | 
      
        | 55 | 4 | ryan | if($query_modules->numRows() > 0) {
 | 
      
        | 56 |  |  | 	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL_IN_USE']);
 | 
      
        | 57 |  |  | }
 | 
      
        | 58 |  |  | 
 | 
      
        | 59 |  |  | // Check if we have permissions on the directory
 | 
      
        | 60 |  |  | if(!is_writable(WB_PATH.'/modules/'.$file)) {
 | 
      
        | 61 |  |  | 	$admin->print_error($MESSAGE['GENERIC']['CANNOT_UNINSTALL']);
 | 
      
        | 62 |  |  | }
 | 
      
        | 63 |  |  | 
 | 
      
        | 64 | 170 | ryan | $database->query("DELETE FROM ".TABLE_PREFIX."modules WHERE directory = '$file'");
 | 
      
        | 65 | 114 | stefan | 
 | 
      
        | 66 | 4 | ryan | // Run the modules uninstall script if there is one
 | 
      
        | 67 |  |  | if(file_exists(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
 | 
      
        | 68 |  |  | 	require(WB_PATH.'/modules/'.$file.'/uninstall.php');
 | 
      
        | 69 |  |  | }
 | 
      
        | 70 |  |  | 
 | 
      
        | 71 |  |  | // Try to delete the module dir
 | 
      
        | 72 |  |  | if(!rm_full_dir(WB_PATH.'/modules/'.$file)) {
 | 
      
        | 73 |  |  | 	$admin->print_error($MESSAGE['MODULES']['CANNOT_UNINSTALL']);
 | 
      
        | 74 | 170 | ryan | } else {
 | 
      
        | 75 |  |  | 	// Remove entry from DB
 | 
      
        | 76 | 210 | stefan | 	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
 | 
      
        | 77 | 4 | ryan | }
 | 
      
        | 78 |  |  | 
 | 
      
        | 79 |  |  | // Print success message
 | 
      
        | 80 |  |  | $admin->print_success($MESSAGE['GENERIC']['UNINSTALLED']);
 | 
      
        | 81 |  |  | 
 | 
      
        | 82 |  |  | // Print admin footer
 | 
      
        | 83 |  |  | $admin->print_footer();
 | 
      
        | 84 |  |  | 
 | 
      
        | 85 |  |  | ?>
 |