-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproduct_page.php
More file actions
130 lines (121 loc) · 5.51 KB
/
product_page.php
File metadata and controls
130 lines (121 loc) · 5.51 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
<?php
require_once "templates/page_setup.php";
include "templates/header.php";
$dbh = new Database();
$productID = checkProductID();
$ingredient = $dbh->getIngredientByID($productID);
$reviewArray = $dbh->getCommentsForIngredient($ingredient);
$reviewCount = $dbh->getNumberOfCommentsForIngredient($ingredient);
$page_name = $ingredient->name;
$title = $ingredient->name;
include 'templates/jumbotron.php';
?>
<div class = "container-fluid product-details" id ="product_details">
<div class="row">
<div class="col-md-3" id = "productImgCol">
<img class = "product-image" src = "<?php echo 'assets/img/'.$ingredient->imgURL;?>" alt="product_image" style="">
</div>
<div class = "col-md-3" id="productDetailsCol">
<?php
if (isset($_SESSION['status'])){
if($_SESSION['status']=='Admin'){
echo
'<div>
<a href="ingredient_form.php?action=update&id='.$productID.'" class = "btn bth-default btn-sm">Click here to edit ingredient. <span class ="glyphicon glyphicon-pencil"></span></a>
<a href="ingredient_form.php?action=delete&id='.$productID.'" class = "btn bth-default btn-sm">Click here to delete ingredient. <span class ="glyphicon glyphicon-minus"></span></a><br>
</div>';
}
}
?>
<h3><?php echo $ingredient->name; ?></h3>
<p><?php echo $ingredient->description;?></p>
<?php echo $dbh->getRatingStars($dbh->averageRating($ingredient));?>
<span class =""><a href="#reviewList"><?php echo $reviewCount;?> Reviews</a></span>
<?php if (isset($_SESSION['username']) and $_SESSION['username']!="Guest"): //adds a cart option if user is signed in ?>
<h4><a href="cart.php<?php echo "?action=cart&id=$productID";?>">Add to Cart</a></h4>
<?php endif;?>
<h4>$<?php echo $ingredient->price;?></h4>
</div>
<div class = "col-md-3" id=productPurchaseCol>
</div>
</div>
<hr>
<div class = "row">
<div class = "col-sm-6" id="reviewList" style="margin-left:20px;">
<?php
if(isset($_SESSION['status'])){
if($_SESSION['status']=='Admin'){
foreach ($reviewArray as $r){
echo
'<div>
<a href="comment_form.php?action=edit&id='.$r->id.'" class="btn bth-default btn-sm">Edit '.$r->name.'\'s comment. <span class ="glyphicon glyphicon-pencil"></span></a>
<a href="comment_form.php?action=delete&id='.$r->id.'" class="btn bth-default btn-sm">Delete '.$r->name.'\'s comment. <span class ="glyphicon glyphicon-minus"></span></a>
</div>
';
}
}
}
?>
<h3>Reviews and Comments</h3>
<?php if(!empty($_SESSION['valid'])){?>
<?php if(isset($submissionOkay) and $submissionOkay ===true):?>
<div class = "alert alert-success" id="formSuccess">
<?php echo "Your review was submitted successfully";?>
</div>
<?php endif;?>
<?php if(isset($submissionOkay) and $submissionOkay != true):?>
<div class = "alert alert-danger" id = "formError">
<?php echo "There was an error with your review ksubmission, please try again.";?>
</div>
<?php endif;?>
<p><button type="button" class="btn btn-info" data-toggle="collapse" data-target="#reviewForm">Review this product</button></p>
<div id="reviewForm" class="collapse">
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) . "?action=review&id=$productID"; ?>">
<div class="form-group">
<label for="nameInput">Your name *</label>
<input type="text" name="name" class="form-control" id="nameInput" placeholder="Enter name" required="true">
</div>
<div class="form-group">
<label for="ratingInput">Your rating *</label><br>
<label class="radio-inline">
<input type="radio" name="rating" value="1" required="true">1
</label>
<label class="radio-inline" >
<input type="radio" name="rating" value="2" required="true">2
</label>
<label class="radio-inline">
<input type="radio" name="rating" value="3" required="true">3
</label>
<label class="radio-inline">
<input type="radio" name="rating" value="4" required="true">4
</label>
<label class="radio-inline">
<input type="radio" name="rating" value="5" required="true">5
</label>
</div>
<div class="form-group">
<label for="commentsInput">Comments</label>
<textarea class="form-control" name="words" id="commentsInput" rows="4"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<?php
} else{
?>
<p style="color:red;">You must be logged in to review!</p>
<?php } ?>
<?php
foreach($reviewArray as $r){
echo '<hr>
<div class = "review">
<h4>Posted by <i>'.$r->name.'</i></h4>
<p>'.$dbh->getRatingStars($r->rating).'</p>
<p>'.$r->words.'</p>
</div>';
}
?>
</div>
</div>
</div>
<?php require 'templates/footer.php';?>