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

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


OR Upload from URL:
URL: Save as:

📄 File: dashboard.php

Path: /home2/outerorb/assetradar.outerorbittech.com/user/dashboard.php

Size: 9.99 KB

Permissions: 0666

<?php
require_once __DIR__ . '/../inc/auth.php';
require_login();
$u = current_user();
if ($u['role_slug'] === 'admin') header('Location: ' . BASE_URL . 'admin/dashboard.php');
if ($u['role_slug'] === 'tl') header('Location: ' . BASE_URL . 'tl/dashboard.php');
include __DIR__ . '/../inc/header.php';
include __DIR__ . '/user_menu.php';

// User queries
$items = $mysqli->query('SELECT i.* FROM items i WHERE i.assigned_to='.(int)$u['id']);
$tickets = $mysqli->query('SELECT * FROM tickets WHERE user_id='.(int)$u['id'].' ORDER BY created_at DESC');
// Recent tickets (last 5)
$recent_tickets = $mysqli->query("SELECT id, item_name, issue_type, status FROM tickets WHERE user_id=".(int)$u['id']." ORDER BY created_at DESC LIMIT 5");
// Items needing attention (damaged or warranty expiring soon)
$attention_items = $mysqli->query("SELECT id, asset_tag, item_name, condition_status, warranty_to AS warranty_expiry FROM items WHERE assigned_to=".(int)$u['id']." AND (condition_status='Damaged' OR (warranty_to IS NOT NULL AND warranty_to <= DATE_ADD(CURDATE(), INTERVAL 30 DAY))) ORDER BY warranty_to ASC LIMIT 5");

?>
<?php if (isset($_GET['success']) && $_GET['success'] == 1): ?>
  <div class="alert alert-success">Issue reported successfully!</div>
<?php endif; ?>

<div class="row g-3">
  <div class="col-md-6 mb-4">
    <div class="card p-3 card-hero h-100">
      <h6 class="mb-3">My Items</h6>
      <div class="mb-2 d-flex flex-wrap gap-2 align-items-center">
        <input type="text" id="searchInputItems" class="form-control w-auto" placeholder="Search..." style="max-width:200px;">
        <select id="conditionFilterItems" class="form-select w-auto" style="max-width:160px;">
          <option value="">All Conditions</option>
          <option value="Working">Working</option>
          <option value="Damaged">Damaged</option>
        </select>
      </div>
      <div class="table-responsive">
      <table class="table align-middle" id="userItemsTable">
          <thead><tr><th>Asset Tag</th><th>Name</th><th>Condition</th><th>Action</th></tr></thead>
          <tbody>
            <?php while($it = $items->fetch_assoc()): ?>
            <tr>
              <td><?php echo esc($it['asset_tag']); ?></td>
              <td><?php echo esc($it['item_name']); ?></td>
              <td><?php echo esc($it['condition_status']); ?></td>
              <td><a class="btn btn-sm btn-outline-danger w-100" href="<?php echo BASE_URL; ?>/user/report_issue.php?item_id=<?php echo $it['id']; ?>">Report Issue</a></td>
            </tr>
            <?php endwhile; ?>
          </tbody>
        </table>
      </div>
      <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center" id="itemsPagination"></ul>
      </nav>
      <script>
        // ...existing code...
      </script>
    </div>
  </div>
  <div class="col-md-6 mb-4">
    <div class="card p-3 h-100">
      <h6 class="mb-3">Items Needing Attention</h6>
      <table class="table table-sm mb-0">
        <thead><tr><th>Tag</th><th>Name</th><th>Status</th><th>Warranty Expiry</th></tr></thead>
        <tbody>
        <?php while($i = $attention_items->fetch_assoc()): ?>
          <tr>
            <td><?php echo esc($i['asset_tag']); ?></td>
            <td><?php echo esc($i['item_name']); ?></td>
            <td><?php echo esc($i['condition_status']); ?></td>
            <td><?php echo $i['warranty_expiry'] ? esc($i['warranty_expiry']) : '-'; ?></td>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>

<div class="row mt-4">
  <div class="col-md-8 mx-auto mb-4">
    <div class="card p-3">
      <h6 class="mb-3">Recent Tickets</h6>
      <table class="table table-sm mb-0">
        <thead><tr><th>ID</th><th>Item</th><th>Issue</th><th>Status</th></tr></thead>
        <tbody>
        <?php while($t = $recent_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><?php echo esc($t['status']); ?></td>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>

<div class="card p-3 card-hero mb-3">
  <div class="d-flex justify-content-between align-items-center">
    <h5>My 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>
  <div class="mb-2 d-flex flex-wrap gap-2 align-items-center">
    <input type="text" id="searchInputTickets" class="form-control w-auto" placeholder="Search..." style="max-width:200px;">
    <select id="statusFilterTickets" 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>
  <div class="table-responsive">
  <table class="table align-middle" id="userTicketsTable">
      <thead><tr><th>ID</th><th>Item</th><th>Issue</th><th>Status</th></tr></thead>
      <tbody>
        <?php
        if (isset($_POST['export_csv'])) {
          header('Content-Type: text/csv');
          header('Content-Disposition: attachment; filename="my_tickets.csv"');
          $out = fopen('php://output','w');
          fputcsv($out, ['ID','Item','Issue','Status']);
          $csv_res = $mysqli->query('SELECT * FROM tickets WHERE user_id='.(int)$u['id'].' ORDER BY created_at DESC');
          while($t = $csv_res->fetch_assoc()) {
            fputcsv($out, [$t['id'], $t['item_name'], $t['issue_type'], $t['status']]);
          }
          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><?php echo esc($t['status']); ?></td>
        </tr>
        <?php endwhile; ?>
      </tbody>
    </table>
  </div>
  <nav aria-label="Page navigation">
    <ul class="pagination justify-content-center" id="ticketsPagination"></ul>
  </nav>
  <script>
    // Simple client-side search, filter, and pagination for tickets
    const searchInput = document.getElementById('searchInputTickets');
    const statusFilter = document.getElementById('statusFilterTickets');
    const table = document.getElementById('userTicketsTable');
    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();
    // Simple client-side search and filter for tickets
    const searchInput = document.getElementById('searchInputTickets');
    const statusFilter = document.getElementById('statusFilterTickets');
    const table = document.getElementById('userTicketsTable');
    searchInput.addEventListener('input', filterTable);
    statusFilter.addEventListener('change', filterTable);
    function filterTable() {
      const search = searchInput.value.toLowerCase();
      const status = statusFilter.value;
      for (const row of table.tBodies[0].rows) {
        let txt = row.innerText.toLowerCase();
        let show = (!search || txt.includes(search));
        let statusVal = row.cells[3].innerText;
        if (status && statusVal !== status) show = false;
        row.style.display = show ? '' : 'none';
      }
    }
  </script>


<!-- Chart.js CDN -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

<div class="row mt-4">
  <div class="col-md-8 mx-auto mb-4">
    <div class="card p-3">
      <h6 class="mb-3">My Ticket Status</h6>
      <canvas id="userTicketChart" height="180"></canvas>
    </div>
  </div>
</div>

<script>
// User ticket status chart
fetch('my_tickets.php?chart_status=1')
  .then(res => res.json())
  .then(data => {
    new Chart(document.getElementById('userTicketChart'), {
      type: 'doughnut',
      data: {
        labels: data.labels,
        datasets: [{
          data: data.counts,
          backgroundColor: ['#4f46e5', '#10b981', '#ef4444', '#f59e42'],
          borderWidth: 1
        }]
      },
      options: {
        responsive: true,
        plugins: { legend: { position: 'bottom' } }
      }
    });
  });
</script>

<?php include __DIR__ . '/../inc/footer.php'; ?>

← Back to Directory Edit File 🔒 Chmod

WP File Manager