Files
tinker_tickets/ticket.php

197 lines
9.1 KiB
PHP
Raw Normal View History

2024-11-30 19:48:01 -05:00
<?php
// Load environment variables and DB connection (same as dashboard.php)
$envFile = __DIR__ . "/.env";
$envVars = parse_ini_file($envFile);
$conn = new mysqli(
$envVars["REACT_APP_DB_HOST"],
$envVars["REACT_APP_DB_USER"],
$envVars["REACT_APP_DB_PASS"],
$envVars["REACT_APP_DB_NAME"]
);
$ticket_id = $_GET["id"];
$sql = "SELECT * FROM tickets WHERE ticket_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $ticket_id);
$stmt->execute();
$result = $stmt->get_result();
$ticket = $result->fetch_assoc();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ticket #<?php echo $ticket_id; ?></title>
<link rel="icon" type="image/png" href="assets/images/favicon.png">
<link rel="stylesheet" href="assets/css/dashboard.css">
<link rel="stylesheet" href="assets/css/ticket.css">
<script src="assets/js/dashboard.js"></script>
<script src="assets/js/ticket.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</head>
<body>
<div class="ticket-container" data-priority="<?php echo $ticket[
"priority"
]; ?>">
<div class="ticket-header">
<h2><input type="text" class="editable title-input" value="<?php echo $ticket[
"title"
]; ?>" data-field="title" disabled></h2>
<div class="ticket-subheader">
<div class="ticket-id">UUID <?php echo $ticket_id; ?></div>
<div class="header-controls">
<div class="status-priority-group">
<span id="statusDisplay" class="status-<?php echo $ticket[
"status"
]; ?>"><?php echo $ticket["status"]; ?></span>
<span class="priority-indicator priority-<?php echo $ticket[
"priority"
]; ?>">P<?php echo $ticket["priority"]; ?></span>
</div>
<button id="editButton" class="btn" onclick="toggleEditMode()">Edit Ticket</button>
</div>
</div>
</div>
<div class="ticket-details">
<div class="detail-group status-priority-row">
<div class="detail-quarter">
<label>Status</label>
<select class="editable" data-field="status" disabled>
<option value="Open" <?php echo $ticket["status"] == "Open"
? "selected"
: ""; ?>>Open</option>
<option value="Closed" <?php echo $ticket["status"] ==
"Closed"
? "selected"
: ""; ?>>Closed</option>
</select>
</div>
<div class="detail-quarter">
<label>Priority</label>
<select class="editable" data-field="priority" disabled>
<option value="1" <?php echo $ticket["priority"] == 1
? "selected"
: ""; ?>>P1 - Critical Impact</option>
<option value="2" <?php echo $ticket["priority"] == 2
? "selected"
: ""; ?>>P2 - High Impact</option>
<option value="3" <?php echo $ticket["priority"] == 3
? "selected"
: ""; ?>>P3 - Medium Impact</option>
<option value="4" <?php echo $ticket["priority"] == 4
? "selected"
: ""; ?>>P4 - Low Impact</option>
</select>
</div>
<div class="detail-quarter">
<label>Category</label>
<select class="editable" data-field="category" disabled>
<option value="Hardware" <?php echo $ticket["category"] ==
"Hardware"
? "selected"
: ""; ?>>Hardware</option>
<option value="Software" <?php echo $ticket["category"] ==
"Software"
? "selected"
: ""; ?>>Software</option>
<option value="Network" <?php echo $ticket["category"] ==
"Network"
? "selected"
: ""; ?>>Network</option>
<option value="Security" <?php echo $ticket["category"] ==
"Security"
? "selected"
: ""; ?>>Security</option>
<option value="Other" <?php echo $ticket["category"] ==
"Other"
? "selected"
: ""; ?>>Other</option>
</select>
</div>
<div class="detail-quarter">
<label>Type</label>
<select class="editable" data-field="type" disabled>
<option value="Maintenance" <?php echo $ticket["type"] == "Maintenance" ? "selected" : ""; ?>>Maintenance</option>
<option value="Install" <?php echo $ticket["type"] == "Install" ? "selected" : ""; ?>>Install</option>
<option value="Task" <?php echo $ticket["type"] == "Task" ? "selected" : ""; ?>>Task</option>
<option value="Upgrade" <?php echo $ticket["type"] == "Upgrade" ? "selected" : ""; ?>>Upgrade</option>
</select>
</div>
</div>
<div class="ticket-tabs">
<button class="tab-btn active" onclick="showTab('description')">Description</button>
<button class="tab-btn" onclick="showTab('comments')">Comments</button>
</div>
<div id="description-tab" class="tab-content active">
<div class="detail-group full-width">
<label>Description</label>
<textarea class="editable" data-field="description" disabled><?php echo $ticket[
"description"
]; ?></textarea>
</div>
</div>
<div id="comments-tab" class="tab-content">
<div class="comments-section">
<h2>Comments</h2>
<div class="comment-form">
<textarea id="newComment" placeholder="Add a comment..."></textarea>
<div class="comment-controls">
<div class="markdown-toggles">
<div class="preview-toggle">
<label class="switch">
<input type="checkbox" id="markdownMaster" onchange="toggleMarkdownMode()">
<span class="slider round"></span>
</label>
<span class="toggle-label">Enable Markdown</span>
</div>
<div class="preview-toggle">
<label class="switch">
<input type="checkbox" id="markdownToggle" onchange="togglePreview()" disabled>
<span class="slider round"></span>
</label>
<span class="toggle-label">Preview Markdown</span>
</div>
</div>
<button onclick="addComment()" class="btn">Add Comment</button>
</div>
<div id="markdownPreview" class="markdown-preview" style="display: none;"></div>
</div>
</div>
<div class="comments-list">
<?php
$commentsSql = "SELECT * FROM ticket_comments WHERE ticket_id = ? ORDER BY created_at DESC";
$stmt = $conn->prepare($commentsSql);
$stmt->bind_param("s", $ticket_id);
$stmt->execute();
$comments = $stmt->get_result();
while($comment = $comments->fetch_assoc()) {
echo "<div class='comment'>";
echo "<div class='comment-header'>";
echo "<span class='comment-user'>{$comment['user_name']}</span>";
echo "<span class='comment-date'>" . date('M d, Y H:i', strtotime($comment['created_at'])) . "</span>";
echo "</div>";
echo "<div class='comment-text'>";
if ($comment['markdown_enabled']) {
echo "<script>document.write(marked.parse(" . json_encode($comment['comment_text']) . "))</script>";
} else {
echo htmlspecialchars($comment['comment_text']);
}
echo "</div>";
echo "</div>";
}
?>
</div>
</div>
</div>
<div class="ticket-footer">
<button onclick="window.location.href='dashboard.php'" class="btn back-btn">Back to Dashboard</button>
</div>
</div>
</body>
</html>