| Server IP : 173.209.174.21 / Your IP : 216.73.216.89 Web Server : Apache/2.4.58 (Ubuntu) System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : nodor ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/vendorset/Vendorapp/backup files/ |
Upload File : |
<?php
// Start the session
session_start();
// Check if the user is logged in as an admin
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header("Location: admin_login.php"); // Redirect to login page if not logged in
exit();
}
// Include the database configuration
include 'config.php';
// Establish a database connection
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if delete action is triggered
if (isset($_GET['delete_id'])) {
$delete_id = $_GET['delete_id'];
$delete_sql = "DELETE FROM vendors WHERE id = ?";
$stmt = $conn->prepare($delete_sql);
$stmt->bind_param("i", $delete_id);
$stmt->execute();
$stmt->close();
header("Location: admin_dashboard.php"); // Redirect to refresh the page
exit();
}
// Fetch vendor data from the database
$sql = "SELECT id, name, email, category, spots, payment_status, description FROM vendors";
$result = $conn->query($sql);
// Calculate total spots taken and number of vendors
$total_vendors = $result->num_rows;
$spots_taken = 0;
while ($row = $result->fetch_assoc()) {
$spots_taken += $row['spots'];
}
$result->data_seek(0); // Reset result pointer
// Export to Excel logic
if (isset($_POST['export_excel'])) {
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="vendors_list.xls"');
header('Cache-Control: max-age=0');
$output = fopen('php://output', 'w');
fputcsv($output, ['ID', 'Name', 'Email', 'Category', 'Spots', 'Payment Status', 'Description']); // Header row
while ($row = $result->fetch_assoc()) {
fputcsv($output, $row);
}
fclose($output);
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #F5F5F5;
color: #333333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.main-container {
background-color: #FFFFFF;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 80%;
max-width: 1200px;
}
h2 {
text-align: center;
color: #1E90FF;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.button {
background-color: #1E90FF;
color: white;
padding: 5px 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.button:hover {
background-color: #1C86EE;
}
.delete-button {
background-color: #ff4d4d;
}
.delete-button:hover {
background-color: #e60000;
}
.export-section {
margin-bottom: 20px;
}
.description-column {
word-wrap: break-word; /* Allow text to wrap */
white-space: normal; /* Allow new lines */
max-width: 300px; /* Limit the column width */
}
</style>
</head>
<body>
<div class="main-container">
<h2>Admin Dashboard</h2>
<!-- Display Tally Information -->
<p><strong>Total Vendors:</strong> <?php echo $total_vendors; ?></p>
<p><strong>Total Spots Taken:</strong> <?php echo $spots_taken; ?></p>
<!-- Export to Excel Button -->
<div class="export-section">
<form method="POST" action="admin_dashboard.php">
<button type="submit" name="export_excel" class="button">Export to Excel</button>
</form>
</div>
<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Category</th>
<th>Spots</th>
<th>Payment Status</th>
<th>Description</th>
<th>Action</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . htmlspecialchars($row['name']) . "</td>";
echo "<td>" . htmlspecialchars($row['email']) . "</td>";
echo "<td>" . htmlspecialchars($row['category']) . "</td>";
echo "<td>" . htmlspecialchars($row['spots']) . "</td>";
echo "<td>" . htmlspecialchars($row['payment_status']) . "</td>";
echo "<td class='description-column'>" . htmlspecialchars($row['description']) . "</td>";
echo "<td>
<a href='edit_vendor.php?id=" . $row['id'] . "' class='button'>Edit</a>
<a href='admin_dashboard.php?delete_id=" . $row['id'] . "' class='button delete-button'>Delete</a>
</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='7'>No vendors found.</td></tr>";
}
?>
</table>
</div>
</body>
</html>
<?php
// Close the database connection
$conn->close();
?>