#!/usr/bin/perl -wT
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$cnt=param("cnt");
$shID=param("shID");
$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 = "p1".$i;  #location Code
	 $n2 = "p2".$i;  #City Name
	 $n3 = "p3".$i;  #Location Name
	 $n4 = "p4".$i;  #Store Type
	 $n5 = "p5".$i;  #Plan Date
	 $n6 = "p6".$i;  #Plan Time
	 $n7 = "p7".$i;  #Shopper Name
	 $n8 = "p8".$i;  #Gender
	 $n9 = "p9".$i;  #Age
	 $n10 = "p10".$i;  #Nationality
	 $n11 = "p11".$i;  #Mailed
	 $n12 = "p12".$i;  #Visited
	 $n13 = "p13".$i;  #send
	 $n14 = "p14".$i;  #Plan Code
	 $n15 = "p15".$i;  #visit Code
	 $n16 = "p16".$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 

