#!/usr/bin/perl -w
#------------------------------------------------------------------------------
# $Id$
#------------------------------------------------------------------------------
# TeamFile Top page CGI
#
# Copyright (c) BAYBITS LLC. All rights reserved.
#------------------------------------------------------------------------------
use strict;
use utf8;
use Encode;
use TF::CommonUtils;
use HTML::Template;

binmode(STDOUT, ":utf8");

# global
my $LOCATION      = $ENV{'TF_LOCATION'};
my $BRAND         = $ENV{'TF_BRANDNAME'};
my $TF_VERSION    = $ENV{'TF_VERSION'};
my $LANGPARAM     = TF::CommonUtils::getLangPriority();
my $TEMPLATE_FILE = './tmpl/top.tmpl.' . $LANGPARAM;

if (!$LOCATION) {
	TF::CommonUtils::showAccessDeny();
	die '';
}

main();

#
# main
#
sub main {
	&printHTML();
}

#
# sub
#
sub printHTML {

	if (open(TEMPLATE, "<$TEMPLATE_FILE")) {
		binmode(TEMPLATE, ":utf8");
		my $htmltmpl = HTML::Template->new(	filehandle => *TEMPLATE,
											case_sensitive => 1,
											die_on_bad_params => 0);
		if ($htmltmpl) {
			$htmltmpl->param(	brandname => $BRAND,
								tfversion => $TF_VERSION,
								location => $LOCATION,
								);
			print "Content-type: text/html; charset=UTF-8\n\n";
			print $htmltmpl->output;
		}
		close(TEMPLATE);
	}
	else {
		TF::CommonUtils::showTemplateOpenErr($LANGPARAM);
	}
}
