#!/usr/local/bin/perl

#$cgiurl="http://202.145.173.3:1000/cgi-bin/hotel.cgi"; 
#$cgiurl="http://comoo.com/cgi-bin/login.cgi"; 
$cgiurl="/cgi-bin/hotel.cgi"; 
$serverpath="/home/comoman/httpd/htdocs";
$datapath="$serverpath/../database";

$uploadpath="$serverpath/../upload";

$vdata     ="$serverpath/hvdata/setup.conf";
$filehead  =  "$datapath/hdata/";
$pagehead  ="$serverpath/hpage/";
$backuphead="$serverpath/hbackup/";
#$time_miss=8;
$expDate = "Sunday, 31-Dec-2000 00:00:00 GMT";
$domain = ".como.com.tw";
$path = "/cgi-bin/"; 

##################################################
#read Var From Disk
#################################################

open (SETMYVAR,"$vdata");
while (<SETMYVAR>)
    {
	$_ =~ s/\r//g;	
    $_ =~ s/^\s+//g;
    $_ =~ s/\s+$//g;
	($myvarname,$mynamevalue) = split (/\=/, $_);
	$$myvarname="$mynamevalue";
	}
close (SETMYVAR);
##################################################
#Page Setup
################################################## Member DBM
$hcidname			="HOTELCIDNAME";		#國家簡稱-->國家英文全名
$hcityidname		="HOTELCITYIDNAME";		#城市簡稱-->城市英文全名
$hcityidcname		="HOTELCITYIDCNAME";	#城市簡稱-->城市中文全名
$hcitybelong		="HOTELCITYBELONG";		#城市簡稱-->城市規屬國名簡稱

$hotelbelong		="HOTELBELONG";			#酒店案號-->酒店規屬城市
$hotelbelong2		="HOTELBELONG2";		#酒店案號-->酒店規屬國家
$hotelbelong3		="HOTELBELONG3";		#酒店案號-->規屬酒店代號

$hotelidname		="HOTELIDNAME";			#酒店代號-->酒店英文名稱

$hotelidclass		="HOTELIDCLASS";		#酒店代號-->酒店等級
$hotelidp01			="HOTELIDP01";			#酒店代號-->單人價格
$hotelidp02			="HOTELIDP02";			#酒店代號-->雙人價格
$hotelmeno			="HOTELIDMENO";			#酒店代號-->備註

$lastlogindatefile  ="LASTLOGINDATE";		#代號-->最後使用時間----------
$lastloginipfile    ="LASTLOGINIP";			#代號-->最後使用IP------------

$horder_belong	  ="HORDERBELONG";			#訂單號-->會員編號
$horder_no		  ="HORDERNO";				#訂單號-->資料編號
$horder_date	  ="HORDERDATE";			#訂單號-->訂單日期
$horder_amout	  ="HORDERAMOUT";			#訂單號-->數量
$horder_cash	  ="HORDERCASH";			#訂單號-->總金額
$horder_passname  ="HORDERPNAME";			#訂單號-->旅客中英文姓名(共2格)
$horder_outback	  ="HORDEROUTBACK";			#訂單號-->Checkin
$horder_room	  ="HORDERROOM";			#訂單號-->簽證備註
$horder_visa	  ="HORDERVISA";			#訂單號-->簽證備註
$horder_ticket	  ="HORDERHOTEL";			#訂單號-->訂房備註
$horder_gift	  ="HORDERGIF";				#訂單號-->贈品
$horder_fno		  ="HORDERFNO";				#訂單號-->飛航編號
$horder_outback2  ="HORDEROUTBACK2";		#訂單號-->Checkout
$horder_follow	  ="HORDERFOLLOW";			#訂單號-->隨行人員
$horder_amout2	  ="HORDERAMOUT2";			#訂單號-->間數




##################################################
#Page Setup
##################################################
$errorpage					="error.htm"; 
$succpage					="succpage.htm"; 
$newpage					="mlogin.htm";
$userfirst					="userfirst.htm";
$doagainpage				="doagain.htm";
$joinsuccpage				="joinsucc.htm";
$profilepage				="profile.htm";
$profile2page				="profile2.htm";
$loginpage					="login.htm";
$m001page					="m001.htm";     # hotel master page for ID & password
$hotelfirst					="hfirst.htm";
$masterpasspage				="mpage.htm";
$cpassok					="cpassok.htm";
$hm001page					="hm001.htm";
$hm002page					="hm002.htm";
$hm002zpage					="hm002z.htm";
$hm003apage					="hm003a.htm";
$hm003bapage				="hm003ba.htm";
$hm003bbpage				="hm003bb.htm";
$hm003bcpage				="hm003bc.htm";
$hm003bdpage				="hm003bd.htm";

$hm003capage				="hm003ca.htm";
$hm003cbpage				="hm003cb.htm";
$hm003ccpage				="hm003cc.htm";
$hm004page					="hm004.htm";
$hsecondpage				="hsecond.htm";

$modifypage					="hmodify.htm";
$regpage					="order.htm";
$ccpage						="cc.htm";
$dailypage					="daily.htm";

##################################################
#Main Program
##################################################
print "Content-type: text/html\n\n";

@querys = split(/&/, $ENV{'QUERY_STRING'});
foreach (@querys) {($name,$value)=split(/=/, $_); &setv($name,$value);}

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach (@pairs) {($name,$value)=split(/=/, $_); &setv($name,$value);}

$V{'id'}         =~ s/\n|∥|"|<|>|\&|;| |\?|\.|\|//g;
$V{'password'}   =~ s/\n|∥|"|<|>|\&|;| |\?|\.|\|//g;
$V{'oldpassword'}=~ s/\n|∥|"|<|>|\&|;| |\?|\.|\|//g;

$V{'email'}="" if ($V{'email'} !~ /(.*)\@(.*)\.(.*)/);
$V{'newemail'}="" if ($V{'newemail'} !~ /(.*)\@(.*)\.(.*)/);

$ip=$ENV{'REMOTE_ADDR'};

#($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time+(3600*$time_miss));    #SERVER在國外之時間修正
($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time);                       #SERVER在國內

$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);
$ticketchktime=substr($no,0,8);
################################################################
# Count Limit Days
################################################################
($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time+(3600*$time_miss)+($limitdays*24*3600));
$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
##################################################
$oldsign=19;
if (($yearn != 99) && ($yearn > 99)) {
$yearntest=$yearn-100;
$yearn=2000+$yearntest;
}
if ($yearn == 99) {
$yearn="$oldsign$yearn";
}
#end of y2k correction
$timeo="$yearn/$monn/$dayn($hourn\:$minn\:$secn)";
##################################################
if ($V{'name'}) {
if (length($V{'name'})>20)			{&doagain("姓名長度不得超過 10 個中文字!");} 
if (length($V{'name'})<2)			{&doagain("姓名長度不得小於 1 個中文字!");}
}
if ($V{'id'}) {
if (length($V{'id'})>20)			{&doagain("使用代號長度不得超過 20 個字!");} 
if (length($V{'id'})<=1)			{&doagain("使用代號長度不得小於 2 個字!");}
}
if ($V{'password'}) {
if (length($V{'password'})>10)		{&doagain("密碼長度不得超過10!");} 
if (length($V{'password'})<2)		{&doagain("密碼長度不得小於2!");} 
}
if ($V{'email'}) {
if ($V{'email'}!~m/\@/)				{&doagain("錯誤的郵件地址 !");} 
if ($V{'email'}!~m/\./)				{&doagain("錯誤的郵件地址 !");} 
}
if ($V{'newemail'}) {
if ($V{'newemail'}!~m/\@/)			{&doagain("錯誤的郵件地址 !");} 
if ($V{'newemail'}!~m/\./)			{&doagain("錯誤的郵件地址 !");} 
}
##################################################
#General CGI Code
##################################################

	if ($V{'ac'} eq "master")				    {do 'master.cgi';					&master;}
	elsif ($V{'ac'} eq "m02")				    {do 'master2.cgi';					&master;}
	elsif ($V{'ac'} eq "cs")				    {do 'clist.cgi';					&clist;}
	elsif ($V{'ac'} eq "ccs")				    {do 'cclist.cgi';					&clist;}
	elsif ($V{'ac'} eq "show")				    {do 'hlist.cgi';					&hlist;}
	elsif ($V{'ac'} eq "show2")				    {do 'hlist2.cgi';					&hlist;}
	elsif ($V{'ac'} eq "show3")				    {do 'hlist3.cgi';					&hlist;}

	elsif ($V{'ac'} eq "test")				    {do 'hoteltest.cgi';				&test;}
	elsif ($V{'ac'} eq "")						{do 'hotelstand.cgi';				&stand;}
	elsif ($V{'ac'} eq "mc")					{do 'hotelmc.cgi';					&mc;}
	elsif ($V{'ac'} eq "cpass")					{do 'hotelcpass.cgi';				&cpass;}
	elsif ($V{'ac'} eq "hm001")					{do 'hm001.cgi';					&hm001;}
	elsif ($V{'ac'} eq "hm0012")				{do 'hm0012.cgi';					&hm0012;}
	elsif ($V{'ac'} eq "hm002")					{do 'hm002.cgi';					&hm002;}
	elsif ($V{'ac'} eq "hm0022")				{do 'hm0022.cgi';					&hm0022;}
	elsif ($V{'ac'} eq "hm002z")				{do 'hm002z.cgi';					&hm002z;}
	elsif ($V{'ac'} eq "hm0022z")				{do 'hm0022z.cgi';					&hm0022z;}
	elsif ($V{'ac'} eq "hm003")					{do 'hm003.cgi';					&clist;}
	elsif ($V{'ac'} eq "hm0031")				{do 'hm0031.cgi';					&clist;}
	elsif ($V{'ac'} eq "hm003a")				{do 'hm003a.cgi';					&hm003a;}
	elsif ($V{'ac'} eq "hm003a2")				{do 'hm003a2.cgi';					&hm003a2;}
	elsif ($V{'ac'} eq "hm003b")				{do 'hm003b.cgi';					&hm003b;}
	elsif ($V{'ac'} eq "hm003ba")				{do 'hm003ba.cgi';					&hm003ba;}
	elsif ($V{'ac'} eq "hm003bb")				{do 'hm003bb.cgi';					&hm003bb;}
	elsif ($V{'ac'} eq "hm003bc")				{do 'hm003bc.cgi';					&hm003bc;}
	elsif ($V{'ac'} eq "hm003bd")				{do 'hm003bd.cgi';					&hm003bd;}

	elsif ($V{'ac'} eq "hm003c")				{do 'hm003c.cgi';					&hm003c;}
	elsif ($V{'ac'} eq "hm003ca")				{do 'hm003ca.cgi';					&hm003ca;}
	elsif ($V{'ac'} eq "hm003cb")				{do 'hm003cb.cgi';					&hm003cb;}
	elsif ($V{'ac'} eq "hm003cc")				{do 'hm003cc.cgi';					&hm003cc;}
	elsif ($V{'ac'} eq "hm003cda")				{do 'hm003cda.cgi';					&hm003cda;}


	elsif ($V{'ac'} eq "hm004")					{do 'hm004.cgi';					&master;}
	elsif ($V{'ac'} eq "hm0041")				{do 'hm0041.cgi';					&hlist;}


	elsif ($V{'ac'} eq "datamodify")			{do 'hm0032.cgi';					&modify;}
	elsif ($V{'ac'} eq "datamodify2")			{do 'hm0033.cgi';					&modify;}
	elsif ($V{'ac'} eq "datadel")				{do 'hm003cda1.cgi';				&hm003cda1;}
	elsif ($V{'ac'} eq "hotellist")				{do 'hotellist.cgi';				&hlist;}
	elsif ($V{'ac'} eq "reg")					{do 'hreg.cgi';						&reg;}
	elsif ($V{'ac'} eq "hmore")					{do 'hlistmore.cgi';				&hlist;}
	elsif ($V{'ac'} eq "ref")					{do 'href.cgi';						&reg;}
	elsif ($V{'ac'} eq "cc")					{do 'hcc.cgi';						&cc;}
	elsif ($V{'ac'} eq "daily")					{do 'hdaily1.cgi';					&daily;}
	elsif ($V{'ac'} eq "daily2")				{do 'hdaily.cgi';					&daily;}
	elsif ($V{'ac'} eq "daily3")				{do 'hdaily3.cgi';					&daily;}
	elsif ($V{'ac'} eq "hreport1")				{do 'hreport1.cgi';					&report;}
	elsif ($V{'ac'} eq "hreport2")				{do 'hreport2.cgi';					&report;}




exit 0;

##################################################
#Read Input
##################################################

sub setv {
$_[1]=~ tr/+/ /;
$_[1]=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$_[1]=~ s/<!--(.|\n)*-->//g;
if ($allow_html != 1) {
   $_[1] =~ s/<([^>]|\n)*>//g;
   $_[1] =~ s/<//g;
}
$_[1]=~ s/\n|∥|\'//g;
if ($V{$_[0]}) {$V{$_[0]}="$V{$_[0]}§$_[1]";} else {$V{$_[0]}=$_[1];}
}


sub homelinks{
  if ($V{'aguser'}) {$tempage1="hall".'_link.htm';
	$outputpage1="$pagehead".'aguser/all/'."$tempage1";  
	@linkpage=&readtxtfile("$outputpage1");
        foreach (@linkpage) {
        $_ =~ s/\$aguser/$aguser/g;	
        $_ =~ s/\$htmlfoot/$htmlfoot/g;
        
        print;
	}
  }
}



sub footdis{
$footer="/home/comoman/httpd/htdocs/page/footer.txt";
open(FOOTER, "$footer") or die "can't open : $!";
local($/) = undef;
$foodis = <FOOTER>;
close FOOTER;
}

sub newsdis{
$news="/home/comoman/httpd/htdocs/page/news.txt";
open(N_EWS, "$news") or die "can't open : $!";
local($/) = undef;
$n_ews = <N_EWS>;
$n_ews =~ s/\r/<br>/g;
$n_ews =~ s/\n/<br>/g;

close N_EWS;
}

##################################################
#Get Cookie
##################################################
sub getCookies {
        # cookies are seperated by a semicolon and a space, this will split
        # them and return a hash of cookies
        local(@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
        local(%cookies);

        foreach(@rawCookies){
        if(/mycomo/i){
		#if(/youemail/i){
            ($key, $val) = split (/=/,$_);
            $cookies{$key} = $val;
            #$cookies{myemail} = $myval;
      ($id,$ltime,$o1,$o2,$o3,$o4,$s) = split (/\:/, $val);
}
        } 

        return %cookies; 
} 

##################################################
#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");
}




##################################################
#Readtxtfile
##################################################
sub readtxtfile {
open(READTXTFILE,"$_[0]");
@readtxtfile=<READTXTFILE>;
close(READTXTFILE);
return @readtxtfile;
}
##################################################
#Readtxtline
##################################################
sub readtxtline {
open(READTXTFILE,"$_[0]");
$readtxtline=<READTXTFILE>;
close(READTXTFILE);
return $readtxtline;
}
##################################################
#Readdbmfile
##################################################
sub readdbmfile {
dbmopen(%READDBMFILE,$_[0],0666);
%TEMPDBM=%READDBMFILE;
dbmclose(%READDBMFILE);
return %TEMPDBM;
}
##################################################
#Readdbmrecord
##################################################
sub readdbmrecord {
$TEMPRECORD="";
dbmopen(%READDBMFILE,$_[0],0666);
if ($READDBMFILE{$_[1]}) {
   $TEMPRECORD=$READDBMFILE{$_[1]};
}
dbmclose(%READDBMFILE);
return $TEMPRECORD;
}
##################################################
#Writedbmrecord
##################################################
sub writedbmrecord {
dbmopen(%WRITEDBMFILE,$_[0],0666);
$WRITEDBMFILE{$_[1]}=$_[2];
dbmclose(%WRITEDBMFILE);
}
##################################################
#Deletedbmrecord
##################################################
sub deletedbmrecord {
dbmopen(%DELETEDBMFILE,$_[0],0666);
delete $DELETEDBMFILE{$_[1]};
dbmclose(%DELETEDBMFILE);
}
##################################################
#Checkempty
##################################################
sub checkempty {
local($chkval)=$_[0];
$chkval =~ s/ |<br>|\n//g;
&error($_[1]) if ($chkval eq "");
}

##################################################
#Error
##################################################
sub error {
&adv;
&footdis;
&newsdis;
@errorpage=&readtxtfile("$pagehead$errorpage");
foreach (@errorpage) {
   $_ =~ s/\$errormessage/$_[0]/g;
   $_ =~ s/\$xip/$ip/g;
   $_ =~ s/\$cgiurl/$cgiurl/g;
   $_ =~ s/\$bannerhere/$bannerhere/g;
   $_ =~ s/\$foodis/$foodis/g;
   $_ =~ s/\$n_ews/$n_ews/g;
   $_ =~ s/\$id/$V{'id'}/g;
   $_ =~ s/\$name/$V{'name'}/g;
   $_ =~ s/\$email/$V{'email'}/g;
   $_ =~ s/\$password/$password/g;
   print;
   }
exit 0;
}

sub doagain {
&adv;
&footdis;
&newsdis;
@errorpage=&readtxtfile("$pagehead$doagainpage");
foreach (@errorpage) {
   $_ =~ s/\$errormessage/$_[0]/g;
   $_ =~ s/\$id/$V{'id'}/g;
   $_ =~ s/\$name/$V{'name'}/g;
   $_ =~ s/\$email/$V{'email'}/g;
   $_ =~ s/\$foodis/$foodis/g;
   $_ =~ s/\$n_ews/$n_ews/g;
   $_ =~ s/\$bannerhere/$bannerhere/g;


   print;
   }
exit 0;
}
##################################################
#limitcount
##################################################
sub limitcount{
if ($chkdep eq "v") {$timevar=$viplimitdays;}
if ($chkdep eq "d") {$timevar=$_[0];}

($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time+(86400*$timevar)+(3600*$time_miss));
$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
##################################################
$oldsign=19;
if (($yearn != 99) && ($yearn > 99)) {
$yearntest=$yearn-100;
$yearn=2000+$yearntest;
}
if ($yearn == 99) {
$yearn="$oldsign$yearn";
}
#end of y2k correction
##################################################

$timen="$yearn/$monn/$dayn($hourn\:$minn\:$secn)";
$timew="$yearn$monn$dayn";
$no   =$timen;
$no   =~ s/\/|\(|\)|\://g;
$limittime=substr($no,0,10);
}
##################################################
#Count Now
##################################################
sub count_now{
($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time);                       #SERVER在國內
$monn=$monn+1;
$sehour=$hourn;
$semin=$minn;
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
##################################################
$oldsign=19;
if (($yearn != 99) && ($yearn > 99)) {
$yearntest=$yearn-100;
$yearn=2000+$yearntest;
}
if ($yearn == 99) {
$yearn="$oldsign$yearn";
}
#end of y2k correction
##################################################
$timen="$yearn/$monn/$dayn($hourn\:$minn\:$secn)";
$timew="$yearn$monn$dayn";
$starttime=$sehour;
$starttime*=60;
$starttime+=$semin;
$sessiontime=$starttime;
$sessiontime+=2;
$no   =$timen;
$no   =~ s/\/|\(|\)|\://g;
$timenow=substr($no,0,10);
$myuutime=substr($no,0,12);

}

#####################################
# get my session number
#####################################
sub getmyno{
($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time);                       #SERVER在國內
$monn=$monn+1;
$sehour=$hourn;
$semin=$minn;
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
##################################################
$oldsign=19;
if (($yearn != 99) && ($yearn > 99)) {
$yearntest=$yearn-100;
$yearn=2000+$yearntest;
}
if ($yearn == 99) {
$yearn="$oldsign$yearn";
}
#end of y2k correction
##################################################
$timen="$yearn/$monn/$dayn($hourn\:$minn\:$secn)";
$timew="$yearn$monn$dayn";
$myno   =$timen;
$myno   =~ s/\/|\(|\)|\://g;
$s1=substr($myno,0,12);
#$s1=$sehour;
#$s1*=60;
#$s1+=$semin;
$s2=$s1;
$s2+=2;

}
##################################################
#Find What Member Effect
##################################################
sub find_what_effect{
%ORDERNUM=&readdbmfile("$filehead$orderidtoid");
%DEP=&readdbmfile("$filehead$iddepfile");
%ORDERCOM=&readdbmfile("$filehead$ordercomment");
%ORDEREFF=&readdbmfile("$filehead$ordereff");
%ORDERLIM=&readdbmfile("$filehead$orderlimit");
%ORDERPO=&readdbmfile("$filehead$orderpoint");

@orderid=keys %ORDERNUM;
@orderid=sort @orderid;

$V{'searchword'}="$V{'id'}";
if ($V{'searchword'}) {
   @temp=();
   foreach (@orderid) {
   if ((&searchwordfororder($_)==1)) {
   push(@temp,$_);
   }
   }
   @orderid=@temp;
}
################## BD Counting ##########################################
if ($DEP{$V{'id'}} eq "d") {
&count_now;
foreach  (@orderid) {

if (($timenow > $ORDERLIM{$_}) && ($ORDEREFF{$_} ne 'ff')) {
&writedbmrecord("$filehead$oldorder"				,$_,"$ORDERLIM{$_}");
&deletedbmrecord("$filehead$orderidtoid"			,$_);
&deletedbmrecord("$filehead$ordereff"				,$_);
}
if (($timenow <= $ORDERLIM{$_}) && ($ORDEREFF{$_} ne 'ff')) {
push (@mytemp,$_);
$chkstill=1;
}
}
if ($chkstill != 1) {
&deletedbmrecord("$filehead$idlimit"			,$V{'id'});
&writedbmrecord("$filehead$idlimit"				,$V{'id'},"0");	
&deletedbmrecord("$filehead$idcpass"			,$V{'id'});
}	
}
#################### END Of BD #############################################
################## AV Counting ##########################################
if ($DEP{$V{'id'}} eq "v") {

foreach  (@orderid) {

if (($ORDERPO{$_} <= $vip_per_min)) {
&writedbmrecord("$filehead$oldorder"				,$_,"{$V{'id'}");
&deletedbmrecord("$filehead$orderidtoid"			,$_);
&deletedbmrecord("$filehead$ordereff"				,$_);
}
if ($ORDERPO{$_} > $vip_per_min) {
push (@mytemp,$_);
$chkstill=1;
}
}
if ($chkstill != 1) {
&deletedbmrecord("$filehead$idlimit"			,$V{'id'});
&writedbmrecord("$filehead$idlimit"				,$V{'id'},0);	
&deletedbmrecord("$filehead$idcpass"			,$V{'id'});
}	
}
#################### END Of AV #############################################
if (@mytemp) {@orderid=@mytemp;}

@temp1=();
foreach $orderid(@orderid) {
if ($ORDEREFF{$orderid} eq "vv") {
push(@temp1,$ORDERCOM{$orderid});
push(@temp2,$ORDERPO{$orderid});
$temppoint=$temp2[0];
}
}

@tempworkid=();
foreach  (@temp1) {
@workid=split (/\./,$_);
push (@tempworkid,@workid);
}
@realwork=();
$yy="@realwork";
foreach $tempworkid(@tempworkid) {
if ($yy!~m/\b$tempworkid\b/i) {
push (@realwork,$tempworkid);
$yy="@realwork";
}
}
@realwork=sort @realwork;
}
##################################################
#find what eff again
##################################################



#################################################
# Dispoint 
################################################



##################################################
#Succ
##################################################
sub succ {
@succpage=&readtxtfile("$pagehead$succpage");
foreach (@succpage) {
   $_ =~ s/\$succmessage/$_[0]/g;
   $_ =~ s/\$message/$message/g;
   $_ =~ s/\$cgiurl/$cgiurl/g;
   $_ =~ s/\$xid/$xid/g;
   $_ =~ s/\$xpass/$xpass/g;
   $_ =~ s/\$manager/$manager/g;
   $_ =~ s/\$name/$V{'name'}/g;
   $_ =~ s/\$score/$V{'score'}/g;
   $_ =~ s/\$dep/$V{'dep'}/g;
   $_ =~ s/\$email/$V{'email'}/g;
   $_ =~ s/\$id/$V{'id'}/g;
   $_ =~ s/\$password/$noticepass/g;
   print;
}

}
##################################################
#Join Succ
##################################################
sub joinsucc {
&adv;
&footdis;
&newsdis;
@succpage=&readtxtfile("$pagehead$joinsuccpage");
foreach (@succpage) {
   $_ =~ s/\$cgiurl/$cgiurl/g;
   $_ =~ s/\$succmessage/$_[0]/g;
   $_ =~ s/\$bannerhere/$bannerhere/g;
   $_ =~ s/\$foodis/$foodis/g;
   $_ =~ s/\$n_ews/$n_ews/g;
   $_ =~ s/\$id/$V{'id'}/g;
   $_ =~ s/\$password/$noticepass/g;
   $_ =~ s/\$name/$V{'name'}/g;
   $_ =~ s/\$email/$V{'email'}/g;
   $_ =~ s/\$password/$password/g;

   
   print;
}

}

##################################################
#Succ more
##################################################
sub succmore {
@succpage=&readtxtfile("$pagehead$succpage");
foreach (@succpage) {
   $_ =~ s/\$succmessage/$_[0]/g;
   $_ =~ s/\$cgiurl/$cgiurl/g;
   $_ =~ s/\$xid/$xid/g;
   $_ =~ s/\$xpass/$xpass/g;
   $_ =~ s/\$manager/$manager/g;
   $_ =~ s/\$name/$V{'name'}/g;
   $_ =~ s/\$score/$V{'score'}/g;
   $_ =~ s/\$dep/$V{'dep'}/g;
   $_ =~ s/\$email/$V{'email'}/g;
   $_ =~ s/\$id/$V{'id'}/g;
   $_ =~ s/\$password/$noticepass/g;
   print;
}
exit 0;
}
##################################################
#top Succ
##################################################
sub topsucc {
@succpage=&readtxtfile("$pagehead$topsuccpage");
foreach (@succpage) {
   $_ =~ s/\$succmessage/$_[0]/g;
   $_ =~ s/\$cgiurl/$cgiurl/g;
   $_ =~ s/\$xid/$V{'manageid'}/g;
   $_ =~ s/\$xpass/$V{'managepassword'}/g;
   $_ =~ s/\$manager/$manager/g;
   $_ =~ s/\$name/$V{'name'}/g;
   $_ =~ s/\$score/$V{'score'}/g;
   $_ =~ s/\$dep/$V{'dep'}/g;
   $_ =~ s/\$email/$V{'email'}/g;
   $_ =~ s/\$id/$V{'id'}/g;
   $_ =~ s/\$password/$noticepass/g;
   print;
}
exit 0;
}

##################################################
#top Succ
##################################################
sub topsucc_gen {
@succpage=&readtxtfile("$pagehead$topsucc_genpage");
foreach (@succpage) {
   $_ =~ s/\$succmessage/$_[0]/g;
   $_ =~ s/\$cgiurl/$cgiurl/g;
   $_ =~ s/\$xid/$V{'manageid'}/g;
   $_ =~ s/\$xpass/$V{'managepassword'}/g;
   $_ =~ s/\$manager/$manager/g;
   $_ =~ s/\$name/$V{'name'}/g;
   $_ =~ s/\$score/$V{'score'}/g;
   $_ =~ s/\$dep/$V{'dep'}/g;
   $_ =~ s/\$email/$V{'email'}/g;
   $_ =~ s/\$id/$V{'id'}/g;
   $_ =~ s/\$password/$noticepass/g;
   print;
}
exit 0;
}
##################################################
#Banner
##################################################

sub adv {
  
  $image_url = "/ximg";
  $default_image_list = "/home/comoman/httpd/htdocs/vdata/myadv.list";
  $location_of_cgi_lib = "/home/comoman/httpd/cgi-bin/cgi-lib.pl";
  srand;
  require "$location_of_cgi_lib";
  $image_database = "$default_image_list";
    
  open (IMAGE_DATABASE, "$image_database") || 
        &CgiDie ("Can't open $image_database");

  while (<IMAGE_DATABASE>)
    {
    ($image, $url , $kk, $hh , $owner) = split (/\|/, $_);
    chop $url;
    push (@imagelist, $image);
    push (@url_list, $url);
    push (@kk_list, $kk);
    push (@hh_list, $hh);
    push (@owner_list, $owner);
    }
  close (IMAGE_DATABSE);

  $random_number = int(rand(@imagelist));
  $random_image = $imagelist[$random_number];
  $random_url = $url_list[$random_number];
  $random_kk = $kk_list[$random_number];
  $random_hh = $hh_list[$random_number];
  $random_owner = $owner_list[$random_number];
  $bannerhere .="<A HREF =$random_url><IMG SRC =\"$image_url/$random_image\" width=468 height=60 border=0 alt=$random_kk></A>";
      
      
    
}





##################################################
#Check manage id password (2)
##################################################
sub chkme{
$topuser="open";
$guser="use";
$cryptpass=$_[1];;
$temppassword=&readdbmrecord("$filehead$passwordfile",$_[0]);
$tempscore=&readdbmrecord("$filehead$scorefile",$_[0]);

if (($_[0]) && ($temppassword eq $cryptpass) && ($tempscore=~m/(m|$topuser|$guser)/i)) 
{
      $return="&manageid=$_[0]&managepassword=$_[1]&score=$_[3]";
   }   
   return $return;
}
##################################################
#Check Member Id And Password
##################################################
sub chkid_password_1{
$tempchkid=&readdbmrecord("$filehead$idnamefile",$V{'id'});
if (!$tempchkid) {&error("您使用的 ID 並不存在!");}
$temppassword=&readdbmrecord("$filehead$passwordfile",$V{'id'});
if ($V{'password'} ne $temppassword) {&error("密碼不符,無權使用!");}

if ($tempchkid && ($V{'password'} eq $temppassword)) 
{
      $return="&id=$_[0]&password=$_[1]";
   }   
   return $return;
}
##################################################
#Check Member Id And Password
##################################################
sub chkid_password_3{
$tempchkid=&readdbmrecord("$filehead$idnamefile",$V{'id'});
if (!$tempchkid) {&error("您使用的 ID 並不存在!");}
$temppassword=&readdbmrecord("$filehead$passwordfile",$V{'id'});
if ($V{'oldpassword'} ne $temppassword) {&error("密碼不符,無權使用!");}

$tempdep=&readdbmrecord("$filehead$iddepfile",$V{'id'});

if ($tempdep eq "v") {
$tempscoreorg=&readdbmrecord("$filehead$vscorefile",$V{'id'});
}

if ($tempdep eq "d") {
%TSCORE=&readdbmfile("$filehead$dscoreorg$V{'id'}");
@sid=keys %TSCORE;
$tempscoreorg="@sid";
}

if ($tempchkid && ($V{'password'} eq $temppassword) && $tempscoreorg) 
{
      $return="&id=$_[0]&password=$_[1]";
   }   
   return $return;
}
##################################################
#Check Member Id And Old Password
##################################################
sub chkid_password_2{
$tempchkid=&readdbmrecord("$filehead$idnamefile",$V{'id'});
if (!$tempchkid) {&error("您使用的 ID 並不存在!");}
$temppassword=&readdbmrecord("$filehead$passwordfile",$V{'id'});
if ($V{'oldpassword'} ne $temppassword) {&error("密碼不符,無權使用!");}
$tempdep=&readdbmrecord("$filehead$iddepfile",$V{'id'});

if ($V{'needtoid'} eq "") {&error("無任何可啟用的作業!");}

if ($tempchkid && ($V{'oldpassword'} eq $temppassword) && $V{'needtoid'}) 
{
      $return="&id=$_[0]&password=$_[1]";
   }   
   return $return;
}
##################################################
#Check Member Id And Old Password
##################################################

sub chkid_password_4{
$tempchkid=&readdbmrecord("$filehead$idnamefile",$V{'id'});
if (!$tempchkid) {&error("您使用的 ID 並不存在!");}
$temppassword=&readdbmrecord("$filehead$passwordfile",$V{'id'});
if ($V{'oldpassword'} ne $temppassword) {&error("密碼不符,無權使用!");}

if ($tempchkid && ($V{'oldpassword'} eq $temppassword) ) 
{
      $return="&id=$_[0]&password=$_[1]";
   }   
   return $return;
}

##################################################
#cp do
##################################################
sub cpdo{
$oldpass=$_[1];
$noticepass=$_[2];
$newpass=crypt($noticepass,NB);
&deletedbmrecord("$filehead$passwordfile",$_[0]);
&writedbmrecord("$filehead$passwordfile",$_[0],$newpass);
&deletedbmrecord("$filehead$idcpass",$_[0]);
&writedbmrecord("$filehead$idcpass",$_[0],$timew);
}
##################################################
#cpemail do
##################################################
sub cpemaildo{
$oldemail=$_[1];
$noticeemail=$_[2];
&deletedbmrecord("$filehead$idemailfile",$_[0]);
&writedbmrecord("$filehead$idemailfile",$_[0],$noticeemail);
}
##################################################
#Check manage id password
##################################################
sub checkmanageidpassword {
local($return)="";
#$managefile="f:/users/myyankee/www/htdocs/member/page/xfile.conf";
$managefile="d:/inetpub/wwwroot/member/page/xfile.conf";

open (XFILE, "$managefile");

  foreach (<XFILE>)
    {
if (/$_[0]/i){

    ($xid, $xpass,$manager) = split (/\|/, $_);
    chop $manager;
    $manage{"$xid"} = "$xpass";
        }
  close (XFILE);
}

if (($_[0] ne "") && ($_[1] ne "")) {
   if (($manage{$_[0]}) && ($manage{$_[0]} eq $_[1])) {
      $return="&manageid=$_[0]&managepassword=$_[1]";
   }     
}
return $return;
}
##################################################
#Check MASTER id password 
##################################################
sub checktopmaster {
$topuser="open";
$cryptpass=$_[1];;
$temppassword=&readdbmrecord("$filehead$passwordfile",$_[0]);
$tempscore=&readdbmrecord("$filehead$scorefile",$_[0]);
$tempdep=&readdbmrecord("$filehead$depfile",$_[0]);

if (($_[0]) && ($temppassword eq $cryptpass) && ($tempscore=~m/$topuser/i)) 
{
	  $return="&manageid=$_[0]&managepassword=$_[1]";
   }   
   return $return;
}


##################################################
#Check manage id password super again
##################################################
sub pc32chkmasteragn {
local($return)="";
$superfile="/home/comoman/httpd/htdocs/hvdata/xxfile.conf";

open (XFILE, "$superfile");

  foreach (<XFILE>)
    {
if (/super/i){

    ($xid, $xpass,$manager) = split (/\|/, $_);
    $manage{"$xid"} = "$xpass";
	chop $manager;
        }
  close (XFILE);
}

if (($_[0] ne "") && ($_[1] ne "")) {


   if (($manage{$_[0]}) && ($manage{$_[0]} eq $_[1]) && ($_[2] eq $manager )) {
      $return="&manageid=$_[0]&managepassword=$_[1]&manager=$_[2]";
   }     
}
return $return;
}

##################################################
#check manage id password super
##################################################

sub pc32chkmaster {
local($return)="";
$superfile="/home/comoman/httpd/htdocs/hvdata/xxfile.conf";
open (XFILE, "$superfile");

  foreach (<XFILE>)
    {
if (/super/i){

    ($xid, $xpass,$manager) = split (/\|/, $_);
    $manage{"$xid"} = "$xpass";
	chop $manager;
        }
  close (XFILE);
}

if (($_[0] ne "") && ($_[1] ne "")) {

$_[1]=crypt($_[1],NB);

   if (($manage{$_[0]}) && ($manage{$_[0]} eq $_[1]) && ($manager eq 'top')) {
      $return="&manageid=$_[0]&managepassword=$_[1]";
   }     
}
return $return;
}

##################################################
#Check Referers
##################################################

sub chkrefer {
@referers = ('210.59.231.40','www.como.com.tw','www.comoo.com');

	local($check_referer) = 0;
  
    if ($ENV{'HTTP_REFERER'}) {
        foreach $referer (@referers) {
            if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) {
                $check_referer = 1;
				last;
                
            }
        }
    }
    #else {
    #    $check_referer = 1;
    #}
if ($check_referer != 1) { &error("不合法的使用!"); }
 
}



##################################################
#check manage id password super cp
##################################################
sub s32cp {
local($return)="";
$superfile="/home/comoman/httpd/htdocs/hvdata/xxfile.conf";

open (XFILE, "$superfile");

  foreach (<XFILE>)
    {
if (/super/i){

    ($xid, $xpass,$manager) = split (/\|/, $_);
    $manage{"$xid"} = "$xpass";
	chop $manager;
        }
  close (XFILE);
}

if (($_[0] ne "") && ($_[1] ne "")) {

#$_[1]=crypt($_[1],NB);

   if (($manage{$_[0]}) && ($manage{$_[0]} eq $_[1]) && ($manager eq 'top')) {
      $return="&manageid=$_[0]&managepassword=$_[1]";
    
 
  
$oldpass=$V{'managepassword'};
$newpass1=$V{'newpass'};
$newpass =crypt($V{'newpass'},NB);


$superfile="/home/comoman/httpd/htdocs/hvdata/xxfile.conf";
$newfile="/home/comoman/httpd/htdocs/hvdata/xxfile.temp";

$record="$_[0]|$newpass|top";

open (WRITE,">$newfile");
open (XFILE,"$superfile");

foreach (<XFILE>) {
  if(/super/){
      print WRITE "$record\n";
}
  else {
      print WRITE "$_";
    }
	
  close(XFILE);
  
  close(WRITE);
}
$t1='/home/comoman/httpd/htdocs/hvdata/xxfile.temp';
$t2='/home/comoman/httpd/htdocs/hvdata/xxfile.conf';


open (kk,"/home/comoman/httpd/htdocs/hvdata/xxfile.temp");
  
open (kk1,">/home/comoman/httpd/htdocs/hvdata/xxfile.conf");
  

  while(<kk>){
    print kk1 "$_";
    }

  close(kk);
  
  close(kk1);

  
}
}
return $return;

  }



sub searchwordfororder {
$return=0;
if ($ORDERNUM{$_[0]} =~m/\b$V{'searchword'}\b/i) {$return=1;}
 
return $return;
}


  
  sub replaceit{

if ($_ =~m /$kk/) {
$_ =~ s/\$replace/selected/g;
   }
   else {
   $_ =~ s/\$replace//g;
   }
   }
sub chkyou{
$tempname=&readdbmrecord("$filehead$idnamefile",$V{'id'});
$tempdep=&readdbmrecord("$filehead$iddepfile",$V{'id'});
$templimit=&readdbmrecord("$filehead$idlimit",$V{'id'});

if ($tempdep eq "v") {
$tempscore=&readdbmrecord("$filehead$vscorefile",$V{'id'});
$tempscoreorg=&readdbmrecord("$filehead$vscoreorg",$V{'id'});
}

&count_now;

if (($tempdep eq "v") && ($tempscore eq "") && $tempscoreorg) {&error("您的帳戶資料尚未確認!");}
if (($tempdep eq "d") && ($timenow > $templimit) ) {&error("您先前購買的天數已使用完畢!");}

if (($tempdep eq "d") && ($templimit eq "")) {&error("您的帳戶資料尚未確認!");}

if (($tempdep eq "v") && ($tempscore <= 0) && $tempscoreorg) {&error("您的帳戶資料尚未確認!");}
if (($tempdep eq "v") && ($timenow > $templimit) && (!$tempscoreorg)) {&error("您的帳戶已無點數可使用!");}
if (($tempdep eq "v") && ($tempscore < $vip_per_min) && (!$tempscoreorg)) {&error("您的帳戶點數已使用完畢,需續購方可繼續使用!");}
}

use Socket;

sub sendmail{

my ($from, $reply, $to, $smtp, $subject, $mailmessage) = @_;
$from=$_[1];
$reply=$from;
$to=$_[0];
$subject=$_[3];
$mailmessage=$_[2];
$smtp="como.com.tw";
my ($fromaddr) = $from;
my ($replyaddr) = $reply;
$to =~ s/[ \t]+/, /g; # pack spaces and add comma
$fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address
$replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address
$replyaddr =~ s/^([^\s]+).*/$1/; # use first address
$mailmessage =~ s/^\./\.\./gm; # handle . as first character
$mailmessage =~ s/\r\n/\n/g; # handle line ending
$mailmessage =~ s/\n/\r\n/g;
$smtp =~ s/^\s+//g; # remove spaces around $smtp
$smtp =~ s/\s+$//g;

if (!$to) { return -8; }

my($proto) = (getprotobyname('tcp'))[2];
my($port) = (getservbyname('smtp', 'tcp'))[2];

my($smtpaddr) = ($smtp =~
/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
? pack('C4',$1,$2,$3,$4)
: (gethostbyname($smtp))[4];

if (!defined($smtpaddr)) { return -1; }

if (!socket(S, AF_INET, SOCK_STREAM, $proto)) { 
  return -2; }
if (!connect(S, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { 
  return -3; }

my($oldfh) = select(S); $| = 1; select($oldfh);

$_ = <S>; if (/^[45]/) { close S; return -4; }

print S "helo localhost\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }

print S "mail from: <$fromaddr>\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }

foreach (split(/, /, $to)) {
  print S "rcpt to: <$_>\r\n";
  $_ = <S>; if (/^[45]/) { close S; return -6; }
  }

print S "data\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }

print S "To: $to\r\n";
print S "From: $from\r\n";
print S "Reply-to: $replyaddr\r\n" if $replyaddr;
print S "X-Mailer: Windows NT Sendmail build 1.98 By YankeeNET\r\n";
print S "Subject: $subject\r\n\r\n";
print S "$mailmessage";
print S "\r\n.\r\n";

$_ = <S>; if (/^[45]/) { close S; return -7; }

print S "quit\r\n";
$_ = <S>;

close S;

return;
}


sub sendmail4 {

my ($from, $reply, $to, $smtp, $subject, $mailmessage) = @_;
$from=$_[1];
$reply=$from;
$to=$_[0];
$subject=$_[3];
$mailmessage=$_[2];
$ccto=$_[4];
my ($fromaddr) = $from;
my ($replyaddr) = $reply;

$to =~ s/[ \t]+/, /g; # pack spaces and add comma
$fromaddr =~ s/.*<([^\s]*?)>/$1/; # get from email address


$replyaddr =~ s/.*<([^\s]*?)>/$1/; # get reply email address
$replyaddr =~ s/^([^\s]+).*/$1/; # use first address
$ownmessage =~ s/^\./\.\./gm; # handle . as first character
$mailmessage =~ s/\r\n/\n/g; # handle line ending
$mailmessage =~ s/\n/\r\n/g;
$smtp =~ s/^\s+//g; # remove spaces around $smtp
$smtp =~ s/\s+$//g;

if (!$to) { return -8; }

my($proto) = (getprotobyname('tcp'))[2];
my($port) = (getservbyname('smtp', 'tcp'))[2];

my($smtpaddr) = ($smtp =~
/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
? pack('C4',$1,$2,$3,$4)
: (gethostbyname($smtp))[4];

if (!defined($smtpaddr)) { return -1; }

if (!socket(S, AF_INET, SOCK_STREAM, $proto)) { 
  return -2; }
if (!connect(S, pack('Sna4x8', AF_INET, $port, $smtpaddr))) { 
  return -3; }

my($oldfh) = select(S); $| = 1; select($oldfh);

$_ = <S>; if (/^[45]/) { close S; return -4; }

print S "helo localhost\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }

print S "mail from: <$fromaddr>\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }

foreach (split(/, /, $to)) {
  print S "rcpt to: <$_>\r\n";
  $_ = <S>; if (/^[45]/) { close S; return -6; }
  }

print S "data\r\n";
$_ = <S>; if (/^[45]/) { close S; return -5; }

print S "To: $to\r\n";
print S "Cd: $ccto\r\n";
print S "From: $from\r\n";
print S "Reply-to: $replyaddr\r\n" if $replyaddr;
print S "X-Mailer: Windows NT Sendmail build 1.98 By YankeeNET\r\n";
print S "Subject: $subject\r\n\r\n";
print S "$mailmessage";
print S "\r\n.\r\n";

$_ = <S>; if (/^[45]/) { close S; return -7; }

print S "quit\r\n";
$_ = <S>;

close S;

return;
}

sub sendemail_to_user{
local($from)=$masteremail;
local($to)=$_[1];
local($username)=$_[0];
local($mastername)=$mastername;
local($userid)=$_[2];
local($userpass)=$_[4];
local($usertime)=$_[3];
local($subject)=$_[5];
local($ticket)=$_[6];
local($page)=$_[7];
local($t03)=$_[8];
local($t04)=$_[9];
local($t05)=$_[10];
local($t06)=$_[11];
local($t07)=$_[12];
local($t08)=$_[13];
local($amout)=$_[14];
local($cash)=$_[15];
local($checkin)=$_[16];
local($roomdis)=$_[17];
local($visadis)=$_[18];
local($parking)=$_[19];
local($myfno)=$_[20];
local($roomdis)=$_[21];
local($gifdis)=$_[22];

$mailprog = '/usr/sbin/sendmail';
#$page="/home/comoman/httpd/htdocs/vdata/new1.dta";
open (PAGE,$page);
	#local($/) = undef;
	$template = <PAGE>;
	close(PAGE);

	$sendtime=localtime (time),;
	$template =~ s/\$username/$username/g;
	$template =~ s/\$userid/$userid/g;
	$template =~ s/\$usertime/$usertime/g;
	$template =~ s/\$userpass/$userpass/g;
	$template =~ s/\$mastername/$mastername/g;
	$template =~ s/\$myticket/$myticket/g;
	$template =~ s/\$t08/$V{'t08'}/g;
	$template =~ s/\$t07/$t07/g;
	$template =~ s/\$amout/$amout/g;
	$template =~ s/\$cash/$cash/g;
	$template =~ s/\$checkin/$checkin/g;
	$template =~ s/\$visadis/$visadis/g;
	$template =~ s/\$parking/$parking/g;
	$template =~ s/\$myfno/$myfno/g;
	$template =~ s/\$roomdis/$roomdis/g;
	$template =~ s/\$gifdis/$gifdis/g;
	
	

open(MAIL,"|$mailprog -t");

    print MAIL "To: $to\n";
    print MAIL "From: $from \n";
    print MAIL "Subject: $subject\n\n";
	print MAIL "\r\n";
    
    print MAIL "$template\n\n";

	
	close (MAIL);


}

sub getCookies_agent {
        # cookies are seperated by a semicolon and a space, this will split
        # them and return a hash of cookies
		$who=$_[0];
        local(@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
        local(%cookies);

        foreach(@rawCookies){
        if(/$who/i){
		#if(/youemail/i){
            ($key, $val) = split (/=/,$_);
            $cookies{$key} = $val;
            #$cookies{myemail} = $myval;
      ($aid,$atime) = split (/\:/, $val);
}
        } 

        return %cookies; 
} 