403Webshell
Server IP : 127.0.0.1  /  Your IP : 192.168.99.1
Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9
System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64
User : Administrator ( 0)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /bpkd_/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /bpkd_/live_widget.php
<?php
/**
 * LIVE ABSENSI — WIDGET (untuk embed di halaman muka)
 * Cara pasang: lihat snippet <iframe> di bagian bawah.
 */

require_once __DIR__ . '/api/pegawai/api_config.php';
date_default_timezone_set('Asia/Jakarta');

// ============================================================
// JAM OPERASIONAL
// ============================================================
$jam_buka  = 6;
$jam_tutup = 15;
$jam_sekarang = (int) date('G');
$dalam_jam = ($jam_sekarang >= $jam_buka && $jam_sekarang < $jam_tutup);

// ============================================================
// AMBIL DATA
// ============================================================
$rows = [];
if ($dalam_jam) {
    try {
        $pdo = new PDO(
            'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4',
            DB_USER, DB_PASS,
            [
                PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            ]
        );
        $stmt = $pdo->prepare("
            SELECT nip, namapegawai, jabatan, waktu, foto, stat
            FROM pegawai
            WHERE tgl_hariini = CURDATE()
              AND stat IS NOT NULL
              AND stat <> ''
            ORDER BY id ASC;
        ");
        $stmt->execute();
        $rows = $stmt->fetchAll();
    } catch (Exception $e) {
        $rows = [];
    }
}

$total = count($rows);
$hadir = $izin = $sakit = 0; $cuti = 0; $wfh = 0;
foreach ($rows as $r) {
    $s = strtoupper(trim($r['stat']));
    if ($s == 'HADIR' || $s == 'ADA') $hadir++;
    elseif ($s === 'IZIN') $izin++;
    elseif ($s === 'SAKIT') $sakit++;
    elseif ($s === 'CUTI') $cuti++;
    elseif ($s === 'WFH') $wfh++;
}

$placeholder = 'data:image/svg+xml;utf8,' . rawurlencode(
    '<svg xmlns="http://www.w3.org/2000/svg" width="300" height="400" viewBox="0 0 300 400">'
    . '<rect width="300" height="400" fill="#334155"/>'
    . '<circle cx="150" cy="150" r="60" fill="#64748b"/>'
    . '<path d="M40 400c0-70 50-110 110-110s110 40 110 110z" fill="#64748b"/>'
    . '</svg>'
);
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="utf-8">
<title>Live Presensi Widget</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    background: transparent;
    font-family: 'Segoe UI', Arial, sans-serif;
    color: #e2e8f0;
    overflow: hidden;
    width: 100%;
}

.live-widget {
    background: #0f172a;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* ---------------- HEADER ---------------- */
.live-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #dc2626;
    color: #fff;
    padding: 5px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    animation: pulse 1.8s infinite;
}
.live-badge .dot {
    width: 7px; height: 7px;
    background: #fff;
    border-radius: 50%;
    animation: blink 1s infinite;
}
@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(220,38,38,0.6); }
    70%  { box-shadow: 0 0 0 12px rgba(220,38,38,0); }
    100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); }
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.3; }
}
.live-title {
    font-size: 16px;
    font-weight: 700;
    color: #f1f5f9;
}
.live-clock {
    margin-left: auto;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 18px;
    font-weight: 700;
    color: #22d3ee;
    letter-spacing: 2px;
}

/* ---------------- SUMMARY ---------------- */
.live-summary {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    font-size: 12px;
}
.live-summary span {
    background: #1e293b;
    border: 1px solid #334155;
    padding: 3px 10px;
    border-radius: 8px;
    color: #cbd5e1;
}
.live-summary span b { color: #fff; }
.live-summary .s-hadir b { color: #4ade80; }
.live-summary .s-izin b  { color: #fbbf24; }
.live-summary .s-sakit b { color: #f87171; }

/* ---------------- GRID ---------------- */
.cards-grid {
    display: grid;
    gap: 10px;
    transition: opacity 0.35s ease;
}
.cards-grid.fade-out { opacity: 0; }

.card {
    position: relative;
    background: #1e293b;
    border-radius: 10px;
    overflow: hidden;
    aspect-ratio: 3 / 4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
.card .photo-wrap { position: absolute; inset: 0; }
.card img {
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: center top;
    display: block;
}
.card .overlay {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: 30px 8px 8px;
    background: linear-gradient(
        to top,
        rgba(0,0,0,0.92) 0%,
        rgba(0,0,0,0.65) 50%,
        rgba(0,0,0,0) 100%
    );
}
.card .nama {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}
.card .jabatan {
    font-size: 10px;
    color: #cbd5e1;
    margin-top: 2px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.card .meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    gap: 4px;
}
.card .waktu {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 11px;
    font-weight: 700;
    color: #22d3ee;
}
.card .stat {
    font-size: 8.5px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    color: #fff;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.stat.HADIR  { background: #16a34a; }
.stat.IZIN   { background: #d97706; }
.stat.SAKIT  { background: #dc2626; }
.stat.CUTI   { background: #2563eb; }
.stat.DL     { background: #7c3aed; }
.stat.default{ background: #64748b; }

/* ---------------- DOTS ---------------- */
.dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}
.dots .dot-nav {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #334155;
    transition: background 0.3s, transform 0.3s;
}
.dots .dot-nav.active {
    background: #22d3ee;
    transform: scale(1.4);
}

/* ---------------- EMPTY ---------------- */
.empty {
    text-align: center;
    padding: 26px 12px;
    color: #64748b;
    font-style: italic;
    font-size: 13px;
}

/* ---------------- MOBILE ---------------- */
@media (max-width: 500px) {
    .live-title { display: none; }
    .live-clock { font-size: 15px; letter-spacing: 1px; }
    .live-widget { padding: 10px; }
}
</style>
</head>
<body>

<?php if (!$dalam_jam || $total === 0): ?>

    <!-- =====================================================
         OFF / KOSONG → beri tahu parent untuk TUTUP widget
         ===================================================== -->
    <div id="off-marker" style="display:none;"></div>

    <script>
    (function () {
        function sendClosed() {
            parent.postMessage(
                { type: 'live-absensi-state', closed: true },
                '*'
            );
        }
        sendClosed();
        window.addEventListener('load', sendClosed);

        // Kalau sekarang masuk jam operasional, minta parent reload iframe
        function cekJam() {
            var h = new Date().getHours();
            if (h >= 6 && h < 15) {
                parent.postMessage(
                    { type: 'live-absensi-state', closed: false, reload: true },
                    '*'
                );
            }
        }
        setInterval(cekJam, 60000); // cek tiap 1 menit
    })();
    </script>

<?php else: ?>

<div class="live-widget">
    <div class="live-header">
        <span class="live-badge"><span class="dot"></span> Live</span>
        <div class="live-title">Profil Kehadiran Hari Ini</div>
        <div class="live-clock" id="clock">--:--:--</div>
    </div>

    <div class="live-summary">
        <span class="s-hadir">Hadir: <b><?= $hadir ?></b></span>
        <span class="s-izin">Izin: <b><?= $izin ?></b></span>
        <span class="s-sakit">Sakit: <b><?= $sakit ?></b></span>
        <span class="s-cuti">Cuti: <b><?= $cuti ?></b></span>
        <span class="s-hadir">Wfh: <b><?= $wfh ?></b></span>
        <span>Total: <b><?= $total ?></b></span>
    </div>

    <div class="cards-grid" id="grid"></div>
    <div class="dots" id="dots"></div>
</div>

<script>
const DATA       = <?= json_encode($rows, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
const PLACEHOLDER= '<?= $placeholder ?>';
const ROTATE_MS  = 5000;

const grid = document.getElementById('grid');
const dots = document.getElementById('dots');

let perRow = 0;
let groups = [];
let current = 0;
let timer = null;

function getPerRow() {
    const w = window.innerWidth;
    if (w >= 1200) return 6;
    if (w >= 900)  return 4;
    if (w >= 600)  return 3;
    return 2;
}

function escapeHtml(s) {
    return String(s).replace(/[&<>"']/g, c => ({
        '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'
    }[c]));
}

function buildCard(r) {
    const stat = (r.stat || '').toUpperCase().trim();
    const known = ['HADIR','IZIN','SAKIT','CUTI','DL', 'WFH'];
    const cls = known.includes(stat) ? stat : 'default';

    const foto = (r.foto || '').trim();
    const src = foto === '' ? PLACEHOLDER : 'assets/foto/' + encodeURIComponent(foto);

    const waktu = r.waktu ? String(r.waktu).substring(11, 16) : '-';
    const nama = escapeHtml(r.namapegawai || '');
    const jab  = escapeHtml(r.jabatan || '');

    return `
        <div class="card">
            <div class="photo-wrap">
                <img src="${src}" alt="${nama}" loading="lazy"
                     onerror="this.onerror=null;this.src='${PLACEHOLDER}';">
            </div>
            <div class="overlay">
                <div class="nama">${nama}</div>
                <div class="jabatan">${jab}</div>
                <div class="meta">
                    <span class="waktu">${waktu}</span>
                    <span class="stat ${cls}">${escapeHtml(stat)}</span>
                </div>
            </div>
        </div>
    `;
}

function chunk(arr, n) {
    const out = [];
    for (let i = 0; i < arr.length; i += n) out.push(arr.slice(i, i + n));
    return out;
}

function renderDots() {
    dots.innerHTML = '';
    if (groups.length <= 1) return;
    groups.forEach((_, i) => {
        const d = document.createElement('span');
        d.className = 'dot-nav' + (i === current ? ' active' : '');
        dots.appendChild(d);
    });
}

function showGroup(i, animate) {
    current = i;

    const doRender = () => {
        grid.style.gridTemplateColumns = `repeat(${perRow}, 1fr)`;
        grid.innerHTML = groups[i].map(buildCard).join('');
        grid.classList.remove('fade-out');
        renderDots();
        sendHeight();
    };

    if (animate) {
        grid.classList.add('fade-out');
        setTimeout(doRender, 350);
    } else {
        doRender();
    }
}

function startRotation() {
    if (timer) clearInterval(timer);
    if (groups.length <= 1) return;
    timer = setInterval(() => {
        showGroup((current + 1) % groups.length, true);
    }, ROTATE_MS);
}

function rebuild() {
    const newPerRow = getPerRow();
    if (newPerRow === perRow && groups.length) return;

    perRow = newPerRow;
    groups = chunk(DATA, perRow);
    current = 0;

    grid.style.gridTemplateColumns = `repeat(${perRow}, 1fr)`;
    showGroup(0, false);
    startRotation();
}

function sendHeight() {
    setTimeout(() => {
        parent.postMessage(
            { type: 'live-absensi-height', height: document.body.scrollHeight },
            '*'
        );
    }, 60);
}

function tickClock() {
    const el = document.getElementById('clock');
    if (!el) return;
    const now = new Date();
    const j = String(now.getHours()).padStart(2,'0');
    const m = String(now.getMinutes()).padStart(2,'0');
    const s = String(now.getSeconds()).padStart(2,'0');
    el.textContent = j + ':' + m + ':' + s;
}

tickClock();
setInterval(tickClock, 1000);

rebuild();

window.addEventListener('resize', () => {
    clearTimeout(window.__resizeT);
    window.__resizeT = setTimeout(rebuild, 250);
});

if (window.ResizeObserver) {
    new ResizeObserver(sendHeight).observe(document.body);
}
window.addEventListener('load', sendHeight);

// Refresh data tiap 90 detik
setTimeout(() => location.reload(), 90000);
</script>

<?php endif; ?>

</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit