From c535ce5e2f78f5223662c97543f718334abf2a35 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Tue, 8 Sep 2020 20:56:19 +0200 Subject: [locations] Migrate openingtimes from infoscreen to locations module - move openingtimes from infoscreen db to locations db - read-only openingtimes in infoscreen --- .../locationinfo/inc/infopanel.inc.php | 2 +- modules-available/locationinfo/install.inc.php | 3 +- .../locationinfo/lang/de/template-tags.json | 2 +- .../locationinfo/lang/en/template-tags.json | 2 +- modules-available/locationinfo/page.inc.php | 97 ++--------- .../templates/ajax-config-location.html | 93 ++++++----- .../locationinfo/templates/page-locations.html | 27 ---- modules-available/locations/clientscript.js | 153 ++++++++++++++++++ modules-available/locations/config.json | 8 +- modules-available/locations/install.inc.php | 22 +++ .../locations/lang/de/template-tags.json | 14 ++ .../locations/lang/en/template-tags.json | 14 ++ modules-available/locations/pages/details.inc.php | 177 +++++++++++++++++++++ .../locations/templates/ajax-opening-location.html | 173 ++++++++++++++++++++ .../locations/templates/location-subnets.html | 44 ++++- .../locations/templates/locations.html | 5 + 16 files changed, 674 insertions(+), 162 deletions(-) create mode 100644 modules-available/locations/clientscript.js create mode 100644 modules-available/locations/templates/ajax-opening-location.html (limited to 'modules-available') diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php index 001f31ea..af32c1ed 100644 --- a/modules-available/locationinfo/inc/infopanel.inc.php +++ b/modules-available/locationinfo/inc/infopanel.inc.php @@ -169,7 +169,7 @@ class InfoPanel $allIds = self::getLocationsWithParents($idList); if (empty($allIds)) return; - $res = Database::simpleQuery("SELECT locationid, openingtime FROM locationinfo_locationconfig + $res = Database::simpleQuery("SELECT locationid, openingtime FROM location WHERE locationid IN (:lids)", array('lids' => $allIds)); $openingTimes = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php index 7e58315b..42bc8234 100644 --- a/modules-available/locationinfo/install.inc.php +++ b/modules-available/locationinfo/install.inc.php @@ -6,7 +6,6 @@ $t1 = $res[] = tableCreate('locationinfo_locationconfig', ' `locationid` INT(11) NOT NULL, `serverid` INT(10) UNSIGNED, `serverlocationid` VARCHAR(150), - `openingtime` BLOB, `calendar` BLOB, `lastcalendarupdate` INT(10) UNSIGNED NOT NULL DEFAULT 0, `lastuse` INT(10) UNSIGNED NOT NULL DEFAULT 0, @@ -53,7 +52,7 @@ if ($t1 === UPDATE_NOOP) { Database::exec('INSERT INTO locationinfo_panel (paneluuid, panelname, locationids, paneltype, panelconfig, lastchange)' . " SELECT UUID(), Concat('Import: ', l.locationname), o.locationid, 'DEFAULT', o.config, 0 " . " FROM locationinfo_locationconfig o INNER JOIN location l USING (locationid)" - . ' WHERE Length(o.config) > 10 OR Length(o.openingtime) > 10'); + . ' WHERE Length(o.config) > 10'); } Database::exec("ALTER TABLE locationinfo_locationconfig CHANGE `serverid` `serverid` INT(10) UNSIGNED NULL"); tableDropColumn('locationinfo_locationconfig', 'hidden'); diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json index 2879184e..90a38885 100644 --- a/modules-available/locationinfo/lang/de/template-tags.json +++ b/modules-available/locationinfo/lang/de/template-tags.json @@ -55,7 +55,7 @@ "lang_locationSettings": "Raum-\/Ortsbezogene Einstellungen", "lang_locations": "Orte", "lang_locationsTable": "R\u00e4ume \/ Orte", - "lang_locationsTableHints": "Hier k\u00f6nnen Sie f\u00fcr die R\u00e4ume und Orte Ihrer Einrichtung \u00d6ffnungszeiten hinterlegen, sowie die Verkn\u00fcpfung mit Raum-IDs aus konfigurierten Backends (z.B. HISinOne) vornehmen, damit Belegungspl\u00e4ne abgerufen werden k\u00f6nnen.", + "lang_locationsTableHints": "Hier k\u00f6nnen Sie f\u00fcr die R\u00e4ume und Orte Ihrer Einrichtung die Verkn\u00fcpfung mit Raum-IDs aus konfigurierten Backends (z.B. HISinOne) vornehmen, damit Belegungspl\u00e4ne abgerufen werden k\u00f6nnen.", "lang_locsHint": "Hier k\u00f6nnen Sie die Orte ausw\u00e4hlen, die in diesem Panel angezeigt werden.", "lang_longFri": "Freitag", "lang_longMon": "Montag", diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json index ba743dfb..64846ab6 100644 --- a/modules-available/locationinfo/lang/en/template-tags.json +++ b/modules-available/locationinfo/lang/en/template-tags.json @@ -55,7 +55,7 @@ "lang_locationSettings": "Location specific settings", "lang_locations": "Locations", "lang_locationsTable": "Rooms \/ Locations", - "lang_locationsTableHints": "Here you can define opening times for your locations and link the location ID to a configured backend (e.g. HISinOne) to show calendar events.", + "lang_locationsTableHints": "Here you can link the location ID to a configured backend (e.g. HISinOne) to show calendar events.", "lang_locsHint": "You can pick up the locations that will be shown in this panel.", "lang_longFri": "Friday", "lang_longMon": "Monday", diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index ee50bc9c..8032642d 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -167,101 +167,20 @@ class Page_LocationInfo extends Page $ignoreServer = 0; } - // Opening times - $openingtimes = Request::post('openingtimes', '', 'string'); - if ($openingtimes !== '') { - $openingtimes = json_decode($openingtimes, true); - if (!is_array($openingtimes)) { - $openingtimes = ''; - } else { - $mangled = array(); - foreach (array_keys($openingtimes) as $key) { - $entry = $openingtimes[$key]; - if (!isset($entry['days']) || !is_array($entry['days']) || empty($entry['days'])) { - Message::addError('ignored-line-no-days'); - continue; - } - $s = $this->getTime($entry['openingtime']); - $e = $this->getTime($entry['closingtime']); - if ($s === false) { - Message::addError('ignored-invalid-start', $entry['openingtime']); - continue; - } - if ($e === false) { - Message::addError('ignored-invalid-end', $entry['closingtime']); - continue; - } - if ($e <= $s) { - Message::addError('ignored-invalid-range', $entry['openingtime'], $entry['closingtime']); - continue; - } - unset($entry['tag']); - $mangled[] = $entry; - } - if (empty($mangled)) { - $openingtimes = null; - } else { - $openingtimes = json_encode($mangled); - } - } - } $NOW = time(); - // Check if openingtimes changed - $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :locationid', compact('locationid')); - $otChanged = $res === false || $res['openingtime'] !== $openingtimes; - Database::exec("INSERT INTO `locationinfo_locationconfig` (locationid, serverid, serverlocationid, openingtime, lastcalendarupdate, lastchange) - VALUES (:id, :insertserverid, :serverlocationid, :openingtimes, 0, :now) + Database::exec("INSERT INTO `locationinfo_locationconfig` (locationid, serverid, serverlocationid, lastcalendarupdate, lastchange) + VALUES (:id, :insertserverid, :serverlocationid, 0, :now) ON DUPLICATE KEY UPDATE serverid = IF(:ignore_server AND serverid IS NULL, NULL, :serverid), serverlocationid = VALUES(serverlocationid), - openingtime = VALUES(openingtime), lastcalendarupdate = 0, lastchange = VALUES(lastchange)", array( + lastcalendarupdate = 0, lastchange = VALUES(lastchange)", array( 'id' => $locationid, 'insertserverid' => $insertServerId, 'serverid' => $serverid, - 'openingtimes' => $openingtimes, 'serverlocationid' => $serverlocationid, 'ignore_server' => $ignoreServer, 'now' => $NOW, )); - if ($otChanged) { - $tree = Location::getLocationsAssoc(); - $todo = array(); - $done = array(); - foreach ($tree as $l) { - if ($l['parentlocationid'] == $locationid) { - $todo[] = $l['locationid']; - } - } - while (!empty($todo)) { - $loc = array_pop($todo); - if (in_array($loc, $done)) - continue; - $done[] = $loc; - // See if this one inherits - $res = Database::queryFirst('SELECT openingtime FROM locationinfo_locationconfig WHERE locationid = :loc', compact('loc')); - if ($res === false) { - $res = Database::exec('INSERT INTO locationinfo_locationconfig (locationid, lastchange) - VALUES (:locationid, :now) ON DUPLICATE KEY UPDATE lastchange = :now', - array('locationid' => $loc, 'now' => $NOW)); - } elseif (strlen($res['openingtime']) < 5) { - $res = Database::exec('UPDATE locationinfo_locationconfig SET lastchange = :now, openingtime = NULL - WHERE locationid = :locationid', - array('locationid' => $loc, 'now' => $NOW)); - } else { - $res = 0; - } - if ($res > 0) { - // Row was updated, which means the openingtime column was empty, which means the openingtime is inherited, descend further - $todo = array_merge($todo, $tree[$loc]['children']); - foreach ($tree as $l) { - if ($l['parentlocationid'] == $loc) { - $todo[] = $l['locationid']; - } - } - } - } - } - if ($changeServerRecursive) { // Recursive overwriting of serverid $children = Location::getRecursiveFlat($locationid); @@ -612,9 +531,10 @@ class Page_LocationInfo extends Page $locations = Location::getLocations(0, 0, false, true); // Get hidden state of all locations - $dbquery = Database::simpleQuery("SELECT li.locationid, li.serverid, li.serverlocationid, li.openingtime, li.lastcalendarupdate, cb.servertype, cb.servername + $dbquery = Database::simpleQuery("SELECT li.locationid, li.serverid, li.serverlocationid, loc.openingtime, li.lastcalendarupdate, cb.servertype, cb.servername FROM `locationinfo_locationconfig` AS li - LEFT JOIN `locationinfo_coursebackend` AS cb USING (serverid)"); + LEFT JOIN `locationinfo_coursebackend` AS cb USING (serverid) + LEFT JOIN `location` AS loc USING (locationid)"); while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) { $locid = (int)$row['locationid']; @@ -780,7 +700,10 @@ class Page_LocationInfo extends Page private function ajaxConfigLocation($id) { User::assertPermission('location.edit', $id); - $locConfig = Database::queryFirst("SELECT serverid, serverlocationid, openingtime FROM `locationinfo_locationconfig` WHERE locationid = :id", array('id' => $id)); + $locConfig = Database::queryFirst("SELECT info.serverid, info.serverlocationid, loc.openingtime + FROM `locationinfo_locationconfig` AS info + LEFT JOIN `location` AS loc USING (locationid) + WHERE locationid = :id", array('id' => $id)); if ($locConfig !== false) { $openingtimes = json_decode($locConfig['openingtime'], true); } else { diff --git a/modules-available/locationinfo/templates/ajax-config-location.html b/modules-available/locationinfo/templates/ajax-config-location.html index 47d4ba8a..f7e96b9d 100644 --- a/modules-available/locationinfo/templates/ajax-config-location.html +++ b/modules-available/locationinfo/templates/ajax-config-location.html @@ -4,11 +4,7 @@ {{^expertMode}}
-
- {{lang_expertMode}} -
- @@ -19,57 +15,57 @@ @@ -78,21 +74,15 @@ {{/expertMode}}
-
-
{{lang_day}}
-
{{lang_delete}}
{{lang_openingTime}}
-
{{lang_closingTime}}
+
{{lang_closingTime}}
+
{{lang_delete}}
+
@@ -105,7 +95,7 @@ @@ -143,6 +133,33 @@ + + diff --git a/modules-available/locations/templates/location-subnets.html b/modules-available/locations/templates/location-subnets.html index 6062b559..b85ddbec 100644 --- a/modules-available/locations/templates/location-subnets.html +++ b/modules-available/locations/templates/location-subnets.html @@ -62,7 +62,7 @@
{{lang_locationInfo}}
-
+
{{#haveDozmod}}
{{lang_referencingLectures}}: {{lectures}} @@ -81,7 +81,13 @@
{{/haveStatistics}}
-
+
+ +
+
{{#roomplanner}} @@ -91,7 +97,7 @@ {{/roomplanner}}
-
+
@@ -130,4 +136,34 @@
-
\ No newline at end of file +
+ + + + \ No newline at end of file diff --git a/modules-available/locations/templates/locations.html b/modules-available/locations/templates/locations.html index 7adfe2fc..12d401c1 100644 --- a/modules-available/locations/templates/locations.html +++ b/modules-available/locations/templates/locations.html @@ -250,5 +250,10 @@ function deleteSubnetWarning(locid) { form.submit(); } } + +function loadOpeningTimes(locid) { + $("#openingTimesModal" + locid).find('.modal-body').load("?do=Locations&page=details&action=getOpeningtimes&locid=" + locid) +} + // --> -- cgit v1.2.3-55-g7522
{{lang_day}}
{{lang_monTilFr}} -
+
- +
-
+
- +
{{lang_saturday}} -
+
- +
-
+
- +
{{lang_sunday}} -
+
- +
-
+
- +