-
Notifications
You must be signed in to change notification settings - Fork 57
/
friends.js
118 lines (104 loc) · 4.43 KB
/
friends.js
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
/***********Pull the Friend Feed from the XML********************/
function printFriendsList(userid)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var xml_doc = xmlhttp.responseXML;
var friends_list = xml_doc.getElementsByTagName('friend');
if (friends_list.length> 0)
{
var friendshtml = "<p></p><table id='friendsTable' >";
for(var i = 0; i < friends_list.length; i += 1)
{
var userid = friends_list[i].getElementsByTagName('userid')[0].textContent;
var fname = friends_list[i].getElementsByTagName('fname')[0].textContent;
var lname = friends_list[i].getElementsByTagName('lname')[0].textContent;
var friendsstatus = parseInt(friends_list[i].getElementsByTagName('friendsstatus')[0].textContent);
friendshtml += "<tr><td><a href='profile.php?id=" + userid + "' 'alt='" + fname + " " + lname + "\'s Profile'><h3>" + fname + " " + lname + "</h3></a></td><td>";
switch(friendsstatus)
{
case -1:
friendshtml += "My Profile <img src='check.png' width='12' height='13' />";
break;
case 0:
friendshtml += "<button type=\"button\" style=\"font: 24px;\" onclick=\"window.location = 'addfriend.php?id=" + userid + "';\">+1 Friend</button>";
break;
case 1:
friendshtml += "<img src='check.png' width='12' height='13' />Friends";
break;
case 2:
friendshtml += "Friend request pending!";
break;
case 3:
friendshtml += "This user wants to be friends. <button type='button' onclick=\"window.location = 'addfriend.php?id=" + userid + "';\">Approve</button> <button type='button' onclick=\"window.location = 'denyrequest.php?id=" + userid + "';\">Deny</button>";
break;
default:
friendshtml += "we;ve got a problem";
}
friendshtml += "</td></tr>";
}
friendshtml += "</table>";
document.getElementById('friendslist').innerHTML = friendshtml;
}
}
}
xmlhttp.open("GET","getfriends.php?id=" + userid, true)
xmlhttp.send()
}
/***********Pull the Friend Feed from the for the Friends/Homepage********************/
function printFriendsPageList(userid)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var xml_doc = xmlhttp.responseXML;
var friends_list = xml_doc.getElementsByTagName('friend');
if (friends_list.length> 0)
{
var friendshtml = "<p></p><h2>You have " + friends_list.length + " friends</h2><table id='friendsPageTable' >";
for(var i = 0; i < friends_list.length; i += 1)
{
var userid = friends_list[i].getElementsByTagName('userid')[0].textContent;
var fname = friends_list[i].getElementsByTagName('fname')[0].textContent;
var lname = friends_list[i].getElementsByTagName('lname')[0].textContent;
var friendsstatus = parseInt(friends_list[i].getElementsByTagName('friendsstatus')[0].textContent);
friendshtml += "<tr><td><a href='profile.php?id=" + userid + "' 'alt='" + fname + " " + lname + "\'s Profile'><h3>" + fname + " " + lname + "</h3></a></td><td>";
switch(friendsstatus)
{
case -1:
friendshtml += "My Profile <img src='check.png' width='12' height='13' />";
break;
case 0:
friendshtml += "<button type=\"button\" style=\"font: 24px;\" onclick=\"window.location = 'addfriend.php?id=" + userid + "';\">+1 Friend</button>";
break;
case 1:
friendshtml += "<img src='check.png' width='12' height='13' />Friends";
break;
case 2:
friendshtml += "Friend request pending!";
break;
case 3:
friendshtml += "This user wants to be friends. <button type='button' onclick=\"window.location = 'addfriend.php?id=" + userid + "';\">Approve</button> <button type='button' onclick=\"window.location = 'denyrequest.php?id=" + userid + "';\">Deny</button>";
break;
default:
friendshtml += "we;ve got a problem";
}
friendshtml += "</td></tr>";
}
friendshtml += "</table>";
document.getElementById('friendslist').innerHTML = friendshtml;
}
else
{
document.getElementById('friendslist').innerHTML = "<h3>You have no friends :(</h3>";
}
}
}
xmlhttp.open("GET","getfriends.php?id=" + userid, true)
xmlhttp.send()
}