-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch.php
More file actions
98 lines (85 loc) · 3.53 KB
/
Copy pathsearch.php
File metadata and controls
98 lines (85 loc) · 3.53 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
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
session_start();
?>
<html>
<head>
<link rel="stylesheet" href="styles/global.css">
<script type="text/javascript">
</script>
</head>
<body>
<div class='topbar'></div>
<div class='container'>
<center>
<?php
//Initiate Session User Variable and Class Variables
$new_class = $_SESSION['new_class'];
//Get Post Variables for Course Information
$coursenum = $_POST['coursenum'];
$semester = $_POST['semester'];
$prof = $_POST['prof'];
$hw_diff=($_POST['hwweight']=='different');
$l_diff=($_POST['lweight']=='different');
$q_diff=($_POST['qweight']=='different');
$t_diff=($_POST['tweight']=='different');
$misc1_diff=($_POST['misc1weight']=='different');
$misc2_diff=($_POST['misc2weight']=='different');
$misc3_diff=($_POST['misc3weight']=='different');
$class_exists=$_SESSION['class_exists']; //Class table exists
$class_correct=$_GET['class_correct']; //Existing class is correct. Set by plot.php or other display page
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1);
}
$db = pg_connect(pg_connection_string_from_database_url());
if ($_SESSION['class_exists']) {
if ($class_correct===null) {
//Display class info by redirecting to plot.php or something
$_SESSION['new_class']=array_pop($_SESSION['dupl_classes'])['name'];
$new_class=$_SESSION['new_class'];
$s=str_replace("0xDEADBEEF","-",$new_class);
header("Location: https://gradephd.herokuapp.com/plot.php?class=$s&search=1");
exit();
} elseif ($class_correct) {
$s=str_replace("0xDEADBEEF","-",$new_class);
session_unset();
header("Location: https://gradephd.herokuapp.com/plot.php?class=$s");
} elseif (!empty($_SESSION['dupl_classes'])) {
print_r($_SESSION['dupl_classes']);
echo "<a href='https://gradephd.herokuapp.com/search.php'>next</a>";
header("Location: https://gradephd.herokuapp.com/search.php");
exit();
} else {
$_SESSION['class_exists']=null;
echo "No Matching Classes Found<br><br><br>";
echo "<a class='button' href='https://gradephd.herokuapp.com/class.php'>Add a new class</a>";
}
}
if ($coursenum && $semester && $prof && !$new_class) {
if (!$skip) {
$class_name=$prof."_".$semester."_".$coursenum;
$class_name=str_replace("-","0xDEADBEEF",$class_name);
$_SESSION['new_class']=$class_name;
//Check if the class already exists
$check_dupl="SELECT NAME FROM ALL_CLASSES WHERE NAME LIKE '$class_name%';";
$result=pg_query($db,$check_dupl);
$numfound=pg_num_rows($result);
if ($numfound>0) {
$_SESSION['numfound']=$numfound;
$_SESSION['class_exists']=true;
$_SESSION['dupl_classes']=pg_fetch_all($result);
print_r($_SESSION['dupl_classes']);
echo "<a href='https://gradephd.herokuapp.com/search.php'>next</a>";
header("Location: https://gradephd.herokuapp.com/search.php");
exit();
} else {
echo "No Matching Classes Found<br><br><br>";
echo "<a class='button' href='https://gradephd.herokuapp.com/class.php'>Add a new class</a>";
}
}
}
?>
</center>
</div>
</body>
</html>