<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.1.7 - Licence Number 239149d8
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2000–2011 vBulletin Solutions Inc. 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 # ||
|| #################################################################### ||
\*======================================================================*/

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('VERSION', '4.1.7');
define('THIS_SCRIPT', 'tools.php');
define('VB_AREA', 'tools');
define('VB_ENTRY', 1);
define('UPGRADE_LANGUAGE', 'de');

if (strlen('cf0267587935d70cffe42b47c9325cbb') == 32)
{
	/**
	* @ignore
	*/
	define('CUSTOMER_NUMBER', 'cf0267587935d70cffe42b47c9325cbb');
}
else
{
	/**
	* @ignore
	*/
	define('CUSTOMER_NUMBER', md5(strtoupper('cf0267587935d70cffe42b47c9325cbb')));
}

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!');
}

if (!file_exists('./install/init.php'))
{
	die('Die Datei <strong>/install/init.php</strong> wurde nicht gefunden.<br /><br />Bitte laden Sie diese Datei bzw. das komplette <i>/install/</i> Verzeichnis wieder hoch.');
}

$languagecode = defined('UPGRADE_LANGUAGE') ? UPGRADE_LANGUAGE : 'de';
if (!file_exists('./install/upgrade_language_' . $languagecode . '.xml'))
{
	die('Die Datei <strong>/install/upgrade_language_' . $languagecode . '.xml</strong> wurde nicht gefunden.<br /><br />Bitte laden Sie diese Datei bzw. das komplette <i>/install/</i> Verzeichnis wieder hoch.');
}

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

$specialtemplates = array();
$datastore_class = (!empty($vbulletin->config['Datastore']['class'])) ? $vbulletin->config['Datastore']['class'] : 'vB_Datastore';

if ($datastore_class != 'vB_Datastore')
{
	require_once(DIR . '/includes/class_datastore.php');
}
$vbulletin->datastore = new $datastore_class($vbulletin, $db);
$vbulletin->datastore->fetch($specialtemplates);

$type = $vbulletin->input->clean_gpc('r', 'type', TYPE_STR);
$customerid = $vbulletin->input->clean_gpc('p', 'customerid', TYPE_STR);
$bbcustomerid = $vbulletin->input->clean_gpc('c', 'bbcustomerid', TYPE_STR);

// #############################################################################
if ($_POST['do'] == 'login')
{
	if (md5(strtoupper($vbulletin->GPC['customerid'])) == CUSTOMER_NUMBER)
	{
		setcookie('bbcustomerid', md5(strtoupper($vbulletin->GPC['customerid'])), 0, '/', '');
		$vbulletin->GPC['bbcustomerid'] = CUSTOMER_NUMBER;
		$_REQUEST['do'] = '';
	}
}

// #############################################################################
if ($vbulletin->GPC['bbcustomerid'] !== CUSTOMER_NUMBER)
{
	global $stylevar;

	// set the style folder
	if (empty($vbulletin->options['cpstylefolder']))
	{
		$vbulletin->options['cpstylefolder'] = 'vBulletin_3_Silver';
	}
	// set the forumhome script
	if (empty($vbulletin->options['forumhome']))
	{
		$vbulletin->options['forumhome'] = 'index';
	}
	// set the version
	$vbulletin->options['templateversion'] = VERSION;

	define('NO_PAGE_TITLE', true);
	print_cp_header('Tools');

	?>
	<form action="<?php echo THIS_SCRIPT; ?>?do=login" method="post">
	<input type="hidden" name="do" value="login" />
	<p>&nbsp;</p><p>&nbsp;</p>
	<table class="tborder" cellpadding="0" cellspacing="0" border="0" width="450" align="center"><tr><td>

		<!-- header -->
		<div class="tcat" style="padding:4px; text-align:center"><b>Bitte geben Sie Ihre Kundennummer ein</b></div>
		<!-- /header -->

		<!-- logo and version -->
		<table cellpadding="4" cellspacing="0" border="0" width="100%" class="navbody">
		<tr valign="bottom">
			<td><img src="../cpstyles/<?php echo $vbulletin->options['cpstylefolder']; ?>/cp_logo.gif" alt="" border="0" /></td>
			<td>
				<b><a href="../<?php echo $vbulletin->options['forumhome']; ?>.php"><?php echo $vbulletin->options['bbtitle']; ?></a></b><br />
				<?php echo 'vBulletin ' . $vbulletin->options['templateversion'] . ' Tools'; ?><br />
				&nbsp;
			</td>
		</tr>
		</table>
		<!-- /logo and version -->

		<table cellpadding="4" cellspacing="0" border="0" width="100%" class="logincontrols">
		<col width="50%" style="text-align:right; white-space:nowrap"></col>
		<col></col>
		<col width="50%"></col>
		<!-- login fields -->
		<tr valign="top">
			<td>&nbsp;<br />Kundennummer<br />&nbsp;</td>
			<td class="smallfont"><input type="text" style="padding-left:5px; font-weight:bold; width:250px" name="customerid" value="" tabindex="1" /><br />Dies ist dieselbe Nummer, mit der Sie sich im vBulletin-Germany.com Kundenbereich anmelden.</td>
			<td>&nbsp;</td>
		</tr>
		<!-- /login fields -->
		<!-- submit row -->
		<tr>
			<td colspan="3" align="center">
				<input type="submit" class="button" value="Tool-System starten" accesskey="s" tabindex="3" />
			</td>
		</tr>
		<!-- /submit row -->
		</table>
	</td></tr></table>
	</form>
	<?php

	unset($debug, $GLOBALS['DEVDEBUG']);
	print_cp_footer();
}

#####################################
# 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-Tools</title>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<link rel="stylesheet" href="../cpstyles/vBulletin_3_Silver/controlpanel.css" />
	<script type="text/javascript">var SESSIONHASH = "";</script>
	<script type="text/javascript" src="../clientscript/vbulletin_global.js"></script>
</head>
<body style="margin:0px">
<!-- END CONTROL PANEL HEADER -->
<?php

if (empty($_REQUEST['do']))
{

	// Get versions of .xml files for header diagnostics
	if ($fp = @fopen('./install/vbulletin-style.xml', 'rb'))
	{
		$data = fread($fp, 256);

		if (preg_match('#vbversion="(.*?)"#', $data, $matches))
		{
			$style_xml = $matches[1];
		}
		else
		{
			$style_xml = 'nicht bekannt';
		}
		fclose($fp);
	}
	else
	{
		$style_xml = 'nicht verf&uuml;gbar';
	}

	if ($fp = @fopen('./install/vbulletin-language.xml', 'rb'))
	{
		$data = fread($fp, 256);

		if (preg_match('#vbversion="(.*?)"#', $data, $matches))
		{
			$language_xml = $matches[1];
		}
		else
		{
			$language_xml = 'nicht bekannt';
		}
		fclose($fp);
	}
	else
	{
		$language_xml = 'nicht verf&uuml;gbar';
	}

	if ($fp = @fopen('./install/vbulletin-settings.xml', 'rb'))
	{
		$data = fread($fp, 300);

		if (preg_match('#<defaultvalue>(.*?)</defaultvalue>#', $data, $matches))
		{
			$settings_xml = $matches[1];
		}
		else
		{
			$settings_xml = 'nicht bekannt';
		}
		fclose($fp);
	}
	else
	{
		$settings_xml = 'nicht verf&uuml;gbar';
	}

	print_form_header();

	echo "<h2>vBulletin-Tools</h2>";

	print_table_header('XML-Dateien importieren');
	print_column_style_code(array('width:30%'));
	print_label_row(construct_link_code('Style', THIS_SCRIPT . '?do=xml&amp;type=style'), "Es wird die Datei ./install/vbulletin-style.xml importiert.<dfn>Version: <b>$style_xml</b></dfn>");
	print_label_row(construct_link_code('Einstellungen', THIS_SCRIPT . '?do=xml&amp;type=settings'), "Es wird die Datei ./install/vbulletin-settings.xml importiert.<dfn>Version: <b>$settings_xml</b></dfn>");
	print_label_row(construct_link_code('Sprache', THIS_SCRIPT . '?do=xml&amp;type=language'), "Es wird die Datei ./install/vbulletin-language.xml importiert.<dfn>Version: <b>$language_xml</b></dfn>");
	print_label_row(construct_link_code('Adminhilfe', THIS_SCRIPT . '?do=xml&amp;type=adminhelp'), 'Es wird die Datei ./install/vbulletin-adminhelp.xml importiert.');
	print_table_break();

	print_table_header('Datastore-Cache');
	print_column_style_code(array('width:30%'));
	print_label_row(construct_link_code('Benutzergruppen/Foren', THIS_SCRIPT . '?do=cache&amp;type=forum'), 'Cache der Benutzergruppen- und Foren-Einstellungen aktualisieren.');
	print_label_row(construct_link_code('vBulletin-Einstellungen', THIS_SCRIPT . '?do=cache&amp;type=options'), 'Cache der vBulletin-Einstellungen aktualisieren.');
	print_label_row(construct_link_code('Bitfelder', THIS_SCRIPT . '?do=bitfields'), 'Cache der Bitfelder aus den Dateien /includes/xml/bitfields_<em>???</em>.xml aktualisieren.');
	print_table_break();

	print_table_header('Cookies');
	print_column_style_code(array('width:30%'));
	$vbulletin->options['cookiedomain'] = $vbulletin->options['cookiedomain'] == '' ? ' ( <em>leer</em> ) ' : '<b>' . htmlspecialchars_uni($vbulletin->options['cookiedomain']) . '</b>';
	$vbulletin->options['cookiepath'] = $vbulletin->options['cookiepath'] == '' ? ' ( <em>leer</em> ) ' : '<b>' . htmlspecialchars_uni($vbulletin->options['cookiepath']) . '</b>';
	print_label_row('Cookie-Pr&auml;fix', '<b>' . htmlspecialchars_uni(COOKIE_PREFIX) . '</b> (<em>gesetzt in includes/config.php</em>)');
	print_label_row(construct_link_code('Cookie-Domain zur&uuml;cksetzen', THIS_SCRIPT . '?do=cookie&amp;type=domain'), 'Cookie-Domain wird gel&ouml;scht.<dfn>Aktuell: ' . $vbulletin->options['cookiedomain'] . '</dfn>');
	print_label_row(construct_link_code('Cookie-Pfad zur&uuml;cksetzen', THIS_SCRIPT . '?do=cookie&amp;type=path'), 'Cookie-Pfad wird auf <b>/</b> gesetzt.<dfn>Aktuell: ' . $vbulletin->options['cookiepath'] . '</dfn>');
	print_table_break();

	print_table_header('MySQL');
	print_column_style_code(array('width:30%'));
	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_label_row(construct_link_code('Administrator-Rechte wiederherstellen', THIS_SCRIPT . '?do=user&amp;type=access'), 'Administrator-Rechte eines Benutzers wiederherstellen');
	print_table_break();

	$randnumb = vbrand(0, 100000000);
	print_table_header('Weitere Tools');
	print_column_style_code(array('width:30%'));
	print_label_row(construct_link_code($vbulletin->options['bbactive'] ? 'vBulletin ausschalten' : 'vBulletin einschalten', THIS_SCRIPT . '?do=bbactive'), 'Ihr Forum ist zurzeit <b>' . ($vbulletin->options['bbactive'] ? 'aktiviert' : 'deaktiviert') . '</b>.');
	$childcount = $db->query_first("
		SELECT COUNT(*) AS count
		FROM " . TABLE_PREFIX . "forum
		WHERE childlist = ''
	");
	if ($childcount['count'])
	{
		print_label_row(construct_link_code('Neu erstellen', THIS_SCRIPT . '?do=childlist'), 'Die Liste der Unterforen ist bei einigen Ihrer Foren leer, daher sollten Sie diese Listen neu erstellen.');
	}
	print_label_row(construct_link_code('URL des Forums korrigieren', THIS_SCRIPT . '?do=resetbburl'), 'Wenn Sie sich unter vBulletin 4 nicht anmelden k&ouml;nnen, k&ouml;nnte die URL des Forums falsch sein.<dfn>Aktuell: <strong>' . $vbulletin->options['bburl'] . '</strong></dfn>');
	print_label_row(construct_link_code('Standard-Sprache', THIS_SCRIPT . '?do=language'), 'Standard-Sprache des Forums zur&uuml;cksetzen');
	print_table_break();

	print_table_header('Zeit');
	print_column_style_code(array('width:30%'));
	print_label_row('Systemzeit', $systemdate = date('r T'));
	print_label_row('Ihre Zeit', $userdate = vbdate('r T'));
	print_table_footer();
}
else if ($_REQUEST['do'] == 'xml')
{
	switch ($vbulletin->GPC['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>';

			$startat = $vbulletin->input->clean_gpc('r', 'startat', TYPE_UINT);

			$vbphrase['go_back'] = 'Zur&uuml;ck';
			$vbphrase['template_group_x'] = 'Template-Gruppe: %1$s';

			$tg_perpage = intval($vbulletin->config['Misc']['tg_perpage']);
			if ($tg_perpage > 0 AND $tg_perpage < 31)
			{
				$perpage = $tg_perpage;
			}
			else
			{
				$perpage = 10;
			}

			$imported = xml_import_style($xml, -1, -1, '', false, 1, false, $startat, $perpage);

			if (!$imported['done'])
			{
				//build the next page url;
				$startat = $startat + $perpage;
				$url = 'tools.php?do=xml&type=style&startat=' . $startat;
				print_cp_redirect($url);
			}

			build_all_styles(0, 1);

			print_cp_redirect('tools.php?do=templatemerge');
		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;
		case 'adminhelp':
			require_once('./includes/adminfunctions_help.php');

			if (!($xml = file_read('./install/vbulletin-adminhelp.xml')))
			{
				echo '<p>Oha, ./install/vbulletin-adminhelp.xml scheint nicht vorhanden zu sein! Laden Sie die Datei hoch und aktualisieren Sie diese Seite.</p>';
				print_cp_footer();
			}

			echo '<p>Importiere vbulletin-adminhelp.xml';
			xml_import_help_topics($xml);
			echo '<br /><span class="smallfont"><b>Fertig!</b></span></p>';
		break;
	}
	define('SCRIPT_REDIRECT', true);
}
else if ($_REQUEST['do'] == 'templatemerge')
{
	$vbulletin->input->clean_array_gpc('r', array(
		'startat' => TYPE_UINT,
	));

	require_once(DIR . '/includes/class_template_merge.php');

	$merge_data = new vB_Template_Merge_Data($vbulletin);
	$merge_data->start_offset = $vbulletin->GPC['startat'];
	$merge_data->add_condition("tnewmaster.product IN ('', 'vbulletin')");

	$merge = new vB_Template_Merge($vbulletin);
	$merge->time_limit = 5;
	$completed = $merge->merge_templates($merge_data, $output);

	if ($completed)
	{
		// completed
		build_all_styles();

		define('SCRIPT_REDIRECT', true);
	}
	else
	{
		// more templates to merge
		print_cp_redirect(
			'tools.php?do=templatemerge&startat=' . ($merge_data->start_offset + $merge->fetch_processed_count())
		);
	}
}
else if ($_REQUEST['do'] == 'cache')
{
	switch ($vbulletin->GPC['type'])
	{
		case 'forum':
			build_forum_permissions();
			define('SCRIPT_REDIRECT', true);
		break;
		case 'options':
			build_options();
			define('SCRIPT_REDIRECT', true);
		break;
	}
}
else if ($_REQUEST['do'] == 'cookie')
{
	switch ($vbulletin->GPC['type'])
	{
		case 'domain':
			$db->query_write("
				UPDATE " . TABLE_PREFIX . "setting
				SET value = ''
				WHERE varname = 'cookiedomain'
			");
			build_options();
			define('SCRIPT_REDIRECT', true);
		break;
		case 'path':
			$db->query_write("
				UPDATE " . TABLE_PREFIX . "setting
				SET value = '/'
				WHERE varname = 'cookiepath'
			");
			build_options();
			define('SCRIPT_REDIRECT', true);
		break;
	}
}
else if ($_REQUEST['do'] == 'bitfields')
{
	require_once(DIR . '/includes/class_bitfield_builder.php');
	vB_Bitfield_Builder::save($db);
	build_forum_permissions();
	define('SCRIPT_REDIRECT', true);
}
else if ($_REQUEST['do'] == 'mysql')
{
	$vbulletin->input->clean_array_gpc('p', array('query' => TYPE_STR, 'tables' => TYPE_ARRAY));

	switch ($vbulletin->GPC['type'])
	{
		case 'query':
			if (empty($vbulletin->GPC['query']) OR !preg_match('#^(Alter|Update)#si', $vbulletin->GPC['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->query_write($vbulletin->GPC['query']);
				define('SCRIPT_REDIRECT', true);
			}
			break;
		case 'repair':
			if (empty($vbulletin->GPC['tables']))
			{
				print_form_header('tools', 'mysql');
				construct_hidden_code('type', 'repair');
				print_table_header('Bitte w&auml;hlen Sie die Tabellen aus');
				print_label_row('Tabelle', "<input type=\"checkbox\" name=\"allbox\" title=\"Alle ausw&auml;hlen\" onclick=\"js_check_all(this.form);\" />Alle ausw&auml;hlen", 'thead');
				$result = $db->query_write("SHOW TABLE STATUS");
				while ($currow = $db->fetch_array($result, DBARRAY_NUM))
				{
					if (!in_array(strtolower($currow[1]), array('heap', 'memory')))
					{
						print_checkbox_row($currow[0], "tables[$currow[0]]", 0, 1, 'Ja');
					}
				}
				print_submit_row('Tabellen reparieren', '');
			}
			else
			{
				foreach($vbulletin->GPC['tables'] AS $key => $val)
				{
					if ($val == 1)
					{
						echo "Repariere $key<br />\n";
						flush();
						$db->query_write("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')
{
	$vbulletin->input->clean_array_gpc('p', array('user' => TYPE_STR));

	switch ($vbulletin->GPC['type'])
	{
		case 'access':
		if (empty($vbulletin->GPC['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->query_first("SELECT userid, usergroupid FROM " . TABLE_PREFIX . "user WHERE username = '" . $db->escape_string(htmlspecialchars_uni($vbulletin->GPC['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->query_first("SELECT * FROM " . TABLE_PREFIX . "usergroup WHERE usergroupid = 6 AND (adminpermissions & " . $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'] . ")");
				if (empty($ugroup['usergroupid']))
				{ // lets give them admin permissions again
					$db->query_write("UPDATE " . TABLE_PREFIX . "usergroup SET adminpermissions = 3 WHERE usergroupid = 6");
					build_forum_permissions();
				}
				/*insert query*/
				$db->query_write("REPLACE INTO " . TABLE_PREFIX . "administrator
					(userid, adminpermissions)
				VALUES
					($userid[userid], " . (array_sum($vbulletin->bf_ugp_adminpermissions) - 3) . ")
				");
				$db->query_write("UPDATE " . TABLE_PREFIX . "user SET usergroupid = 6 WHERE userid = $userid[userid]");
				define('SCRIPT_REDIRECT', true);
			}
		}
		break;
	}
}
if ($_REQUEST['do'] == 'childlist')
{
	function construct_child_list($forumid)
	{
		global $db;

		if ($forumid == -1)
		{
			return '-1';
		}

		$childlist = $forumid;

		$children = $db->query_read("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE parentid = " . intval($forumid));
		while ($child = $db->fetch_array($children))
		{
			$childlist .= ',' . $child['forumid'];
		}

		$childlist .= ',-1';

		return $childlist;
	}

	$forums = $db->query_read("SELECT forumid FROM " . TABLE_PREFIX . "forum WHERE childlist = ''");

	$count = 0;
	while ($forum = $db->fetch_array($forums))
	{
		$childlist = construct_child_list($forum['forumid']);
		$db->query_write("
			UPDATE " . TABLE_PREFIX . "forum
			SET childlist = '$childlist'
			WHERE forumid = $forum[forumid]
		");
		$count++;
	}
	build_forum_permissions();
	echo "<p align=\"center\">$count Foren wurden aktualisiert.</p>";
	define('SCRIPT_REDIRECT', true);
}
else if ($_REQUEST['do'] == 'bbactive')
{
	$db->query_write("
		UPDATE " . TABLE_PREFIX . "setting
		SET value = " . ($vbulletin->options['bbactive'] ? 0 : 1) . "
		WHERE varname = 'bbactive'
	");
	build_options();
	define('SCRIPT_REDIRECT', true);
}
else if ($_REQUEST['do'] == 'resetbburl')
{
	$vbulletin->input->clean_array_gpc('p', array('bburl' => TYPE_STR));
	if (empty($vbulletin->GPC['bburl']))
	{
		print_form_header('tools', 'resetbburl');
		print_table_header('Geben Sie hier die URL Ihres Forums an.<br />Hinweis: Achten Sie darauf, dass am Ende der URL kein Slash steht! ("/")');
		print_input_row('URL des Forums', 'bburl', $vbulletin->options['bburl']);
		print_submit_row('Speichern', '');
	}
	else
	{
		$db->query_write("
			UPDATE " . TABLE_PREFIX . "setting
			SET value = '" . $db->escape_string(htmlspecialchars_uni($vbulletin->GPC['bburl'])) . "'
			WHERE varname = 'bburl'
		");
		build_options();
		define('SCRIPT_REDIRECT', true);
	}
}
else if ($_REQUEST['do'] == 'language')
{
	$vbulletin->input->clean_array_gpc('p', array('languageid' => TYPE_UINT));

	require_once(DIR . '/includes/adminfunctions_language.php');

	$languages = $db->query_read('SELECT * FROM ' . TABLE_PREFIX . 'language');
	if ($db->num_rows($languages) == 0)
	{
		// this is just taken from install.php
		$db->query_write("INSERT INTO " . TABLE_PREFIX . "language (title, languagecode, charset, decimalsep, thousandsep) VALUES ('Deutsch (Sie)', 'de', 'ISO-8859-1', ',', '.')");
		$_languageid = $db->insert_id();

		$db->query_write("
			UPDATE " . TABLE_PREFIX . "setting
			SET value = " . $_languageid . "
			WHERE varname = 'languageid'
		");

		$db->query_write("
			UPDATE " . TABLE_PREFIX . "user
			SET languageid = 0
		");
		build_options();
		build_language($_languageid);
		build_language_datastore();
		define('SCRIPT_REDIRECT', true);
	}
	else
	{
		$sellanguages = array();
		while ($language = $db->fetch_array($languages))
		{
			$sellanguages[$language['languageid']] = $language['title'];
		}

		$languageids = implode(',', array_keys($sellanguages));

		$db->query_write("
			UPDATE " . TABLE_PREFIX . "user
			SET languageid = 0
			WHERE languageid NOT IN ($languageids)
		");

		if (empty($vbulletin->GPC['languageid']))
		{
				print_form_header('tools', 'language');
				print_table_header('W&auml;hlen Sie bitte die neue Standard-Sprache');
				print_select_row('Sprache', 'languageid', $sellanguages, $vbulletin->options['languageid']);
				print_submit_row('Speichern', '');
		}
		else
		{
			$db->query_write("
				UPDATE " . TABLE_PREFIX . "setting
				SET value = " . $vbulletin->GPC['languageid'] . "
				WHERE varname = 'languageid'
			");
			build_options();
			build_language($vbulletin->GPC['languageid']);
			build_language_datastore();
			define('SCRIPT_REDIRECT', true);
		}
	}
}

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 = " . (10) . ";
	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" class="smallfont"><a href="http://www.vbulletin-germany.com/" target="_blank" class="copyright">vBulletin <?php echo VERSION; ?>, Copyright &copy;2000-<?php echo date('Y'); ?>, vBulletin Solutions Inc.</a></p>
</body>
</html>
<?php

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 15:31, Sat Oct 29th 2011
|| # CVS: $RCSfile$ - $Revision: 2338 $ 41161
|| ####################################################################
\*======================================================================*/
?>