-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontacts.php
More file actions
160 lines (150 loc) · 5.09 KB
/
Copy pathcontacts.php
File metadata and controls
160 lines (150 loc) · 5.09 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
<?php
session_start();
setcookie('messages', '',0);
setcookie('senders', '', 0);
if($_SESSION['error']== "error")
{
echo '<script language="javascript">';
echo 'alert("User doesn\'t exist")';
echo '</script>';
$_SESSION['error'] = "none";
}
else if ($_SESSION['error'] == "private") {
echo '<script language="javascript">';
echo 'alert("That user\'s profile is private.")';
echo '</script>';
$_SESSION['error'] = "none";
}
if(!isset($_COOKIE['username'])) {
header('Location: index.php');
}
setcookie('username', $_SESSION['username'], 0);
?>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script src="javascript.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="navigation.css">
</head>
<body>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '411711342356748',
xfbml : true,
version : 'v2.5'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div>
<nav class="main-menu">
<ul>
<li><a onclick ="FB.logout()" href="logout.php">Logout</a></li>
<li id="currentpage"><a href="">Contacts</a></li>
<li><a href="messages.php">Messages</a></li>
<li><a id="userProf">Profile</a></li>
</ul>
</nav>
</div>
<script type="text/javascript">
function getContacts(){
var username = parse();
$.ajax({
type: 'GET',
url: './getContacts.php',
data: {username: username},
success: function(data) {
var obj = jQuery.parseJSON(data);
var conts = obj.contacts;
for(i = 0; i < conts.length; i++){
var btn = document.createElement("BUTTON");
btn.setAttribute("id", "contactBtn_");
btn.setAttribute("value", conts[i]);
btn.onclick=function(){
window.location.replace("profile.php?userVar="+this.value);
};
var t = document.createTextNode(conts[i]);
btn.appendChild(t);
document.body.appendChild(btn);
}
}
});
}
document.addEventListener('DOMContentLoaded', function(){
if(Notification.permission != "granted"){
Notification.requestPermission();
}
});
function initNotifications(x, tracked, runCount){
var username = parse();
$.ajax({
type: 'GET',
url: './notifications.php',
data: {username: username, time: x},
success: function(data){
var obj = jQuery.parseJSON(data);
var messages = obj.message;
var senders = obj.sender;
var times = obj.times;
for(i = 0; i < messages.length; i++){
//make sure the array doesnt grow too large
if(runCount >= 500){
tracked = []
}
if(tracked.indexOf(times[i]) > -1){
continue;
}
else{
runCount += 1;
tracked.push(times[i]);
}
temp = document.cookie;
document.cookie = "sender="+senders[i];
document.cookie = "message="+messages[i];
if (Notification.permission != "granted")
Notification.requestPermission();
else {
var notification = new Notification(parseSender(), {body: parseMessage()});
notification.onclick = function () {
window.location.replace("./messages.php?contacts="+parseSender());};
setTimeout(function(){
notification.close();
}, 5000);
}
document.cookie = temp;
}
initNotifications(obj.time, tracked, runCount);
}
});
}
$(function(){
document.getElementById("userProf").setAttribute("href", "profile.php?userVar="+parse());
getContacts();
var d = new Date();
var tracked = [];
initNotifications(d.getTime(), tracked, 0);
});
</script>
<br>
<form action="addContact.php" id="addCnt" method="get">
<input type="hidden" name="username" value="<?php echo htmlspecialchars($_SESSION['username']); ?>">
Add user to contacts:<br>
<input type="username" name="contact" id="addCntInput" placeholder="Username">
<input type="submit" value="Add">
</form>
</body>
</html>
<script>
</script>