forked from hngi/Team-EOS-Chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat-page.php
More file actions
149 lines (130 loc) · 4.19 KB
/
chat-page.php
File metadata and controls
149 lines (130 loc) · 4.19 KB
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
<?php
include 'inc/dbh.php';
session_start();
$username = $_SESSION['user'];
if (!isset($username)) {
header("Location: index.html");
}
$check = "SELECT * FROM users WHERE user ='$username' LIMIT 1";
$checkResult = $conn->query($check);
while ($row = $checkResult->fetch_assoc()) {
$userId = $row['id'];
}
date_default_timezone_set('Africa/Lagos');
?>
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="images/logoD.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="css/main.css">
<title>EOS chat-page</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="chat-side">
<div class="chat-header">
<!-- <div class="header-title"> -->
<img src="images/logos-hipchat.svg" class="logo" width="15%">
<span class="logo-name">Buzz Donna</span>
<!-- </div> -->
</div>
<div class="chat-body">
<!-- Bot Greetings -->
<div class="chatbox right">
<div class="chatbox-inner">
<div class="chatbox-content">
Hey <?php echo $username; ?>, I will be your health provider today.<br>How may i help you?
</div>
</div>
</div>
<!-- User chats with bot -->
<div id="dropbox">
<!-- The messages/Chats will appear here -->
</div>
</div>
<div class="send">
<div class="form-group">
<div class="input-group">
<div id="error"></div>
<input type="text" class="form-control" id="question" placeholder="Talk to Donna, she is a masterpiece">
<input type="hidden" id="user" data-user="<?php echo $userId; ?>">
<div class="input-group-addon">
<button id="submit_message"><i class="fa fa-paper-plane"></i></button>
</div>
</div>
</div>
<!-- <button id="close_chat">Close Chat</i></button> -->
</div>
</div>
</div>
<div class="col-md-6 text-center second-panel">
<!-- <div class="col-md-8"> -->
<img src="images/logoD.png" class="logo" alt="donnas" width="50%">
<h3 class="name">Buzz Donna</h3>
<p class="description">The Fitness Guardian</p>
<!-- </div> -->
</div>
</div>
</div>
</body>
<!-- Chatbot App js requirement -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- <script type="text/javascript" src="js/chat.js"></script> -->
<script>
$(document).ready(function() {
displayChat(); // Displays the chat(s) immediately the page loads
// submit the user inputs
$("#submit_message").click(function(){
var question = $("#question").val();
var user = $("#user").data("user"); // get user ID
$.ajax({
url: "ajax.php",
type: "POST",
async: false,
data: {
"done": 1,
"userId" : user,
"question" : question
},
success: function(data){
displayChat();
$("#question").val('');
}
})
});
});
// This displays the chat
function displayChat() {
var userId = $("#user").data("user"); // get user ID
$.ajax({
url: "ajax.php",
type: "POST",
async: false,
data: {
"display": 1,
"userId" : userId
},
success: function(d){
//$(".bot-reply").hide();
//setTimeout(delayBotReply, 1000); // The bot reply will display after 1.5 secs
$("#dropbox").html(d);
}
});
}
// delay the bot reply function
// function delayBotReply() {
// $(".bot-reply").show();
// }
</script>
</html>