<?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('style');
$specialtemplates = array();

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

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

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

if (!vbhosting_haspermission('managestyles'))
{
	print_cp_no_permission();
}

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

if ($_REQUEST['do'] == 'update')
{
	$nozip = true;
}

print_cp_header($vbphrase['vbhosting_edit_colors'], iif($_REQUEST['do'] == 'modify' || $_REQUEST['do'] == 'showdefault', 'init_color_preview()'));

echo '<script type="text/javascript" src="../clientscript/vbulletin_cpcolorpicker.js"></script>';

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

if ($_POST['do'] == 'update')
{
	globalize($_POST, array(
		'css',
		'delete'
	));

	$style = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "style WHERE styleid = $dostyleid");
	$templateids = implode(',', unserialize($style['templatelist']));
	$templates = $DB_site->query("
		SELECT templateid, title, template, template_un, styleid, templatetype
		FROM " . TABLE_PREFIX . "template
		WHERE templateid IN($templateids)
		AND templatetype = 'css'
		");

	$templatecache = array();
	while ($template = $DB_site->fetch_array($templates))
	{
		$templatecache["$template[templatetype]"]["$template[title]"] = $template;
	}

	build_special_templates($css, 'css', 'css');

	vbhosting_quiet_build_style($dostyleid, '', array('docss' => 1, 'dostylevars' => 0, 'doreplacements' => 0, 'doposteditor' => 0));

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

if ($_REQUEST['do'] == 'modify')
{
	cache_styles();
	
	$templatelist = unserialize($stylecache["$dostyleid"]['templatelist']);
	$templates = $DB_site->query("SELECT title, template, styleid FROM " . TABLE_PREFIX . "template WHERE templateid IN (" . implode(',', $templatelist) . ") AND templatetype='css'");
	
	$css = array();
	$css_info = array();
	while($template = $DB_site->fetch_array($templates))
	{
		$css["{$template['title']}"] = unserialize($template['template']);
		if ($template['styleid'] == $dostyleid)
		{
			$css_info["{$template['title']}"] = $dostyleid;
		}
		else
		{
			$css_info["{$template['title']}"] = -1;
		}
	}
	
	print_form_header('color', 'update');
	construct_hidden_code('hostedid', $hostedid);
	
	print_description_row($vbphrase['vbhosting_color_editor_description']);
	print_table_break();
	
	print_css_row($vbphrase['body'], $vbphrase['body_desc'], 'body', 1);
	print_css_row($vbphrase['page_background'], $vbphrase['page_background_desc'], '.page', 1);
	print_css_row('<td>, <th>, <p>, <li>', $vbphrase['text_desc'], 'td, th, p, li', 0);
	print_css_row($vbphrase['table_border'], $vbphrase['table_border_desc'], '.tborder', 0);
	print_css_row($vbphrase['category_strips'], $vbphrase['category_strips_desc'], '.tcat', 1);
	print_css_row($vbphrase['table_header'], $vbphrase['table_header_desc'], '.thead', 1);
	print_css_row($vbphrase['table_footer'], $vbphrase['table_footer_desc'], '.tfoot', 1);
	print_css_row($vbphrase['first_alternating_color'], $vbphrase['first_alternating_color_desc'], '.alt1, .alt1Active', 1);
	print_css_row($vbphrase['second_alternating_color'], $vbphrase['second_alternating_color_desc'], '.alt2, .alt2Active', 1);
	print_css_row(construct_phrase($vbphrase['wysiwyg_editor_style'], $vbphrase['second_alternating_color'], $vbphrase['input_fields']), $vbphrase['wysiwyg_editor_style_desc'], '.wysiwyg', 1);
	print_css_row($vbphrase['input_fields'], $vbphrase['input_fields_desc'], 'textarea, .bginput', 0);
	print_css_row($vbphrase['buttons'], $vbphrase['buttons_desc'], '.button', 0);
	print_css_row($vbphrase['menus'], $vbphrase['menus_desc'], 'select', 0);
	print_css_row($vbphrase['small_font'], $vbphrase['small_font_desc'], '.smallfont', 0);
	print_css_row($vbphrase['time_color'], $vbphrase['time_color_desc'], '.time', 0);
	print_css_row($vbphrase['navbar_text'], $vbphrase['navbar_text_desc'], '.navbar', 1);
	print_css_row($vbphrase['highlighted_font'], $vbphrase['highlighted_font_desc'], '.highlight', 0);
	print_css_row($vbphrase['panel_surround'], $vbphrase['panel_surround_desc'], '.panelsurround', 0);
	print_css_row($vbphrase['panel'], $vbphrase['panel_desc'], '.panel', 1);
	print_css_row('<legend>', $vbphrase['legend_desc'], 'legend', 0);
	print_css_row($vbphrase['popup_menu_control'], $vbphrase['popup_menu_control_desc'], '.vbmenu_control', 1);
	print_css_row($vbphrase['popup_menu_body'], $vbphrase['popup_menu_body_desc'], '.vbmenu_popup', 0);
	print_css_row($vbphrase['popup_menu_option'], $vbphrase['popup_menu_option_desc'], '.vbmenu_option', 1);
	print_css_row($vbphrase['popup_menu_hilite'], $vbphrase['popup_menu_hilite_desc'], '.vbmenu_hilite', 1);

	print_table_footer(2, '
		<input type="submit" class="button" value="' . $vbphrase['save'] . '" accesskey="s" tabindex="1" />
		<input type="reset" class="button" value="' . $vbphrase['reset'] . '" accesskey="r" tabindex="1" onclick="this.form.reset(); init_color_preview(); return false;" />
	');
	
	echo construct_color_picker();
	
	echo '<script type="text/javascript">
	<!--
	function js_show_default_item(url, dolinks)
	{
		gotourl = "color.php?s=' .  $session['sessionhash'] . '&amp;hostedid=' . $hostedid . '&amp;do=showdefault&amp;dolinks=" + dolinks + "&amp;" + url;
		if (dolinks==1)
		{
			wheight = 510;
		}
		else
		{
			wheight = 400;
		}
		window.open(gotourl, \'showdefault\', \'resizable=yes,width=700,height=\' + wheight);
	}

	var bburl = "' . $vboptions['bburl'] . '/";
	var cpstylefolder = "' . $vboptions['cpstylefolder'] . '";
	var numColors = ' . intval($numcolors) . ';
	var colorPickerWidth = ' . intval($colorPickerWidth) . ';
	var colorPickerType = ' . intval($colorPickerType) . ';
	var vbphrase = {
		"css_value_invalid" : "' . $vbphrase['css_value_invalid'] . '",
		"color_picker_not_ready" : "' . $vbphrase['color_picker_not_ready'] . '"
	};

	//-->
	</script>';
}

if ($_REQUEST['do'] == 'showdefault')
{
	globalize($_REQUEST, array('title', 'item', 'dolinks'));

	$dostyleid = $vboptions['vbhosting_create_parentstyle'];

	cache_styles();
	
	$templatelist = unserialize($stylecache["$dostyleid"]['templatelist']);
	$template = $DB_site->query_first("SELECT title, template, styleid FROM " . TABLE_PREFIX . "template WHERE templateid IN (" . implode(',', $templatelist) . ") AND title='" . addslashes($item) . "' AND templatetype='css'");
	
	$css = array();
	$css_info = array();
	$css["{$template['title']}"] = unserialize($template['template']);
	$css_info["{$template['title']}"] = -1;
	
	$readonly = 1;
	
	print_form_header('color', 'update');
	construct_hidden_code('hostedid', $hostedid);
	print_css_row($title, '', $item, $dolinks);
	print_table_footer(2, '<input type="button" class="button" value="' . $vbphrase['close'] . '" onclick="self.close();" tabindex="1" />');
	
	echo construct_color_picker();

	echo '<script type="text/javascript">
	<!--

	var bburl = "' . $vboptions['bburl'] . '/";
	var cpstylefolder = "' . $vboptions['cpstylefolder'] . '";
	var numColors = ' . intval($numcolors) . ';
	var colorPickerWidth = ' . intval($colorPickerWidth) . ';
	var colorPickerType = ' . intval($colorPickerType) . ';
	var vbphrase = {
		"css_value_invalid" : "' . $vbphrase['css_value_invalid'] . '",
		"color_picker_not_ready" : "' . $vbphrase['color_picker_not_ready'] . '"
	};

	//-->
	</script>';
}

print_cp_footer();

?>