Exemplo n.º 1
0
<?php

session_start();
include_once 'db/BookDB.php';
include_once 'db/BookReservationDB.php';
$db = new DBHandler();
$bookDB = new BookDB($db);
$reserveDB = new BookReservationDB($db);
$book = NULL;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $title = $_POST['title'];
    $description = $_POST['description'];
    $Image_Url = $_POST['imageUrl'];
    $date_publish = $_POST['date'];
    $count = $_POST['count'];
    $author = $_POST['author'];
    $isbn = $_POST['isbn'];
    if (isset($_POST['bookId'])) {
        $bookDB->UpdateBook($_POST['bookId'], $isbn, $title, $description, $Image_Url, $author, $date_publish, $count);
        $book = $bookDB->GetBookById($_POST['bookId']);
    } else {
        $bookDB->AddBook($isbn, $title, $description, $Image_Url, $author, $date_publish, $count);
        header("Location: viewAllBooks.php");
    }
} else {
    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
        if (isset($_GET['isbn'])) {
            $result = $bookDB->GetBookByISBN($_GET['isbn']);
            if (count($result) > 0) {
                $book = $result;
            }
Exemplo n.º 2
0
<?php

session_start();
include_once "db/BookReservationDB.php";
include_once "db/BookDB.php";
include_once "db/UserDB.php";
$db = new DBHandler();
$bookDB = new BookDB($db);
$reservationDB = new BookReservationDB($db);
$userDB = new UserDB($db);
$reservations = array();
$user = NULL;
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['userId'])) {
    $user = $userDB->GetUser($_GET['userId']);
    $reservations = $reservationDB->GetReservationForUser($user['id']);
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>BookÉTS</title>
    <!-- Favicon -->
    <link rel="shortcut icon" type="image/icon" href="assets/images/favicon.ico"/>
    <!-- Font Awesome -->
    <link href="assets/css/font-awesome.css" rel="stylesheet">
    <!-- Bootstrap -->
Exemplo n.º 3
0
<?php

include_once 'db/BookReservationDB.php';
include_once 'db/BookDB.php';
include_once 'db/GenericDB.php';
include_once 'db/UserDB.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['method'])) {
    if ($_POST['method'] == "DELETE" && isset($_POST['id'])) {
        $reservationDB = new BookReservationDB();
        $reservationDB->DeleteReservation($_POST['id']);
    } else {
        if ($_POST['method'] == "PUT" && isset($_POST['bookId']) && isset($_POST['userId']) && isset($_POST['reservationLength'])) {
            $db = new DBHandler();
            $reservationDB = new BookReservationDB($db);
            $bookDB = new BookDB($db);
            $genericDB = new GenericDB($db);
            $settings = $genericDB->GetSettings();
            $errorMessage = array();
            $date_start = date("Y-m-d");
            $date_end = date('Y-m-d', strtotime('+' . $_POST['reservationLength']));
            $reservations = $reservationDB->GetReservationsForBook($_POST['bookId']);
            $book = $bookDB->GetBookById($_POST['bookId']);
            if (count($reservations) >= $book['Count']) {
                $errorMessage[] = "Aucun exemplaire disponible.";
            }
            $reservations = $reservationDB->GetReservationForUser($_POST['userId']);
            if (count($reservations) >= $settings['MaxReservationCount']) {
                $errorMessage[] = "Nombre maximum de réservations atteint.";
            }
            if (count($errorMessage) == 0) {
                $reservationDB->AddReservation($date_start, $date_end, $_POST['bookId'], $_POST['userId']);