-
Notifications
You must be signed in to change notification settings - Fork 2
/
search.php
159 lines (130 loc) · 4.46 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
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
<?php
if(session_status()!=PHP_SESSION_ACTIVE)
session_start();
if (!isset($_SESSION['user']) or $_SESSION['user']==""){
session_unset();
session_destroy();
echo "<script>location.replace('login.php?next=search.php');</script>";
}
include "db_connect.php";
$con=Connect();
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style/main.css">
<link rel="stylesheet" type="text/css" href="style/form.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- IMPORT FONTS -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300|Lato&display=swap" rel="stylesheet">
<!-- ICONS !-->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.7.0/css/all.css'>
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!-- Menu -->
<script type="text/javascript">
function ToggleNav(){
$('ul.nav').slideToggle("slow");
}
</script>
<title>FIND USER | <?php echo $_SESSION['user']['name']?></title>
<style type="text/css">
input,select{
min-width: 40%;
max-width: 90vw;
}
input[type=submit]{
min-width: 5%;
}
button.msg{
min-width: 5px;
border-radius: 50%;
border: none;
font-size: 1.25em;
}
button.msg:hover, button.msg:focus{
background-color: #000;
color: #fff;
}
</style>
</head>
<body>
<header>
<div id="toggle"><a onclick="$('ul.nav').slideToggle('slow');"><i class="material-icons" style="font-size:1.5em;color:#fff">menu</i></a></div>
<div class="profile">
<img src="prof-pic/<?php echo $_SESSION['user']['username'];?>.png" onerror="this.src='prof-pic/default.png';" class="prof-pic">
<div class="prof-name"><?php echo $_SESSION['user']['name']; ?></div>
</div>
<ul class="nav">
<li><a href="index.php">Home</a></li>
<li><a href="assg.php">Assignments</a></li>
<li><a href="message.php">Messages</a></li>
<li><a href="news.php">Announcements</a></li>
<li><a href="search.php" class="selected">Find user</a></li>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</header>
<div class="container" align="center">
<form method="GET">
<span class="open-sans">FIND</span>  <input type="text" class="search" value= "<?php echo $_REQUEST['id']?>" name="id" pattern="[a-zA-Z0-9]+">  <span class="op
">BY</span> 
<select name="by">
<option value="username" <?php if ($_REQUEST['by']=='username'){?> selected ="true" <?php } ?>>Username</option>
<option value="name" <?php if ($_REQUEST['by']=='name'){?> selected ="true" <?php } ?>>Name</option>
</select>
<input type="submit">
</form>
<?php if (isset($_REQUEST['id'])){?>
<hr>
<div class="title" style="font-size: 1.5em; color: #444444">Search Results</div>
<table>
<thead>
<tr>
<th>Username</th>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
if (!preg_match("/^[a-zA-Z0-9]*$/",$_REQUEST['id']) or !preg_match("/^(name|username)$/",$_REQUEST['by']))
echo "Invalid search query! Try again";
else{
if ($_REQUEST['by']=='name')
$res=mysqli_query($con,"SELECT info.username,list.name,info.role from info,list where list.name LIKE '%".mysqli_real_escape_string($con,$_REQUEST['id'])."%' and info.adm_no=list.adm_no ");
else
$res=mysqli_query($con,"SELECT info.username,list.name,info.role from info,list where info.username LIKE '%".mysqli_real_escape_string($con,$_REQUEST['id'])."%' and info.adm_no=list.adm_no ");
$i=0;
while ($t=mysqli_fetch_assoc($res))
{?>
<tr>
<form action="message.php" method="GET"><tr valign="top">
<td><?php echo $t['username']?></td>
<td><?php echo $t['name']?></td>
<td><input type="text" name="user2" readonly="true" hidden="true" value="<?php echo $t['username']?>">
<button class="msg"><i class="far fa-comment"></i></button></td>
</form>
</tr>
<?php $i++; }
if ($i==0)
{?>
<tr>
<td colspan="3"><center>No records found</center></td>
</tr>
<?php } ?>
</tr>
</table>
<?php
}
}
Close($con); ?>
</div>
<footer>
<div class="copy">© All Rights Reserved</div>
<div class="last-login"><?php echo "Last Logout: ".$_SESSION['user']['active'];?></div>
</footer>
</body>
</html>