From 75b7c70b0130c1d8eff2de03b76d2771f1f19781 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Jun 2016 11:25:27 +0200 Subject: [exams] Unify add/edit templates, add error messages, limit zoom range some more --- modules-available/exams/lang/de/messages.json | 3 +- modules-available/exams/lang/de/module.json | 3 + modules-available/exams/lang/de/template-tags.json | 1 + modules-available/exams/lang/en/messages.json | 5 +- modules-available/exams/lang/en/template-tags.json | 1 + modules-available/exams/page.inc.php | 154 +++++++++++---------- .../exams/templates/page-add-edit-exam.html | 70 ++++++++++ .../exams/templates/page-add-exam.html | 61 -------- .../exams/templates/page-edit-exam.html | 61 -------- modules-available/exams/templates/page-exams.html | 3 +- 10 files changed, 167 insertions(+), 195 deletions(-) create mode 100644 modules-available/exams/templates/page-add-edit-exam.html delete mode 100644 modules-available/exams/templates/page-add-exam.html delete mode 100644 modules-available/exams/templates/page-edit-exam.html (limited to 'modules-available/exams') diff --git a/modules-available/exams/lang/de/messages.json b/modules-available/exams/lang/de/messages.json index b2c1e451..01be29fd 100644 --- a/modules-available/exams/lang/de/messages.json +++ b/modules-available/exams/lang/de/messages.json @@ -4,5 +4,6 @@ "exam-added-success": "Klausurzeitraum erfolgreich hinzugef\u00fcgt", "exam-deleted-success": "Klausurzeitraum erfolgreich gel\u00f6scht", "exam-not-added": "Klausurzeitraum konnte nicht hinzugef\u00fcgt werden", - "exam-not-deleted-error": "Klausurzeitraum konnte nicht gel\u00f6scht werden" + "exam-not-deleted-error": "Klausurzeitraum konnte nicht gel\u00f6scht werden", + "invalid-exam-id": "Ung\u00fcltige Klausur-ID: {{0}}" } \ No newline at end of file diff --git a/modules-available/exams/lang/de/module.json b/modules-available/exams/lang/de/module.json index 3c0038a7..226810fd 100644 --- a/modules-available/exams/lang/de/module.json +++ b/modules-available/exams/lang/de/module.json @@ -1,3 +1,6 @@ { + "module_name": "Klausurmodus", + "title_add-exam": "Klausur hinzuf\u00fcgen", + "title_edit-exam": "Klausur bearbeiten", "warning_lecture_is_not_enabled": "Warnung: Diese Vorlesung ist nicht vom Dozenten aktiviert" } \ No newline at end of file diff --git a/modules-available/exams/lang/de/template-tags.json b/modules-available/exams/lang/de/template-tags.json index 430599f9..ab138d65 100644 --- a/modules-available/exams/lang/de/template-tags.json +++ b/modules-available/exams/lang/de/template-tags.json @@ -14,5 +14,6 @@ "lang_id": "ID", "lang_location": "Raum\/Ort", "lang_locations": "R\u00e4ume\/Orte", + "lang_pleaseSelectLocation": "Bitte w\u00e4hlen Sie mindestens einen Raum\/Ort", "lang_saveExam": "Klausurzeitraum speichern" } \ No newline at end of file diff --git a/modules-available/exams/lang/en/messages.json b/modules-available/exams/lang/en/messages.json index 83db3414..a684a82c 100644 --- a/modules-available/exams/lang/en/messages.json +++ b/modules-available/exams/lang/en/messages.json @@ -1,6 +1,9 @@ { + "changes-successfully-saved": "Changes successfully saved", + "error-while-saving-changes": "Error saving changes", "exam-added-success": "Exam period successfully added", "exam-deleted-success": "Exam period successfully deleted", "exam-not-added": "Exam period was not added", - "exam-not-deleted-error": "Exam period was not deleted" + "exam-not-deleted-error": "Exam period was not deleted", + "invalid-exam-id": "Invalid exam id: {{0}}" } \ No newline at end of file diff --git a/modules-available/exams/lang/en/template-tags.json b/modules-available/exams/lang/en/template-tags.json index 502cf44d..b1b0ab0a 100644 --- a/modules-available/exams/lang/en/template-tags.json +++ b/modules-available/exams/lang/en/template-tags.json @@ -14,5 +14,6 @@ "lang_id": "ID", "lang_location": "Room\/Location", "lang_locations": "Rooms\/Locations", + "lang_pleaseSelectLocation": "Please select at least one room\/location", "lang_saveExam": "Save Exam Period" } \ No newline at end of file diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 2718cada..211ae5ac 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -2,10 +2,11 @@ class Page_Exams extends Page { - var $action; + var $action = false; var $exams; var $locations; var $lectures; + private $currentExam; /** if examid is set, also add a column 'selected' **/ @@ -114,52 +115,98 @@ class Page_Exams extends Page } return $out; } + + private function saveExam() + { + if (!Request::isPost()) { + Util::traceError('Is not post'); + } + /* process form-data */ + $locationids = Request::post('locations', [], "ARRAY"); + + /* global room has id 0 */ + if(empty($locationids)) { + $locationids[] = 0; + } + + $examid = Request::post('examid', 0, 'int'); + $starttime = strtotime(Request::post('starttime_date') . " " . Request::post('starttime_time')); + $endtime = strtotime(Request::post('endtime_date') . " " . Request::post('endtime_time')); + $description = Request::post('description'); + + if ($examid === 0) { + // No examid given, is add + $res = Database::exec("INSERT INTO exams(starttime, endtime, description) VALUES(:starttime, :endtime, :description);", + compact('starttime', 'endtime', 'description')) !== false; + + $exam_id = Database::lastInsertId(); + foreach ($locationids as $lid) { + $res = $res && Database::exec("INSERT INTO exams_x_location(examid, locationid) VALUES(:exam_id, :lid)", compact('exam_id', 'lid')) !== false; + } + if ($res === false) { + Message::addError('exam-not-added'); + } else { + Message::addInfo('exam-added-success'); + } + Util::redirect('?do=exams'); + } + + // Edit + + $this->currentExam = Database::queryFirst("SELECT * FROM exams WHERE examid = :examid", array('examid' => $examid)); + if ($this->currentExam === false) { + Message::addError('invalid-exam-id', $examid); + Util::redirect('?do=exams'); + } + + /* update fields */ + $res = Database::exec("UPDATE exams SET starttime = :starttime, endtime = :endtime, description = :description WHERE examid = :examid", + compact('starttime', 'endtime', 'description', 'examid')) !== false; + /* drop all connections and reconnect to rooms */ + $res = $res && Database::exec("DELETE FROM exams_x_location WHERE examid = :examid", compact('examid')) !== false; + /* reconnect */ + foreach ($locationids as $lid) { + $res = $res && Database::exec("INSERT INTO exams_x_location(examid, locationid) VALUES(:examid, :lid)", compact('examid', 'lid')) !== false; + } + if ($res !== FALSE) { + Message::addInfo("changes-successfully-saved"); + } else { + Message::addError("error-while-saving-changes"); + } + Util::redirect('?do=exams'); + } + protected function doPreprocess() { User::load(); - $req_action = Request::get('action', 'show'); - if (in_array($req_action, ['show', 'add', 'delete', 'edit'])) { + $req_action = Request::any('action', 'show'); + if (in_array($req_action, ['show', 'add', 'delete', 'edit', 'save'])) { $this->action = $req_action; } if ($this->action === 'show') { + $this->readExams(); $this->readLocations(); $this->readLectures(); - } elseif ($this->action === 'add') { - $this->readLocations(); - if (Request::isPost()) { - /* process form-data */ - $locationids = Request::post('locations', [], "ARRAY"); - - /* global room has id 0 */ - if(empty($locationids)) { - $locationids[] = 0; - } - - $starttime = strtotime(Request::post('starttime_date') . " " . Request::post('starttime_time')); - $endtime = strtotime(Request::post('endtime_date') . " " . Request::post('endtime_time')); - $description = Request::post('description'); - - $res = Database::exec("INSERT INTO exams(starttime, endtime, description) VALUES(:starttime, :endtime, :description);", - compact('starttime', 'endtime', 'description')); - - $exam_id = Database::lastInsertId(); - foreach ($locationids as $lid) { - $res = $res && Database::exec("INSERT INTO exams_x_location(examid, locationid) VALUES(:exam_id, :lid)", compact('exam_id', 'lid')); - } + } elseif ($this->action === 'edit') { - if ($res === false) { - Message::addError('exam-not-added'); - } else { - Message::addInfo('exam-added-success'); - } + $examid = Request::get('examid', 0, 'int'); + $this->currentExam = Database::queryFirst("SELECT * FROM exams WHERE examid = :examid", array('examid' => $examid)); + if ($this->currentExam === false) { + Message::addError('invalid-exam-id', $examid); Util::redirect('?do=exams'); } + $this->readLocations($examid); + + } elseif ($this->action === 'save') { + + $this->saveExam(); } elseif ($this->action === 'delete') { + if (!Request::isPost()) { die('delete only works with a post request'); } $examid = Request::post('examid'); $res = Database::exec("DELETE FROM exams WHERE examid = :examid;", compact('examid')); @@ -170,49 +217,16 @@ class Page_Exams extends Page Message::addInfo('exam-deleted-success'); } Util::redirect('?do=exams'); - } elseif ($this->action === 'edit') { - $examid = Request::get('examid', -1, 'int'); - $this->readLocations($examid); - $this->currentExam = Database::queryFirst("SELECT * FROM exams WHERE examid = :examid", array('examid' => $examid)); - if (Request::isPost()) { - $locationids = Request::post('locations', [], "ARRAY"); - - /* global room has id 0 */ - if(empty($locationids)) { - $locationids[] = 0; - } + } elseif ($this->action === false) { - $starttime = strtotime(Request::post('starttime_date') . " " . Request::post('starttime_time')); - $endtime = strtotime(Request::post('endtime_date') . " " . Request::post('endtime_time')); - $description = Request::post('description'); - /* update fields */ - $res = Database::exec("UPDATE exams SET starttime = :starttime, endtime = :endtime, description = :description WHERE examid = :examid", - compact('starttime', 'endtime', 'description', 'examid')); - /* drop all connections and reconnect to rooms */ - $res = $res !== FALSE && Database::exec("DELETE FROM exams_x_location WHERE examid = :examid", compact('examid')); - /* reconnect */ - foreach ($locationids as $lid) { - $res = $res !== FALSE && Database::exec("INSERT INTO exams_x_location(examid, locationid) VALUES(:examid, :lid)", compact('examid', 'lid')); - } - if ($res !== FALSE) { - Message::addInfo("changes-successfully-saved"); - } else { - Message::addError("error-while-saving-changes"); - } - Util::redirect('?do=exams'); - } - - } else { Util::traceError("action not implemented"); + } } protected function doRender() { - // Render::setTitle(Dictionary::translate('lang_exams')); - //Render::addTemplate('page-exams', $_POST); - if ($this->action === "show") { Render::setTitle("All Exams"); Render::addTemplate('page-exams', @@ -225,10 +239,11 @@ class Page_Exams extends Page 'vis_max_date' => strtotime('+3 month') * 1000 ]); } elseif ($this->action === "add") { - Render::setTitle("Add Exam"); - Render::addTemplate('page-add-exam', ['locations' => $this->locations]); + Render::setTitle(Dictionary::translate('title_add-exam')); + $this->readLocations(); + Render::addTemplate('page-add-edit-exam', ['locations' => $this->locations]); } elseif ($this->action === 'edit') { - Render::setTitle("Edit Exam"); + Render::setTitle(Dictionary::translate('title_edit-exam')); $exam = [ 'examid' => $this->currentExam['examid'], 'starttime_date' => date('Y-m-d', $this->currentExam['starttime']), @@ -237,9 +252,8 @@ class Page_Exams extends Page 'endtime_time' => date('H:i', $this->currentExam['endtime']), 'description' => $this->currentExam['description'] ]; - Render::addTemplate('page-edit-exam', ['exam' => $exam, 'locations' => $this->locations]); + Render::addTemplate('page-add-edit-exam', ['exam' => $exam, 'locations' => $this->locations]); } - // Render::output('hi'); } } diff --git a/modules-available/exams/templates/page-add-edit-exam.html b/modules-available/exams/templates/page-add-edit-exam.html new file mode 100644 index 00000000..26cbf8bc --- /dev/null +++ b/modules-available/exams/templates/page-add-edit-exam.html @@ -0,0 +1,70 @@ +{{#exam.examid}} +

{{lang_editExam}}

+{{/exam.examid}} +{{^exam.examid}} +

{{lang_addExam}}

+{{/exam.examid}} + +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + + + + +
+ + diff --git a/modules-available/exams/templates/page-add-exam.html b/modules-available/exams/templates/page-add-exam.html deleted file mode 100644 index 89a7881a..00000000 --- a/modules-available/exams/templates/page-add-exam.html +++ /dev/null @@ -1,61 +0,0 @@ -

{{lang_addExam}}

- -
-
- - -
- -
-
- - -
-
- - -
-
- -
-
- - -
-
- - -
-
-
-
- - -
-
- - - -
- - diff --git a/modules-available/exams/templates/page-edit-exam.html b/modules-available/exams/templates/page-edit-exam.html deleted file mode 100644 index 61848ec2..00000000 --- a/modules-available/exams/templates/page-edit-exam.html +++ /dev/null @@ -1,61 +0,0 @@ -

{{lang_editExam}}:

- -
-
- - -
- -
-
- - -
-
- - -
-
- -
-
- - -
-
- - -
-
-
-
- - -
-
- - - -
- - diff --git a/modules-available/exams/templates/page-exams.html b/modules-available/exams/templates/page-exams.html index c714ed2b..b2483d6e 100644 --- a/modules-available/exams/templates/page-exams.html +++ b/modules-available/exams/templates/page-exams.html @@ -65,7 +65,8 @@ document.addEventListener("DOMContentLoaded", function () { 'editable' : false, 'min' : {{vis_min_date}}, 'max' : {{vis_max_date}}, - 'zoomMin': 2 * 3600 * 1000, + 'zoomMin': 6 * 3600 * 1000, + 'zoomMax': 2 * 86400 * 1000, 'order' : customOrder, 'locale' : language, 'moment' : function(date) { return vis.moment(date).utc(); } -- cgit v1.2.3-55-g7522