<?
session_start();
include("dbconfig.php");
if(isset($_SESSION['username']) && isset($_SESSION['password']))
{
    $username=$_SESSION['username'];
    $pass=$_SESSION['password'];
    
}
else
{
     echo '<META http-equiv="refresh" content="0;logout.php">';
}


$patid=$_POST['patid'];
if(isset($_POST['Pname'])){
    mysqli_query($db,"UPDATE patientdetails SET Name='$_POST[Pname]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}

if(isset($_POST['fhname'])){
    mysqli_query($db,"UPDATE patientdetails SET FHName='$_POST[fhname]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['contact1'])){
    mysqli_query($db,"UPDATE patientdetails SET Contact='$_POST[contact1]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['contact2'])){
    mysqli_query($db,"UPDATE patientdetails SET EmContact='$_POST[contact2]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['email'])){
    mysqli_query($db,"UPDATE patientdetails SET Email='$_POST[email]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['dob'])){
    mysqli_query($db,"UPDATE patientdetails SET Dob='$_POST[dob]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['age'])){
    mysqli_query($db,"UPDATE patientdetails SET Age='$_POST[age]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['Gender'])){
    mysqli_query($db,"UPDATE patientdetails SET Gender='$_POST[Gender]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['Blood'])){
    mysqli_query($db,"UPDATE patientdetails SET BloodGroup='$_POST[Blood]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['Weight'])){
    mysqli_query($db,"UPDATE patientdetails SET BodyWeight='$_POST[Weight]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['Height'])){
    mysqli_query($db,"UPDATE patientdetails SET Height='$_POST[Height]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['Aadhaar'])){
    mysqli_query($db,"UPDATE patientdetails SET AadhaarNo='$_POST[Aadhaar]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['Address'])){
    mysqli_query($db,"UPDATE patientdetails SET Address='$_POST[Address]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['Mark'])){
    mysqli_query($db,"UPDATE patientdetails SET Mark='$_POST[Mark]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}

if(isset($_POST['Consultant'])){
    mysqli_query($db,"UPDATE patientdetails SET Consultant='$_POST[Consultant]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['PatientType'])){
    mysqli_query($db,"UPDATE patientdetails SET PatientType='$_POST[PatientType]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['CaseType'])){
    mysqli_query($db,"UPDATE patientdetails SET CaseType='$_POST[CaseType]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['AdmitDate'])){
    mysqli_query($db,"UPDATE patientdetails SET AdmitDate='$_POST[AdmitDate]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['AdmitTime'])){
    mysqli_query($db,"UPDATE patientdetails SET AdmitTime='$_POST[AdmitTime]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['AdvanceAmount'])){
    mysqli_query($db,"UPDATE patientdetails SET AdvanceAmount='$_POST[AdvanceAmount]' WHERE PatId='$patid'");
    
    $ad=mysqli_query($db,"SELECT * FROM patientdetails WHERE PatId='$patid'");
    while($row=$ad->fetch_assoc()){
        $date=$row['AdmitDate'];
    }
   mysqli_query($db,"UPDATE advance SET Amount='$_POST[AdvanceAmount]' WHERE PatId='$patid' AND AdvanceDate='$date'"); 
    
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}
if(isset($_POST['PaymentMode'])){
    mysqli_query($db,"UPDATE patientdetails SET PaymentMode='$_POST[PaymentMode]' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}

if(isset($_FILES['Photo'])){
$fileName=$_FILES['Photo']['name'];
                        $fileTmpName=$_FILES['Photo']['tmp_name'];
                        $fileSize=$_FILES['Photo']['size'];
                        $fileError=$_FILES['Photo']['error'];
                        $fileType=$_FILES['Photo']['type'];

                        $fileExt=explode('.',$fileName);
                        $fileActualExt=strtolower(end($fileExt));
                        $allowed=array('jpg','jpeg','png','JPG','JPEG','PNG');

                        if(in_array($fileActualExt, $allowed))
                        {
                            if($fileError ===0){
                                if($fileSize<=3000000){
                                    $PfileNameNew=uniqid('',true).".".$fileActualExt;

    
                                    $fileDestination = '../../assets/PatientPhotos/'.$PfileNameNew;
                                    move_uploaded_file($fileTmpName, $fileDestination);  
                                }
                                else{
                                    echo "Your File Size is large";
                                }

                            }else{
                                    echo "Error Uploading File";
                                }
                            
                        }


    mysqli_query($db,"UPDATE patientdetails SET Photo='$PfileNameNew' WHERE PatId='$patid'");
    echo "<script>alert('Patient Data Updated!')</script>";
$url="/Billing/Admin/default/ViewMorePatient.php?patid=$patid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />"; 
}

