MOON
Server: Apache
System: Linux server30c.hostingraja.org 3.10.0-962.3.2.lve1.5.63.el7.x86_64 #1 SMP Fri Oct 8 12:03:35 UTC 2021 x86_64
User: jibhires (1887)
PHP: 8.1.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, allow_url_fopen, symlink, escapeshellcmd, pcntl_exec
Upload Files
File: //home/jibhires/demo.brightsolutionsindia.com/images/admin_dashboard.php
<?php
session_start();
include 'db_connect.php';

// Ensure only admins can access this page
if ($_SESSION['role'] != 'Admin') {
    echo "Access denied!";
    exit;
}

// Build the query with filtering options
$conditions = [];
if (!empty($_GET['machine_id'])) {
    $conditions[] = "qc_sheets.machine_id = " . $_GET['machine_id'];
}
if (!empty($_GET['status'])) {
    $conditions[] = "qc_sheets.status = '" . $_GET['status'] . "'";
}
if (!empty($_GET['qc_date'])) {
    $conditions[] = "qc_sheets.qc_date = '" . $_GET['qc_date'] . "'";
}

// Base query
$query = "SELECT qc_sheets.id, machines.machine_name, users.username AS operator, qc_sheets.qc_date, qc_sheets.status 
          FROM qc_sheets 
          JOIN machines ON qc_sheets.machine_id = machines.id 
          JOIN users ON qc_sheets.operator_id = users.id";

// Add filters if there are any
if (!empty($conditions)) {
    $query .= " WHERE " . implode(" AND ", $conditions);
}

$stmt = $pdo->query($query);
$qc_sheets = $stmt->fetchAll();
?>

<!DOCTYPE html>
<html>
<head>
    <title>Admin Dashboard</title>
</head>
<body>
    <h1>Admin Dashboard</h1>

    <!-- Table displaying QC sheet data -->
    <table border="1">
        <tr>
            <th>QC Sheet ID</th>
            <th>Machine</th>
            <th>Operator</th>
            <th>Date</th>
            <th>Status</th>
        </tr>
        <?php foreach ($qc_sheets as $qc_sheet): ?>
            <tr>
                <td><?php echo $qc_sheet['id']; ?></td>
                <td><?php echo $qc_sheet['machine_name']; ?></td>
                <td><?php echo $qc_sheet['operator']; ?></td>
                <td><?php echo $qc_sheet['qc_date']; ?></td>
                <td><?php echo $qc_sheet['status']; ?></td>
            </tr>
        <?php endforeach; ?>
    </table>

    <!-- Filtering form -->
    <h3>Filter Results</h3>
    <form method="GET" action="admin_dashboard.php">
        <label for="machine_id">Filter by Machine:</label>
        <select name="machine_id">
            <option value="">Select Machine</option>
            <?php
            $machine_query = "SELECT * FROM machines";
            $machines = $pdo->query($machine_query)->fetchAll();
            foreach ($machines as $machine) {
                echo "<option value='" . $machine['id'] . "'>" . $machine['machine_name'] . "</option>";
            }
            ?>
        </select><br><br>

        <label for="status">Filter by Status:</label>
        <select name="status">
            <option value="">All</option>
            <option value="Pending">Pending</option>
            <option value="ApprovedL1">Approved by Supervisor L1</option>
            <option value="ApprovedL2">Approved by Supervisor L2</option>
            <option value="Rejected">Rejected</option>
        </select><br><br>

        <label for="qc_date">Filter by Date:</label>
        <input type="date" name="qc_date"><br><br>

        <input type="submit" value="Filter Results">
    </form>

    <!-- Export to CSV button -->
    <form method="POST" action="export_csv.php">
        <input type="submit" value="Export to CSV">
    </form>

</body>
</html>