-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook.php
155 lines (130 loc) · 5.85 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
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
<?php
/**
* Created by PhpStorm.
* User: beeker
* Date: 2019-04-12
* Time: 15:49
*/
require_once 'db-connect.php';
session_start();
unset($_SESSION['wish']);
unset($_SESSION['cart']);
$isbn = $_GET['isbn'];
$email = $_SESSION['email'];
$queryString;
if(!$email) {
$queryString = 'SELECT b.title, b.isbn, b.price, b.pages, b.binding, b.pubDate, b.description, b.imageFilename, a.compositeName FROM tblBooks b' .
' LEFT JOIN tblBooksAuthorsXref xref ON xref.isbn = b.isbn LEFT JOIN tblAuthors a ON xref.authorId = a.authorId' .
" WHERE b.isbn='$isbn';";
} else {
$queryString = 'CREATE TABLE FilteredUC(cemail varchar(225), isbn char(16), PRIMARY KEY(cemail, isbn));';
$myConn->set_query_string($queryString);
$result = $myConn->execute_query();
$queryString = 'CREATE TABLE FilteredUW(wemail varchar(225), isbn char(16), PRIMARY KEY(wemail, isbn));';
$myConn->set_query_string($queryString);
$result = $myConn->execute_query();
$queryString = "INSERT INTO FilteredUC (cemail, isbn) SELECT email, isbn FROM tblUserCartXref ucx WHERE ucx.email = '$email';";
$myConn->set_query_string($queryString);
$result = $myConn->execute_query();
$queryString = "INSERT INTO FilteredUW (wemail, isbn) SELECT email, isbn FROM tblUserWishXref uwx WHERE uwx.email = '$email';";
$myConn->set_query_string($queryString);
$result = $myConn->execute_query();
$queryString = 'SELECT b.title, b.isbn, b.price, b.pages, b.binding, b.pubDate, b.description, b.imageFilename, a.compositeName, fuc.cemail, fuw.wemail FROM tblBooks b' .
' LEFT JOIN tblBooksAuthorsXref xref ON xref.isbn = b.isbn LEFT JOIN tblAuthors a ON xref.authorId = a.authorId' .
' LEFT JOIN FilteredUC fuc ON fuc.isbn = b.isbn LEFT JOIN FilteredUW fuw ON fuw.isbn = b.isbn' .
" WHERE b.isbn='$isbn';";
}
$myConn->set_query_string($queryString);
$result = $myConn->execute_query();
if (!$result)
die ('The query failed for some reason');
$book = $myConn->get_first_result(RETURN_OBJECT);
$description = preg_replace('/[^(\x20-\x7F)]*/', '', html_entity_decode($book->description));
function clean($str){
$trimmed = $str;
return $trimmed;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Volga/<?php echo $book->title ?></title>
<link href="style.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,600,800" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">
</head>
<body>
<div class="inner">
<form class="left" id="searchBar" method="post" action="books.php">
<input class="left" type="text" name="muse" id="search"/>
<select class="left" id="searchOptions" name="category" size="1">
<option selected>Title</option>
<option>Author</option>
<option>Isbn</option>
</select>
<input class="left" type="submit" id="searchButton" value="SEARCH"/>
</form>
<p class="account right"><?php
if(!$_SESSION["name"]){
echo '<a class="login" href="login.html">Login</a>';
} else {
echo 'Hello, ' . $_SESSION["name"] . "     <a class='login' href='cart.php'>Cart</a>     <a class='login' href='wishlist.php'>Wishlist</a>     <a class='login' href='logout.php?href=book.php?isbn=$isbn'>Logout</a>";
}
?>
</p>
<a id="logo" href="index.php">
<h1>Volga</h1>
</a>
</div>
<header>
<nav class="inner">
<!-- Start nav list-->
<ul>
<li>
<a href="index.php">
Home
</a>
</li><li>
<a href="books.php">
Books
</a>
</li><li>
<a href="get-genres.php">
Genres
</a>
</li>
</ul><!-- End nav list -->
</nav>
</header>
<div class="inner">
<div class="left" id="imgHolder">
<img id="pic" src="images/books/<?php echo $book->imageFilename ?>" alt="book cover for <?php echo $book->title?>" width="391px">
<h3 id="pages"><?php echo $book->pages ?> Pages</h3>
</div>
<div class="right" id="booksDetails">
<h2><?php echo $book->title . ' (' . $book->binding . ')' ?></h2>
<h3><?php echo $book->compositeName ?></h3>
<p><?php print($description) ?></p>
</div>
<div id="bottomContent">
<h4 id="price">$<?php echo sprintf("%.2f", $book->price) ?></h4>
<?php
if(!$book->cemail){
echo '<a href="addcart.php?href=book.php?isbn=' . $book->isbn . '&isbn=' . $book->isbn . '" class="addCart">Add To Cart</a>';
} else {
echo '<a href="removecart.php?href=book.php?isbn=' . $book->isbn . '&isbn=' . $book->isbn . '" class="addCart" style="font-size:15px">Remove From Cart</a>';
}
if(!$book->wemail){
echo '<a href="addwishlist.php?href=book.php?isbn=' . $book->isbn . '&isbn=' . $book->isbn . '" class="addWish">Add To Wishlist</a>';
} else {
echo '<a href="removewishlist.php?href=book.php?isbn=' . $book->isbn . '&isbn=' . $book->isbn . '" class="addWish" style="font-size:12px;">Remove from Wishlist</a>';
}
$queryString = 'DROP TABLE FilteredUC, FilteredUW;';
$myConn->set_query_string($queryString);
$result = $myConn->execute_query();
?>
</div>
</div>
</body>
</html>