-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.php
executable file
·379 lines (360 loc) · 12.8 KB
/
product.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<?php
header("Content-Type: text/html; charset=utf-8");
require_once("session.php");
require_once("class.user.php");
require_once("mycart.php");
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT *
FROM users
WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
// ------------------------------------ //
// Product menu- ---------------------- //
// ------------------------------------ //
$query_RecProduct = "SELECT * FROM `product` WHERE `productid`=".$_GET["id"];
$RecProduct = $auth_user->runQuery($query_RecProduct);
$RecProduct->execute();
$row_RecProduct=$RecProduct->fetch(PDO::FETCH_ASSOC);
// ------------------------------------ //
// Category menu- ---------------------- //
// ------------------------------------ //
$query_RecCategory = "SELECT `category`.`categoryid`, `category`.`categoryname`, `category`.`categorysort`, count(`product`.`productid`) as productNum FROM `category` LEFT JOIN `product` ON `category`.`categoryid` = `product`.`categoryid` GROUP BY `category`.`categoryid`, `category`.`categoryname`, `category`.`categorysort` ORDER BY `category`.`categorysort` ASC";
$RecCategory = $auth_user->runQuery($query_RecCategory);
$RecCategory->execute();
// Total record
$query_RecTotal = "SELECT count(`productid`)as totalNum FROM `product`";
$RecTotal = $auth_user->runQuery($query_RecTotal);
$RecTotal->execute();
$row_RecTotal=$RecTotal->fetch(PDO::FETCH_ASSOC);
// ------------------------------------ //
// Shopping cart ---------------------- //
// ------------------------------------ //
$cart = unserialize($_SESSION['cart']);
if(!is_object($cart))
{
$cart = new myCart();
}
$_SESSION['cart'] = serialize($cart);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> NCTU E-SHOP </title>
<link href="style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="index.css" type="text/css" />
<style><!--Discussion form css-->
.top{
margin:auto;
width:56vw;
text-align:right;
padding:15vh 0 0 0;
font-family:微軟正黑體;
}
/*.nav{
background-color:#339;
padding: 10px 0px;
}*/
.nav a {
color: #5a5a5a;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
}
.nav li {
display: inline;
}
.CSSTableGenerator {
margin:auto;
padding:0px;
width:35vw;
}
.CSSTableGenerator table{
border-collapse: collapse;
border-spacing: 0;
width:100%;
height:100%;
margin:0px;padding:0px;
}.CSSTableGenerator tr:last-child td:last-child {
-moz-border-radius-bottomright:9px;
-webkit-border-bottom-right-radius:9px;
border-bottom-right-radius:9px;
}
.CSSTableGenerator table tr:first-child td:first-child {
-moz-border-radius-topleft:9px;
-webkit-border-top-left-radius:9px;
border-top-left-radius:9px;
}
.CSSTableGenerator table tr:first-child td:last-child {
-moz-border-radius-topright:9px;
-webkit-border-top-right-radius:9px;
border-top-right-radius:9px;
}.CSSTableGenerator tr:last-child td:first-child{
-moz-border-radius-bottomleft:9px;
-webkit-border-bottom-left-radius:9px;
border-bottom-left-radius:9px;
}.CSSTableGenerator tr:hover td{
background-color:#005fbf;
color:white;
}
.CSSTableGenerator td{
vertical-align:middle;
background-color:#e5e5e5;
border:1px solid #999999;
border-width:0px 1px 1px 0px;
text-align:left;
padding:8px;
font-size:16px;
font-family:Arial,微軟正黑體;
font-weight:normal;
color:#000000;
}.CSSTableGenerator tr:last-child td{
border-width:0px 1px 0px 0px;
}.CSSTableGenerator tr td:last-child{
border-width:0px 0px 1px 0px;
}.CSSTableGenerator tr:last-child td:last-child{
border-width:0px 0px 0px 0px;
}
.CSSTableGenerator tr:first-child td{
background:-o-linear-gradient(bottom, #005fbf 5%, #005fbf 100%);
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #005fbf) );
background:-moz-linear-gradient( center top, #005fbf 5%, #005fbf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#005fbf");
background: -o-linear-gradient(top,#005fbf,005fbf);
background-color:#005fbf;
text-align:center;
font-size:20px;
font-family:Arial, 微軟正黑體;
font-weight:bold;
color:#ffffff;
}
.CSSTableGenerator tr:first-child:hover td{
background:-o-linear-gradient(bottom, #005fbf 5%, #005fbf 100%);
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #005fbf), color-stop(1, #005fbf) );
background:-moz-linear-gradient( center top, #005fbf 5%, #005fbf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#005fbf", endColorstr="#005fbf");
background: -o-linear-gradient(top,#005fbf,005fbf);
background-color:#005fbf;
}
<!--增加留言css-->
.container{
margin:auto;
background-color:#f5f5f5;
width:800px;
padding-bottom: 20px;
}
.button{
text-align:center;
padding:20px 0;
}
.top h3{
font-family:微軟正黑體;
text-align:center;
padding:10px 0;
}
.form-group{
font-family:微軟正黑體;
font-size:16px;
}
</style>
</head>
<body>
<div class="forbeut1" >
<a href="homepage.php?"><img src="images/logo.png" width="150" align="absmiddle"></a><br><br>
</div>
<table width="80%" border="0" align="center" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td class="tdbline"><table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr valign="top">
<td width="200" class="tdrline">
<div class="boxtl"></div>
<div class="boxtr"></div>
<div class="categorybox">
<p class="heading">
<img src="images/search_icon.png" width="16" height="16" align="absmiddle"> Product
<span class="smalltext"> Search </span>
</p>
<form name="form1" method="get" action="homepage.php">
<p>
<input name="keyword" type="text" id="keyword" value="Search for anything" size="12" onClick="this.value='';">
<input type="submit" id="button" value="Search">
</p>
</form>
<p class="heading">
<img src="images/price-icon.png" width="16" height="16" align="absmiddle"> Price
<span class="smalltext"> range </span>
</p>
<form action="homepage.php" method="get" name="form2" id="form2">
<p>
<input name="price1" type="text" id="price1" value="0" size="3">
-
<input name="price2" type="text" id="price2" value="0" size="3">
<input type="submit" id="button2" value="Search">
</p>
</form>
</div>
<div class="boxbl"></div>
<div class="boxbr"></div>
<hr width="100%" size="1" />
<div class="boxtl"></div>
<div class="boxtr"></div>
<div class="categorybox">
<p class="heading">
<img src="images/type_icon.png" width="16" height="16" align="absmiddle"> Shop by Category
</p>
<ul>
<li><a href="homepage.php?"> All <span class="categorycount">(<?php echo $row_RecTotal["totalNum"];?>)</span></a></li>
<?php while($row_RecCategory=$RecCategory->fetch(PDO::FETCH_ASSOC)){ ?>
<li><a href="homepage.php?cid=<?php echo $row_RecCategory["categoryid"];?>"><?php echo $row_RecCategory["categoryname"];?> <span class="categorycount">(<?php echo $row_RecCategory["productNum"];?>)</span></a></li>
<?php }?>
</ul>
</div>
<div class="boxbl"></div>
<div class="boxbr"></div></td>
<td><div class="subjectDiv"> <span class="heading"><img src="images/store_icon.png" width="16" height="16" align="absmiddle"></span> Product Detail </div>
<div class="actionDiv"><a href="cart.php"><img src="./images/shoppingcar.jpg" title="購物車" width="90px" height="40px"></a></div>
<div class="list"> Dear <?php echo $userRow['user_email']; ?>
<ul class="pslist">
<li><a href="resetpass.php" class="c"> Reset password </a></li>
<li><a href="logout.function.php?logout=true" class="c"> Logout </a></li>
</ul>
</div>
<div class="whole">
<div class="albumDiv">
<div class="picDiv">
<?php if($row_RecProduct["productimages"]==""){?>
<img src="***" alt="No image" width="120" height="120" border="0" />
<?php }else{?>
<img src="proimg/<?php echo $row_RecProduct["productimages"];?>" alt="<?php echo $row_RecProduct["productname"];?>" width="135" height="135" border="0" />
<?php }?>
</div>
<div class="albuminfo">
<span class="smalltext"> $ </span>
<span class="redword"> <?php echo $row_RecProduct["productprice"];?></span>
</div>
</div>
<div class="contentDiv">
<div class="titleDiv">
<?php echo $row_RecProduct["productname"];?></div>
<div class="dataDiv">
<p><?php echo nl2br($row_RecProduct["description"]);?></p>
<hr width="100%" size="1" />
<form name="form3" method="post" action="cart.php">
<input name="id" type="hidden" id="id" value="<?php echo $row_RecProduct["productid"];?>">
<input name="name" type="hidden" id="name" value="<?php echo $row_RecProduct["productname"];?>">
<input name="price" type="hidden" id="price" value="<?php echo $row_RecProduct["productprice"];?>">
<input name="qty" type="hidden" id="qty" value="1">
<input type="submit" name="button3" id="button3" value="Add to Cart">
<input type="button" name="button4" id="button4" value="Back" onClick="window.history.back();">
</form>
</div>
</br>
<!-- Display message board -->
<?php
$auth_user = new USER();
$product_id = $row_RecProduct["productid"];
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT *
FROM usermessage
WHERE msg_product_id=$product_id");
$stmt->execute();
while($userRow=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="container" width="56%" >
<div class="CSSTableGenerator" width="56%">
<table align="center" width="56%">
<tr>
<td><?php echo $userRow['message_subject']?></td>
</tr>
<tr>
<td width="15%"> User #</td>
<td width="41%"><?php echo $userRow['user_id']?></td>
</tr>
<tr>
<td> Review </td>
<td><?php echo $userRow['message_content']?></td>
</tr>
</table>
</div>
</div>
<br />
<?php } ?>
<!-- Add message -->
<?php
if(isset($_POST['leavemessage']))
{
$message_subject = strip_tags($_POST['txt_message_subject']);
$message_content = strip_tags($_POST['txt_message_content']);
$product_id = $row_RecProduct["productid"];
if($message_subject=="")
{
$error[] = "Create a subject!";
}
else if($message_content=="")
{
$error[] = "Leave your question!";
}
else
{
try
{
$auth_user = new USER();
$user_id = $_SESSION['user_session'];
$stmt = $auth_user->runQuery("SELECT *
FROM users
WHERE user_id=:user_id");
$stmt->execute(array(":user_id"=>$user_id));
$auth_user->LeaveMessage($user_id,$message_subject,$message_content, $product_id);
echo "<meta http-equiv='refresh' content='0'>";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
}
?>
<form id="form1" name="form1" method="post" action="" class="form-horizontal">
<div class="form-group">
<?php
if(isset($error))
{
foreach($error as $error)
{
?>
<?php echo $error; ?>
<?php
}
}
?>
</div>
<div class="form-group">
<label for="guestSubject" class="col-sm-4 control-label"> Subject </label>
<div class="col-sm-6">
<input type="text" class="form-control" name="txt_message_subject" id="guestSubject" />
</div>
</div>
<div class="form-group">
<label for="guestContent" class="col-sm-4 control-label"> Content </label>
<div class="col-sm-6">
<textarea type="text" name="txt_message_content" class="form-control" id="guestContent" rows="5"></textarea>
</div>
</div>
<div class="button">
<input type="submit" name="leavemessage" id="button" value="Submit" class="btn"/>
</div>
</form>
</div>
</div>
</td>
</tr>
</table></td>
</tr>
<tr>
<td height="30" align="center" class="trademark"> NCTU E-Store </td>
</tr>
</table>
</body>
</html>