-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
154 lines (142 loc) · 7.41 KB
/
index.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
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BeSmile Webboard</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap/icons/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="BeSmile/css/style.css">
<script src="bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="BeSmile/javascript/Besmile.js"></script>
<script type="text/javascript">
function deleteCon(){
let r = confirm('--- [ Final Warning !!! ] ---\n Are You sure you want to delete this?');
return r;
// e.preventDefault();
}
</script>
</head>
<body>
<div class="container-lg">
<h1 class="mt-3 mb-3" style="text-align: center;">BeSmile WebBoard</h1>
<?php include "nav.php" ?>
<div class="mt-3 d-flex justify-content-between">
<div>
<label>หมวดหมู่</label>
<span class="dropdown">
<button class="btn btn-sm btn-light btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<?php
if(isset($_GET['cat'])){
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8", "root", "");
$sql = "SELECT * FROM category WHERE id = $_GET[cat]";
foreach($conn->query($sql) as $row){
echo "$row[name]";
}
$conn = null;
}
else{
echo "--ทั้งหมด--";
}
?>
</button>
<ul class="dropdown-menu" aria-labelledby="Button2">
<li><a class="dropdown-item" href="index.php">ทั้งหมด</a></li>
<?php
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8", "root", "");
$sql = "SELECT * FROM category";
foreach($conn->query($sql) as $row){
echo "<li><a class='dropdown-item' href=index.php?cat=$row[id]>$row[name]</a></li>";
}
$conn = null
?>
</ul>
</span>
</div>
<?php
if(isset($_SESSION["id"]))
{?>
<div>
<a href="newpost.php" class="btn btn-success btn-sm"><i class="bi bi-plus"></i> สร้างกระทู้ใหม่</a>
</div>
<?php
}?>
</div>
<div>
<table class="table table-striped mt-4">
<?php
$conn = new PDO("mysql:host=localhost;dbname=webboard;charset=utf8", "root", "");
if(isset($_GET['cat'])){
$sql = "SELECT category.name, post.title, post.id, user.username, post.post_date, post.user_id FROM post
INNER JOIN user ON (post.user_id = user.id)
INNER JOIN category ON (post.cat_id = category.id)
WHERE post.cat_id = '$_GET[cat]'
ORDER BY post.post_date DESC";
}
else{
$sql = "SELECT category.name, post.title, post.id, user.username, post.post_date, post.user_id FROM post
INNER JOIN user ON (post.user_id = user.id)
INNER JOIN category ON (post.cat_id = category.id)
ORDER BY post.post_date DESC";
}
$result = $conn->query($sql);
while($row = $result->fetch()){
echo "<tr><td class='d-flex justify-content-between'>
<div>
[$row[0]] <a href=post.php?id=$row[2] style=text-decoration:none;>$row[1]</a>
<br>
$row[3] - [ $row[4] ]
</div>";
if(isset($_SESSION["id"]))
{
if($_SESSION["role"] == "a" || $_SESSION["user_id"] == $row[5]){
echo "<div class='align-self-center'>";
if($_SESSION["user_id"] == $row[5]){
echo "<a href='editpost.php?id=$row[2]' class='btn btn-warning btn-sm me-1'><i class='bi bi-pencil-fill'></i></a>";
}
echo "<button class='btn btn-danger btn-sm me-3 ' data-bs-toggle='modal' data-bs-target='#deletePostModal$row[2]'><i class='bi bi-trash'></i></button></div>";
echo "<div class='modal fade' id='deletePostModal$row[2]' tabindex='-1' aria-labelledby='deletePostModalLabel' aria-hidden='true'>
<div class='modal-dialog modal-dialog-centered'>
<div class='modal-content'>
<div class='modal-header'>
<h1 class='modal-title fs-5 text-danger' id='exampleModalLabel'>[ DANGER!! ] ต้องการที่จะลบกระทู้นี้ หรือไม่!!!</h1>
<button type='button' id='modalclosebtn' class='btn-close' data-bs-dismiss='modal' aria-label='Close'></button>
</div>
<div class='modal-body bg-light'>
<div>
[$row[0]] <span class='text-primary'>$row[1]</span>
<br>
$row[3] - $row[4]
</div>
</div>
<div class='modal-footer d-flex justify-content-center'>
<a href='delete.php?id=$row[2]' onclick='return deleteCon()' class='btn btn-danger'>Delete</a>
<button type='button' class='btn btn-secondary' data-bs-dismiss='modal'>Close</button>
</div>
</div>
</div>
</div>";
}
}
echo "</td></tr>";
}
$conn = null;
//<a href='delete.php?id=$row[2]' class='btn btn-danger'>Delete</a>
// for($j = 1; $j <= 10; $j++)
// {
// echo "<tr><td class='d-flex justify-content-between'><a href='post.php?id=".$j."' style='text-decoration: none;'>กระทู้ที่ $j</a>";
// if(isset($_SESSION["id"]) && $_SESSION["role"] == "a")
// {
// echo "    <a href = delete.php?id=$j class='btn btn-danger btn-sm me-3'><i class='bi bi-trash'></i></a>";
// }
// echo "</td></tr>";
// }
?>
</table>
</div>
</div>
</body>
</html>