-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.php
235 lines (194 loc) · 10.7 KB
/
check.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
require_once("resources/config.php");
require_once(COMPONENTS_PATH . "/header.php");
require_once(COMPONENTS_PATH . "/navbar.php");
?>
<div class="jumbotron container mt-5">
<form action="" method="POST">
<div class="form-group">
<label for="inputisbn">Codice ISBN</label>
<input name="isbn" type="text" class="form-control" id="inputisbn" aria-describedby="isbnInput">
<small id="isbnInput" class="form-text text-muted">ISBN 10 o ISBN 13</small>
</div>
<button type="submit" name="submit" class="btn btn-primary">Controlla Libro</button>
</form>
</div>
<?php
if (isset($_POST['submit'])) {
$isbn = $_POST['isbn'];
$jsonurl = "https://www.googleapis.com/books/v1/volumes?q=isbn:" . $isbn;
$jsoncontent = file_get_contents($jsonurl);
$json = json_decode($jsoncontent);
if ($json->totalItems == 0) { ?>
<div class="jumbotron container mt-5">
<h3>Libro non trovato</h3>
</div>
<?php } else {
// Book item main api
$bookItem = $json->items[0];
// Self link per piu info sul libro
$selfLink = $bookItem->selfLink;
$selfLinkJsonContent = file_get_contents($selfLink);
$selfLinkJson = json_decode($selfLinkJsonContent);
// Price
$priceapi = "https://booksrun.com/api/price/sell/" . $isbn . "?key=fqfb16h7x2sss8k52ily";
$priceJsonContent = file_get_contents($priceapi);
$priceJson = json_decode($priceJsonContent);
?>
<div class="jumbotron container mt-5">
<div class="row">
<div class="col-md-3">
<?php
if (isset($bookItem->volumeInfo->imageLinks->smallThumbnail)) {
$thumbnailUrl = $bookItem->volumeInfo->imageLinks->smallThumbnail; ?>
<img src="<?php echo $thumbnailUrl ?>" class="card-img" alt="Book Cover">
<?php } else { ?>
<img src="https://isbndb.com/modules/isbndb/img/default-book-cover.jpg" alt="Cover non disponibiler">
<?php } ?>
</div>
<div class="col-md-9">
<div class="card-body">
<h3 class="card-title"><?php echo $bookItem->volumeInfo->title; ?></h3>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#info">Informazioni</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#desc">Descrizione</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#biblio">Biblioteca</a>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active show" id="info">
<table class="table table-hover">
<tbody>
<?php
if (isset($bookItem->volumeInfo->authors)) {
$authors = $bookItem->volumeInfo->authors; ?>
<tr class="table-action">
<td>Autori</td>
<td>
<?php foreach ($authors as $author) {
echo $author;
} ?>
</td>
</tr>
<?php } ?>
<?php
if (isset($selfLinkJson->volumeInfo->publisher)) {
$publisher = $selfLinkJson->volumeInfo->publisher; ?>
<tr>
<td>Casa Editrice</td>
<td><?php echo $publisher ?></td>
</tr>
<?php }
?>
<?php
if (isset($bookItem->volumeInfo->publishedDate)) {
$publishDate = $bookItem->volumeInfo->publishedDate; ?>
<tr class="table-action">
<td>Anno</td>
<td>
<?php echo $publishDate; ?>
</td>
</tr>
<?php } ?>
<?php
if (isset($bookItem->volumeInfo->industryIdentifiers)) {
$identifiers = $bookItem->volumeInfo->industryIdentifiers;
foreach ($identifiers as $id) { ?>
<tr class="table-action">
<td><?php echo $id->type ?></td>
<td><?php echo $id->identifier ?></td>
</tr>
<?php }
}
?>
<?php
if (isset($bookItem->volumeInfo->pageCount)) {
$pages = $bookItem->volumeInfo->pageCount; ?>
<tr>
<td>Numero di pagine</td>
<td><?php echo $pages ?></td>
</tr>
<?php }
?>
<?php
if (isset($bookItem->volumeInfo->language)) {
$lang = $bookItem->volumeInfo->language; ?>
<tr>
<td>Lingua</td>
<td><?php echo $lang ?></td>
</tr>
<?php }
?>
<?php
if (isset($selfLinkJson->volumeInfo->dimensions)) {
$dimensions = $selfLinkJson->volumeInfo->dimensions; ?>
<tr>
<td>Dimensioni</td>
<td><?php echo $dimensions->height ?></td>
</tr>
<?php }
?>
<?php
if ($priceJson->result->status == "success") {
$prezzo = $priceJson->result->text->Average; ?>
<tr>
<td>Prezzo Medio</td>
<td><?php echo $prezzo ?> $</td>
</tr>
<?php }
?>
<?php
if (isset($selfLinkJson->volumeInfo->categories)) {
$cats = $selfLinkJson->volumeInfo->categories; ?>
<tr class="table-action">
<td>Categorie</td>
<td>
<?php
foreach ($cats as $cat) { ?>
<?php echo $cat . ', ' ?>
<?php } ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="desc">
<?php
$desc = $selfLinkJson->volumeInfo->description;
if ($desc) { ?>
<p><?php echo $desc; ?></p>
<?php }
?>
</div>
<div class="tab-pane fade" id="biblio">
<table class="table table-hover">
<tbody>
<tr>
<td>Posizione</td>
<td>Scaffale 1</td>
</tr>
<tr>
<td>Data</td>
<td>2013</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
require_once(COMPONENTS_PATH . "/footer.php");
?>