-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·224 lines (207 loc) · 9.96 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Technion Dependencies Helper </title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"
crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<div style="text-align: center;"><h1> Technion Dependency Helper </h1></div>
<h2><b> BETA </b>, report bugs! </h2>
<p> Updated Jan 27th, 2021 </p>
<a href="https://github.com/Eladkay/TechnionDependenciesHelper"> GitHub for issues and suggestions </a>
<p> Enter here the course numbers you took, separated by spaces, and we will tell you what courses you can
take! </p> <br>
<form method="post">
<div class="input-group">
<label for="courses">
Course numbers, separated by spaces:
</label>
<input type="text" class="form-control" name="courses" id="courses"
value="<?php echo $_POST['courses']; ?>"/>
</div>
<br>
<div class="input-group">
<label for="digits">
Optionally, filter only courses whose course numbers begin with the given three digits:
</label>
<input type="text" class="form-control" name="digits" id="digits" value="<?php echo $_POST['digits']; ?>"/>
<br>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="filter" id="filter"
value="yes" <?php if (isset($_POST["filter"])) echo "checked"; ?>>
<label class="form-check-label" for="filter">
Filter subjects with no dependencies
</label>
<br>
<input class="form-check-input" type="checkbox" name="filter_equiv" id="filter_equiv"
value="yes" <?php if (isset($_POST["filter_equiv"])) echo "checked"; ?>>
<label class="form-check-label" for="filter_equiv">
Filter subjects that overlap with, are incorporated in, or incorporate courses you have already completed
</label>
</div>
<!-- <input type="submit" name="bidusa"> <-- Bidusa Button </input> <br> <br> !-->
<div class="form-check">
<input class="form-check-input" type="checkbox" name="chem" id="chem"
value="yes" <?php if (isset($_POST["chem"])) echo "checked"; ?>>
<label class="form-check-label" for="chem">
Include courses that require chemistry classification
</label>
<br>
<input class="form-check-input" type="checkbox" name="phys1" id="phys1"
value="yes" <?php if (isset($_POST["phys1"])) echo "checked"; ?>>
<label class="form-check-label" for="phys1">
Include courses that require physics classification for mechanics
</label>
<br>
<input class="form-check-input" type="checkbox" name="phys2" id="phys2"
value="yes" <?php if (isset($_POST["phys2"])) echo "checked"; ?>>
<label class="form-check-label" for="phys2">
Include courses that require physics classification for electricity
</label>
</div>
<br>
<div style="text-align: center;"><input type="submit"/></div>
</form>
<br>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
function foilify($arr)
{
$ret = array();
if (count($arr) == 0) return $ret;
$induction_hypothesis = foilify(array_slice($arr, 1));
foreach ($ret[0] as $item) {
foreach ($induction_hypothesis as $ih) {
$ret_int = array($item);
array_push($ret, array_merge($ret_int, $ih));
}
}
return $ret;
}
function parse_course_string($course_string)
{
$str = str_replace("או", "or", $course_string);
$str = str_replace("ו-", "and", $str);
$or_split = explode("or", $str);
$and_split = explode("and", $str);
$flag = true;
foreach ($or_split as $item)
if (!preg_match("/^\s*\(?.*\)?\s*/", $item)) $flag = false;
if ($flag) { // or central
$ret = array();
foreach ($or_split as $item) {
$contents = explode("and", str_replace("(", "", str_replace(")", "", $item)));
$ret_int = array();
foreach ($contents as $data) array_push($ret_int, trim($data));
array_push($ret, $ret_int);
}
return $ret;
} else { // and central
$ret = array();
foreach ($and_split as $item) {
$contents = explode("or", str_replace("(", "", str_replace(")", "", $item)));
$ret_int = array();
foreach ($contents as $data) array_push($ret_int, trim($data));
array_push($ret, $ret_int);
}
return foilify($ret);
}
}
function check_kdamim($course_string, $courses_took)
{
$parsed = parse_course_string($course_string);
if (count($parsed) == 0) return true;
$flag = false;
foreach ($parsed as $item_set) {
$flag2 = true;
foreach ($item_set as $item) {
if (!in_array(trim($item), $courses_took) && !in_array(substr($item, 0, 6), $courses_took)) {
$flag2 = false;
}
}
if ($flag2) $flag = true;
}
return $flag;
}
if (isset($_POST["bidusa"])) {
$num = rand(10, 100);
for ($i = 2; $i < $num; $i++) {
$flag = true;
for ($j = 2; $j < $i; $j++) if ($i % $j == 0) $flag = false;
if ($flag) echo $i . "<br>";
}
echo "All in O(n)!";
return;
}
if (!isset($_POST["courses"])) return;
$digits = "***";
if (isset($_POST["digits"])) {
if (strlen($_POST["digits"]) == 3) $digits = $_POST["digits"];
else if (strlen($_POST["digits"]) != 0) {
echo "<div> Input into filter must be exactly three characters long! </div>";
}
}
$data = json_decode(file_get_contents("courses_202002.json"), true);
if (!$data) echo "null!";
echo "<table class='table table-hover caption-top'>";
echo "<caption>Courses you can take (with the correct tzmudim):</caption>";
echo "<thead><tr><th>Course Number</th><th>Course Name</th><th>Requirements</th><th>Tzmudim</th></tr>
</thead><tbody>";
$classifications = "";
if (isset($_POST["chem"]) && $_POST["chem"] == "yes") $classifications .= " 123015 ";
if (isset($_POST["phys1"]) && $_POST["phys1"] == "yes") $classifications .= "113013 ";
if (isset($_POST["phys2"]) && $_POST["phys2"] == "yes") $classifications .= "113014";
$courses_took = explode(" ", trim($_POST["courses"] . $classifications));
foreach ($data as $course) {
if (substr($course["general"]["מספר מקצוע"], 0, 3) == $digits || $digits == "***") {
if (isset($_POST["filter"]) && $_POST["filter"] == "yes" && !isset($course["general"]["מקצועות קדם"])) continue;
if (in_array($course["general"]["מספר מקצוע"], $courses_took)) continue;
if (isset($_POST["filter_equiv"]) && $_POST["filter_equiv"] == "yes") {
// assuming these relations are symmetric
if(isset($course["general"]["מקצועות ללא זיכוי נוסף"]))
$no_additional_credit = explode(" ", $course["general"]["מקצועות ללא זיכוי נוסף"]);
else $no_additional_credit = array();
if(isset($course["general"]["מקצועות ללא זיכוי נוסף (מוכלים)"]))
$incorporated = explode(" ", trim($course["general"]["מקצועות ללא זיכוי נוסף (מוכלים)"]));
else $incorporated = array();
if(isset($course["general"]["מקצועות ללא זיכוי נוסף (מכילים)"]))
$incorporating = explode(" ", trim($course["general"]["מקצועות ללא זיכוי נוסף (מכילים)"]));
else $incorporating = array();
$total_no_additional_credit = array_merge($no_additional_credit, $incorporated, $incorporating);
$flag = false;
foreach($total_no_additional_credit as $included_course) {
if(in_array($included_course, $courses_took)) $flag = true;
}
if($flag) continue;
}
if (!isset($course["general"]["מקצועות קדם"]) || check_kdamim($course["general"]["מקצועות קדם"], $courses_took)) {
echo "<tr>";
if (!isset($course["general"]["מקצועות קדם"])) $kdamim = "";
else $kdamim = $course["general"]["מקצועות קדם"];
if (!isset($course["general"]["מקצועות צמודים"])) $tzmudim = "";
else $tzmudim = $course["general"]["מקצועות צמודים"];
echo "<td>" . $course["general"]["מספר מקצוע"] . "</td><td><p dir=\"rtl\">" . $course["general"]["שם מקצוע"] . "</p></td><td><p dir=\"rtl\">" . $kdamim . "</p></td><td><p dir=\"rtl\">" . $tzmudim . "</p></td>";
echo "</tr>";
}
}
}
echo "</tbody></table>";
?>
</div>
</body>
</html>