<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin Hack Management System                                 # ||
|| # ---------------------------------------------------------------- # ||
|| # All PHP code in this file is ©2004 GameCrash.org.                # ||
|| # http://www.gamecrash.org (soon) | http://www.letzplay.de         # ||
|| # ---------------------------------------------------------------- # ||
|| # 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 # ||
|| #################################################################### ||
\*======================================================================*/

// Define some important variables
define('VBHMS_VERSION', '1.0.0 Beta 1');
define('VBHMS_BUILD', 2);
define('VERSION', 'Hack Management System');

// attempt to extend php timeout limit
if (function_exists('set_time_limit') and get_cfg_var('safe_mode') == 0)
{
	@set_time_limit(1200);
}

// disable shutdown functions
define('NOSHUTDOWNFUNC', 1);

// Some phrasegroups we will need
$phrasegroups[] = 'style';

// Use the AdminCP global.php to do the login procedure for us
require_once('../' . vbhms_get_configfile_var('admincpdir', 'admincp') . '/global.php');

// Load all basic functions
require_once('./includes/hackfunctions.php');
require_once('./includes/hackfunctions_xml.php');

require_once('./includes/adminfunctions_template.php');
require_once('./includes/adminfunctions_language.php');
require_once('./includes/functions_xml.php');

// Don't gzip this pages
$nozip = true;
exec_headers();

// Get some basic vars
globalize($_REQUEST, array	(
		'step' => INT,
		'hack' => STR_NOHTML
	));

// Check the vBHMS is installed correctly

$instcheck = false;

if (!(THIS_SCRIPT == 'install.php' && $_REQUEST['hack'] == 'vbhms'))
{
	$DB_site->reporterror = 0;
	$DB_site->errno = 0;
	$instcheck = $DB_site->query_first("SELECT hackversion FROM " . TABLE_PREFIX . "vbhms_hack WHERE hackname='vbhms'");
	$DB_site->reporterror = 1;

	if ($DB_site->errno > 0)
	{
		// If we are using any vBHMS version below Alpha 3 the table is called
		// hack - this has been changed to not collidate with the HTL hack
		$DB_site->reporterror = 0;
		$DB_site->errno = 0;
		$instcheck = $DB_site->query_first("SELECT hackversion FROM " . TABLE_PREFIX . "hack WHERE hackname='vbhms'");
		$DB_site->reporterror = 1;

		if ($DB_site->errno > 0 || $instcheck === false)
		{
			// Okay, we really don't have this hack installed
			header('Location: install.php?hack=vbhms');
			exit;
		}
		
		$DB_site->query("ALTER TABLE " . TABLE_PREFIX . "hack RENAME " . TABLE_PREFIX . "vbhms_hack");
	}
}

if (isset($instcheck['hackversion']) && VBHMS_VERSION != $instcheck['hackversion'] && !(THIS_SCRIPT == 'update.php' && $_REQUEST['hack'] == 'vbhms'))
{
	// The installed version is older than the one installed
	header('Location: update.php?hack=vbhms');
	exit;
}

// Check we have $hack
if (empty($hack) && THIS_SCRIPT != 'index.php')
{
	header('Location: index.php');
	exit;
}

if (THIS_SCRIPT != 'index.php')
{
	// Define the instructionfile XML schema
	$xmlschema = array();
	require_once('./includes/hackfunctions_execute.php');
}

// #################### vbhms_get_configfile_var ####################
// Get any config.php variable without killing the require_once in init.php
// We need this function to find our hackfunctions.php file so we declare it here
function vbhms_get_configfile_var($varname, $defaultvar='')
{
	// Find out where config.php is (did we already chdir(./../)?
	if (is_readable('./includes/config.php'))
	{
		$content = @file('./includes/config.php');
	}
	else
	{
		$content = @file('../includes/config.php');
	}
	
	// If we failed return the default
	if (!is_array($content) || count($content) < 3)
	{
		return $defaultvar;
	}
	
	// Remove the first and last line to get code we can eval
	unset($content[count($content) - 1]);
	unset($content[0]);
	
	// Eval the content to get the variables
	$content = implode('', $content);
	eval($content);
	
	// Return the variable
	return $$varname;
}

?>