TIF_NGANJUK_E41212020/admin/template/template1.php

129 lines
5.0 KiB
PHP

<?php
session_start();
// $timeout = 1; // setting timeout dalam menit
// $logout = "../login/index.php"; // redirect halaman logout
// $timeout = $timeout * 360; // menit ke detik
// if(isset($_SESSION['start_session'])){
// $elapsed_time = time()-$_SESSION['start_session'];
// if($elapsed_time >= $timeout){
// session_destroy();
// echo "<script type='text/javascript'>alert('Sesi telah berakhir');window.location='$logout'</script>";
// }
// }
// $_SESSION['start_session']=time();
include $_SERVER['DOCUMENT_ROOT'] . "/config.php";
// Pastikan session user sudah ada
if (!isset($_SESSION['user_global_admin'])) {
header("Location: ../login.php");
exit;
}
$base_url = "http://localhost";
// Query untuk mendapatkan profil awal
$query = mysqli_query($conn, "SELECT * FROM profil WHERE id_usaha = 1");
$profile = mysqli_fetch_assoc($query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Admin - <?php echo $profile['nama_usaha']; ?></title>
<meta content="" name="description">
<meta content="" name="keywords">
<!-- Favicons -->
<link href="../assets/img/favicon.png" rel="icon">
<link href="../assets/img/apple-touch-icon.png" rel="apple-touch-icon">
<!-- Google Fonts -->
<link href="https://fonts.gstatic.com" rel="preconnect">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="../assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="../assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="../assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
<link href="../assets/vendor/quill/quill.snow.css" rel="stylesheet">
<link href="../assets/vendor/quill/quill.bubble.css" rel="stylesheet">
<link href="../assets/vendor/remixicon/remixicon.css" rel="stylesheet">
<link href="../assets/vendor/simple-datatables/style.css" rel="stylesheet">
<!-- Template Main CSS File -->
<link href="../assets/css/style.css" rel="stylesheet">
<script src="../../dist/sweetalert2.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<!-- DataTables CSS for Bootstrap -->
<link href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css" rel="stylesheet">
<!-- =======================================================
* Template Name: NiceAdmin
* Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
* Updated: Apr 20 2024 with Bootstrap v5.3.3
* Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/
======================================================== -->
</head>
<body>
<script>
function cekPesananBaru() {
fetch('<?= $base_url ?>/admin/ajax/cek_pesanan.php')
.then(response => response.json())
.then(data => {
const notifWrapper = document.getElementById('notif-wrapper');
const notifCount = document.getElementById('notif-count');
const notifHeaderText = document.getElementById('notif-header-text');
notifWrapper.innerHTML = ''; // kosongkan dulu
if (data.total > 0) {
notifCount.textContent = data.total;
notifHeaderText.textContent = `Ada ${data.total} pesanan baru`;
const notifList = document.createElement('ul'); // buat ul di dalam li
notifList.style.listStyle = 'none'; // biar ga ada bullet
notifList.style.padding = '0';
notifList.style.margin = '0';
data.data.forEach(order => {
const notifItem = document.createElement('li');
notifItem.className = 'notification-item';
notifItem.innerHTML = `
<a href="<?= $base_url ?>/admin/transaksi/detail.php?id_order=${order.id_order}" style="text-decoration:none; color:inherit;">
<i class="bi bi-cart"></i>
<div>
<h4>ID Order: ${order.id_order}</h4>
<p>Status: <b>${order.status_order}</b></p>
<p>${order.tanggal_order}</p>
</div>
</a>
`;
notifList.appendChild(notifItem);
});
notifWrapper.appendChild(notifList); // masukin ul ke dalam notif-wrapper
} else {
notifCount.textContent = '0';
notifHeaderText.textContent = 'Tidak ada notifikasi baru';
}
})
.catch(error => console.error('Gagal cek pesanan:', error));
}
// Cek awal dan interval
setInterval(cekPesananBaru, 10000);
document.addEventListener('DOMContentLoaded', cekPesananBaru);
</script>