<?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 # ||
|| #################################################################### ||
\*======================================================================*/

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

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'index.php');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array();
$specialtemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

// #############################################################################
// ########################### START MAIN SCRIPT ###############################
// #############################################################################

vbhms_print_header('', 'Hacks Overview', 'Hacks Overview');

vbhms_print_info_line('Welcome to the vBulletin Hack Management System.');
vbhms_print_info_line('Here you can install, update, repair and (if you really want) uninstall hacks supporting this system.');

print_table_start(false, '100%');
print_table_header('Currently installed hacks', 4);
print_cells_row(array('Hack title', 'Hack autor', 'Hack info', 'Actions'), 1, 0, -3);

$installedhacks = $DB_site->query("SELECT * FROM " . TABLE_PREFIX . "vbhms_hack ORDER BY installdate");
while ($installedhack = $DB_site->fetch_array($installedhacks))
{
	$hackinfo = vbhms_import_infofile($installedhack['hackname']);
	
	$title = '<strong>' . $hackinfo['hacktitle']['data'] . '</strong> ' . $installedhack['hackversion'];
	if (!empty($hackinfo['hackurl']['data']))
	{
		$title = '<a href="' . $hackinfo['hackurl']['data'] . '" title="' . $hackinfo['hackdescription']['data'] . '" target="_blank">' . $title . '</a>';
	}
	
	$autor = $hackinfo['autorname']['data'];
	if (!empty($hackinfo['autorurl']['data']))
	{
		$autor = '<a href="' . $hackinfo['autorurl']['data'] . '" target="_blank">' . $autor . '</a>';
	}
	
	$actions = array();
	if (isset($hackinfo['updatefile'][$installedhack['hackversion']]))
	{
		$actions[] = '<a href="update.php?hack=' . $installedhack['hackname'] . '">[Update to ' . $hackinfo['updatefile'][$installedhack['hackversion']]['attrs']['toversion'] . ']</a>';
	}
	if (!empty($hackinfo['repairfile']['data']))
	{
		$actions[] = '<a href="repair.php?hack=' . $installedhack['hackname'] . '">[Repair]</a>';
	}
	if (!empty($hackinfo['uninstallfile']['data']))
	{
		$actions[] = '<a href="uninstall.php?hack=' . $installedhack['hackname'] . '">[Uninstall]</a>';
	}
	
	print_cells_row(array($title, $autor, '<a href="info.php?hack=' . $installedhack['hackname'] . '">[Show details]</a>', implode(' &nbsp; ', $actions)), 0, 0, -3);
	
	$hackisinstalled[$installedhack['hackname']] = true;
}

print_table_footer(4);

print_table_start(true, '100%');
print_table_header('Hacks available for installation', 4);
print_cells_row(array('Hack title', 'Hack autor', 'Hack info', 'Actions'), 1, 0, -3);

$directory = dir('./hacks');
while (false !== ($entry = $directory->read()))
{
	if (!$hackisinstalled[$entry] && is_readable("./hacks/$entry/info.xml"))
	{
		$hackinfo = vbhms_import_infofile($entry);
		
		$title = '<strong>' . $hackinfo['hacktitle']['data'] . '</strong> ' . $hackinfo['hackversion']['data'];
		if (!empty($hackinfo['hackurl']['data']))
		{
			$title = '<a href="' . $hackinfo['hackurl']['data'] . '" title="' . $hackinfo['hackdescription']['data'] . '" target="_blank">' . $title . '</a>';
		}
		
		$autor = $hackinfo['autorname']['data'];
		if (!empty($hackinfo['autorurl']['data']))
		{
			$autor = '<a href="' . $hackinfo['autorurl']['data'] . '" target="_blank">' . $autor . '</a>';
		}
		
		if (!empty($hackinfo['installfile']['data']))
		{
			$actions = '<a href="install.php?hack=' . $entry . '">[Install]</a>';
		}
		
		print_cells_row(array($title, $autor, '<a href="info.php?hack=' . $entry . '">[Show details]</a>', $actions), 0, 0, -3);
	}
}

print_table_footer(4);

vbhms_print_footer(false);

?>