-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomepage.php
More file actions
144 lines (129 loc) · 5.18 KB
/
homepage.php
File metadata and controls
144 lines (129 loc) · 5.18 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
<?php
date_default_timezone_set('Asia/Dhaka');
require_once 'dbconfig/config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<br>
<br>
<br>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<title>Aresa Chatbot</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link href="style.css" rel="stylesheet">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</head>
<style>
body
{
background-image: url('https://png.pngtree.com/thumb_back/fw800/background/20190223/ourmid/pngtree-smart-robot-arm-advertising-background-backgroundrobotblue-backgrounddark-backgroundlightlight-image_68405.jpg' );
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
</style>
<body>
<div class="container">
<div class="row justify-content-md-center mb-8">
<div class="col-md-8">
<form class="myform" action="homepage.php" method="post">
<input name="logout" type="submit" id="logout_btn" value="Log Out"/><br>
</form>
<?php
if(isset($_POST['logout']))
{
session_destroy();
header('location:index.php');
}
?>
<!--start code-->
<div class="card">
<div class="card-body messages-box">
<ul class="list-unstyled messages-list">
<?php
$sql = "SELECT * FROM message";
$stmt = $db->prepare($sql);
$stmt->execute();
if($stmt->rowCount()>0){
$content='';
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$message = $row['message'];
$added_on = $row['added_on'];
$strtotime = strtotime($added_on);
$time = date('h:i A',$strtotime);
$type = $row['type'];
if($type == 'user'){
$class = "messages-me";
$imgAvatar = "user_avatar.png";
$name = "Me";
}else{
$class="messages-you";
$imgAvatar="bot_avatar.png";
$name="Chatbot";
}
$content .= '<li class="'.$class.' clearfix"><span class="message-img"><img src="image/'.$imgAvatar.'" class="avatar-sm rounded-circle"></span><div class="message-body clearfix"><div class="message-header"><strong class="messages-title">'.$name.'</strong> <small class="time-messages text-muted"><span class="fas fa-time"></span> <span class="minutes">'.$time.'</span></small> </div><p class="messages-p">'.$message.'</p></div></li>';
}
//echo $html;
}else{
?>
<li class="messages-me clearfix start_chat">
Please start
</li>
<?php
}
$stmt->closeCursor();
?>
</ul>
</div>
<div class="card-header">
<div class="input-group">
<input id="input-me" type="text" name="messages" class="form-control input-sm" placeholder="Type your message here..." />
<span class="input-group-append">
<input type="button" class="btn btn-primary" value="Send" onclick="send_msg()">
</span>
</div>
</div>
</div>
<!--end code-->
</div>
</div>
</div>
<script type="text/javascript">
function getCurrentTime(){
var now = new Date();
var hh = now.getHours();
var min = now.getMinutes();
var ampm = (hh>=12)?'PM':'AM';
hh = hh%12;
hh = hh?hh:12;
hh = hh<10?'0'+hh:hh;
min = min<10?'0'+min:min;
var time = hh+":"+min+" "+ampm;
return time;
}
function send_msg(){
jQuery('.start_chat').hide();
var txt=jQuery('#input-me').val();
var html='<li class="messages-me clearfix"><span class="message-img"><img src="image/user_avatar.png" class="avatar-sm rounded-circle"></span><div class="message-body clearfix"><div class="message-header"><strong class="messages-title">Me</strong> <small class="time-messages text-muted"><span class="fas fa-time"></span> <span class="minutes">'+getCurrentTime()+'</span></small> </div><p class="messages-p">'+txt+'</p></div></li>';
jQuery('.messages-list').append(html);
jQuery('#input-me').val('');
if(txt){
jQuery.ajax({
url:'get_bot_message.php',
type:'post',
data:'txt='+txt,
success:function(result){
var html='<li class="messages-you clearfix"><span class="message-img"><img src="image/bot_avatar.png" class="avatar-sm rounded-circle"></span><div class="message-body clearfix"><div class="message-header"><strong class="messages-title">Chatbot</strong> <small class="time-messages text-muted"><span class="fas fa-time"></span> <span class="minutes">'+getCurrentTime()+'</span></small> </div><p class="messages-p">'+result+'</p></div></li><a href="invalidans.php" id="invalid_btn"><i>Invalid Answer ?</i></a>';
jQuery('.messages-list').append(html);
jQuery('.messages-box').scrollTop(jQuery('.messages-box')[0].scrollHeight);
}
});
}
}
</script>
</body>
</html>