-
Notifications
You must be signed in to change notification settings - Fork 0
/
addEtudiantToCoursTreatment.php
100 lines (93 loc) · 4.13 KB
/
addEtudiantToCoursTreatment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once("connection.php");
$result4 = $connect->query("SELECT campus FROM lieux");
$result = $connect->query("SELECT classe FROM classes");
$result2 = $connect->query("SELECT id, nom FROM users WHERE role = 'intervenant'");
$result3 = $connect->query("SELECT id, nom FROM users WHERE role = 'etudiant'");
function verifyFields($field)
{
$classe = filter_input(INPUT_POST, "classe");
$nom = filter_input(INPUT_POST, "etudiant");
$intervenant_name = filter_input(INPUT_POST, "intervenant");
$cours = filter_input(INPUT_POST, "cours");
$lieux = filter_input(INPUT_POST, "lieux");
$date = filter_input(INPUT_POST, "date");
$msgReturn = "";
switch ($field) {
case "classe":
if ($classe == "") {
$msgReturn .= "Please select a class<br>";
}
break;
case "etudiant":
if ($nom == "") {
$msgReturn .= "Please select a student<br>";
}
break;
case "date":
if ($date == "") {
$msgReturn .= "Please select a date<br>";
}
break;
case "lieux":
if ($lieux == "") {
$msgReturn .= "Please select location<br>";
}
break;
case "cours":
if ($cours == "") {
$msgReturn .= "Please select the subject<br>";
}
break;
case "intervenant":
if ($intervenant_name == "") {
$msgReturn .= "Please select the teacher<br>";
}
break;
}
return $msgReturn;
}
function checkError($post)
{
$Error = [];
foreach ($post as $key => $value) {
$err = verifyFields($key);
if (strlen($err) > 0)
$Error[] = $err;
}
return $Error;
}
if (isset($_POST["date"], $_POST["classe"], $_POST["etudiant"], $_POST["lieux"], $_POST["cours"], $_POST["intervenant"])) {
$errors = checkError($_POST);
if (empty($errors)) {
$date = filter_input(INPUT_POST, "date");
$lieux = filter_input(INPUT_POST, "lieux");
$getAdresse = $conn->prepare("SELECT * FROM lieux WHERE campus = :lieux");
$getAdresse->execute([':lieux' => $lieux]);
$adresseList = $getAdresse->fetchAll();
$adresse = $adresseList[0]['adresse'];
$cours = filter_input(INPUT_POST, "cours");
$theme = filter_input(INPUT_POST, "theme");
$debut_am = filter_input(INPUT_POST, "debut_am");
$fin_am = filter_input(INPUT_POST, "fin_am");
$debut_pm = filter_input(INPUT_POST, "debut_pm");
$fin_pm = filter_input(INPUT_POST, "fin_pm");
$intervenant_name = filter_input(INPUT_POST, "intervenant");
$getId = $conn->prepare("SELECT id FROM users WHERE nom = :intervenant_name");
$getId->execute([':intervenant_name' => $intervenant_name]);
$details = $getId->fetchAll();
$intervenant_id = $details[0]['id'];
$classe = filter_input(INPUT_POST, "classe");
$nom = filter_input(INPUT_POST, "etudiant");
if (!$conn) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
} else {
$sql = $conn->prepare("INSERT INTO `planning`(`id_planning`, `date`, `lieux`, `adresse`, `cours`, `theme`, `debut_am`, `fin_am`, `debut_pm`, `fin_pm`, `intervenant_name`, `intervenant_id`, `classe`, `nom`) VALUES (NULL, :date, :lieux, :adresse, :cours, :theme, :debut_am, :fin_am, :debut_pm, :fin_pm, :intervenant_name, :intervenant_id, :classe, :nom)");
$sql->execute([':date' => $date, ':lieux' => $lieux, ':adresse' => $adresse, ':cours' => $cours, ':theme' => $theme, ':debut_am' => $debut_am, ':fin_am' => $fin_am, ':debut_pm' => $debut_pm, ':fin_pm' => $fin_pm, ':intervenant_name' => $intervenant_name, ':intervenant_id' => $intervenant_id, ':classe' => $classe, ':nom' => $nom]);
header('Location: addEtudiantToCours.php?id=Database updated');
}
// mysqli_close($conn);
}
}