-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.php
More file actions
164 lines (136 loc) · 4.17 KB
/
Copy pathbook.php
File metadata and controls
164 lines (136 loc) · 4.17 KB
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
<?php
$dsn = 'mysql:dbname=b7_obookstore;host=ja-cdbr-azure-east-a.cloudapp.net;charset=utf8';
$username = 'b62d87cb5623a5';
$password = '6d93d6d8';
$pdo = new PDO($dsn, $username, $password);
$id = $_GET["id"];
if ($id == NULL){
header( "Location: index.php" ) ;
exit;
}
$json = file_get_contents("https://www.googleapis.com/books/v1/volumes/$id?key=AIzaSyBczORlfI6MEmYnkTFwP5au6rq_oo4h92s");
$results = json_decode($json, TRUE);
foreach ($results[volumeInfo][industryIdentifiers] as $i => $identifier) {
if ($identifier[type] === "ISBN_10") {
$isbn10 = $identifier[identifier];
}
if ($identifier[type] === "ISBN_13") {
$janCode = $identifier[identifier];
}
}
$title = $results[volumeInfo][title]." ".$results[volumeInfo][subtitle];
$publishedDate = $results[volumeInfo][publishedDate];
$description = $results[volumeInfo][description];
$publisher = $results[volumeInfo][publisher];
$categories = $results[volumeInfo][categories];
foreach($results[volumeInfo][authors] as $i => $author) {
$authors = $authors.$author." ";
}
$authors = rtrim($authors,' ');
if ($results[volumeInfo][imageLinks][small] == NULL){
if ($results[volumeInfo][imageLinks][thumbnail] == NULL){
$imageLink = "img/noimage.png";
} else {
$imageLink = $results[volumeInfo][imageLinks][thumbnail];
}
} else {
$imageLink = $results[volumeInfo][imageLinks][small];
}
$listPrice = $results[saleInfo][listPrice][amount];
$stmt = $pdo->query("SELECT Price FROM product WHERE JANCode = $janCode");
if ($result = $stmt->fetch()) {
$listPrice = $result[Price];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="css/book.css">
<link rel="icon" href="img/favicon.ico">
<title>O書店</title>
</head>
<body>
<header>
<h1><a href="index.php">O書店</a></h1>
<span>Web注文機能を使うためには、ログインしてください</span>
<a id="login" href="">ログイン</a>
</header>
<form id="search" method="get" action="search.php">
<input name="q" type="search" placeholder="書籍を検索">
<input type="submit" value="">
</form>
<div id="main">
<section id="container">
<img alt="<?php echo $title ?>" src="<?php echo $imageLink ?>">
<div>
<a id="add" class="button" href="cart_update.php?id=<?php echo $id ?>">カートに追加</a>
<h2><?php echo $title ?></h2>
<p class="publishedDate"><?php echo $publishedDate ?></p>
<p><?php echo $authors ?></p>
<p class="price">¥ <?php
if ($listPrice == NULL){
echo "(注文確定後にお知らせ)";
} else {
echo $listPrice;
}
?></p>
<h3>在庫状況</h3>
<table>
<tr>
<?php
$stmt = $pdo->query("SELECT StoreName FROM store");
foreach ($stmt as $row) {
echo "<th>$row[StoreName]</th>";
$storeCount++;
}
?>
</tr>
<tr>
<?php
for ($i = 0; $i < $storeCount; $i++){
$stmt = $pdo->query("SELECT Num FROM stock WHERE JANCode = $janCode AND StoreNumber = $i");
$stock = $stmt->fetch();
$num = $stock[Num];
echo '<td>';
if ($num == 0 || !$stock) {
echo '×';
} else if ($num < 5) {
echo '△';
} else {
echo '〇';
}
echo '</td>';
}
?>
</tr>
</table>
</div>
</section>
<section id="info">
<?php
if ($description != NULL){
echo '<h3>商品説明</h3>';
echo "<p>$description</p>";
}
?>
<?php
if ($categories != NULL){
echo '<h3>ジャンル</h3>';
foreach($categories as $i => $category) {
echo "<p>$category</p>";
}
}
?>
<h3>出版社</h3>
<p><?php echo $publisher ?></p>
</section>
</div>
<footer>
<a href="">規約</a>
<a href="">プライバシー</a>
<a href="">店舗</a>
</footer>
</body>
</html>