diff options
author | Simon Rettberg | 2017-07-25 19:02:01 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-07-25 19:02:01 +0200 |
commit | bb53f6136e2950f3d656728be469d318a0d9f606 (patch) | |
tree | 4e8648ff6fde4b8496eba6e19afdfd7bf542c241 /modules-available | |
parent | [locationinfo] Better error handling in hisinone backend (diff) | |
download | slx-admin-bb53f6136e2950f3d656728be469d318a0d9f606.tar.gz slx-admin-bb53f6136e2950f3d656728be469d318a0d9f606.tar.xz slx-admin-bb53f6136e2950f3d656728be469d318a0d9f606.zip |
[locationinfo] Make panel accessible via slxadmin, add URL type panel
Diffstat (limited to 'modules-available')
17 files changed, 687 insertions, 414 deletions
diff --git a/modules-available/locationinfo/frontend/jquery-week-calendar/jquery.weekcalendar.js b/modules-available/js_weekcalendar/clientscript.js index 28b9e3cf..28b9e3cf 100755 --- a/modules-available/locationinfo/frontend/jquery-week-calendar/jquery.weekcalendar.js +++ b/modules-available/js_weekcalendar/clientscript.js diff --git a/modules-available/locationinfo/frontend/jquery-week-calendar/jquery.weekcalendar.css b/modules-available/js_weekcalendar/style.css index aae8f956..aae8f956 100755 --- a/modules-available/locationinfo/frontend/jquery-week-calendar/jquery.weekcalendar.css +++ b/modules-available/js_weekcalendar/style.css diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index 05af4111..e14fe9d7 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -1,5 +1,37 @@ <?php +if (Request::get('redirect', false, 'int') !== false) { + // Redirect to actual panel from uuid + $uuid = Request::get('uuid', false, 'string'); + if ($uuid === false) { + http_response_code(400); + die('Missing uuid parameter'); + } + $row = Database::queryFirst('SELECT paneltype, panelconfig FROM locationinfo_panel WHERE paneluuid = :uuid', compact('uuid')); + if ($row === false) { + http_response_code(404); + die('Panel not found'); + } + if ($row['paneltype'] === 'DEFAULT') { + Util::redirect(dirname($_SERVER['SCRIPT_NAME']) . '/modules/locationinfo/frontend/doorsign.html?uuid=' . $uuid); + } elseif ($row['paneltype'] === 'SUMMARY') { + Util::redirect(dirname($_SERVER['SCRIPT_NAME']) . '/modules/locationinfo/frontend/overview.html?uuid=' . $uuid); + } elseif ($row['paneltype'] === 'URL') { + $data = json_decode($row['panelconfig'], true); + if (!$data || !isset($data['url'])) { + http_response_code('500'); + die('Panel config corrupted on server'); + } + Util::redirect($data['url']); + } + http_response_code('500'); + die('Panel has invalid type "' . $row['paneltype'] . '"'); +} + +/* + * vvv - API to Panel - vvv + */ + HandleParameters(); /** @@ -16,10 +48,14 @@ function HandleParameters() } elseif ($get === "machines") { $locationIds = getLocationsOr404($uuid); $output = array(); - appendMachineData($output, $locationIds, false); + InfoPanel::appendMachineData($output, $locationIds, false); $output = array_values($output); } elseif ($get === "config") { - $output = getConfig($uuid); + $type = InfoPanel::getConfig($uuid, $output); + if ($type === false) { + http_response_code(404); + die('Panel not found'); + } } elseif ($get === "pcstates") { $locationIds = getLocationsOr404($uuid); $output = getPcStates($locationIds); @@ -55,213 +91,6 @@ function getLocationsOr404($paneluuid) die('Panel not found'); } -// ########## <Locationinfo> ########## -/** - * Gets the location info of the given locations. - * Append to passed array which is expected to - * map location ids to properties of that location. - * A new key 'machines' will be created in each - * entry of $array that will take all the machine data. - * - * @param array $array location list to populate with machine data - * @param bool $withPosition Defines if coords should be included or not. - */ -function appendMachineData(&$array, $idList = false, $withPosition = false) -{ - if (empty($array) && $idList === false) - return; - if ($idList === false) { - $idList = array_keys($array); - } - - $positionCol = $withPosition ? 'm.position,' : ''; - $query = "SELECT m.locationid, m.machineuuid, $positionCol m.logintime, m.lastseen, m.lastboot FROM machine m - WHERE m.locationid IN (:idlist)"; - $dbquery = Database::simpleQuery($query, array('idlist' => $idList)); - - // Iterate over matching machines - while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) { - settype($row['locationid'], 'int'); - if (!isset($array[$row['locationid']])) { - $array[$row['locationid']] = array('id' => $row['locationid'], 'machines' => array()); - } - if (!isset($array[$row['locationid']]['machines'])) { - $array[$row['locationid']]['machines'] = array(); - } - // Compact the pc data in one array. - $pc = array('id' => $row['machineuuid']); - if ($withPosition && !empty($row['position'])) { - $position = json_decode($row['position'], true); - if (isset($position['gridCol']) && isset($position['gridRow'])) { - $pc['x'] = $position['gridCol']; - $pc['y'] = $position['gridRow']; - if (!empty($position['overlays']) && is_array($position['overlays'])) { - $pc['overlays'] = $position['overlays']; - } - } - } - $pc['pcState'] = LocationInfo::getPcState($row); - //$pc['pcState'] = ['BROKEN', 'OFF', 'IDLE', 'OCCUPIED'][mt_rand(0,3)]; // XXX - - // Add the array to the machines list. - $array[$row['locationid']]['machines'][] = $pc; - } -} - -// ########## </Locationinfo> ########### - -/** - * Returns all the passed location ids and appends - * all their direct and indirect parent location ids. - * - * @param int[] $idList location ids - * @return int[] more location ids - */ -function getLocationsWithParents($idList) -{ - $locations = Location::getLocationsAssoc(); - $allIds = $idList; - foreach ($idList as $id) { - if (isset($locations[$id]) && isset($locations[$id]['parents'])) { - $allIds = array_merge($allIds, $locations[$id]['parents']); - } - } - return array_map('intval', $allIds); -} - -// ########## <Openingtime> ########## -/** - * Gets the Opening time of the given locations. - * - * @param array $array list of locations, indexed by locationId - * @param int[] $idList list of locations - */ -function appendOpeningTimes(&$array, $idList) -{ - // First, lets get all the parent ids for the given locations - // in case we need to get inherited opening times - $allIds = getLocationsWithParents($idList); - if (empty($allIds)) - return; - $res = Database::simpleQuery("SELECT locationid, openingtime FROM locationinfo_locationconfig - WHERE locationid IN (:lids)", array('lids' => $allIds)); - $openingTimes = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $openingTimes[(int)$row['locationid']] = $row; - } - // Now we got all the calendars for locations and parents - // Iterate over the locations we're actually interested in - $locations = Location::getLocationsAssoc(); - foreach ($idList as $locationId) { - // Start checking at actual location... - $currentId = $locationId; - while ($currentId !== 0) { - if (!empty($openingTimes[$currentId]['openingtime'])) { - $cal = json_decode($openingTimes[$currentId]['openingtime'], true); - if (is_array($cal)) { - $cal = formatOpeningtime($cal); - } - if (!empty($cal)) { - // Got a valid calendar - if (!isset($array[$locationId])) { - $array[$locationId] = array('id' => $locationId); - } - $array[$locationId]['openingtime'] = $cal; - break; - } - } - // Keep trying with parent - $currentId = $locations[$currentId]['parentlocationid']; - } - } - return; -} - -/** - * Format the openingtime in the frontend needed format. - * One key per week day, wich contains an array of { - * 'HourOpen' => hh, 'MinutesOpen' => mm, - * 'HourClose' => hh, 'MinutesClose' => mm } - * - * @param array $openingtime The opening time in the db saved format. - * @return mixed The opening time in the frontend needed format. - */ -function formatOpeningtime($openingtime) -{ - $result = array(); - foreach ($openingtime as $entry) { - $openTime = explode(':', $entry['openingtime']); - $closeTime = explode(':', $entry['closingtime']); - if (count($openTime) !== 2 || count($closeTime) !== 2) - continue; - $convertedTime = array( - 'HourOpen' => $openTime[0], - 'MinutesOpen' => $openTime[1], - 'HourClose' => $closeTime[0], - 'MinutesClose' => $closeTime[1], - ); - foreach ($entry['days'] as $day) { - if (!isset($result[$day])) { - $result[$day] = array(); - } - $result[$day][] = $convertedTime; - } - } - return $result; -} - -// ########## </Openingtime> ########## -/** - * Gets the config of the location. - * - * @param int $locationID ID of the location - * @return array configuration struct - */ -function getConfig($paneluuid) -{ - $panel = Database::queryFirst('SELECT panelconfig, paneltype, locationids, lastchange FROM locationinfo_panel WHERE paneluuid = :paneluuid', - compact('paneluuid')); - - if ($panel === false || empty($panel['locationids'])) { - http_response_code(404); - die('Panel not found'); - } - - $config = LocationInfo::defaultPanelConfig($panel['paneltype']); - $locations = Location::getLocationsAssoc(); - $overrides = false; - - if (!empty($panel['panelconfig'])) { - $json = json_decode($panel['panelconfig'], true); - if (is_array($json)) { - if (isset($json['overrides']) && is_array($json['overrides'])) { - $overrides = $json['overrides']; - } - unset($json['overrides']); - $config = $json + $config; - } - } - $config['locations'] = array(); - $lids = array_map('intval', explode(',', $panel['locationids'])); - foreach ($lids as $lid) { - $config['locations'][$lid] = array( - 'id' => $lid, - 'name' => isset($locations[$lid]) ? $locations[$lid]['locationname'] : 'noname00.pas', - ); - if (isset($overrides[$lid]) && is_array($overrides[$lid])) { - $config['locations'][$lid]['config'] = $overrides[$lid]; - } - } - appendMachineData($config['locations'], $lids, true); - appendOpeningTimes($config['locations'], $lids); - - $config['ts'] = (int)$panel['lastchange']; - $config['locations'] = array_values($config['locations']); - $config['time'] = date('Y-n-j-G-') . (int)date('i') . '-' . (int)(date('s')); - - return $config; -} - /** * Get last config modification timestamp for given panel. * This was planned to be smart and check the involved locations, @@ -309,7 +138,7 @@ function getPcStates($idList) } $locationInfoList = array(); - appendMachineData($locationInfoList, $idList); + InfoPanel::appendMachineData($locationInfoList, $idList); foreach ($locationInfoList as $locationInfo) { $id = $locationInfo['id']; foreach ($locationInfo['machines'] as $pc) { diff --git a/modules-available/locationinfo/clientscript.js b/modules-available/locationinfo/clientscript.js index a2a8ee1f..f9872e02 100644 --- a/modules-available/locationinfo/clientscript.js +++ b/modules-available/locationinfo/clientscript.js @@ -36,7 +36,7 @@ const allDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturd * Adds a new opening time to the table in expert mode. */ function newOpeningTime(vals) { - var $row = $('#expert-template div.row').clone(); + var $row = $('#expert-template').find('div.row').clone(); if (vals['days'] && Array.isArray(vals['days'])) { for (var i = 0; i < allDays.length; ++i) { $row.find('.i-' + allDays[i]).attr('checked', vals['days'].indexOf(allDays[i]) !== -1); diff --git a/modules-available/locationinfo/frontend/jquery-week-calendar/jquery.weekcalendar.iml b/modules-available/locationinfo/frontend/jquery-week-calendar/jquery.weekcalendar.iml deleted file mode 100755 index 0f7b5ef4..00000000 --- a/modules-available/locationinfo/frontend/jquery-week-calendar/jquery.weekcalendar.iml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module relativePaths="true" type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$" /> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> - diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php new file mode 100644 index 00000000..66ee0ae7 --- /dev/null +++ b/modules-available/locationinfo/inc/infopanel.inc.php @@ -0,0 +1,219 @@ +<?php + +class InfoPanel +{ + + /** + * Gets the config of the location. + * + * @param int $locationID ID of the location + * @param mixed $config the panel config will be returned here + * @return string|bool paneltype, false if not exists + */ + public static function getConfig($paneluuid, &$config) + { + $panel = Database::queryFirst('SELECT panelname, panelconfig, paneltype, locationids, lastchange FROM locationinfo_panel WHERE paneluuid = :paneluuid', + compact('paneluuid')); + + if ($panel === false) { + return false; + } + + if ($panel['paneltype'] === 'URL') { + $config = json_decode($panel['panelconfig'], true); + return $panel['paneltype']; + } + + $config = LocationInfo::defaultPanelConfig($panel['paneltype']); + $locations = Location::getLocationsAssoc(); + $overrides = false; + + if (!empty($panel['panelconfig'])) { + $json = json_decode($panel['panelconfig'], true); + if (is_array($json)) { + if (isset($json['overrides']) && is_array($json['overrides'])) { + $overrides = $json['overrides']; + } + unset($json['overrides']); + $config = $json + $config; + } + } + if (isset($config['showtitle']) && $config['showtitle']) { + $config['title'] = $panel['title']; + } + $config['locations'] = array(); + $lids = array_map('intval', explode(',', $panel['locationids'])); + foreach ($lids as $lid) { + $config['locations'][$lid] = array( + 'id' => $lid, + 'name' => isset($locations[$lid]) ? $locations[$lid]['locationname'] : 'noname00.pas', + ); + if (isset($overrides[$lid]) && is_array($overrides[$lid])) { + $config['locations'][$lid]['config'] = $overrides[$lid]; + } + } + self::appendMachineData($config['locations'], $lids, true); + self::appendOpeningTimes($config['locations'], $lids); + + $config['ts'] = (int)$panel['lastchange']; + $config['locations'] = array_values($config['locations']); + $config['time'] = date('Y-n-j-G-') . (int)date('i') . '-' . (int)(date('s')); + + return $panel['paneltype']; + } + + /** + * Gets the location info of the given locations. + * Append to passed array which is expected to + * map location ids to properties of that location. + * A new key 'machines' will be created in each + * entry of $array that will take all the machine data. + * + * @param array $array location list to populate with machine data + * @param bool $withPosition Defines if coords should be included or not. + */ + public static function appendMachineData(&$array, $idList = false, $withPosition = false) + { + if (empty($array) && $idList === false) + return; + if ($idList === false) { + $idList = array_keys($array); + } + + $positionCol = $withPosition ? 'm.position,' : ''; + $query = "SELECT m.locationid, m.machineuuid, $positionCol m.logintime, m.lastseen, m.lastboot FROM machine m + WHERE m.locationid IN (:idlist)"; + $dbquery = Database::simpleQuery($query, array('idlist' => $idList)); + + // Iterate over matching machines + while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) { + settype($row['locationid'], 'int'); + if (!isset($array[$row['locationid']])) { + $array[$row['locationid']] = array('id' => $row['locationid'], 'machines' => array()); + } + if (!isset($array[$row['locationid']]['machines'])) { + $array[$row['locationid']]['machines'] = array(); + } + // Compact the pc data in one array. + $pc = array('id' => $row['machineuuid']); + if ($withPosition && !empty($row['position'])) { + $position = json_decode($row['position'], true); + if (isset($position['gridCol']) && isset($position['gridRow'])) { + $pc['x'] = $position['gridCol']; + $pc['y'] = $position['gridRow']; + if (!empty($position['overlays']) && is_array($position['overlays'])) { + $pc['overlays'] = $position['overlays']; + } + } + } + $pc['pcState'] = LocationInfo::getPcState($row); + //$pc['pcState'] = ['BROKEN', 'OFF', 'IDLE', 'OCCUPIED'][mt_rand(0,3)]; // XXX + + // Add the array to the machines list. + $array[$row['locationid']]['machines'][] = $pc; + } + } + + /** + * Gets the Opening time of the given locations. + * + * @param array $array list of locations, indexed by locationId + * @param int[] $idList list of locations + */ + public static function appendOpeningTimes(&$array, $idList) + { + // First, lets get all the parent ids for the given locations + // in case we need to get inherited opening times + $allIds = self::getLocationsWithParents($idList); + if (empty($allIds)) + return; + $res = Database::simpleQuery("SELECT locationid, openingtime FROM locationinfo_locationconfig + WHERE locationid IN (:lids)", array('lids' => $allIds)); + $openingTimes = array(); + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + $openingTimes[(int)$row['locationid']] = $row; + } + // Now we got all the calendars for locations and parents + // Iterate over the locations we're actually interested in + $locations = Location::getLocationsAssoc(); + foreach ($idList as $locationId) { + // Start checking at actual location... + $currentId = $locationId; + while ($currentId !== 0) { + if (!empty($openingTimes[$currentId]['openingtime'])) { + $cal = json_decode($openingTimes[$currentId]['openingtime'], true); + if (is_array($cal)) { + $cal = self::formatOpeningtime($cal); + } + if (!empty($cal)) { + // Got a valid calendar + if (!isset($array[$locationId])) { + $array[$locationId] = array('id' => $locationId); + } + $array[$locationId]['openingtime'] = $cal; + break; + } + } + // Keep trying with parent + $currentId = $locations[$currentId]['parentlocationid']; + } + } + return; + } + + + /** + * Returns all the passed location ids and appends + * all their direct and indirect parent location ids. + * + * @param int[] $idList location ids + * @return int[] more location ids + */ + private static function getLocationsWithParents($idList) + { + $locations = Location::getLocationsAssoc(); + $allIds = $idList; + foreach ($idList as $id) { + if (isset($locations[$id]) && isset($locations[$id]['parents'])) { + $allIds = array_merge($allIds, $locations[$id]['parents']); + } + } + return array_map('intval', $allIds); + } + +// ########## <Openingtime> ########## + + /** + * Format the openingtime in the frontend needed format. + * One key per week day, wich contains an array of { + * 'HourOpen' => hh, 'MinutesOpen' => mm, + * 'HourClose' => hh, 'MinutesClose' => mm } + * + * @param array $openingtime The opening time in the db saved format. + * @return mixed The opening time in the frontend needed format. + */ + private static function formatOpeningtime($openingtime) + { + $result = array(); + foreach ($openingtime as $entry) { + $openTime = explode(':', $entry['openingtime']); + $closeTime = explode(':', $entry['closingtime']); + if (count($openTime) !== 2 || count($closeTime) !== 2) + continue; + $convertedTime = array( + 'HourOpen' => $openTime[0], + 'MinutesOpen' => $openTime[1], + 'HourClose' => $closeTime[0], + 'MinutesClose' => $closeTime[1], + ); + foreach ($entry['days'] as $day) { + if (!isset($result[$day])) { + $result[$day] = array(); + } + $result[$day][] = $convertedTime; + } + } + return $result; + } + +}
\ No newline at end of file diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php index 6e6cfcd7..a5feb9ed 100644 --- a/modules-available/locationinfo/inc/locationinfo.inc.php +++ b/modules-available/locationinfo/inc/locationinfo.inc.php @@ -64,6 +64,7 @@ class LocationInfo 'mode' => 1, 'vertical' => false, 'eco' => false, + 'prettytime' => true, 'scaledaysauto' => true, 'daystoshow' => 7, 'rotation' => 0, @@ -88,10 +89,21 @@ class LocationInfo public static function configHook($machineUuid, $panelUuid) { - // TODO Panel type + $row = Database::queryFirst('SELECT paneltype, panelconfig FROM locationinfo_panel WHERE paneluuid = :uuid', + array('uuid' => $panelUuid)); + if ($row === false) { + // TODO: Invalid panel - what should we do? + } elseif ($row['paneltype'] === 'URL') { + // Check if we should set the insecure SSL mode (accept invalid/self signed certs etc.) + $data = json_decode($row['panelconfig'], true); + if ($data && $data['insecure-ssl']) { + ConfigHolder::add('SLX_BROWSER_INSECURE', '1'); + } + } ConfigHolder::add('SLX_BROWSER_URL', 'http://' . $_SERVER['SERVER_ADDR'] . '/panel/' . $panelUuid); ConfigHolder::add('SLX_ADDONS', '', 1000); - ConfigHolder::add('SLX_LOGOUT_TIMEOUT', 1000); + ConfigHolder::add('SLX_LOGOUT_TIMEOUT', '', 1000); + ConfigHolder::add('SLX_SCREEN_STANDBY_TIMEOUT', '', 1000); } } diff --git a/modules-available/locationinfo/install.inc.php b/modules-available/locationinfo/install.inc.php index a738a863..10422241 100644 --- a/modules-available/locationinfo/install.inc.php +++ b/modules-available/locationinfo/install.inc.php @@ -26,7 +26,7 @@ $t3 = $res[] = tableCreate('locationinfo_panel', " `paneluuid` char(36) CHARACTER SET ascii NOT NULL, `panelname` varchar(30) NOT NULL, `locationids` varchar(20) CHARACTER SET ascii NOT NULL, - `paneltype` enum('DEFAULT','SUMMARY') NOT NULL, + `paneltype` enum('DEFAULT','SUMMARY', 'URL') NOT NULL, `panelconfig` blob NOT NULL, `lastchange` int(10) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`paneluuid`), @@ -67,6 +67,11 @@ if ($t1 === UPDATE_DONE) { } } +if ($t3 === UPDATE_NOOP) { + Database::exec("ALTER TABLE `locationinfo_panel` CHANGE `paneltype` + `paneltype` ENUM('DEFAULT', 'SUMMARY', 'URL') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); +} + // Create response for browser if (in_array(UPDATE_RETRY, $res)) { diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json index 9b30a14a..1574d9e8 100644 --- a/modules-available/locationinfo/lang/de/template-tags.json +++ b/modules-available/locationinfo/lang/de/template-tags.json @@ -91,5 +91,22 @@ "lang_typeTooltip": "Legt fest um welchen Server-Typ es sich handelt", "lang_updateRates": "Aktualisierungsintervall", "lang_vertical": "Vertikaler Modus", - "lang_verticalTooltip": "Legt fest, ob Kalender und Raum \u00fcbereinander angezeigt werden sollen" + "lang_verticalTooltip": "Legt fest, ob Kalender und Raum \u00fcbereinander angezeigt werden sollen", + "lang_closed": "Geschlossen", + "lang_free": "Frei", + "lang_shortSun": "So", + "lang_shortMon": "Mo", + "lang_shortTue": "Di", + "lang_shortWed": "Mi", + "lang_shortThu": "Do", + "lang_shortFri": "Fr", + "lang_shortSat": "Sa", + "lang_longSun": "Sonntag", + "lang_longMon": "Montag", + "lang_longTue": "Dienstag", + "lang_longWed": "Mittwoch", + "lang_longThu": "Donnerstag", + "lang_longFri": "Freitag", + "lang_longSat": "Samstag", + "lang_to": "bis" }
\ No newline at end of file diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json index ae308281..900839a9 100644 --- a/modules-available/locationinfo/lang/en/template-tags.json +++ b/modules-available/locationinfo/lang/en/template-tags.json @@ -87,5 +87,22 @@ "lang_typeTooltip": "Defines on which type of server you want to connect to", "lang_updateRates": "Update rates", "lang_vertical": "Vertical mode", - "lang_verticalTooltip": "Defines whether the room and calendar are shown above each other" + "lang_verticalTooltip": "Defines whether the room and calendar are shown above each other", + "lang_closed": "Closed", + "lang_free": "Free", + "lang_shortSun": "Sun", + "lang_shortMon": "Mon", + "lang_shortTue": "Tue", + "lang_shortWed": "Wed", + "lang_shortThu": "Thu", + "lang_shortFri": "Fri", + "lang_shortSat": "Sat", + "lang_longSun": "Sunday", + "lang_longMon": "Monday", + "lang_longTue": "Tuesday", + "lang_longWed": "Wednesday", + "lang_longThu": "Thursday", + "lang_longFri": "Friday", + "lang_longSat": "Saturday", + "lang_to": "to" }
\ No newline at end of file diff --git a/modules-available/locationinfo/lang/pt/template-tags.json b/modules-available/locationinfo/lang/pt/template-tags.json new file mode 100644 index 00000000..e5c2aba8 --- /dev/null +++ b/modules-available/locationinfo/lang/pt/template-tags.json @@ -0,0 +1,21 @@ +{ + "lang_room": "Quarto", + "lang_closed": "Fechado", + "lang_free": "Livre", + "lang_shortSun": "Do", + "lang_shortMon": "Se", + "lang_shortTue": "Te", + "lang_shortWed": "Qu", + "lang_shortThu": "Qu", + "lang_shortFri": "Se", + "lang_shortSat": "Sá", + "lang_longSun": "Domingo", + "lang_longMon": "Segunda-feira", + "lang_longTue": "Terça-feira", + "lang_longWed": "Quarta-feira", + "lang_longThu": "Quinta-feira", + "lang_longFri": "Sexta-feira", + "lang_longSat": "Sábado", + "lang_to": "para" + +}
\ No newline at end of file diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index f5e64209..f8aa1c5b 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -10,13 +10,16 @@ class Page_LocationInfo extends Page */ protected function doPreprocess() { + $show = Request::any('show', '', 'string'); + if ($show === 'panel') { + $this->showPanel(); + exit(0); + } User::load(); if (!User::isLoggedIn()) { Message::addError('main.no-permission'); Util::redirect('?do=Main'); // does not return } - - $show = Request::any('show', '', 'string'); $this->action = Request::post('action'); if ($this->action === 'writePanelConfig') { $this->writePanelConfig(); @@ -49,6 +52,7 @@ class Page_LocationInfo extends Page */ protected function doRender() { + // Do this here so we always see backend errors $backends = $this->loadBackends(); $show = Request::get('show', '', 'string'); Render::addTemplate('page-tabs', array('class-' . $show => 'active')); @@ -77,7 +81,7 @@ class Page_LocationInfo extends Page { $id = Request::post('serverid', false, 'int'); if ($id === false) { - Messages::addError('server-id-missing'); + Message::addError('server-id-missing'); return; } $res = Database::exec("DELETE FROM `locationinfo_coursebackend` WHERE serverid=:id", array('id' => $id)); @@ -90,7 +94,7 @@ class Page_LocationInfo extends Page { $id = Request::post('uuid', false, 'string'); if ($id === false) { - Messages::addError('main.parameter-missing', 'uuid'); + Message::addError('main.parameter-missing', 'uuid'); return; } $res = Database::exec("DELETE FROM `locationinfo_panel` WHERE paneluuid = :id", array('id' => $id)); @@ -208,29 +212,78 @@ class Page_LocationInfo extends Page } /** - * Updated the config in the db. + * Get all location ids from the locationids parameter, which is comma separated, then split + * and remove any ids that don't exist. The cleaned list will be returned + * @param bool $failIfEmpty Show error and redirect to main page if parameter is missing or list is empty + * @return array list of locations from parameter */ - private function writePanelConfig() + private function getLocationIdsFromRequest($failIfEmpty) { - // UUID - existing or new - $paneluuid = Request::post('uuid', false, 'string'); - if (($paneluuid === false || strlen($paneluuid) !== 36) && $paneluuid !== 'new') { - Message::addError('invalid-panel-id', $paneluuid); - Util::redirect('?do=locationinfo'); - } - // Check locations $locationids = Request::post('locationids', false, 'string'); if ($locationids === false) { + if (!$failIfEmpty) + return array(); Message::addError('main.paramter-missing', 'locationids'); Util::redirect('?do=locationinfo'); } $locationids = explode(',', $locationids); $all = array_map(function ($item) { return $item['locationid']; }, Location::queryLocations()); $locationids = array_filter($locationids, function ($item) use ($all) { return in_array($item, $all); }); - if (empty($locationids)) { + if ($failIfEmpty && empty($locationids)) { Message::addError('main.paramter-empty', 'locationids'); Util::redirect('?do=locationinfo'); } + return $locationids; + } + + /** + * Updated the config in the db. + */ + private function writePanelConfig() + { + // UUID - existing or new + $paneluuid = Request::post('uuid', false, 'string'); + if (($paneluuid === false || strlen($paneluuid) !== 36) && $paneluuid !== 'new') { + Message::addError('invalid-panel-id', $paneluuid); + Util::redirect('?do=locationinfo'); + } + // Check panel type + $paneltype = Request::post('ptype', false, 'string'); + + if ($paneltype === 'DEFAULT') { + $params = $this->preparePanelConfigDefault(); + } elseif ($paneltype === 'URL') { + $params = $this->preparePanelConfigUrl(); + } else { + Message::addError('invalid-panel-type', $paneltype); + Util::redirect('?do=locationinfo'); + } + + if ($paneluuid === 'new') { + $paneluuid = Util::randomUuid(); + $query = "INSERT INTO `locationinfo_panel` (paneluuid, panelname, locationids, paneltype, panelconfig, lastchange) + VALUES (:id, :name, :locationids, :type, :config, :now)"; + } else { + $query = "UPDATE `locationinfo_panel` + SET panelname = :name, locationids = :locationids, paneltype = :type, panelconfig = :config, lastchange = :now + WHERE paneluuid = :id"; + } + $params['id'] = $paneluuid; + $params['name'] = Request::post('name', '-', 'string'); + $params['type'] = $paneltype; + $params['now'] = time(); + $params['config'] = json_encode($params['config']); + $params['locationids'] = implode(',', $params['locationids']); + Database::exec($query, $params); + + Message::addSuccess('config-saved'); + Util::redirect('?do=locationinfo'); + } + + private function preparePanelConfigDefault() + { + // Check locations + $locationids = self::getLocationIdsFromRequest(true); if (count($locationids) > 4) { $locationids = array_slice($locationids, 0, 4); } @@ -240,6 +293,7 @@ class Page_LocationInfo extends Page 'mode' => Request::post('mode', 1, 'int'), 'vertical' => Request::post('vertical', false, 'bool'), 'eco' => Request::post('eco', false, 'bool'), + 'prettytime' => Request::post('prettytime', false, 'bool'), 'scaledaysauto' => Request::post('scaledaysauto', false, 'bool'), 'daystoshow' => Request::post('daystoshow', 7, 'int'), 'rotation' => Request::post('rotation', 0, 'int'), @@ -254,27 +308,16 @@ class Page_LocationInfo extends Page if ($conf['calupdate'] < 30) { $conf['calupdate'] = 30; } + return array('config' => $conf, 'locationids' => $locationids); + } - if ($paneluuid === 'new') { - $paneluuid = Util::randomUuid(); - $query = "INSERT INTO `locationinfo_panel` (paneluuid, panelname, locationids, paneltype, panelconfig, lastchange) - VALUES (:id, :name, :locationids, :type, :config, :now)"; - } else { - $query = "UPDATE `locationinfo_panel` - SET panelname = :name, locationids = :locationids, paneltype = :type, panelconfig = :config, lastchange = :now - WHERE paneluuid = :id"; - } - Database::exec($query, array( - 'id' => $paneluuid, - 'name' => Request::post('name', '-', 'string'), - 'locationids' => implode(',', $locationids), - 'type' => 'DEFAULT', // TODO - 'config' => json_encode($conf), - 'now' => time(), - )); - - Message::addSuccess('config-saved'); - Util::redirect('?do=locationinfo'); + private function preparePanelConfigUrl() + { + $conf = array( + 'url' => Request::post('url', 'https://www.bwlehrpool.de/', 'string'), + 'insecure-ssl' => Request::post('insecure-ssl', 0, 'int'), + ); + return array('config' => $conf, 'locationids' => []); } /** @@ -402,6 +445,8 @@ class Page_LocationInfo extends Page while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) { $locid = (int)$row['locationid']; + if (!isset($locations[$locid])) + continue; $glyph = !empty($row['openingtime']) ? 'ok' : ''; $backend = ''; if (!empty($row['serverid']) && !empty($row['serverlocationid'])) { @@ -437,7 +482,7 @@ class Page_LocationInfo extends Page private function showPanelsTable() { - $res = Database::simpleQuery('SELECT p.paneluuid, p.panelname, p.locationids, + $res = Database::simpleQuery('SELECT p.paneluuid, p.panelname, p.locationids, p.panelconfig, p.paneltype FROM locationinfo_panel p ORDER BY panelname ASC'); $hasRunmode = Module::isAvailable('runmode'); @@ -447,11 +492,16 @@ class Page_LocationInfo extends Page $panels = array(); $locations = Location::getLocationsAssoc(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $lids = explode(',', $row['locationids']); - $locs = array_map(function($id) use ($locations) { - return isset($locations[$id]) ? $locations[$id]['locationname'] : $id; - }, $lids); - $row['locations'] = implode(', ', $locs); + if ($row['paneltype'] === 'URL') { + $url = json_decode($row['panelconfig'], true)['url']; + $row['locations'] = $row['locationurl'] = $url; + } else { + $lids = explode(',', $row['locationids']); + $locs = array_map(function ($id) use ($locations) { + return isset($locations[$id]) ? $locations[$id]['locationname'] : $id; + }, $lids); + $row['locations'] = implode(', ', $locs); + } $len = mb_strlen($row['panelname']); if ($len < 5) { $row['panelname'] .= str_repeat('…', 5 - $len); @@ -720,6 +770,13 @@ class Page_LocationInfo extends Page 'paneltype' => 'SUMMARY', ); $id = 'new'; + } elseif ($id === 'new-url') { + // Creating new panel + $panel = array( + 'panelname' => '', + 'paneltype' => 'URL', + ); + $id = 'new'; } else { // Get Config data from db $panel = Database::queryFirst("SELECT panelname, locationids, paneltype, panelconfig @@ -756,6 +813,7 @@ class Page_LocationInfo extends Page 'mode' => $config['mode'], 'vertical_checked' => $config['vertical'] ? 'checked' : '', 'eco_checked' => $config['eco'] ? 'checked' : '', + 'prettytime_checked' => $config['prettytime'] ? 'checked' : '', 'scaledaysauto_checked' => $config['scaledaysauto'] ? 'checked' : '', 'daystoshow' => $config['daystoshow'], 'rotation' => $config['rotation'], @@ -766,6 +824,14 @@ class Page_LocationInfo extends Page 'locations' => Location::getLocations(), 'locationids' => $panel['locationids'], )); + } elseif ($panel['paneltype'] === 'URL') { + Render::addTemplate('page-config-panel-url', array( + 'new' => $id === 'new', + 'uuid' => $id, + 'panelname' => $panel['panelname'], + 'url' => $config['url'], + 'ssl_checked' => $config['insecure-ssl'] ? 'checked' : '', + )); } else { // TODO Render::addTemplate('page-config-panel-summary', array( 'new' => $id === 'new', @@ -779,4 +845,36 @@ class Page_LocationInfo extends Page } } + private function showPanel() + { + $uuid = Request::get('uuid', false, 'string'); + if ($uuid === false) { + http_response_code(400); + die('Missing parameter uuid'); + } + $type = InfoPanel::getConfig($uuid, $config); + if ($type === false) { + http_response_code(404); + die('Panel with given uuid not found'); + } + + if ($type === 'URL') { + Util::redirect($config['url']); + } + + $data = array( + 'uuid' => $uuid, + 'config' => json_encode($config), + 'language' => $config['language'], + ); + + preg_match('#^(.*)/#', $_SERVER['PHP_SELF'], $script); + preg_match('#^([^?]+)/#', $_SERVER['REQUEST_URI'], $request); + if ($script[1] !== $request[1]) { + $data['dirprefix'] = $script[1] . '/'; + } + + echo Render::parse('frontend-default', $data); + } + } diff --git a/modules-available/locationinfo/frontend/doorsign.html b/modules-available/locationinfo/templates/frontend-default.html index 5e6306a0..fc9c3eac 100755 --- a/modules-available/locationinfo/frontend/doorsign.html +++ b/modules-available/locationinfo/templates/frontend-default.html @@ -7,7 +7,6 @@ required: uuid: [integer] panel id, see in admin panel optional: - lang:[en,de] set the language mode:[1,2,3,4] sets the displaying 1: Calendar & Room 2: only Calendar @@ -23,12 +22,12 @@ optional: scaledaysauto: [true] if true it finds automatically the daystoshow parameter depending on display size --> -<html lang="de"> +<html lang="{{language}}"> <meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8"> <head> <title>DoorSign</title> - <link rel='stylesheet' type='text/css' href='../../js_jqueryui/style.css'/> - <link rel='stylesheet' type='text/css' href='jquery-week-calendar/jquery.weekcalendar.css'/> + <link rel='stylesheet' type='text/css' href='{{dirprefix}}modules/js_jqueryui/style.css'/> + <link rel='stylesheet' type='text/css' href='{{dirprefix}}modules/js_weekcalendar/style.css'/> <style type='text/css'> @@ -340,14 +339,38 @@ optional: width: 50px; } + #i18n { + display: none; + } + </style> - <script type='text/javascript' src='../../../script/jquery.js'></script> - <script type='text/javascript' src='../../js_jqueryui/clientscript.js'></script> - <script type='text/javascript' src="jquery-week-calendar/jquery.weekcalendar.js"></script> + <script type='text/javascript' src='{{dirprefix}}script/jquery.js'></script> + <script type='text/javascript' src='{{dirprefix}}modules/js_jqueryui/clientscript.js'></script> + <script type='text/javascript' src="{{dirprefix}}modules/js_weekcalendar/clientscript.js"></script> </head> <body> +<div id="i18n"> + <span data-tag="room">{{lang_room}}</span> + <span data-tag="closed">{{lang_closed}}</span> + <span data-tag="free">{{lang_free}}</span> + <span data-tag="shortSun">{{lang_shortSun}}</span> + <span data-tag="shortMon">{{lang_shortMon}}</span> + <span data-tag="shortTue">{{lang_shortTue}}</span> + <span data-tag="shortWed">{{lang_shortWed}}</span> + <span data-tag="shortThu">{{lang_shortThu}}</span> + <span data-tag="shortFri">{{lang_shortFri}}</span> + <span data-tag="shortSat">{{lang_shortSat}}</span> + <span data-tag="longSun">{{lang_longSun}}</span> + <span data-tag="longMon">{{lang_longMon}}</span> + <span data-tag="longTue">{{lang_longTue}}</span> + <span data-tag="longWed">{{lang_longWed}}</span> + <span data-tag="longThu">{{lang_longThu}}</span> + <span data-tag="longFri">{{lang_longFri}}</span> + <span data-tag="longSat">{{lang_longSat}}</span> + <span data-tag="to">{{lang_to}}</span> +</div> </body> <script type="text/javascript"> @@ -358,7 +381,7 @@ optional: var hasMode4 = false; var globalConfig = {}; var roomIds = []; - var panelUuid = false; + var panelUuid = '{{{uuid}}}'; const IMG_FORMAT_LIST = (function() { if (typeof(SVGRect) !== "undefined") { return [".svg", ".png", ".jpg", ".gif"]; @@ -366,51 +389,8 @@ optional: return [".png", ".jpg", ".gif"]; })(); - // TODO: Get languages from slx-admin - var translation = { - "en": { - "room": "Room", - "closed": "Closed", - "free": "Free", - "shortDays": ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], - "longDays": ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], - "to": "to" - - }, - "de": { - "room": "Raum", - "closed": "Geschlossen", - "free": "Frei", - "shortDays": ["Son", "Mon", "Die", "Mit", "Don", "Frei", "Sam"], - "longDays": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"], - "to": "bis" - }, - "pt": { - "room": "Quarto", - "closed": "Fechado", - "free": "Livre", - "shortDays": ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Se', 'Sáb'], - "longDays": ['Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', - 'Sexta-feira', 'Sábado'], - "to": "para" - - } - }; - $(document).ready(function () { - var uuid; - uuid = window.location.pathname.match( /[a-z0-9\-]{36}/gi ); - if (uuid === null) { - uuid = getUrlParameter("uuid"); - } else { - uuid = uuid[0]; - } - if (!uuid) { - console.log('No panel uuid given'); - $("body").empty().append($('<h1>').text('No panel UUID given.')); - return; - } - getConfig(uuid); + applyConfig({{{config}}}); }); /** @@ -427,70 +407,49 @@ optional: }, 60000); } + function applyConfig(result) { + if (!result.locations || result.locations.constructor !== Array) { + fatalError("Requested panel doesn't contain locations / not array"); + return; + } - /** - * Downloads the config of a room, also reloads the page if the config hase changed over time - * @param uuid ID of the room - */ - - function getConfig(uuid) { - $.ajax({ - url: "../../../api.php?do=locationinfo&get=config&uuid=" + uuid, - dataType: 'json', - cache: false, - timeout: 30000, - success: function (result) { - - if (!result.locations || result.locations.constructor !== Array) { - fatalError("Requested panel doesn't contain locations / not array"); - return; - } - - var fetchedRooms = result.locations.filter(function (x) { - // filter out if no numeric id, or id already present, or already got 4 locations - if (typeof(x.id) !== 'number' || x.id <= 0 || roomIds.indexOf(x.id) !== -1 || roomIds.length >= 4) - return false; - roomIds.push(x.id); - return true; - }); - - if (roomIds.length === 0) { - fatalError("List of location ids is empty"); - return; - } - - var time = false; - var p = result.time.split('-'); - if (p.length === 6) { - time = new Date(p[0], p[1], p[2], p[3], p[4], p[5]); - console.log(time); - } - if (time === false || isNaN(time.getTime()) || time.getYear() < 2010) { - time = new Date(result.time); - } - if (isNaN(time.getTime()) || time.getYear() < 2010) { - time = new Date(); - } - SetUpDate(time); - delete result.time; - delete result.locations; + var fetchedRooms = result.locations.filter(function (x) { + // filter out if no numeric id, or id already present, or already got 4 locations + if (typeof(x.id) !== 'number' || x.id <= 0 || roomIds.indexOf(x.id) !== -1 || roomIds.length >= 4) + return false; + roomIds.push(x.id); + return true; + }); - globalConfig = result; - sanitizeGlobalConfig(); - lastRoomUpdate = MyDate().getTime(); + if (roomIds.length === 0) { + fatalError("List of location ids is empty"); + return; + } - for (var i = 0; i < fetchedRooms.length; ++i) { - addRoom(fetchedRooms[i]); - } + var time = false; + var p = result.time.split('-'); + if (p.length === 6) { + time = new Date(p[0], p[1], p[2], p[3], p[4], p[5]); + console.log(time); + } + if (time === false || isNaN(time.getTime()) || time.getYear() < 2010) { + time = new Date(result.time); + } + if (isNaN(time.getTime()) || time.getYear() < 2010) { + time = new Date(); + } + SetUpDate(time); + delete result.time; + delete result.locations; - panelUuid = uuid; - initRooms(); - // TODO: Check for changed config using get=timestamp and reload whole page on change + globalConfig = result; + sanitizeGlobalConfig(); + lastRoomUpdate = MyDate().getTime(); - }, error: function () { - fatalError('Could not fetch panel config'); - } - }) + for (var i = 0; i < fetchedRooms.length; ++i) { + addRoom(fetchedRooms[i]); + } + initRooms(); } const PARAM_STRING = 1; @@ -550,7 +509,6 @@ optional: */ function sanitizeGlobalConfig() { sanitizeConfig(globalConfig); - $('html').attr('lang', globalConfig.language); } function sanitizeConfig(config) { @@ -566,6 +524,7 @@ optional: setRoomConfigFromUrl(config, 'scaledaysauto', PARAM_BOOL); setRoomConfigFromUrl(config, 'vertical', PARAM_BOOL); setRoomConfigFromUrl(config, 'eco', PARAM_BOOL); + setRoomConfigFromUrl(config, 'prettytime', PARAM_BOOL); setRoomConfigFromUrl(config, 'scale', PARAM_INT); setRoomConfigFromUrl(config, 'rotation', PARAM_INT); @@ -805,10 +764,10 @@ optional: readonly: true, showHeader: false, hourLine: true, - shortDays: t("shortDays", room.config.language), - longDays: t("longDays", room.config.language), + shortDays: [t("shortSun"), t("shortMon"), t("shortTue"), t("shortWed"), t("shortThu"), t("shortFri"), t("shortSat")], + longDays: [t("longSun"), t("longMon"), t("longTue"), t("longWed"), t("longThu"), t("longFri"), t("longSat")], buttons: false, - timeSeparator: " " + t("to", room.config.language) + " ", + timeSeparator: " - ", startOnFirstDayOfWeek: false, displayFreeBusys: true, defaultFreeBusy: {free: false} @@ -817,7 +776,6 @@ optional: /** * Generates the Calendar Div, depending on it's width - * @param width width of the Calendar Div * @param room Room Object */ @@ -937,7 +895,7 @@ optional: */ function queryCalendars() { if (!panelUuid) return; - var url = "../../../api.php?do=locationinfo&get=calendar&uuid=" + panelUuid; + var url = "{{dirprefix}}api.php?do=locationinfo&get=calendar&uuid=" + panelUuid; $.ajax({ url: url, dataType: 'json', @@ -996,6 +954,7 @@ optional: cal.weekCalendar("option", "defaultFreeBusy", {free: !room.openingTimesCalendar}); cal.weekCalendar("updateFreeBusy", room.openingTimesCalendar); cal.weekCalendar("resizeCalendar"); + cal.weekCalendar("option", "hourLine", true); setTimeout(function() { scaleRoom(room); }, 550); @@ -1086,34 +1045,40 @@ optional: * computes the time difference between 2 Date objects * @param {Date} a * @param {Date} b - * @param room Room Object * @returns {string} printable time */ - function GetTimeDiferenceAsString(a, b, room) { + function GetTimeDiferenceAsString(a, b) { if (!a || !b) { return ""; } var milliseconds = a.getTime() - b.getTime(); + var days = Math.floor((milliseconds / (1000 * 60 * 60 * 24)) % 31); + if (days !== 0) { + // don't show? + return ""; + } var seconds = Math.floor((milliseconds / 1000) % 60); milliseconds -= seconds * 1000; var minutes = Math.floor((milliseconds / (1000 * 60)) % 60); milliseconds -= minutes * 1000 * 60; var hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24); - var days = Math.floor((milliseconds / (1000 * 60 * 60 * 24)) % 31); - if (seconds < 10) { - seconds = "0" + seconds; + if (globalConfig.prettytime) { + var str = ''; + if (hours > 0) { + str += hours + 'muh'; + } } + if (minutes < 10) { minutes = "0" + minutes; } - if (days !== 0) { - // don't show? - return ""; - } if (globalConfig.eco) { return hours + ":" + minutes; } + if (seconds < 10) { + seconds = "0" + seconds; + } return hours + ":" + minutes + ":" + seconds; } @@ -1213,7 +1178,7 @@ optional: function SetFreeSeats(room) { room.$.seatsCounter.text(room.freePcs >= 0 ? room.freePcs : ''); if (room.freePcs > 0 && room.state && room.state.free) { - room.$.seatsBackground.css('background-color', '#250'); + room.$.seatsBackground.css('background-color', '#250'); } else if (room.freePcs === -1) { room.$.seatsBackground.css('background-color', 'red'); } else { @@ -1234,19 +1199,19 @@ optional: var newText = false, newTime = false; var seats = room.freePcs; if (tmp.state === 'closed' || tmp.state === 'CalendarEvent' || tmp.state === 'Free') { - newTime = GetTimeDiferenceAsString(tmp.end, MyDate(), room); + newTime = GetTimeDiferenceAsString(tmp.end, MyDate()); } else if (!same) { newTime = ''; } if (tmp.state === "closed") { - if (!same) newText = t("closed", globalConfig.language); + if (!same) newText = t("closed"); } else if (tmp.state === "CalendarEvent") { if (!same) newText = tmp.title; seats = -1; } else if (tmp.state === "Free") { - if (!same) newText = t("free", room.config.language); + if (!same) newText = t("free"); } else if (tmp.state === "FreeNoEnd") { - if (!same) newText = t("free", room.config.language); + if (!same) newText = t("free"); } if (newText !== false) { room.$.currentEvent.text(newText); @@ -1300,15 +1265,15 @@ optional: // no closing so event is next if (!closing) { - room.state = {state: "Free", end: event.start, title: "", next: "event"}; + room.state = {state: "Free", end: event.start, title: "", next: "event", free: true}; return; } // event sooner then closing if (event.start.getTime() < closing) { - room.state = {state: "Free", end: event.start, title: "", next: "event"}; + room.state = {state: "Free", end: event.start, title: "", next: "event", free: true}; } else { - room.state = {state: "Free", end: closing, title: "", next: "closing"}; + room.state = {state: "Free", end: closing, title: "", next: "closing", free: true}; } } @@ -1552,7 +1517,7 @@ optional: */ function queryPanelChange() { $.ajax({ - url: "../../../api.php?do=locationinfo&get=timestamp&uuid=" + panelUuid, + url: "{{dirprefix}}api.php?do=locationinfo&get=timestamp&uuid=" + panelUuid, dataType: 'json', cache: false, timeout: 5000, @@ -1575,7 +1540,7 @@ optional: */ function queryRooms() { $.ajax({ - url: "../../../api.php?do=locationinfo&get=machines&uuid=" + panelUuid, + url: "{{dirprefix}}api.php?do=locationinfo&get=machines&uuid=" + panelUuid, dataType: 'json', cache: false, timeout: 30000, @@ -1641,7 +1606,7 @@ optional: * @param room Room object */ function scaleRoom(room) { - if (!room.$.layout.is(':visible')) return; + if (!room.$.layout || !room.$.layout.is(':visible')) return; room.resizeRoom = false; generateOffsetAndScale(room); room.$.layout.css('font-size', Math.floor(room.scale) + 'pt'); @@ -1707,19 +1672,15 @@ optional: /** * Function for translation * @param toTranslate key which we wan't to translate - * @param lang languages in which should be translated * @returns r translated string */ - function t(toTranslate, lang) { - - var r; - if (!lang || !translation[lang] || !translation[lang][toTranslate]) { - r = translation['en'][toTranslate] || 'missing'; - } else { - r = translation[lang][toTranslate]; - } - return r; + function t(toTranslate) { + if (tCache[toTranslate]) + return tCache[toTranslate]; + var r = $('#i18n').find('[data-tag="' + toTranslate + '"]'); + return tCache[toTranslate] = (r.length === 0 ? toTranslate : r.text()); } + var tCache = {}; function resizeIfRequired(room) { if (room.resizeCalendar) { diff --git a/modules-available/locationinfo/frontend/panel.html b/modules-available/locationinfo/templates/frontend-summary.html index dd5fc25d..dd5fc25d 100644 --- a/modules-available/locationinfo/frontend/panel.html +++ b/modules-available/locationinfo/templates/frontend-summary.html diff --git a/modules-available/locationinfo/templates/page-config-panel-default.html b/modules-available/locationinfo/templates/page-config-panel-default.html index 4632a718..b55e3d4d 100644 --- a/modules-available/locationinfo/templates/page-config-panel-default.html +++ b/modules-available/locationinfo/templates/page-config-panel-default.html @@ -8,6 +8,7 @@ <form method="post" action="?do=locationinfo" id="config-form"> <input type="hidden" name="token" value="{{token}}"> <input type="hidden" name="action" value="writePanelConfig"> + <input type="hidden" name="ptype" value="DEFAULT"> <input type="hidden" name="uuid" value="{{uuid}}"> <div class="row"> @@ -90,6 +91,22 @@ </div> </div> </div> + + <div class="list-group-item"> + <div class="row"> + <div class="col-sm-3"> + <label for="input-prettytime">{{lang_prettytime}}</label> + </div> + <div class="col-sm-7"> + <input id="input-prettytime" type="checkbox" name="prettytime" {{prettytime_checked}}> + </div> + <div class="col-sm-2"> + <a class="btn btn-default helptext" title="{{lang_prettytimeTooltip}}"> + <span class="glyphicon glyphicon-question-sign"></span> + </a> + </div> + </div> + </div> </div> </div> </div> diff --git a/modules-available/locationinfo/templates/page-config-panel-url.html b/modules-available/locationinfo/templates/page-config-panel-url.html new file mode 100644 index 00000000..401214bd --- /dev/null +++ b/modules-available/locationinfo/templates/page-config-panel-url.html @@ -0,0 +1,81 @@ +<h2> + {{#new}}{{lang_createPanel}}{{/new}} + {{^new}}{{lang_editPanel}}{{/new}} +</h2> + +<p>{{lang_editUrlPanelHints}}</p> + +<form method="post" action="?do=locationinfo" id="config-form"> + <input type="hidden" name="token" value="{{token}}"> + <input type="hidden" name="action" value="writePanelConfig"> + <input type="hidden" name="ptype" value="URL"> + <input type="hidden" name="uuid" value="{{uuid}}"> + + <div class="panel panel-default"> + <div class="panel-heading">{{lang_display}}</div> + <div class="panel-body"> + <div class="list-group"> + + <div class="list-group-item"> + <div class="row"> + <div class="col-sm-3"> + <label for="panel-title">{{lang_displayName}}</label> + </div> + <div class="col-sm-7"> + <input class="form-control" name="name" id="panel-title" type="text" value="{{panelname}}"> + </div> + <div class="col-sm-2"> + <a class="btn btn-default helptext" title="{{lang_displayNameTooltip}}"> + <span class="glyphicon glyphicon-question-sign"></span> + </a> + </div> + </div> + </div> + + <div class="list-group-item"> + <div class="row"> + <div class="col-sm-3"> + <label for="panel-url">{{lang_url}}</label> + </div> + <div class="col-sm-7"> + <input class="form-control" name="url" id="panel-url" type="text" value="{{url}}" + placeholder="http://www.bwlehrpool.de/" pattern=".*://.*" required> + </div> + <div class="col-sm-2"> + <a class="btn btn-default helptext" title="{{lang_urlTooltip}}"> + <span class="glyphicon glyphicon-question-sign"></span> + </a> + </div> + </div> + </div> + + <div class="list-group-item"> + <div class="row"> + <div class="col-sm-3"> + <label for="input-ssl">{{lang_insecureSsl}}</label> + </div> + <div class="col-sm-7"> + <input id="input-ssl" type="checkbox" name="insecure-ssl" {{ssl_checked}} value="1"> + </div> + <div class="col-sm-2"> + <a class="btn btn-default helptext" title="{{lang_ignoreSslTooltip}}"> + <span class="glyphicon glyphicon-question-sign"></span> + </a> + </div> + </div> + </div> + </div> + </div> + </div> + + <button type="submit" class="btn btn-primary">{{lang_save}}</button> + <a href="?do=locationinfo&show=panels" class="btn btn-default">{{lang_cancel}}</a> +</form> + +<script type="text/javascript"><!-- + +document.addEventListener("DOMContentLoaded", function () { + +}); + +//--></script> diff --git a/modules-available/locationinfo/templates/page-panels.html b/modules-available/locationinfo/templates/page-panels.html index 8b567410..0c87a70b 100644 --- a/modules-available/locationinfo/templates/page-panels.html +++ b/modules-available/locationinfo/templates/page-panels.html @@ -22,13 +22,15 @@ {{#panels}} <tr> <td> - <a href="modules/locationinfo/frontend/doorsign.html?uuid={{paneluuid}}" target="_blank">{{panelname}}</a> + <a href="/panel/{{paneluuid}}" target="_blank">{{panelname}}</a> </td> <td> {{paneltype}} </td> <td> + {{#locationurl}}<a href="{{locationurl}}" target="_blank">{{/locationurl}} {{locations}} + {{#locationurl}}</a>{{/locationurl}} </td> {{#hasRunmode}} <td> @@ -65,4 +67,8 @@ <span class="glyphicon glyphicon-plus"></span> {{lang_summaryPanel}} </a> + <a class="btn btn-sm btn-success" href="?do=locationinfo&show=edit-panel&uuid=new-url"> + <span class="glyphicon glyphicon-plus"></span> + {{lang_urlPanel}} + </a> </div>
\ No newline at end of file |