<?php  

session_start();
if(!$_SESSION['id']){
    header('location:index.php');
}

  require_once '../system/conn.php';
  
    $stmt = $conn->prepare("SELECT * FROM `emp_details` WHERE `sn`=?");
    $stmt->execute([$_POST['id']]);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);

    $candidate= $conn->prepare("SELECT * FROM `candidate_details` WHERE `full_name`=?");
    $candidate->execute([$row['e_name']]);
    $cand = $candidate->fetch(PDO::FETCH_ASSOC);
?>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">

<style>
    .letter-container {
        width: 800px;
        margin: 50px auto;
        padding: 40px;
        border: 2px solid #000;
        background-color: #fff;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
        font-family: 'Arial', sans-serif;
    }

    .header {
        text-align: center;
        margin-bottom: 30px;
    }

    .header img {
        width: 100px;
        margin-bottom: 10px;
    }

    .header h1 {
        font-size: 22px;
        text-transform: uppercase;
        margin: 0;
        font-weight: bold;
    }

    .sub-header {
        text-align: center;
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 20px;
    }

    .details-table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 20px;
    }

    .details-table td {
        padding: 8px;
        border-bottom: 1px solid #ddd;
        font-size: 16px;
    }

    .details-table td:first-child {
        font-weight: bold;
        width: 30%;
    }

    .signature-section {
        margin-top: 40px;
        display: flex;
        justify-content: space-between;
    }

    .signature-block {
        text-align: center;
    }

    .signature-block p {
        margin-top: 60px;
        border-top: 1px solid #000;
        padding-top: 5px;
        font-weight: bold;
    }
</style>

<div class="letter-container">
    <div class="header">
        <img src="http://hr.utcpl.co.in/hrm/admin/assets/images/logo-utcpl.webp" alt="Company Logo">
        <h1>UTKAL TEAM CARE PVT LTD</h1>
        <p class="sub-header">FOR OFFICE USE ONLY</p>
    </div>

    <table class="details-table">
        <tr>
            <td>Name of the Candidate</td>
            <td>: <?php echo htmlspecialchars($row['e_name']); ?></td>
        </tr>
        <tr>
            <td>Date of Interview</td>
            <td>: <?php echo htmlspecialchars($cand['doi']); ?></td>
        </tr>
        <tr>
            <td>Date of Joining</td>
            <td>: <?php echo htmlspecialchars($row['e_doj']); ?></td>
        </tr>
        <tr>
            <td>Working Site</td>
            <td>: <?php 
            $branch = $row['branch'];

            $b = $conn->prepare("SELECT * FROM `site` WHERE `id` = ?");
            $b->execute([$branch]);
            $row1 = $b->fetch(PDO::FETCH_ASSOC);
                echo $row1['name'];
            ?></td>
        </tr>
        <tr>
            <td>Designation</td>
            <td>: <?php echo htmlspecialchars($row['designation']); ?></td>
        </tr>
        <tr>
            <td>Salary (Gross Pay)</td>
            <td>: ₹<?php echo htmlspecialchars($row['salary']); ?></td>
        </tr>
        <tr>
            <td>Duty Hours</td>
            <td>: <?php echo htmlspecialchars($cand['duty']); ?> hours</td>
        </tr>
    </table>

    <div class="signature-section">
        <div class="signature-block">
            <p>Candidate's Signature</p>
            <p style="text-align: right;border:0!important; margin-top: 20px;">
                <strong>Date:</strong> <?php echo date("d-m-Y"); ?><br>
                <strong>Time:</strong> <?php echo date("h:i A"); ?>
            </p>
        </div>
        <div class="signature-block">
            <p>Authorized Person's Signature</p>
        </div>
        <div class="signature-block">
            <p>DGM's Signature</p>
        </div>
    </div>
    <hr>
<footer>
    <p style="text-align:center"><strong><big>UTKAL Team Care(p) Ltd.</big></strong></p>
</footer>
    
</div>
