Mini Kabibi Habibi
<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: index.php"); // Redirect to login page if not logged in
exit();
}
include 'db_connection.php'; // Include database connection file
// Get school_id from the session
$school_id = $_SESSION['school_id']; // Assuming school_id is saved during the login process
// Fetch the Name of School and District from the database
$sql_school = "SELECT name_of_school, district FROM schools WHERE school_id = ?";
$stmt_school = mysqli_prepare($conn, $sql_school);
mysqli_stmt_bind_param($stmt_school, 's', $school_id); // Bind school_id to the query
mysqli_stmt_execute($stmt_school);
$result_school = mysqli_stmt_get_result($stmt_school);
$school_name = '';
$district = ''; // Initialize the district variable
if ($row = mysqli_fetch_assoc($result_school)) {
$school_name = $row['name_of_school'];
$district = $row['district']; // Fetch the district from the database
}
// Prepare and execute the query to fetch the submitted inventory for the logged-in school
$sql = "SELECT * FROM submitted_inventory WHERE school_id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 's', $school_id); // Bind school_id to the query
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
// Get success message from session (if any)
$success_message = isset($_SESSION['success_message']) ? $_SESSION['success_message'] : '';
$error_message = isset($_SESSION['error_message']) ? $_SESSION['error_message'] : '';
// Clear the success and error messages after they're displayed
unset($_SESSION['success_message']);
unset($_SESSION['error_message']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>School Dashboard - DCP Inventory Management</title>
<style>
/* General Body Styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
height: 100vh;
font-size: 14px;
background-color: #f4f7fc;
}
/* Sidebar Styling */
.sidebar {
width: 180px;
background-color: #2c3e50;
color: white;
padding: 8px;
height: 100%;
position: fixed;
}
.sidebar h2 {
font-size: 18px;
text-align: center;
margin-bottom: 20px;
}
.sidebar a {
text-decoration: none;
color: white;
font-size: 13px;
padding: 8px 15px;
display: block;
margin-bottom: 10px;
border-radius: 5px;
text-align: center;
}
.sidebar a:hover {
background-color: #34495e;
}
/* Main Content Styling */
.content {
flex: 1;
margin-left: 180px;
padding: 60px;
}
.inventory-form {
width: 100%;
max-width: 700px;
padding: 30px;
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
gap: 10px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 10px;
}
.label {
font-size: 13px;
color: #555;
font-weight: bold;
}
.input-field, .select-field {
padding: 8px;
font-size: 13px;
border-radius: 4px;
border: 1px solid #ccc;
}
.submit-btn {
background-color: #28a745;
color: white;
padding: 5px 15px;
font-size: 16px;
font-weight: bold;
border-radius: 6px;
border: none;
cursor: pointer;
transition: background-color 0.3s;
}
.submit-btn:hover {
background-color: #218838;
}
/* Table Styling for Submitted Inventory */
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; /* Reduced font size for the table content */
}
th, td {
padding: 6px 12px;
text-align: center;
border: 1px solid #ddd; /* Adds borders to cells */
}
th {
background-color: #f2f2f2;
font-weight: bold;
color: #333;
}
tbody tr:nth-child(even) {
background-color: #f9f9f9;
}
tbody tr:hover {
background-color: #f1f1f1;
}
tbody tr {
border-bottom: 1px solid #ddd; /* Adds a border line between each row */
}
/* Success/Error Message Styling */
.highlight-success {
background-color: #28a745; /* Green background */
color: white; /* White text color */
padding: 15px; /* Padding for better spacing */
font-size: 16px; /* Adjust font size */
font-weight: bold; /* Make it bold */
border-radius: 8px; /* Rounded corners */
text-align: center; /* Center the text */
margin-bottom: 20px; /* Space below the message */
}
.error-message {
background-color: #e74c3c;
color: white;
padding: 10px;
text-align: center;
margin-bottom: 20px;
}
/* Logout Button Styling */
.logout-btn {
background-color: #2980b9;
color: white;
padding: 6px 12px;
font-size: 12px;
border-radius: 5px;
position: fixed;
top: 30px;
right: 20px;
text-decoration: none;
}
.logout-btn:hover {
background-color: #3498db;
}
</style>
</head>
<body>
<!-- Logout Button -->
<a href="logout.php" class="logout-btn">Logout</a>
<!-- Sidebar Navigation -->
<div class="sidebar">
<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>School Dashboard</h2>
<a href="javascript:void(0)" onclick="showDashboard()">Dashboard</a>
<a href="javascript:void(0)" onclick="showInventoryForm()">Submit Inventory</a>
<a href="javascript:void(0)" onclick="showSubmittedInventory()">View Submitted Inventory</a>
</div>
<!-- Main Content Area -->
<div class="content" id="mainContent">
<!-- Default content is the Dashboard -->
<div id="dashboardContent">
<h2 class="welcome-message">Welcome to the School Dashboard</h2>
<p class="dashboard-text">This is your personal dashboard where you can view and manage your inventory.</p>
<p class="dashboard-text">Use the sidebar to navigate through different sections, including submitting inventory and viewing the submitted inventory.</p>
<br>
<p class="dashboard-text">How to determine the current status?</p>
<p class="dashboard-text">a. Functional - if all components are working properly</p>
<p class="dashboard-text">b. Not Functional - if all components are not working and the server is completely dead</p>
<p class="dashboard-text">c. Need Repair - if some components are still working and the server is powering on</p>
<br>
<p class="dashboard-text"><i>For your queries please contact the ICT UNIT via email at <strong>ictunit.batangascity@deped.gov.ph.</strong></i></p>
<!-- Success or Error Message Display -->
<?php if (!empty($success_message)): ?>
<div class="highlight-success">
<?php echo htmlspecialchars($success_message); ?>
</div>
<?php endif; ?>
<?php if (!empty($error_message)): ?>
<div class="error-message">
<?php echo htmlspecialchars($error_message); ?>
</div>
<?php endif; ?>
</div>
</div>
<script>
// Function to load the "Dashboard" content into the main content area
function showDashboard() {
const dashboardHTML = `
<h2 class="welcome-message">Welcome to the School Dashboard</h2>
<p class="dashboard-text">This is your personal dashboard where you can view and manage your inventory.</p>
<p class="dashboard-text">Use the sidebar to navigate through different sections, including submitting inventory and viewing the submitted inventory.</p>
`;
document.getElementById('mainContent').innerHTML = dashboardHTML;
}
// Function to load the "Submit Inventory" form into the main content area
function showInventoryForm() {
const formHTML = `
<div class="inventory-form">
<h2>Submit DCP Inventory</h2>
<form action="process_inventory.php" method="POST">
<div class="form-group">
<label for="school_id" class="label">School ID:</label>
<input type="text" name="school_id" id="school_id" class="input-field" value="<?php echo $school_id; ?>" readonly required>
</div>
<div class="form-group">
<label for="name_of_school" class="label">Name of School:</label>
<input type="text" name="name_of_school" id="name_of_school" class="input-field" value="<?php echo htmlspecialchars($school_name); ?>" required readonly>
</div>
<div class="form-group">
<label for="district" class="label">District:</label>
<input type="text" name="district" id="district" class="input-field" value="<?php echo htmlspecialchars($district); ?>" required>
</div>
<div class="form-group">
<label for="dcp_batch_number_received" class="label">DCP Batch Number Received:</label>
<input type="text" name="dcp_batch_number_received" id="dcp_batch_number_received" class="input-field" required>
</div>
<div class="form-group">
<label for="quantity" class="label">Quantity:</label>
<input type="text" name="quantity" id="quantity" class="input-field" required>
</div>
<div class="form-group">
<label for="supplier" class="label">Supplier:</label>
<input type="text" name="supplier" id="supplier" class="input-field" required>
</div>
<div class="form-group">
<label for="date_received" class="label">Date Received:</label>
<input type="date" name="date_received" id="date_received" class="input-field" required>
</div>
<div class="form-group">
<label for="current_status" class="label">Current Status:</label>
<select name="current_status" id="current_status" class="select-field" required>
<option value="" disabled selected>Select Current Status</option>
<option value="Functional">Functional</option>
<option value="Not Functional">Not Functional</option>
<option value="Need Repair">Need Repair</option>
<option value="Stolen">Stolen</option>
</select>
</div>
<button type="submit" class="submit-btn">Submit Inventory</button>
</form>
</div>
`;
document.getElementById('mainContent').innerHTML = formHTML;
}
// Function to load the "View Submitted Inventory" table into the main content area
function showSubmittedInventory() {
<?php
// Fetch the submitted inventory data from the database
$sql = "SELECT * FROM submitted_inventory WHERE school_id = ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 's', $school_id); // Bind school_id to the query
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
?>
const tableHTML = `
<h2>Submitted Inventory</h2>
<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>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($result)): ?>
<tr>
<td><?php echo $row['school_id']; ?></td>
<td><?php echo $row['name_of_school']; ?></td>
<td><?php echo $row['district']; ?></td>
<td><?php echo $row['dcp_batch_number_received']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['supplier']; ?></td>
<td><?php echo $row['date_received']; ?></td>
<td><?php echo $row['current_status']; ?></td>
<td>
<a href="edit_inventory.php?id=<?php echo $row['id']; ?>" class="edit-btn">Edit</a>
<a href="delete_inventory.php?id=<?php echo $row['id']; ?>" class="delete-btn" onclick="return confirm('Are you sure you want to delete this record?')">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
`;
document.getElementById('mainContent').innerHTML = tableHTML;
}
</script>
</body>
</html>