-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_panel.html
172 lines (157 loc) · 6.22 KB
/
admin_panel.html
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
160
161
162
163
164
165
166
167
168
169
170
171
172
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>Admin Panel</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="style.css">
<style>
body {
background-color: #f8f9fa; /* Light background color for the rest of the page */
}
.navbar {
background-color: #343a40; /* Dark background color for the navbar */
color: #ffffff; /* Light text color */
}
</style>
</head>
<body>
<div class="container-xxl">
<nav class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="#">
<img src="iitgn_logo.png" width="30" height="30" class="d-inline-block align-top" alt="Your Logo">
IITGN Helpdesk
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<input type="text" id="searchBar" class="searchbar search-bar" placeholder="Search queries...">
<div class="logout">
<li class="nav-item">
<a class="btn logout-button" id="logoutButton">
<i class="fas fa-sign-out-alt"></i> Logout
</a>
</li>
</div>
</ul>
</div>
</nav>
</div>
<div class="controls">
<select id="sortQueries" class="sort-queries">
<option value="newest">Newest First</option>
<option value="oldest">Oldest First</option>
</select>
<!-- <button id="logoutButton" class="btn btn-primary logout-button">Logout</button> -->
</div>
<table id="queriesTable">
<tr class="m-3">
<th>ID</th>
<th>Date</th>
<th>Name</th>
<th>Department</th>
<th>Type</th>
<th>Media/Link</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
<!-- Data rows will be inserted here by jQuery -->
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
// Load the admin queries when the page loads
function fetchQueries(searchTerm = '', sortOrder = 'newest') {
$.ajax({
url: 'admin_panel.php',
type: 'GET',
data: {search: searchTerm, sort: sortOrder},
dataType: 'json',
success: function(queries){
if(queries.error) {
// Handle the error, maybe redirect to login
alert(queries.error);
window.location.href = 'admin_login.html';
} else {
// Clear existing rows
$('#queriesTable tr:not(:first)').remove();
// Insert the data into the table
$.each(queries, function(i, query) {
var actionButtonText = query.status === 'open' ? 'Resolve' : 'Reopen';
$('#queriesTable').append(
`<tr>
<td>${query.query_id}</td>
<td>${query.create_date}</td>
<td>${query.name}</td>
<td>${query.department}</td>
<td>${query.query_type}</td>
<td>${query.query_type === 'Social Media' ? `<a href="${query.image_video}">View Media</a>` : `<a href="${query.website_link}">${query.website_link}</a>`}</td>
<td>${query.description}</td>
<td id="status-${query.query_id}">${query.status}</td>
<td><button onclick="updateStatus(${query.query_id})">${actionButtonText}</button></td>
</tr>`
);
});
}
},
error: function(){
alert('Error fetching data.');
}
});
}
// Listen for sort order changes
$('#sortQueries').change(function() {
fetchQueries($('#searchBar').val(), $(this).val());
});
// Listen for search input
$('#searchBar').on('input', function() {
fetchQueries($(this).val(), $('#sortQueries').val());
});
// Initial fetch
fetchQueries();
// Logout button logic
$('#logoutButton').click(function(){
$.ajax({
url: 'admin_logout.php',
type: 'POST',
success: function(response){
// Redirect to login after logout
window.location.href = 'admin_login.html';
}
});
});
});
function updateStatus(queryId) {
const statusElement = document.getElementById(`status-${queryId}`);
const currentStatus = statusElement.innerText.toLowerCase();
const newStatus = currentStatus === 'open' ? 'resolved' : 'open';
fetch('update_status.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `query_id=${queryId}¤t_status=${currentStatus}`,
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Update the UI with the new status
statusElement.innerText = newStatus.charAt(0).toUpperCase() + newStatus.slice(1);
const buttonElement = statusElement.nextElementSibling.children[0];
buttonElement.innerText = newStatus === 'open' ? 'Resolve' : 'Reopen';
} else {
// Handle failure
alert('Failed to update status. Please try again.');
}
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred while updating the status. Please try again.');
});
}
</script>
</body>