-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
92 lines (84 loc) · 2.39 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>E-LibPHPant</title>
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
<link rel="stylesheet" href="style.css">
<script src="app.js" defer></script>
</head>
<?php
require_once("Book.php");
require_once("BookHandler.php");
$bookHandler = BookHandler::getInstance();
if (isset($_POST["title"])) {
$book = new Book(
$_POST["title"],
$_POST["author"],
intval($_POST["pages"])
);
$bookExist = $bookHandler->exist($book);
if (!$bookExist) {
$bookHandler->addBook($book);
}
}
?>
<body>
<header class="container">
<h1>
<u>E-Lib-PHPant</u>
</h1>
</header>
<main class="container">
<section>
<button name="open-modal" class="button outline">Add Book +</button>
</section>
<section>
<?php
$books = $bookHandler->getBooks();
foreach($books as $key=>$value) {
$index = $key + 1;
$title = $value->getTitle();
$author = $value->getAuthor();
$pages = $value->getPages();
echo
"<article data-title='$title' data-author='$author' data-pages='$pages'>
<header>
$index. $title
</header>
<ul>
<li>Author: $author</li>
<li>Pages: $pages</li>
</ul>
</article>";
}
?>
</section>
<section>
<dialog>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<h2>New Book</h2>
<!-- Framework forece me to include the header inside the form -->
<label for="title">Title</label>
<input type="text" name="title" id="title" autocomplete="off" title="Title of the book" required>
<label for="author">Author</label>
<input type="text" name="author" id="author" autocomplete="off"
title="Name of the author of the book" required>
<label for=" pages">Pages</label>
<input type="number" name="pages" id="pages" min="1" max="100000" step="1"
title="Number of pages of the book" required>
<button type=" submit">Create</button>
<button name="close-modal" class="button secondary">Back</button>
</form>
</dialog>
</section>
</main>
<footer class="container">
<section>
<p>Made by <a href="https://github.com/Cromega08">Cromega</a> </p>
</section>
</footer>
</body>
</html>