-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
159 lines (141 loc) · 5.41 KB
/
admin.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
157
158
159
<?php
session_start();
require 'dbconn.php';
$error="";
$color="";
if(isset($_POST['approve_btn']))
{
$url = $_SERVER['REQUEST_URI'];
$url_segments = explode('/', $url);
$segment_1 = $url_segments[1];
$segment_2 = $url_segments[2];
$id= explode('=',explode('?', $segment_2)[1])[1];
$query = "UPDATE posts SET approved = 1 WHERE id = '$id'";
$result = $conn->query($query);
header("Location: /tutormanagement/admin.php");
}
else if(isset($_POST['delete_btn']))
{
$url = $_SERVER['REQUEST_URI'];
$url_segments = explode('/', $url);
$segment_1 = $url_segments[1];
$segment_2 = $url_segments[2];
$id= explode('=',explode('?', $segment_2)[1])[1];
$query = "DELETE FROM posts WHERE id = '$id'";
$result = $conn->query($query);
header("Location: /tutormanagement/admin.php");
}
else if(isset($_POST['refuse_btn']))
{
$url = $_SERVER['REQUEST_URI'];
$url_segments = explode('/', $url);
$segment_1 = $url_segments[1];
$segment_2 = $url_segments[2];
$id= explode('=',explode('?', $segment_2)[1])[1];
$query = "UPDATE posts SET approved = 0 WHERE id = '$id'";
$result = $conn->query($query);
header("Location: /tutormanagement/admin.php");
}
$query = "SELECT * FROM posts WHERE approved=0";
$result = $conn->query($query);
$query = "SELECT * FROM posts WHERE approved=1";
$result2 = $conn->query($query);
?>
<?php
include "navbar.php"
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin</title>
</head>
<body>
<h3 class="alert alert-info text-center">Admin Panel</h3>
<br>
<div class="row">
<div onclick="col1Pressed()" class="col-md-6 text-center" id="col1">
<button class="btn btn-info">Pending Requests</button>
</div>
<div onclick="col2Pressed()" class="col-md-6 text-center" id="col2">
<button class="btn btn-warning">Approved Requests</button>
</div>
</div>
<br><br>
<div class="container" id="data1">
<table class="table">
<tbody>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Transaction Id</th>
<th>Action</th>
</tr>
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['email'] ?></td>
<td><?php echo $row['phone'] ?></td>
<td><?php echo $row['transaction_id'] ?></td>
<td>
<form class="btn btn-success" action="/tutormanagement/admin.php?id=<?php echo $row['id'];?>" method="post"><button class="btn text-white" name="approve_btn">Approve</button></form>
<form class="btn btn-danger" action="/tutormanagement/admin.php?id=<?php echo $row['id'];?>" method="post"><button name="delete_btn" class="btn text-white">Delete</button></form>
</td>
</tr>
<?php } }?>
</tbody>
</table>
</div>
<div class="container" id="data2">
<table class="table">
<tbody>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Transaction Id</th>
<th>Action</th>
</tr>
<?php
if ($result2->num_rows > 0) {
// output data of each row
while($row = $result2->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['email'] ?></td>
<td><?php echo $row['phone'] ?></td>
<td><?php echo $row['transaction_id'] ?></td>
<td>
<form class="btn btn-warning" action="/tutormanagement/admin.php?id=<?php echo $row['id'];?>" method="post"><button class="btn text-white" name="refuse_btn">Refuse</button></form>
<form class="btn btn-danger" action="/tutormanagement/admin.php?id=<?php echo $row['id'];?>" method="post"><button name="delete_btn" class="btn text-white">Delete</button></form>
</td>
</tr>
<?php } }?>
</tbody>
</table>
</div>
</body>
<script>
var col1=document.getElementById("col1");
var col2=document.getElementById("col2");
var data1=document.getElementById("data1");
var data2=document.getElementById("data2");
data2.style.display='none'
function col1Pressed(){
data2.style.display='none'
data1.style.display='block'
}
function col2Pressed(){
data1.style.display='none'
data2.style.display='block'
}
</script>
</html>