-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticket_detail.php
210 lines (170 loc) · 8.79 KB
/
ticket_detail.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!-- ticket_detail.php -->
<?php
session_start();
require 'db_connection.php';
if (!isset($_SESSION['user_id'])) {
header("Location: " . ($phpenable === 'true' ? $login_url . '.php' : $login_url));
exit;
}
if (!isset($_GET['ticket_id'])) {
header("Location: " . ($phpenable === 'true' ? $ticket_url . '.php' : $ticket_url));
exit;
}
$ticketId = $_GET['ticket_id'];
$userId = $_SESSION['user_id']; // Benutzer-ID aus der Sitzung holen
// Überprüfen, ob der Benutzer das Recht hat, das Ticket zu sehen
$sqlCheckUser = "SELECT id FROM tickets WHERE id = ? AND user_id = ?";
$stmtCheckUser = $conn->prepare($sqlCheckUser);
$stmtCheckUser->bind_param("ii", $ticketId, $userId);
$stmtCheckUser->execute();
$stmtCheckUser->store_result();
include 'settings/config.php';
include 'settings/head.php';
include 'settings/header.php';
if ($stmtCheckUser->num_rows <= 0) {
echo '<h1 class="text-center mt-5">Sie haben keine Berechtigung, dieses Ticket anzuzeigen.</h1>';
echo '<meta http-equiv="refresh" content="0;url=' . ($phpenable === 'true' ? $ticket_url . '.php' : $ticket_url) . '">';
exit;
}
$stmtCheckUser->close();
$sql = "SELECT subject, status, created_at FROM tickets WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $ticketId);
$stmt->execute();
$stmt->bind_result($subject, $status, $createdAt);
if ($stmt->fetch()) {
echo '<h1 class="text-center mt-5">' . $subject . '</h1>';
if ($status == "offen") {
$badgeClass = "bg-success xl";
$statusText = ($translations['ticket_detail']['status']['open']);
} elseif ($status == "geschlossen") {
$badgeClass = "bg-danger";
$statusText = ($translations['ticket_detail']['status']['closed']);
} elseif ($status == "bearbeitung") {
$badgeClass = "bg-warning";
$statusText = ($translations['ticket_detail']['status']['in_progress']);
} else {
$badgeClass = "bg-secondary";
$statusText = ($translations['ticket_detail']['status']['unknown']);
}
echo '<center><span class="badge badge-dot badge-lg"><i class="' . $badgeClass . '"></i>' . $statusText . '</span>';
$datetime = new DateTime($createdAt, new DateTimeZone('Europe/Berlin'));
$formattedDate = $datetime->format('d.m.Y H:i');
echo '<p>'. ($translations['ticket_detail']['created']) .' ' . $formattedDate . '</p>';
echo '<p>'. ($translations['ticket_detail']['ticket_id']) .' <strong>' . $ticketId . '</strong></p></center>';
echo '</div>';
} else {
echo '<h1 class="text-center mt-5">Ticket wurde nicht gefunden</h1>';
echo '<meta http-equiv="refresh" content="0;url=' . ($phpenable === 'true' ? $ticket_url . '.php' : $ticket_url) . '">';
exit;
}
$stmt->close();
?>
<title>
<?= str_replace('{websiteName}', $name, $translations['ticket_detail']['title']) ?>
</title>
<section class="pt-5 bg-section-secondary">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-9" style="max-width: 100%;">
<?php if (isset($_SESSION['success_message'])) { ?>
<div class="alert alert-success" role="alert">
<div class="alert-group-prepend">
<span class="alert-group-icon text-">
<i class="fa-solid fa-circle-check"></i>
</span>
<?php echo $_SESSION['success_message']; ?>
</div>
</div>
<?php unset($_SESSION['success_message']); // Lösche die Session-Variablen nach der Anzeige ?>
<?php } ?>
<?php if (isset($_SESSION['error_message'])) { ?>
<div class="alert alert-danger" role="alert">
<div class="alert-group-prepend">
<span class="alert-group-icon text-">
<i class="fa-solid fa-circle-exclamation"></i>
</span>
<?php echo $_SESSION['error_message']; ?>
</div>
</div>
<?php unset($_SESSION['error_message']); // Lösche die Session-Variablen nach der Anzeige ?>
<?php } ?>
<div class="card mb-n7 position-relative zindex-100">
<h2 class="text-center mt-5"> <?= ($translations['ticket_detail']['messages']) ?></h2>
<?php
if ($status != "geschlossen") {
// Antwortformular nur anzeigen, wenn das Ticket nicht geschlossen ist
echo '<form action="actions/add_reply.php" method="post">';
echo '<input type="hidden" name="ticket_id" value="' . $ticketId . '">';
echo '<div class="form-group">';
echo '<label for="reply_message">'. ($translations['ticket_detail']['answer']['field']) .'</label>';
echo '<textarea class="form-control" id="reply_message" name="reply_message" rows="4" resize="none" required placeholder="Guten Tag,"></textarea>';
echo '</div>';
echo '<button type="submit" class="btn btn-primary">'. ($translations['ticket_detail']['answer']['send']) .'</button>';
echo '</form>';
echo '<form action="actions/close_ticket.php" method="post">';
echo '<input type="hidden" name="ticket_id" value="' . $ticketId . '">';
echo '<button type="submit" class="btn btn-danger">'. ($translations['ticket_detail']['answer']['close']) .'</button>';
echo '</form>';
} else {
echo '<center><button class="btn btn-secondary btn-block" disabled>'. ($translations['ticket_detail']['closed']) .'</button></center>';
echo '<br>';
}
?>
<br>
<div class="table-responsive">
<tbody class="list">
<?php
$sql = "SELECT benutzer.name, message, created_at, team_reply FROM ticket_replies
INNER JOIN benutzer ON ticket_replies.user_id = benutzer.id
WHERE ticket_id = ?
ORDER BY created_at DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $ticketId);
$stmt->execute();
$stmt->bind_result($userName, $message, $replyCreatedAt, $teamReply);
$isNewMessage = true; // Annahme: Die erste Nachricht ist neu
while ($stmt->fetch()) {
echo '<div class="media media-comment">';
echo '<img alt="Image placeholder" class="rounded-circle shadow mr-4" src="../assets/img/user.png" style="width:58px">';
echo '<div class="media-body">';
echo '<div class="media-comment-bubble left-top">';
echo '<h6 class="mt-0">' . htmlspecialchars($userName) . ')';
echo '<p class="text-sm lh-160">' . nl2br(htmlspecialchars($message)) . '</p>';
echo '<div class="icon-actions">';
echo '<a>';
$replyDateTime = new DateTime($replyCreatedAt, new DateTimeZone('Europe/Berlin'));
$currentDateTime = new DateTime();
$interval = $currentDateTime->diff($replyDateTime);
echo '<span class="text-muted">' . $replyDateTime->format('d.m.Y H:i') . '</span>';
if ($isNewMessage) {
echo '<a>';
echo '<span class="badge badge-primary">'. ($translations['ticket_detail']['answer']['new']) .'</span>';
echo '</a>';
$isNewMessage = false;
}
if ($teamReply == 1) {
echo '<a>';
echo '<span class="badge badge-dark">'. ($translations['ticket_detail']['answer']['team']) .'</span>';
echo '</a>';
}
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div><hr>';
}
$stmt->close();
?>
</div>
</div>
<br>
</tbody>
</div>
</div>
</div>
</div>
</section>
<br><br><br><br>
<?php
include 'settings/footer.php';
?>