<?php 

session_start();
if (!isset($_SESSION['username'])) {
  header("location:login/main_login.php");
}
  
    // load up your config file
   require_once("setting.php");
	
    require_once(connection);
    require_once(header_e);
?>
<div class="container">
<div class="row justify-content-md-center">
<?php include_once(menu_penal);
?>
</div>
      <div class="row justify-content-center">
    <div class="col-5">
  <h2>Edit Customer Detail</h2> </div></div>
  <form class="form-horizontal" action="" method="post">
	  <div class="form-row">

      <label for="disabledInput" class="col-sm-4 control-label">Customer ID</label>
      <div class="col-md-6">
        <input class="form-control" id="c_id" type="text" placeholder="" disabled>
      </div>
      <label class="col-sm-4 control-label">Search Customer Name</label>
      <div class="col-sm-6">
        <input class="form-control" name="search" id="search"  type="search" placeholder="Customer Name">
      </div>
	  <label class="col-sm-4 control-label">Father Name</label>
      <div class="col-sm-6">
        <input class="form-control" name="cfname" id="cfname" type="text" placeholder="Father Name">
      </div>
	  </div>
	  	  	  <div class="form-row">
<label class="col-sm-2 control-label">Address</label>
      <div class="col-sm-10">
        <input class="form-control" name="address" id="address" type="text" placeholder="Customer Address">
      </div>
</div>
	  <div class="form-row">
 <label class="col-sm-2 control-label">Email</label>
      <div class="col">
        <input class="form-control" name="email" id="email" type="email" placeholder="Email">
      </div>
 <label class="col-sm-2 control-label">CNIC No.</label>
      <div class="col">
        <input class="form-control" name="cnic" id="cnic" type="text" placeholder="ID Card No.">
      </div>
</div>
	  	  <div class="form-row">

	  <label class="col-sm-2 control-label">Cell No.</label>
      <div class="col">
        <input class="form-control" name="phone1" id="phone1" type="text" placeholder="Mobile No.">
      </div>
  <label class="col-sm-2 control-label">Phone No.</label>
      <div class="col">
        <input class="form-control" name="phone2" id="phone2" type="text" placeholder="Phone No.">
      </div>
</div>
	  	  <div class="form-row">

  <label class="col-sm-3 control-label" for="sel1">Select Pkg Plan:</label>
      <div class="col-sm-3">


   

	  <div class="selDiv">
  <select class="form-control" id="option" name="pkg">
<?php $sql="SELECT * FROM pkg ORDER BY pkg_id";
if ($result=mysqli_query($con,$sql)){ 
while($row = $result->fetch_assoc()) { 
echo '<option value="'.$row['pkg_id'].'">'.$row['pkg_name'].'</option>';
    }}?>    
  </select>
  </div>
</div>
  <label class="col-sm-2 control-label">Date</label>

      <div class="col">
	          <input class="form-control" name="date" id="date" type="date" placeholder="Date">

</div>

</div>
<div class="form-row">

  <label class="col-sm-3 control-label" >Status</label>
      <div class="col-sm-3">

  <select class="form-control" id="status" name="status">
    <option value="active">Active</option>
    <option value="close">Deactive</option>
  </select>
</div>
</div>
</br>
  <div class="row justify-content-center">
    <div class="col-1">
   <input class="btn btn-primary" type="submit" name="submit" value="Submit" />
</div>
</div>
  </form>
</div>
<?php
if(isset($_POST['submit'])){
$name= $_POST['cname'];
$fname = $_POST['cfname'];
$address = $_POST['address'];
$email = $_POST['email'];
$cnic = $_POST['cnic'];
$pkg = $_POST['pkg'];
$date = $_POST['date'];
$phone1= $_POST['phone1'];
$phone2 = $_POST['phone2'];
$status = $_POST['status'];
$other = "";
$datee=date('Y/m/d');
$sql = "INSERT INTO customer(c_name,c_fname,c_address,c_cnic,c_email,conn_date,c_pkg,c_phone1,c_phone2,c_other)
VALUES ('$name','$fname','$address','$cnic','$email','$date','$pkg','$phone1','$phone2','$other')";


if ($con->query($sql) === TRUE) {
$last_id = $con->insert_id;
echo $last_id;	
$sq = "INSERT INTO status(c_id,c_name,s_date,e_date,status,pkg_id) VALUES ('$last_id','$name','$date','$datee','$status','$pkg')";

   if ($con->query($sq) === TRUE) {
	echo '<script type="text/javascript">alert("New record:::' . $name .'_ID_'.$last_id. ':::created successfully"); </script>';   }else {
    echo "Error: " . $sq . "<br>" . $con->error;
}


    

} else {
    echo "Error: " . $sql . "<br>" . $con->error;
}

$con->close();
}
?>
</body>
</html>