Mini Kabibi Habibi
<?php
// admin_dashboard.php
// Include database connection
include 'db_connection.php';
// Initialize variables for filter
$school_filter = isset($_POST['school']) ? $_POST['school'] : '';
$district_filter = isset($_POST['district']) ? $_POST['district'] : '';
// Get the 'status' parameter from the URL (if set)
$status_filter = isset($_GET['status']) ? $_GET['status'] : '';
// Build the SQL query with optional filtering
$sql = "SELECT * FROM submitted_inventory WHERE 1"; // Start with a condition that always evaluates to true
// Apply filters if they are set
if ($school_filter) {
$sql .= " AND name_of_school LIKE '%" . mysqli_real_escape_string($conn, $school_filter) . "%'";
}
if ($district_filter) {
$sql .= " AND district LIKE '%" . mysqli_real_escape_string($conn, $district_filter) . "%'";
}
// Apply the status filter if it's set
if ($status_filter) {
$sql .= " AND current_status = '" . mysqli_real_escape_string($conn, $status_filter) . "'";
}
// Execute the query to get the filtered submissions
$result = mysqli_query($conn, $sql);
// Query to get the total number of submissions
$total_sql = "SELECT COUNT(*) AS total_submissions FROM submitted_inventory";
$total_result = mysqli_query($conn, $total_sql);
$total_row = mysqli_fetch_assoc($total_result);
$total_submissions = $total_row['total_submissions'];
// Query to get the number of functional submissions
$functional_sql = "SELECT COUNT(*) AS functional_count FROM submitted_inventory WHERE current_status = 'Functional'";
$functional_result = mysqli_query($conn, $functional_sql);
$functional_row = mysqli_fetch_assoc($functional_result);
$functional_count = $functional_row['functional_count'];
// Query to get the number of non-functional submissions
$non_functional_sql = "SELECT COUNT(*) AS non_functional_count FROM submitted_inventory WHERE current_status = 'Not Functional'";
$non_functional_result = mysqli_query($conn, $non_functional_sql);
$non_functional_row = mysqli_fetch_assoc($non_functional_result);
$non_functional_count = $non_functional_row['non_functional_count'];
// Query to get the number of submissions with "Needs Repair" status
$needs_repair_sql = "SELECT COUNT(*) AS needs_repair_count FROM submitted_inventory WHERE current_status = 'Needs Repair'";
$needs_repair_result = mysqli_query($conn, $needs_repair_sql);
$needs_repair_row = mysqli_fetch_assoc($needs_repair_result);
$needs_repair_count = $needs_repair_row['needs_repair_count'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - DCP Inventory Management</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
/* Basic layout and sidebar styling */
body {
font-family: Arial, sans-serif;
margin: 0;
display: flex;
}
/* Sidebar Navigation */
.sidebar {
width: 170px;
background-color: #2c3e50;
color: white;
padding: 8px;
height: 100vh;
position: fixed;
}
.sidebar h2 {
text-align: center;
font-size: 17px;
}
.sidebar ul {
list-style: none;
padding: 0;
margin: 20px 0;
}
.sidebar ul li {
margin: 12px 0;
}
.sidebar ul li a {
color: white;
text-decoration: none;
font-size: 12px;
padding: 8px;
display: block;
border-radius: 5px;
}
.sidebar ul li a:hover {
background-color: #34495e;
}
/* Main content area */
.main-content {
margin-left: 200px;
padding: 20px;
width: 100%;
}
/* Logout Button Styling */
.logout-btn {
background-color: #2980b9;
color: white;
padding: 6px 12px;
font-size: 12px;
border-radius: 5px;
position: fixed;
top: 10px;
right: 20px;
text-decoration: none;
}
.logout-btn:hover {
background-color: #3498db;
}
/* Table Styling */
table {
width: 100%;
table-layout: fixed;
margin-top: 30px;
border-collapse: collapse;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
font-size: 12px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 8px 12px;
text-align: center;
}
th {
background-color: #f2f2f2;
font-weight: bold;
color: #333;
}
tbody tr:nth-child(even) {
background-color: #f9f9f9;
}
tbody tr:hover {
background-color: #f1f1f1;
}
/* Filter Section Styling */
#filter-section {
margin-top: 20px;
margin-bottom: 20px;
}
#filter-section input {
padding: 5px;
margin-right: 10px;
font-size: 12px;
}
#filter-section button {
padding: 6px 12px;
font-size: 12px;
cursor: pointer;
background-color: #2980b9;
color: white;
border: none;
border-radius: 5px;
}
#filter-section button:hover {
background-color: #3498db;
}
/* Filter Section Label Styling */
#filter-section label {
font-size: 12px;
margin-right: 5px;
}
/* Dashboard Stats Section */
#dashboard-stats {
display: flex;
justify-content: space-around;
margin-top: 20px;
padding: 20px;
background-color: #ecf0f1;
border-radius: 8px;
}
#dashboard-stats .stat {
text-align: center;
font-size: 16px;
}
#dashboard-stats .stat h3 {
font-size: 24px;
color: #2980b9;
}
/* Chart Container */
.chart-container {
margin-top: 20px;
width: 80%; /* Adjust the width as needed */
margin-left: auto;
margin-right: auto;
text-align: center;
display: block; /* Ensure the container is a block element */
}
/* Adjusting Canvas Height */
#inventoryChart {
height: 250px !important; /* Increased height for better display */
}
/* Remove underline from links in the dashboard stats section */
#dashboard-stats .stat a {
text-decoration: none;
color: inherit; /* Optional: Keep the link color consistent with the text */
}
/* Optional: Add hover effect to links without underline */
#dashboard-stats .stat a:hover {
text-decoration: underline; /* Add underline on hover to indicate interactivity */
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="sidebar">
<!-- Logo Below the Submitted Inventory Tab -->
<img src="image/sdologo.png" alt="Logo" style="width: 100%; max-width: 90px; margin-top: 20px; display: block; margin-left: auto; margin-right: auto;">
<h2>Admin Dashboard</h2>
<ul>
<li><a href="admin_dashboard.php" id="dashboard-tab">Dashboard</a></li>
<li><a href="admin_dashboard.php#submitted-inventory" id="submitted-inventory-tab">Submitted Inventory</a></li>
<li><a href="admin_dashboard.php#user-profile" id="user-profile">User Profile</a></li>
</ul>
</div>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Logout Button -->
<a href="logout.php" class="logout-btn">Logout</a>
<!-- Dashboard Stats Section -->
<div id="dashboard-stats">
<div class="stat">
<h3><?php echo $total_submissions; ?></h3>
<p>Total Submissions</p>
</div>
<div class="stat">
<h3><a href="admin_dashboard.php?status=Functional"><?php echo $functional_count; ?></a></h3>
<p><a href="admin_dashboard.php?status=Functional">Functional</a></p>
</div>
<div class="stat">
<h3><a href="admin_dashboard.php?status=Not%20Functional"><?php echo $non_functional_count; ?></a></h3>
<p><a href="admin_dashboard.php?status=Not%20Functional">Not Functional</a></p>
</div>
<div class="stat">
<h3><a href="admin_dashboard.php?status=Needs%20Repair"><?php echo $needs_repair_count; ?></a></h3>
<p><a href="admin_dashboard.php?status=Needs%20Repair">Needs Repair</a></p>
</div>
</div>
<!-- Small Graph Section (Only on Dashboard) -->
<div class="chart-container" id="chart-container" style="display: <?php echo $status_filter ? 'none' : 'block'; ?>;">
<canvas id="inventoryChart"></canvas>
</div>
<!-- Submitted Inventory Section -->
<div id="submitted-inventory" style="display: <?php echo $status_filter ? 'block' : 'none'; ?>;">
<h3>Submitted Inventory</h3>
<!-- Filter Section -->
<div id="filter-section">
<form method="POST" action="admin_dashboard.php#submitted-inventory">
<label for="school">School Name:</label>
<input type="text" id="school" name="school" value="<?php echo htmlspecialchars($school_filter); ?>" placeholder="Search by school name">
<label for="district">District:</label>
<input type="text" id="district" name="district" value="<?php echo htmlspecialchars($district_filter); ?>" placeholder="Search by district">
<button type="submit">Apply Filters</button>
</form>
</div>
<!-- Display Filtered Inventory Table -->
<table>
<thead>
<tr>
<th>School ID</th>
<th>Name of School</th>
<th>District</th>
<th>DCP Batch Number Received</th>
<th>Quantity</th>
<th>Supplier</th>
<th>Date Received</th>
<th>Current Status</th>
</tr>
</thead>
<tbody>
<?php
// Check if there are any records in the database
if (mysqli_num_rows($result) > 0) {
// Fetch and display each row
while ($row = mysqli_fetch_assoc($result)) {
echo "
<tr>
<td>{$row['school_id']}</td>
<td>{$row['name_of_school']}</td>
<td>{$row['district']}</td>
<td>{$row['dcp_batch_number_received']}</td>
<td>{$row['quantity']}</td>
<td>{$row['supplier']}</td>
<td>{$row['date_received']}</td>
<td>{$row['current_status']}</td>
</tr>";
}
} else {
echo "<tr><td colspan='8'>No inventory submissions found matching the filters.</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
<!-- JavaScript to toggle the views -->
<script>
document.getElementById('dashboard-tab').addEventListener('click', function () {
document.getElementById('dashboard-stats').style.display = 'block';
document.getElementById('submitted-inventory').style.display = 'none';
document.getElementById('chart-container').style.display = 'block';
});
document.getElementById('submitted-inventory-tab').addEventListener('click', function () {
document.getElementById('dashboard-stats').style.display = 'none';
document.getElementById('submitted-inventory').style.display = 'block';
document.getElementById('chart-container').style.display = 'none';
});
// Chart.js - Create Bar Chart
var ctx = document.getElementById('inventoryChart').getContext('2d');
var inventoryChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['Total Submissions', 'Functional', 'Not Functional', 'Needs Repair'],
datasets: [{
label: 'Line Graph',
data: [<?php echo $total_submissions; ?>, <?php echo $functional_count; ?>, <?php echo $non_functional_count; ?>, <?php echo $needs_repair_count; ?>],
backgroundColor: ['#007bff', '#28a745', '#e74c3c', '#f39c12'],
borderColor: ['#0056b3', '#218838', '#c0392b', '#e67e22'],
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Number of Submissions'
}
}
}
}
});
</script>
</body>
</html>