created admin dashboard-users page and updated sidebar
This commit is contained in:
parent
e6a1151759
commit
eb5076d91a
3 changed files with 245 additions and 3 deletions
112
hotel_booking/admin/ajax/users.php
Normal file
112
hotel_booking/admin/ajax/users.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
require('../components/utils.php');
|
||||
require('../components/db_config.php');
|
||||
adminLogin();
|
||||
|
||||
if(isset($_POST['get_users'])){
|
||||
$res = selectAll('user_creds');
|
||||
$i = 1;
|
||||
$data = "";
|
||||
|
||||
while($row = mysqli_fetch_assoc($res)){
|
||||
$date = date("M-d-Y", strtotime($row['datentime']));
|
||||
$delete_btn = "<button type='button' onclick='remove_user($row[id])' class='btn-cancel' style='padding: 2px 4px; font-size: 12px;'>Delete user</button>";
|
||||
$verified = "<span class='badge bg-danger'>No</span>";
|
||||
|
||||
if($row['is_verified']){
|
||||
$verified = "<span class='badge bg-success'>Yes</span>";
|
||||
$delete_btn = "";
|
||||
}
|
||||
|
||||
$status = "<button onclick='toggleStatus($row[id], 0)' class='btn-third fw-bold' style='padding: 2px 4px; font-size: 12px;'>Active</button>";
|
||||
if(!$row['status']){
|
||||
$status = "<button onclick='toggleStatus($row[id], 1)' class='btn-cancel fw-bold' style='padding: 2px 4px; font-size: 12px;'>Inactive</button>";
|
||||
}
|
||||
|
||||
$data.="
|
||||
<tr>
|
||||
<td>$i</td>
|
||||
<td>$row[firstname]</td>
|
||||
<td>$row[lastname]</td>
|
||||
<td>$row[email]</td>
|
||||
<td>$row[phone]</td>
|
||||
<td>$row[address]</td>
|
||||
<td>$row[birth]</td>
|
||||
<td>$verified</td>
|
||||
<td>$status</td>
|
||||
<td>$date</td>
|
||||
<td>$delete_btn</td>
|
||||
</tr>
|
||||
";
|
||||
$i++;
|
||||
}
|
||||
echo $data;
|
||||
}
|
||||
|
||||
if(isset($_POST['toggleStatus'])){
|
||||
$frm_data = filteration($_POST);
|
||||
$q = "UPDATE `user_creds` SET `status`=? WHERE `id`=?";
|
||||
$values = [$frm_data['value'], $frm_data['toggleStatus']];
|
||||
|
||||
if(update($q, $values, 'ii')){
|
||||
echo 1;
|
||||
} else{
|
||||
echo 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_POST['remove_user'])){
|
||||
$frm_data = filteration($_POST);
|
||||
|
||||
$res = delete("DELETE FROM `user_creds` WHERE `id`=? AND `is_verified`=?", [1, $frm_data['user_id'], 0], 'ii');
|
||||
|
||||
if($res){
|
||||
echo 1;
|
||||
} else{
|
||||
echo 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_POST['search_users'])){
|
||||
$frm_data = filteration($_POST);
|
||||
$query = "SELECT * FROM `user_creds` WHERE `firstname` LIKE ?";
|
||||
$res = select($query, ["%$frm_data[firstname]%"], 's');
|
||||
$i = 1;
|
||||
$data = "";
|
||||
|
||||
while($row = mysqli_fetch_assoc($res)){
|
||||
$date = date("M-d-Y", strtotime($row['datentime']));
|
||||
$delete_btn = "<button type='button' onclick='remove_user($row[id])' class='btn-cancel' style='padding: 2px 4px; font-size: 12px;'>Delete user</button>";
|
||||
$verified = "<span class='badge bg-danger'>No</span>";
|
||||
|
||||
if($row['is_verified']){
|
||||
$verified = "<span class='badge bg-success'>Yes</span>";
|
||||
$delete_btn = "";
|
||||
}
|
||||
|
||||
$status = "<button onclick='toggleStatus($row[id], 0)' class='btn-third fw-bold' style='padding: 2px 4px; font-size: 12px;'>Active</button>";
|
||||
if(!$row['status']){
|
||||
$status = "<button onclick='toggleStatus($row[id], 1)' class='btn-cancel fw-bold' style='padding: 2px 4px; font-size: 12px;'>Inactive</button>";
|
||||
}
|
||||
|
||||
$data.="
|
||||
<tr>
|
||||
<td>$i</td>
|
||||
<td>$row[firstname]</td>
|
||||
<td>$row[lastname]</td>
|
||||
<td>$row[email]</td>
|
||||
<td>$row[phone]</td>
|
||||
<td>$row[address]</td>
|
||||
<td>$row[birth]</td>
|
||||
<td>$verified</td>
|
||||
<td>$status</td>
|
||||
<td>$date</td>
|
||||
<td>$delete_btn</td>
|
||||
</tr>
|
||||
";
|
||||
$i++;
|
||||
}
|
||||
echo $data;
|
||||
}
|
||||
|
||||
?>
|
|
@ -19,15 +19,18 @@
|
|||
<li class="nav-item" id="dashboard">
|
||||
<a class="nav-link text-white" href="dashboard.php">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item" id="users">
|
||||
<a class="nav-link text-white" href="users.php">Users</a>
|
||||
</li>
|
||||
<li class="nav-item" id="user_query">
|
||||
<a class="nav-link text-white" href="user_query.php">User Query</a>
|
||||
</li>
|
||||
<li class="nav-item" id="rooms">
|
||||
<a class="nav-link text-white" href="rooms.php">Rooms</a>
|
||||
</li>
|
||||
<li class="nav-item" id="accomm">
|
||||
<a class="nav-link text-white" href="accomm.php">Accommodation</a>
|
||||
</li>
|
||||
<li class="nav-item" id="user_query">
|
||||
<a class="nav-link text-white" href="user_query.php">User Query</a>
|
||||
</li>
|
||||
<li class="nav-item" id="settings">
|
||||
<a class="nav-link text-white" href="settings.php">Settings</a>
|
||||
</li>
|
||||
|
|
127
hotel_booking/admin/users.php
Normal file
127
hotel_booking/admin/users.php
Normal file
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
require('components/utils.php');
|
||||
require('components/db_config.php');
|
||||
adminLogin();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard-users | Midtown Hotel</title>
|
||||
<?php require('components/link.php') ?>
|
||||
<style>
|
||||
.custom-alert-t{
|
||||
position:fixed;
|
||||
top: 100px;
|
||||
right: 25px;
|
||||
z-index: 10000;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php require('components/sidebar.php')?>
|
||||
<div class="container-fluid" id="dashboard-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-10 ms-auto p-4 overflow-hidden">
|
||||
<h4 class="mb-4">Users</h4>
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<div class="mb-4 text-end">
|
||||
<input type="text" oninput="search_users(this.value)" class="form-control w-25 ms-auto shadow-none" placeholder="Search">
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover border">
|
||||
<thead>
|
||||
<tr style="background-color: #D3D3D3;">
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Firstname</th>
|
||||
<th scope="col">Lastname</th>
|
||||
<th scope="col">Email</th>
|
||||
<th scope="col">Phone</th>
|
||||
<th scope="col">Address</th>
|
||||
<th scope="col">Birthday</th>
|
||||
<th scope="col">Verify</th>
|
||||
<th scope="col">Status</th>
|
||||
<th scope="col">Date</th>
|
||||
<th scope="col">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="users_data">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<?php require('components/script.php') ?>
|
||||
<script>
|
||||
function get_users(){
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "ajax/users.php", true);
|
||||
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onload = function(){
|
||||
document.getElementById('users_data').innerHTML = this.responseText;
|
||||
}
|
||||
xhr.send('get_users');
|
||||
}
|
||||
|
||||
function toggleStatus(id, val){
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "ajax/users.php", true);
|
||||
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onload = function(){
|
||||
if(this.responseText == 1){
|
||||
alert('success', 'Active');
|
||||
get_users();
|
||||
} else{
|
||||
alert('success', 'Inactive');
|
||||
}
|
||||
}
|
||||
xhr.send('toggleStatus='+id+'&value='+val);
|
||||
}
|
||||
|
||||
function remove_user(user_id){
|
||||
if(confirm("Are you sure you want to delete this user?")){
|
||||
let data = new FormData();
|
||||
data.append('user_id', room_id);
|
||||
data.append('remove_user', '');
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "ajax/users.php", true)
|
||||
|
||||
xhr.onload = function(){
|
||||
if(this.responseText == 1){
|
||||
alert('success', 'Delete user');
|
||||
get_users();
|
||||
} else{
|
||||
alert('error', 'Fail to delete this user');
|
||||
}
|
||||
}
|
||||
xhr.send(data);
|
||||
}
|
||||
}
|
||||
|
||||
function search_users(username){
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "ajax/users.php", true);
|
||||
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
|
||||
|
||||
xhr.onload = function(){
|
||||
document.getElementById('users_data').innerHTML = this.responseText;
|
||||
}
|
||||
xhr.send('search_users&firstname='+username);
|
||||
}
|
||||
|
||||
window.onload = function(){
|
||||
get_users();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue