Skip to content
Newer
Older
100644 176 lines (166 sloc) 7.11 KB
ac148d1 @phillipberndt Initialized GIT-Repository
authored
1 <?php if(!logged_in()):
8d80058 @phillipberndt Improved registration formular usability
authored
2 require("login.inc.php");
3 else:
ac148d1 @phillipberndt Initialized GIT-Repository
authored
4 $hide_invisible = !(isset($_GET['inv']) && $_GET['inv'] == 1);
5 $only_feed = isset($_GET['f']) && $_GET['f'] ? intval($_GET['f']) : false;
6
22de2a8 @phillipberndt Show main page to moderators even if empty
authored
7 if($database->query('SELECT COUNT(*) FROM user_feeds WHERE user_id = '.user()->id)->fetchColumn() == 0 && user()->level < 1) {
ac148d1 @phillipberndt Initialized GIT-Repository
authored
8 gotop('index.php?q=feeds');
9 }
10
2d59849 @phillipberndt New feature: Direct printing via SSH connections
authored
11 // Rückfrage ob die Drucken Funktion verfügbar ist; per Ajax
12 if(isset($_GET['ajax']) && $_GET['ajax'] == 'can-print') {
13 header('Content-type: application/json');
14 ob_end_clean();
15 die($ssh_printing_enabled && user()->ssh && user()->ssh['validated'] ? 'true' : 'false');
16 }
17
ac148d1 @phillipberndt Initialized GIT-Repository
authored
18 // Notiz ändern
19 if(isset($_POST['note_id']) && isset($_POST['value'])) {
20 ob_end_clean();
21 try {
22 $stmt = $database->prepare('INSERT INTO user_data (data_id, user_id, comment) VALUES (?, ?, ?)');
23 $stmt->execute(array(intval($_POST['note_id']), user()->id, $_POST['value']));
24 }
25 catch(Exception $e) {
26 $stmt = $database->prepare('UPDATE user_data SET comment = ? WHERE data_id = ? AND user_id = ?');
27 $stmt->execute(array($_POST['value'], intval($_POST['note_id']), user()->id));
28 }
29 die();
30 }
31
32 // Sichtbarkeit ändern
33 if($_GET['d']) {
34 if($database->query('SELECT COUNT(*) FROM data WHERE id = '.intval($_GET['d']))->fetchColumn() == 0) die();
35 $value = $database->query('SELECT invisible FROM user_data WHERE data_id = '.intval($_GET['d']).' AND user_id = '.user()->id)->fetchColumn();
36 if($value === false) {
37 $database->exec('INSERT INTO user_data (user_id, data_id, invisible) VALUES ('.user()->id.', '.intval($_GET['d']).', 1)');
38 }
39 else {
40 $database->exec('UPDATE user_data SET invisible = '.($value == 1 ? 0 : 1).' WHERE user_id = '.user()->id.' AND data_id = '.intval($_GET['d']));
41 }
42 if(isset($_GET['ajax'])) {
43 ob_end_clean();
44 die();
45 }
46 gotop('index.php');
47 }
48
49 // Gelesen-Status ändern
50 if($_GET['r']) {
51 if($database->query('SELECT COUNT(*) FROM data WHERE id = '.intval($_GET['r']))->fetchColumn() == 0) die();
52 $value = $database->query('SELECT known FROM user_data WHERE data_id = '.intval($_GET['r']).
53 ' AND user_id = '.user()->id)->fetchColumn();
54 if($value === false) {
55 $database->exec('INSERT INTO user_data (user_id, data_id, known) VALUES ('.user()->id.', '.
56 intval($_GET['r']).', 1)');
57 }
58 else {
59 $database->exec('UPDATE user_data SET known = 1 WHERE user_id = '.
60 user()->id.' AND data_id = '.intval($_GET['r']));
61 }
62 }
63 ?>
64 <div id="content">
65 <h2>Übersicht</h2>
acb2de5 @phillipberndt Store (and inform user) when a feed was last successfully updated
authored
66 <?php
67 // Gibt es Kurse, deren Update im Verzug ist?
68 $update_timestamp = $database->query('SELECT min(update_timestamp) FROM feeds WHERE id IN
69 (SELECT feed_id FROM user_feeds WHERE user_id = ' . user()->id . ')')->fetchColumn();
8b85268 @phillipberndt Made the "outdated" label timeout configurable
authored
70 if($update_timestamp > 0 && $update_timestamp < time() - (isset($outdated_timeout) ? $outdated_timeout : 3600)):
acb2de5 @phillipberndt Store (and inform user) when a feed was last successfully updated
authored
71 ?>
72 <p class="info nomargin"><strong>Achtung:</strong> Die Übungsaufgaben sind nicht aktuell. Ein Feed konnte seit <?php
a47c44e @phillipberndt Fixed the last-update-warning's time display
authored
73 $time = time() - $update_timestamp;
acb2de5 @phillipberndt Store (and inform user) when a feed was last successfully updated
authored
74 $days = floor($time / 86400);
75 $time %= 86400;
76 if($days) echo $days . ' Tage(n), ';
77 echo gmdate('H:i:s', $time);
78 ?> Stunden nicht geladen werden!</p>
79 <?php
80 endif;
81 ?>
ac148d1 @phillipberndt Initialized GIT-Repository
authored
82 <table id="kurse-uebersicht">
83 <tr><th>Kurs</th><th>Zettel</th><th>Notiz</th><th>&nbsp;</th></tr>
84 <?php
85 $descs = array();
86 foreach($database->query('SELECT id, short FROM feeds') as $feed) $descs[$feed['id']] = $feed['short'];
87
88 // Diese ekelige Art mit den Subqueries statt right joins ist leider
89 // für SQLite-Support notwendig (Stand: SQLite 3)
90 $exercises = $database->query('
91 SELECT
92 id, data, feed_id,
93 (SELECT comment FROM user_data WHERE user_id = '.user()->id.' AND data_id = id) AS comment,
94 (SELECT invisible FROM user_data WHERE user_id = '.user()->id.' AND data_id = id) AS invisible,
95 (SELECT known FROM user_data WHERE user_id = '.user()->id.' AND data_id = id) AS known
96 FROM
97 data
98 WHERE feed_id IN (SELECT feed_id FROM user_feeds WHERE user_id = '.user()->id.')'.
ec5fdad @phillipberndt Only deactivate removed sheets instead of removing them
authored
99 ' AND timestamp IS NOT NULL '.
ac148d1 @phillipberndt Initialized GIT-Repository
authored
100 ($only_feed !== false ? ' AND feed_id = '.$only_feed : '').
a6d94c2 @phillipberndt Fixed an SQL-bug when displaying all sheets from a selected feed
authored
101 ' ORDER BY id ASC');
ac148d1 @phillipberndt Initialized GIT-Repository
authored
102
103 $outputted = false;
104 foreach($exercises as $exercise) {
5d66f35 @phillipberndt Added support for PostgreSQL
authored
105 if($exercise['invisible'] && $hide_invisible) continue;
ac148d1 @phillipberndt Initialized GIT-Repository
authored
106 $outputted = true;
bdc4215 @phillipberndt Added the ability to cache all HTTP-Content
authored
107 $formatted_data = format_data($exercise['data'], $exercise['id']);
ac148d1 @phillipberndt Initialized GIT-Repository
authored
108 $classes = ($formatted_data != $data && !$exercise['known']) ? ' neu' : '';
c231dd6 @phillipberndt Added new field "course_url" to feeds
authored
109 echo('<tr class="'.$classes.'" id="data-'.$exercise['id'].'"><td><a class="course-disp-only" href="index.php?inv=' . ($hide_invisible ? 0 : 1 ) .
18fc981 @phillipberndt Restricted combine.php to stored sheets
authored
110 '&amp;f=' . $exercise['feed_id'] . '">'.
ac148d1 @phillipberndt Initialized GIT-Repository
authored
111 htmlspecialchars($descs[$exercise['feed_id']]).'</a></td><td>'.
112 $formatted_data.'</td><td class="editable-note" id="edit-'.$exercise['id'].'">'.
113 htmlspecialchars($exercise['comment']).'</td><td>');
114 echo( '<a class="erledigt" href="index.php?inv=' . ($hide_invisible ? 0 : 1 ) . '&amp;f=' . ($only_feed !== false ? $only_feed : '') .
115 '&amp;d=' . $exercise['id'] . '">'.
116 ($exercise['invisible'] == 1 ? 'Unerledigt' : 'Erledigt').'</a></td></tr>');
117 }
118 if(!$outputted) {
119 echo('<tr><td colspan="4">Derzeit sind keine Aufgaben zu bearbeiten.</td></tr>');
120 }
121 ?>
122 </table>
123 <p class="right small">
124 <a href="index.php?inv=<?=$hide_invisible ? 1 : 0?>&amp;f=<?=$only_feed ? $only_feed : ''?>"><?=$hide_invisible ? 'Erledigte Übungen anzeigen' :
125 'Erledigte Übungen ausblenden'?></a>
126 <?php if($only_feed): ?>
127 | <a href="index.php?inv=<?=$hide_invisible ? 0 : 1?>">Alle Fächer anzeigen</a>
128 <?php endif; ?>
129 </p>
130
c231dd6 @phillipberndt Added new field "course_url" to feeds
authored
131 <div id="course_links">
132 <h3>Links auf Deine Kurse</h3>
133 <ul>
134 <?php
0bca40b @phillipberndt New feature: Multiple (homepage) URLs per Course
authored
135 $course_urls = $database->query('SELECT feed_id, title, url FROM feed_links WHERE feed_id IN
136 (SELECT feed_id FROM user_feeds WHERE user_id = ' . user()->id . ')');
c231dd6 @phillipberndt Added new field "course_url" to feeds
authored
137 foreach($course_urls as $course) {
0bca40b @phillipberndt New feature: Multiple (homepage) URLs per Course
authored
138 echo('<li><a data-id="' . $course['feed_id'] . '" data-title="' . htmlspecialchars($course['title']) . '"
139 href="' . htmlspecialchars($course['url']) . '">' . htmlspecialchars($descs[$course['feed_id']]) . ': ' .
140 htmlspecialchars($course['title']) . '</a></li>');
c231dd6 @phillipberndt Added new field "course_url" to feeds
authored
141 }
142 ?>
143 </ul>
144 </div>
145
8c527a0 @phillipberndt Show suggestions also to moderators
authored
146 <?php if(user()->level >= 1):
ac148d1 @phillipberndt Initialized GIT-Repository
authored
147 if(isset($_GET['delsug'])) {
86280f9 @phillipberndt Status-Messages can now be induced from another session, inform user …
authored
148 $uid = $database->query('SELECT user_id FROM suggestions WHERE id = '.intval($_GET['delsug']))->fetchColumn();
149 if($uid) {
3b0a838 @phillipberndt Gave moderators the ability to answer to suggestions
authored
150 if($_GET['response']) {
151 status_message('Es gibt eine Rückfrage zu Deinem vorgeschlagenen Kurs:<br/>' . htmlspecialchars($_GET['response']), $uid);
152 }
153 else {
154 status_message('Deine vorgeschlagenen Kurse wurden von uns eingestellt! Du kannst sie nun abbonieren.', $uid);
155 }
86280f9 @phillipberndt Status-Messages can now be induced from another session, inform user …
authored
156 }
ac148d1 @phillipberndt Initialized GIT-Repository
authored
157 $database->query('DELETE FROM suggestions WHERE id = '.intval($_GET['delsug']));
158 gotop("index.php");
159 }
160 $suggestions = $database->query('SELECT * FROM suggestions')->fetchAll();
161 if($suggestions):
162 ?>
8c527a0 @phillipberndt Show suggestions also to moderators
authored
163 <h3>Vorschläge</h3>
164 <p>Hier findest Du Vorschläge anderer Benutzer für neue Kurse</p>
165 <ul>
166 <?php
167 foreach($suggestions as $suggestion) {
91baacc @phillipberndt Fixed XSS-Injection-Bug in suggestions
authored
168 echo('<li>'.nl2br(htmlspecialchars($suggestion['text'])).' (<a class="confirm resolve_sug" href="index.php?delsug='.$suggestion['id'].'">Erledigt</a>)</li>');
8c527a0 @phillipberndt Show suggestions also to moderators
authored
169 }
170 ?>
171 </ul>
172 <?php endif;
173 endif; ?>
ac148d1 @phillipberndt Initialized GIT-Repository
authored
174 </div>
175 <?php endif; ?>
Something went wrong with that request. Please try again.