<?php include('db_connection.php'); ?>
<!DOCTYPE html>
<html>
<head>
    <title>Manage Payroll - School Management System</title>
    <link rel="stylesheet" type="text/css" href="#">
    <style type="text/css">
        /* styles.css */

body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
}

.container {
    width: 80%;
    margin: 0 auto;
    overflow: hidden;
}

.header {
    background: #333;
    color: #fff;
    padding: 20px 0;
    text-align: center;
}

.header h1 {
    margin: 0;
}

.navbar {
    background: #555;
    color: #fff;
    padding: 10px 0;
    text-align: center;
}

.navbar a {
    color: #fff;
    padding: 14px 20px;
    text-decoration: none;
    text-transform: uppercase;
}

.navbar a:hover {
    background: #444;
    transition: background 0.3s;
}

.sidebar {
    float: left;
    width: 25%;
    background: #f4f4f4;
    padding: 15px;
    box-sizing: border-box;
}

.sidebar h3 {
    margin-top: 0;
}

.sidebar ul {
    list-style-type: none;
    padding: 0;
}

.sidebar ul li {
    margin-bottom: 10px;
}

.sidebar ul li a {
    color: #333;
    text-decoration: none;
}

.sidebar ul li a:hover {
    text-decoration: underline;
}

.content {
    float: left;
    width: 70%;
    padding: 15px;
    box-sizing: border-box;
    background: #fff;
    margin-left: 5%;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.content h2 {
    margin-top: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

table, th, td {
    border: 1px solid #ddd;
}

th, td {
    padding: 8px;
    text-align: left;
}

th {
    background-color: #f2f2f2;
}

tr:nth-child(even) {
    background-color: #f9f9f9;
}

tr:hover {
    background-color: #f1f1f1;
}

form {
    margin: 20px 0;
}

form label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

form input[type="text"],
form input[type="date"],
form input[type="number"],
form select,
form textarea {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

form input[type="submit"] {
    background: #333;
    color: #fff;
    border: none;
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 4px;
}

form input[type="submit"]:hover {
    background: #555;
}

.footer {
    clear: both;
    background: #333;
    color: #fff;
    text-align: center;
    padding: 10px 0;
    margin-top: 20px;
    position: relative;
    bottom: 0;
    width: 100%;
}
.btn {
    display: inline-block;
    padding: 10px 15px;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    outline: none;
    color: #fff;
    background-color: #4CAF50;
    border: none;
    border-radius: 15px;
    box-shadow: 0 9px #999;
}

.btn:hover {background-color: #3e8e41}

.btn:active {
    background-color: #3e8e41;
    box-shadow: 0 5px #666;
    transform: translateY(4px);
}

    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>Manage Payroll</h1>
        </div>
        <div class="navbar">
            <a href="admin_dashboard.php">Dashboard</a>
            <a href="manage_teachers.php">Manage Teachers</a>
            <a class="active" href="manage_payroll.php">Manage Payroll</a>
            <a href="manage_attendance.php">Manage Attendance</a>
            <!-- Add more links as needed -->
        </div>
        <div class="sidebar">
            <h3>Navigation</h3>
            <ul>
                <li><a href="view_payroll.php">View Payroll</a></li>
                <li><a href="add_payroll.php">Add Payroll Entry</a></li>
                <!-- Add more sidebar links as needed -->
            </ul>
        </div>
        <div class="content">
            <h2>View Payroll</h2>
            <table>
                <thead>
                    <tr>
                        <th>Payroll ID</th>
                        <th>Teacher</th>
                        <th>Salary</th>
                        <th>Payment Date</th>
                        <th>Payment Method</th>
                        <th>Notes</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $query = "SELECT p.payroll_id, t.name AS teacher_name, p.salary, p.payment_date, p.payment_method, p.notes 
                              FROM payrolls p
                              JOIN teachers t ON p.teacher_id = t.teacher_id";
                    $result = mysqli_query($conn, $query);
                    if (mysqli_num_rows($result) > 0) {
                        while ($row = mysqli_fetch_assoc($result)) {
                            echo "<tr>";
                            echo "<td>" . $row['payroll_id'] . "</td>";
                            echo "<td>" . $row['teacher_name'] . "</td>";
                            echo "<td>" . $row['salary'] . "</td>";
                            echo "<td>" . $row['payment_date'] . "</td>";
                            echo "<td>" . $row['payment_method'] . "</td>";
                            echo "<td>" . $row['notes'] . "</td>";
                            echo "<td><a class='btn' href='edit_payroll.php?payroll_id=" . $row['payroll_id'] . "'>Edit</a> | <a class='btn' href='delete_payroll.php?payroll_id=" . $row['payroll_id'] . "' onclick='return confirm(\"Are you sure you want to delete this record?\")'>Delete</a></td>";
                            echo "</tr>";
                        }
                    } else {
                        echo "<tr><td colspan='7'>No payrolls found.</td></tr>";
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <div class="footer">
            <p>&copy; 2024 School Management System</p>
        </div>
    </div>
</body>
</html>
