-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.php
204 lines (191 loc) · 6.67 KB
/
chat.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
<?php
include 'includes/header.php';
include('database_connection.php');
$user_id = $_SESSION['id'];
if (isset($_POST["Send"])) {
try {
$statement = $connect->prepare("
INSERT INTO `chat`(
`user_id`,
`message`
)
VALUES(
:user_id,
:message
);
");
$statement->execute(
array(
':user_id' => trim($user_id),
':message' => trim($_POST["message"])
)
);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
if (isset($_GET["delete"]) && $_GET["delete"] == 1) {
if ($_SESSION["User_type"] == "Admin") {
$statement = $connect->prepare(
"DELETE FROM chat"
);
$statement->execute();
echo '
<script>
alert("Message deleted sucessfully!");
window.top.location = "chat.php";
</script>
';
} else {
?>
<script>
alert("You are not allowed to delete 😡!");
window.top.location = "chat.php";
</script>
<?php
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Swipe – The Simplest Chat Platform</title>
<meta name="description" content="#">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Swipe core CSS -->
<link href="css/swipe.min.css" type="text/css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<!-- Favicon -->
<link href="img/favicon.png" type="image/png" rel="icon">
</head>
<body>
<main>
<div class="layout">
<div class="main">
<div class="tab-content" id="nav-tabContent">
<!-- Start of Babble -->
<div class="babble tab-pane fade active show" id="list-chat" role="tabpanel" aria-labelledby="list-chat-list">
<!-- Start of Chat -->
<div class="chat" id="chat1">
<div class="top">
<div class="container">
<div class="col-md-12">
<div class="inside">
<a href="#"><img class="avatar-md" src="img/avatars/avatar-female-5.jpg" data-toggle="tooltip" data-placement="top" title="Keith" alt="avatar"></a>
<div class="status">
<i class="material-icons online">fiber_manual_record</i>
</div>
<div class="data">
<h5><a href="#">Group Chat</a></h5>
</div>
<div class="dropdown">
<button class="btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="material-icons md-30">more_vert</i></button>
<div class="dropdown-menu dropdown-menu-right">
<a href="profile.php"><button class="dropdown-item info"><i class="material-icons">info</i>Account Info</button></a>
<?php
include_once 'header.php';
if ($_SESSION["User_type"] == "Admin") {
?>
<a href="chat.php?delete=1"><button class="dropdown-item delete"><i class="material-icons">delete</i>Delete History</button></a>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="content" id="content">
<div class="container">
<div class="col-md-12" id="msg-list"></div>
</div>
</div>
<script>
var chat = {};
$(document).ready(function() {
scrollToBottom(document.getElementById('content'));
chat.fetchMessage = function() {
scrollToBottom(document.getElementById('content'));
$.ajax({
url: "load.php",
method: "POST",
success: function(data) {
$('#msg-list').html(data);
}
});
scrollToBottom(document.getElementById('content'));
};
chat.interval = setInterval(chat.fetchMessage, 3000);
chat.fetchMessage();
scrollToBottom(document.getElementById('content'));
});
</script>
<div class="container">
<div class="col-md-12">
<div class="bottom">
<form method="post" id="message_form" class="position-relative w-100">
<textarea name="message" id="message" class="form-control" placeholder="Start typing for reply..." rows="1"></textarea>
<button class="btn emoticons"><i class="material-icons">insert_emoticon</i></button>
<button type="submit" id="Send" name="Send" class="btn send"><i class="material-icons">send</i></button>
</form>
<label>
<a href="index.php"><span class="btn attach d-sm-block d-none"><i class="material-icons">home</i></span></a>
</label>
</div>
<script>
$(document).ready(function() {
$('#Send').click(function() {
$('#message_form').submit();
scrollToBottom(document.getElementById('content'));
});
});
</script>
</div>
</div>
</div>
<!-- End of Chat -->
</div>
<!-- End of Babble -->
<!-- Start of Babble -->
<div class="babble tab-pane fade" id="list-empty" role="tabpanel" aria-labelledby="list-empty-list">
<!-- Start of Chat -->
<div class="chat" id="chat2">
<div class="container">
<div class="col-md-12">
<div class="bottom">
<form class="position-relative w-100">
<textarea class="form-control" placeholder="Start typing for reply..." rows="1" autofocus="autofocus" onfocus="this.select()"></textarea>
<button class="btn emoticons"><i class="material-icons">insert_emoticon</i></button>
<button type="submit" class="btn send"><i class="material-icons">send</i></button>
</form>
<label>
<input type="file">
<span class="btn attach d-sm-block d-none"><i class="material-icons">attach_file</i></span>
</label>
</div>
</div>
</div>
</div>
<!-- End of Chat -->
</div>
</div>
</div> <!-- Layout -->
</main>
<!-- Bootstrap/Swipe core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/popper.min.js"></script>
<script src="js/swipe.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script>
function scrollToBottom(el) {
el.scrollTop = el.scrollHeight;
}
scrollToBottom(document.getElementById('content'));
</script>
</body>
</html>