summaryrefslogtreecommitdiffstats
path: root/modules-available/exams
diff options
context:
space:
mode:
authorChristian Klinger2016-06-10 17:19:50 +0200
committerChristian Klinger2016-06-10 17:19:50 +0200
commitcab4355fec9928639e688d096d9ad5e77cb28493 (patch)
tree79aa7dc308c4c877bef87f89cf2b88fbe917ef74 /modules-available/exams
parentuse Module:: instead of require (diff)
downloadslx-admin-cab4355fec9928639e688d096d9ad5e77cb28493.tar.gz
slx-admin-cab4355fec9928639e688d096d9ad5e77cb28493.tar.xz
slx-admin-cab4355fec9928639e688d096d9ad5e77cb28493.zip
first rough version of exams-module.
Diffstat (limited to 'modules-available/exams')
-rw-r--r--modules-available/exams/config.json5
-rw-r--r--modules-available/exams/inc/exams.inc.php17
-rw-r--r--modules-available/exams/page.inc.php76
-rw-r--r--modules-available/exams/templates/page-add-exam.html25
-rw-r--r--modules-available/exams/templates/page-exams.html32
5 files changed, 155 insertions, 0 deletions
diff --git a/modules-available/exams/config.json b/modules-available/exams/config.json
new file mode 100644
index 00000000..e109b27b
--- /dev/null
+++ b/modules-available/exams/config.json
@@ -0,0 +1,5 @@
+{
+ "category":"main.status",
+ "dependencies": [ "locations" ],
+ "permission": "0"
+}
diff --git a/modules-available/exams/inc/exams.inc.php b/modules-available/exams/inc/exams.inc.php
new file mode 100644
index 00000000..9e5833ba
--- /dev/null
+++ b/modules-available/exams/inc/exams.inc.php
@@ -0,0 +1,17 @@
+<?php
+
+class Exams {
+
+
+ /**
+ * @param: array of location ids
+ * @return: true iff for any of the given location ids an exam is scheduled
+ **/
+ public static function isInExamMode($locationIds) {
+ // TODO: Better use prepared statement
+ $l = '(' . implode(', ', $locationIds) . ')';
+ $res = Database::queryFirst("SELECT (COUNT(examid) > 0) as examMode FROM exams WHERE starttime < NOW() AND endtime > NOW() AND locationid IN $l", []);
+
+ return $res['examMode'];
+ }
+}
diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php
new file mode 100644
index 00000000..e5129d38
--- /dev/null
+++ b/modules-available/exams/page.inc.php
@@ -0,0 +1,76 @@
+<?php
+
+class Page_Exams extends Page
+{
+ var $action;
+ var $exams;
+ var $locations;
+
+ protected function doPreprocess()
+ {
+ User::load();
+
+ $req_action = Request::get('action', 'show');
+ if (in_array($req_action, ['show', 'add', 'delete'])) {
+ $this->action = $req_action;
+ }
+
+ if ($this->action === 'show') {
+ $tmp = Database::simpleQuery("select * from exams NATURAL LEFT OUTER JOIN location;", []);
+ while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) {
+ $this->exams[] = $exam;
+ }
+ } elseif ($this->action === 'add') {
+ $tmp = Database::simpleQuery("select * from location;", []);
+ while ($loc = $tmp->fetch(PDO::FETCH_ASSOC)) {
+ $this->locations[] = $loc;
+ }
+
+ if (Request::isPost()) {
+ /* process form-data */
+ $locationid = Request::post('location');
+ $starttime = Request::post('starttime');
+ $endtime = Request::post('endtime');
+
+ $res = Database::exec("INSERT INTO exams(locationid, starttime, endtime) VALUES(:locationid, :starttime, :endtime);",
+ compact('locationid', 'starttime', 'endtime'));
+
+ if ($res === false) {
+ Message::addError('exam-not-added');
+ } else {
+ Message::addInfo('exam-added-success');
+ }
+ Util::redirect('?do=exams');
+ }
+
+ } 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'));
+ if ($res === false) {
+ Message::addError('exam-not-deleted-error');
+ } else {
+ Message::addInfo('exam-deleted-success');
+ }
+ Util::redirect('?do=exams');
+ } else {
+ Util::traceError("unknown action");
+ }
+ }
+
+ 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', ['exams' => $this->exams]);
+ } elseif ($this->action === "add") {
+ Render::setTitle("Add Exam");
+ Render::addTemplate('page-add-exam', ['locations' => $this->locations]);
+ }
+ // Render::output('hi');
+ }
+
+}
diff --git a/modules-available/exams/templates/page-add-exam.html b/modules-available/exams/templates/page-add-exam.html
new file mode 100644
index 00000000..b610fcd8
--- /dev/null
+++ b/modules-available/exams/templates/page-add-exam.html
@@ -0,0 +1,25 @@
+<h1>Add Exam</h1>
+
+<form class="form" method="POST" action="?do=exams&action=add">
+ <div class="form-group">
+ <label for="location">Location</label>
+ <select name="location" class="form-control">
+ {{#locations}}
+ <option value="{{locationid}}"> {{locationname}} </option>
+ {{/locations}}
+ </select>
+ </div>
+
+ <div class="form-group">
+ <label for="starttime">Start Time</label>
+ <input class="form-control" type="datetime" name="starttime" />
+ </div>
+
+ <div class="form-group">
+ <label for="endtime">Start Time</label>
+ <input class="form-control" type="datetime" name="endtime" />
+ </div>
+
+ <input type="hidden" name="token" value="{{token}}" />
+ <input type="submit" class="btn btn-success" value="Add Exam"></input>
+</form>
diff --git a/modules-available/exams/templates/page-exams.html b/modules-available/exams/templates/page-exams.html
new file mode 100644
index 00000000..6c67fa2c
--- /dev/null
+++ b/modules-available/exams/templates/page-exams.html
@@ -0,0 +1,32 @@
+
+<h1>All Exams</h1>
+
+<table class="table">
+ <tr>
+ <th>ID</th>
+ <th>Location</th>
+ <th>Begin</th>
+ <th>End</th>
+ <th>Actions</th>
+ </tr>
+ {{#exams}}
+ <tr>
+ <td>{{examid}}</td>
+ <td>
+ <a href="?do=baseconfig&module=locations&locationid={{locationid}}"> {{locationname}} </a>
+ </td>
+ <td>{{starttime}}</td>
+ <td>{{endtime}}</td>
+ <td>
+ <form method="POST" action="?do=exams&action=delete"
+ onsubmit="return confirm('delete really?');">
+ <input type="hidden" name="token" value="{{token}}"/>
+ <input type="hidden" name="examid" value="{{examid}}"/>
+ <input type="submit" value="Delete" class="btn btn-sm" />
+ </form>
+ </td>
+ </tr>
+ {{/exams}}
+
+</table>
+<a href="?do=exams&action=add" class="btn btn-success">Add Exam </a>