-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriends.php
249 lines (247 loc) · 8.92 KB
/
friends.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
<?php
include_once('include/authentication.php');
if(isset($_GET['id']) && is_numeric($_GET['id']) && !$_POST['submitted'])
{
$friendsData = mysql_query('SELECT friend1, friend2, name, id FROM friends, users WHERE (((friend1= users.id AND friend1='.$_GET['id'].') OR (friend2= users.id AND friend2 ='.$_GET['id'].')) AND pending=0) ORDER BY users.id;', $connection) or die(mysql_error());//header('Location: login.php');
$id = $_GET['id'];
}
else if(isset($_COOKIE['userid'])&& is_numeric($_COOKIE['userid']) && !$_POST['submitted'])
{
$friendsData = mysql_query('SELECT friend1, friend2, name, id FROM friends, users WHERE (((friend1= users.id AND friend1='.$_COOKIE['userid'].') OR (friend2= users.id AND friend2 ='.$_COOKIE['userid'].')) AND pending=0) ORDER BY users.id;', $connection);
$id = $_COOKIE['userid'];
}
else if (isset($_POST['submitted']) && isset($_GET['id']) && is_numeric($_GET['id']))
{
$name = strtoupper($_POST['name']);
$nameconst = $_POST['name'];
$finds = array();
$continue = true;
while($continue)
{
$pos = strpos($name, " ");
if($pos)
{
$temp = substr($name, 0 , $pos);
}
else
{
$temp = substr($name, 0);
$continue = false;
}
if(strlen($temp)> -1)
{
array_push($finds, $temp);
}
$name = substr($name, $pos);
}
$data = mysql_query('SELECT friend1, friend2, name, id FROM friends, users WHERE pending=0 AND ((friend1 = users.id AND users.name = "'.$nameconst.'") OR (friend2 = users.id AND users.name = "'.$nameconst.'")) AND (friend1 = '.$_GET['id'].' OR friend2 = '.$_GET['id'].');', $connection);
$row = mysql_fetch_array($data, MYSQL_ASSOC);
$found = true;
if(strcmp(strtoupper($row['name']), strtoupper($nameconst))) //if there is no data matching names exactly...
{
$found = false;
$gotOne = false;
$ids = array(); //initialize a new array to hold the school id numbers
$data = mysql_query('SELECT friend1, friend2 FROM friends WHERE pending=0 AND ((friend1 = '.$_GET['id'].') OR (friend2 = '.$_GET['id'].'));', $connection) or die("error: 45 ".mysql_error());
//retrieve all the data from schools
$common = array();
while($row = mysql_fetch_array($data, MYSQL_ASSOC)) //while there is still data to be served
{
$occur = 0;
foreach($finds as $find) //for each part of the school name entered...
{
if($row['friend1'] != $_GET['id'] && $row['friend1'] != $_COOKIE['userid'])
{
$friend = mysql_query('select name, id from users where id='.$row['friend1'].';', $connection);
}
else
{
$friend = mysql_query('select name, id from users where id='.$row['friend2'].';', $connection);
}
$user = mysql_fetch_array($friend, MYSQL_ASSOC);
//if the section of the entered data is in the name or the description..
if(!strcmp($find, $user['name']) ||
(strpos(strtoupper($user['name']), $find) > -1))
{//|| (strpos(strtoupper($row['description']), $find) > -1)
$gotOne = true;
array_push($ids, $user['id']); //add this user's id.
$occur++;
}//end if
}//end for
$common[$user['id']] = $occur;
}//end while
$ids = array_unique($ids);
} //end if
if (isset($common))
{
arsort($common);
}
}
/**IF FOR YOURSELF**/
else if (isset($_POST['submitted']) && !isset($_GET['id']) && is_numeric($_COOKIE['userid']))
{
$name = $_POST['name'];
$name = strtoupper($_POST['name']);
$nameconst = $_POST['name'];
$finds = array();
$found = false;
$gotOne = false;
$continue = true;
while($continue)
{
$pos = strpos($name, " ");
if($pos)
{
$temp = substr($name, 0 , $pos);
}
else
{
$temp = substr($name, 0);
$continue = false;
}
if(strlen($temp)> -1)
{
array_push($finds, $temp);
}
$name = substr($name, $pos + 1);
}
$data = mysql_query('SELECT friend1, friend2, name, id FROM friends, users WHERE pending=0 AND ((friend1 = users.id AND users.name = "'.$name.'") OR (friend2 = users.id AND users.name = "'.$name.'")) AND (friend1 = '.$_COOKIE['userid'].' OR friend2 = '.$_COOKIE['userid'].');', $connection);
$row = mysql_fetch_array($data, MYSQL_ASSOC);
$found = true;
if(strcmp(strtoupper($row['name']), strtoupper($nameconst))) //if there is no data matching names exactly...
{
$found = false;
$ids = array(); //initialize a new array to hold the school id numbers
$data = mysql_query('SELECT friend1, friend2, name, id FROM friends, users WHERE pending=0 AND ( friend1 = '.$_COOKIE['userid'].') OR ( friend2 = '.$_COOKIE['userid'].');', $connection) or die("error:103"); //retrieve all the data from schools
$common = array();
while($row = mysql_fetch_array($data, MYSQL_ASSOC)) //while there is still data to be served
{
$occur = 0;
foreach($finds as $find) //for each part of the school name entered...
{
if($row['friend1'] != $_GET['id'] && $row['friend1'] != $_COOKIE['userid'])
{
$friend = mysql_query('select name, id from users where id='.$row['friend1'].';', $connection);
}
else
{
$friend = mysql_query('select name, id from users where id='.$row['friend2'].';', $connection);
}
$user = mysql_fetch_array($friend, MYSQL_ASSOC);
//if the section of the entered data is in the name or the description..
if(!strcmp($find, $user['name']) ||
(strpos(strtoupper($user['name']), $find) > -1))
{//|| (strpos(strtoupper($row['description']), $find) > -1)
$gotOne = true;
array_push($ids, $user['id']); //add this user's id.
$occur++;
}//end if
}//end for
$common[$user['id']] = $occur;
}//end while
$ids = array_unique($ids);
} //end if
if (isset($common))
{
arsort($common);
}
}
else
{
header('Location: login.php');
}
include_once('include/header.php');
if(!isset($_POST['submitted']))
{
$friendArrayData = array();
$friendArray = array();
$counter = 0;
while($row = mysql_fetch_array($friendsData, MYSQL_ASSOC))
{
if($row['friend1'] == $id)
{
$friendid = $row['friend2'];
}
else
{
$friendid = $row['friend1'];
}
$friendName = mysql_query('SELECT lastName FROM users WHERE id='.$friendid.';', $connection) or die('error');
$friendNameRow = mysql_fetch_array($friendName, MYSQL_ASSOC);
$friendArray[$friendid] = $friendNameRow['lastName'];
}
asort($friendArray);
}
?>
<div id="mainContentPart">
<div class="schoolIndexCenterbox">
<div id ="schoolIndexSearch">
<label class="schoolsearch">Search Friends</label><br>
<p>Search through this person's friends. Type in any name.</p>
<form name="friendsSearch" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="text" name="name" onClick="document.friendsSearch.name.select();" value="Search Friends"><br>
<input type="submit" class="button" value="Search">
<input type="hidden" name="submitted" value="1">
</form>
</div>
<?php
if(!isset($_POST['submitted']))
{
print '<div class="pageTitle">Friends</div>';
if(mysql_num_rows($friendsData) > 0)
{
print 'Listing '.mysql_num_rows($friendsData).' friends';
print '<table id="friendsList" cellspacing="0">';
foreach($friendArray as $friendID =>$name)
{
$pictureData = mysql_query('SELECT name, thumb_url FROM users WHERE id='.$friendID.';', $connection);
$picture = mysql_fetch_array($pictureData, MYSQL_ASSOC);
print '<tr><td class="friendsTD"><a href="profile.php?id='.$friendID.'"><img src="'.$picture['thumb_url'].'"></img><br>'.$picture['name'].'</a></td><td><a href="profile.php?id='.$friendID.'">View Profile</a><br>
<a href="friends.php?id='.$friendID.'">View Friends</a><br><a href="addFriend.php?id='.$friendID.'">Friend Me</a><br>
<a href="compose.php?id='.$friendID.'">Send Message</a></td></tr>';
}
print '</table>';
}
else
{
print 'No Friends Found';
}
}
else
{
if ($found)
{
print 'FOUND: '.$row['name'];
}
else if($gotOne)
{
print '<table id="friendsList" cellspacing="0">';
foreach($common as $id => $num)
{
if($num > 0)
{
$data = mysql_query('SELECT name, id FROM users WHERE id = '.$id.';', $connection);
$row = mysql_fetch_array($data, MYSQL_ASSOC);
$pictureData = mysql_query('SELECT name, thumb_url FROM users WHERE id='.$id.';', $connection);
$picture = mysql_fetch_array($pictureData, MYSQL_ASSOC);
print '<tr><td class="friendsTD"><a href="profile.php?id='.$id.'"><img src="'.$picture['thumb_url'].'"></img><br>'.$picture['name'].'</a></td><td><a href="profile.php?id='.$id.'">View Profile</a><br>
<a href="friends.php?id='.$id.'">View Friends</a><br><a href="addFriend.php?id='.$id.'">Friend Me</a><br>
<a href="compose.php?id='.$id.'">Send Message</a></td></tr>';
}
}
print '</table>';
}
else
{
print '<br><br><div class="pagetitle2">No Matches Found</div>';
}
}
?>
</div>
</div></div></div></div>
<img id="bodyBottom" src="/images/bodybottom.gif"></img>
</td></tr></table>
</div>
</div>
</div>
</div>