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: ticket_view.php

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

Size: 5.86 KB

Permissions: 0666

<?php
// Unified ticket view with comments and close logic
require_once __DIR__ . '/../inc/auth.php';
require_once __DIR__ . '/../functions.php';
require_login();
$u = current_user();
$ticket_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$ticket = $mysqli->query('SELECT t.*, u.name as reporter FROM tickets t LEFT JOIN users u ON t.user_id=u.id WHERE t.id=' . $ticket_id)->fetch_assoc();
if (!$ticket) die('Ticket not found');

// Handle add comment
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['comment'])) {
    verify_csrf();
    $comment = trim($_POST['comment']);
  if ($comment) {
    $stmt = $mysqli->prepare('INSERT INTO ticket_comments (ticket_id, user_id, comment) VALUES (?,?,?)');
    $stmt->bind_param('iis', $ticket_id, $_SESSION['user_id'], $comment);
    $stmt->execute();
    // Multi-level notification: ticket owner, TL, admin
    $agent_id = $ticket['user_id'];
  // Always use agent's team for TL notification
  $agent_row = $mysqli->query('SELECT team_id FROM users WHERE id=' . (int)$agent_id)->fetch_assoc();
  $team_id = $agent_row ? (int)$agent_row['team_id'] : 0;
    $msg = 'New comment on ticket #' . $ticket_id . ' by ' . esc($u['name']);
    $exclude = [$u['id']]; // don't notify self
  notify_team_and_admins($agent_id, $team_id, $msg, $exclude, $ticket_id);
  }
  header('Location: ticket_view.php?id=' . $ticket_id);
  exit;
}

// Handle close ticket
if (isset($_POST['close_ticket']) && $ticket['status'] !== 'Closed') {
    verify_csrf();
    // Only allow close by admin or ticket owner
  if ($u['role_slug'] === 'admin' || $u['id'] == $ticket['user_id']) {
    $mysqli->query('UPDATE tickets SET status="Closed" WHERE id=' . $ticket_id);
    // Multi-level notification: ticket owner, TL, admin
    $agent_id = $ticket['user_id'];
  // Always use agent's team for TL notification
  $agent_row = $mysqli->query('SELECT team_id FROM users WHERE id=' . (int)$agent_id)->fetch_assoc();
  $team_id = $agent_row ? (int)$agent_row['team_id'] : 0;
    $msg = 'Ticket #' . $ticket_id . ' has been closed.';
    $exclude = [$u['id']]; // don't notify self
  notify_team_and_admins($agent_id, $team_id, $msg, $exclude, $ticket_id);
    header('Location: ticket_view.php?id=' . $ticket_id);
    exit;
  }
}

// Fetch comments
$comments = $mysqli->query('SELECT c.*, u.name FROM ticket_comments c LEFT JOIN users u ON c.user_id=u.id WHERE c.ticket_id=' . $ticket_id . ' ORDER BY c.created_at ASC');

include __DIR__ . '/../inc/header.php';
include 'user_menu.php';
?>
<div class="container mt-4">
  <div class="card mb-3">
    <div class="card-body">
      <h5>Ticket #<?php echo $ticket['id']; ?> - <?php echo esc($ticket['item_name']); ?></h5>
      <p><strong>Reported by:</strong> <?php echo esc($ticket['reporter']); ?> | <strong>Status:</strong> <?php echo esc($ticket['status']); ?></p>
      <p><strong>Issue:</strong> <?php echo esc($ticket['issue_type']); ?></p>
      <p><strong>Description:</strong> <?php echo esc($ticket['description']); ?></p>
      <?php if (!empty($ticket['screenshot_path'])): ?>
        <p><strong>Screenshot:</strong><br>
          <img src="<?php echo BASE_URL; ?>/<?php echo esc($ticket['screenshot_path']); ?>" alt="Screenshot" style="max-width:320px;max-height:240px;border:1px solid #ccc;cursor:pointer;" onclick="showScreenshotModal()">
        </p>
        <!-- Screenshot Modal -->
        <div class="modal fade" id="screenshotModal" tabindex="-1" aria-labelledby="screenshotModalLabel" aria-hidden="true">
          <div class="modal-dialog modal-xl modal-dialog-centered">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="screenshotModalLabel">Screenshot</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>
              <div class="modal-body text-center" style="padding:0; background:#222; min-height:80vh;">
                <img src="<?php echo BASE_URL; ?>/<?php echo esc($ticket['screenshot_path']); ?>" alt="Screenshot" style="max-width:100%; max-height:78vh; border:1px solid #ccc; display:block; margin:auto;">
              </div>
            </div>
          </div>
        </div>
        <script>
          function showScreenshotModal() {
            var modal = new bootstrap.Modal(document.getElementById('screenshotModal'));
            modal.show();
          }
        </script>
      <?php endif; ?>
      <p><strong>Created:</strong> <?php echo esc($ticket['created_at']); ?></p>
      <?php if ($ticket['status'] !== 'Closed' && ($u['role_slug'] === 'admin' || $u['id'] == $ticket['user_id'])): ?>
        <form method="post" class="d-inline">
          <?php echo csrf_field(); ?>
          <button name="close_ticket" class="btn btn-danger btn-sm" onclick="return confirm('Close this ticket?')">Close Ticket</button>
        </form>
      <?php endif; ?>
    </div>
  </div>
  <div class="card mb-3">
    <div class="card-header">Comments</div>
    <div class="card-body">
      <?php while($c = $comments->fetch_assoc()): ?>
        <div class="mb-2">
          <strong><?php echo esc($c['name']); ?></strong> <span class="text-muted small">(<?php echo esc($c['created_at']); ?>)</span><br>
          <?php echo nl2br(esc($c['comment'])); ?>
        </div>
      <?php endwhile; ?>
      <?php if ($ticket['status'] !== 'Closed'): ?>
      <form method="post" class="mt-3">
        <?php echo csrf_field(); ?>
        <textarea name="comment" class="form-control mb-2" rows="2" required placeholder="Add a comment..."></textarea>
        <button class="btn btn-primary btn-sm">Add Comment</button>
      </form>
      <?php endif; ?>
    </div>
  </div>
  <a href="<?php echo BASE_URL; ?>/user/dashboard.php" class="btn btn-secondary">Back to Dashboard</a>
</div>
<?php include __DIR__ . '/../inc/footer.php'; ?>


← Back to Directory Edit File 🔒 Chmod

WP File Manager