HEX
Server: nginx/1.24.0
System: Linux webserver-one 6.8.0-101-generic #101-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 9 10:15:05 UTC 2026 x86_64
User: www-data (33)
PHP: 8.4.18
Disabled: NONE
Upload Files
File: /srv/www/rectt-csmcri.res.in/public_html/pdf_primary.php
<?php
// session_start();
include_once 'sites/config/config.php';

// Main function to get the HTML as a string for PDF
function getPrimaryDetailsHtml($user_id)
{
    global $conn; // Make sure $conn is available

    // Fetch primary details
    $stmt = $conn->prepare("SELECT * FROM primary_details WHERE user_id = ?");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $res = $stmt->get_result();
    $d = $res->fetch_assoc();

    // Fetch relatives
    $relatives = [];
    if ($d && strtolower($d['relative_in_csir']) == 'yes') {
        $stmt2 = $conn->prepare("SELECT * FROM relatives WHERE user_id = ?");
        $stmt2->bind_param("i", $user_id);
        $stmt2->execute();
        $relatives = $stmt2->get_result()->fetch_all(MYSQLI_ASSOC);
    }

    // Helper functions
    $addr_line = function ($prefix, $city, $district, $state, $pincode) {
        $addr = trim($prefix);
        if ($city) $addr .= ', ' . $city;
        if ($district && stripos($addr, $district) === false) $addr .= ', ' . $district;
        if ($state && stripos($addr, $state) === false) $addr .= ', ' . $state;
        if ($pincode) $addr .= ',' . $pincode;
        return $addr;
    };
    $yesno = function ($v) {
        return (strtolower($v) === 'yes') ? 'yes' : 'no';
    };
    $fieldval = function ($val) {
        return $val ? htmlspecialchars($val) : '<em>-</em>';
    };

    ob_start();
?>
    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>Primary Details (Minimal)</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                background: #fff;
                color: #222;
            }

            .main-table {
                width: 830px;
                margin: 0 auto 35px auto;
            }

            .info-table {
                width: 100%;
                border-collapse: collapse;
                font-size: 13px;
                margin-bottom: 10px;
            }

            .info-table td {
                padding: 8px 10px;
                vertical-align: top;
                border-bottom: 1px solid #eee;
            }

            .info-table tr:last-child td {
                border-bottom: none;
            }

            .label {
                width: 320px;
                color: #444;
                font-weight: 500;
            }

            .value {
                color: #000;
            }

            em {
                color: #aaa;
            }

            .rel-section-title {
                font-weight: bold;
                color: #333;
                margin: 18px 0 8px 6px;
                font-size: 14px;
            }

            .rel-table {
                width: 95%;
                margin: 10px 0 0 10px;
                border-collapse: collapse;
                font-size: 12px;
            }

            .rel-table th,
            .rel-table td {
                padding: 6px 10px;
                border-bottom: 1px solid #e4e4e4;
            }

            .rel-table th {
                background: #fafafb;
                color: #555;
                font-weight: bold;
            }

            .rel-table tr:last-child td {
                border-bottom: none;
            }
        </style>
    </head>

    <body>
        <?php if ($d): ?>
            <table class="main-table">
                <tr>
                    <td>
                        <table class="info-table">
                            <tr>
                                <td class="label">Name as per SSC / 10<sup>th</sup> certificate</td>
                                <td class="value"><?= $fieldval($d['ssc_name']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Name (Ever changed)</td>
                                <td class="value"><?= $yesno($d['has_name_changed']) ?></td>
                            </tr>
                            <?php if (strtolower($d['has_name_changed']) === 'yes'): ?>
                                <tr>
                                    <td class="label">If yes, then New Name</td>
                                    <td class="value"><?= $fieldval($d['new_name']) ?></td>
                                </tr>
                            <?php endif; ?>
                            <tr>
                                <td class="label">Father's Name</td>
                                <td class="value"><?= $fieldval($d['father_name']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Mother's Name</td>
                                <td class="value"><?= $fieldval($d['mother_name']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Date of Birth (DD-MM-YYYY)</td>
                                <td class="value"><?= $d['dob'] ? date('d-m-Y', strtotime($d['dob'])) : '<em>-</em>' ?></td>
                            </tr>
                            <tr>
                                <td class="label">Age</td>
                                <td class="value">
                                    <?php
                                    if ($d['dob']) {
                                        $from = new DateTime($d['dob']);
                                        $to = new DateTime('today');
                                        $years = $from->diff($to)->y;
                                        $months = $from->diff($to)->m;
                                        $days = $from->diff($to)->d;
                                        echo "{$years} years {$months} months {$days} days";
                                    } else {
                                        echo '<em>-</em>';
                                    }
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">Place of Birth</td>
                                <td class="value"><?= $fieldval($d['place_ob']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Citizenship</td>
                                <td class="value"><?= $fieldval($d['citizenship']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Gender</td>
                                <td class="value"><?= $fieldval($d['gender']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Religion</td>
                                <td class="value"><?= $fieldval($d['religion']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Are You Physically Disabled (More than or equal to 40%)</td>
                                <td class="value"><?= strtolower($d['disability']) == 'yes' ? 'yes' : 'no' ?></td>
                            </tr>
                            <tr>
                                <td class="label" colspan="2">
                                    a) Hard of hearing:
                                    <strong><?= strtolower($d['disability_hearing'] ?? '') === 'yes' ? 'Yes' : 'No' ?></strong>
                                    <br>
                                    b) Locomotor disability including cerebral palsy, leprosy cured, dwarfism, acid attack victims and muscular dystrophy:
                                    <strong><?= strtolower($d['disability_walking'] ?? '') === 'yes' ? 'Yes' : 'No' ?></strong>
                                    <br>
                                    c) Multiple disabilities from amongst persons under clauses (a) and (b):
                                    <strong><?= strtolower($d['disability_multiple'] ?? '') === 'yes' ? 'Yes' : 'No' ?></strong>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">Category</td>
                                <td class="value"><?= $fieldval($d['category']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Are you Ex-Servicemen</td>
                                <td class="value"><?= $yesno($d['ex_servicemen']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Length of service in Armed Forces</td>
                                <td class="value">
                                    <?php
                                    if (strtolower($d['ex_servicemen']) === 'yes') {
                                        echo ($d['service_years'] ?? '0') . ' Years, ' . ($d['service_months'] ?? '0') . ' Months, ' . ($d['service_days'] ?? '0') . ' Days';
                                    } else {
                                        echo 'Years, Months, days';
                                    }
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">Are you permanent Govt/Autonomous/Semi Govt/PSU employee?</td>
                                <td class="value"><?= $yesno($d['gov_employee']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">If Yes, details of the Organization, Post held</td>
                                <td class="value"><?= (strtolower($d['gov_employee']) === 'yes') ? $fieldval($d['gov_organization'] . ', ' . $d['gov_post']) : '<em>-</em>' ?></td>
                            </tr>
                            <tr>
                                <td class="label">Are you CSIR Employee?</td>
                                <td class="value"><?= $yesno($d['csir_employee']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">If yes, the name of Institute / lab &amp; Designation</td>
                                <td class="value"><?= (strtolower($d['csir_employee']) === 'yes') ? $fieldval($d['csir_lab'] . ', ' . $d['csir_designation']) : '<em>-</em>' ?></td>
                            </tr>
                            <tr>
                                <td class="label">Marital Status</td>
                                <td class="value"><?= $fieldval($d['marital_status']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Are you staying abroad</td>
                                <td class="value"><?= $yesno($d['staying_abroad']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Address of Correspondence</td>
                                <td class="value">
                                    <?= $fieldval($addr_line($d['corr_house'], $d['corr_city'], $d['corr_district'], $d['corr_state'], $d['corr_pincode'])) ?>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">Address of Permanent</td>
                                <td class="value">
                                    <?= $fieldval($addr_line($d['perm_house'], $d['perm_city'], $d['perm_district'], $d['perm_state'], $d['perm_pincode'])) ?>
                                </td>
                            </tr>
                            <tr>
                                <td class="label">Email id</td>
                                <td class="value"><?= $fieldval($d['email']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Secondary Email id</td>
                                <td class="value"><?= $fieldval($d['secondary_email']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Mobile</td>
                                <td class="value"><?= $fieldval($d['mobile']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Alternate Mobile</td>
                                <td class="value"><?= $fieldval($d['alt_mobile']) ?></td>
                            </tr>
                            <tr>
                                <td class="label">Any relative in CSIR?</td>
                                <td class="value"><?= $yesno($d['relative_in_csir']) ?></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>

            <?php if (count($relatives) > 0): ?>
                <div class="main-table">
                    <div class="rel-section-title">Relative(s) in CSIR:</div>
                    <table class="rel-table">
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Post</th>
                                <th>Lab/Institute</th>
                                <th>Relationship</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($relatives as $rel): ?>
                                <tr>
                                    <td><?= $fieldval($rel['relative_name']) ?></td>
                                    <td><?= $fieldval($rel['post']) ?></td>
                                    <td><?= $fieldval($rel['lab_institute']) ?></td>
                                    <td><?= $fieldval($rel['relationship']) ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
        <?php else: ?>
            <div style="color:#a00;text-align:center;margin-top:50px;">No data found.</div>
        <?php endif; ?>
    </body>

    </html>
<?php
    $data = ob_get_clean();
    return $data;
}


// $data = getPrimaryDetailsHtml(15);

// Example: Output for testing (remove/comment this in production)
// echo $data;

// require_once dirname(__DIR__) . "/vendor/autoload.php";

// // Use the custom temporary directory setting
// $mpdf = new \Mpdf\Mpdf([
//     "tempDir" => dirname(__DIR__) . "/tmp", // Custom writable tmp directory
// ]);

// // Define the output directory and filename
// $outputDir = "sites/upload"; // 'applications' folder outside public_html
// $outputFilename = "1SUMMMm" . ".pdf";

// $outputPath = $outputDir . "/" . $outputFilename;
// $mpdf->WriteHTML($data);
// $mpdf->Output($outputPath, "D");
?>