-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathu_asynchChat.php
155 lines (113 loc) · 5.38 KB
/
u_asynchChat.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
#!/usr/local/bin/php
<?php
$host = "127.0.0.1";
$user = "root";
$password = "";
$db="login_it";
session_start();
$data=mysqli_connect($host,$user,$password,$db);
$username=$_SESSION['username'];
$sql="SELECT * FROM users WHERE username='".$username."'";
$result=mysqli_query($data,$sql);
$row=mysqli_fetch_array($result);
if($row["usertype"]=="employee"){
header("location:employeehome.php");
}
define('__HEADER_FOOTER_PHP__', true);
if(!isset($_SESSION["username"]))
{
header("location:login.php");
}
$data = mysqli_connect($host, $user, $password, $db);
//test when id=1
//MAKE SURE TO CHANGE THIS TO 'id'
$ticket_id = $_GET["id"];
$employeeid = $_GET["employeeid"];
//CITE: https://learnsql.com/cookbook/how-to-order-by-date-in-mysql/#:~:text=Use%20the%20ORDER%20BY%20keyword,shown%20last%2C%20etc.).
$sql_chats = "SELECT chats.id, chats.to_user, chats.from_user, chats.time, chats.body, chats.subject FROM chats WHERE chats.ticket_id='$ticket_id' ORDER BY chats.id DESC";
$result_chats = $data->query($sql_chats);
?>
<!--Users-->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
<title>Asynchronous Chat</title>
</head>
<body style="font-family: K2D; background-color: #e0f2f3">
<div class="jumbotron jumbotron-fluid text-center" style="margin-bottom:0; padding: 40px ;background-color: cadetblue; color: aliceblue">
<a style="text-decoration: none; color: aliceblue; font-size: xx-large " href="userhome.php">iTicket</a>
</div>
<nav class="navbar navbar-expand-sm justify-content-center" style=" background-color: #3f7778; color: #f0f8ff">
<ul class="navbar-nav">
<li class="nav-item" ><a class="nav-link" href="userhome.php" style="color: aliceblue; ">Home</a></li>
<li class="nav-item" ><a class="nav-link" href="ticketCreation.php" style="color: aliceblue; ">Create Ticket</a></li>
<li class="nav-item" ><a class="nav-link" href="user_dash.php" style="color: aliceblue; ">View History</a></li>
<li class="nav-item" ><a class="nav-link" href="u_livechat.php" style="color: aliceblue; ">Live Chat</a></li>
<li class="nav-item" ><a class="nav-link" href="logout.php" style="color: #98d8da; ">Logout <?php echo $_SESSION['username'] ?></a></li>
</ul>
</nav>
<div class="justify-content-center text-center" style="margin-top: 50px; color: #174142">
<!--
CITATIONS:
https://stackoverflow.com/questions/26924762/assigning-variables-to-sql-query-result
https://www.w3schools.com/php/func_mysqli_fetch_assoc.asp
https://stackoverflow.com/questions/4309950/how-to-align-input-forms-in-html
-->
<section class="container grey-text">
<h4 class="center">Chat with:<b> <?php echo $employeeid; ?></b></h4>
<p class="center">Regarding ticket ID: <b> <?php echo $ticket_id; ?> </b></p>
<br>
<form class="white" action="u_addChat.php?employeeid=<?php echo $employeeid; ?>&ticket_id=<?php echo $ticket_id; ?>" method="POST">
<label style="display: inline-block; width: 100px; text-align: right;">Subject</label>
<input type="text" name="subject">
<br><br>
<label style="display: inline-block; width: 100px; text-align: right;">Description</label>
<textarea type="text" name="body"></textarea>
<br>
<br>
<div class="center">
<input type="submit" name="submit" value="Submit" class="btn brand z-depth-0 rounded" style = "color: #3f7778;border: 2px solid #5e979a; display: inline-block; padding: 5px; ">
</div>
</form>
</section>
<br>
<hr style="width: 50%; margin: auto; background-color: #3f7778">
<br>
<!-- Fetch chat history from database, original code made from mixture of previous code in this repository -->
<h4>Chat History:</h4>
<?php
if ($result_chats->num_rows > 0) {
// Output data of each row
while ($row = $result_chats->fetch_assoc()) {
echo "
<table class='center w-75' style='border: 1px solid black; margin-left: auto;margin-right: auto;'
<tr>
<th style='border: 1px solid black; background-color: #88cacc' class='w-50'>To: " . $row["to_user"] . "</th>
<th style='border: 1px solid black; background-color: #88cacc' class='w-50'>From: " . $row["from_user"] . "</th>
</tr>
<tr>
<td colspan='2' style='border: 1px solid black;'> <b>Subject:</b> " . $row["subject"] . "</td>
</tr>
<tr>
<td colspan='2' style='border: 1px solid black;'>" . $row["body"] . "</td>
</tr>
</table>
<p style='font-size: 8pt'>" . $row["time"] . "</p>
<br>
";
}
} else {
echo "No chats found";
}
?>
</div>
<footer class="text-center" style="background-color: #3f7778; color: #F0F8FFFF; padding: 15px">
<p>© Debug Divas 2024</p>
<p>CEN3031 Final Project</p>
</footer>
</body>
</html>