diff options
Diffstat (limited to 'modules-available/exams/page.inc.php')
-rw-r--r-- | modules-available/exams/page.inc.php | 76 |
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'); + } + +} |