This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducts.php
318 lines (248 loc) · 11.9 KB
/
products.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
<?php
include_once("backend/connection.php");
include_once("header.php");
$productid = $_GET['prod_id'];
$sql = "SELECT * FROM product,inventory WHERE product.inv_id=inventory.inv_id AND prod_id=".$productid;
$result = $conn->query($sql);
$result = $result->fetch_assoc();
if ($result['inv_discount'] == 0) {
$tts_price = number_format($result['inv_price'] ,2);
} else {
$tts_price = number_format($result['inv_price'] - ($result['inv_price'] * ($result['inv_discount'] * 0.01)),2);
}
$addToViews = "UPDATE product,inventory SET inv_views = inv_views + 1 WHERE product.inv_id=inventory.inv_id AND prod_id=".$productid;
$conn->query($addToViews);
$TTS_data = $result['prod_name'].". Price. ".$tts_price." . Pesos";
?>
<!DOCTYPE html>
<html>
<head>
<title>BakaAG</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/admin/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/style_global.css">
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<? echo $result['prod_picture_link'];?>
<br><br>
<div class="container-fluid">
<div class="row container-center">
<div class="col-lg-5">
<div class="bs-component">
<div class="card border-primary mb-3" style="max-width: 30rem;">
<div class="card-header"><h4 style="display: inline-block !important;"><?php echo $result['prod_name']?></h4><input class="btn btn-link" style="display: inline-block !important; cursor: pointer;" onclick='responsiveVoice.speak(<?php echo "\"".$TTS_data."\""; ?>, "Japanese Female");' type='button' value='🔊' /></div>
<div class="card-body text-primary">
<h4 class="card-title"></h4>
<p class="card-text">
<?php echo '<div id="main-image" style="width: 350px; height: 250px; background-image: url(\''.$result['prod_picture_link'].'\'); background-size: cover; background-repeat: no-repeat; background-position:center center;" class="img-responsive"></div>';?>
<!--<div class="row small-thumbnail">
<a href="#1"><div id="thumbA" style="width: 60px; height: 60px; background-image: url('img/1.jpg'); background-size: cover; background-repeat: no-repeat; background-position: 50% 50%;" class="img-responsive"></div></a>
<a href="#2"><div id="thumbB" style="width: 60px; height: 60px; background-image: url('img/2.jpg'); background-size: cover; background-repeat: no-repeat; background-position: 50% 50%;" class="img-responsive"></div></a>
<a href="#3"><div id="thumbC" style="width: 60px; height: 60px; background-image: url('img/3.jpg'); background-size: cover; background-repeat: no-repeat; background-position: 50% 50%;" class="img-responsive"></div></a>
<a href="#4"><div id="thumbD" style="width: 60px; height: 60px; background-image: url('img/4.jpg'); background-size: cover; background-repeat: no-repeat; background-position: 50% 50%;" class="img-responsive"></div></a>
</div>-->
</p>
</div>
</div>
</div>
</div>
<div id="success" style="display: none; position: fixed; width: 25%; top: 80%; left: 70%; z-index: 100;"
class="alert alert-dismissible alert-success">
<strong>Success!</strong>
</div>
<div id="error" style="display: none; position: fixed; width: 25%; top: 80%; left: 70%; z-index: 100;"
class="alert alert-dismissible alert-danger">
<strong>Error!</strong>
</div>
<div class="col-lg-7 data-container">
<div class="bs-component">
<div class="card border-primary mb-3" style="max-width: 65rem;">
<div class="card-header">Product Details</div>
<div class="card-body text-primary">
<h4 class="card-title">PHP
<?php
if ($result['inv_discount'] == 0) {
echo number_format($result['inv_price'] ,2);
} else {
echo number_format($result['inv_price'] - ($result['inv_price'] * ($result['inv_discount'] * 0.01)),2);
echo "<p style='color:orange;'>".$result['inv_discount']."% OFF! </p>";
}
?>
</h4>
<p class="card-text">
<button type="button" class="btn btn-primary" style="cursor: pointer;" onclick="addtocart(<?php echo $result['prod_id']?>)">Add to cart</button>
<span class="glyphicon glyphicon-shopping-heart"></span>
<?php
if (isset($_SESSION['acc_id'])) {
$sql_wish = "SELECT * FROM wishlist WHERE acc_id=".$_SESSION['acc_id']." AND prod_id=".$_GET['prod_id'];
$result_wish = $conn->query($sql_wish);
if (mysqli_num_rows($result_wish) > 0) {
echo '<button type="button" class="btn btn-primary disabled">Product already in wishlist</button>';
} else {
echo '<button type="button" id="addToWishlist" style="cursor: pointer;" class="btn btn-primary">Add to wishlist</button>';
}
echo '<input id="acc_id" type="number" class="hidden" value="'.$_SESSION['acc_id'].'" >';
echo '<input id="prod_id" type="number" class="hidden" value="'.$_GET['prod_id'].'" >';
echo '<input id="inv_id" type="number" class="hidden" value="'.$result['inv_id'].'" >';
}
?>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Product Type</th>
<th scope="col">Genre</th>
<th scope="col">Stock</th>
</tr>
</thead>
<tbody>
<tr class="table-active">
<th scope="row"><?php
$sql2 = "SELECT prod_type_name FROM product_type WHERE prod_type_id=".$result['prod_type_id'];
$result2 = $conn->query($sql2);
$result2 = $result2->fetch_assoc();
echo $result2['prod_type_name'];
?></th>
<td><?php
$sql2 = "SELECT prod_genre_name FROM product_genre WHERE prod_genre_id=".$result['prod_genre_id'];
$result2 = $conn->query($sql2);
$result2 = $result2->fetch_assoc();
echo $result2['prod_genre_name'];
?></td>
<td><?php
if($result['inv_stock']>0)
echo "In stock";
else
echo "Out of stock";
?></td>
</tr>
</tbody>
</table>
<div>
<?php
$sql_rating_sum = "SELECT SUM(rate_num) AS total FROM rating WHERE inv_id=".$result['inv_id'];
$sql_rating_count = "SELECT COUNT(rate_num) AS counter FROM rating WHERE inv_id=".$result['inv_id'];
$sql_check_rating = "SELECT * FROM rating WHERE inv_id=".$result['inv_id'];
$result_check_rating = $conn->query($sql_check_rating);
$people_rates = "(0 people voted for this item)";
if (mysqli_num_rows($result_check_rating) > 0) {
$result_rating_sum = $conn->query($sql_rating_sum);
$result_rating_count = $conn->query($sql_rating_count);
$fetch_sum = $result_rating_sum->fetch_assoc();
$fetch_count = $result_rating_count->fetch_assoc();
$sum = $fetch_sum['total'];
$count_rating = $fetch_count['counter'];
$formula = ($sum / $count_rating) / 5 * 100;
$star = '';
$people_rates = " (".$fetch_count['counter']." user(s) voted for this item)";
for ($i=1; $i <= $formula; $i++) {
if (($i % 20) == 0) {
$star .= "★";
}
}
} else {
$star = "NO RATING";
}
echo '<h4>RATING: '.'<span style="color:gold !important;">'.$star.'</span><small>'.$people_rates.'</small></h4>';
if (isset($_SESSION['acc_id'])) {
echo '
<ul class="pagination">
<li class="page-item">
<a id="rate-btn-1" style="cursor:pointer;" class="page-link">1</a>
</li>
<li class="page-item">
<a id="rate-btn-2" style="cursor:pointer;" class="page-link">2</a>
</li>
<li class="page-item">
<a id="rate-btn-3" style="cursor:pointer;" class="page-link">3</a>
</li>
<li class="page-item">
<a id="rate-btn-4" style="cursor:pointer;" class="page-link">4</a>
</li>
<li class="page-item">
<a id="rate-btn-5" style="cursor:pointer;" class="page-link">5</a>
</li>
</ul>
';
}
?>
</div>
<hr>
<h4>Product Description</h4>
<p><?php echo $result['prod_desc']?></p>
</p>
</div>
</div>
</div>
<div class="card border-primary mb-3" style="height: 600px;">
<div class="card-header">Comments</div>
<div class="card-body" style="padding-bottom: 20px; overflow-y: scroll;">
<?php
if (isset($_SESSION['acc_id'])) {
echo '
<div class="form-group">
<textarea id="comment-box" maxlength="380" placeholder="Enter Comment" class="form-control" id="exampleTextarea" rows="3" style="margin-top: 0px; margin-bottom: 0px; height: 107px;"></textarea>
<button id="add-comment" style="cursor:pointer;" class="btn btn-primary btn-sm">Add Comment</button>
</div>
';
}
?>
<div id="comment-container" class="comment-container">
<?php
$sql = "SELECT * FROM comments,account WHERE comments.prod_id=".$_GET['prod_id']." AND comments.acc_id=account.acc_id ORDER BY comment_date DESC LIMIT 6";
$result_comments = $conn->query($sql);
if (mysqli_num_rows($result_comments) < 1) {
echo "<center><small>NO COMMENTS</small></center>";
}
$viewAllComments = '';
if (mysqli_num_rows($result_comments) >= 6) {
$viewAllComments = '<center><button id="view-all" style="cursor:pointer;" class="btn btn-primary btn-sm">View All Comments</button></center>';
}
while ($getComments = $result_comments->fetch_assoc()) {
echo '
<div>
<span class="badge badge-info">'.$getComments['acc_fname']." ".$getComments['acc_lname'].'</span><br><br>
<p style="text-align: justify;">'.$getComments['content'].'</p>
<small>'.date('g:ia \o\n l jS F Y', strtotime($getComments['comment_date'])).'</small>
<hr>
</div>
';
}
echo $viewAllComments;
?>
</div>
</div>
</div>
<div class="card border-primary mb-3" id="all-comments" style="padding-bottom: 10px; width: 90%; z-index: 300; position: fixed; display: none; top: 0; left: 0; top: 5%; left: 5%;">
<div class="card-header">Comments</div>
<div class="card-body" style="padding-bottom: 20px; height: 450px; overflow-y: scroll;">
<div id="comment-container-all" class="comment-container">
<?php
$sql_getAllComments = "SELECT * FROM comments,account WHERE comments.prod_id=".$_GET['prod_id']." AND comments.acc_id=account.acc_id ORDER BY comment_date DESC";
$result_comments_all = $conn->query($sql_getAllComments);
while ($getAllComments = $result_comments_all->fetch_assoc()) {
echo '
<div>
<span class="badge badge-info">'.$getAllComments['acc_fname']." ".$getAllComments['acc_lname'].'</span><br><br>
<p style="text-align: justify;">'.$getAllComments['content'].'</p>
<small>'.date('g:ia \o\n l jS F Y', strtotime($getAllComments['comment_date'])).'</small>
<hr>
</div>
';
}
?>
</div>
</div>
<button id="close-view-all" style="cursor:pointer; margin-left: 10px;" class="btn btn-primary btn-sm">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/funcs.js"></script>
<script src='https://code.responsivevoice.org/responsivevoice.js'></script>
</body>
</html>
<?php
include_once("footer.php");
?>