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/tl/

📁 Create New:
⬆️ Upload File:
Current Dir [ Writable ] Root [ Writable ]


OR Upload from URL:
URL: Save as:

📄 File: team_tickets.php

Path: /home2/outerorb/assetradar.outerorbittech.com/tl/team_tickets.php

Size: 6.6 KB

Permissions: 0666

<?php
// Chart status API for dashboard chart
if (isset($_GET['chart_status']) && $_GET['chart_status'] == '1') {
  require_once __DIR__ . '/../inc/auth.php';
  require_login();
  $u = current_user();
  header('Content-Type: application/json');
  $statuses = [];
  $counts = [];
  $team_id = (int)$u['team_id'];
  $res = $mysqli->query("SELECT status, COUNT(*) as c FROM tickets WHERE user_id IN (SELECT id FROM users WHERE team_id=$team_id) GROUP BY status");
  while($row = $res->fetch_assoc()) {
    $statuses[] = $row['status'];
    $counts[] = (int)$row['c'];
  }
  echo json_encode(['labels' => $statuses, 'counts' => $counts]);
  exit;
}
require_once __DIR__ . '/../inc/auth.php';
require_login();
$u = current_user();
require_tl();
include __DIR__ . '/../inc/header.php';
include __DIR__ . '/tl_menu.php';
$team_id = (int)$u['team_id'];
$tickets = $mysqli->query('SELECT t.*, u.name as reporter FROM tickets t JOIN users u ON t.user_id=u.id WHERE u.team_id=' . $team_id . ' ORDER BY t.created_at DESC');
?>
<div class="container mt-4">
  <div class="d-flex justify-content-between align-items-center">
    <h4>Team Tickets</h4>
    <form method="post" style="margin:0;">
      <button type="submit" name="export_csv" class="btn btn-outline-success btn-sm">Export CSV</button>
    </form>
  </div>
  <div class="mb-2 d-flex flex-wrap gap-2 align-items-center">
    <input type="text" id="searchInput" class="form-control w-auto" placeholder="Search..." style="max-width:200px;">
    <select id="statusFilter" class="form-select w-auto" style="max-width:160px;">
      <option value="">All Statuses</option>
      <option value="Pending">Pending</option>
      <option value="Closed">Closed</option>
      <option value="In Progress">In Progress</option>
    </select>
  </div>
  <table class="table" id="teamTicketsTable">
    <thead><tr><th>ID</th><th>Item</th><th>Issue</th><th>Status</th><th>Reported By</th></tr></thead>
    <tbody>
      <?php
      if (isset($_POST['export_csv'])) {
        header('Content-Type: text/csv');
        header('Content-Disposition: attachment; filename="team_tickets.csv"');
        $out = fopen('php://output','w');
        fputcsv($out, ['ID','Item','Issue','Status','Reported By']);
        $csv_res = $mysqli->query('SELECT t.*, u.name as reporter FROM tickets t JOIN users u ON t.user_id=u.id WHERE u.team_id=' . (int)$team_id . ' ORDER BY t.created_at DESC');
        while($t = $csv_res->fetch_assoc()) {
          fputcsv($out, [$t['id'], $t['item_name'], $t['issue_type'], $t['status'], $t['reporter']]);
        }
        fclose($out);
        exit;
      }
      ?>
      <?php while($t = $tickets->fetch_assoc()): ?>
      <tr>
  <td><a href="ticket_view.php?id=<?php echo $t['id']; ?>" class="btn btn-link btn-sm">#<?php echo $t['id']; ?></a></td>
        <td><?php echo esc($t['item_name']); ?></td>
        <td><?php echo esc($t['issue_type']); ?></td>
        <td>
          <select class="form-select form-select-sm ticket-status" data-id="<?php echo $t['id']; ?>">
            <option value="Pending" <?php if($t['status']==='Pending')echo 'selected';?>>Pending</option>
            <option value="In Progress" <?php if($t['status']==='In Progress')echo 'selected';?>>In Progress</option>
            <option value="Closed" <?php if($t['status']==='Closed')echo 'selected';?>>Closed</option>
          </select>
        </td>
        <td><?php echo esc($t['reporter']); ?></td>
        <td>
          <button class="btn btn-sm btn-outline-success close-ticket" data-id="<?php echo $t['id']; ?>">Close</button>
        </td>
      </tr>
      <?php endwhile; ?>
    </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" id="ticketsPagination"></ul>
  </nav>
  <script>
    // Simple client-side search, filter, and pagination
    const searchInput = document.getElementById('searchInput');
    const statusFilter = document.getElementById('statusFilter');
    const table = document.getElementById('teamTicketsTable');
    const pagination = document.getElementById('ticketsPagination');
    const rows = Array.from(table.tBodies[0].rows);
    const perPage = 10;
    let currentPage = 1;
    searchInput.addEventListener('input', updateTable);
    statusFilter.addEventListener('change', updateTable);
    function updateTable() {
      const search = searchInput.value.toLowerCase();
      const status = statusFilter.value;
      let filtered = rows.filter(row => {
        let txt = row.innerText.toLowerCase();
        let statusVal = row.cells[3].innerText;
        let show = (!search || txt.includes(search));
        if (status && statusVal !== status) show = false;
        return show;
      });
      // Pagination
      let totalPages = Math.ceil(filtered.length / perPage);
      if (currentPage > totalPages) currentPage = 1;
      rows.forEach(r => r.style.display = 'none');
      filtered.slice((currentPage-1)*perPage, currentPage*perPage).forEach(r => r.style.display = '');
      // Render pagination
      pagination.innerHTML = '';
      for (let i=1; i<=totalPages; i++) {
        let li = document.createElement('li');
        li.className = 'page-item' + (i===currentPage?' active':'');
        let a = document.createElement('a');
        a.className = 'page-link';
        a.href = '#';
        a.textContent = i;
        a.onclick = (e) => { e.preventDefault(); currentPage=i; updateTable(); };
        li.appendChild(a);
        pagination.appendChild(li);
      }
    }
    updateTable();
  </script>
</div>
<?php include __DIR__ . '/../inc/footer.php'; ?>


← Back to Directory Edit File 🔒 Chmod

WP File Manager