-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsers.php
191 lines (190 loc) · 5.82 KB
/
Users.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
<?php
include_once('include/collegeconnection.php');
if(isset($_GET['id']) && is_numeric($_GET['id']) && !$_POST['submitted'])
{
$friendsData = mysql_query('SELECT name, id FROM users ', $connection);
$id = $_GET['id'];
}
else if(isset($_COOKIE['userid'])&& is_numeric($_COOKIE['userid']) && !$_POST['submitted'])
{
$friendsData = mysql_query('SELECT name, id FROM users ', $connection);
$id = $_COOKIE['userid'];
}
else if (isset($_POST['submitted']))
{
$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 name, id FROM users WHERE (users.name = "'.$name.'");', $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 name, id FROM users;', $connection) or die("error:103"); //retrieve all the data from schools
//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 the section of the entered data is in the name or the description..
if(!strcmp($find, $row['name']) ||
(strpos(strtoupper($row['name']), $find) > -1))
{//|| (strpos(strtoupper($row['description']), $find) > -1)
$gotOne = true;
array_push($ids, $row['id']); //add this user's id.
$occur++;
}//end if
}//end for
$common[$row['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 name, id FROM users WHERE (users.name = "'.$name.'");', $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 name, id FROM users;', $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 the section of the entered data is in the name or the description..
if(!strcmp($find, $row['name']) ||
(strpos(strtoupper($row['name']), $find) > -1))
{//|| (strpos(strtoupper($row['description']), $find) > -1)
$gotOne = true;
array_push($ids, $row['id']); //add this user's id.
$occur++;
}//end if
}//end for
$common[$row['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');
?>
<div id="mainContentPart">
<div class="schoolIndexCenterbox">
<div id ="schoolIndexSearch">
<label class="schoolsearch">Search users</label><br>
<p>Search through the site's users. Type in any name.</p>
<form name="usersSearch" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="text" name="name" onClick="document.friendsSearch.name.select();" value="Search Users"><br>
<input type="submit" class="button" value="Search">
<input type="hidden" name="submitted" value="1">
</form>
</div>
<?php
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, school 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'];
if($picture['school'] != '*Not Here*' && $picture['school'] != 'No School')
{
print ' ('.$picture['school'].')';
}
print '</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 if ($_POST['submitted'])
{
print '<br><br><div class="pagetitle2">No Matches Found</div>';
}
?>
</div>
</div>
</div>
</div>
<img id="bodyBottom" src="/images/bodybottom.gif"></img>
</td></tr></table>
</div>
</div>
</div>
</div>