diff options
Diffstat (limited to 'modules-available/locations')
4 files changed, 74 insertions, 11 deletions
diff --git a/modules-available/locations/inc/openingtimes.inc.php b/modules-available/locations/inc/openingtimes.inc.php index 72ce92f4..18e25063 100644 --- a/modules-available/locations/inc/openingtimes.inc.php +++ b/modules-available/locations/inc/openingtimes.inc.php @@ -6,11 +6,12 @@ class OpeningTimes /** * Get opening times for given location. * Format is the decoded JSON from DB column, i.e. currently a list of entries: - * { + * <pre>{ * "days": ["Monday", "Tuesday", ...], * "openingtime": "8:00", * "closingtime": "20:00" - * } + * }</pre> + * @return array|null */ public static function forLocation(int $locationId) { @@ -31,4 +32,32 @@ class OpeningTimes return null; } + /** + * Check whether given location is open according to openingtimes. + * @param int $locationId location + * @param int $openOffsetMin offset to apply to opening times when checking. this is subtracted from opening time + * @param int $closeOffsetMin offset to apply to closing times when checking. this is added to closing time + */ + public static function isRoomOpen(int $locationId, int $openOffsetMin = 0, int $closeOffsetMin = 0): bool + { + $openingTimes = self::forLocation($locationId); + if ($openingTimes === null) + return true; // No opening times should mean room is always open + $now = time(); + $today = date('l', $now); + foreach ($openingTimes as $row) { + foreach ($row['days'] as $day) { + if ($day !== $today) + continue; // Not today! + if (strtotime("today {$row['openingtime']} -$openOffsetMin minutes") > $now) + continue; + if (strtotime("today {$row['closingtime']} +$closeOffsetMin minutes") < $now) + continue; + // Bingo! + return true; + } + } + return false; + } + }
\ No newline at end of file diff --git a/modules-available/locations/pages/details.inc.php b/modules-available/locations/pages/details.inc.php index 86bfebd6..d2ec7b24 100644 --- a/modules-available/locations/pages/details.inc.php +++ b/modules-available/locations/pages/details.inc.php @@ -39,9 +39,10 @@ class SubPage $openingTimes = Request::post('openingtimes', Request::REQUIRED, 'string'); $locationid = Request::post('locationid', Request::REQUIRED, 'int'); $wol = Request::post('wol', false, 'bool'); - $woloffset = Request::post('wol-offset', 0, 'int'); + $wolOffset = Request::post('wol-offset', 0, 'int'); $sd = Request::post('sd', false, 'bool'); - $sdoffset = Request::post('sd-offset', 0, 'int'); + $sdOffset = Request::post('sd-offset', 0, 'int'); + $raMode = Request::post('ra-mode', 'ALWAYS', 'string'); User::assertPermission('location.edit.openingtimes', $locationid); @@ -93,7 +94,16 @@ class SubPage if (Module::isAvailable('rebootcontrol')) { // Set options - Scheduler::setLocationOptions($locationid, $wol, $sd, $woloffset, $sdoffset); + if (!Scheduler::isValidRaMode($raMode)) { + $raMode = Scheduler::RA_ALWAYS; + } + Scheduler::setLocationOptions($locationid, [ + 'wol' => $wol, + 'sd' => $sd, + 'wol-offset' => $wolOffset, + 'sd-offset' => $sdOffset, + 'ra-mode' => $raMode, + ]); } } @@ -396,7 +406,7 @@ class SubPage if (Module::get('rebootcontrol') !== false) { $res = Database::queryFirst("SELECT action, nextexecution FROM `reboot_scheduler` WHERE locationid = :id", ['id' => $locationId]); - if ($res !== false) { + if ($res !== false && $res['nextexecution'] > 0) { $data['next_action'] = $res['action']; $data['next_time'] = Util::prettyTime($res['nextexecution']); } @@ -431,12 +441,13 @@ class SubPage $data['rebootcontrol'] = $rebootcontrol; if ($rebootcontrol) { $data['scheduler-options'] = Scheduler::getLocationOptions($id); + $data['scheduler_' . $data['scheduler-options']['ra-mode'] . '_checked'] = 'checked'; } echo Render::parse('ajax-opening-location', $data); } - private static function isSimpleMode(&$array) + private static function isSimpleMode(&$array): bool { if (empty($array)) return true; diff --git a/modules-available/locations/templates/ajax-opening-location.html b/modules-available/locations/templates/ajax-opening-location.html index 967e111c..861bef65 100644 --- a/modules-available/locations/templates/ajax-opening-location.html +++ b/modules-available/locations/templates/ajax-opening-location.html @@ -1,5 +1,5 @@ <div> - <h3>{{lang_openingTime}}</h3> + <h4>{{lang_openingTime}}</h4> <div class="checkbox"> <input id="oi{{id}}" class="openingtimes-inherited" type="checkbox" name="openingtimes-inherited" value="1" {{openingtimes_inherited}}> @@ -129,7 +129,7 @@ </div> {{#rebootcontrol}} -<hr> +<h4>{{lang_automatedMachineActions}}</h4> <div class="row wol"> <div class="col-sm-4"> <div class="checkbox checkbox-inline"> @@ -164,9 +164,32 @@ </div> </div> </div> +<h4>{{lang_remoteAccessConstraints}}</h4> +<div class="slx-smallspace"> + <div class="radio"> + <input id="ra-ALWAYS-check-{{id}}" name="ra-mode" value="ALWAYS" type="radio" + {{scheduler_ALWAYS_checked}}> + <label for="ra-ALWAYS-check-{{id}}">{{lang_remoteAccessNoRestriction}}</label> + </div> +</div> +<div class="slx-smallspace"> + <div class="radio"> + <input id="ra-SELECTIVE-check-{{id}}" name="ra-mode" value="SELECTIVE" type="radio" + {{scheduler_SELECTIVE_checked}}> + <label for="ra-SELECTIVE-check-{{id}}">{{lang_remoteAccessOnlyWhenClosed}}</label> + </div> +</div> +<div class="slx-smallspace"> + <div class="radio"> + <input id="ra-NEVER-check-{{id}}" name="ra-mode" value="NEVER" type="radio" + {{scheduler_NEVER_checked}}> + <label for="ra-NEVER-check-{{id}}">{{lang_remoteAccessNever}}</label> + </div> +</div> +<p><i>{{lang_remoteAccessHelp}}</i></p> {{/rebootcontrol}} -<script type="application/javascript"> +<script> (function() { var $loc = $('#openingTimesModal{{id}}'); diff --git a/modules-available/locations/templates/location-subnets.html b/modules-available/locations/templates/location-subnets.html index 80e63abf..85c5a744 100644 --- a/modules-available/locations/templates/location-subnets.html +++ b/modules-available/locations/templates/location-subnets.html @@ -150,7 +150,7 @@ <input type="hidden" name="openingtimes" value=""> <input type="hidden" name="locationid" value="{{locationid}}"> - <div class="modal-header">{{locationname}}</div> + <div class="modal-header"><h3>{{locationname}}</h3></div> <div class="modal-body"></div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_close}}</button> |