-
Notifications
You must be signed in to change notification settings - Fork 0
/
pending.php
143 lines (103 loc) · 4.19 KB
/
pending.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
<html>
<body>
<form name="friendRequests">
<table id="theTable">
<b>Current Friend Requests!</b><br></br>
<?php
session_start();
$sessionID = $_SESSION["ID"];
// Initialize the table from the database on the server
//$db = mysqli_connect('localhost', 'root', 'password', 'test');
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_DATABASE", "test");
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
$testdatabase = mysql_select_db("test");
if($db->connect_error){
print "Error - Could not connnect to MySQL";
exit;
}
$checkPending = mysqli_query($db,"SELECT * FROM Relationship WHERE Friend2 = '$sessionID' and Status = 1");
$rows = $checkPending->num_rows;
if($rows == 0){
echo "You have no pending requests at this time!";
}
for ($ctr = 1; $ctr <= $rows; $ctr++){
echo "<tr align = 'center'>";
$row = mysqli_fetch_array($checkPending);
$id = $row['Friend1'];
$getName = mysqli_query($db,"SELECT * FROM Users WHERE ID = '$id'");
$user = mysqli_fetch_array($getName);
$name = $user['Name'];
echo "<td>$name has requested to add you as a friend!</td>";
?>
<div id="help">hi </div>
<?php
echo "<td><input type = 'submit' name = 'Accept' id = 'a'
value = 'Accept'
onclick = 'processRequest(2, $id)'></td>";
echo "<td><input type = 'submit' name = 'Decline' id = 'd'
value = 'Decline'
onclick = 'processRequest(3, $id)'></td>";
echo "</tr>";
}
?>
</table>
</form>
<script>
function processRequest() {
var httpRequest;
var type = arguments[0]; // get whether accepted or denied
var id = arguments[1];
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
//alert('XMLHttpRequest');
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // Older versions of IE
//alert('IE -- XMLHTTP');
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
// update the sql table to whether it is accept or decline
var data;
data = 'type=' + type + '&id=' + id;
httpRequest.open('POST', 'updateFriendRequest.php', true);
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
/*send the name of the friend to a showTable function that will reprint the info but will say accepted or will be invisible if the user declines? maybe...we'll see */
httpRequest.onreadystatechange = function () {
showTable(httpRequest);
};
httpRequest.send(data);
}
//function that happens on click but i'm not sure this is really needed as a separate function??
function showTable(httpRequest) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
var confirmed = httpRequest.responseText;
help = document.getElementById("help");
if (confirmed == "accepted") {
window.location = "/HackPrinceton/landing-page/landing.html"
alert("?");
}
if (confirmed == "declined") {
help.innerHTML = "You have declined this request!";
window.location = "/HackPrinceton/landing-page/landing.html"
}
}
}
}
</script>
</body>
</html>