35429-vm/tickets.php
2025-11-02 20:12:50 +00:00

104 lines
4.9 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, title, status, priority, created_at FROM tickets ORDER BY created_at DESC");
$tickets = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching tickets: ' . $e->getMessage() . '</div>';
$tickets = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Tickets</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTicketModal">
Add Ticket
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Title</th>
<th>Status</th>
<th>Priority</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($tickets)): ?>
<tr>
<td colspan="5" class="text-center">No tickets found.</td>
</tr>
<?php else: ?>
<?php foreach ($tickets as $ticket): ?>
<tr>
<td><?php echo htmlspecialchars($ticket['title']); ?></td>
<td><span class="badge bg-<?php echo str_replace(' ', '-', strtolower($ticket['status'])) == 'open' ? 'success' : (strtolower($ticket['status']) == 'in-progress' ? 'warning' : 'secondary'); ?>"><?php echo htmlspecialchars($ticket['status']); ?></span></td>
<td><span class="badge bg-<?php echo strtolower($ticket['priority']) == 'high' ? 'danger' : (strtolower($ticket['priority']) == 'medium' ? 'warning' : 'success'); ?>"><?php echo htmlspecialchars($ticket['priority']); ?></span></td>
<td><?php echo htmlspecialchars($ticket['created_at']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Ticket Modal -->
<div class="modal fade" id="addTicketModal" tabindex="-1" aria-labelledby="addTicketModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addTicketModalLabel">Add New Ticket</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_ticket.php" method="POST">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description"></textarea>
</div>
<div class="mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option value="Open">Open</option>
<option value="In Progress">In Progress</option>
<option value="Closed">Closed</option>
</select>
</div>
<div class="mb-3">
<label for="priority" class="form-label">Priority</label>
<select class="form-select" id="priority" name="priority">
<option value="Low">Low</option>
<option value="Medium" selected>Medium</option>
<option value="High">High</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Ticket</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>