-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.php
186 lines (162 loc) · 5.57 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
<?php
session_start();
if(!isset($_SESSION['id'])){
header("location: login.php");
}
require "database/connection.php";
if(isset($_SESSION['id'])){
$id = $_SESSION['id'];
}
//date_default_timezone_set('Africa/Lagos');
$sql = "SELECT * FROM users WHERE user_id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $id);
if($stmt->execute()){
$result = $stmt->get_result();
if($result->num_rows > 0){
$row = $result->fetch_assoc();
}
}
$rm_sql = "SELECT * FROM users WHERE user_id=? AND (department='' OR school='' OR faculty='')";
$rm_stmt = $conn->prepare($rm_sql);
$rm_stmt->bind_param('s', $id);
if($rm_stmt->execute()){
$rm_result = $rm_stmt->get_result();
if($rm_result->num_rows > 0){
echo "<script>location.href = 'verify-email.php';</script>";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta content="" name="description">
<meta content="" name="keywords">
<!-- Favicons -->
<link href="./assets/img/easylearn/logo4.png" rel="icon">
<link href="./assets/img/easylearn/logo4.png" rel="apple-touch-icon">
<title>EazyLearn</title>
<link rel="stylesheet" href="vendors/bootstrap-3.3.7-dist/css/bootstrap.css">
<link rel="stylesheet" href="vendors/bootstrap-icons/bootstrap-icons.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/query.css">
<link rel="stylesheet" href="./assets/css/sweetalert.css">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,600;1,700&family=Roboto:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Work+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
</head>
<body>
<style>
p{
font-size: 1.4rem;
}
.chat-box{
position: fixed;
left: 0;
right: 0;
bottom: 10;
}
header{
align-items: center;
}
</style>
<?php
$incoming_id = $_SESSION['id'];
if(isset($_GET['id'])){
$outgoing_id = $_GET['id'];
}
$sql = "SELECT * FROM users WHERE user_id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $outgoing_id);
if($stmt->execute()){
$result = $stmt->get_result();
if($result->num_rows > 0){
$rows = $result->fetch_assoc();
}
}
?>
<section class="container-fluid index-wrapper">
<header class="d-flex-sb" style="padding-bottom: 2.5rem;">
<a href="javascript:history.back()"><i class="bi bi-arrow-left"></i></a>
<img src="uploads/<?= $rows['image']; ?>">
<h3><a href="friends-profile.html"><?= $rows['lastname'] .' '. $rows['firstname']; ?></a></h3>
<i class="bi bi-three-dots-vertical notifications"></i>
</header>
<div class="chat-wrapper" style="margin-top: 2rem;">
<div class="chats" style="overflow-y: auto;">
</div>
<form id="chat_form">
<div class="say-something chat-box">
<div class="add-icon">
<i class="bi bi-plus-lg"></i>
</div>
<div class="write-something cb-ws">
<input type="text" class="form-control" id="message" placeholder="Enter a message">
<input type="hidden" class="form-control" id="outgoing_id" value="<?= $outgoing_id; ?>">
<input type="hidden" class="form-control" id="incoming_id" value="<?= $incoming_id; ?>">
</div>
<div class="add-emoji cb">
<i class="bi bi-emoji-smile"></i>
<i id="chat_btn" class="bi bi-send cb-send"></i>
</div>
</div>
</form>
</div>
</section>
<?php require "includes/dashboard-footer.php"; ?>
<script>
$(document).ready(function(){
var outgoing_id = $('#outgoing_id').val();
var incoming_id = $('#incoming_id').val();
var message = $('#message').val();
fetch_student_chat();
setInterval(function(){
fetch_student_chat();
}, 1000);
function fetch_student_chat(){
$.ajax({
url: "backend/fetch-chat.php",
type: "POST",
data:
{
outgoing_id: outgoing_id,
incoming_id: incoming_id,
message:message
},
success:function(data){
$('.chats').html(data);
}
});
}
$(document).on('click', '#chat_btn', function(e){
e.preventDefault();
var outgoing_id = $('#outgoing_id').val();
var incoming_id = $('#incoming_id').val();
var message = $('#message').val();
if(message == ""){
Swal.fire(
'Invalid',
'Enter a message',
'error'
)
}
else{
$.ajax({
url: 'backend/get-chat.php',
type: 'post',
data:
{
outgoing_id: outgoing_id,
incoming_id: incoming_id,
message:message,
},
success: function(data){
$('.chats').html(data);
}
});
$('#chat_form')[0].reset();
}
});
});
</script>