<?php

	error_reporting(E_ALL);
	ini_set('display_errors', 1);

	$Conf=GetConfig();
	
	$AdditionalStyling = "";
	
	If (StrToLower($Conf['showlogo']) == "false") {
		$AdditionalStyling .= ".site-logo {display: none;}\n";
	}
	If (IsSet($Conf['sitetitlecolor'])) {
		$AdditionalStyling .= ".SiteTitleLine {color: ".$Conf['sitetitlecolor'].";}\n";
	}
	If (StrToLower($Conf['showsitetitle']) == "false") {
		$AdditionalStyling .= ".SiteTitleLine {display: none;}\n";
	}
	If (StrToLower($Conf['showcomingsoon']) == "false") {
		$AdditionalStyling .= ".ComingSoonLine {display: none;}\n";
	}
	If (StrToLower($Conf['showcooltext']) == "false") {
		$AdditionalStyling .= ".CoolTextLine {display: none;}\n";
	}
	If (StrToLower($Conf['showcatchphrase']) == "false") {
		$AdditionalStyling .= ".CatchPhraseLine {display: none;}\n";
	}
	If (StrToLower($Conf['showphoneno']) == "false") {
		$AdditionalStyling .= ".PhoneNumberLine {display: none;}\n";
	}
	If (StrToLower($Conf['showbackground']) == "false") {
		$AdditionalStyling .= "body {background-image: none;}\n";
	}
	If ($Conf['extracss'] != "") {
		$AdditionalStyling .= $Conf['extracss'];
	}


	$Template = GetHTML(StrToLower($Conf['template']).".html");

	$Template = Str_iReplace("%FontColor%", $Conf['fontcolor'], $Template);
	$Template = Str_iReplace("%BackgroundColor%", $Conf['backgroundcolor'], $Template);
	$Template = Str_iReplace("%ShadowText%", $Conf['shadowtext'], $Template);
	$Template = Str_iReplace("%LogoPath%", $Conf['logopath'], $Template);
	$Template = Str_iReplace("%BackgroundImage%", $Conf['backgroundimage'], $Template);
	$Template = Str_iReplace("%PhoneNoTextColor%", $Conf['phonenotextcolor'], $Template);
	$Template = Str_iReplace("%ComingSoonText%", $Conf['comingsoontext'], $Template);
	$Template = Str_iReplace("%CoolText%", $Conf['cooltext'], $Template);
	$Template = Str_iReplace("%CatchPhraseText%", $Conf['catchphrasetext'], $Template);
	$Template = Str_iReplace("%PhoneNumberIntro%", $Conf['phonenumberintro'], $Template);
	$Template = Str_iReplace("%PhoneNumberText%", $Conf['phonenumbertext'], $Template);
	$Template = Str_iReplace("%PhoneNumberDial%", $Conf['phonenumberdial'], $Template);
	$Template = Str_iReplace("%FontSize%", $Conf['fontsize'], $Template);
	$Template = Str_iReplace("%SiteTitle%", $Conf['sitetitle'], $Template);

	$Template = Str_iReplace("%AdditionalStyling%", $AdditionalStyling, $Template);
#	$Template = Str_iReplace("%%", $Conf[''], $Template);
#	$Template = Str_iReplace("%%", $Conf[''], $Template);

	
	
	Echo $Template;

Function GetConfig($FileName="index.conf") {
	$hFile = FOpen($FileName, "r");
	$Entry = Array();
	$Conf = Array();
	$i = 0;
	While (!FEOF($hFile)):
		$Line_of_Text = FGets($hFile);
		If (Trim($Line_of_Text)!="") {
#			Echo "$Line_of_Text <br />";
			$Entry = Explode("=", $Line_of_Text, 2);
			$Key = Trim(StrToLower($Entry[0]));
			$Conf[$Key] = Trim($Entry[1]);
			If ((SubStr($Conf[$Key], 0, 1) == '"') && (SubStr($Conf[$Key], -1, 1) == '"')) {
				$Conf[$Key] = SubStr($Conf[$Key], 1, StrLen($Conf[$Key])-2);
			}
			If ((SubStr($Conf[$Key], 0, 1) == "'") && (SubStr($Conf[$Key], -1, 1) == "'")) {
				$Conf[$Key] = SubStr($Conf[$Key], 1, StrLen($Conf[$Key])-2);
			}
#			echo "$Entry[0]=$Conf[$Entry[0]]<br />";
			If(!FEOF($hFile)) {
				$i++;
			}
		}
	EndWhile;
	FClose($hFile);
	Return $Conf;
}

Function GetHTML($FileName) {
#> Reads HTML template and returns the data
	$hFile = FOpen($FileName, "r") or die("Unable to open file! - ".$FileName);
	$HTML = FRead($hFile, FileSize($FileName));
	FClose($hFile);
	
	Return $HTML;
}

?>