-
Notifications
You must be signed in to change notification settings - Fork 0
/
gestionoutils.php
145 lines (126 loc) · 4.19 KB
/
gestionoutils.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
//todo empecher acces
include_once("connexionBD.php");
function ajoutelement($elem, $denomination)
{
$connexion = connectionDB();
$sql = "INSERT INTO elements (LIBELLE, DENOMINATION) VALUES(?,?)";
$stmt = $connexion->prepare($sql);
$stmt->bind_param("ss", $elem, $denomination);
$stmt->execute();
mysqli_close($connexion);
}
function get_prof($prof_id)
{
$connexion = connectionDB();
$req = "select USERNAME from professeurs where id=$prof_id";
$result = mysqli_query($connexion, $req);
$data = mysqli_fetch_row($result);
mysqli_close($connexion);
if ($data) {
return $data[0];
}
return null;
}
function get_element($elem_id): array
{
$connexion = connectionDB();
$req = "SELECT LIBELLE, IDENTIFIANT FROM elements WHERE IDENTIFIANT=$elem_id";
$result = mysqli_query($connexion, $req);
$array = array();
if ($data = mysqli_fetch_row($result)) {
$array[] = array($data[0], $data[1]);
}
mysqli_close($connexion);
return $array;
}
function get_reservation_prof($prof_id)
{
$connexion = connectionDB();
$req = "SELECT LIBELLE, IDENTIFIANT FROM elements WHERE RESERVE_PAR=$prof_id";
$result = mysqli_query($connexion, $req);
$data = mysqli_fetch_row($result);
if ($data) {
return array($data[0], $data[1]);
}
mysqli_close($connexion);
return null;
}
function get_reservation_elem($elem_id)
{
$connexion = connectionDB();
$req = "SELECT LIBELLE, IDENTIFIANT,RESERVE_PAR FROM elements WHERE IDENTIFIANT=$elem_id AND RESERVE_PAR IS NOT NULL";
$result = mysqli_query($connexion, $req);
$data = mysqli_fetch_row($result);
if ($data) {
return array($data[0], $data[1],$data[2]);
}
mysqli_close($connexion);
return null;
}
function faire_reservation($prof_id, $elem_id): bool
{
//todo faire reservation et verifier si
if (get_reservation_prof($prof_id) == null && get_element($elem_id) !== null && get_prof($prof_id) != null && get_reservation_elem($elem_id) == null) {
$connexion = connectionDB();
$sql = "UPDATE elements SET RESERVE_PAR=? WHERE IDENTIFIANT=?";
$stmt = $connexion->prepare($sql);
$stmt->bind_param("ii", $prof_id, $elem_id);
$stmt->execute();
mysqli_close($connexion);
return true;
}
return false;
// le prof a déja reservé un truc -> pas possible
// l'objet demandé est déja reservé -> pas possible
//renvoi un boolen vrai si reussi sinon faux
}
function annuler_reservation($prof_id, $elem_id)
{
if (get_reservation_prof($prof_id) != null && get_element($elem_id) !== null && get_prof($prof_id) != null) {
$res = get_reservation_elem($elem_id);
if($res[2] != $prof_id) return null;
$connexion = connectionDB();
$req = "UPDATE elements SET RESERVE_PAR=null where IDENTIFIANT = ?";
$stmt = $connexion->prepare($req);
$stmt->bind_param("i", $elem_id);
$stmt->execute();
mysqli_close($connexion);
}
return true;
}
function liste_reservations($uniquement_non_reserve = true): array
{
$connexion = connectionDB();
$req = "SELECT e.LIBELLE, e.DENOMINATION, e.RESERVE_PAR,IDENTIFIANT FROM elements e";
if ($uniquement_non_reserve) {
$req = "$req WHERE e.RESERVE_PAR IS NULL";
}
$result = mysqli_query($connexion, $req);
$array = array();
while ($data = mysqli_fetch_row($result)) {
$outils = $data[0];
$denomination = $data[1];
$prof = $data[2];
$identifient = $data[3];
if ($prof) {
$req2 = "SELECT USERNAME from professeurs where id=$prof";
$result2 = mysqli_query($connexion, $req2);
while ($data2 = mysqli_fetch_row($result2)) {
$prof = $data2[0];
}
}
$array[] = array($outils, $denomination, $prof,$identifient);
}
mysqli_close($connexion);
return $array;
}
/**$host = "localhost";
* $login = "root";
* $mdp = "";
* //connexion au SGBD Mysql en root
* $connexion = mysqli_connect($host, $login, $mdp)
* or die("Connexion Impossible");
* //utilisation de mesoutils
* $filebd = "mesoutils";
* $bd = mysqli_select_db($connexion, $filebd);*/