-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
89 lines (77 loc) · 2.87 KB
/
view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
include 'functions.php';
// Connect to MySQL using the below function
$pdo = pdo_connect_mysql();
// Check if the ID param in the URL exists
if (!isset($_GET['id'])) {
exit('No ID specified!');
}
// MySQL query that selects the ticket by the ID column, using the ID GET request variable
$stmt = $pdo->prepare('SELECT * FROM tickets WHERE id = ?');
$stmt->execute([ $_GET['id'] ]);
$ticket = $stmt->fetch(PDO::FETCH_ASSOC);
// Check if ticket exists
if (!$ticket) {
exit('Invalid ticket ID!');
}
// Update status
if (isset($_GET['status']) && in_array($_GET['status'], array('open', 'closed', 'resolved'))) {
$stmt = $pdo->prepare('UPDATE tickets SET status = ? WHERE id = ?');
$stmt->execute([ $_GET['status'], $_GET['id'] ]);
header('Location: view.php?id=' . $_GET['id']);
exit;
}
// Check if the comment form has been submitted
if (isset($_POST['msg']) && !empty($_POST['msg'])) {
// Insert the new comment into the "tickets_comments" table
$stmt = $pdo->prepare('INSERT INTO tickets_comments (ticket_id, msg) VALUES (?, ?)');
$stmt->execute([ $_GET['id'], $_POST['msg'] ]);
header('Location: view.php?id=' . $_GET['id']);
exit;
}
$stmt = $pdo->prepare('SELECT * FROM tickets_comments WHERE ticket_id = ? ORDER BY created DESC');
$stmt->execute([ $_GET['id'] ]);
$comments = $stmt->fetchAll(PDO::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</title>
<!-- Link to your CSS stylesheet -->
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?=template_header('Ticket')?>
<div class="content view">
<h2><?=htmlspecialchars($ticket['title'], ENT_QUOTES)?> <span class="<?=$ticket['status']?>">(<?=$ticket['status']?>)</span></h2>
<div class="ticket">
<p class="created"><?=date('F dS, G:ia', strtotime($ticket['created']))?></p>
<p class="msg"><?=nl2br(htmlspecialchars($ticket['msg'], ENT_QUOTES))?></p>
</div>
<div class="btns">
<a href="view.php?id=<?=$_GET['id']?>&status=closed" class="btn red">Close</a>
<a href="view.php?id=<?=$_GET['id']?>&status=resolved" class="btn">Resolve</a>
</div>
<div class="comments">
<?php foreach($comments as $comment): ?>
<div class="comment">
<div>
<i class="fas fa-comment fa-2x"></i>
</div>
<p>
<span><?=date('F dS, G:ia', strtotime($comment['created']))?></span>
<?=nl2br(htmlspecialchars($comment['msg'], ENT_QUOTES))?>
</p>
</div>
<?php endforeach; ?>
<form action="" method="post">
<textarea name="msg" placeholder="Enter your comment..."></textarea>
<input type="submit" value="Post Comment">
</form>
</div>
</div>
<?=template_footer()?>
</body>
</html>