-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
51 lines (47 loc) · 1.56 KB
/
search.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
<?php
// Import util functions
require("util.php");
checkSession();
dbConnect();
// Get query and type from url
$query = "";
$type = null;
if (isset($_GET["query"])) { $query = htmlspecialchars($_GET["query"]); }
if (isset($_GET["type"])) { $type = htmlspecialchars($_GET["type"]); }
echoHeader(1);
?>
<div id="content">
<form method="get" action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>>
<input type="hidden" name="type" value="user" />
<p id="label">Search for user: <input type="text" name="query" value=<?php echo("\"" . $query . "\""); ?> />
<input type="submit" value="Search" /></p>
</form>
<div id = "results">
<?php
// Display search results depending on given type
switch ($type) {
case "user":
// Get users from query
$users = searchUsers($id, $query);
//Display found users
if (count($users) == 0) {
setError("No results found.");
} else {
foreach ($users as $u) {
$result = userFromID($u);
$name = $result["firstname"] . " " . $result["lastname"];
echo("<a id=\"user\" href=\"user.php?id=" . $result["username"] . "\">" . $name . "</a><br>");
}
}
break;
default:
// Set error message if type invalid
setError("No results found.");
}
// Display error message if set
if (!empty($errorMessage)) { echo($errorMessage); }
?>
</div>
</div>
</body>
</html>