<?php 
session_start();
include_once '../config.php';
$user_id = $_SESSION['Admin']['id'];
$CurrDate = date('dmY');
if($_REQUEST['action'] == 'SaveAppointment'){
	$MrdNo = $_REQUEST['MrdNo'];
	$Suffix = addslashes(trim($_REQUEST['Suffix']));
	$Fname = addslashes(trim($_REQUEST['Fname']));
	$Mname = addslashes(trim($_REQUEST['Mname']));
	$Lname = addslashes(trim($_REQUEST['Lname']));
	$Phone = addslashes(trim($_REQUEST['Phone']));
	$Phone2 = addslashes(trim($_REQUEST['Phone2']));
	$Gender = addslashes(trim($_REQUEST['Gender']));
	$City = addslashes(trim($_REQUEST['City']));
	$State = addslashes(trim($_REQUEST['State']));
	$Address = addslashes(trim($_REQUEST['Address']));
	$Dob = addslashes(trim($_REQUEST['Dob']));
	$Age = addslashes(trim($_REQUEST['Age']));
	$Consultant = addslashes(trim($_REQUEST['Consultant']));
	$Fees = addslashes(trim($_REQUEST['Fees']));
	$PayMode = addslashes(trim($_REQUEST['PayMode']));
	$AppointDate=date('Y-m-d');
	$AppointTime = addslashes(trim($_REQUEST['AppointTime']));
	$CreatedDate = date('Y-m-d');
	$PatientName = $Suffix." ".$Fname." ".$Mname." ".$Lname;
	$Flag = 0;

	$sql5 = "SELECT Name FROM tbl_users WHERE id='$Consultant'";
	$row5 = getRecord($sql5);
	$ConsultantName = $row5['Name'];
  try {
   $sql = "INSERT INTO tbl_opd_appointments (MrdNo,Suffix,Fname,Mname,Lname,PatientName,Gender,Age,Phone,City,State,Address,Consultant,ConsultantName,Fees,PayMode,CreatedBy,CreatedDate,AppointDate,AppointTime,Flag) VALUES (:MrdNo,:Suffix,:Fname,:Mname,:Lname,:PatientName,:Gender,:Age,:Phone,:City,:State,:Address,:Consultant,:ConsultantName,:Fees,:PayMode,:CreatedBy,:CreatedDate,:AppointDate,:AppointTime,:Flag)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':MrdNo', $MrdNo);
$stmt->bindParam(':Suffix', $Suffix);
$stmt->bindParam(':Fname', $Fname);
$stmt->bindParam(':Mname', $Mname);
$stmt->bindParam(':Lname', $Lname);
$stmt->bindParam(':PatientName', $PatientName);
$stmt->bindParam(':Gender', $Gender);
$stmt->bindParam(':Age', $Age);
$stmt->bindParam(':Phone', $Phone);
$stmt->bindParam(':City', $City);
$stmt->bindParam(':State', $State);
$stmt->bindParam(':Address', $Address);
$stmt->bindParam(':Consultant', $Consultant);
$stmt->bindParam(':ConsultantName', $ConsultantName);
$stmt->bindParam(':Fees', $Fees);
$stmt->bindParam(':PayMode', $PayMode);
$stmt->bindParam(':AppointDate', $AppointDate);
$stmt->bindParam(':AppointTime', $AppointTime);
$stmt->bindParam(':CreatedBy', $user_id);
$stmt->bindParam(':CreatedDate', $CreatedDate);
$stmt->bindParam(':Flag', $Flag);
if ($stmt->execute()) {
  echo "<script>window.location.href='../opd-appointment.php';</script>";
}
}
catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
}
?>
