From aefcaf9c027febdbd9a51869744d7a6a978b4413 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 23 Jun 2016 17:03:29 +0200 Subject: [exams] Fix vis.js when an exam is active in more than one location (id collision), complete install hook (missing table), limit max. zoom level for vis.js --- modules-available/exams/install.inc.php | 25 +++++++++++++++++------ modules-available/exams/page.inc.php | 16 +++++++-------- modules-available/exams/templates/page-exams.html | 21 ++++++++----------- 3 files changed, 35 insertions(+), 27 deletions(-) (limited to 'modules-available/exams') diff --git a/modules-available/exams/install.inc.php b/modules-available/exams/install.inc.php index b61a0af2..aa8c9a0d 100644 --- a/modules-available/exams/install.inc.php +++ b/modules-available/exams/install.inc.php @@ -3,13 +3,26 @@ $res = array(); $res[] = tableCreate('exams', ' - `examid` int(11) NOT NULL AUTO_INCREMENT, - `starttime` int(11) NOT NULL, - `endtime` int(11) NOT NULL, - `description` varchar(100) DEFAULT NULL, - PRIMARY KEY (`examid`) - '); + `examid` int(11) NOT NULL AUTO_INCREMENT, + `starttime` int(11) NOT NULL, + `endtime` int(11) NOT NULL, + `description` varchar(100) DEFAULT NULL, + PRIMARY KEY (`examid`) + '); +$res[] = tableCreate('exams_x_location', ' + `examid` int(11) NOT NULL, + `locationid` int(11) NOT NULL, + PRIMARY KEY (`examid`, `locationid`) +'); + +if (Database::exec("ALTER TABLE exams ADD INDEX `idx_daterange` ( `starttime` , `endtime` )") === false) { + if (!preg_match('/\b1061\b/', Database::lastError())) { + finalResponse(UPDATE_FAILED, 'Could not add startdate/enddate index: ' . Database::lastError()); + } +} else { + $res[] = UPDATE_DONE; +} if (in_array(UPDATE_DONE, $res)) { finalResponse(UPDATE_DONE, 'Tables created successfully'); diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 20101229..2718cada 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -15,7 +15,7 @@ class Page_Exams extends Page $tmp = Database::simpleQuery("SELECT locationid, locationname FROM location;", []); } else { $tmp = Database::simpleQuery("SELECT locationid, locationname, " . - "EXISTS(SELECT * FROM exams NATURAL JOIN exams_x_locations WHERE locationid = x.locationid AND examid= :examid) AS selected FROM location x", compact('examid')); + "EXISTS(SELECT * FROM exams NATURAL JOIN exams_x_location WHERE locationid = x.locationid AND examid= :examid) AS selected FROM location x", compact('examid')); } while ($loc = $tmp->fetch(PDO::FETCH_ASSOC)) { $this->locations[] = $loc; @@ -26,7 +26,7 @@ class Page_Exams extends Page { $tmp = Database::simpleQuery("select examid, starttime, endtime, description, GROUP_CONCAT(locationid) AS locationids, " . "GROUP_CONCAT(locationname) AS locationnames FROM " - . "exams NATURAL LEFT JOIN exams_x_locations NATURAL LEFT JOIN location GROUP BY examid", []); + . "exams NATURAL LEFT JOIN exams_x_location NATURAL LEFT JOIN location GROUP BY examid", []); while ($exam = $tmp->fetch(PDO::FETCH_ASSOC)) { $this->exams[] = $exam; } @@ -76,7 +76,7 @@ class Page_Exams extends Page foreach ($this->lectures as $l) { $mark = ''; $out[] = [ - 'id' => $l['lectureid'], + 'id' => $l['lectureid'] . '/' . $l['locationid'], 'content' => htmlspecialchars($l['displayname']) . $mark , 'title' => $l['isenabled'] ? '' : Dictionary::translate('warning_lecture_is_not_enabled'), 'start' => intval($l['starttime']) * 1000, @@ -147,7 +147,7 @@ class Page_Exams extends Page $exam_id = Database::lastInsertId(); foreach ($locationids as $lid) { - $res = $res && Database::exec("INSERT INTO exams_x_locations(examid, locationid) VALUES(:exam_id, :lid)", compact('exam_id', 'lid')); + $res = $res && Database::exec("INSERT INTO exams_x_location(examid, locationid) VALUES(:exam_id, :lid)", compact('exam_id', 'lid')); } @@ -163,7 +163,7 @@ class Page_Exams extends Page 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')); - $res = Database::exec("DELETE FROM exams_x_locations WHERE examid = :examid;", compact('examid')); + $res = Database::exec("DELETE FROM exams_x_location WHERE examid = :examid;", compact('examid')); if ($res === false) { Message::addError('exam-not-deleted-error'); } else { @@ -190,10 +190,10 @@ class Page_Exams extends Page $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_locations WHERE examid = :examid", compact('examid')); + $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_locations(examid, locationid) VALUES(:examid, :lid)", compact('examid', '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"); @@ -219,7 +219,7 @@ class Page_Exams extends Page [ 'exams' => $this->makeExamsForTemplate(), 'exams_json' => $this->makeItemsForVis(), 'rooms_json' => $this->makeGroupsForVis(), - 'vis_begin' => time() * 1000, + 'vis_begin' => strtotime('-5 minute') * 1000, 'vis_end' => strtotime('+2 day') * 1000, 'vis_min_date' => strtotime('-1 day') * 1000, 'vis_max_date' => strtotime('+3 month') * 1000 diff --git a/modules-available/exams/templates/page-exams.html b/modules-available/exams/templates/page-exams.html index 3efe377a..9cd1d4c0 100644 --- a/modules-available/exams/templates/page-exams.html +++ b/modules-available/exams/templates/page-exams.html @@ -17,18 +17,12 @@ {{starttime}} {{endtime}} - +
+ {{lang_edit}} + + + +
{{/exams}} @@ -69,8 +63,9 @@ document.addEventListener("DOMContentLoaded", function () { 'end' : {{vis_end}}, 'stack' : false, 'editable' : false, - 'min' : {{vis_begin}}, + 'min' : {{vis_min_date}}, 'max' : {{vis_max_date}}, + 'zoomMin': 2 * 3600 * 1000, 'order' : customOrder, 'locale' : language, 'moment' : function(date) { return vis.moment(date).utc(); } -- cgit v1.2.3-55-g7522