<?php

require_once __DIR__ . '/db_config.php';

$r = array();
$r["list"] = array();
$r["profile"]=array();
$r["dependent"]=array();
$r["address"]=array();
$r["experience"]=array();
$r["address"]=array();


if (isset($_POST["cname"]) ) {
 
$cname=$_POST["cname"];
$email=$_POST["mail"];
$id=$_POST["id"];
$list=json_decode($_POST["list"],true);
$status=$_POST["status"];

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

$profileQuery="SELECT Id,companyname,adminemailid,employeename,emp_id,emailid,mobilenumber,companytype,designation,groups,subgroup1,subgroup2,aadhar,middle_name,last_name,nationality,date_of_birth,gender,religion,blood_group,marital_status,dateandtime,signout,imagefilepath FROM signupdetails WHERE companyname='$cname' AND emailid='$email' ";
$result=mysqli_query($con,$profileQuery);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["profile"], $row);
    }
}

    $dependentQuery="SELECT email,dependent_name,relationship,mobile,date,createdby,createdtype FROM employee_dependent WHERE  email='$email'";

$result=mysqli_query($con,$dependentQuery);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["dependent"], $row);
    }
}

$addressQuery="SELECT email,permanent_door,permanent_addr1,permanent_addr2,permanent_city,permanent_state,permanent_zipcode,permanent_country,present_door,present_addr1,present_addr2,present_city,present_state,present_zipcode,present_country,date,created_by,created_type FROM  employee_address WHERE email='$email' ";

$result=mysqli_query($con,$addressQuery);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["address"], $row);
    }
}


$experienceQuery="SELECT email,companyname,jobtitle,from_date,to_date,job_description,date,createdby,createdtype FROM employee_work_experience WHERE email='$email'";

$result=mysqli_query($con,$experienceQuery);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["experience"], $row);
    }
}

$educationQuery="SELECT emailid,institution_name,degree,fieldofstudy,dateofcompletion,interests,date,createdby,createdtype FROM employee_education WHERE emailid='$email'";
$r["education"]=array();

$result=mysqli_query($con,$educationQuery);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["education"], $row);
    }
}

$passportQuery="SELECT pass_number,pass_emailid,pass_date_issue,surname,pass_Authority,pass_expiry,pass_datetime,pass_deleted,pass_created_by,pass_created_type FROM hcm_passport WHERE pass_emailid='$email'";
$r["passport"]=array();

$result=mysqli_query($con,$passportQuery);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["passport"], $row);
    }
}

$accountQuery="SELECT email_id,bank_name,account_number,ifsc_code,account_type,acc_date_time,acc_created_by,acc_created_type FROM hcm_employee_account_details WHERE email_id='$email'";
$r["account"]=array();
$result=mysqli_query($con,$accountQuery);
if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["account"], $row);
    }
}



    mysqli_close($con);

}

echo json_encode($r,JSON_UNESCAPED_SLASHES);


?>