-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearchusers.php
391 lines (365 loc) · 16.5 KB
/
searchusers.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<?php
@ob_start();
session_start();
date_default_timezone_set('Asia/Singapore');
if (!isset( $_SESSION['NUSEmail'] ) ) {
// Redirect them to the login page
if ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] =='443'){
header("Location: http://localhost/orbital/signup.php");
}
else{
header("Location: http://localhost:8080/orbital/signup.php");
}
}
?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link rel="icon" href="img\studylah_logo.jpg" type="image/jpg">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css\navbar.css">
<title>StudyLah</title>
</head>
<style>
#searchsection{
text-align:center;
display:block;
width:70%;
border-left:1px solid rgba(0, 0, 0, 0.3);
border-right:1px solid rgba(0, 0, 0, 0.3);
box-shadow: 0px 10px 5px rgba(0, 0, 0, 0.3);
margin:0 auto;
background-color:white;
padding-top: 60px;
}
#profilepic{
border-radius:50%;
padding:30px;
}
#profilebio{
font-style:italic;
text-align:center;
width:250px;
margin:30px auto;
}
.bigtext{
padding:20px;
font-size:30px;
text-decoration:underline;
}
.hrstyle{
width:50%;
margin-top:15px;
margin-bottom:15px;
}
.centertable{
margin-left:auto;
margin-right:auto;
padding:20px;
}
tr, td{
padding:15px;
text-align:left;
border-bottom:1px solid #bfbfbf;
}
.tablerows:hover{
opacity:0.7;
cursor:pointer;
}
.tdsecond{
color:gray;
}
.userprofilepic{
border-radius:50%;
}
#searchimg{
margin-right:10px;
}
</style>
<body style="font-family:'Inter',sans-serif;">
<!--navbar-->
<?php include('header.php');?>
<!--profile section-->
<section style="background-color:#424240;">
<section id="searchsection">
<div>
<div class="bigtext"><img src="img/search.png" width="20px" height="20px" id="searchimg">Search Users</div>
<div>
<input type="text" id="searchNameInput" onkeyup="searchName()" placeholder="Search by name...">
<input type="text" id="searchModInput" onkeyup="searchMod()" placeholder="Search by a current mod...">
<select name="Course" class="input-field" id="searchCourseInput" onchange="searchCourse()" required>
<option selected value="All Course">All Course</option>
<option value="Data Science and Economics">Data Science and Economics</option>
<option value="Food Science and Technology">Food Science and Technology</option>
<option value="Humanities Sciences">Humanities Sciences</option>
<option value="Pharmaceutical Science">Pharmaceutical Science</option>
<option value="Philosophy, Politics, Economics">Philosophy, Politics, Economics</option>
<option value="Architecture">Architecture</option>
<option value="Industrial Design">Industrial Design</option>
<option value="Landscape Architecture">Landscape Architecture</option>
<option value="Project & Facilities">Project & Facilities</option>
<option value="Real Estate">Real Estate</option>
<option value="Biomedical Engineering">Biomedical Engineering</option>
<option value="Civil Engineering">Civil Engineering</option>
<option value="Chemical Engineering">Chemical Engineering</option>
<option value="Engineering Science">Engineering Science</option>
<option value="Environmental Engineering">Environmental Engineering</option>
<option value="Electrical Engineering">Electrical Engineering</option>
<option value="Mechanical Engineering">Mechanical Engineering</option>
<option value="Industrial and Systems Engineering">Industrial and Systems Engineering</option>
<option value="Material Science Engineering">Material Science Engineering</option>
<option value="Business Administration (Accountancy)">Business Administration (Accountancy)</option>
<option value="Information Security">Information Security</option>
<option value="Computer Science">Computer Science</option>
<option value="Information System">Information System</option>
<option value="Business Analytics">Business Analytics</option>
<option value="Computer Engineering">Computer Engineering</option>
<option value="Dentistry">Dentistry</option>
<option value="Undergraduate Law Programme">Undergraduate Law Programme</option>
<option value="Medicine">Medicine</option>
<option value="Nursing">Nursing</option>
<option value="Pharmacy">Pharmacy</option>
<option value="Music">Music</option>
</select>
</div>
<br><br>
<div>
<select name="Gender" class="input-field" id="searchGenderInput" onchange="searchGender()" required>
<option selected value="All Gender">All Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Others">Others</option>
</select>
<select name="YearOfStudy" class="input-field" id="searchYearInput" onchange="searchYear()" required>
<option selected value="Any Year of Study">Any Year of Study</option>
<option value="1">Year 1</option>
<option value="2">Year 2</option>
<option value="3">Year 3</option>
<option value="4">Year 4</option>
<option value="5">Year 5</option>
</select>
<input type="text" id="searchCCAInput" onkeyup="searchCCA()" placeholder="Search by CCA...">
<button type="button" id="clearfilters">Clear Filters</button>
</div>
<br><br>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname= "orbital";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$currentuseremail=$_SESSION['NUSEmail'];
$sqlgetuser="SELECT * FROM users WHERE NOT NUSEmail='$currentuseremail' ORDER BY UserID ASC";//dont show myself
$resultgetuser=mysqli_query($conn,$sqlgetuser);
echo "<table class=\"centertable\" id=\"usersTable\">";
echo "<tr style=\"font-weight:bold;\"><td></td><td>Name</td><td>Gender</td><td>Course</td><td>Year of Study</td><td>Current Mods</td><td>CCA</td></tr>";
if(mysqli_num_rows($resultgetuser) > 0){//get users
while($rowgetuser=mysqli_fetch_array($resultgetuser)){
$userprofilepic=$rowgetuser['ProfilePic'];
$userid=$rowgetuser['UserID'];
echo "<form method=\"post\" action=\"viewusers.php\" id=\"userform$userid\">";//submit form onclick of row
echo "<tr class=\"tablerows\" onclick=\"document.getElementById('userform$userid').submit();\">";
if($userprofilepic == "" || $userprofilepic == NULL){
echo "<td><img src=\"img/user.png\" width=\"100px\" height=\"100px\" class=\"userprofilepic\"></td>";
}
else{
echo "<td><img src=\"userprofilepic/$userprofilepic\" width=\"100px\" height=\"100px\" class=\"userprofilepic\"></td>";
}
echo "<td>".$rowgetuser['FullName']."<input type=\"number\" value=\"$userid\" name=\"theuserid\" hidden></td>";
echo "<td>".$rowgetuser['Gender']."</td>";
echo "<td>".$rowgetuser['Course']."</td>";
echo "<td>Year ".$rowgetuser['YearOfStudy']."</td>";
$currentmods = $rowgetuser['CurrentMod'];
$currentmodsexplode=preg_split('/[\ \n\,]+/', $currentmods);//split string by regular expressions e.g comma, space
echo "<td>";
for($eachcurrmod = 0; $eachcurrmod < count($currentmodsexplode); $eachcurrmod++){
$getcurrmods=$currentmodsexplode[$eachcurrmod];
echo "$getcurrmods<br>";
}
echo "</td>";
//cca
$currentcca = $rowgetuser['CCA'];
if($currentcca == NULL || $currentcca == ""){
echo "<td>";
echo "No CCA";
echo "</td>";
}
else{
$currentccasexplode = preg_split('/[\ \n\,]+/', $currentcca);
echo "<td>";
for($eachcurrcca = 0; $eachcurrcca < count($currentccasexplode); $eachcurrcca++){
$getcurrcca=$currentccasexplode[$eachcurrcca];
echo "$getcurrcca<br>";
}
echo "</td>";
}
echo "</tr>";
echo "<button type=\"submit\" name=\"eachuserprofile\" hidden></button>";
echo "</form>";
}
}
else{
echo "<div>No other users...</div>";
}
echo "</table>";
?>
</div>
</section>
</section>
</body>
<script>
function searchName() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("searchNameInput");
filter = input.value.toUpperCase();
table = document.getElementById("usersTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1]; //get Name
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
function searchMod() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("searchModInput");
filter = input.value.toUpperCase();
table = document.getElementById("usersTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[5]; //get current mod
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
function searchCourse() {
var input, table, tr, td, i, txtValue;
input = document.getElementById("searchCourseInput").value;
table = document.getElementById("usersTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
if(input == "All Course"){
tr[i].style.display = "";
}
else{
td = tr[i].getElementsByTagName("td")[3]; //get course
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.indexOf(input) > -1) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
}
function searchGender() {
var input, table, tr, td, i, txtValue;
input = document.getElementById("searchGenderInput").value;
table = document.getElementById("usersTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
if(input == "All Gender"){
tr[i].style.display = "";
}
else{
td = tr[i].getElementsByTagName("td")[2]; //get gender
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.indexOf(input) > -1) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
}
function searchYear() {
var input, table, tr, td, i, txtValue;
input = document.getElementById("searchYearInput").value;
table = document.getElementById("usersTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
if(input == "Any Year of Study"){
tr[i].style.display = "";
}
else{
td = tr[i].getElementsByTagName("td")[4]; //get YOS
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.indexOf(input) > -1) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
}
function searchCCA(){
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("searchCCAInput");
filter = input.value.toUpperCase();
table = document.getElementById("usersTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[6]; //get CCA
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
}
else {
tr[i].style.display = "none";
}
}
}
}
// Get the button that clear filters
var btn = document.getElementById("clearfilters");
// When the user clicks the button, clear filters
btn.onclick = function() {
document.getElementById("searchNameInput").value = "";
document.getElementById("searchModInput").value = "";
var dropDown1 = document.getElementById("searchCourseInput");
dropDown1.selectedIndex = 0;
var dropDown2 = document.getElementById("searchGenderInput");
dropDown2.selectedIndex = 0;
var dropDown3 = document.getElementById("searchYearInput");
dropDown3.selectedIndex = 0;
document.getElementById("searchCCAInput").value = "";
var table, tr, td, i;
table = document.getElementById("usersTable");
tr = table.getElementsByTagName("tr");
for (i = 1; i < tr.length; i++) {
tr[i].style.display = "";
}
}
</script>
</html>