Skip to content
Snippets Groups Projects
Commit f6ac4edf authored by ZHANG David's avatar ZHANG David
Browse files

Upload New File

parent 4bc764f1
No related branches found
No related tags found
No related merge requests found
<?php
include 'config.php';
session_start();
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'tutor') {
echo "<div class='container'><p class='error'>Access denied. Only tutors can create sessions.</p><a href='login.php'>Go back</a></div>";
exit;
}
$user = $_SESSION['user'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$subject = $conn->real_escape_string($_POST['subject']);
$room = $conn->real_escape_string($_POST['room']);
$start_time = $conn->real_escape_string($_POST['start_time']);
$end_time = $conn->real_escape_string($_POST['end_time']);
$tutor_id = $_SESSION['user']['id'];
// Calculer la durée entre start_time et end_time
$start = strtotime($start_time);
$end = strtotime($end_time);
$duration = ($end - $start) / 3600; // Convertir en heures
// Vérifier que la durée est entre 1 et 2 heures
if ($duration < 1 || $duration > 2) {
echo "<div class='container'><p class='error'>The session duration must be between 1 and 2 hours.</p><a href='create_session.php'>Go back</a></div>";
exit;
}
// Insérer la session si la durée est valide
$sql = "INSERT INTO Session (tutor_id, subject, start_time, end_time, status)
VALUES ('$tutor_id', '$subject', '$start_time', '$end_time', 'scheduled')";
if ($conn->query($sql) === TRUE) {
echo "<div class='container' style='text-align: center; margin-top: 50px; font-family: Arial, sans-serif;'>
<p style='color: #28a745; font-size: 20px; font-weight: 600; margin-bottom: 20px;'>Session created successfully.</p>
<a href='welcome.php' style='display: inline-block; padding: 12px 24px; background-color: #28a745; color: white; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 500; transition: background-color 0.3s;'>
Go back
</a>
</div>";
} else {
echo "<div class='container' style='text-align: center; margin-top: 50px; font-family: Arial, sans-serif;'>
<p style='color: #dc3545; font-size: 20px; font-weight: 600; margin-bottom: 20px;'>Error: " . htmlspecialchars($conn->error, ENT_QUOTES, 'UTF-8') . "</p>
<a href='create_session.php' style='display: inline-block; padding: 12px 24px; background-color: #dc3545; color: white; text-decoration: none; border-radius: 8px; font-size: 16px; font-weight: 500; transition: background-color 0.3s;'>
Try again
</a>
</div>";
}
} else {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Session</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php include 'sidebar.php'; ?>
<div class="main-content">
<div class="create-session-page">
<h1>Create a Session</h1>
<form method="POST">
<label for="subject">Subject:</label>
<input type="text" name="subject" id="subject" required>
<label for="room">Room :</label>
<select id="room" Room="salles">
<option value="madras">Madras</option>
<option value="bombay">Bombay</option>
<option value="shanghai">Shanghai</option>
</select>
<label for="start_time">Start Time:</label>
<input type="datetime-local" name="start_time" id="start_time" required>
<label for="end_time">End Time:</label>
<input type="datetime-local" name="end_time" id="end_time" required>
<button type="submit">Create Session</button>
</form>
</div>
</div>
</body>
</html>
<?php } ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment