#!/usr/local/bin/perl

$time_miss=16;
$expDate = "Sunday, 31-Dec-2000 00:00:00 GMT";
$domain = ".como.com.tw";
$path = "/cgi-bin/"; 
%data = &get_data();
($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time);                       #SERVER¦b°ê¤º
$monn=$monn+1;
if ($monn<10)  {$monn="0$monn";}
if ($dayn<10)  {$dayn="0$dayn";}
if ($hourn<10) {$hourn="0$hourn";}
if ($minn<10)  {$minn="0$minn";}
if ($secn<10)  {$secn="0$secn";}

#y2k correction from here
##################################################
$yearn+=1900;
#end of y2k correction
##################################################
#end of y2k correction
##################################################

$timen="$yearn/$monn/$dayn($hourn\:$minn\:$secn)";
$timew="$yearn$monn$dayn";
$no   =$timen;
$no   =~ s/\/|\(|\)|\://g;
$chktime=substr($no,0,10);
$chktimemore=substr($no,0,8);
$timeo="$yearn/$monn/$dayn($hourn\:$minn\:$secn)";
##################################################
$kvv="$data{'aguser'}:$timew";
#&setCookie("$data{'user'}", "$kvv", $expDate, $path, $domain);
$confirm1=substr($data{'aguser'},0,1);
$confirm2=substr($data{'aguser'},1,5);

##################################################
if ($confirm1 eq 'i') {$where="index_ag.cgi";}
if ($confirm1 eq 't') {$where="ticket_ag.cgi";}
if ($confirm1 eq 'g') {$where="group_ag.cgi";}
if ($confirm1 eq 'h') {$where="hotel_agent.cgi";}
if ($confirm1 eq 'p') {$where="package_ag.cgi";}

do "$where";
#eval("$where");

##################################################
#Get Cookie
##################################################
sub setCookie {
        # end a set-cookie header with the word secure and the cookie will only
        # be sent through secure connections
        local($name, $value, $expiration, $path, $domain, $secure) = @_;

        print "Set-Cookie: ";
        print ($name, "=", $value, "; expires=", $expiration,
                "; path=", $path, "; domain=", $domain, "; ", $secure, "\n");
}
sub get_data {
    local($string);

    # get data
    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
        $string = $ENV{'QUERY_STRING'};
    }				
    else { read(STDIN, $string, $ENV{'CONTENT_LENGTH'}); }

    # split data into name=value pairs
    @data = split(/&/, $string);
   
    # split into name=value pairs in associative array
    foreach (@data) {
	split(/=/, $_);
	$_[0] =~ s/\+/ /g; # plus to space
        $_[0] =~ s/%0D%0A%0D%0A/\n\n/g; #added by kristina make newlines?
        $_[0] =~ s/%0a/newline/g;
#        $_[0] =~ s/\%0D\%0A/\n/g;
	$_[0] =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric
	if(defined($data{$_[0]})){ 
	   $data{$_[0]} .= "\0";
	   $data{$_[0]} .= "$_[1]";
	   }
	else {
	$data{"$_[0]"} = $_[1];
	  }
    }
    # translate special characters
    foreach (keys %data) {
	$data{"$_"} =~ s/\+/ /g; # plus to space
	$data{"$_"} =~ s/%(..)/pack("c", hex($1))/ge; # hex to alphanumeric
    }

    %data;			# return associative array of name=value
}


