-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshow-ticket.php
161 lines (154 loc) · 5.85 KB
/
show-ticket.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
<?php
session_start();
require "config/config.php";
if (!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true) {
header("location: login.php?redirect_link=show-ticket.php");
exit;
}
if (!isset($_GET['id'])) {
header('Location: index.php');
exit();
} else {
$id = $_GET['id'];
$queryString = "SELECT * FROM tickets WHERE id=$id";
$result = mysqli_query($link, $queryString);
$row = mysqli_fetch_assoc($result);
$ticketid = $row['id'];
$created_at = $row['created_at'];
$text = $row['text'];
$user_id = $row['userid'];
$closed = $row['closed'];
$sql = "SELECT * FROM users WHERE id=$user_id";
$newResult = mysqli_query($link, $sql);
$newRow = mysqli_fetch_assoc($newResult);
$ticket_username = $newRow['username'];
$email = $newRow['email'];
}
$err_message = "";
if (!empty($_GET['err_message'])) {
$err_message = $_GET['err_message'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height">
<title>Tickets</title>
<link rel="shortcut icon" href="logos/logo.png" type="image/x-icon">
<link rel="stylesheet" href="css/showTicket.css?v=<?php echo time(); ?>">
</head>
<body>
<?php require_once("header.php"); ?>
<div style="margin: 20px;">
<h2 id="err_message"><?php echo $err_message; ?></h2>
<div class="main-div">
<?php
if ($_SESSION['admin'] == 0 && $_SESSION['id'] != $user_id) {
echo '<span class="user-error">You don\'t have access!</span>';
return;
} else {
echo "<div class='secondary-div'>";
?>
<div class='ticket-info'>
<h1>Ticket #<?php echo $ticketid; ?></h1>
<?php
if ($closed == 0) {
echo "
<div id='opened'>
<span>Opened</span>
</div>
";
} else {
echo "
<div id='opened' style='background-color: #874c57;'>
<span>Closed</span>
</div>
";
}
?>
</div>
<div class="text">
<div><span style="color:white; font-weight: bold; font-style: italic;"><?php echo $text ?></span><br></div>
<div><span style="color:white">Email: <?php echo $email ?></span><br></div>
<div><span style="color:white">Username: <a href="profile.php?id=<?php echo $user_id ?>"><?php echo $ticket_username ?></a></span><br></div>
<div><span style="color:white">User ID: <?php echo $user_id; ?></span><br></div>
</div>
<?php
if ($closed == 0) {
echo '
<form action="actions.php?action=send_ticket_message" method="post" id="form">
<textarea type="text" name="message" class="user-input" placeholder="Reply as '.$_SESSION["username"].'..." autofocus></textarea>
<input type="text" name="text" id="text" value="'.$ticketid.'" style="display: none">
<input type="submit" class="user-button" value="Reply">
</form>
';
}
if ($_SESSION['admin'] == 1) {
if ($closed == 0) {
echo "<p><a href='actions.php?action=close_ticket&id=$ticketid' style='text-decoration: none'>Close Ticket</a></p>";
} else {
echo "<br><p><a href='actions.php?action=open_ticket&id=$ticketid' style='text-decoration: none'>Open Ticket</a> <span style='color: white; font-style: italic; text-decoration: underline;'>You can't add comments until someone opens the ticket!</span></p>";
}
} else {
if ($closed == 1) {
echo "<br><p style='color: white; font-style: italic; text-decoration: underline;'>You can't add comments until someone opens the ticket!</p>";
}
}
?>
<h3>Comments:</h3>
<div style="display: flex; flex-direction: column-reverse;">
<?php
$sql = "SELECT * FROM `comments` WHERE forTicket=$id";
$querys = mysqli_query($link, $sql);
if (mysqli_num_rows($querys) > 0) {
while ($row = mysqli_fetch_assoc($querys)) {
$comment_user_id = $row['userid'];
$text = $row['text'];
$created_at = $row['created_at'];
$sql = "SELECT * FROM users WHERE id=$comment_user_id";
$newResult = mysqli_query($link, $sql);
$newRow = mysqli_fetch_assoc($newResult);
$comment_username = $newRow['username'];
$comment_admin = $newRow['admin'];
$comment_file = $newRow['file'];
echo "
<div id='comment'>
<div id='name'>
<img src='$comment_file' alt='Profile Picture' id='profilePicture'>
<span style='margin-top: 7px; margin-left: 10px; color: white;'><b><a href='profile.php?id=$comment_user_id'>$comment_username</a></b>
";
if ($comment_admin == 1) {
echo "*technical support*";
}
echo "
</span>
</div>
<div id='message'>
<span style='white-space: pre-wrap;'>$text</span>
</div>
<small style='float: right; color: white; font-style: italic; text-shadow: 1px 1px 1px white;'>$created_at</small>
</div>";
}
} else {
echo "<div id='comment'><p style='color: white;'>No Comments.</p></div>";
}
echo "
</div>
<p id='data-sended'>The ticket was created at: $created_at</p>
";
}
?>
</div>
</div>
<script>
setTimeout(() => {
let p = document.getElementById("err_message");
if (p.innerHTML != "") {
p.innerHTML = "";
}
}, 5000);
</script>
</body>
</html>