<?php
session_start();
include 'db.php';

if (!isset($_SESSION['candidate_id'])) {
    header("Location: login.php");
    exit();
}

$success = false;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    $candidate_id = $_SESSION['candidate_id'];

    $father_name = mysqli_real_escape_string($conn, $_POST['father_name']);
    $mother_name = mysqli_real_escape_string($conn, $_POST['mother_name']);
    $dob = $_POST['dob'];
    $gender = $_POST['gender'];
    $marital_status = $_POST['marital_status'];
    $blood_group = $_POST['blood_group'];
    $aadhaar = $_POST['aadhaar'];
    $pan = $_POST['pan'];
    $permanent_address = mysqli_real_escape_string($conn, $_POST['permanent_address']);
    $current_address = mysqli_real_escape_string($conn, $_POST['current_address']);

    $sql = "INSERT INTO candidate_onboarding
    (
        candidate_id,
        father_name,
        mother_name,
        dob,
        gender,
        marital_status,
        blood_group,
        aadhaar_number,
        pan_number,
        permanent_address,
        current_address
    )
    VALUES
    (
        '$candidate_id',
        '$father_name',
        '$mother_name',
        '$dob',
        '$gender',
        '$marital_status',
        '$blood_group',
        '$aadhaar',
        '$pan',
        '$permanent_address',
        '$current_address'
    )";

    if($conn->query($sql) === TRUE){
        $success = true;
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Personal Information</title>

<style>

body{
    font-family:Arial;
    background:#f5f5f5;
    padding:40px;
}

.box{
    background:#fff;
    max-width:700px;
    margin:auto;
    padding:30px;
    border-radius:10px;
}

input, select, textarea{
    width:100%;
    padding:14px;
    margin-top:10px;
    border:1px solid #ddd;
    border-radius:8px;
    box-sizing:border-box;
}

button{
    width:100%;
    background:#28a745;
    border:none;
    color:#fff;
    padding:15px;
    border-radius:8px;
    margin-top:20px;
    cursor:pointer;
}

</style>
</head>
<body>

<div class="box">

<?php if($success){ ?>

<h2>✅ Personal Information Saved</h2>

<a href="dashboard.php">
Back To Dashboard
</a>

<?php } else { ?>

<h2>Personal Information</h2>

<form method="POST">

<input type="text" name="father_name"
placeholder="Father Name" required>

<input type="text" name="mother_name"
placeholder="Mother Name" required>

<input type="date" name="dob" required>

<select name="gender" required>
<option value="">Gender</option>
<option>Male</option>
<option>Female</option>
<option>Other</option>
</select>

<select name="marital_status" required>
<option value="">Marital Status</option>
<option>Single</option>
<option>Married</option>
</select>

<input type="text" name="blood_group"
placeholder="Blood Group">

<input type="text" name="aadhaar"
placeholder="Aadhaar Number">

<input type="text" name="pan"
placeholder="PAN Number">

<textarea name="permanent_address"
placeholder="Permanent Address"></textarea>

<textarea name="current_address"
placeholder="Current Address"></textarea>

<button type="submit">
Save Personal Information
</button>

</form>

<?php } ?>

</div>

</body>
</html>