-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdetail.php
More file actions
152 lines (152 loc) · 7.68 KB
/
Copy pathdetail.php
File metadata and controls
152 lines (152 loc) · 7.68 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
<!DOCTYPE html>
<html lang="en">
<?php
include("login.php");
include("review.php");
include("includes/head.php");
include("includes/scripts.php");
$logInOut = (isset($_SESSION['user'])? 'Logged in as:'.$_SESSION['user'].' '.'<a href="logout.php" data-toggle="modal" data-target="#login-modal">Logout</a>' : '<a href="#" data-toggle="modal" data-target="#login-modal">Login</a>');
if(!empty(trim($_GET['id'])) && is_numeric($_GET['id'])){
$id = (int)$_GET['id'];
$conn = setupDb($dbhost,$dbSelectUsername,$dbSelectPassword);
$stmt = $conn->prepare("SELECT COUNT(*) FROM php.product WHERE product_id=:id;"); //kijken of er uberhaupt items zijn
$stmt->bindParam(':id',$id);
$stmt->execute();
if($stmt->fetchColumn() == 1){
$product_id = $name = $description = $price = $img = $extraDes = $cat = ""; //variabelen voor productinformatie
$alreadySet = false;
$stmt = $conn->prepare("SELECT * FROM php.product LEFT OUTER JOIN php.review using(product_id) WHERE product.product_id =:id ;"); //include reviews
$stmt->bindParam(':id',$id);
if($stmt->execute()){
while($row = $stmt->fetch()){
if(!$alreadySet){ //hoeft maar 1 keer gedaan te worden
$product_id = $row[0];
$name = $row[1];
$price = $row[2];
$description = (!empty($row[3])? $row[3]: 'No description available.'); //description is niet verplicht
$img = ".".$row[4];
$extraDes = (!empty($row[5])? $row[5]: ""); //als er geen 'extraDes' is, moet het een empty string zijn
$cat = $row[6];
$_SESSION['productid'] = $product_id;
$alreadySet = true;
}
if(!empty($row[8])){
array_push($reviews,array($row[8],$row[9],$row[10])); //reviews toevoegen aan array
}
}
if(count($reviews) > 0){
$reviewText = $reviewText.showReviews($reviews);
}
else {
$reviewText = 'No reviews of "'.$name.'" yet. Be the first to write a review!'.'<hr>';
}
}
}
else{
echo "<h2>No item found with this id..</h><br>";
}
$stmt = null;
$conn = null;
}
else{
echo "No valid id set";
}
?>
<body>
<div id="navb">
<?php
include("includes/topbar.php");
include("includes/navbar.php");
?>
</div>
<div id="all">
<div id="content">
<div class="container">
<div class="col-md-12">
<ul class="breadcrumb">
<li><a href="index.php">Home</a></li>
<li><a href="search.php?cat=all">All items</a></li>
<li><a href="search.php?cat=<?php echo $cat ?>"><?php echo $cat ?></a></li>
<li><?php echo $name ?></li>
<?php if((isset($_SESSION['user'])) && $_SESSION['user'] == $admin){echo '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#edit-modal">Edit product</button>';} ?>
</ul>
</div>
<div class="col-md-3"> </div>
<div class="col-md-10">
<div class="row" id="productMain">
<div class="col-sm-6">
<div id="mainImage">
<img src=<?php echo $img?> alt="" class="img-responsive">
</div>
</div>
<div class="col-sm-6">
<div class="box">
<h1 class="text-center"><?php echo htmlspecialchars($name) ?></h1>
<p class="price">€<?php echo htmlspecialchars($price) ?></p>
<p class="text-center-buttons">
<?php $dis=!isset($_SESSION['user'])?'disabled':''; // disable button if not logged in
echo '<a name="'. $product_id .'" class="btn btn-primary add_basket" '.$dis.' >Add to cart<i class="fa fa-shopping-cart"></i></a>'; ?>
</p>
</div>
<div class="row" id="thumbs">
<div class="col-xs-4">
<a href=<?php echo $img ?> class="thumb">
<img src=<?php echo $img ?> alt="" class="img-responsive">
</a>
</div>
<div class="col-xs-4">
<a href=<?php echo str_replace(".jpg","_2.jpg",$img) ?> class="thumb">
<img src=<?php echo str_replace(".jpg","_2.jpg",$img) ?> alt="" class="img-responsive">
</a>
</div>
</div>
</div>
</div>
<div class="box" id="details">
<p>
<h4>Product description</h4>
<p><?php echo htmlspecialchars($description);?></p>
<?php if(!empty($extraDes)){
echo '<hr>
<blockquote>
<p><em>'.$extraDes.'</em>
</p>
</blockquote>';
} ?>
</div>
<?php reviewPrint($reviewText);?>
</div>
</div>
<div class="modal fade" id="edit-modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit</h4>
</div>
<div class="modal-body">
<div class="box">
<form action="edit.php" id="form" method="POST">
<p>Product name:</p>
<input type = "text" name="productname" class="form-control" value="<?php echo $name ?>">
<p>Product price:</p>
<input type = "text" name="productprice" class="form-control" value="<?php echo $price ?>">
<p>Product description:</p>
<textarea name="productdesc" form="form" class="form-control"><?php echo $description ?></textarea>
</form>
</div>
</div>
<div class="modal-footer">
<input class="btn btn-primary" type = "submit" value="Edit product" form="form">
<button type ="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<?php
include("includes/footer.php");
include("includes/copyright.php");
?>
</body>
</html>