forked from tasminoni/CSE370-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adminblog.php
120 lines (109 loc) · 3.5 KB
/
adminblog.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if(isset($_POST['blog_id']) && isset($_POST['action'])) {
$blog_id = $_POST['blog_id'];
$action = $_POST['action'];
$update_sql = "UPDATE blog SET status = '$action' WHERE id = $blog_id";
if ($conn->query($update_sql) === TRUE) {
} else {
echo "Error updating blog status: " . $conn->error;
}
}
}
$sql = "SELECT * FROM blog WHERE status NOT IN ('approve', 'deny')";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Admin Panel</title>
<style>
/* Your CSS styles here */
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
td select {
padding: 8px 10px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
}
td input[type='submit'] {
padding: 8px 15px;
border: none;
border-radius: 4px;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
td input[type='submit']:hover {
background-color: #45a049;
}
.home-button {
position: absolute;
top: 20px;
left: 20px;
background-color: green;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<br>
<a href='admin.php' class='home-button'>Home</a>
<br>
<br>
<h1>Pending Blog Posts</h1>
<table>
<tr><th>Flat ID</th><th>Title</th><th>Content</th><th>Image</th><th>Blog Status</th><th>Action</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["id"] . "</td>";
echo "<td>" . $row["title"] . "</td>";
echo "<td>" . $row["content"] . "</td>";
echo "<td><img src='images/" . $row["img"] . "' alt='Blog Image' height='100'></td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td>";
echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='post'>";
echo "<input type='hidden' name='blog_id' value='" . $row["id"] . "'>";
echo "<select name='action'>";
echo "<option value='approve'>Approve</option>";
echo "<option value='deny'>Deny</option>";
echo "</select>";
echo "<input type='submit' value='Submit'>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<a href='admin.php' class='home-button'>Home</a>";
echo "<br>";
echo "0 results";
}
$conn->close();
?>