-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.php
More file actions
192 lines (147 loc) · 5.33 KB
/
chat.php
File metadata and controls
192 lines (147 loc) · 5.33 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
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
<?php
session_start();
if(!(isset($_SESSION['user'])))
{
header('Location: verify.php');
}
//get the user!
global $user;
$user = $_SESSION['user'];
if(isset($user))
{
date_default_timezone_set('America/Los_Angeles');
$timezone = date_default_timezone_get();
$date = date('h:i:s a', time());
$file = fopen("log.txt","a") or die("Error");
$info = $user['name']." ".$date."\n";
fwrite($file,$info);
fclose($file);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chat</title>
<link href="bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="chat.js"></script>
<script type="text/javascript">
// ask user for name with popup prompt
var name = <?php echo "'".$user['name']."'"; ?>;
// default name is 'Guest'
if (!name || name === ' ') {
name = "Guest";
}
// strip tags
name = name.replace(/(<([^>]+)>)/ig,"");
// display name on page
$("#name-area").html("You are: <span>" + name + "</span>");
// kick off chat
var chat = new Chat();
var queries = 0;
$(function() {
chat.getState();
// watch textarea for key presses
$("#sendie").keydown(function(event) {
var key = event.which;
//all keys including return.
if (key >= 33) {
var maxLength = $(this).attr("maxlength");
var length = this.value.length;
// don't allow new content if length is maxed out
if (length >= maxLength) {
event.preventDefault();
}
}
});
// watch textarea for release of key press
$('#sendie').keyup(function(e) {
if (e.keyCode == 13) {
var text = $(this).val();
var maxLength = $(this).attr("maxlength");
var length = text.length;
// send
if (length <= maxLength + 1) {
chat.send(text, name);
$(this).val("");
if(queries > 9)
{
window.location = "destroy.php";
}
} else {
$(this).val(text.substring(0, maxLength));
}
}
});
});
</script>
<script>
window.onfocus = function() { document.title = "Chat"};
</script>
</head>
<body onload="setInterval('chat.update()', 1000)">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.php">Westview Tutoring</a>
<div class="nav-collapse">
<ul class="nav">
<li><a href="index.php">Home</a></li>
<li><a href="chat.php">Chat</a></li>
<li><a href="tutor.php">Tutors</a></li>
</ul>
<ul class = "nav pull-right">
<li><a href="contact.php">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<br><br>
<div class = "container">
<div id="page-wrap" align = "left">
<h2>Chat
<?php
date_default_timezone_set('America/Los_Angeles');
$timezone = date_default_timezone_get();
$date = date('h:i:s a', time());
$hour = substr($date,1,1);
$pm = substr($date,9,9);
if(($pm === "pm") && $hour > 4 && $hour < 10)
{
echo "<small>active</small>";
}
else
{
echo "<small>inactive</small>";
}
?></h2>
<p id="name-area"></p>
<div id="chat-wrap"><div id="chat-area">
<?php
$string = file('chat.txt');
$size = sizeof($string);
for($i = $size - 5 ; $i < $size ; $i++)
{
echo "<p>". $string[$i]."</p>" ;
}
?>
</div></div>
<p>Your Message</p>
<form id="send-message-area">
<textarea id="sendie" placeholder = "Press enter to send" maxlength = '100' ></textarea>
</form>
</div>
<h3 align = "left">Instructions</h3>
<p align = "left">After you log into chat, please state what class you need help with and your Skype ID.<br>
Connect with the tutor through Skype.(They may display their ID in the chatroom or pm you in Skype)<br>
Add the person on Skype and accept their call. (You don't necessarily need a microphone or webcam to do this)
</p>
<p><small> <b>Please close this window after you get a tutor.</b></small><br><br> <a href = "destroy.php" class = "btn btn-primary">Signout</a> </p>
<footer>
<a href = "contact.php"></a>
</footer>
</div>
</body>
</html>