<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBHosting Version 2                                              # ||
|| # ---------------------------------------------------------------- # ||
|| # 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);

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

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

// ############################# LOG ACTION ###############################
vbhosting_log();

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

if (!vbhosting_haspermission('managestyles') || !$vboptions['vbhosting_general_allowheaderfooter'])
{
	print_cp_no_permission();
}

if (empty($_REQUEST['do']))
{
	$_REQUEST['do'] = 'modify';
}

print_cp_header($vbphrase['vbhosting_header_and_footer']);

$dostyleid = $DB_site->query_first("SELECT styleid FROM " . TABLE_PREFIX . "vbhosting_hosted WHERE hostedid={$hostedid}");
$dostyleid = $dostyleid['styleid'];

if ($_REQUEST['do'] == 'modify')
{
	$header = $DB_site->query_first("SELECT template FROM " . TABLE_PREFIX . "template WHERE title='{headerinclude}' AND templatetype='replacement' AND styleid={$dostyleid}");
	$header = $header['template'];
	$footer = $DB_site->query_first("SELECT template FROM " . TABLE_PREFIX . "template WHERE title='{footerinclude}' AND templatetype='replacement' AND styleid={$dostyleid}");
	$footer = $footer['template'];
	
	print_form_header('headerandfooter', 'update');
	construct_hidden_code('hostedid', $hostedid);
	print_table_header($vbphrase['vbhosting_edit_header_and_footer']);
	
	print_description_row($vbphrase['vbhosting_header_and_footer_description']);
	print_textarea_row($vbphrase['vbhosting_header'], 'header', $header, 10, 80, 1, 0);
	print_textarea_row($vbphrase['vbhosting_footer'], 'footer', $footer, 10, 80, 1, 0);
	
	print_submit_row();
	print_table_footer();
	
}

if ($_REQUEST['do'] == 'update')
{
	globalize($_REQUEST, array(
		'header' => STR,
		'footer' => STR
	));
	
	if (!empty($header))
	{
		$DB_site->query("REPLACE INTO " . TABLE_PREFIX . "template (styleid, title, template, templatetype, dateline, username) VALUES ({$dostyleid}, '{headerinclude}', '" . addslashes($header) . "', 'replacement', " . TIMENOW . ", '" . addslashes($bbuserinfo['username']) . "')");
	}
	else
	{
		$DB_site->query("DELETE FROM " . TABLE_PREFIX . "template WHERE title='{headerinclude}' AND templatetype='replacement' AND styleid={$dostyleid}");
	}
	
	if (!empty($footer))
	{
		$DB_site->query("REPLACE INTO " . TABLE_PREFIX . "template (styleid, title, template, templatetype, dateline, username) VALUES ({$dostyleid}, '{footerinclude}', '" . addslashes($footer) . "', 'replacement', " . TIMENOW . ", '" . addslashes($bbuserinfo['username']) . "')");
	}
	else
	{
		$DB_site->query("DELETE FROM " . TABLE_PREFIX . "template WHERE title='{footerinclude}' AND templatetype='replacement' AND styleid={$dostyleid}");
	}
	
	vbhosting_quiet_build_style($dostyleid, '', array('docss' => 0, 'dostylevars' => 0, 'doreplacements' => 1, 'doposteditor' => 0));

	print_cp_message($vbphrase['vbhosting_header_and_footer_have_been_updated'], "headerandfooter.php?hostedid={$hostedid}&do=modify");
}

?>