-
Notifications
You must be signed in to change notification settings - Fork 2
/
getTransferedCourses.php
61 lines (53 loc) · 3.53 KB
/
getTransferedCourses.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
<?php
session_start();
require 'connect.php';
header('Access-Control-Allow-Origin: https://engineersabroad.uvacreate.virginia.edu'); //comment out when using localhost
//header('Access-Control-Allow-Origin: http://localhost:4200'); //comment out when using hosted server
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding');
$getdata = $_GET['str'];
if(isset($getdata) && !empty($getdata)){
$request = json_decode($getdata);
$selectedMajor = mysqli_real_escape_string($con, trim($request->selectedMajor));
$selectedTerm = mysqli_real_escape_string($con, trim($request->selectedTerm));
$freeSearchEntry = mysqli_real_escape_string($con, trim($request->freeSearchEntry));
//handle all possible cases of entries and the proper SQL code
$sql = "";
if( ($selectedMajor == "" || $selectedMajor == "Any") && ($selectedTerm == "" || $selectedTerm == "Any") && ($freeSearchEntry == "")){
$sql = "SELECT * FROM transferredCourses";
}
else if( ($selectedMajor == "" || $selectedMajor == "Any") && ($selectedTerm == "" || $selectedTerm == "Any") && !($freeSearchEntry == "")){
$sql = "SELECT * FROM transferredCourses where (program LIKE '%$freeSearchEntry%' OR UVAcourse LIKE '%$freeSearchEntry%' OR HostCourse LIKE '%$freeSearchEntry%' OR country LIKE '%$freeSearchEntry%')";
}
else if( ($selectedMajor == "" || $selectedMajor == "Any") && !($selectedTerm == "" || $selectedTerm == "Any") && ($freeSearchEntry == "")){
$sql = "SELECT * FROM transferredCourses where semester='$selectedTerm'";
}
else if( ($selectedMajor == "" || $selectedMajor == "Any") && !($selectedTerm == "" || $selectedTerm == "Any") && !($freeSearchEntry == "")){
$sql = "SELECT * FROM transferredCourses where semester='$selectedTerm' and (program LIKE '%$freeSearchEntry%' OR UVAcourse LIKE '%$freeSearchEntry%' OR HostCourse LIKE '%$freeSearchEntry%' OR country LIKE '%$freeSearchEntry%')";
}
else if( !($selectedMajor == "" || $selectedMajor == "Any") && ($selectedTerm == "" || $selectedTerm == "Any") && ($freeSearchEntry == "")){
$sql = "SELECT * FROM transferredCourses where major='$selectedMajor'";
}
else if( !($selectedMajor == "" || $selectedMajor == "Any") && ($selectedTerm == "" || $selectedTerm == "Any") && !($freeSearchEntry == "")){
$sql = "SELECT * FROM transferredCourses where major='$selectedMajor' and (program LIKE '%$freeSearchEntry%' OR UVAcourse LIKE '%$freeSearchEntry%' OR HostCourse LIKE '%$freeSearchEntry%' OR country LIKE '%$freeSearchEntry%')";
}
else if( !($selectedMajor == "" || $selectedMajor == "Any") && !($selectedTerm == "" || $selectedTerm == "Any") && ($freeSearchEntry == "")){
$sql = "SELECT * FROM transferredCourses where major='$selectedMajor' and semester='$selectedTerm' ";
}
else{
$sql = "SELECT * FROM transferredCourses where major='$selectedMajor' and semester='$selectedTerm' and (program LIKE '%$freeSearchEntry%' OR UVAcourse LIKE '%$freeSearchEntry%' OR HostCourse LIKE '%$freeSearchEntry%' OR country LIKE '%$freeSearchEntry%')";
}
$sql = $sql." ORDER BY country, program, UVAcourse";
//echo json_encode($sql);
if($result = mysqli_query($con, $sql)){
$rows = [];
while($row = mysqli_fetch_assoc($result)){
$rows[] = $row; //add each row found into array
}
echo json_encode($rows);;
}
else{
echo json_encode(false);
http_response_code(404);
}
}
?>