42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'manager') {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
require_once 'db/config.php';
|
|
|
|
$name = $_POST['name'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
$date = $_POST['date'] ?? '';
|
|
$location = $_POST['location'] ?? '';
|
|
$manager_id = $_SESSION['user_id'];
|
|
|
|
if (empty($name) || empty($description) || empty($date) || empty($location)) {
|
|
// Handle empty fields
|
|
header('Location: manager_dashboard.php?error=empty_fields');
|
|
exit();
|
|
}
|
|
|
|
try {
|
|
$conn = db();
|
|
$stmt = $conn->prepare("INSERT INTO events (name, description, date, location, status, created_by) VALUES (:name, :description, :date, :location, 'pending', :created_by)");
|
|
$stmt->bindParam(':name', $name);
|
|
$stmt->bindParam(':description', $description);
|
|
$stmt->bindParam(':date', $date);
|
|
$stmt->bindParam(':location', $location);
|
|
$stmt->bindParam(':created_by', $manager_id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
|
|
header('Location: manager_dashboard.php?success=event_created');
|
|
exit();
|
|
} catch (PDOException $e) {
|
|
// Handle database error
|
|
header('Location: manager_dashboard.php?error=db_error');
|
|
exit();
|
|
}
|
|
}
|