31 lines
998 B
PHP
31 lines
998 B
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'coach') {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$coach_id = $_SESSION['user_id'];
|
|
$day_of_week = $_POST['day_of_week'];
|
|
$start_time = $_POST['start_time'];
|
|
$end_time = $_POST['end_time'];
|
|
|
|
if (isset($day_of_week) && !empty($start_time) && !empty($end_time)) {
|
|
try {
|
|
$stmt = db()->prepare("INSERT INTO coach_recurring_availability (coach_id, day_of_week, start_time, end_time) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([$coach_id, $day_of_week, $start_time, $end_time]);
|
|
header('Location: dashboard.php?status=recurring_added');
|
|
} catch (PDOException $e) {
|
|
header('Location: dashboard.php?status=error');
|
|
}
|
|
} else {
|
|
header('Location: dashboard.php?status=error');
|
|
}
|
|
} else {
|
|
header('Location: dashboard.php');
|
|
}
|
|
exit;
|