-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview.php
97 lines (93 loc) · 3.9 KB
/
view.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
<?php
include 'templates/header.php';
$a_id = $_GET['a_id'];
$sql = "SELECT title, content, img, `timestamp`, username AS author, name AS category FROM article AS a
JOIN user AS u ON(a.user_id = u.id)
JOIN category AS c ON(a.category_id = c.id) WHERE article_id=$a_id";
$article = mysqli_query($connect, $sql);
$article = $article->fetch_assoc();
?>
<main class="container mt-4">
<section class="row justify-content-center">
<div class="col-md-8">
<h2 class="mb-4 text-center text-capitalize"><?= $article['title'] ?></h2>
<?php
if ($article['img'] != '') { ?>
<div class="d-flex align-items-center">
<img class="card-img-top" src="<?= $article['img'] ?>" alt="article image">
</div>
<?php
}
?>
<small class="text-muted">By <?= $article['author'] ?> in <?= $article['category'] ?></small>
<article class="my-3">
<?= $article['content'] ?>
</article>
</div>
</section>
<section class="row justify-content-center">
<div class="col-md-8">
<h2>Comment</h2>
<hr>
<?php
if (isset($_SESSION['username'])) {
?>
<div class="card mb-5">
<form class="card-body" method="POST" action="process/comment.php">
<input type="hidden" name="a_id" value="<?= $a_id ?>">
<textarea class="form-control card mb-3" id="user-comment" rows="3" name="comment" placeholder="Insert comment here"></textarea>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<?php
} else {
?>
<div class="card mb-5">
<div class="card-body text-outline-dark">
<p>Login to comment</p>
<a href="login.php" target="_blank" class="btn btn-primary">Login</a>
</div>
</div>
<?php
}
$sql = "SELECT u.username, c.comment, c.user_id, c.id FROM comment c
JOIN user u ON(u.id = c.user_id)
WHERE article_id=$a_id ORDER BY `timestamp` DESC";
$comments = mysqli_query($connect, $sql);
if (mysqli_num_rows($comments) > 0) {
foreach ($comments as $comment) {
?>
<div class="card mb-3">
<form class="card-body" method="POST" action="process/delcomment.php">
<input type="hidden" name="a_id" value="<?= $a_id ?>">
<input type="hidden" name="c_id" value="<?= $comment['id'] ?>">
<h5><?= $comment['username'] ?></h5>
<?= $comment['comment'] ?>
<?php
if (isset($_SESSION['username'])) {
if (($id == $comment['user_id']) || $role == 1) {
?>
<div class="d-flex justify-content-end">
<button name="submit" type="submit" class="btn btn-danger">Delete </button>
</div>
<?php
}
}
?>
</form>
</div>
<?php
}
} else { ?>
<div class="card mb-5">
<div class="card-body">
<p>There are no comment yet</p>
</div>
</div>
<?php
}
?>
</div>
</section>
</main>
<?php include 'templates/footer.php' ?>