From b7d68b713b427bc7c9c04ee12f6f72b5771cb750 Mon Sep 17 00:00:00 2001 From: ZHANG David <david.zhang@etu.univ-amu.fr> Date: Thu, 30 Jan 2025 20:25:30 +0000 Subject: [PATCH] Upload New File --- code/prof_create_depot.php | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 code/prof_create_depot.php diff --git a/code/prof_create_depot.php b/code/prof_create_depot.php new file mode 100644 index 0000000..62ee1c6 --- /dev/null +++ b/code/prof_create_depot.php @@ -0,0 +1,50 @@ +<?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 depots.</p><a href='login.php'>Go back</a></div>"; + exit; +} + +$user = $_SESSION['user']; +$tutor_id = $user['id']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $nom = $conn->real_escape_string($_POST['nom']); + $description = $conn->real_escape_string($_POST['description']); + + $sql = "INSERT INTO depots (nom, description, tutor_id) VALUES ('$nom', '$description', '$tutor_id')"; + + if ($conn->query($sql) === TRUE) { + echo "<div class='container'><p class='success'>Depot created successfully.</p><a href='welcome.php'>Go back</a></div>"; + } else { + echo "<div class='container'><p class='error'>Error: " . htmlspecialchars($conn->error, ENT_QUOTES, 'UTF-8') . "</p><a href='prof_create_depot.php'>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 Depot</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 Depot</h1> + <form method="POST"> + <label for="nom">Depot Name:</label> + <input type="text" name="nom" id="nom" required> + <label for="description">Description:</label> + <textarea name="description" id="description"></textarea> + <button type="submit">Create Depot</button> + </form> + </div> +</body> +</html> +<?php } ?> -- GitLab