You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
5.1 KiB
144 lines
5.1 KiB
<?php
|
|
session_start();
|
|
include 'connect.php';
|
|
|
|
if (!isset($_SESSION['employer_id'])) {
|
|
echo "You must be logged in to post a job.";
|
|
exit(); // Stop further execution if not logged in
|
|
}
|
|
|
|
$employer_id = $_SESSION['employer_id']; // Get employer ID from session
|
|
|
|
|
|
// Handle job posting
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['job_title'])) {
|
|
try {
|
|
// Sanitize input data
|
|
$job_title = $_POST['job_title'];
|
|
$job_description = $_POST['job_description'];
|
|
$location = $_POST['location'];
|
|
$salary = $_POST['salary'];
|
|
$requirements = $_POST['requirements'];
|
|
|
|
// Prepare the SQL query to insert job data into job_postings table
|
|
$stmt = $conn->prepare(
|
|
"INSERT INTO job_postings (employer_id, job_title, job_description, location, salary, requirements)
|
|
VALUES (?, ?, ?, ?, ?, ?)"
|
|
);
|
|
$stmt->bind_param(
|
|
"isssss", // Define parameter types (string, string, string, string, string, string)
|
|
$employer_id,
|
|
$job_title,
|
|
$job_description,
|
|
$location,
|
|
$salary,
|
|
$requirements
|
|
);
|
|
$stmt->execute();
|
|
|
|
echo "<script>alert('Job posted successfully!'); window.location.href = 'employerdash';</script>";
|
|
exit;
|
|
|
|
} catch (Exception $e) {
|
|
// Return error response if an issue occurs
|
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
|
exit;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Manage Jobs</title>
|
|
<link rel="stylesheet" href="ManageJob.css">
|
|
</head>
|
|
|
|
<body>
|
|
<?php include 'navbar.php'; ?>
|
|
<div class="container">
|
|
<div class="post-job">
|
|
<form method="Post" action="">
|
|
<input type="text" name="job_title" placeholder="Job Title" required>
|
|
<textarea name="job_description" placeholder="Job Description" required></textarea>
|
|
<input type="text" name="location" placeholder="Location" required>
|
|
<input type="text" name="salary" placeholder="Salary" required>
|
|
<textarea name="requirements" placeholder="Requirements" required></textarea>
|
|
<button type="submit">Post Job</button>
|
|
</form>
|
|
</div>
|
|
|
|
</div>
|
|
<?php include 'footer.php'; ?>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
fetchJobs();
|
|
|
|
document.getElementById('postJobForm').addEventListener('submit', function (event) {
|
|
event.preventDefault();
|
|
postJob();
|
|
});
|
|
});
|
|
|
|
// Function to fetch jobs from the database
|
|
function fetchJobs() {
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('GET', 'manage_jobs.php', true);
|
|
xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
const data = JSON.parse(xhr.responseText);
|
|
const jobsList = document.getElementById('jobsList');
|
|
jobsList.innerHTML = '';
|
|
data.forEach(job => {
|
|
const jobDiv = document.createElement('div');
|
|
jobDiv.className = 'job';
|
|
jobDiv.innerHTML = `
|
|
<h3>${job.job_title}</h3>
|
|
<p><strong>Location:</strong> ${job.location}</p>
|
|
<p><strong>Salary:</strong> ${job.salary}</p>
|
|
<p><strong>Requirements:</strong> ${job.requirements}</p>
|
|
<p><strong>Posted Date:</strong> ${new Date(job.posted_date).toLocaleDateString()}</p>
|
|
<p>${job.job_description}</p>
|
|
<button onclick="applyJob(this)">Quick Apply</button>
|
|
`;
|
|
jobsList.appendChild(jobDiv);
|
|
});
|
|
}
|
|
};
|
|
xhr.send();
|
|
}
|
|
|
|
// Function to post a new job
|
|
function postJob() {
|
|
const xhr = new XMLHttpRequest();
|
|
const form = document.getElementById('postJobForm');
|
|
const formData = new FormData(form);
|
|
|
|
xhr.open('POST', 'manage_jobs.php', true);
|
|
xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
const response = JSON.parse(xhr.responseText);
|
|
if (response.status === 'success') {
|
|
alert(response.message);
|
|
fetchJobs();
|
|
} else {
|
|
alert(response.message);
|
|
}
|
|
}
|
|
};
|
|
xhr.send(formData);
|
|
}
|
|
|
|
// Function for the "Quick Apply" button
|
|
function applyJob(button) {
|
|
const jobDiv = button.parentElement;
|
|
alert(`Applying for: ${jobDiv.querySelector('h3').textContent}`);
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|
|
|