| 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 |  |  | require_once(WB_PATH.'/framework/class.admin.php');
 | 
      
        | 21 | 1457 | Luisehahne | $admin = new admin('Addons', 'modules_uninstall', false);
 | 
      
        | 22 |  |  | if( !$admin->checkFTAN() )
 | 
      
        | 23 |  |  | {
 | 
      
        | 24 | 1467 | Luisehahne | 	$admin->print_header();
 | 
      
        | 25 | 1457 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
 | 
      
        | 26 |  |  | }
 | 
      
        | 27 |  |  | // After check print the header
 | 
      
        | 28 |  |  | $admin->print_header();
 | 
      
        | 29 | 1712 | Luisehahne | 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 | 656 | thorn | 
 | 
      
        | 35 | 1712 | Luisehahne | // 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 | 4 | ryan | // Check if user selected module
 | 
      
        | 47 |  |  | if(!isset($_POST['file']) OR $_POST['file'] == "") {
 | 
      
        | 48 |  |  | 	header("Location: index.php");
 | 
      
        | 49 | 286 | stefan | 	exit(0);
 | 
      
        | 50 | 4 | ryan | } else {
 | 
      
        | 51 | 656 | thorn | 	$file = $admin->add_slashes($_POST['file']);
 | 
      
        | 52 | 4 | ryan | }
 | 
      
        | 53 |  |  | 
 | 
      
        | 54 | 268 | ryan | // Extra protection
 | 
      
        | 55 |  |  | if(trim($file) == '') {
 | 
      
        | 56 |  |  | 	header("Location: index.php");
 | 
      
        | 57 | 286 | stefan | 	exit(0);
 | 
      
        | 58 | 268 | ryan | }
 | 
      
        | 59 |  |  | 
 | 
      
        | 60 | 4 | ryan | // Check if the module exists
 | 
      
        | 61 |  |  | if(!is_dir(WB_PATH.'/modules/'.$file)) {
 | 
      
        | 62 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_NOT_INSTALLED']);
 | 
      
        | 63 | 4 | ryan | }
 | 
      
        | 64 | 1712 | Luisehahne | */
 | 
      
        | 65 | 4 | ryan | 
 | 
      
        | 66 | 1712 | Luisehahne | // Include the WB functions file
 | 
      
        | 67 |  |  | require_once(WB_PATH.'/framework/functions.php');
 | 
      
        | 68 |  |  | 
 | 
      
        | 69 | 863 | aldus | 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 | 4 | ryan | }
 | 
      
        | 75 |  |  | 
 | 
      
        | 76 | 863 | aldus | $info = $database->query("SELECT section_id, page_id FROM ".TABLE_PREFIX."sections WHERE module='".$_POST['file']."'" );
 | 
      
        | 77 |  |  | 
 | 
      
        | 78 |  |  | if ( $info->numRows() > 0) {
 | 
      
        | 79 | 1712 | Luisehahne | 
 | 
      
        | 80 | 863 | aldus | 	/**
 | 
      
        | 81 |  |  | 	*	Modul is in use, so we have to warn the user
 | 
      
        | 82 |  |  | 	*/
 | 
      
        | 83 | 893 | aldus | 	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 | 1712 | Luisehahne | 		$msg_template_str = $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL'];
 | 
      
        | 89 |  |  | 		$temp = explode(";",$MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
 | 
      
        | 90 | 893 | aldus | 		$add = $info->numRows() == 1 ? $temp[0] : $temp[1];
 | 
      
        | 91 |  |  | 	}
 | 
      
        | 92 | 863 | aldus | 	/**
 | 
      
        | 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 | 1712 | Luisehahne | 
 | 
      
        | 97 | 893 | aldus | 	$values = array ('type' => 'Modul', 'type_name' => $file, 'pages' => $add );
 | 
      
        | 98 | 863 | aldus | 	$msg = replace_all ( $msg_template_str,  $values );
 | 
      
        | 99 | 1712 | Luisehahne | 
 | 
      
        | 100 | 863 | aldus | 	$page_names = "";
 | 
      
        | 101 | 1712 | Luisehahne | 
 | 
      
        | 102 | 879 | aldus | 	while ($data = $info->fetchRow() ) {
 | 
      
        | 103 | 1712 | Luisehahne | 
 | 
      
        | 104 | 863 | aldus | 		$temp = $database->query("SELECT page_title from ".TABLE_PREFIX."pages where page_id=".$data['page_id']);
 | 
      
        | 105 | 896 | Ruebenwurz | 		$temp_title = $temp->fetchRow();
 | 
      
        | 106 | 1712 | Luisehahne | 
 | 
      
        | 107 | 863 | aldus | 		$page_info = array(
 | 
      
        | 108 | 1712 | Luisehahne | 			'id'	=> $data['page_id'],
 | 
      
        | 109 | 863 | aldus | 			'title' => $temp_title['page_title']
 | 
      
        | 110 |  |  | 		);
 | 
      
        | 111 | 1712 | Luisehahne | 
 | 
      
        | 112 | 863 | aldus | 		$page_names .= replace_all ( $page_template_str, $page_info );
 | 
      
        | 113 |  |  | 	}
 | 
      
        | 114 | 1712 | Luisehahne | 
 | 
      
        | 115 | 863 | aldus | 	/**
 | 
      
        | 116 |  |  | 	*	Printing out the error-message and die().
 | 
      
        | 117 |  |  | 	*/
 | 
      
        | 118 | 1712 | Luisehahne | 	$admin->print_error(str_replace ($TEXT['FILE'], "Modul", $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
 | 
      
        | 119 | 863 | aldus | }
 | 
      
        | 120 |  |  | 
 | 
      
        | 121 | 4 | ryan | // Check if we have permissions on the directory
 | 
      
        | 122 |  |  | if(!is_writable(WB_PATH.'/modules/'.$file)) {
 | 
      
        | 123 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL']);
 | 
      
        | 124 | 4 | ryan | }
 | 
      
        | 125 |  |  | 
 | 
      
        | 126 |  |  | // Run the modules uninstall script if there is one
 | 
      
        | 127 | 1712 | Luisehahne | if(is_readable(WB_PATH.'/modules/'.$file.'/uninstall.php')) {
 | 
      
        | 128 | 4 | ryan | 	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 | 1712 | Luisehahne | 	$admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL']);
 | 
      
        | 134 | 170 | ryan | } else {
 | 
      
        | 135 |  |  | 	// Remove entry from DB
 | 
      
        | 136 | 210 | stefan | 	$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE directory = '".$file."' AND type = 'module'");
 | 
      
        | 137 | 4 | ryan | }
 | 
      
        | 138 |  |  | 
 | 
      
        | 139 |  |  | // Print success message
 | 
      
        | 140 | 1712 | Luisehahne | $admin->print_success($MESSAGE['GENERIC_UNINSTALLED']);
 | 
      
        | 141 | 4 | ryan | 
 | 
      
        | 142 |  |  | // Print admin footer
 | 
      
        | 143 |  |  | $admin->print_footer();
 |