#!/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;
#my $dbh=DBI->connect('dbi:mysql:parc_demog:localhost:3306','root','root') or die "Unable to connect: $DBI::errstr\n";

print <<blk;
content-type: text/html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
</head>
<body>
blk
$cnt=param("cnt");
$shID=param("shID");
for ($i=1;$i<=$cnt ;$i++) 
{
	 $n1 = "pa1".$i;
	 $n2 = "pb2".$i;
	 $n3 = "pc3".$i;
	 $n4 = "pd4".$i;
	 $n5 = "pe5".$i;
	 $n6 = "pf6".$i;
	 $n7 = "pg7".$i;

	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 $planCode =param("$n7");
	my$YY = substr $arsdate[2],-2;
	my $visitCode=$locCode.$arsdate[0].$arsdate[1].$YY.$shID;

	if($planDate ne '--')
	{
		my $strsql="INSERT INTO cf_visitDetail(planCode,visitCode,locCode,visitDate,visitTime,shID,hasMailed,hasVisited)VALUES ($planCode,'$visitCode','$locCode','$planDate','$planTime',$shID,'F','F')";
		my $rv=$dbh->do($strsql);
		$dbh->disconnect;
		$msg="Visit Plan submitted successfully!!!";
	}
}
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
