-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.php
288 lines (225 loc) · 9.61 KB
/
profile.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/* Displays user information and some useful messages */
include 'db.php';
session_start();
// Check if user is logged in using the session variable
if ( $_SESSION['logged_in'] != 1 ) {
$_SESSION['error'] = "You must log in before viewing your profile page!";
header("location: error.php");
}
else {
// Makes it easier to read
$first = $_SESSION['first'];
$last = $_SESSION['last'];
$email = $_SESSION['email'];
$active = $_SESSION['active'];
$uid = $_SESSION['uid'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome <?= $first.' '.$last ?></title>
</head>
<body>
<div class="form">
<h1><?= $first.' '.$last ?>'s Statistics</h1>
<p>
<?php
// Display message about account verification link only once
if ( isset($_SESSION['message']) )
{
echo $_SESSION['message'];
// Don't annoy the user with more messages upon page refresh
unset( $_SESSION['message'] );
}
?>
</p>
<?php
// Keep reminding the user this account is not active, until they activate
if ( !$active ){
echo
'<div class="info">
Account is unverified, please confirm your email by clicking
on the email link!
</div>';
//$_SESSION['error'] = "Account is unverified, please confirm your email by clicking on the email link!";
//header("location: error.php");
}
?>
<p><?= $email ?></p>
</div>
<form name="form1" action="" method="post">
<div id="disp_data"></div>
<input type="text" id="txtgolfcourseins" placeholder="Golf Course">
<input type="text" id="txtscoreins" placeholder="Score">
<input type="text" id="txtfairwaysins" placeholder="Fairways">
<input type="text" id="txtgirins" placeholder="GIR's">
<input type="text" id="txtsandsavesins" placeholder="Sand Saves">
<input type="text" id="txtupanddownsins" placeholder="Up & Downs">
<input type="text" id="txtputtsins" placeholder="Putts">
<input type="button" class="insertBtn" id="but1" value="insert" onclick="insert();">
</form>
<a href="searchMembers.php"><button class="searchBtn" name="search">Search Members</button></a>
<a href="logout.php"><button class="logoutBtn" name="logout">Log Out</button></a>
<a href="pendingRequests.php"><button class="pendingRequestsBtn" name="pendingRequests">Pending Requests</button></a>
<a href="leaderboards.php"><button class="leaderboardsBtn" name="leaderboards">Leaderboards</button></a>
<div id="friendsList">
<h3>Your Friends</h3>
<?php
$sql = "SELECT * FROM users U JOIN friends F ON U.uid = F.uid AND F.friendRequest = 1 WHERE F.friendUid = :uid";
$query = $pdo->prepare($sql);
$query->bindParam(':uid', $uid);
$query->execute();
/*$sql = "SELECT * FROM users U JOIN friends F ON U.uid = F.friendUid AND F.friendRequest = 1 WHERE F.friendUid = ? OR F.uid = ?";
$query = $pdo->prepare($sql);
$query->bindParam(1, $uid);
$query->bindParam(2, $uid);
$query->execute();*/
$sql2 = "SELECT * FROM users U JOIN friends F ON U.uid = F.friendUid AND F.friendRequest = 1 WHERE F.uid = :uid";
$query2 = $pdo->prepare($sql2);
$query2->bindParam(':uid', $uid);
$query2->execute();
if ($query->rowCount() > 0) {
$results = $query->fetchAll();
foreach($results as $row) {
echo $row['first'].' '.$row['last'].' '.$row['uid'].'<br>';
}
}
if ($query2->rowCount() > 0) {
$results2 = $query2->fetchAll();
foreach($results2 as $row2) {
echo $row2['first'].' '.$row2['last'].' '.$row2['friendUid'].'<br>';
}
}
else {
echo "No friends yet";
}
?>
</div>
<script type="text/javascript">
disp_data();
function disp_data() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?status=disp",false);
xmlhttp.send(null);
document.getElementById("disp_data").innerHTML=xmlhttp.responseText;
}
function toggle(up) {
var x = document.getElementById(up);
if (x.style.visibility === 'hidden') {
x.style.visibility = 'visible';
} else {
x.style.visibility = 'hidden';
}
}
function editRow(val) {
golfcourseid = "golfcourse"+val;
txtgolfcourseid = "txtgolfcourse"+val;
var golfcourse = document.getElementById(golfcourseid).innerHTML;
document.getElementById(golfcourseid).innerHTML="<input class='golfcourseedit' type='text' value='"+golfcourse+"' id='"+txtgolfcourseid+"'>";
scoreid = "score"+val;
txtscoreid = "txtscore"+val;
var score = document.getElementById(scoreid).innerHTML;
document.getElementById(scoreid).innerHTML="<input class='scoreedit' type='text' value='"+score+"' id='"+txtscoreid+"'>";
fairwaysid = "fairways"+val;
txtfairwaysid = "txtfairways"+val;
var fairways = document.getElementById(fairwaysid).innerHTML;
document.getElementById(fairwaysid).innerHTML="<input class='fairwaysedit' type='text' value='"+fairways+"' id='"+txtfairwaysid+"'>";
girid = "gir"+val;
txtgirid = "txtgir"+val;
var gir = document.getElementById(girid).innerHTML;
document.getElementById(girid).innerHTML="<input class='giredit' type='text' value='"+gir+"' id='"+txtgirid+"'>";
sandsavesid = "sandsaves"+val;
txtsandsavesid = "txtsandsaves"+val;
var sandsaves = document.getElementById(sandsavesid).innerHTML;
document.getElementById(sandsavesid).innerHTML="<input class='sandsavesedit' type='text' value='"+sandsaves+"' id='"+txtsandsavesid+"'>";
upanddownsid = "upanddowns"+val;
txtupanddownsid = "txtupanddowns"+val;
var upanddowns = document.getElementById(upanddownsid).innerHTML;
document.getElementById(upanddownsid).innerHTML="<input class='upanddownsedit' type='text' value='"+upanddowns+"' id='"+txtupanddownsid+"'>";
puttsid = "putts"+val;
txtputtsid = "txtputts"+val;
var putts = document.getElementById(puttsid).innerHTML;
document.getElementById(puttsid).innerHTML="<input class='puttsedit' type='text' value='"+putts+"' id='"+txtputtsid+"'>";
updateid = "update"+val;
editid = "edit"+val;
deleteid = "delete"+val;
toggle(editid);
toggle(deleteid);
toggle(updateid);
}
function updateRow(b) {
var golfcourseid = "txtgolfcourse"+b;
var golfcourse = document.getElementById(golfcourseid).value;
var scoreid = "txtscore"+b;
var score = document.getElementById(scoreid).value;
var fairwaysid = "txtfairways"+b;
var fairways = document.getElementById(fairwaysid).value;
var girid = "txtgir"+b;
var gir = document.getElementById(girid).value;
var sandsavesid = "txtsandsaves"+b;
var sandsaves = document.getElementById(sandsavesid).value;
var upanddownsid = "txtupanddowns"+b;
var upanddowns = document.getElementById(upanddownsid).value;
var puttsid = "txtputts"+b;
var putts = document.getElementById(puttsid).value;
update_value(b,golfcourse,score,fairways,gir,sandsaves,upanddowns,putts);
updateid = "update"+b;
editid = "edit"+b;
deleteid = "delete"+b;
toggle(editid);
toggle(deleteid);
toggle(updateid);
document.getElementById("golfcourse"+b).innerHTML=golfcourse;
document.getElementById("score"+b).innerHTML=score;
document.getElementById("fairways"+b).innerHTML=fairways;
document.getElementById("gir"+b).innerHTML=gir;
document.getElementById("sandsaves"+b).innerHTML=sandsaves;
document.getElementById("upanddowns"+b).innerHTML=upanddowns;
document.getElementById("putts"+b).innerHTML=putts;
}
function update_value(id,golfcourse,score,fairways,gir,sandsaves,upanddowns,putts) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?id="+id+"&golfcourse="+golfcourse+"&score="+score+"&fairways="+fairways+
"&gir="+gir+"&sandsaves="+sandsaves+"&upanddowns="+upanddowns+"&putts="+putts+"&status=update",false);
xmlhttp.send(null);
}
function deleteRow(id) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?id="+id+"&status=delete",false);
xmlhttp.send(null);
disp_data();
}
function insert() {
var gc = document.getElementById("txtgolfcourseins").value;
var score = document.getElementById("txtscoreins").value;
var fairways = document.getElementById("txtfairwaysins").value;
var gir = document.getElementById("txtgirins").value;
var sandsaves = document.getElementById("txtsandsavesins").value;
var upanddowns = document.getElementById("txtupanddownsins").value;
var putts = document.getElementById("txtputtsins").value;
if (gc != "") {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?gc="+gc+"&score="+score+"&fairways="+fairways+"&gir="+gir+
"&sandsaves="+sandsaves+"&upanddowns="+upanddowns+"&putts="+putts+"&status=insert",false);
xmlhttp.send(null);
disp_data();
}
else {
alert("Must enter in golf course");
}
document.getElementById("txtgolfcourseins").value = "";
document.getElementById("txtscoreins").value = "";
document.getElementById("txtfairwaysins").value = "";
document.getElementById("txtgirins").value = "";
document.getElementById("txtsandsavesins").value = "";
document.getElementById("txtupanddownsins").value = "";
document.getElementById("txtputtsins").value = "";
}
</script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>