#!/usr/bin/perl -wT
use CGI ':standard'; 
use CGI::Carp qw(fatalsToBrowser);
$cnt=param("cnt");
#$shID=param("shID");
my $logName;
$logName="/var/www/vhosts/arabdemog.com/httpdocs/cf/images";
my @fileholder;  
open (LOG, ">$logName/link.log") || Error('open', 'file');  
for ($i=1;$i<=$cnt ;$i++) 
{
	 $n1 = "pa".$i;  #location Code
	 #$n2 = "pb".$i;  #City Name
	 $n3 = "pc".$i;  #Location Name
	 #$n4 = "pd".$i;  #Store Type
	 $n5 = "pe".$i;  #Plan Date
	 $n6 = "pf".$i;  #Plan Time
	 #$n7 = "pg".$i;  #Shopper Name
	 #$n8 = "ph".$i;  #Gender
	 #$n9 = "pi".$i;  #Age
	 #$n10 = "pj".$i;  #Nationality
	 #$n11 = "pk".$i;  #Mailed
	 #$n12 = "pl".$i;  #Visited
	 $n13 = "pm".$i;  #send
	 #$n14 = "pn".$i;  #Plan Code
	 $n15 = "po".$i;  #visit Code
	 $n16 = "pp".$i;  #Email
	my $locCode =param("$n1");
	#my $city =param("$n2");
	my $location =param("$n3");
	#my $type =param("$n4");
	my $planDate =param("$n5");

	my @arsdate=split('-',$planDate);
	$planDate=$arsdate[2]."-".$arsdate[1]."-".$arsdate[0];
	
	my $planTime =param("$n6");
	#my $shopperName =param("$n7");
	#my $gender =param("$n8");
	#my $age =param("$n9");
	#my $nationality =param("$n10");
	#my $hasMailed =param("$n11");
	#my $hasVisited =param("$n12");
	my $send =param("$n13");
	#my $planCode =param("$n14");
	my $visitCode =param("$n15");
	my $email =param("$n16");
	#print LOG "yues\n\n" or die "Could not Write"; 
	#if($send ne "T")
	#{
		
		if($send==1)
		{
			my $lnk = "http://www.arabdemog.com/reg/reg.pl?locCode=$locCode&planDate=$planDate&visitCode=$visitCode";
			print LOG "$lnk\n" or die "Could not Write"; 
		}
	#}
}
	close (LOG);
	open(DLFILE, "<$logName/link.log") || Error('open', 'file');   
	@fileholder = <DLFILE>;   
	close (DLFILE) || Error ('close', 'file');  

print "Content-Type:application/x-download\n";  
print "Content-Disposition:attachment;filename=$logName/link.log\n\n";  
print @fileholder 

