-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
85 lines (82 loc) · 3.17 KB
/
search.php
File metadata and controls
85 lines (82 loc) · 3.17 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
<?php
session_start();
require_once "backend/connect.php";
if (isset($_POST['valueToSearch']) && $_POST['valueToSearch'] != ""){
$query = 'SELECT `FirstName`, `LastName`, `status`, `location`, `exchange_rate`, `email` FROM `user` WHERE CONCAT(`FirstName`, `LastName`, `status`, `location`) LIKE "%'.$_POST['valueToSearch'].'%"';
} else {
$query = "SELECT `FirstName`, `LastName`, `status`, `location`, `exchange_rate`, `email` FROM `user` WHERE 1";
}
// if (isset($_SESSION["user_id"])) {
// $query .= " AND `user_id` !=".$_SESSION['user_id'];
// }
$orderBy = array('FirstName', 'LastName', 'status', 'location', 'exchange_rate');
if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
$order = $_GET['orderBy'];
$query .= " ORDER BY ".$order;
}
$stmt = $dbh->prepare($query);
$stmt->execute();
?>
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
<?php include("common/head.html"); ?>
<link rel="stylesheet" type="text/css" href="style/search.css">
</head>
<body>
<?php include("common/header.php");?>
<main>
<form id="searchForm" action="search.php" method="post">
<input id="searchText" type="text" name="valueToSearch" placeholder="Search Users" class="form-control2">
<input id="searchSubmit" type="submit" name="search" value="Search" class="btn"><br/>
</form>
<?php
if ($stmt->rowCount() > 0) {
echo "
<table>
<tr>
<th class='firstname'><a href='?orderBy=FirstName'>First Name</a></th>
<th class='lastname'><a href='?orderBy=LastName'>Last Name</a></th>
<th class='status'><a href='?orderBy=status'>Flex Status</a></th>
<th class='location'><a href='?orderBy=location'>Location</a></th>
<th class='rate'><a href='?orderBy=exchange_rate'>\$USD/\$FLEX</a></th>
<th class='contact'><a href='??orderBy=status'>Contact</a></th>
</tr>
";
while($row = $stmt->fetch()) {
$status = "";
$contactButton = "";
if ($row['status'] == 0){
$status = 'Flexing';
$contactButton = "
<form action='email.php' method='post'>
<input type='hidden' name='email' value=" . $row['email'] . ">
<input type='hidden' name='name' value=" . $row['FirstName'] . ">
<input type='submit' name='search' value='Exchange' class='btn'>
</form>
";
} else if ($row['status'] == 1){
$status = 'Offline';
} else {
$status = 'Status Unavailable';
}
echo "
<tr>
<td>" . $row['FirstName'] . "</td>
<td>" . $row['LastName'] . "</td>
<td>" . $status . "</td>
<td>" . $row['location'] . "</td>
<td>" . $row['exchange_rate'] . "</td>
<td>" . $contactButton . "</td>
</tr>
";
}
echo "</table>";
} else {
echo "<h1>No Results</h1>";
}
?>
</main>
</body>
</html>