<?php
session_start();
if(!isset($_SESSION['titles']) || !isset($_SESSION['positions'])|| !isset($_SESSION['usernames'])){
}

$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_diana");
if(isset($_POST['Submit'])) {
$dbname = $_REQUEST['dbname'];
$dibname = $_REQUEST['dibname'];
$outltname = $_REQUEST['outltname'];	
$dibnic = $_REQUEST['dibnic'];
$dbaddres = $_REQUEST['dbaddres'];
$dbcntact = $_REQUEST['dbcontact'];
$dbturn = $_REQUEST['dbturn'];
$mrates = $_REQUEST['mrates'];
$bacount = $_REQUEST['bacount'];
$rgtpe = $_REQUEST['rgtype'];
$bank = $_REQUEST['bank'];
$pmode = $_REQUEST['paymode'];
$sts='Active';
$userr=$_SESSION['titles'];
$psitn=$_SESSION['positions'];



$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_diana");
$rsqlst =mysqli_query($conn,"select zone,region,agent_type,chanelname,territory_name from agentsmrd where agent_name='".$dbname."'");

if(mysqli_num_rows($rsqlst)==0){
printf("following Distributor do not exist - %s<br>",$dbname);

}
else{
$trst=mysqli_fetch_row($rsqlst);
	$zone=$trst[0];
	$rgn=$trst[1];
	$agtype=$trst[2];
	$chnl=$trst[3];
	$terri=$trst[4];

$result = mysqli_query($con,"insert into dbsdirect(zone,region,agentype,territory,dbdirectname,
dbadress,dbcontact,outletname,nicno,outlettype,dbasign,turnover,bankname,bankacount,paymode,chanell,marginrate)values
('$zone','$rgn','$agtype','$terri','$dibname','$dbaddres','$dbcntact','$outltname','$dibnic','$rgtpe','$dbname','$dbturn','$bank','$bacount','$pmode','$chnl'
,'$mrates')");
header("Location: prdashbs.php");

$msgs=$msgs."<p style='font-family:calibri;font-size:12;'>Sales web program-Auto generated email: New Direct Dealer</p>";
$msgs=$msgs."<table style='font-family:calibri;font-size:12;width:70%%;'><th style='background:silver;' colspan='2'>New Direct Dealer</th>";
$msgs=$msgs."<tr style='background:silver'><td style='border:1px solid silver;width:50%%;' >Direct Dealer</td><td style='border:1px solid silver;width:50%%;' >".$_REQUEST['dibname']."</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Address</td><td style='border:1px solid silver;' >".$_REQUEST['dbaddres']."</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Contact</td><td style='border:1px solid silver;' >".$_REQUEST['dbcontact']."</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Channel</td><td style='border:1px solid silver;' >'".$chnl."'</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Zone</td><td style='border:1px solid silver;' >'".$zone."'</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Region</td><td style='border:1px solid silver;' >'".$rgn."'</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Nearst DBPoint</td><td style='border:1px solid silver;' >".$_REQUEST['dbname']."</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Agent type</td><td style='border:1px solid silver;' >'".$agtype."'</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Territory name</td><td style='border:1px solid silver;' >'".$terri."'</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' colspan='2'>".$psitn." - ".$userr."</td></tr>";
$msgs=$msgs."</table>";
$msgs=$msgs."<p style='font-family:calibri;font-size:12;'>Contact Sales and marketing department regarding any issues regarding this new Direct Dealer information shown above.</p>";

$hdrs = "Content-type: text/html\r\n";
$hdrs .= 'To: jeewaneshwary@diana.lk,pathmasiri@diana.lk,asela@diana.lk,hazari@diana.lk,upendra@diana.lk,priyanka@diana.lk,thanuja@diana.lk,wijewardana@diana.lk,sudath@diana.lk,jayantha@diana.lk,dilrukshi@diana.lk,roshan.r@diana.lk' . "\r\n";
$hdrs .= 'From: Sales web program' . "\r\n";
$hdrs .= 'Cc: prasanna@diana.lk' . "\r\n";
mail("prasanna@diana.lk","Sale web program: New Direct Dealer",$msgs,$hdrs);
}
}
?>

