-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.php
197 lines (170 loc) · 4.77 KB
/
index.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
<?php
session_start();
//Create a session of username and logging in the user to the chat room
if(isset($_POST['username'])){
$_SESSION['username']=$_POST['username'];
}
//Unset session and logging out user from the chat room
if(isset($_GET['logout'])){
unset($_SESSION['username']);
header('Location:index.php');
}
?>
<html>
<head>
<title>Title Here</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js" ></script>
<script type="text/javascript" src="js/pubnub-3.7.13.min.js" ></script>
</head>
<body>
<div class='header'>
<h1>
Title Here
<?php // Adding the logout link only for logged in users ?>
<?php if(isset($_SESSION['username'])) { ?>
Welcome
<?php echo $_SESSION['username'] ?><a class='logout' href="?logout"> Logout</a>
<?php } ?>
</h1>
</div>
<div class='main'>
<?php //Check if the user is logged in or not ?>
<?php if(isset($_SESSION['username'])) { ?>
<div id='result'></div>
<div class='chatcontrols'>
<form method="post" onsubmit="return submitchat();">
<input type='text' name='chat' id='chatbox' autocomplete="off" required placeholder="ENTER CHAT HERE" />
<input type='submit' name='send' id='send' class='btn btn-send' value='Send' />
<input type='button' name='clear' class='btn btn-clear' id='clear' value='X' title="Clear Chat" />
</form>
<script>
// Javascript function to submit new chat entered by user
function submitchat(){
if($('#chat').val()=='' || $('#chatbox').val()==' ') return false;
$.ajax({
url:'chat.php',
data:{chat:$('#chatbox').val(),ajaxsend:true},
method:'post',
success:function(data){
$('#result').html(data); // Get the chat records and add it to result div
$('#chatbox').val(''); //Clear chat box after successful submition
document.getElementById('result').scrollTop=document.getElementById('result').scrollHeight; // Bring the scrollbar to bottom of the chat resultbox in case of long chatbox
}
})
return false;
};
// Function to continously check the some has submitted any new chat
setInterval(function(){
$.ajax({
url:'chat.php',
data:{ajaxget:true},
method:'post',
success:function(data){
$('#result').html(data);
}
})
}
,1000);
// Function to chat history
$(document).ready(function(){
$('#clear').click(function(){
if(!confirm('Are you sure you want to clear chat?'))
return false;
$.ajax({
url:'chat.php',
data:{username:"<?php echo $_SESSION['username'] ?>",ajaxclear:true},
method:'post',
success:function(data){
$('#result').html(data);
}
})
})
})
</script>
<?php } else { ?>
<div class='userscreen'>
<form method="post">
<input type='text' class='input-user' required placeholder="ENTER YOUR NAME HERE" name='username' />
<input type='submit' class='btn btn-user' value='START CHAT' />
</form>
</div>
<?php } ?>
</div>
</div>
<script>
<?php
$count = 0;
$myFile = "chatdata.txt";
$fh = fopen($myFile, 'r');
while(!feof($fh)){
$fr = fread($fh, 8192);
$count += substr_count($fr, 'br');
}
fclose($fh);
?>
setInterval(function()
{
<?php
$count2 = 0;
$myFile = "chatdata.txt";
$fh = fopen($myFile, 'r');
while(!feof($fh)){
$fr = fread($fh, 8192);
$count2 += substr_count($fr, 'br');
}
fclose($fh);
if($count2<$count) {
?>
alert("under construction");
<?php } ?>
}, 3000);
</script>
</body>
<style>
.sidenav {
height: 100%;
width: 160px;
position: fixed;
z-index: 1;
top: 0;
right: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 20px;
}
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 10px;
color: #818181;
display: block;
}
.sidenav a:hover {
color: #f1f1f1;
font-size: 10px;
}
.sidenav form {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
</style>
<div class="sidenav">
<form action="upload.php" method="post" enctype="multipart/form-data">
Upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload" name="submit">
</form>
<?php
$files = scandir('./uploads');
sort($files); // this does the sorting
foreach($files as $file){
echo'<a href="uploads/'.$file.'"><br>'.$file.'</a>';
}
?>
</div>
</html>