summaryrefslogtreecommitdiffstats
path: root/modules-available/exams/page.inc.php
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/page.inc.php
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/page.inc.php')
-rw-r--r--modules-available/exams/page.inc.php76
1 files changed, 76 insertions, 0 deletions
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');
+ }
+
+}