|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/assetradar.outerorbittech.com/admin/ | |
|
Path: /home2/outerorb/assetradar.outerorbittech.com/admin/tickets.php
Size: 4.7 KB
Permissions: 0666
<?php
require_once __DIR__ . '/../inc/auth.php';
require_login();
$u = current_user();
require_admin();
define('ADMIN_PAGE', true);
include __DIR__ . '/../inc/header.php';
include __DIR__ . '/admin_menu.php';
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
$per_page = 20;
$offset = ($page - 1) * $per_page;
$total_res = $mysqli->query('SELECT COUNT(*) as cnt FROM tickets');
$total = $total_res ? $total_res->fetch_assoc()['cnt'] : 0;
$res = $mysqli->query('SELECT t.*, i.asset_tag, i.item_name, u.name as reported_by FROM tickets t LEFT JOIN items i ON t.item_id=i.id LEFT JOIN users u ON t.user_id=u.id ORDER BY t.created_at DESC LIMIT ' . $per_page . ' OFFSET ' . $offset);
?>
<div class="card p-3 card-hero">
<div class="d-flex justify-content-between align-items-center">
<h5>Tickets</h5>
<form method="post" style="margin:0;">
<button type="submit" name="export_csv" class="btn btn-outline-success btn-sm">Export CSV</button>
</form>
</div>
<table class="table">
<thead><tr><th>ID</th><th>Item</th><th>Reported By</th><th>Issue</th><th>Status</th><th>Action</th></tr></thead>
<tbody>
<?php
$hasRows = false;
while($r = $res->fetch_assoc()) {
$hasRows = true;
?>
<tr>
<td><?php echo $r['id']; ?></td>
<td><?php echo esc($r['item_name'].' ('.$r['asset_tag'].')'); ?></td>
<td><?php echo esc($r['reported_by']); ?></td>
<td><?php echo esc($r['issue_type'].' — '.substr($r['description'],0,80)); ?></td>
<td>
<select class="form-select form-select-sm ticket-status" data-id="<?php echo $r['id']; ?>">
<option value="Pending" <?php if($r['status']==='Pending')echo 'selected';?>>Pending</option>
<option value="In Progress" <?php if($r['status']==='In Progress')echo 'selected';?>>In Progress</option>
<option value="Closed" <?php if($r['status']==='Closed')echo 'selected';?>>Closed</option>
</select>
</td>
<td>
<a class="btn btn-sm btn-primary" href="ticket_view.php?id=<?php echo $r['id']; ?>">View / Update</a>
<button class="btn btn-sm btn-outline-success ms-1 close-ticket" data-id="<?php echo $r['id']; ?>">Close</button>
</td>
</tr>
<?php }
// Export handling
if (isset($_POST['export_csv'])) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="tickets.csv"');
$out = fopen('php://output','w');
fputcsv($out, ['ID','Item','Reported By','Issue','Status']);
$csv_res = $mysqli->query('SELECT t.*, i.asset_tag, i.item_name, u.name as reported_by FROM tickets t LEFT JOIN items i ON t.item_id=i.id LEFT JOIN users u ON t.user_id=u.id ORDER BY t.created_at DESC');
while($r2 = $csv_res->fetch_assoc()) {
fputcsv($out, [$r2['id'], $r2['item_name'].' ('.$r2['asset_tag'].')', $r2['reported_by'], $r2['issue_type'].' — '.substr($r2['description'],0,80), $r2['status']]);
}
fclose($out);
exit;
}
if (!$hasRows) {
echo '<tr><td colspan="6" class="text-center">No tickets found.</td></tr>';
}
?>
</tbody>
</table>
<script>
document.querySelectorAll('.close-ticket').forEach(btn => {
btn.onclick = function() {
const id = btn.getAttribute('data-id');
fetch('<?php echo BASE_URL; ?>/api/ticket_action.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'id=' + id + '&action=close'
}).then(r => r.json()).then(data => { if(data.ok) location.reload(); });
};
});
document.querySelectorAll('.ticket-status').forEach(sel => {
sel.onchange = function() {
const id = sel.getAttribute('data-id');
const status = sel.value;
fetch('<?php echo BASE_URL; ?>/api/ticket_action.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'id=' + id + '&action=status&status=' + encodeURIComponent(status)
}).then(r => r.json()).then(data => { if(data.ok) location.reload(); });
};
});
</script>
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
<?php
$num_pages = ceil($total / $per_page);
for ($i = 1; $i <= $num_pages; $i++):
$active = ($i == $page) ? 'active' : '';
$params = $_GET;
$params['page'] = $i;
$url = '?' . http_build_query($params);
?>
<li class="page-item <?php echo $active; ?>"><a class="page-link" href="<?php echo $url; ?>"><?php echo $i; ?></a></li>
<?php endfor; ?>
</ul>
</nav>
</div>
<?php include __DIR__ . '/../inc/footer.php'; ?>