<?php

session_start();

include '../config/koneksi.php';

$data = mysqli_query(
    $conn,
    "SELECT * FROM berkas
     WHERE status='pending'
     ORDER BY id DESC"
);

?>

<!DOCTYPE html>
<html>

<head>

<title>verifikasi berkas BPKAD</title>

<link rel="stylesheet"
href="../assets/style.css">

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">

</head>

<body>

<div class="wrapper">



<!-- SIDEBAR -->

<div class="sidebar">

<h2>BPKAD</h2>

<a href="dashboard.php">

<i class="fa-solid fa-house"></i>

Dashboard

</a>

<a href="history.php">

<i class="fa-solid fa-clock-rotate-left"></i>

History

</a>

<a href="../logout.php"
onclick="return konfirmasiLogout()">

<i class="fa-solid fa-right-from-bracket"></i>

Logout

</a>

</div>

<div class="profile-box">

<img src="../assets/profile/default.png">

<h3>

<?= $_SESSION['username']; ?>

</h3>

<p>User Kantor</p>

</div>

<div class="profile-box">

<img src="../assets/profile/default.png">

<h3>

<?= $_SESSION['username']; ?>

</h3>

<p>Administrator</p>

</div>





<!-- CONTENT -->

<div class="loader"
id="loader">

<div class="spinner"></div>

</div>

<div class="content">

<!-- TOPBAR -->

<div class="topbar">

<div class="header-flex">

<div>

<h1>(PERBENDAHARAAN)</h1>

<p>BADAN PENGELOLA KEUANGAN DAN ASET DAERAH</p>

</div>

<span class="notification">

<?php

echo mysqli_num_rows(
mysqli_query(
$conn,
"SELECT * FROM berkas
WHERE status='pending'"
)
);

?>

Berkas Pending

</span>

<img src="../assets/img/logo minahasa.png"
class="logo">



</div>

<br>

<button onclick="darkMode()">

🌙 Dark Mode

</button>

</div>


`

<!-- CARD STATISTIK -->

<div class="cards">

<div class="card">

<h3>Total berkas masuk</h3>

<p>

<?php

echo mysqli_num_rows(
mysqli_query(
$conn,
"SELECT * FROM berkas
WHERE status='diterima'"
)
);

?>

</p>

</div>



<div class="card">

<h3>Total Revisi</h3>

<p>

<?php

echo mysqli_num_rows(
mysqli_query(
$conn,
"SELECT * FROM berkas
WHERE status='revisi'"
)
);

?>

</p>

</div>

</div>


<!-- CHART -->

<div class="table-container">

<h2>Grafik Statistik Berkas</h2>

<br>

<canvas id="myChart"></canvas>

</div>

<br><br>


<!-- TABLE -->

<div class="table-container">

<!-- SEARCH -->

<div class="search-box">

<input type="text"
id="searchInput"
placeholder="Cari nama berkas atau kantor...">

</div>

<table>

<tr>

<th>No</th>
<th>Nama Berkas</th>
<th>Asal Kantor</th>
<th>File</th>
<th>Status</th>
<th>Tanggal Upload</th>
<th>Keterangan Admin</th>
<th>Aksi</th>

</tr>

<?php

$no = 1;

while($d = mysqli_fetch_assoc($data)){

?>

<tr>

<td><?= $no++; ?></td>



<td>

<?= $d['nama_berkas']; ?>

</td>



<td>

<?= $d['asal_kantor']; ?>

</td>



<td>

<a href="../uploads/<?php echo $d['file']; ?>"
target="_blank">

Lihat / Download

</a>

</td>



<td class="<?= $d['status']; ?>">

<?= $d['status']; ?>

</td>



<td>

<?= date(
'd-m-Y H:i',
strtotime($d['tanggal_upload'])
); ?>

</td>



<!-- FORM -->

<td>

<form action="verifikasi.php"
method="POST">

<input type="hidden"
name="id"
value="<?= $d['id']; ?>">

<textarea
name="keterangan"
placeholder="Tulis keterangan admin..."
required
style="
width:100%;
height:90px;
padding:10px;
border-radius:10px;
border:1px solid #ccc;
resize:none;
"></textarea>

</td>



<!-- BUTTON -->

<td>

<button
type="submit"
name="status"
value="diterima"
class="btn-acc">

🟢 Terima

</button>

<br><br>

<button
type="submit"
name="status"
value="revisi"
class="btn-tolak">

🔴 Revisi

</button>

</form>

</td>

</tr>

<?php } ?>

</table>

</div>

</div>

</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="../assets/script.js"></script>
<script>

const ctx =
document.getElementById(
'myChart'
);

new Chart(ctx, {

type: 'bar',

data: {

labels: [
'Pending',
'Diterima',
'Revisi'
],

datasets: [{

label: 'Jumlah Berkas',

data: [

<?php

$total_berkas = mysqli_num_rows(

    mysqli_query(
        $conn,
        "SELECT * FROM berkas"
    )

);

?>,

<?php

echo mysqli_num_rows(
mysqli_query(
$conn,
"SELECT * FROM berkas
WHERE status='diterima'"
)
);

?>,

<?php

echo mysqli_num_rows(
mysqli_query(
$conn,
"SELECT * FROM berkas
WHERE status='revisi'"
)
);

?>

],

borderWidth: 1

}]

},

options: {

responsive:true

}

});

</script>

</body>
</html>