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/tech_form.php
<?php
session_start();
include_once 'sites/config/config.php';

if (!isset($_SESSION['registered']) || $_SESSION['registered'] !== "registered") {
    header("location: login.php");
    exit;
}

if (!isset($_SESSION['primary_saved']) || $_SESSION['primary_saved'] !== 'Yes') {
    header("Location: primary.php");
    exit();
}

if (!isset($_SESSION['user_id'], $_SESSION['ad_id'], $_SESSION['category'], $_SESSION['disability'])) {
    header("location: login.php");
    exit;
}

if (!isset($_SESSION['user_id'], $_SESSION['session_token'])) {
    session_destroy();
    header("Location: logout.php");
    exit;
}

$user_id = $_SESSION['user_id'];
$token = $_SESSION['session_token'];

$stmt = $conn->prepare("SELECT session_token FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$stmt->bind_result($db_token);
$stmt->fetch();
$stmt->close();

if ($token !== $db_token) {
    session_destroy();
    die("You have been logged out because your account was logged in elsewhere.");
}

// $user_id = $_SESSION['user_id'];
$ad_id = $_SESSION['ad_id'];
$category = $_SESSION['category'];
$disability = $_SESSION['disability'];
$post_id = $_GET['post_id'] ?? null;
if (!$post_id) {
    die("Invalid access - post ID missing.");
}

// Only allow access if this post_id matches the one the user picked in dashboard
if (!isset($_SESSION['active_post_id']) || $_SESSION['active_post_id'] != $post_id) {
    echo '<div class="alert alert-danger text-center mt-5">
        You have not started this application from the dashboard, or you have canceled your application.<br>
        <a href="dashboard.php" class="btn btn-primary btn-sm mt-3">Back to Dashboard</a>
    </div>';
    exit;
}
?>
<?php
if (!empty($_SESSION['flash'])) {
    if (is_array($_SESSION['flash'])) {
        foreach ($_SESSION['flash'] as $msg) {
            echo "<div class='alert alert-danger text-center'>" . htmlspecialchars($msg) . "</div>";
        }
    } else {
        echo "<div class='alert alert-danger text-center'>" . htmlspecialchars($_SESSION['flash']) . "</div>";
    }
    unset($_SESSION['flash']);
}

// Fetch Advertisement details
$ad_stmt = $conn->prepare("SELECT Ad_id, title FROM Advertisement WHERE id = ? LIMIT 1");
$ad_stmt->bind_param("i", $ad_id);
$ad_stmt->execute();
$ad_data = $ad_stmt->get_result()->fetch_assoc();
$ad_stmt->close();

$ad_id_val = $ad_data['Ad_id'] ?? '-';
$ad_title = $ad_data['title'] ?? '-';

// Fetch Post details
$post_stmt = $conn->prepare("SELECT post_title FROM posts WHERE id = ? LIMIT 1");
$post_stmt->bind_param("i", $post_id);
$post_stmt->execute();
$post_data = $post_stmt->get_result()->fetch_assoc();
$post_stmt->close();

$post_title = $post_data['post_title'] ?? '-';

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Technical Application</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        select.form-select.form-select-sm.form-select-a {
            width: auto;
        }
    </style>
</head>

<body class="bg-light">
    <div class="container mt-5">
        <center>
            <h2 class="mb-2">
                Technical Application Form
            </h2>
            <div class="mb-2" style="font-size: 1.05rem;">
                <b>Advertisement ID:</b> <?= htmlspecialchars($ad_id_val) ?>
                &nbsp; | &nbsp;
                <b>Advertisement Title:</b> <?= htmlspecialchars($ad_title) ?>
                &nbsp; | &nbsp;
                <b>Post ID:</b> <?= htmlspecialchars($post_id) ?>
                &nbsp; | &nbsp;
                <b>Post Title:</b> <?= htmlspecialchars($post_title) ?>
            </div>
            <div class="mb-3">
                <a href="dashboard.php" class="btn btn-primary">
                    &larr; Back to Dashboard
                </a>
            </div>
        </center>

        <form method="POST" action="process_tech.php" enctype="multipart/form-data" id="applicationForm">
            <input type="hidden" name="post_id" value="<?= htmlspecialchars($post_id) ?>">
            <input type="hidden" name="ad_id" value="<?= htmlspecialchars($ad_id) ?>">

            <hr class="my-4">

            <!-- Educational Section -->
            <div class="form-section mb-4">
                <h5>Educational Qualifications</h5>
                <div class="table-responsive">
                    <table class="table table-bordered align-middle">
                        <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 (1st Class, 2nd Class, 1st Class with Distinction, University top etc)</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $levels = [
                                'ssc' => '10/SSC<span class="text-danger">*</span>',
                                'hsc' => '12/XII/Intermediate',
                                'iti' => 'ITI Qualification'
                            ];

                            foreach ($levels as $key => $label): ?>
                                <tr>
                                    <td><strong><?= $label ?></strong></td>
                                    <td><input type="text" name="<?= $key ?>_school" class="form-control" <?= $key == 'ssc' ? 'required' : '' ?>></td>
                                    <td><input type="text" name="<?= $key ?>_board" class="form-control" <?= $key == 'ssc' ? 'required' : '' ?>></td>
                                    <td><input type="text" name="<?= $key ?>_subjects" class="form-control" <?= $key == 'ssc' ? 'required' : '' ?>></td>
                                    <td><input type="number" step="0.01" name="<?= $key ?>_marks" class="form-control" <?= $key == 'ssc' ? 'required' : '' ?>></td>
                                    <td>
                                        <select name="<?= $key ?>_scale" class="form-select form-select-sm form-select-a" <?= $key == 'ssc' ? 'required' : '' ?>>
                                            <option value="">Select Scale</option>
                                            <option value="percentage">Percentage</option>
                                            <option value="cgpa10">CGPA (Out of 10)</option>
                                            <option value="cgpa5">CGPA (Out of 5)</option>
                                        </select>
                                    </td>
                                    <td><input type="date" name="<?= $key ?>_pass_date" class="form-control" <?= $key == 'ssc' ? 'required' : '' ?>>
                                    </td>
                                    <td>
                                        <select name="<?= $key ?>_mode" class="form-select form-select-sm form-select-a" <?= $key == 'ssc' ? 'required' : '' ?>>
                                            <option value="">Select</option>
                                            <option value="Regular">Regular</option>
                                            <option value="Distance">Distance</option>
                                            <option value="Online">Online</option>
                                        </select>
                                    </td>
                                    <td><input type="text" name="<?= $key ?>_remarks" class="form-control"></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>

            <hr class="my-4">

            <!-- Trade Details Section -->
            <div class="form-section mb-4">
                <h5 class="mb-3">Trade Details</h5>
                <div class="row g-3">
                    <div class="col-md-4">
                        <label for="trade_name" class="form-label">Name of the Trade</label>
                        <input type="text" id="trade_name" name="trade_name" class="form-control">
                    </div>

                    <div class="col-md-4">
                        <label for="trade_certificate" class="form-label">Certificate</label>
                        <input type="text" id="trade_certificate" name="trade_certificate" class="form-control">
                    </div>

                    <div class="col-md-4">
                        <label for="trade_board" class="form-label">Name of the Board/Institute/Organization (with address)</label>
                        <input type="text" id="trade_board" name="trade_board" class="form-control">
                    </div>

                    <div class="col-md-3">
                        <label for="trade_from_date" class="form-label">From Date</label>
                        <input type="date" id="trade_from_date" name="trade_from_date" class="form-control">
                    </div>

                    <div class="col-md-3">
                        <label for="trade_to_date" class="form-label">To Date</label>
                        <input type="date" id="trade_to_date" name="trade_to_date" class="form-control">
                    </div>

                    <div class="col-md-3">
                        <label for="trade_year" class="form-label">Year of Passing</label>
                        <input type="number" id="trade_year" name="trade_year" class="form-control" min="1900" max="2099">
                    </div>

                    <div class="col-md-3">
                        <label for="trade_percentage" class="form-label">Percentage</label>
                        <input type="number" step="0.01" id="trade_percentage" name="trade_percentage" class="form-control">
                    </div>
                </div>
            </div>


            <hr class="my-4">

            <!-- Uploads Section -->
            <div class="row form-section mb-4 g-2">
                <h5>Upload Documents</h5>
                <?php
                function uploadField($label, $name, $required, $extra = '', $maxSizeKB = 1024, $onlyImages = false)
                {
                    $req = $required ? 'required' : '';
                    $accept = $onlyImages ? 'accept=".jpg,.jpeg,.png"' : 'accept=".pdf,.jpg,.jpeg,.png"';
                    echo "<div class='col-auto mb-3'>";
                    echo "<label class='form-label'><strong>{$label}</strong></label>";
                    echo "<input type='file' name='{$name}' class='form-control form-control-sm upload-check' data-max='{$maxSizeKB}' {$accept} {$req}> {$extra}";
                    echo "</div>";
                }

                // Category/Disability: (PDF or image, max 1MB)
                if ($category !== 'General') {
                    uploadField('Category Certificate in Central Government format from competent authority need to be attached<span class="text-danger">*</span><small><a href="sites/formats/Anenxure_II_IV_Caste_Certificate.pdf" target="_blank">click here for format</a></small>', 'category_certificate', true, "<small class='text-muted'>Max 1MB</small>", 1024, false);
                }

                if ($disability === 'Yes') {
                    uploadField('Disability Certificate from competent authority need to be attached in case of PWD (Divyang) &
whose disability not less than 40%]<span class="text-danger">*</span><small><a href="sites/formats/Annexure_VI_Disability_Certificate.pdf" target="_blank">click here for format</a></small>', 'disability_certificate', true, "<small class='text-muted'>Max 1MB</small>", 1024, false);
                }

                // Marksheet (PDF or image, max 1MB)
                uploadField('10/SSC Marksheet<span class="text-danger">*</span>', 'ssc_marksheet', true, "<small class='text-muted'>Max 1MB</small>", 1024, false);
                uploadField('12/XII/Intermediate Marksheet', 'hsc_marksheet', false, "<small class='text-muted'>Max 1MB</small>", 1024, false);

                // 💥 New: Trade Certificate Upload
                uploadField('Trade Certificate', 'trade_certificate', false, "<small class='text-muted'>Max 1MB</small>", 1024, false);

                // Photograph and Signature (image only, max 100KB)
                uploadField('Photograph<span class="text-danger">*</span><small><a href="sites/formats/Photograph_Requirements.pdf" target="_blank">click here for format</a></small>', 'photograph', true, "<small class='text-muted'>Max 100KB, JPG/PNG</small>", 100, true);
                uploadField('Signature<span class="text-danger">*</span><small><a href="sites/formats/Signature_Requirements.pdf" target="_blank">click here for format</a></small>', 'signature', true, "<small class='text-muted'>Max 100KB, JPG/PNG</small>", 100, true);
                ?>
            </div>

            <hr class="my-4">

            <!-- Remarks -->
            <div class="form-section mb-4">
                <label class="form-label">Additional Remarks (optional)</label>
                <textarea
                    name="additional_remarks"
                    class="form-control"
                    id="additional_remarks"
                    rows="2"
                    placeholder="Any other information you'd like to share"
                    oninput="limitWords(this, 'remarks_counter', 70)"></textarea>
                <div class="text-end"><small id="remarks_counter">0/70 words</small></div>
            </div>

            <hr class="my-4">

            <!-- Payment Reference -->
            <!-- Payment Reference -->
            <div class="row form-section mb-4">
                <div class="col-auto">
                    <label class="form-label">Payment Reference No<span class="text-danger">*</span></label>
                </div>
                <div class="col-auto">
                    <?php
                    $is_exempt = in_array($category, ['SC', 'ST']) || $_SESSION['gender'] === 'Female' || $_SESSION['ex_servicemen'] === 'Yes' || $_SESSION['csir_employee'] === 'Yes' || $disability === 'Yes';
                    ?>
                    <input type="text" name="paymentReferenceNo"
                        class="form-control form-control-sm"
                        required <?= $is_exempt ? 'readonly value="Fee Exempted"' : '' ?>>
                </div>

                <?php if (!$is_exempt): ?>
                    <div class="col-auto">
                        <label class="form-label">Payment Date<span class="text-danger">*</span></label>
                    </div>
                    <div class="col-auto">
                        <input type="date" name="payment_date"
                            class="form-control form-control-sm"
                            required>
                    </div>
                <?php endif; ?>
            </div>


            <hr class="my-4">

            <!-- Work Experience Section -->
            <div class="form-section mb-4">
                <h5>Work Experience (if any)</h5>
                <div id="experienceContainer">
                    <div class="experience-block mb-3 p-3 border rounded">
                        <div class="row g-2">
                            <div class="col-md-3">
                                <label class="form-label">Type of Organization</label>
                                <input type="text" name="experience[0][org_type]" class="form-control">
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Name of Organization</label>
                                <input type="text" name="experience[0][organization]" class="form-control">
                            </div>
                            <div class="col-md-2">
                                <label class="form-label">Position Held</label>
                                <input type="text" name="experience[0][position]" class="form-control">
                            </div>
                            <div class="col-md-2">
                                <label class="form-label">From</label>
                                <input type="date" name="experience[0][from]" class="form-control">
                            </div>
                            <div class="col-md-2">
                                <label class="form-label">To</label>
                                <input type="date" name="experience[0][to]" class="form-control">
                            </div>
                            <div class="col-md-3">
                                <label class="form-label">Nature of Work</label>
                                <input type="text" name="experience[0][nature]" class="form-control">
                            </div>
                            <div class="col-md-2">
                                <label class="form-label">Last Pay Drawn</label>
                                <input type="text" name="experience[0][last_pay]" class="form-control">
                            </div>
                            <div class="col-md-2">
                                <label class="form-label">Status of Job</label>
                                <input type="text" name="experience[0][status]" class="form-control">
                            </div>
                            <div class="col-md-2 d-flex align-items-end">
                                <button type="button" class="btn btn-danger removeExperienceBtn">Remove</button>
                            </div>
                        </div>
                    </div>
                </div>
                <button type="button" class="btn btn-primary mt-2" onclick="addExperience()">Add Experience</button>
            </div>

            <hr class="my-4">

            <!-- Declaration -->
            <div class="form-section mb-4">
                <h5>Declaration</h5>
                <p>I, hereby declare that the particulars given in the application form are true, complete and appropriate as per my knowledge and belief and if any information given by me is found false or inappropriate or before and after selection if any ineligibility comes to the notice, then my candidature would liable to be cancelled/terminated at any stage of selection & appointment without any notice and action may be taken against me.</p>
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" name="agree" value="1" required>
                    <label class="form-check-label">I Agree</label>
                </div>
            </div>

            <div class="text-center">
                <button type="submit" name="submit" class="btn btn-primary btn-lg" onclick="return confirm('Submit this application? This cannot be undone.')">Submit Application</button>
            </div>
        </form>
    </div>

    <script>
        function addExperience() {
            const container = document.getElementById('experienceContainer');
            const index = container.querySelectorAll('.experience-block').length;

            const block = document.createElement('div');
            block.className = 'experience-block mb-3 p-3 border rounded';
            block.innerHTML = `
        <div class="row g-2">
            <div class="col-md-3">
                <label class="form-label">Type of Organization</label>
                <input type="text" name="experience[${index}][org_type]" class="form-control">
            </div>
            <div class="col-md-3">
                <label class="form-label">Name of Organization</label>
                <input type="text" name="experience[${index}][organization]" class="form-control">
            </div>
            <div class="col-md-2">
                <label class="form-label">Position Held</label>
                <input type="text" name="experience[${index}][position]" class="form-control">
            </div>
            <div class="col-md-2">
                <label class="form-label">From</label>
                <input type="date" name="experience[${index}][from]" class="form-control">
            </div>
            <div class="col-md-2">
                <label class="form-label">To</label>
                <input type="date" name="experience[${index}][to]" class="form-control">
            </div>
            <div class="col-md-3">
                <label class="form-label">Nature of Work</label>
                <input type="text" name="experience[${index}][nature]" class="form-control">
            </div>
            <div class="col-md-2">
                <label class="form-label">Last Pay Drawn</label>
                <input type="text" name="experience[${index}][last_pay]" class="form-control">
            </div>
            <div class="col-md-2">
                <label class="form-label">Status of Job</label>
                <input type="text" name="experience[${index}][status]" class="form-control">
            </div>
            <div class="col-md-2 d-flex align-items-end">
                <button type="button" class="btn btn-danger removeExperienceBtn">Remove</button>
            </div>
        </div>`;
            container.appendChild(block);
        }

        document.addEventListener('click', function(e) {
            if (e.target.classList.contains('removeExperienceBtn')) {
                e.target.closest('.experience-block').remove();
            }
        });
        document.getElementById('applicationForm').addEventListener('submit', function(e) {
            const uploadInputs = document.querySelectorAll('.upload-check');
            let valid = true;
            let errorMsg = "";

            uploadInputs.forEach(function(input) {
                if (input.files.length) {
                    const file = input.files[0];
                    const maxSizeKB = parseInt(input.getAttribute('data-max')) || 1024;
                    const onlyImages = input.accept.includes('.pdf') ? false : true;

                    // Check file size
                    if (file.size > maxSizeKB * 1024) {
                        valid = false;
                        errorMsg += `${input.previousElementSibling.innerText}: File size should not exceed ${maxSizeKB}KB.\n`;
                    }

                    // Check file type
                    const ext = file.name.split('.').pop().toLowerCase();
                    if (onlyImages) {
                        if (!['jpg', 'jpeg', 'png'].includes(ext)) {
                            valid = false;
                            errorMsg += `${input.previousElementSibling.innerText}: Only JPG, JPEG, PNG images allowed.\n`;
                        }
                    } else {
                        if (!['pdf', 'jpg', 'jpeg', 'png'].includes(ext)) {
                            valid = false;
                            errorMsg += `${input.previousElementSibling.innerText}: Only PDF, JPG, JPEG, PNG files allowed.\n`;
                        }
                    }
                }
            });

            if (!valid) {
                alert(errorMsg.trim());
                e.preventDefault();
            }
        });

        function limitWords(textarea, counterId, maxWords) {
            let text = textarea.value;
            // Split by whitespace, filter out empty strings
            let words = text.trim().split(/\s+/).filter(Boolean);
            if (words.length > maxWords) {
                // Limit to maxWords
                words = words.slice(0, maxWords);
                textarea.value = words.join(" ");
            }
            document.getElementById(counterId).innerText = words.length + "/" + maxWords + " words";
        }

        // Instantly validate uploads as soon as user selects a file
        document.querySelectorAll('.upload-check').forEach(function(input) {
            input.addEventListener('change', function() {
                if (!input.files.length) return;

                const file = input.files[0];
                const maxSizeKB = parseInt(input.getAttribute('data-max')) || 1024;
                const onlyImages = input.accept.includes('.pdf') ? false : true;
                const label = input.previousElementSibling.innerText;

                // Size check
                if (file.size > maxSizeKB * 1024) {
                    alert(`${label}: File size should not exceed ${maxSizeKB}KB.`);
                    input.value = ''; // Clear the input
                    return;
                }

                // Type check
                const ext = file.name.split('.').pop().toLowerCase();
                if (onlyImages) {
                    if (!['jpg', 'jpeg', 'png'].includes(ext)) {
                        alert(`${label}: Only JPG, JPEG, PNG images allowed.`);
                        input.value = '';
                        return;
                    }
                } else {
                    if (!['pdf', 'jpg', 'jpeg', 'png'].includes(ext)) {
                        alert(`${label}: Only PDF, JPG, JPEG, PNG files allowed.`);
                        input.value = '';
                        return;
                    }
                }
            });
        });
    </script>

</body>

</html>