<?php
include("dbconfig.php");
if(isset($_POST['createFullName'])){
    mysqli_query($db,"INSERT INTO billlogin(Username,Password,Name) VALUES('$_POST[Username]','$_POST[Password]','$_POST[createFullName]')");
    echo "<script>alert('User Added!')</script>";

 $url="/Billing/Admin/default/ViewUsers.php";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";
}

if(isset($_POST['StaffName'])){
    $staffid=$_POST['StaffId'];
    $name=$_POST['StaffName'];
mysqli_query($db,"UPDATE staffdetails SET Name='$name' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";
}
if(isset($_POST['StaffGroup'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET StaffGroup='$_POST[StaffGroup]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";  
}
if(isset($_POST['StaffSpec'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET Specification='$_POST[StaffSpec]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";
}
if(isset($_POST['StaffFHN'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET FatherHusband='$_POST[StaffFHN]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";  
}

if(isset($_POST['StaffContact'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET Contact='$_POST[StaffContact]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";
}
if(isset($_POST['StaffEmContact'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET EmContact='$_POST[StaffEmContact]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";
 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";  
}
if(isset($_POST['StaffEmail'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET Email='$_POST[StaffEmail]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";  
}
if(isset($_POST['Staffdob'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET dob='$_POST[Staffdob]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";  
}

if(isset($_POST['StaffGender'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET Gender='$_POST[StaffGender]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";  
}
if(isset($_POST['StaffBlood'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET ='$_POST[StaffBlood]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";
}
if(isset($_POST['StaffEducation'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET Education='$_POST[StaffEducation]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";
}
if(isset($_POST['StaffAddress'])){
    $staffid=$_POST['StaffId'];
mysqli_query($db,"UPDATE staffdetails SET Address='$_POST[StaffAddress]' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";  
}
if(isset($_FILES['StaffPhoto'])){
    $staffid=$_POST['StaffId'];
    $fileName=$_FILES['StaffPhoto']['name'];
                        $fileTmpName=$_FILES['StaffPhoto']['tmp_name'];
                        $fileSize=$_FILES['StaffPhoto']['size'];
                        $fileError=$_FILES['StaffPhoto']['error'];
                        $fileType=$_FILES['StaffPhoto']['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/StaffPhotos/'.$PfileNameNew;
                                    move_uploaded_file($fileTmpName, $fileDestination);  
                                }
                                else{
                                    echo "Your File Size is large";
                                }

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




mysqli_query($db,"UPDATE staffdetails SET Photo='$PfileNameNew' WHERE StaffId='$staffid'");
echo "<script>alert('Data Updated!')</script>";

 $url="/Billing/Admin/default/ViewMoreStaff.php?StaffId=$staffid";
echo "<meta http-equiv=\"refresh\" content=\"0;url=$url\" />";
}


?>
