#!/usr/bin/perl -w
use CGI qw/:all/;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
my $dbh=DBI->connect('dbi:mysql:parc_demog:localhost','parcdemog','parc9904')or die "Couldn't connect to database: " . DBI->errstr;
#######
use CGI;
my $query = new CGI;
my $conCode=param('conCode');
my $cmd=param('cmd');
#print $query->header( );
########
print <<blk;
content-type: text/html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
blk
$strCond="";
if ($conCode ne "All") 
{
	$strCond=" Where country=$conCode and forCF='T'";
}
$strSh="SELECT fName,lName,email FROM shopper $strCond";
$sthSh=$dbh->prepare($strSh);
$sthSh->execute;
#$emailFrom="PARC-Mystery-Shopping";
$emailFrom="parcdxb\@emirates.net.ae";
while ($sh=$sthSh->fetchrow_hashref())
  {
	$emailTo="$sh->{'email'}";
	$link="http://www.arabdemog.com/reg/reg.pl?frmType=3";
	$comments="Dear Shopper, \n$cmd\n\n Here is the link.\n\n$link\n\n\nNOTE:-DO NOT VISIT ANY LOCATION UNTIL YOU RECEIVE APPROVAL / CONFIRMATION ALONG WITH THE LINK FOR ALLOCATED LOCATIONS FROM OUR END. ANY VISIT CONDUCTED WITHOUT APPROVAL WILL NOT BE ACCEPTED\n\n";
	#########
#		# Email the form results
		$subject="Visit Plan - Carrefour!"; 
		$sendmailpath="/usr/sbin/sendmail"; 
		open (sil, "| $sendmailpath -t"); 
		print sil "Subject: $subject\n"; 
		print sil "From: $emailFrom\n"; 
		print sil "To: $emailTo\n";
		print sil "$comments\n\n"; 
		print sil "Thanks"; 
		close (sil)|| print("unable to send $!"); 
	#########
	$msg="Mail has been Delivered";
}
$dbh->disconnect;
print<<blk1;
<tableborder="1"cellpadding="0"cellspacing="0"width="100%"bordercolor="#000080"height="359">
<tr>
<tdwidth="100%"height="357">
<palign="center"><fontface="Verdana"color="#000080"size="5"><b>$msg</b></font></td>
</tr>
</table>
</body>
</html>
blk1
