« Back to History
career_apply.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================ File: /erp/career_apply.php Purpose: Public Candidate Application Page (NO LOGIN REQUIRED) ============================================================================ */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors', '1'); /* ================= CONTEXT & CONNECTION LOADING ================= */ require_once __DIR__ . '/modules/auth/page_acl.php'; if (isset($ctx) && is_array($ctx)) { $pdo = $ctx['pdo'] ?? null; } if (!isset($pdo) || $pdo === null) { if (isset($conn) && $conn !== null) { $pdo = $conn; } elseif (isset($db) && $db !== null) { $pdo = $db; } else { die("System database connection initialize nahi ho paya."); } } // URL Parameter (?cid=X) ya session se company filtering $COMPANY_ID = 1; if (isset($_GET['cid']) && (int)$_GET['cid'] > 0) { $COMPANY_ID = (int)$_GET['cid']; } elseif (isset($_SESSION['company_id'])) { $COMPANY_ID = (int)$_SESSION['company_id']; } function j($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } $message = ''; $error = ''; /* ================= FETCH OPEN JOBS WITH SAFE COLUMN CHECK ================= */ try { $checkStmt = $pdo->prepare("SHOW COLUMNS FROM jobs LIKE 'location'"); $checkStmt->execute(); $hasLocation = $checkStmt->fetch(); $checkAddrStmt = $pdo->prepare("SHOW COLUMNS FROM jobs LIKE 'company_address'"); $checkAddrStmt->execute(); $hasAddress = $checkAddrStmt->fetch(); if ($hasLocation && $hasAddress) { $sql = "SELECT id, job_code, title, department, location, company_address FROM jobs WHERE company_id = ? AND status = 'Open' ORDER BY id DESC"; } elseif ($hasLocation) { $sql = "SELECT id, job_code, title, department, location, '' AS company_address FROM jobs WHERE company_id = ? AND status = 'Open' ORDER BY id DESC"; } else { $sql = "SELECT id, job_code, title, department, 'Not Specified' AS location, '' AS company_address FROM jobs WHERE company_id = ? AND status = 'Open' ORDER BY id DESC"; } $stmt = $pdo->prepare($sql); $stmt->execute([$COMPANY_ID]); $open_jobs = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $error = "Jobs load nahi ho payin: " . $e->getMessage(); $open_jobs = []; } /* ================= HANDLE FORM SUBMISSION ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'apply_job') { try { $pdo->beginTransaction(); $name = trim($_POST['name']); $mobile = trim($_POST['mobile']); $whatsapp = trim($_POST['whatsapp']); $job_id = (int)$_POST['job_id']; $experience = trim($_POST['experience']); $current_salary = !empty($_POST['current_salary']) ? (float)$_POST['current_salary'] : 0.00; $expected_salary = !empty($_POST['expected_salary']) ? (float)$_POST['expected_salary'] : 0.00; if (empty($name) || empty($mobile) || empty($job_id)) { throw new Exception("Full Name, Mobile, aur Position Applied mandatory hain."); } $job_stmt = $pdo->prepare("SELECT company_id FROM jobs WHERE id = ?"); $job_stmt->execute([$job_id]); $job_data = $job_stmt->fetch(PDO::FETCH_ASSOC); if (!$job_data) { throw new Exception("Chuni gayi position valid nahi hai."); } $TARGET_COMPANY_ID = (int)$job_data['company_id']; // 1. INSERT INTO candidates (Corrected column names) $stmt = $pdo->prepare(" INSERT INTO candidates (company_id, full_name, mobile, whatsapp, total_experience, current_salary, expected_salary, status) VALUES (?, ?, ?, ?, ?, ?, ?, 'New') "); $stmt->execute([$TARGET_COMPANY_ID, $name, $mobile, $whatsapp, $experience, $current_salary, $expected_salary]); $candidate_id = $pdo->lastInsertId(); // 2. INSERT INTO job_applications $stmt = $pdo->prepare(" INSERT INTO job_applications (company_id, candidate_id, job_id, application_status, applied_at) VALUES (?, ?, ?, 'New', CURRENT_TIMESTAMP) "); $stmt->execute([$TARGET_COMPANY_ID, $candidate_id, $job_id]); // 3. HANDLE RESUME UPLOAD if (isset($_FILES['resume']) && $_FILES['resume']['error'] === UPLOAD_ERR_OK) { $file_tmp = $_FILES['resume']['tmp_name']; $file_original_name = $_FILES['resume']['name']; $file_ext = strtolower(pathinfo($file_original_name, PATHINFO_EXTENSION)); $allowed_exts = ['pdf', 'doc', 'docx', 'jpg', 'jpeg', 'png']; if (!in_array($file_ext, $allowed_exts)) { throw new Exception("Invalid file format. Sirf PDF, DOC, DOCX, JPG/PNG allowed hain."); } $upload_dir = __DIR__ . '/uploads/resumes/'; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0755, true); } $new_file_name = 'resume_' . $candidate_id . '_' . time() . '.' . $file_ext; $destination = $upload_dir . $new_file_name; if (move_uploaded_file($file_tmp, $destination)) { $relative_path = 'uploads/resumes/' . $new_file_name; $stmt = $pdo->prepare(" INSERT INTO candidate_documents (company_id, candidate_id, document_type, file_name, file_path) VALUES (?, ?, 'resume', ?, ?) "); $stmt->execute([$TARGET_COMPANY_ID, $candidate_id, $file_original_name, $relative_path]); } else { throw new Exception("Resume upload folder me save nahi ho paya."); } } $pdo->commit(); $message = "Application successfully submit ho gayi!"; } catch (Exception $e) { $pdo->rollBack(); $error = "Application Save Error: " . $e->getMessage(); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Join Our Team - Career Application</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.min.css"> <style> .location-badge-box { display: none; transition: all 0.3s ease-in-out; } </style> </head> <body class="bg-light"> <div class="container py-5"> <div class="row justify-content-center"> <div class="col-lg-8"> <?php if (!empty($message)): ?> <div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert"> <i class="bi bi-check-circle-fill me-2"></i> <?= j($message) ?> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div> <?php endif; ?> <?php if (!empty($error)): ?> <div class="alert alert-danger alert-dismissible fade show border-0 shadow-sm" role="alert"> <i class="bi bi-exclamation-triangle-fill me-2"></i> <?= j($error) ?> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div> <?php endif; ?> <div class="card shadow border-0"> <div class="card-header bg-dark text-white p-4 text-center"> <h4 class="mb-0 fw-bold text-uppercase">Join Our Team</h4> </div> <div class="card-body p-4 p-md-5"> <form method="POST" enctype="multipart/form-data" autocomplete="off"> <input type="hidden" name="action" value="apply_job"> <h5 class="fw-bold text-secondary mb-4 border-bottom pb-2">Personal Information</h5> <div class="row g-3 mb-4"> <div class="col-md-12"> <label class="form-label fw-semibold">Full Name <span class="text-danger">*</span></label> <input type="text" class="form-control" name="name" required> </div> <div class="col-md-6"> <label class="form-label fw-semibold">Mobile <span class="text-danger">*</span></label> <input type="tel" class="form-control" name="mobile" required> </div> <div class="col-md-6"> <label class="form-label fw-semibold">WhatsApp</label> <input type="tel" class="form-control" name="whatsapp"> </div> </div> <h5 class="fw-bold text-secondary mb-4 border-bottom pb-2">Professional Details</h5> <div class="row g-3 mb-4"> <div class="col-md-12"> <label class="form-label fw-semibold">Position Applied <span class="text-danger">*</span></label> <select class="form-select" id="jobSelect" name="job_id" required> <option value="" selected disabled>Select Post</option> <?php foreach ($open_jobs as $job): ?> <option value="<?= (int)$job['id'] ?>" data-location="<?= j($job['location']) ?>" data-address="<?= j($job['company_address']) ?>"> <?= j($job['title']) ?> (<?= j($job['job_code']) ?>) </option> <?php endforeach; ?> </select> </div> <div class="col-md-12"> <div id="locationBox" class="alert alert-info location-badge-box"> <i class="bi bi-geo-alt-fill"></i> Location: <span id="locationText"></span> </div> </div> <div class="col-md-12"> <label class="form-label fw-semibold">Total Experience</label> <input type="text" class="form-control" name="experience" placeholder="e.g. 2 Years"> </div> <div class="col-md-6"> <label class="form-label fw-semibold">Current Salary</label> <input type="number" step="0.01" class="form-control" name="current_salary"> </div> <div class="col-md-6"> <label class="form-label fw-semibold">Expected Salary</label> <input type="number" step="0.01" class="form-control" name="expected_salary"> </div> <div class="col-12"> <label class="form-label fw-semibold">Resume</label> <input type="file" class="form-control" name="resume"> </div> </div> <div class="d-grid"> <button type="submit" class="btn btn-primary btn-lg">Submit Application</button> </div> </form> </div> </div> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> <script> document.getElementById('jobSelect').addEventListener('change', function () { const opt = this.options[this.selectedIndex]; const loc = opt.getAttribute('data-location'); const box = document.getElementById('locationBox'); if (loc && loc !== 'Not Specified') { document.getElementById('locationText').textContent = loc; box.style.display = 'block'; } else { box.style.display = 'none'; } }); </script> </body> </html>