This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
252 lines (239 loc) · 10.6 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
// Check login state
require($_SERVER["DOCUMENT_ROOT"] . "/res/php/session.php");
start_session();
require($_SERVER["DOCUMENT_ROOT"] . "/res/php/checkLogin.php");
if (!checkLogin()) header("Location: https://account.noten-app.de");
// Get config
require($_SERVER["DOCUMENT_ROOT"] . "/config.php");
// Get point system transformer
require($_SERVER["DOCUMENT_ROOT"] . "/res/php/point-system.php");
// DB Connection
$con = mysqli_connect(
$config["db"]["credentials"]["host"],
$config["db"]["credentials"]["user"],
$config["db"]["credentials"]["password"],
$config["db"]["credentials"]["name"]
);
if (mysqli_connect_errno()) exit("Error with the Database");
// Count homework status
// Count for status 0,1 or 2 seperately
if ($stmt = $con->prepare("SELECT status FROM " . $config["db"]["tables"]["homework"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($status);
$status_list = [];
while ($stmt->fetch()) {
array_push($status_list, $status);
}
$stmt->close();
}
$status_count = array_count_values($status_list);
if (!isset($status_count[0])) $status_count[0] = 0;
if (!isset($status_count[1])) $status_count[1] = 0;
if (!isset($status_count[2])) $status_count[2] = 0;
// Get homework due tomorrow or earlier
if ($stmt = $con->prepare("SELECT * FROM " . $config["db"]["tables"]["homework"] . " WHERE user_id = ? AND deadline <= ? AND status = 0 AND year = ?")) {
// If day is sat or sun (and friday - AFTER 15 o clock), set to monday
if (date("N") == 5 && date("H") >= 15) $tomorrow = date("Y-m-d", strtotime("+3 day"));
else if (date("N") == 6) $tomorrow = date("Y-m-d", strtotime("+2 day"));
else $tomorrow = date("Y-m-d", strtotime("+1 day"));
$stmt->bind_param("sss", $_SESSION["user_id"], $tomorrow, $_SESSION["setting_year"]);
$stmt->execute();
$result = $stmt->get_result();
$homework = $result->fetch_all(MYSQLI_ASSOC);
$stmt->close();
}
// Get all subjects
if ($stmt = $con->prepare("SELECT * FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$result = $stmt->get_result();
$subjects = $result->fetch_all(MYSQLI_ASSOC);
}
// Count grades
if ($stmt = $con->prepare("SELECT COUNT(*) FROM " . $config["db"]["tables"]["grades"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($num_of_grades);
$stmt->fetch();
$stmt->close();
}
// Get last inserted grade
if ($stmt = $con->prepare("SELECT grade FROM " . $config["db"]["tables"]["grades"] . " WHERE user_id = ? AND year = ? ORDER BY id DESC LIMIT 1")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($last_grade);
$stmt->fetch();
$stmt->close();
}
// Calculate average
if ($stmt = $con->prepare("SELECT average FROM " . $config["db"]["tables"]["subjects"] . " WHERE user_id = ? AND year = ?")) {
$stmt->bind_param("ss", $_SESSION["user_id"], $_SESSION["setting_year"]);
$stmt->execute();
$stmt->bind_result($average);
$average_list = [];
while ($stmt->fetch()) {
if ($average != 0) array_push($average_list, $average);
}
$stmt->close();
if (count($average_list) == 0) $average = 0;
else $average = array_sum($average_list) / count($average_list);
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home | Noten-App</title>
<link rel="stylesheet" href="/res/fontawesome/css/fontawesome.min.css">
<link rel="stylesheet" href="/res/fontawesome/css/regular.min.css">
<link rel="stylesheet" href="/res/fontawesome/css/solid.min.css">
<link rel="stylesheet" href="/res/css/fonts.css">
<link rel="stylesheet" href="/res/css/main.css">
<link rel="stylesheet" href="/res/css/navbar.css">
<link rel="stylesheet" href="/home/style.css">
<link rel="apple-touch-icon" sizes="180x180" href="/res/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/res/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/res/img/favicon-16x16.png">
<link rel="mask-icon" href="/res/img/safari-pinned-tab.svg" color="#eb660e">
<link rel="shortcut icon" href="/res/img/favicon.ico">
<meta name="apple-mobile-web-app-title" content="Noten-App">
<meta name="application-name" content="Noten-App">
<meta name="msapplication-TileColor" content="#282c36">
<meta name="msapplication-TileImage" content="/res/img/mstile-144x144.png">
<meta name="theme-color" content="#ffffff">
<link rel="manifest" href="/app.webmanifest">
<meta name="msapplication-config" content="/browserconfig.xml">
</head>
<body>
<nav>
<a href="/" class="nav-link nav-active">
<div class="navbar_icon">
<i class="fas fa-home"></i>
</div>
</a>
<a href="/homework/" class="nav-link">
<div class="navbar_icon">
<i class="fas fa-calendar-check"></i>
</div>
</a>
<a href="/subjects/" class="nav-link">
<div class="navbar_icon">
<i class="fas fa-book"></i>
</div>
</a>
</nav>
<main id="main">
<div class="homework_overview card">
<div class="homework">
<canvas id="homework_status_chart"></canvas>
</div>
<div class="homework_sidebutton homework_button-settings" onclick="location.assign('/settings/');">
<div>
<i class="fa-solid fa-gear"></i>
</div>
</div>
<div class="homework_sidebutton homework_button-theme" id="theme-icon" onclick="cycleTheme();">
<div>
<i class="fa-solid fa-circle-half-stroke"></i>
</div>
</div>
</div>
<div class="grades_overview card">
<div class="grade_average-value grades-value noborder">
<?php
if (systemRun("punkte")) echo (number_format(calcToPoints(false, $average), $_SESSION["setting_rounding"], '.', ''));
else if (isset($_SESSION["setting_rounding"])) echo number_format($average, $_SESSION["setting_rounding"], '.', '');
?>
</div>
<div class="grade_average-label grades-label noborder">Total Average</div>
<div class="num_of_grades-value grades-value"><?= $num_of_grades ?></div>
<div class="num_of_grades-label grades-label">Number of Grades</div>
<div class="last_grade-value grades-value">
<?php
if (systemRun("punkte")) echo (number_format(calcToPoints(false, $last_grade)));
else if (isset($_SESSION["setting_rounding"])) echo number_format($last_grade, $_SESSION["setting_rounding"], '.', '');
?>
</div>
<div class="last_grade-label grades-label">Last grade</div>
</div>
<?php if (count($homework) != 0) { ?>
<div class="homework_due card">
<div class="homework_list">
<?php }
if (count($homework) != 0) foreach ($homework as $hw_task) {
echo '<div class="homework_entry">';
echo '<div class="subjectname">';
foreach ($subjects as $subject) if ($subject["id"] == $hw_task["subject"]) echo $subject["name"];
echo '</div><div class="task" onclick="location.assign(\'/homework/edit/?task=' . $hw_task["entry_id"] . '\')"><span>' . $hw_task["text"] . '</span></div>';
echo '<div class="dot" id="dot-' . $hw_task["entry_id"] . '" onclick="toggleState(\'' . $hw_task["entry_id"] . '\')">';
if ($hw_task["status"] == 0) echo '<i class="fa-regular fa-circle"></i></div>';
else if ($hw_task["status"] == 2) echo '<i class="fa-regular fa-circle-xmark"></i></div>';
else echo '<i class="fa-regular fa-check-circle"></i></div>';
switch ($hw_task["type"]) {
case 'b':
echo '<div class="type_badge"><i class="fa-solid fa-book"></i></div>';
break;
case 'w':
echo '<div class="type_badge"><i class="fa-solid fa-sheet-plastic"></i></div>';
break;
case 'v':
echo '<div class="type_badge"><i class="fa-solid fa-language"></i></div>';
break;
}
echo '</div>';
}
if (count($homework) != 0) {
?>
</div>
</div>
<?php } ?>
</main>
<script src="https://assets.noten-app.de/js/themes/themes.js"></script>
<script src="https://assets.noten-app.de/js/jquery/jquery-3.6.1.min.js"></script>
<script src="https://assets.noten-app.de/js/chartjs/chart.min.js"></script>
<script src="/home/state.js"></script>
<script>
new Chart("homework_status_chart", {
type: "doughnut",
data: {
labels: [
'To Do',
'Done',
'Skipped'
],
datasets: [{
data: [<?= $status_count[0] ?>, <?= $status_count[1] ?>, <?= $status_count[2] ?>],
backgroundColor: [
'rgb(255, 99, 132)',
'rgb(54, 235, 162)',
'rgb(54, 54, 54)'
]
}]
},
options: {
borderWidth: 0,
plugins: {
legend: {
display: false
},
title: {
display: true,
text: "Homework Status"
}
}
}
});
</script>
<script>
// Check which tasks are overflowing
document.querySelectorAll(".task").forEach(task => {
if (task.offsetWidth < task.querySelector("span").scrollWidth) task.querySelector("span").classList.add("scroll")
});
</script>
<?php if ($config["tracking"]["matomo"]["on"]) echo ($config["tracking"]["matomo"]["code"]); ?>
</body>
</html>