<?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('managesettings'))
{
	print_cp_no_permission();
}

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

print_cp_header($vbphrase['vbhosting_edit_settings']);

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

if ($_REQUEST['do'] == 'update')
{
	globalize($_REQUEST, array(
		'websitetitle' => STR,
		'websiteurl' => STR,
		'websitelogo' => STR
	));
	
	$remove = array();
	$insert = array();
	
	if (empty($websitetitle))
	{
		$remove[] = "(templatetype='replacement' AND title='{hostedsitename}')";
	}
	else
	{
		$insert[] = "({$dostyleid}, '{hostedsitename}', '" . addslashes(htmlspecialchars_uni($websitetitle)) . "', 'replacement', " . TIMENOW . ", '" . addslashes($bbuserinfo['username']) . "')";
	}
	
	if (empty($websiteurl))
	{
		$remove[] = "(templatetype='replacement' AND title='{hostedsiteurl}')";
	}
	else
	{
		$insert[] = "({$dostyleid}, '{hostedsiteurl}', '" . addslashes(htmlspecialchars_uni($websiteurl)) . "', 'replacement', " . TIMENOW . ", '" . addslashes($bbuserinfo['username']) . "')";
	}
	
	if (empty($websitelogo))
	{
		$remove[] = "(templatetype='stylevar' AND title='titleimage')";
	}
	else
	{
		$insert[] = "({$dostyleid}, 'titleimage', '" . addslashes(htmlspecialchars_uni($websitelogo)) . "', 'stylevar', " . TIMENOW . ", '" . addslashes($bbuserinfo['username']) . "')";
	}
	
	if (count($remove) > 0)
	{
		$DB_site->query("DELETE FROM " . TABLE_PREFIX . "template WHERE " . implode(' OR ', $remove));
	}
	
	if (count($insert) > 0)
	{
		$DB_site->query("REPLACE INTO " . TABLE_PREFIX . "template (styleid, title, template, templatetype, dateline, username) VALUES " . implode(', ', $insert));
	}
	
	vbhosting_quiet_build_style($dostyleid, '', array('docss' => 0, 'dostylevars' => 1, 'doreplacements' => 1, 'doposteditor' => 0));
	
	print_cp_message(construct_phrase($vbphrase['vbhosting_settings_updated_successfully'], $username), "setting.php?hostedid={$hostedid}&do=modify");
}

if ($_REQUEST['do'] == 'modify')
{
	$current = array();
	$currents = $DB_site->query("SELECT title, template FROM " . TABLE_PREFIX . "template WHERE styleid={$dostyleid} AND (templatetype='replacement' OR templatetype='stylevar')");
	while($item = $DB_site->fetch_array($currents))
	{
		$current["{$item['title']}"] = $item['template'];
	}

	print_form_header('setting', 'update');
	construct_hidden_code('hostedid', $hostedid);
	print_table_header($vbphrase['vbhosting_website_settings']);
	print_input_row($vbphrase['vbhosting_website_title'], 'websitetitle', $current['{hostedsitename}']);
	print_input_row($vbphrase['vbhosting_website_url'], 'websiteurl', $current['{hostedsiteurl}']);
	print_input_row($vbphrase['vbhosting_website_logo'], 'websitelogo', $current['titleimage']);
	print_submit_row();
	print_table_footer();
}

print_cp_footer();

?>