From f6ac4edfee5b7954db090d1d39d577b126a82238 Mon Sep 17 00:00:00 2001
From: ZHANG David <david.zhang@etu.univ-amu.fr>
Date: Thu, 30 Jan 2025 20:25:12 +0000
Subject: [PATCH] Upload New File

---
 code/create_session.php | 84 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 code/create_session.php

diff --git a/code/create_session.php b/code/create_session.php
new file mode 100644
index 0000000..d75ff2c
--- /dev/null
+++ b/code/create_session.php
@@ -0,0 +1,84 @@
+<?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 } ?>
-- 
GitLab