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/admin_html/view_tech.php
<?php
require_once dirname(__DIR__) . '/public_html/sites/config/config.php';
require_once 'view_primary.php'; // provides getPrimaryDetailsHtml_BS($user_id)

if (!isset($_SESSION['admin_logged_in']) || !in_array($_SESSION['admin_role'], ['superadmin', 'manager', 'reviewer'])) {
    header("Location: admin_dashboard.php");
    // echo $_SESSION['admin_role'];

    exit;
}
// 1) basic session checks
if (
    empty($_SESSION['admin_id']) || empty($_SESSION['session_token'])
) {
    header("Location: admin_login.php");
    exit;
}

// 2) pull the token (and role) from the database
$stmt = $conn->prepare("SELECT session_token FROM admin_users WHERE id = ?");
$stmt->bind_param("i", $_SESSION['admin_id']);
$stmt->execute();
$result = $stmt->get_result()->fetch_assoc();
$stmt->close();

// 3) if the DB token is gone or doesn’t match the session’s, force logout
if (
    ! $result || $result['session_token'] !== $_SESSION['session_token']
) {
    session_unset();
    session_destroy();
    header("Location: admin_login.php?error=" . urlencode("Your session has expired."));
    exit;
}

function getTechSummaryHtml($application_id, $application_type = 'tech')
{
    global $conn;

    // Fetch master ledger details for this tech application
    $stmt = $conn->prepare("SELECT registration_id, ad_id, post_id FROM all_applications WHERE application_table_id = ? AND application_type = ? LIMIT 1");
    $app_type = 'tech';
    $stmt->bind_param("is", $application_id, $app_type);
    $stmt->execute();
    $ledger = $stmt->get_result()->fetch_assoc();
    $stmt->close();

    $registration_id = $ledger['registration_id'] ?? '<em>-</em>';
    $ad_id = $ledger['ad_id'] ?? null;
    $post_id = $ledger['post_id'] ?? null;

    // Advertisement details (Advt No)
    $advt_no = '<em>-</em>';
    if ($ad_id) {
        $stmt = $conn->prepare("SELECT Ad_id FROM Advertisement WHERE id = ? LIMIT 1");
        if ($stmt) {
            $stmt->bind_param("i", $ad_id);
            $stmt->execute();
            $ad_result = $stmt->get_result()->fetch_assoc();
            $stmt->close();
            $advt_no = $ad_result['Ad_id'] ?? '<em>-</em>';
        }
    }

    // Post details (Post Code, Title, Category)
    $post_code = $post_name = $category = '<em>-</em>';
    if ($post_id) {
        $stmt = $conn->prepare("SELECT post_code, post_title, category FROM posts WHERE id = ? LIMIT 1");
        if ($stmt) {
            $stmt->bind_param("i", $post_id);
            $stmt->execute();
            $post_result = $stmt->get_result()->fetch_assoc();
            $stmt->close();
            $post_code = $post_result['post_code'] ?? '<em>-</em>';
            $post_name = $post_result['post_title'] ?? '<em>-</em>';
            $category = $post_result['category'] ?? '<em>-</em>';
        }
    }

    $lab_name = "CSIR-CSMCRI";
    $institute_name = "Central Salt and Marine Chemicals Research Institute";


    // Helper functions
    $fieldval = fn($v) => $v !== null && $v !== '' ? htmlspecialchars($v) : '<em class="text-muted">-</em>';
    $yesno = fn($v) => (strtolower($v) === 'yes') ? 'Yes' : 'No';
    $dateFormat = fn($d) => $d ? date('d-m-Y', strtotime($d)) : '<em class="text-muted">-</em>';

    // Fetch application (to get user_id)
    $stmt = $conn->prepare("SELECT * FROM tech_applications WHERE id = ?");
    $stmt->bind_param("i", $application_id);
    $stmt->execute();
    $app = $stmt->get_result()->fetch_assoc();
    $stmt->close();

    if (!$app) return "<div class='alert alert-danger text-center'>No data found.</div>";

    $user_id = $app['user_id'];

    // Fetch exemption-relevant details from primary_details
    $stmt = $conn->prepare("SELECT gender, ex_servicemen, csir_employee, category, disability FROM primary_details WHERE user_id = ?");
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $user_meta = $stmt->get_result()->fetch_assoc();
    $stmt->close();

    $gender = $user_meta['gender'] ?? '';
    $ex_servicemen = $user_meta['ex_servicemen'] ?? '';
    $csir_employee = $user_meta['csir_employee'] ?? '';
    $category_meta = $user_meta['category'] ?? 'General';
    $disability = $user_meta['disability'] ?? 'No';

    $is_exempt = (in_array($category_meta, ['SC', 'ST']) ||
        $gender === 'Female' ||
        $ex_servicemen === 'Yes' ||
        $csir_employee === 'Yes' ||
        $disability === 'Yes');


    // Fetch primary details HTML
    $primaryHtml = getPrimaryDetailsHtml_BS($user_id);

    // Fetch qualifications
    $stmt = $conn->prepare("SELECT * FROM tech_qualifications WHERE application_id = ? ORDER BY FIELD(qualification_type, 'ssc', 'hsc', 'iti')");
    $stmt->bind_param("i", $application_id);
    $stmt->execute();
    $quals = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
    $stmt->close();

    // Fetch trade details
    $stmt = $conn->prepare("SELECT * FROM tech_trade_details WHERE application_id = ?");
    $stmt->bind_param("i", $application_id);
    $stmt->execute();
    $trade = $stmt->get_result()->fetch_assoc();
    $stmt->close();

    // Fetch experience
    $stmt = $conn->prepare("SELECT * FROM tech_experience WHERE application_id = ?");
    $stmt->bind_param("i", $application_id);
    $stmt->execute();
    $exps = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
    $stmt->close();

    // Fetch uploads
    $uploads = [];
    $stmt = $conn->prepare("SELECT document_type, file_path FROM tech_uploads WHERE application_id = ?");
    $stmt->bind_param("i", $application_id);
    $stmt->execute();
    $res = $stmt->get_result();
    while ($row = $res->fetch_assoc()) $uploads[$row['document_type']] = $row['file_path'];
    $stmt->close();

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

    <head>
        <meta charset="UTF-8">
        <title>Technical Application Summary</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
        <style>
            .section-title {
                font-size: 1.15rem;
                font-weight: 500;
                color: #374151;
                margin: 30px 0 12px 0;
            }

            .table th,
            .table td {
                vertical-align: middle;
            }

            .sub-label {
                color: #888;
                font-size: 0.93em;
            }

            .not-uploaded {
                color: #b0b0b0;
                font-style: italic;
                text-align: center;
            }

            .photo-sign-img {
                max-width: 200px;
                width: 100%;
                height: auto;
                border: 2px solid #bbb;
                border-radius: 6px;
                background: #f9f9f9;
                margin: 0 auto;
            }

            .sign-img {
                max-width: 160px;
                width: 100%;
                height: auto;
                border: 2px solid #bbb;
                border-radius: 6px;
                background: #f9f9f9;
                margin: 0 auto;
            }

            .section-divider {
                border: none;
                border-top: 1px solid #ddd;
                margin: 40px 0 30px 0;
            }

            .max-card-width {
                max-width: 900px;
                margin-left: auto;
                margin-right: auto;
            }
        </style>
    </head>

    <body>
        <div class="container my-4">

            <div class="card shadow-sm mb-4 max-card-width">
                <div class="card shadow-sm mb-4">
                    <center>
                        <div class="row mb-2">
                            <div class="col-12 h5 mb-1"><?= htmlspecialchars($institute_name) ?></div>
                        </div>
                        <div class="row mb-1">
                            <div class="col-6"><b>Registration ID:</b> <?= htmlspecialchars($registration_id) ?></div>
                            <div class="col-6"><b>Advt No:</b> <?= htmlspecialchars($advt_no) ?></div>
                        </div>
                        <div class="row mb-1">
                            <div class="col-6"><b>Lab Name:</b> <?= htmlspecialchars($lab_name) ?></div>
                            <div class="col-6"><b>Post Code:</b> <?= htmlspecialchars($post_code) ?></div>
                        </div>
                        <div class="row mb-1">
                            <div class="col-12"><b>Name of Position:</b> <?= htmlspecialchars($post_name) ?> (<?= htmlspecialchars($category) ?>)</div>
                        </div>
                    </center>
                </div>


                <?= $primaryHtml ?>

                <div class="card shadow-sm mb-4">
                    <div class="card-body">

                        <div class="section-title">Educational Qualifications</div>
                        <table class="table table-bordered qual-table mb-4">
                            <thead class="table-light">
                                <tr>
                                    <th>Qualification</th>
                                    <th>School/College</th>
                                    <th>Board/University</th>
                                    <th>Subjects Studied</th>
                                    <th>Marks</th>
                                    <th>Scale</th>
                                    <th>Passing Date</th>
                                    <th>Mode of Study</th>
                                    <th>Remarks</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($quals as $q): ?>
                                    <tr>
                                        <td>
                                            <?php
                                            $type = strtolower($q['qualification_type']);
                                            switch ($type) {
                                                case 'ssc':
                                                    echo '10/SSC';
                                                    break;
                                                case 'hsc':
                                                    echo '12/XII/Intermediate';
                                                    break;
                                                case 'iti':
                                                    echo 'ITI Qualification';
                                                    break;
                                                default:
                                                    echo $fieldval($q['qualification_type']);
                                            }
                                            ?>
                                        </td>
                                        <td><?= $fieldval($q['school_name']) ?></td>
                                        <td><?= $fieldval($q['board_or_university']) ?></td>
                                        <td><?= $fieldval($q['subjects']) ?></td>
                                        <td><?= $fieldval($q['marks']) ?></td>
                                        <td><?= $fieldval($q['scale']) ?></td>
                                        <td><?= $dateFormat($q['pass_date']) ?></td>
                                        <td><?= $fieldval($q['mode_of_study']) ?></td>
                                        <td><?= $fieldval($q['remarks']) ?></td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>

                        <div class="section-title">Trade Details</div>
                        <table class="table table-bordered trade-table mb-4">
                            <thead class="table-light">
                                <tr>
                                    <th>Trade Name</th>
                                    <th>Trade Certificate</th>
                                    <th>Trade Board/Institute/Organization (with address)</th>
                                    <th>From</th>
                                    <th>To</th>
                                    <th>Year of Passing</th>
                                    <th>Percentage</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if ($trade): ?>
                                    <tr>
                                        <td><?= $fieldval($trade['trade_name']) ?></td>
                                        <td><?= $fieldval($trade['trade_certificate']) ?></td>
                                        <td><?= $fieldval($trade['trade_board']) ?></td>
                                        <td><?= $dateFormat($trade['from_date']) ?></td>
                                        <td><?= $dateFormat($trade['to_date']) ?></td>
                                        <td><?= $fieldval($trade['year_of_passing']) ?></td>
                                        <td><?= $fieldval($trade['percentage']) ?></td>
                                    </tr>
                                <?php else: ?>
                                    <tr>
                                        <td colspan="7" class="not-uploaded"><em>No trade details provided</em></td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>

                        <div class="section-title">Employment / Experience</div>
                        <table class="table table-bordered exp-table mb-4">
                            <thead class="table-light">
                                <tr>
                                    <th>Type of the Organization</th>
                                    <th>Name of the Organization</th>
                                    <th>Position Held</th>
                                    <th>From</th>
                                    <th>To</th>
                                    <th>Nature of Work</th>
                                    <th>Last Pay Drawn</th>
                                    <th>Status of Job</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if ($exps): foreach ($exps as $e): ?>
                                        <tr>
                                            <td><?= $fieldval($e['org_type']) ?></td>
                                            <td><?= $fieldval($e['organization']) ?></td>
                                            <td><?= $fieldval($e['position']) ?></td>
                                            <td><?= $dateFormat($e['from_date']) ?></td>
                                            <td><?= $dateFormat($e['to_date']) ?></td>
                                            <td><?= $fieldval($e['nature_of_work']) ?></td>
                                            <td><?= $fieldval($e['last_pay']) ?></td>
                                            <td><?= $fieldval($e['job_status']) ?></td>
                                        </tr>
                                    <?php endforeach;
                                else: ?>
                                    <tr>
                                        <td colspan="8" class="not-uploaded"><em>No experience provided</em></td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>

                        <div class="section-title">Uploaded Documents</div>
                        <table class="table table-bordered upload-table mb-4">
                            <thead class="table-light">
                                <tr>
                                    <th>Document Type</th>
                                    <th>File</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($uploads as $type => $path): ?>
                                    <?php if (!in_array($type, ['photograph', 'signature'], true)): ?>
                                        <tr>
                                            <td>
                                                <?php
                                                $labels = [
                                                    'ssc_marksheet'         => '10/SSC Marksheet',
                                                    'hsc_marksheet'         => '12/XII/Intermediate Marksheet',
                                                    'trade_certificate'     => 'Trade Certificate',
                                                    'category_certificate'  => 'Category Certificate',
                                                    'disability_certificate' => 'Disability Certificate',
                                                ];
                                                echo htmlspecialchars($labels[$type] ?? ucwords(str_replace('_', ' ', $type)), ENT_QUOTES, 'UTF-8');
                                                ?>
                                            </td>
                                            <td>
                                                <?php if ($path): ?>
                                                    <a href="<?= htmlspecialchars('../public_html/' . $path) ?>" target="_blank" class="btn btn-sm btn-primary">View</a>
                                                <?php else: ?>
                                                    <span class="not-uploaded">No</span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </tbody>
                        </table>

                        <div class="row my-4">
                            <div class="col-md-6 text-center">
                                <div class="fw-bold">Photograph</div>
                                <?php if (!empty($uploads['photograph'])): ?>
                                    <img class="photo-sign-img" src="<?= htmlspecialchars('../public_html/' . $uploads['photograph']) ?>">
                                <?php else: ?>
                                    <div class="not-uploaded">Not uploaded</div>
                                <?php endif; ?>
                            </div>
                            <div class="col-md-6 text-center">
                                <div class="fw-bold">Signature</div>
                                <?php if (!empty($uploads['signature'])): ?>
                                    <img class="sign-img" src="<?= htmlspecialchars('../public_html/' . $uploads['signature']) ?>">
                                <?php else: ?>
                                    <div class="not-uploaded">Not uploaded</div>
                                <?php endif; ?>
                            </div>
                        </div>

                        <div class="mb-3">
                            <span class="fw-bold">Additional Remarks: </span>
                            <?= $fieldval($app['additional_remarks']) ?>
                        </div>
                        <div class="mb-3">
                            <span class="fw-bold">Payment Reference: </span>
                            <?= $fieldval($app['payment_reference_no']) ?>
                        </div>
                        <?php if (!$is_exempt): ?>
                            <div class="mb-3">
                                <span class="fw-bold">Payment Date: </span>
                                <?= $dateFormat($app['payment_date'] ?? '') ?>
                            </div>
                        <?php endif; ?>


                        <div class="alert alert-success mt-4" style="font-size: 1rem;">
                            <span class="me-2"><i class="bi bi-check2-square"></i></span>
                            I, hereby, declare that all the statements made in this application are true, complete and correct to the best of my knowledge and belief.
                            In the event of any information being found false or incorrect or any ineligibility being detected before or after the selection, my candidature is liable to be cancelled and action can be initiated against me.
                        </div>
                        <div class="text-end text-muted mt-4">
                            <b>Submitted On:</b> <?= $dateFormat($app['created_at'] ?? '') ?>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </body>

    </html>
<?php
    return ob_get_clean();
}
// echo getTechSummaryHtml(10);

?>