#!/usr/bin/perl5 -w
# ´Á»ú¥³¡¼¥É EUC

#
use CGI::Carp qw(carpout fatalsToBrowser);
use SIC;
use SICX::Commander::Unit;
use Cycom::Util::Server;
#
my $comm = SICX::Commander::Unit->new();
my $cgi = $comm->{cgi};
my $siteid = $cgi->param('siteid');
my $areaid = $cgi->param('areaid');
my $unitid = $cgi->param('unitid');

exit if &RedirectUnit($siteid, $areaid, $unitid);
exit if &checkBusy();


#$comm->{sess}->set_config(
#    filedir => '/home/SIC/tmp/sess',
#    expires => '+1y',
#    path => '/',
#    domain => 'data.shop-info.com'
#);
if ( $siteid and $areaid and $unitid ){
	if ( $siteid eq 'arida' ){
		print $comm->{cgi}->redirect( sprintf qq{http://www.konomise.com/cgi/units/index.cgi?siteid=%s&areaid=%s&unitid=%s}, $siteid, $areaid, $unitid);
		exit;
	}
}

unless ($comm->start('SICX::Proc::Unit::index')) {
    $comm->error();
}

#
$comm->finish();

#
exit(0);

__END__


sub RedirectUnit {
	my ( $siteid, $areaid, $unitid ) = @_;

	my %hostname = (
		'kunitachi'=>'kunitachi.shop-info.com',
		'chofu'=>'chofu.com',
		'nishitokyo'=>'nishitokyo.shop-info.com',
		'kokubunji'=>'kokubunji.shop-info.com',
		'tachikawa'=>'www.annex-tachikawa.com'
	);

	my ( $hostname, $location );

	if ( $siteid =~ /^(kunitachi|chofu|nishitokyo|kokubunji|tachikawa)$/ ){
		$hostname = $hostname{$siteid};
		my $path = sprintf qq{/home/sites/%s/web}, $hostname;
		if ( -e "$path/$unitid" ){
			$location = sprintf("http://%s/%s/", $hostname, $unitid);
		} elsif ( -e "$path/units/$areaid/$unitid" ){
			$location = sprintf("http://%s/units/%s/%s/", $hostname, $areaid, $unitid);
		}
		printf "Location: %s\n\n", $location;
		return 1;
	}
	return 0;
}