-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.php
More file actions
83 lines (67 loc) · 1.68 KB
/
func.php
File metadata and controls
83 lines (67 loc) · 1.68 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
<?php
// CURL Request Template
function sendRequest($curl, $url, $method, $body = Null) {
$prepare = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
// CURLOPT_HTTPHEADER => [],
];
if($method == "POST"){
$prepare[CURLOPT_POSTFIELDS] = $body;
}
curl_setopt_array($curl, $prepare);
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
exit("ERROR (cURL) - " . $err);
}
if (curl_getinfo($curl)['http_code'] != 200) {
echo("STATUS " . curl_getinfo($curl)['http_code']);
var_dump($response);
exit("ERROR");
}
return($response);
}
function getScheduleForQuarter($curl, $student_id, $quarter) {
$url = "https://portalproxy.uchicago.edu/coursecalendar?termid=" . $quarter . "&emplid=" . $student_id . "";
//echo($url . "<br/>");
$r = sendRequest(
$curl,
$url,
"GET"
);
return($r);
}
function quarterIdToString($quarter_id) {
$quarter_string = "";
$quarter_id = strval($quarter_id);
// Get Season
$last_digit = substr($quarter_id, -1);
switch($last_digit) {
case 2:
$quarter_string = $quarter_string . "Winter";
break;
case 4:
$quarter_string = $quarter_string . "Spring";
break;
case 6:
$quarter_string = $quarter_string . "Summer";
break;
case 8:
$quarter_string = $quarter_string . "Fall";
break;
default:
$quarter_string = $quarter_string . "Unknown";
}
// Get Year
$year = intval(substr($quarter_id, 0, 3)) + 1800;
$quarter_string = $quarter_string . " " . $year;
return($quarter_string);
}
?>