-
Notifications
You must be signed in to change notification settings - Fork 0
/
book.php
62 lines (57 loc) · 1.46 KB
/
book.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
<?php
// Controleur qui gère l'affichage du détail d'un livre
require 'model/Database.php';
require 'model/BookManager.php';
require 'model/entity/Book.php';
require 'model/entity/User.php';
require 'model/UserManager.php';
$book_manager = new BookManager();
$user_manager = new UserManager();
//on affiche un livre avec son emprunteur s'il y a.
$book = $book_manager->getBookByGetId();
//Delete book
if (isset($_POST["delete"])) {
$delete_book = $book_manager->deleteBook();
if ($delete_book) {
header("Location: index.php");
exit();
}
}
$error = "";
$field = "";
//update book lending
if (isset($_POST["bookLending"])) {
if (!empty($_POST["identificationUser"])) {
try {
$user = new User($_POST);
} catch (\Exception $e) {
$error = $e->getMessage();
}
if (empty($error)) {
if ($user_manager->checkIdentificationUser($_POST["identificationUser"])) {
$user = $user_manager->getUser($user);
$lend = $book_manager->updateBookStatus($user);
header("Location: book.php?id={$_GET["id"]}");
exit();
}
else {
$field = "identifiant inconnu";
}
}
}
else {
$field = "Champs vides";
}
}
//update book back
if (isset($_POST["bookBack"])) {
if (!empty($_POST["userId"])) {
$book = $book_manager->updateBookStatusBack();
header("Location: book.php?id={$_GET["id"]}");
exit();
}
else {
$field = "Veuillez sélectionner 'rendu'";
}
}
include "View/bookView.php";