forked from ElzeroWebSchool/eCommerceCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.php
More file actions
153 lines (133 loc) · 4.52 KB
/
Copy pathitems.php
File metadata and controls
153 lines (133 loc) · 4.52 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
153
<?php
ob_start();
session_start();
$pageTitle = 'Show Items';
include 'init.php';
// Check If Get Request item Is Numeric & Get Its Integer Value
$itemid = isset($_GET['itemid']) && is_numeric($_GET['itemid']) ? intval($_GET['itemid']) : 0;
// Select All Data Depend On This ID
$stmt = $con->prepare("SELECT items.*, categories.Name AS category_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");
// Execute Query
$stmt->execute(array($itemid));
$count = $stmt->rowCount();
if ($count > 0) {
// Fetch The Data
$item = $stmt->fetch();
?>
<h1 class="text-center"><?php echo $item['Name'] ?></h1>
<div class="container">
<div class="row">
<div class="col-md-3">
<img class="img-responsive img-thumbnail center-block" src="img.png" alt="" />
</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>
<em class="fa fa-calendar fa-fw"></em>
<span>Added Date</span> : <?php echo $item['Add_Date'] ?>
</li>
<li>
<em class="fa fa-money fa-fw"></em>
<span>Price</span> : <?php echo $item['Price'] ?>
</li>
<li>
<em class="fa fa-building fa-fw"></em>
<span>Made In</span> : <?php echo $item['Country_Made'] ?>
</li>
<li>
<em class="fa fa-tags fa-fw"></em>
<span>Category</span> : <a href="categories.php?pageid=<?php echo $item['Cat_ID'] ?>"><?php echo $item['category_name'] ?></a>
</li>
<li>
<em class="fa fa-user fa-fw"></em>
<span>Added By</span> : <a href="#"><?php echo $item['Username'] ?></a>
</li>
<li class="tags-items">
<em class="fa fa-user fa-fw"></em>
<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 class="custom-hr">
<?php if (isset($_SESSION['user'])) { ?>
<!-- Start Add Comment -->
<div class="row">
<div class="col-md-offset-3">
<div class="add-comment">
<h3>Add Your Comment</h3>
<form action="<?php echo $_SERVER['PHP_SELF'] . '?itemid=' . $item['Item_ID'] ?>" method="POST">
<textarea name="comment" required></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);
$itemid = $item['Item_ID'];
$userid = $_SESSION['uid'];
if (!empty($comment)) {
$stmt = $con->prepare("INSERT INTO comments(comment, status, comment_date, item_id, user_id) VALUES(:zcomment, 0, NOW(), :zitemid, :zuserid)");
$stmt->execute(array(
'zcomment' => $comment,
'zitemid' => $itemid,
'zuserid' => $userid
));
if ($stmt) {
echo '<div class="alert alert-success">Comment Added</div>';
}
} else {
echo '<div class="alert alert-danger">You Must Add Comment</div>';
}
}
?>
</div>
</div>
</div>
<!-- End Add Comment -->
<?php } else {
echo '<a href="login.php">Login</a> or <a href="login.php">Register</a> To Add Comment';
} ?>
<hr class="custom-hr">
<?php
// Select All Users Except Admin
$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 ORDER BY c_id DESC");
// Execute The Statement
$stmt->execute(array($item['Item_ID']));
// Assign To Variable
$comments = $stmt->fetchAll();
foreach ($comments as $comment) { ?>
<div class="comment-box">
<div class="row">
<div class="col-sm-2 text-center">
<img class="img-responsive img-thumbnail img-circle center-block" src="img.png" alt="" />
<?php echo $comment['Member'] ?>
</div>
<div class="col-sm-10">
<p class="lead"><?php echo $comment['comment'] ?></p>
</div>
</div>
</div>
<hr class="custom-hr">
<?php } ?>
</div>
<?php
} else {
echo '<div class="container">';
echo '<div class="alert alert-danger">There\'s no Such ID Or This Item Is Waiting Approval</div>';
echo '</div>';
}
include $tpl . 'footer.php';
ob_end_flush();
?>