Project

General

Profile

1 4 ryan
<?php
2 1467 Luisehahne
/**
3
 *
4
 * @category        admin
5
 * @package         languages
6 1712 Luisehahne
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 1467 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
 * @filesource      $HeadURL$
14
 * @lastmodified    $Date$
15
 * @description
16
 *
17
 */
18 4 ryan
19 1785 Luisehahne
// Include config file
20
$config_file = realpath('../../config.php');
21
if(file_exists($config_file) && !defined('WB_URL'))
22
{
23
	require($config_file);
24
}
25
26
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
27
28 1457 Luisehahne
$admin = new admin('Addons', 'languages_uninstall', false);
29
if( !$admin->checkFTAN() )
30
{
31 1467 Luisehahne
	$admin->print_header();
32 1457 Luisehahne
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
33
}
34
// After check print the header
35
$admin->print_header();
36 2098 darkviper
$oLang = Translate::getInstance();
37
$oLang->enableAddon('admin\\languages');
38 1457 Luisehahne
39 1712 Luisehahne
// Get language name
40
if(!isset($_POST['code']) OR $_POST['code'] == "") {
41
	$code = '';
42
	$file = '';
43
} else {
44
	$code = $_POST['code'];
45
	$file = $_POST['code'].'.php';
46
}
47
// fix secunia 2010-93-2
48
if (!preg_match('/^([A-Z]{2}.php)/', $file)) {
49 2098 darkviper
	$admin->print_error($oLang->MESSAGE_GENERIC_FORGOT_OPTIONS);
50 1712 Luisehahne
}
51
52
// Check if the template exists
53
if(!is_file(WB_PATH.'/languages/'.$file)) {
54 2098 darkviper
	$admin->print_error($oLang->MESSAGE_GENERIC_NOT_INSTALLED);
55 1712 Luisehahne
}
56
57
// Check if the template exists
58
if(!is_readable(WB_PATH.'/languages/'.$file)) {
59 2098 darkviper
	$admin->print_error($oLang->MESSAGE_ADMIN_INSUFFICIENT_PRIVELLIGES);
60 1712 Luisehahne
}
61
62
// Include the WB functions file
63
require_once(WB_PATH.'/framework/functions.php');
64 4 ryan
65
// Check if the language is in use
66 1712 Luisehahne
if($code == DEFAULT_LANGUAGE OR $code == LANGUAGE) {
67 2098 darkviper
	$admin->print_error($oLang->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE);
68 4 ryan
} else {
69 1785 Luisehahne
	$sql  = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'users` ';
70 1868 Luisehahne
	$sql .= 'WHERE`language`=\''.$database->escapeString($code).'\'';
71 1785 Luisehahne
	if( $database->get_one($sql) ) {
72 2098 darkviper
		$admin->print_error($oLang->MESSAGE_GENERIC_CANNOT_UNINSTALL_IN_USE);
73 4 ryan
	}
74
}
75
76
// Try to delete the language code
77 1712 Luisehahne
if(!unlink(WB_PATH.'/languages/'.$file)) {
78 2098 darkviper
	$admin->print_error($oLang->MESSAGE_GENERIC_CANNOT_UNINSTALL);
79 170 ryan
} else {
80
	// Remove entry from DB
81 1785 Luisehahne
	$sql  = 'DELETE FROM `'.TABLE_PREFIX.'addons` ';
82 1868 Luisehahne
	$sql .= 'WHERE `directory`=\''.$database->escapeString($code).'\' ';
83 1785 Luisehahne
	$sql .=   'AND `type`=`type`=\'language\' ';
84
	if( $database->query($sql) ) {
85
        // Print success message
86 2098 darkviper
        $admin->print_success($oLang->MESSAGE_GENERIC_UNINSTALLED);
87 1785 Luisehahne
    } else {
88 2098 darkviper
    	$admin->print_error($oLang->MESSAGE_GENERIC_CANNOT_UNINSTALL.'<br />'.$database->get_error());
89 1785 Luisehahne
    }
90 4 ryan
}
91
92
// Print admin footer
93
$admin->print_footer();