This repository was archived by the owner on May 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcourse.php
More file actions
200 lines (175 loc) · 6.85 KB
/
Copy pathcourse.php
File metadata and controls
200 lines (175 loc) · 6.85 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
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
<!DOCTYPE html>
<html lang="en">
<?php
if (!isset($_GET["course"])) {
exit();
}
$course_nr = $_GET["course"];
$db = new SQLite3('secret/CourseReviews.db');
$stmt = $db->prepare("SELECT NAME FROM COURSES WHERE COURSE=:course");
$stmt->bindParam(':course', $course_nr, SQLITE3_TEXT);
$result = $stmt->execute();
$course = $result->fetchArray();
$course_url = "";
$db->close();
if ($course) {
$course_url = "?course=" . $course_nr;
}
?>
<?php
function getRatingsHead(String $course_nr)
{
$ducky = "https://rubberducky.vsos.ethz.ch:1855/rating/";
$ducky = $ducky . $course_nr;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ducky);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CAINFO, "cacert-2022-04-26.pem");
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code != 200) {
print($code);
return;
}
$js = json_decode($result, false);
$js = json_decode($js, false);
$rating_names = [
"AVG(Recommended)" => "Would <b>recommend</b> it",
"AVG(Interesting)" => "<b>Interesting</b> content",
"AVG(Difficulty)" => "Approriate <b>difficulty</b>",
"AVG(Effort)" => "Approriate amount of <b>effort</b>",
"AVG(Resources)" => "Amount and quality of <b>resources</b>"
];
foreach ($js[0] as $nkey => $stars) {
if ($stars == null) {
continue;
}
//Printing star amount with respective Description
print "[" . $rating_names[$nkey] . ": " . round(doubleval($stars), 2) . "] ";
}
return;
}
?>
<script>
//add ratings body
function addRatings() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
if (this.status == 200) {
var ratings = {
"AVG(Recommended)": "Would <b>recommend</b> it",
"AVG(Interesting)": "<b>Interesting</b> content",
"AVG(Difficulty)": "Approriate <b>difficulty</b>",
"AVG(Effort)": "Approriate amount of <b>effort</b>",
"AVG(Resources)": "Amount and quality of <b>resources</b>"
};
var resp = JSON.parse(JSON.parse(this.responseText))[0];
var stars = document.createElement("div");
for (var key in ratings) {
if (resp[key] == null) {
continue;
}
//body
var div = document.createElement("div");
div.innerHTML = ratings[key];
var starsOuter = document.createElement("div");
starsOuter.classList.add("stars-outer");
var starsInner = document.createElement("div");
starsInner.classList.add("stars-inner");
starsInner.style = "width: " + Math.round(resp[key] * 20) + "%;";
div.appendChild(starsOuter);
starsOuter.appendChild(starsInner);
stars.appendChild(div);
}
document.getElementById("columnA").insertBefore(stars, document.getElementById("reviews"));
}
}
xmlhttp.open("GET", "https://rubberducky.vsos.ethz.ch:1855/rating/" + window.location.href.split("?course=")[1], true);
xmlhttp.send();
}
</script>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy">
<title><?php if ($course) { print $course[0] . " - "; } ?>CourseReview</title>
<link rel="icon" href="icon.png" type="image/icon type">
<meta name="viewport" content="width=device-width">
<meta name="keywords" content="" />
<meta name="description" content="Reviews and ratings on CourseReview of a specific course from ETHZ." />
<link href="main.css" rel="stylesheet" type="text/css" />
<?php
if ($course) {
?>
<meta property="og:image" content="https://n.ethz.ch/~lteufelbe/coursereview/icon.png" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="CourseReview" />
<meta property="og:title" content="<?php print "$course_nr: $course[0]"; ?>" />
<meta property="og:description" content="<?php getRatingsHead($course_nr); ?>" />
<meta property="og:url" content="https://n.ethz.ch/~lteufelbe/coursereview/?course=<?php print htmlspecialchars($course_nr) ?>" />
<?php
} else {
require("meta.php");
?>
<meta property="og:url" content="https://n.ethz.ch/~lteufelbe/coursereview/">
<meta property="og:title" content="CourseReview Homepage">
<?php
}
?>
</head>
<script>
//add reviews
function addReviews() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
if (this.status == 200) {
var resp = JSON.parse(JSON.parse(this.responseText));
var reviews = document.createElement("div");
reviews.id = "reviews";
if (resp.length == 0) {
reviews.textContent = "There is no review here yet. Would be nice if you add one if you took this course.";
} else {
for (var rev of resp) {
reviews.appendChild(document.createElement("br"));
var box = document.createElement("p");
box.classList.add("box");
box.innerText = rev["Review"];
if (rev["Semester"] != null && rev["Semester"].trim() != "") {
var semester = document.createElement("div");
semester.classList.add("semester");
semester.classList.add("box");
semester.textContent = rev["Semester"];
box.appendChild(semester);
}
reviews.appendChild(box);
}
}
document.getElementById("columnA").appendChild(reviews);
}
}
xmlhttp.open("GET", "https://rubberducky.vsos.ethz.ch:1855/course/" + window.location.href.split("?course=")[1], true);
xmlhttp.send();
}
</script>
<body>
<?php include 'includes/menu.php' ?>
<div id="content">
<div id="columnA">
<?php
if ($course) {
print "<b>$course_nr $course[0]</b><br>";
?>
<script>
addRatings();
addReviews();
</script>
<?php
} else {
echo 'This course number is not correct! If you think there should be a course with that number please contact me.';
}
?>
</div>
</div>
<?php include 'includes/footer.php'; ?>
</body>
</html>