<?php
session_start();
if(!isset($_SESSION['titles']) || !isset($_SESSION['positions'])|| !isset($_SESSION['usernames'])){
}
$userr=$_SESSION['titles'];
$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_diana");
$result=mysqli_query($con,"select distinct agent_name,zone_order,zone,region,rsm_name,executive_name,agent_type,range_type,territory_name from agentsmrd where user_names='".$userr."'");
while($row = mysqli_fetch_array($result)) { 
$user=$row['agent_name'];
$zoredr=$row['zone_order'];
$zone=$row['zone'];
$region=$row['region'];
$rsm=$row['rsm_name'];
$exs=$row['executive_name'];
$atype=$row['agent_type'];
$rgtype=$row['range_type'];
$trnam=$row['territory_name'];
if(isset($_POST['Submit'])) {	
$custname = $_REQUEST['custname'];
$custtype = $_REQUEST['dropdown'];
$custaddres = $_REQUEST['custaddres'];
$custroute = $_REQUEST['custroute'];
$custarea = $_REQUEST['custarea'];
$custtp = $_REQUEST['custtp'];	
$sts='Active';
$result = mysqli_query($con,"insert into customer(custname,custaddres,custtp,custroute,custarea,custtype,agent_name,zone_order,zone,region,rsm_name,executive_name,agent_type,range_type,territory_name,cus_status)values('$custname','$custaddres','$custtp','$custroute','$custarea','$custtype','$user','$zoredr','$zone','$region','$rsm','$exs','$atype','$rgtype','$trnam','$sts')");
header("Location: updatecus.php");

$msgs=$msgs."<p style='font-family:calibri;font-size:12;'>Sales web program-Auto generated email: New Customer creation</p>";
$msgs=$msgs."<table style='font-family:calibri;font-size:12;width:70%%;'><th style='background:silver;' colspan='2'>New Customer creation</th>";
$msgs=$msgs."<tr style='background:silver'><td style='border:1px solid silver;width:50%%;' >Customer name</td><td style='border:1px solid silver;width:50%%;' >".$_REQUEST['custname']."</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['custaddres']."</td></tr>";
$msgs=$msgs."<tr style='border:1px solid silver;'><td style='border:1px solid silver;' >Route</td><td style='border:1px solid silver;' >".$_REQUEST['custroute']."</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 Customer information shown above.</p>";

$hdrs = "Content-type: text/html\r\n";
$hdrs .= 'To:prasi8283@gmail.com' . "\r\n";
$hdrs .= 'From: Sales web program' . "\r\n";
mail("prasanna@diana.lk","Sale web program: New item creation",$msgs,$hdrs);
}
}
?>

