-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_people.php
executable file
·114 lines (102 loc) · 3.32 KB
/
search_people.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
<?php
require_once "Authenticator.php";
require_once 'AuthenticatedPage.php';
require_once "Component.php";
require_once "fbl_common.php";
require_once 'CommonHeader.php';
require_once 'FrameworkRoot.php';
require_once 'UserActions.php';
require_once 'FriendReqs.php';
class SearchResults extends Component {
private $conn;
function renderHTML() {
db_connect($this->conn);
$queryStr = "
select screen_name, full_name, gender, status, location,
email_address
from member where upper(screen_name) like '%' || :person || '%'
or upper(full_name) like '%' || :person || '%'";
$person = isset($_GET["person"]) ? $_GET["person"] : "";
$person = strtoupper($person);
$stmt = oci_parse($this->conn, $queryStr);
oci_bind_by_name($stmt, "person", $person);
$succ = oci_execute($stmt);
if (!$succ) {
echo "Error searching";
return;
}
?>
<div id="main-content-container">
<h1>Friend search results</h1>
<?php echo "<p>Friends like: $person</p>"; ?>
<table id='search-results'>
<thead><tr>
<th>Screen name</th>
<th>Full name</th>
<th>Gender</th>
<th>Status</th>
<th>Location</th>
<th>Friendship</th>
</tr></thead>
<tbody>
<?php
while ($row = oci_fetch_row($stmt)) {
// Skip ourselves
if ($row[5] == $_SESSION['email']) { continue; }
$this->renderRow($row);
}
?></tbody></table></div>
<?php
}
function renderRow($row) {
echo '<tr>';
for ($col = 0; $col < 5; ++$col) {
if ($col == 3) { //status
echo '<td>',$row[$col]->load(),'</td>';
continue;
}
echo "<td>",$row[$col],'</td>';
}
$targetEmail = $row[5];
$queryStr = "select COUNT(*) from friendship
where (member1 = :us and member2 = :them)
or (member2 = :us and member1 = :them)";
$stmt = oci_parse($this->conn, $queryStr);
oci_bind_by_name($stmt, "us", $_SESSION['email']);
oci_bind_by_name($stmt, "them", $targetEmail);
$succ = oci_execute($stmt);
$friendsAlready = oci_fetch_row($stmt)[0] > 0;
if ($friendsAlready) {
?><td>
<form action="remove_friend.php">
<input type="submit" value="Remove friend/Cancel request"/><?php
} else {
?><td>
<form action="request_friend.php">
<input type="submit" value="Send friend request"/><?php
}
// Common form elements
echo '<input type="hidden" name="target" value="',
$targetEmail,'"/>';
echo '<input type="hidden" name="search_term" value="',
$_GET['person'],'"/>';
echo "</form></td>\n";
echo "</tr>\n";
}
}
class SearchPage extends AuthenticatedPage {
private $conn;
function renderHTML() {
$this->children = [
new CommonHeader([], ["title" => "Find friends"]),
new FrameworkRoot([
'accMgmt' => new UserActions(),
'mgAcc' => new SearchResults(),
'friendReqs' => new FriendReqs(),
])
];
parent::renderHTML();
}
}
$page = new SearchPage();
$page->pageMain();