created setting page, sidebar component, and ajax file

This commit is contained in:
Juthatip McDevitt 2024-06-13 22:17:32 -05:00
parent 10fae86e2b
commit ddd37d01cf
4 changed files with 231 additions and 0 deletions

View file

@ -0,0 +1,24 @@
<?php
require('../components/utils.php');
require('../components/db_config.php');
adminLogin();
if(isset($_POST['get_general'])){
$q = "SELECT * FROM `settings` WHERE `sr_no`=?";
$values = [1];
$res = select($q, $values, "i");
$data = mysqli_fetch_assoc($res);
$json_data = json_encode($data);
echo $json_data;
}
if(isset($_POST['upd_general'])){
$frm_data = filteration($_POST);
$q = "UPDATE `settings` SET `site_title`=? WHERE `sr_no`=?";
$values = [$frm_data['site_title'],1];
$res = update($q, $values, 'ss');
echo $res;
}
?>

View file

@ -0,0 +1,64 @@
.btn-second{
background-color: #B6C2C2;
border: none;
color: #112E2E;
padding: 6px 12px;
text-align: center;
font-size: 18px;
font-weight: 500;
border-radius: 3px;
text-decoration: none;
}
.btn-second:hover, .btn-third:hover{
background-color: lightgray;
color: black;
transition: all 0.5s ease;
}
.btn-third{
background-color: #135D66;
border: none;
color: #E3FEF7;
padding: 5px 12px;
text-align: center;
font-size: 16px;
font-weight: 500;
border-radius: 3px;
text-decoration: none;
}
.btn-cancle{
background-color: #EE4E4E;
border: none;
color: white;
padding: 5px 12px;
text-align: center;
font-size: 16px;
font-weight: 500;
border-radius: 3px;
text-decoration: none;
}
.btn-cancle:hover{
background-color: #FF8080;
color: white;
transition: all 0.5s ease;
}
#dashboard-menu{
position: fixed;
height: 100%;
background-color: #194141;
color: white;
}
.custom-alert-t{
position: fixed;
top: -220px;
right: 20px;
width: 320px;
}
@media (max-width:992px) {
#dashboard-menu{
width: 100%;
height: auto;
}
#dashboard-body{
margin-top: 60px;
}
}

View file

@ -0,0 +1,35 @@
<!--Header-->
<div class="container-fluid text-light p-2 d-flex align-items-center justify-content-between sticky-top" style="background-color: #112E2E;">
<div class="d-flex align-items-center">
<img src="../images/logo-white.png" alt="logo" style="width: 100px;"/>
<h6 style="text-transform: uppercase; font-weight: 600;">Admin Dashboard</h6>
</div>
<a href="logout.php" class="btn-second" style="margin-right: 20px;">Logout</a>
</div>
<!--Sidebar-->
<div class="col-lg-2" id="dashboard-menu">
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #194141;">
<div class="container-fluid flex-lg-column align-items-stretch">
<p class="mt-2" style="font-weight: 600; font-size: 18px;">Admin Panel</p>
<button class="navbar-toggler shadow-none border-none mb-2" type="button" data-bs-toggle="collapse" data-bs-target="#adminDropdown" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<i class="bi bi-list" style="color: white;"></i>
</button>
<div class="collapse navbar-collapse flex-column align-items-stretch" id="adminDropdown">
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link text-white" href="dashboard.php">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Rooms</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Users</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="settings.php">Settings</a>
</li>
</ul>
</div>
</div>
</nav>
</div>

View file

@ -0,0 +1,108 @@
<?php
require('components/utils.php');
adminLogin();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings | Midtown Hotel</title>
<?php require('components/link.php')?>
</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">Settings</h4>
<!--General setting-->
<div class="card">
<div class="card-body">
<div class="d-flex mb-3 align-items-center justify-content-between">
<h5 class="card-title m-0">General Settings</h5>
<button type="button" class="btn-third" data-bs-toggle="modal" data-bs-target="#general-setting">Edit</button>
</div>
<h6 class="card-subtitle mb-1" style="font-weight: 600;">Site Title</h6>
<p class="card-text" id="site_title"></p>
</div>
</div>
<!--General setting modal-->
<div class="modal fade" id="general-setting" data-bs-backdrop="static" data-bs-keyboard="true" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<form>
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">General Settings</h5>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label" style="font-weight: 600;">Site Title</label>
<input type="text" name="site_title" id="site_title_input" class="form-control shadow-none"/>
</div>
</div>
<div class="modal-footer">
<button type="button" onclick="site_title.value = general_data.site_title" class="btn-cancle" data-bs-dismiss="modal">Cancle</button>
<button type="button" onclick="upd_general(site_title.value)" class="btn-third">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require('components/script.php') ?>
<script>
let general_data;
function get_general(){
let site_title = document.getElementById('site_title');
let site_title_input = document.getElementById('site_title_input');
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/settings_crud.php", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
general_data = JSON.parse(this.responseText);
site_title.innerText = general_data.site_title;
site_title_input.value = general_data.site_title;
}
xhr.send('get_general');
}
function upd_general(site_title_val){
let xhr = new XMLHttpRequest();
xhr.open("POST", "ajax/settings_crud.php", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function(){
var myModal = document.getElementById('general-setting');
var modal = bootstrap.Modal.getInstance(myModal);
modal.hide()
if(this.responseText == 1){
alert('success', 'Your data is updated');
get_general();
} else{
alert('error', 'Fail to update your data');
}
}
xhr.send('site_title='+site_title_val+'&upd_general');
}
window.onload = function(){
get_general();
}
</script>
</body>
</html>