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 pathmain.php
More file actions
155 lines (138 loc) · 6.17 KB
/
Copy pathmain.php
File metadata and controls
155 lines (138 loc) · 6.17 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
<!DOCTYPE html>
<html lang="en">
<?php
$token = file_get_contents("secret/key.txt");
$api = trim(file_get_contents("secret/api.txt"));
?>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy">
<title>CourseReview</title>
<?php include "meta.php" ?>
<meta property="og:url" content="https://n.ethz.ch/~lteufelbe/coursereview/">
<meta property="og:title" content="CourseReview Homepage">
<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="Homepage of CourseReview, list of last reviewed Courses, search to find reviews of courses and other links to helpful stuff about ETHZ." />
<link href="main.css" rel="stylesheet" type="text/css" />
<?php
if (isset($_POST["course"])) {
$course = $_POST["course"] . " ";
$course = substr($course, 0, strpos($course, " "));
$db = new SQLite3('secret/CourseReviews.db');
$stmt = $db->prepare("SELECT NAME FROM COURSES WHERE COURSE=:course");
$stmt->bindParam(':course', $course, SQLITE3_TEXT);
$result = $stmt->execute();
if ($result->fetchArray()) {
echo "<meta http-equiv=\"Refresh\" content=\"0; url='?course=$course'\" />)";
$db->close();
exit();
}
$db->close();
}
?>
</head>
<script>
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
if (this.status === 200) {
var dataList = document.getElementById("courses");
var jsonOptions = JSON.parse(this.responseText);
jsonOptions.forEach(function(item) {
var option = document.createElement('option');
option.value = item;
dataList.appendChild(option);
});
}
}
xmlhttp.open("GET", "https://n.ethz.ch/~lteufelbe/coursereview/courses.json", true);
xmlhttp.send();
}
</script>
<body>
<?php include 'includes/menu.php' ?>
<div id="content">
<div id="columnA">
<?php
if (isset($_POST["course"])) {
$db = new SQLite3('secret/CourseReviews.db');
$stmt = $db->prepare("SELECT * FROM COURSES WHERE NAME Like '%' || REPLACE(:input, ' ', '%') || '%' limit 10;");
$stmt->bindParam(':input', $_POST["course"], SQLITE3_TEXT);
$result = $stmt->execute();
?>
Your search didn't find an exact result, so here are the closest ones: <br>
<ol>
<?php
while ($row = $result->fetchArray()) {
?>
<li><a href="<?php echo "?course=" . htmlspecialchars($row[0]); ?>"><?php echo htmlspecialchars($row[0]) . " <b>" . htmlspecialchars($row[1]) . "</b>"; ?></a></li>
<?php
}
$db->close();
?>
</ol>
<?php
}
?>
<form method="post" action="#">
<input id="search" list="courses" name="course" placeholder="Search for Reviews">
<datalist id="courses">
</datalist>
<input id="searchbutton" type="submit" value="Search">
</form>
<script>
//get stats
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
if (this.status == 200) {
var total = document.getElementById("total");
var percourse = document.getElementById("percourse");
var resp = JSON.parse(JSON.parse(this.responseText))[0];
total.textContent = resp.total;
percourse.textContent = resp.percourse;
}
}
xmlhttp.open("GET", "https://rubberducky.vsos.ethz.ch:1855/stats", true);
xmlhttp.send();
}
//get latest
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
if (this.status == 200) {
var latest = document.getElementById("latest");
var resp = JSON.parse(JSON.parse(this.responseText));
for (row of resp) {
var li = document.createElement("li");
var link = document.createElement("a");
link.textContent = row.CourseName;
link.href = "?course=" + row.CourseNumber;
li.appendChild(link);
latest.appendChild(li);
}
}
}
xmlhttp.open("GET", "https://rubberducky.vsos.ethz.ch:1855/latestReviews", true);
xmlhttp.send();
}
</script>
<h3>Welcome!</h3>
<p>Here you can add and read reviews of courses from ETHZ!</p>
<a href="add/">Add a review!</a> <br>
<a href="edit/">Edit your existing reviews!</a> <br>
<a href="all.php">All courses with reviews!</a> <br>
<a href="https://ergebnisseub.sp.ethz.ch/" target="_blank">Results of the Teaching evaluation</a> <br>
<a href="https://addons.mozilla.org/en-GB/firefox/addon/vvz-coursereview/" target="_blank">VVZ extension for Firefox</a> <br>
<a href="https://chrome.google.com/webstore/detail/vvz-coursereview/pjgjdmehkhpdhlpdgfbbpgekfajlhhgn" target="_blank">VVZ extension for Chrome</a> <br>
<b id="total"> </b> reviews & ratings for <b id="percourse"> </b> courses have been published so far.
<br> Courses with the newest Reviews:
<ul id="latest">
</ul>
</div>
</div>
<?php include 'includes/footer.php'; ?>
</body>
</html>