add a search_result php for searchingjobs

added remove options for Employer to remove job postings
change the index file to dymanically show the jobs fetched from the database
main
Grim0o5 6 months ago
parent 08880f013c
commit ab6eb51002
  1. 139
      index.php
  2. 54
      job_details.php
  3. 153
      search_results.php

@ -5,41 +5,79 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TempHire • Future of Work</title>
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.7.2/dist/full.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="min-h-screen bg-gradient-to-br from-base-300 via-base-100 to-base-300 text-base-content">
<?php include 'navbar.php'; ?>
<div class="hero min-h-[70vh] bg-base-200 relative overflow-hidden">
<div class="absolute inset-0 bg-grid-slate-900/[0.04] bg-[size:40px_40px]"></div>
<div class="hero-content text-center">
<div class="max-w-xl relative z-10">
<h1
class="text-5xl font-bold mb-8 bg-clip-text text-transparent bg-gradient-to-r from-primary to-secondary">
<h1 class="text-5xl font-bold mb-8 bg-clip-text text-transparent bg-gradient-to-r from-primary to-secondary">
The Future of Work
</h1>
<p class="py-6 text-lg">Discover opportunities that match your schedule and skills in real-time.</p>
<div class="join w-full backdrop-blur-sm bg-base-100/50 rounded-lg p-1">
<input class="input join-item flex-1 !outline-none border-primary/20"
placeholder="Search for jobs..." />
<button class="btn join-item btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
<form action="search_results.php" method="GET" class="join w-full backdrop-blur-sm bg-base-100/50 rounded-lg p-1">
<input name="search" class="input join-item flex-1 !outline-none border-primary/20"
placeholder="Search for jobs..." value="<?php echo isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; ?>" />
<button type="submit" class="btn join-item btn-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
<button class="btn join-item" onclick="document.getElementById('filter_modal').showModal()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" />
<button type="button" class="btn join-item" onclick="document.getElementById('filter_modal').showModal()">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" />
</svg>
</button>
</div>
</form>
</div>
</div>
</div>
<div class="container mx-auto p-8">
<h2 class="text-3xl font-bold mb-8 text-center">Featured Job Posts</h2>
<div class="grid grid-cols-1 gap-4">
<?php
include 'connect.php';
// Query to get featured jobs (most recent 3 jobs)
$sql = "SELECT * FROM job_postings ORDER BY posted_date DESC LIMIT 3";
$stmt = $conn->prepare($sql);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while ($job = $result->fetch_assoc()) {
?>
<div class="card bg-base-200 shadow-xl hover:shadow-primary/10 transition-all">
<div class="card-body">
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<div>
<h3 class="card-title"><?= htmlspecialchars($job['job_title']) ?></h3>
<div class="flex flex-wrap gap-2 mt-2">
<span class="badge badge-outline"><?= htmlspecialchars($job['location']) ?></span>
<span class="badge badge-primary"><?= htmlspecialchars($job['salary']) ?></span>
</div>
<p class="mt-2"><?= htmlspecialchars(substr($job['job_description'], 0, 150)) ?>...</p>
</div>
<a href="job_details.php?id=<?= $job['job_id'] ?>" class="btn btn-primary">View Details</a>
</div>
</div>
</div>
<?php
}
} else {
echo "<p class='text-center'>No jobs available.</p>";
}
$conn->close();
?>
<div class="text-center mt-4">
<a href="alljobs.php"><button class="btn btn-outline btn-primary btn-sm">View More</button></a>
</div>
</div>
</div>
@ -49,20 +87,7 @@
<form method="dialog" class="modal-box bg-base-200">
<h3 class="font-bold text-lg mb-4">Filter Options</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="form-control w-full">
<label class="label">
<span class="label-text">Location</span>
</label>
<select class="select select-bordered">
<option value="">Select Location</option>
<option value="kathmandu">Kathmandu</option>
<option value="lalitpur">Lalitpur</option>
<option value="bhaktapur">Bhaktapur</option>
<option value="pokhara">Pokhara</option>
<option value="biratnagar">Biratnagar</option>
<option value="butwal">Butwal</option>
</select>
</div>
<div class="form-control w-full">
<label class="label">
@ -112,54 +137,6 @@
</form>
</dialog>
<div class="container mx-auto p-8">
<h2 class="text-3xl font-bold mb-8 text-center">Recent Job Posts</h2>
<div class="grid grid-cols-1 gap-4">
<div class="card bg-base-200 shadow-xl hover:shadow-primary/10 transition-all">
<div class="card-body">
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<div>
<h3 class="card-title">Senior Care Specialist</h3>
<div class="flex flex-wrap gap-2 mt-2">
<span class="badge badge-outline">Full Time</span>
<span class="badge badge-outline">Kathmandu</span>
<span class="badge badge-primary">Rs. 3000/day</span>
</div>
<p class="mt-2">Looking for an experienced caregiver for elderly assistance. Medical
background preferred.</p>
</div>
<button class="btn btn-primary">Apply Now</button>
</div>
</div>
</div>
<div class="card bg-base-200 shadow-xl hover:shadow-primary/10 transition-all">
<div class="card-body">
<div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<div>
<h3 class="card-title">House Cleaning Expert</h3>
<div class="flex flex-wrap gap-2 mt-2">
<span class="badge badge-outline">Part Time</span>
<span class="badge badge-outline">Lalitpur</span>
<span class="badge badge-primary">Rs. 1500/day</span>
</div>
<p class="mt-2">Weekly house cleaning position available. Experience with modern cleaning
equipment required.</p>
</div>
<button class="btn btn-primary">Apply Now</button>
</div>
</div>
</div>
<div class="text-center mt-4">
<a href="alljobs"><button class="btn btn-outline btn-primary btn-sm">View More</button></a>
</div>
</div>
</div>
<div class="container mx-auto p-8">
<h2 class="text-3xl font-bold mb-8 text-center">How It Works</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">

@ -6,7 +6,8 @@ if (!isset($_SESSION['email'])) {
header("Location: login.php");
exit();
}
$seeker_id = $_SESSION['seeker_id'];
// Check if seeker_id exists in the session
$seeker_id = isset($_SESSION['seeker_id']) ;
include 'connect.php';
@ -35,6 +36,7 @@ if ($job_id > 0) {
// Check if the logged-in user is a job seeker
$is_job_seeker = ($_SESSION['user_type'] === 'Job seeker');
$is_employer = ($_SESSION['user_type'] === 'Employer');
// Handle job application
if (isset($_POST['apply']) && $is_job_seeker) {
@ -54,6 +56,36 @@ if (isset($_POST['apply']) && $is_job_seeker) {
$application_message = "There was an error while applying. Please try again later.";
}
}
// Handle job deletion (for employers only)
if (isset($_POST['remove']) && $is_employer) {
$conn->begin_transaction(); // Start a transaction
try {
// Delete related applications
$sql_delete_applications = "DELETE FROM applications WHERE job_id = ?";
$stmt_delete_applications = $conn->prepare($sql_delete_applications);
$stmt_delete_applications->bind_param("i", $job_id);
$stmt_delete_applications->execute();
// Delete the job posting
$sql_delete_job = "DELETE FROM job_postings WHERE job_id = ?";
$stmt_delete_job = $conn->prepare($sql_delete_job);
$stmt_delete_job->bind_param("i", $job_id);
$stmt_delete_job->execute();
$conn->commit(); // Commit the transaction
echo '<script>
alert("Job deleted successfully!");
window.location.href = "viewjobs.php";
</script>';
exit();
} catch (Exception $e) {
$conn->rollback(); // Rollback the transaction on error
$delete_message = "There was an error while deleting the job. Please try again later.";
}
}
?>
<!DOCTYPE html>
@ -140,6 +172,26 @@ if (isset($_POST['apply']) && $is_job_seeker) {
You must be a job seeker to apply
</button>
<?php endif; ?>
<?php if ($is_employer): ?>
<form method="POST">
<button type="submit" name="remove" class="btn btn-error">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
Remove Job Posting
</button>
</form>
<?php else: ?>
<button class="btn btn-disabled" disabled>
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
</svg>
You must be a Employer to remove
</button>
<?php endif; ?>
</div>
</div>
</div>

@ -0,0 +1,153 @@
<?php
session_start();
include 'connect.php';
// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: login.php");
exit();
}
// Build the SQL query based on search parameters
$where_conditions = array();
$params = array();
$types = "";
// Search by job title or description
if (!empty($_GET['search'])) {
$where_conditions[] = "(job_title LIKE ? OR description LIKE ?)";
$search_term = "%" . $_GET['search'] . "%";
$params[] = $search_term;
$params[] = $search_term;
$types .= "ss";
}
// Search by location
if (!empty($_GET['location'])) {
$where_conditions[] = "location = ?";
$params[] = $_GET['location'];
$types .= "s";
}
// Search by job type
if (!empty($_GET['job_type'])) {
$where_conditions[] = "job_type = ?";
$params[] = $_GET['job_type'];
$types .= "s";
}
// Search by salary type
if (!empty($_GET['salary_type'])) {
$where_conditions[] = "salary LIKE ?";
$params[] = "%" . $_GET['salary_type'] . "%";
$types .= "s";
}
// Search by skill level
if (!empty($_GET['skill_level'])) {
$where_conditions[] = "skill_level = ?";
$params[] = $_GET['skill_level'];
$types .= "s";
}
$sql = "SELECT * FROM job_postings";
if (!empty($where_conditions)) {
$sql .= " WHERE " . implode(" AND ", $where_conditions);
}
$sql .= " ORDER BY posted_date DESC";
$stmt = $conn->prepare($sql);
if (!empty($params)) {
$stmt->bind_param($types, ...$params);
}
?>
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Results • TempHire</title>
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.7.2/dist/full.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="min-h-screen bg-base-200">
<?php include 'navbar.php'; ?>
<main class="container mx-auto px-4 py-8">
<div class="text-sm breadcrumbs mb-6">
<ul>
<li><a href="index.php">Home</a></li>
<li class="text-primary">Search Results</li>
</ul>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<?php
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while ($job = $result->fetch_assoc()) {
?>
<div class="lg:col-span-1">
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title text-xl mb-4"><?= htmlspecialchars($job['job_title']) ?></h2>
<div class="space-y-4">
<div class="flex items-center gap-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-primary" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z" clip-rule="evenodd" />
</svg>
<div>
<div class="text-sm opacity-70">Location</div>
<div class="font-medium"><?= htmlspecialchars($job['location']) ?></div>
</div>
</div>
<div class="flex items-center gap-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-primary" viewBox="0 0 20 20" fill="currentColor">
<path d="M8.433 7.418c.155-.103.346-.196.567-.267v1.698a2.305 2.305 0 01-.567-.267C8.07 8.34 8 8.114 8 8c0-.114.07-.34.433-.582zM11 12.849v-1.698c.22.071.412.164.567.267.364.243.433.468.433.582 0 .114-.07.34-.433.582a2.305 2.305 0 01-.567.267z" />
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-13a1 1 0 10-2 0v.092a4.535 4.535 0 00-1.676.662C6.602 6.234 6 7.009 6 8c0 .99.602 1.765 1.324 2.246.48.32 1.054.545 1.676.662v1.941c-.391-.127-.68-.317-.843-.504a1 1 0 10-1.51 1.31c.562.649 1.413 1.076 2.353 1.253V15a1 1 0 102 0v-.092a4.535 4.535 0 001.676-.662C13.398 13.766" />
</svg>
<div>
<div class="text-sm opacity-70">Salary</div>
<div class="font-medium"><?= htmlspecialchars($job['salary']) ?></div>
</div>
</div>
<div class="flex items-center gap-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-primary" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd" />
</svg>
<div>
<div class="text-sm opacity-70">Posted Date</div>
<div class="font-medium"><?= date('F j, Y', strtotime($job['posted_date'])) ?></div>
</div>
</div>
</div>
<div class="divider"></div>
<a href="job_details.php?id=<?= $job['job_id'] ?>" class="btn btn-primary btn-block">
View Details
</a>
</div>
</div>
</div>
<?php
}
} else {
echo "<p>No jobs available.</p>";
}
$conn->close();
?>
</div>
</main>
<?php include 'footer.php'; ?>
</body>
</html>
Loading…
Cancel
Save