-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
100 lines (67 loc) · 2.61 KB
/
search.php
File metadata and controls
100 lines (67 loc) · 2.61 KB
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
<?php
include "baglan.php";
require("classes.php");
session_start();
if (isset($_SESSION['userId'])) {
if($_POST['action'] == "search") {
$userId = $_SESSION['userId'];
$q = $_POST['q'];
$words = explode(" ", $q);
for ($i = 0; $i < count($words); $i++) {
mysql_query("INSERT INTO SEARCH (Id, FirstName, LastName, Email, PictureURL)
SELECT Id, FirstName, LastName, Email, PictureURL FROM USER WHERE
(FirstName LIKE '%$words[$i]%' OR
LastName LIKE '%$words[$i]%') AND
Id <> $userId");
}
$result = mysql_query("SELECT DISTINCT Id, FirstName, LastName, Email, PictureURL FROM SEARCH");
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_array($result)) {
$user = new User($row['Id'], $row['FirstName'], $row['LastName'], $row['Email'], "", "", $row['PictureURL']);
$isFriend = mysql_query("SELECT Relationship FROM FRIENDSHIP
WHERE (User1Id = $userId AND User2Id = " . $user->getId() . ")
OR (User1Id = " . $user->getId() . " AND User2Id = $userId)");
if (mysql_num_rows($isFriend) > 0) {
$row = mysql_fetch_array($isFriend);
$user->displayOnSearchResult($row['Relationship']);
} else {
$isRequestPending = mysql_query("SELECT * FROM FRIENDREQUEST
WHERE SenderId = $userId AND ReceiverId = " . $user->getId());
if (mysql_num_rows($isRequestPending) > 0) {
$user->displayOnSearchResult("pending");
} else {
$user->displayOnSearchResult("notFriend");
}
}
}
} else {
echo "<br><br>No people found :(<br>";
}
mysql_query("DELETE FROM SEARCH");
for ($i = 0; $i < count($words); $i++) {
mysql_query("INSERT INTO GROUPSEARCH (GroupId, Name, PictureURL, AdminId)
SELECT GroupId, Name, PictureURL, AdminId FROM GROUPINFO
WHERE Name LIKE '%$words[$i]%'");
}
$result = mysql_query("SELECT DISTINCT GroupId, Name, PictureURL, AdminId FROM GROUPSEARCH");
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_array($result)) {
$group = new GroupInfo($row['GroupId'], $row['Name'], $row['PictureURL'], $row['AdminId']);
$isJoined_query = mysql_query("SELECT UserId FROM USERGROUP
WHERE UserId = $userId
AND GroupId = " . $row['GroupId']);
if (mysql_num_rows($isJoined_query) > 0) {
$isJoined = true;
} else {
$isJoined = false;
}
$group->displayOnSearchResult($isJoined);
}
} else {
echo "<br><br>No group found :(<br>";
}
mysql_query("DELETE FROM GROUPSEARCH");
mysql_close();
}
}
?>