<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.0.3 - Licence Number 239149d8
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000–2004 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

error_reporting(E_ALL & ~E_NOTICE);

define('VERSION', '3.0.3');
define('THIS_SCRIPT', 'tools.php');

if (file_exists('./../includes/init.php'))
{ // need to go up a single directory, we must be in includes / admincp / modcp / install
	chdir('./../');
}
else
{
	die('Bitte speichern Sie diese Datei im admincp oder install Verzeichnis!');
}

require_once('./includes/init.php');
require_once('./includes/functions.php');
require_once('./includes/adminfunctions.php');

#####################################
# phrases for import systems
#####################################
$vbphrase['importing_language'] = 'Importiere die Sprachdatei';
$vbphrase['importing_style'] = 'Importiere die Styledatei';
$vbphrase['importing_admin_help'] = 'Importiere die Administratoren-Hilfe';
$vbphrase['importing_settings'] = 'Importiere die Einstellungen';
$vbphrase['please_wait'] = 'Bitte warten';
$vbphrase['language'] = 'Sprache';
$vbphrase['master_language'] = 'MASTER-LANGUAGE';
$vbphrase['admin_help'] = 'Administratoren-Hilfe';
$vbphrase['style'] = 'Style';
$vbphrase['styles'] = 'Styles';
$vbphrase['settings'] = 'Einstellungen';
$vbphrase['master_style'] = 'MASTER-STYLE';
$vbphrase['templates'] = 'Templates';
$vbphrase['css'] = 'CSS';
$vbphrase['stylevars'] = 'Stylevariablen';
$vbphrase['replacement_variables'] = 'Ersetzungsvariablen';
$vbphrase['controls'] = 'Einstellungen';
$vbphrase['rebuild_style_information'] = 'Style-Information neu erstellen';
$vbphrase['updating_style_information_for_each_style'] = 'Aktualisiere Styleinformationen f&uuml;r jeden Style...';
$vbphrase['updating_styles_with_no_parents'] = 'Aktualisiere Stylesets ohne Oberstyle';
$vbphrase['updated_x_styles'] = '%1$s Style(s) aktualisiert';
$vbphrase['no_styles_needed_updating'] = 'Keine Styles mussten aktualisiert werden';
$vbphrase['processing_complete_proceed'] = 'Bearbeitung abgeschlossen - Weiter';

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>vBulletin 3.0 Tools</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<link rel="stylesheet" href="../cpstyles/vBulletin_3_Default/controlpanel.css" />
	<script type="text/javascript">var SESSIONHASH = "";</script>
	<script type="text/javascript" src="../clientscript/generic.js"></script>

</head>
<body style="margin:0px">
<!-- END CONTROL PANEL HEADER -->
<?php

if (empty($_REQUEST['do']))
{
	print_form_header();
	print_table_header('XML-Dateien importieren');
	print_label_row(construct_link_code('Style', THIS_SCRIPT . '?do=xml&amp;type=style'), 'Es wird die Datei ./install/vbulletin-style.xml importiert.');
	print_label_row(construct_link_code('Einstellungen', THIS_SCRIPT . '?do=xml&amp;type=settings'), 'Es wird die Datei ./install/vbulletin-settings.xml importiert.');
	print_label_row(construct_link_code('Sprache', THIS_SCRIPT . '?do=xml&amp;type=language'), 'Es wird die Datei ./install/vbulletin-language.xml importiert.');
	print_table_header('Datastore Caches');
	print_label_row(construct_link_code('Benutzergruppen-/Forum-Cache', THIS_SCRIPT . '?do=cache&amp;type=forum'), 'Cache der Benutzergruppen- und Foren-Einstellungen aktualisieren.');
	print_label_row(construct_link_code('vBulletin-Einstellungen-Cache', THIS_SCRIPT . '?do=mysql&amp;type=options'), 'Cache der vBulletin-Einstellungen aktualisieren.');
	print_table_header('MySQL');
	print_label_row(construct_link_code('Query ausf&uuml;hren', THIS_SCRIPT . '?do=mysql&amp;type=query'), 'ALTER und UPDATE Querys in der Datenbank ausf&uuml;hren.');
	print_label_row(construct_link_code('Tabellen reparieren', THIS_SCRIPT . '?do=mysql&amp;type=repair'), 'Einzelne oder mehrere Tabellen reparieren.');
	print_table_header('MySQL');
	print_label_row(construct_link_code('Administrator-Rechte wiederherstellen', THIS_SCRIPT . '?do=user&amp;type=access'), 'Administrator-Rechte eines Benutzers wiederherstellen');
	print_table_footer();
}
else if ($_REQUEST['do'] == 'xml')
{
	switch ($_REQUEST['type'])
	{
		case 'style':
			require_once('./includes/adminfunctions_template.php');
		
			if (!($xml = file_read('./install/vbulletin-style.xml')))
			{
				echo '<p>Oha, ./install/vbulletin-style.xml scheint nicht vorhanden zu sein! Laden Sie die Datei hoch und aktualisieren Sie diese Seite.</p>';
				break;
			}
		
			echo '<p>Importiere vbulletin-style.xml</p>';
		
			xml_import_style($xml);
		
			// define those phrases that are used for the import
			$vbphrase['importing_x'] = 'Importiere %1$s';
			$vbphrase['style'] = 'Style';
			$vbphrase['please_wait'] = 'Bitte warten';
		
			build_all_styles(0, 1);
		break;
		case 'settings':
			require_once('./includes/adminfunctions_options.php');
		
			if (!($xml = file_read('./install/vbulletin-settings.xml')))
			{
				echo '<p>Oha, ./install/vbulletin-settings.xml scheint nicht vorhanden zu sein! Laden Sie die Datei hoch und aktualisieren Sie diese Seite.</p>';
				print_cp_footer();
			}
		
			echo '<p>Importiere vbulletin-settings.xml';
			xml_import_settings($xml);
			echo '<br /><span class="smallfont"><b>Fertig!</b></span></p>';
		break;
		case 'language':
			require_once('./includes/adminfunctions_language.php');
		
			if (!($xml = file_read('./install/vbulletin-language.xml')))
			{
				echo '<p>Oha, ./install/vbulletin-language.xml scheint nicht vorhanden zu sein! Laden Sie die Datei hoch und aktualisieren Sie diese Seite.</p>';
				print_cp_footer();
			}
		
			echo '<p>Importiere vbulletin-language.xml';
			xml_import_language($xml);
			build_language();
			echo '<br /><span class="smallfont"><b>Fertig!</b></span></p>';
		break;
	}
	define('SCRIPT_REDIRECT', true);
}
else if ($_REQUEST['do'] == 'cache')
{
	switch ($_REQUEST['type'])
	{
		case 'forum':
			build_forum_permissions();
			define('SCRIPT_REDIRECT', true);
		break;
		case 'options':
			build_options();
			define('SCRIPT_REDIRECT', true);
		break;
	}
}
else if ($_REQUEST['do'] == 'mysql')
{
	switch ($_REQUEST['type'])
	{
		case 'query':
		if (empty($_POST['query']) OR !preg_match('#^(Alter|Update)#si', $_POST['query']))
		{
			print_form_header('tools', 'mysql');
			construct_hidden_code('type', 'query');
			print_table_header('Schreiben Sie Ihr ALTER oder UPDATE Query in dieses Feld');
			print_textarea_row('Query', 'query','', 6, 60, 0, 0);
			print_submit_row('Ausf&uuml;hren', '');
		}
		else
		{
			$DB_site->query($_POST['query']);
			define('SCRIPT_REDIRECT', true);
		}
		break;
		case 'repair':
		if (empty($_POST['tables']))
		{
			print_form_header('tools', 'mysql');
			construct_hidden_code('type', 'repair');
			print_table_header('Bitte w&auml;hlen Sie die Tabellen aus');
			$result = $DB_site->query("SHOW tables");
			while ($currow = $DB_site->fetch_array($result, DBARRAY_NUM))
			{
				print_checkbox_row($currow[0], "tables[$currow[0]]", 0);
			}
			print_submit_row('Tabellen reparieren', '');
		}
		else
		{
			$result = $DB_site->query("SHOW tables");
			foreach($_POST['tables'] AS $key => $val)
			{
				if ($val == 1)
				{
					echo "Repariere $key<br />\n";
					flush();
					$DB_site->query("REPAIR TABLE $key");
					echo "Fertig!<br />\n";
				}
			}
			echo "Alle ausgew&auml;hlten Tabellen wurden repariert.<br />";
			define('SCRIPT_REDIRECT', true);
		}
		break;
	}
}
else if ($_REQUEST['do'] == 'user')
{
	switch ($_REQUEST['type'])
	{
		case 'access':
		if (empty($_POST['user']))
		{
			print_form_header('tools', 'user');
			construct_hidden_code('type', 'access');
			print_table_header('Benutzer, dessen Rechte wiederhergestellt werden sollen');
			print_input_row('Benutzername', 'user', '');
			print_submit_row('Und los!', '');
		}
		else
		{
			$userid = $DB_site->query_first("SELECT userid, usergroupid FROM " . TABLE_PREFIX . "user WHERE username = '" . addslashes(htmlspecialchars_uni($_POST['user'])) . "'");
			if (empty($userid['userid']))
			{
				echo '<p align="center">Dieser Benutzername existiert nicht!</p>';
			}
			else
			{
				// lets check that usergroupid 6 is still admin
				$ugroup = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = 6 AND (adminpermissions & " . CANCONTROLPANEL . ")");
				if (empty($ugroup['usergroupid']))
				{ // lets give them admin permissions again
					$DB_site->query("UPDATE " . TABLE_PREFIX . "usergroup SET adminpermissions = 3 WHERE usergroupid = 6");
					build_forum_permissions();
				}
				$DB_site->query("REPLACE INTO " . TABLE_PREFIX . "administrator
					(userid, adminpermissions)
				VALUES
					($userid[userid], " . (array_sum($_BITFIELD['usergroup']['adminpermissions'])-3) . ")
				");
				$DB_site->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = 6 WHERE userid = $userid[userid]");
				define('SCRIPT_REDIRECT', true);
			}
		}
		break;
	}
}

if (defined('SCRIPT_REDIRECT'))
{
	echo '<p align="center" class="smallfont"><a href="tools.php" onclick="javascript:clearTimeout(timerID);">' . $vbphrase['processing_complete_proceed'] . '</a></p>';
	echo "\n<script type=\"text/javascript\">\n";
	echo "myvar = \"\"; timeout = " . (20) . ";
	function exec_refresh()
	{
		window.status=\"" . $vbphrase['redirecting'] . "\"+myvar; myvar = myvar + \" .\";
		timerID = setTimeout(\"exec_refresh();\", 100);
		if (timeout > 0)
		{ timeout -= 1; }
		else { clearTimeout(timerID); window.status=\"\"; window.location=\"tools.php\"; }
	}
	exec_refresh();";
	echo "\n</script>\n";
}
?>
<!-- START CONTROL PANEL FOOTER -->
<p align="center"><a href="http://www.vbulletin.com/" target="_blank" class="copyright">vBulletin <?php echo VERSION; ?>, Copyright ©2000-2004, Jelsoft Enterprises Ltd</a></p>
</div>
</body>
</html>