diff options
Diffstat (limited to 'modules-available/locationinfo/page.inc.php')
-rw-r--r-- | modules-available/locationinfo/page.inc.php | 86 |
1 files changed, 36 insertions, 50 deletions
diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index f81fca13..91de0012 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -100,7 +100,7 @@ class Page_LocationInfo extends Page /** * Deletes the server from the db. */ - private function deleteServer($id) + private function deleteServer($id): void { User::assertPermission('backend.edit'); if ($id === 0) { @@ -113,7 +113,7 @@ class Page_LocationInfo extends Page } } - private function deletePanel() + private function deletePanel(): void { $id = Request::post('uuid', false, 'string'); if ($id === false) { @@ -130,7 +130,7 @@ class Page_LocationInfo extends Page } } - private function getTime($str) + private function getTime(string $str): int { $str = explode(':', $str); if (count($str) !== 2) return false; @@ -138,17 +138,17 @@ class Page_LocationInfo extends Page return $str[0] * 60 + $str[1]; } - private function writeLocationConfig() + private function writeLocationConfig(): void { // Check locations $locationid = Request::post('locationid', false, 'int'); if ($locationid === false) { Message::addError('main.parameter-missing', 'locationid'); - return false; + return; } if (Location::get($locationid) === false) { Message::addError('location.invalid-location-id', $locationid); - return false; + return; } User::assertPermission('location.edit', $locationid); @@ -198,29 +198,23 @@ class Page_LocationInfo extends Page )); } } - - return true; } /** * 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 + * and remove any ids that don't exist. The cleaned list will be returned. + * Will show error and redirect to main page if parameter is missing + * * @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 getLocationIdsFromRequest($failIfEmpty) + private function getLocationIdsFromRequest(): array { - $locationids = Request::post('locationids', false, 'string'); - if ($locationids === false) { - if (!$failIfEmpty) - return array(); - Message::addError('main.parameter-missing', 'locationids'); - Util::redirect('?do=locationinfo'); - } + $locationids = Request::post('locationids', Request::REQUIRED_EMPTY, 'string'); $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 ($failIfEmpty && empty($locationids)) { + if (empty($locationids)) { Message::addError('main.parameter-empty', 'locationids'); Util::redirect('?do=locationinfo'); } @@ -230,7 +224,7 @@ class Page_LocationInfo extends Page /** * Updated the config in the db. */ - private function writePanelConfig() + private function writePanelConfig(): void { // UUID - existing or new $paneluuid = Request::post('uuid', false, 'string'); @@ -276,10 +270,10 @@ class Page_LocationInfo extends Page Util::redirect('?do=locationinfo'); } - private function preparePanelConfigDefault() + private function preparePanelConfigDefault(): array { // Check locations - $locationids = self::getLocationIdsFromRequest(true); + $locationids = self::getLocationIdsFromRequest(); if (count($locationids) > 4) { $locationids = array_slice($locationids, 0, 4); } @@ -331,7 +325,7 @@ class Page_LocationInfo extends Page return array('config' => $conf, 'locationids' => $locationids); } - private function preparePanelConfigUrl() + private function preparePanelConfigUrl(): array { $bookmarkNames = Request::post('bookmarkNames', [], 'array'); $bookmarkUrls = Request::post('bookmarkUrls', [], 'array'); @@ -354,14 +348,14 @@ class Page_LocationInfo extends Page 'split-login' => Request::post('split-login', 0, 'bool'), 'browser' => Request::post('browser', 'slx-browser', 'string'), 'interactive' => Request::post('interactive', '0', 'bool'), - 'bookmarks' => $bookmarkString ? $bookmarkString : '', + 'bookmarks' => $bookmarkString ?: '', 'allow-tty' => Request::post('allow-tty', '', 'string'), 'zoom-factor' => Request::post('zoom-factor', 100, 'int'), ); return array('config' => $conf, 'locationids' => []); } - private function preparePanelConfigSummary() + private function preparePanelConfigSummary(): array { // Build json structure $conf = array( @@ -374,14 +368,14 @@ class Page_LocationInfo extends Page $conf['panelupdate'] = 15; } // Check locations - $locationids = self::getLocationIdsFromRequest(true); + $locationids = self::getLocationIdsFromRequest(); return array('config' => $conf, 'locationids' => $locationids); } /** * Updates the server settings in the db. */ - private function updateServerSettings() + private function updateServerSettings(): void { User::assertPermission('backend.edit'); $serverid = Request::post('id', -1, 'int'); @@ -423,7 +417,7 @@ class Page_LocationInfo extends Page * * @param int $id Server id which connection should be checked. */ - private function checkConnection($serverid = 0) + private function checkConnection(int $serverid = 0): void { if ($serverid === 0) { ErrorHandler::traceError('checkConnection called with no server id'); @@ -449,7 +443,7 @@ class Page_LocationInfo extends Page LocationInfo::setServerError($serverid, $serverInstance->getErrors()); } - private function loadBackends() + private function loadBackends(): array { // Get a list of all the backend types. $servertypes = array(); @@ -487,7 +481,7 @@ class Page_LocationInfo extends Page /** * Show the list of backends */ - private function showBackendsTable($serverlist) + private function showBackendsTable(array $serverlist): void { User::assertPermission('backend.*'); $data = array( @@ -498,7 +492,7 @@ class Page_LocationInfo extends Page Render::addTemplate('page-servers', $data); } - private function showBackendLog() + private function showBackendLog(): void { $id = Request::get('serverid', false, 'int'); if ($id === false) { @@ -523,7 +517,7 @@ class Page_LocationInfo extends Page Render::addTemplate('page-server-log', $server); } - private function showLocationsTable() + private function showLocationsTable(): void { $allowedLocations = User::getAllowedLocations('location.edit'); if (empty($allowedLocations)) { @@ -578,7 +572,7 @@ class Page_LocationInfo extends Page )); } - private function showPanelsTable() + private function showPanelsTable(): void { $visibleLocations = User::getAllowedLocations('panel.list'); if (in_array(0, $visibleLocations)) { @@ -662,7 +656,7 @@ class Page_LocationInfo extends Page * * @param int $id Serverid */ - private function ajaxServerSettings($id) + private function ajaxServerSettings(int $id): void { User::assertPermission('backend.edit'); $oldConfig = Database::queryFirst('SELECT servername, servertype, credentials @@ -711,7 +705,7 @@ class Page_LocationInfo extends Page * * @param int $id id of the location */ - private function ajaxConfigLocation($id) + private function ajaxConfigLocation(int $id): void { User::assertPermission('location.edit', $id); $locConfig = Database::queryFirst("SELECT info.serverid, info.serverlocationid, loc.openingtime @@ -766,12 +760,6 @@ class Page_LocationInfo extends Page echo Render::parse('ajax-config-location', $data); } - private function fmtTime($time) - { - $t = explode(':', $time); - return sprintf('%02d:%02d', $t[0], $t[1]); - } - /** * Checks if simple mode or expert mode is active. * Tries to merge/compact the opening times schedule, and @@ -780,7 +768,7 @@ class Page_LocationInfo extends Page * * @return array new optimized openingtimes */ - private function compressTimes(&$array) + private function compressTimes(array $array): array { if (empty($array)) return []; @@ -825,9 +813,9 @@ class Page_LocationInfo extends Page /** * @param array $daysArray List of days, "Monday", "Tuesday" etc. Must not contain duplicates. - * @return string Human readable representation of list of days + * @return string Human-readable representation of list of days */ - private function buildDaysString(array $daysArray) + private function buildDaysString(array $daysArray): string { /* Dictionary::translate('monday') Dictionary::translate('tuesday') Dictionary::translate('wednesday') * Dictionary::translate('thursday') Dictionary::translate('friday') Dictionary::translate('saturday') @@ -884,7 +872,7 @@ class Page_LocationInfo extends Page // $start must lie before range start, otherwise we'd have hit the case above $e = $current[1]; unset($array[$day][$key]); - continue; + //continue; } } $array[$day][] = array($s, $e); @@ -892,10 +880,8 @@ class Page_LocationInfo extends Page /** * Ajax the config of a panel. - * - * @param $id Location ID */ - private function showPanelConfig() + private function showPanelConfig(): void { $id = Request::get('uuid', false, 'string'); if ($id === false) { @@ -1040,7 +1026,7 @@ class Page_LocationInfo extends Page } } - private function showPanel() + private function showPanel(): void { $uuid = Request::get('uuid', false, 'string'); if ($uuid === false) { @@ -1097,9 +1083,9 @@ class Page_LocationInfo extends Page /** * @param string|array $panelOrUuid UUID of panel, or array with keys paneltype and locationds * @param string $permission - * @param null|int[] $additionalLocations + * @param int[]|null $additionalLocations */ - private function assertPanelPermission($panelOrUuid, $permission, $additionalLocations = null) + private function assertPanelPermission($panelOrUuid, string $permission, array $additionalLocations = null): void { if (is_array($panelOrUuid)) { $panel = $panelOrUuid; |