-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
357 lines (331 loc) · 12.9 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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
session_start();
$conn = new mysqli("localhost", "root", "", "accounts");
if(mysqli_connect_error()){
die('Connect Error('. mysqli_connect_error().')'. mysqli_connect_error());
}else {
$sqlRows = "SELECT * FROM listings";
$sqlRowData = mysqli_query($conn, $sqlRows);
$numRows = mysqli_num_rows($sqlRowData);
// Get the array of the latest tuple
$sqlTop = "SELECT * FROM listings WHERE ID=$numRows";
$sqlTopData = mysqli_query($conn, $sqlTop);
$latestListing = mysqli_fetch_assoc($sqlTopData);
$frstImgUrl = "./uploads/{$latestListing['Image1']}";
// Get the 2nd latest tuple
$scndTop = $numRows-1;
$sqlScnd = "SELECT * FROM listings WHERE ID=$scndTop";
$sqlScndData = mysqli_query($conn, $sqlScnd);
$scndListing = mysqli_fetch_assoc($sqlScndData);
$scndImgUrl = "./uploads/{$scndListing['Image1']}";
// Get the 3rd latest tuple
$thirdTop = $numRows-2;
$sqlTHIRDTop = "SELECT * FROM listings WHERE ID=$thirdTop";
$sqlTHIRDData = mysqli_query($conn, $sqlTHIRDTop);
$thirdListing = mysqli_fetch_assoc($sqlTHIRDData);
$thirdImgUrl = "./uploads/{$thirdListing['Image1']}";
//map {very poor: 1, ..., Excellent: 5}
//This is for creating star rating later
$ratingScale = array(
"Very Poor"=>1,
"Poor"=>2,
"Fair"=>3,
"Good"=>4,
"Excellent"=>5
);
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Triple-B</title>
<!-- <link rel="stylesheet" href="styles.css"> -->
<link rel="stylesheet" href="styles.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="nav-styles.css?v=<?php echo time(); ?>">
</head>
<body>
<nav>
<div class ="container">
<a href="index.php" class="nav-left">
<h1>Buy Borrow Books</h1>
</a>
<ul class="nav-right">
<li class="item"><a href="index.php" ><ion-icon name="home-outline" class="mobileHome"></ion-icon></ion-icon></a></li>
<li class="item"><a href="browse.php" ><ion-icon name="search-outline"></ion-icon></a></li>
<li class="item"><a href="profile.php" ><ion-icon name="person-outline"></ion-icon></ion-icon></a></li>
<!-- Sign Out / Log In Logic -->
<?php
$sqlLoggedIn = "SELECT * FROM users";
$sqlLogInQuery = mysqli_query($conn, $sqlLoggedIn);
$LoggedIn = false;
while($logResult = mysqli_fetch_array($sqlLogInQuery)){
if ($logResult['Active']) {
$LoggedIn = true;
break;
}
}
if($LoggedIn){
echo '<li><a href="login.html" class="action">Sign In/Out</a></li>';
// $latestListing['Active'] = false;
$updateActivity = "UPDATE users SET Active=false WHERE Active=true";
if(mysqli_query($conn, $updateActivity)) {
} else {
}
} else {
echo '<li><a href="login.html" class="action">Sign In/Out</a></li>';
}
?>
</ul>
</div>
</nav>
<!-- hero -->
<div class="hero">
<h1>Welcome</h1>
</div>
<!-- First View -->
<div class="category-section">
<div class="mix-grid">
<!-- LATEST BOOK -->
<div class="nested">
<h3><?php echo $latestListing['TextbookTitle'];?></h3>
<?php echo "<a href='listing.php?tupleID=$latestListing[ID]'><img src='$frstImgUrl' alt='Image 1'></a>"?>
<div>
<!-- Category Description -->
<div>
<div class="category-title">
<h4>PRICE: $<?php echo $latestListing['Price'];?></h4>
</div>
<div class="category-title">
<h4>ISBN:</h4>
<?php echo $latestListing['ISBN'];?>
</div>
<div class="category-title">
<h4>DESCRIPTION:</h4>
<?php echo $latestListing['Description'];?>
</div>
<div class="more-info">
<h6>click the book for more information...</h6>
</div>
</div>
</div>
<!-- Ranking system -->
<div class="rating">
<!-- CREATES 5 STAR RATING BASED ON THE BOOK -->
<?php
$goldStars = $ratingScale[$latestListing['BookCondition']];
$blankStars = 5- $goldStars;
for($stars = 0; $stars < $goldStars; $stars++){
echo '<p class="star s-active"></p>';
}
for($greystars = 0; $greystars < $blankStars; $greystars++){
echo '<p class="star"></p>';
}
?>
</div>
</div>
<!-- SECOND TO LATEST BOOK -->
<div class="nested">
<h3><?php echo $scndListing['TextbookTitle'];?></h3>
<?php echo "<a href='listing.php?tupleID=$scndListing[ID]'><img src='$scndImgUrl' alt='Image 1'></a>"?>
<div>
<!-- Category Description -->
<div>
<div class="category-title">
<h4>PRICE: $<?php echo $scndListing['Price'];?></h4>
</div>
<div class="category-title">
<h4>ISBN:</h4>
<?php echo $scndListing['ISBN'];?>
</div>
<div class="category-title">
<h4>DESCRIPTION:</h4>
<?php echo $scndListing['Description'];?>
</div>
<div class="more-info">
<h6>click the book for more information...</h6>
</div>
</div>
</div>
<!-- Ranking system -->
<div class="rating">
<!-- CREATES 5 STAR RATING BASED ON THE BOOK -->
<?php
$goldStars = $ratingScale[$scndListing['BookCondition']];
$blankStars = 5- $goldStars;
for($stars = 0; $stars < $goldStars; $stars++){
echo '<p class="star s-active"></p>';
}
for($greystars = 0; $greystars < $blankStars; $greystars++){
echo '<p class="star"></p>';
}
?>
</div>
</div>
<!-- THIRD TO LATEST BOOK -->
<div class="nested">
<h3><?php echo $thirdListing['TextbookTitle'];?></h3>
<?php echo "<a href='listing.php?tupleID=$thirdListing[ID]'><img src='$thirdImgUrl' alt='Image 1'></a>"?>
<div>
<!-- Category Description -->
<div>
<div class="category-title">
<h4>PRICE: $<?php echo $thirdListing['Price'];?></h4>
</div>
<div class="category-title">
<h4>ISBN:</h4>
<?php echo $thirdListing['ISBN'];?>
</div>
<div class="category-title">
<h4>DESCRIPTION:</h4>
<?php echo $thirdListing['Description'];?>
</div>
<div class="more-info">
<h6>click the book for more information...</h6>
</div>
</div>
</div>
<!-- Ranking system -->
<div class="rating">
<!-- CREATES 5 STAR RATING BASED ON THE BOOK -->
<?php
$goldStars = $ratingScale[$thirdListing['BookCondition']];
$blankStars = 5- $goldStars;
for($stars = 0; $stars < $goldStars; $stars++){
echo '<p class="star s-active"></p>';
}
for($greystars = 0; $greystars < $blankStars; $greystars++){
echo '<p class="star"></p>';
}
?>
</div>
</div>
</div>
<!-- List sections -->
<div class="list-section">
<div class="list-title">
<h2 class="desktopTitle">🖥️ Popular Computer Science Books 💻</h2>
<h2 class="mobileTitle">🖥️ Computer Science 💻</h2>
</div>
<div class="scroller-grid">
<!-- cs book 1 -->
<a href="listing.php?tupleID=11">
<div class="book-cont">
<img src="./uploads/204169227771iTDxDY7CL.jpg" alt="image">
<div class="listing-info">
<p>Price: $100<br>Condition: Excellent</p>
<p class="smol-text">click to learn more...</p>
</div>
</div>
</a>
<!-- cs book 2 -->
<a href="listing.php?tupleID=13" class="book-cont">
<img src="./uploads/90625752581Uec7eLvaL.jpg" alt="image">
<div class="listing-info">
<p>Price: $200<br>Condition: Very Poor</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- cs book 3 -->
<a href="listing.php?tupleID=14" class="book-cont">
<img src="./uploads/411ejyE8obL._SX377_BO1,204,203,200_.jpg" alt="image">
<div class="listing-info">
<p>Price: $0<br>Condition: Fair</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- cs book 4 -->
<a href="listing.php?tupleID=12" class="book-cont">
<img src="./uploads/12125434891JLJ+dZOUL.jpg" alt="image">
<div class="listing-info">
<p>Price: $400<br>Condition: Good</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
</div>
</div>
<div class="list-section">
<div class="list-title">
<h2 class="desktopTitle">🧪 Popular Chemistry Books ⚗️</h2>
<h2 class="mobileTitle">🧪 Chemistry Books ⚗️</h2>
</div>
<div class="scroller-grid">
<!-- chem book 1 -->
<a href="listing.php?tupleID=7" class="book-cont">
<img src="./uploads/fchem.jpg" alt="image">
<div class="listing-info">
<p>Price: $275<br>Condition: Fair</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- chem book 2 -->
<a href="listing.php?tupleID=8" class="book-cont">
<img src="./uploads/ochem.jpg" alt="image">
<div class="listing-info">
<p>Price: $600<br>Condition: Excellent</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- chem book 3 -->
<a href="listing.php?tupleID=9" class="book-cont">
<img src="./uploads/bchem.jpg" alt="image">
<div class="listing-info">
<p>Price: $350<br>Condition: Good</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- chem book 4 -->
<a href="listing.php?tupleID=10" class="book-cont">
<img src="./uploads/chem book.jpg" alt="image">
<div class="listing-info">
<p>Price: $828<br>Condition: Good</p>
<p class="smol-text">click to learn more...</p>
</div>
</a></div>
</div>
<div class="list-section">
<div class="list-title">
<h2 class="desktopTitle">🌎 Popular Geology Books 🌍</h2>
<h2 class="mobileTitle">🌎 Geology Books 🌍</h2>
</div>
<div class="scroller-grid">
<!-- geo book 1 -->
<a href="listing.php?tupleID=15" class="book-cont hiddenMobile">
<img src="./uploads/51e7lVxA-ZL._SL500_.jpg" alt="image">
<div class="listing-info">
<p>Price: $123<br>Condition: Poor</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- geo book 2 -->
<a href="listing.php?tupleID=16" class="book-cont hiddenMobile">
<img src="./uploads/51el5oz411L.jpg" alt="image">
<div class="listing-info">
<p>Price: $452<br>Condition: Excellent</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- geo book 3 -->
<a href="listing.php?tupleID=17" class="book-cont">
<img src="./uploads/613OsdBOPXL.jpg" alt="image">
<div class="listing-info">
<p>Price: $253452<br>Condition: Very Poor</p>
<p class="smol-text">click to learn more...</p>
</div>
</a>
<!-- geo book 4 -->
<a href="listing.php?tupleID=18" class="book-cont">
<img src="./uploads/9780393667523_300.jpeg" alt="image">
<div class="listing-info">
<p>Price: $34343<br>Condition: Poor</p>
<p class="smol-text">click to learn more...</p>
</div>
</a></div>
</div>
<div class="messages">
<a href="chat2.html">👋</a>
</div>
<script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script>
</body>
</html>