diff options
author | Simon Rettberg | 2016-06-24 11:25:27 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-06-24 11:25:27 +0200 |
commit | 75b7c70b0130c1d8eff2de03b76d2771f1f19781 (patch) | |
tree | 7a3f834728c47f6f7dc4ed9c61a342afe57fbec3 /modules-available/exams | |
parent | Fix indentation (diff) | |
download | slx-admin-75b7c70b0130c1d8eff2de03b76d2771f1f19781.tar.gz slx-admin-75b7c70b0130c1d8eff2de03b76d2771f1f19781.tar.xz slx-admin-75b7c70b0130c1d8eff2de03b76d2771f1f19781.zip |
[exams] Unify add/edit templates, add error messages, limit zoom range some more
Diffstat (limited to 'modules-available/exams')
-rw-r--r-- | modules-available/exams/lang/de/messages.json | 3 | ||||
-rw-r--r-- | modules-available/exams/lang/de/module.json | 3 | ||||
-rw-r--r-- | modules-available/exams/lang/de/template-tags.json | 1 | ||||
-rw-r--r-- | modules-available/exams/lang/en/messages.json | 5 | ||||
-rw-r--r-- | modules-available/exams/lang/en/template-tags.json | 1 | ||||
-rw-r--r-- | modules-available/exams/page.inc.php | 154 | ||||
-rw-r--r-- | modules-available/exams/templates/page-add-edit-exam.html | 70 | ||||
-rw-r--r-- | modules-available/exams/templates/page-add-exam.html | 61 | ||||
-rw-r--r-- | modules-available/exams/templates/page-edit-exam.html | 61 | ||||
-rw-r--r-- | modules-available/exams/templates/page-exams.html | 3 |
10 files changed, 167 insertions, 195 deletions
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}} +<h1>{{lang_editExam}}</h1> +{{/exam.examid}} +{{^exam.examid}} +<h1>{{lang_addExam}}</h1> +{{/exam.examid}} + +<form class="form" method="POST" action="?do=exams" id="tolleform"> + <div class="form-group"> + <label for="locations">{{lang_location}}</label> + <select id="locations" multiple name="locations[]"> + {{#locations}} + <option value="{{locationid}}" {{#selected}}selected{{/selected}}> {{locationname}}</option> + {{/locations}} + </select> + </div> + + <div class="row"> + <div class="form-group col-xs-6"> + <label for="starttime_date">{{lang_begin_date}}</label> + <input required class="form-control datepicker" name="starttime_date" id="starttime_date" value="{{exam.starttime_date}}"> + </div> + <div class="form-group col-xs-6"> + <label for="starttime_time">{{lang_begin_time}}</label> + <input required type="text" class="form-control timepicker" name="starttime_time" id="starttime_time" value="{{exam.starttime_time}}" + pattern="[0-9]{1,2}:[0-9]{2}"> + </div> + </div> + + <div class="row"> + <div class="form-group col-xs-6"> + <label for="endtime_date">{{lang_end_date}}</label> + <input required class="form-control datepicker" name="endtime_date" id="endtime_date" value="{{exam.endtime_date}}"> + </div> + <div class="form-group col-xs-6"> + <label for="endtime_time">{{lang_end_time}}</label> + <input required type="texxt" class="form-control timepicker" name="endtime_time" id="endtime_time" value="{{exam.endtime_time}}" + pattern="[0-9]{1,2}:[0-9]{2}"> + </div> + </div> + <div class="row"> + <div class="form-group col-xs-12"> + <label for="description">{{lang_description}}</label> + <textarea class="form-control" type="textarea" name="description" id="description">{{exam.description}}</textarea> + </div> + </div> + + <input type="hidden" name="action" value="save"> + <input type="hidden" name="token" value="{{token}}"> + <input type="hidden" name="examid" value="{{exam.examid}}"> + <button class="btn btn-success">{{lang_addExam}}</button> +</form> + +<script type="application/javascript"><!-- +document.addEventListener("DOMContentLoaded", function () { + var dateSettings = { + format: 'yyyy-mm-dd', + weekStart: 1, + startDate: 'today', + }; + var timeSettings = { + showSeconds: false, + showMeridian: false + }; + $('.datepicker').datepicker(dateSettings); + $('.timepicker').timepicker(timeSettings); + + $('#locations').multiselect({numberDisplayed: 1}); +}, false); +// --></script> 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 @@ -<h1>{{lang_addExam}}</h1> - -<form class="form" method="POST" action="?do=exams&action=add"> - <div class="form-group"> - <label for="locations">{{lang_location}}</label> - <select id="locations" multiple="multiple" name="locations[]" class=""> - {{#locations}} - <option value="{{locationid}}"> {{locationname}} </option> - {{/locations}} - </select> - </div> - - <div class="row"> - <div class="form-group col-xs-6"> - <label for="starttime_date">{{lang_begin_date}}</label> - <input required class="form-control datepicker" name="starttime_date" /> - </div> - <div class="form-group col-xs-6"> - <label for="starttime_time">{{lang_begin_time}}</label> - <input required type="text" class="form-control timepicker" name="starttime_time" /> - </div> - </div> - - <div class="row"> - <div class="form-group col-xs-6"> - <label for="endtime_date">{{lang_end_date}}</label> - <input required class="form-control datepicker" name="endtime_date" /> - </div> - <div class="form-group col-xs-6"> - <label for="endtime_time">{{lang_end_time}}</label> - <input required type="texxt" class="form-control timepicker" name="endtime_time" /> - </div> - </div> - <div class="row"> - <div class="form-group col-xs-12"> - <label for="description">{{lang_description}}</label> - <textarea class="form-control" type="textarea" name="description"></textarea> - </div> - </div> - - <input type="hidden" name="token" value="{{token}}" /> - <input type="submit" class="btn btn-success" value="{{lang_addExam}}"></input> -</form> - -<script type="application/javascript"><!-- -document.addEventListener("DOMContentLoaded", function () { - var dateSettings = { - format: 'yyyy-mm-dd', - weekStart: 1, - startDate: 'today', - }; - var timeSettings = { - showSeconds: false, - showMeridian: false - }; - $('.datepicker').datepicker(dateSettings); - $('.timepicker').timepicker(timeSettings); - - $('#locations').multiselect({numberDisplayed: 1}); -}, false); -// --></script> 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 @@ -<h1>{{lang_editExam}}: </h1> - -<form class="form" method="POST" action="?do=exams&action=edit&examid={{exam.examid}}"> - <div class="form-group"> - <label for="locations">{{lang_location}}</label> - <select id="locations" multiple="multiple" name="locations[]" class=""> - {{#locations}} - <option value="{{locationid}}" {{#selected}}selected{{/selected}} > {{locationname}} </option> - {{/locations}} - </select> - </div> - - <div class="row"> - <div class="form-group col-xs-6"> - <label for="starttime_date">{{lang_begin_date}}</label> - <input required class="form-control datepicker" name="starttime_date" value="{{exam.starttime_date}}"/> - </div> - <div class="form-group col-xs-6"> - <label for="starttime_time">{{lang_begin_time}}</label> - <input required type="text" class="form-control timepicker" name="starttime_time" value="{{exam.starttime_time}}" /> - </div> - </div> - - <div class="row"> - <div class="form-group col-xs-6"> - <label for="endtime_date">{{lang_end_date}}</label> - <input required class="form-control datepicker" name="endtime_date" value="{{exam.endtime_date}}"/> - </div> - <div class="form-group col-xs-6"> - <label for="endtime_time">{{lang_end_time}}</label> - <input required type="texxt" class="form-control timepicker" name="endtime_time" value="{{exam.endtime_time}}"/> - </div> - </div> - <div class="row"> - <div class="form-group col-xs-12"> - <label for="description">{{lang_description}}</label> - <textarea class="form-control" type="textarea" name="description">{{exam.description}}</textarea> - </div> - </div> - - <input type="hidden" name="token" value="{{token}}" /> - <input type="submit" class="btn btn-success" value="{{lang_saveExam}}"></input> -</form> - -<script type="application/javascript"><!-- -document.addEventListener("DOMContentLoaded", function () { - var dateSettings = { - format: 'yyyy-mm-dd', - weekStart: 1, - startDate: 'today', - }; - var timeSettings = { - showSeconds: false, - showMeridian: false - }; - $('.datepicker').datepicker(dateSettings); - $('.timepicker').timepicker(timeSettings); - - $('#locations').multiselect({numberDisplayed: 1}); -}, false); -// --></script> 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(); } |