-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitems.php
156 lines (143 loc) · 6.36 KB
/
items.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
<?php
session_start();
$pageTitle = 'Show Items';
include("init.php");
// check if the req is GET and the itemid is number
$itemid = isset($_GET['itemid']) && is_numeric($_GET['itemid']) ? intval($_GET['itemid']) : 0;
// select all data with this id || we use ? to execute the variable next
$stmt = $con->prepare("SELECT
items.* , categories.Name AS Cat_Name , users.username
FROM
items
INNER JOIN
categories
ON
categories.ID = items.Cat_ID
INNER JOIN
users
ON
users.UserID = items.Member_ID
WHERE
Item_ID = ?
AND
Approve = 1");
// search on itemid in database
$stmt->execute(array($itemid));
$count = $stmt->rowCount();
if($count > 0){
// get the data in array form
$item = $stmt->fetch();
?>
<h1 class="text-center"><?php echo $item['Name'] ?></h1>
<div class="container">
<div class="row md-3">
<div class="col-md-3">
<img src="layout/img/avatar.png" alt="..." class="card-img-top img-thumbnail img-fluid">
</div>
<div class="col-md-9 item-info">
<h2><?php echo $item['Name'] ?></h2>
<p><?php echo $item['Description'] ?></p>
<ul class="list-unstyled">
<li><i class="bi bi-calendar-check"></i> <span>Added In</span> : <?php echo $item['Add_Date'] ?></li>
<li><i class="bi bi-cash"></i> <span>Price</span> : $<?php echo $item['Price'] ?></li>
<li><i class="bi bi-bank"></i> <span>Made In</span> : <?php echo $item['Country_Made'] ?></li>
<li><i class="bi bi-tags"></i> <span>Category</span> : <a href="categories.php?pageid=<?php $item['Cat_ID'] ?>"><?php echo $item['Cat_Name'] ?></a></li>
<li><i class="bi bi-person"></i> <span>Added By</span> : <a href="#"><?php echo $item['username'] ?></a></li>
<li class="tags-items"><i class="bi bi-tags">
</i> <span>Tags</span> :
<?php
$allTags = explode(",",$item['tags']);
foreach($allTags as $tag){
$tag = str_replace(' ', '',$tag);
$lowertag = strtolower($tag);
if(! empty($tag)){
echo "<a href='tags.php?name={$lowertag}'> " . $tag . '</a>';
}
}
?>
</li>
</ul>
</div>
</div>
<hr>
<?php if(isset($_SESSION['member'])){ ?>
<div class="row md-3">
<div class="col-md-3 offset-md-3">
<div class="add-comment">
<h3>Add Your Comment</h3>
<form action="<?php echo $_SERVER['PHP_SELF'] . '?itemid=' . $item['Item_ID'] ?>" method="POST">
<textarea required name="comment"></textarea>
<input class="btn btn-primary" type="submit" value="Add Comment">
</form>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$comment = filter_var($_POST['comment'],FILTER_SANITIZE_STRING);
$userid = $_SESSION['uid'];
$itemid = $item['Item_ID'];
if(! empty($comment)){
$stmt = $con->prepare("INSERT INTO
comments(comment, status, comment_date, item_id, user_id)
VALUES(:zcomment, 0, NOW(), :itemid, :userid)");
$stmt->execute(array(
'zcomment' => $comment,
'userid' => $userid,
'itemid' => $itemid
));
if($stmt){
echo '<div class="alert alert-success">Comment Added</div>';
}
}
}
?>
</div>
</div>
</div>
<?php }else{
echo '<a href="login.php">Login</a> Or <a href="login.php">Registered</a> To Add Comment';
}?>
<hr>
<?php
$stmt = $con->prepare("SELECT
comments.*,users.username AS Member
FROM
comments
INNER JOIN
users
ON
users.UserID = comments.user_id
WHERE
item_id = ?
AND
Status = 1");
$stmt->execute(array($itemid));
$comments = $stmt->fetchAll();
?>
<?php
foreach($comments as $comment){
?>
<div class="comment-box">
<div class="row md-3">
<div class="col-sm-2 text-center">
<img src="layout/img/avatar.png" alt="..." class="card-img-top img-thumbnail rounded-circle img-fluid">
<?php echo $comment['Member'] ?>
</div>
<div class="col-sm-10">
<p class="lead"><?php echo $comment['comment']?></p>
</div>
</div>
</div>
<hr>
<?php } ?>
</div>
</div>
<?php
}else{
echo "<div class='container'>";
$theMsg = '<div class="alert alert-danger">There Is No Such ID Or This Item Is Waiting Approval</div>';
redirectHome($theMsg);
echo "</div>";
}
?>
<?php
include("include/templates/footer.php");
?>