<!DOCTYPE html>
<!--// $Id$ //-->
<html>
<head>
	<title>{block name=title}LMS{/block}</title>
	<meta name="GENERATOR" content="LMS {$layout.lmsv}">
	{include file="language.html"}
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	{include file="jquery.html" language=Localisation::getCurrentHtmlLanguage() lms_language=Localisation::getCurrentUiLanguage()}
	<link href="{ConfigHelper::getConfig('phpui.style', 'css/style.css')}" rel="stylesheet" type="text/css">
	<link href="css/map.css" rel="stylesheet" type="text/css">
	<link rel="preconnect" href="https://fonts.googleapis.com">
	<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
	<link href="https://fonts.googleapis.com/css2?family=Fira+Code&display=swap" rel="stylesheet">
	{block name="extra-css-styles"}{/block}
	<link href="{ConfigHelper::getConfig('phpui.shortcut_icon', 'img/lms-net.gif')}" rel="shortcut icon">
	<script src="js/common.js"></script>
	<script src="js/base64.js"></script>
	<script src="js/ClickShowHideMenu.js"></script>
	<script src="js/autosuggest.js"></script>
	<script src="js/mousetrap/mousetrap.min.js"></script>
	<script src="js/mousetrap/plugins/global-bind/mousetrap-global-bind.min.js"></script>
	<script>
	{block name="extra-js-scripts"}{/block}
	</script>
</head>
<body onload="start_login_timeout({ConfigHelper::getConfig('phpui.timeout')})" class="lms-ui-main-document">
<input type="file" id="tinymce-image-upload" style="display: none;">
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:100;"></div>
<div class="lms-ui-gallery-container">
	<div class="lms-ui-gallery-overlay"></div>
	<div class="lms-ui-gallery"></div>
</div>
<button id="lms-ui-back-to-top" class="lms-ui-button no-print">
	<i class="lms-ui-icon-back"></i>
	<span class="lms-ui-label">{trans("Back to top")}</span>
</button>

<script>

	$(window).resize(function() {
		var back_button = $("#lms-ui-back-to-top");
		back_button.css('transform', 'translateX(' + back_button.outerWidth() + 'px)');
	})

</script>
<script src="js/overlib.js"></script>

{include file="modal-dialogs.html"}
<script src="js/modal-dialogs.js"></script>

{include file="popup-menu.html"}
<script src="js/popup-menu.js"></script>

{include file="list.html"}

{if $layout.popup}
	{block name=module_content}{/block}
{else}
	{block name=pageleftbar}
		{include file="menu-panel.html"}
	{/block}
	{block name=pagecontent}
		{include file="spinner.html"}
		{$__old_history_entry = Session::getOldHistoryEntry()}
		{$__history_entry = Session::getHistoryEntry()}
		<input type="hidden" id="old-history-entry" value="{$__old_history_entry}">
		<input type="hidden" id="history-entry" value="{$__history_entry}">
		<script>

			var AUTOSUGGEST_MAX_LENGTH = {ConfigHelper::getConfig('phpui.autosuggest_max_length', 40)};

			$('#lms-ui-back-to-top').click(function() {
				$('html,body').animate({ scrollTop: 0 });
			});

			// we use 'tabId' session storage value for identifying web browser tabs
			// which should preserve some form data per tab
			var lmsTabId = sessionStorage.getItem('tabId');

/*
			const bc = new BroadcastChannel("lms-broadcast-channel");
			bc.onmessage = (event) => {
				var newLmsTabId = event.data.srcTabId;
				if (newLmsTabId == lmsTabId) {
					event.srcElement.postMessage({
						srcTabId: 0
					});
				} else if (newLmsTabId == 0) {
					lmsTabId = Date.now();
					sessionStorage.setItem('tabId', lmsTabId);

					// new browser tab can be opened as hidden or tabid of new tab can be not initialised
					// so we have to be careful and handle 'backto' session variable in special way and
					// correct this variable when new tab id has been determined before the moment
					var oldLmsTabId = getCookie('tabId');
					{if $__history_entry}
						if (oldLmsTabId) {
							$.ajax({
								url: '?old_tab_id=' + oldLmsTabId + '&tab_id=' + lmsTabId,
								method: "POST",
								dataType: 'json',
								data: {
									old_history_entry: $('#old-history-entry').val(),
									history_entry: $('#history-entry').val()
								}
							});
						}
					{/if}

					if (!document.hidden) {
						setCookie('tabId', lmsTabId);
					}
				}
			};
			bc.postMessage({
				srcTabId: lmsTabId
			});
*/

			if (!lmsTabId) {
				lmsTabId = Date.now();
				sessionStorage.setItem('tabId', lmsTabId);

				// new browser tab can be opened as hidden or tabid of new tab can be not initialised
				// so we have to be careful and handle 'backto' session variable in special way and
				// correct this variable when new tab id has been determined before the moment
				var oldLmsTabId = getCookie('tabId');
				{if $__history_entry}
					if (oldLmsTabId) {
						$.ajax({
							url: '?old_tab_id=' + oldLmsTabId + '&tab_id=' + lmsTabId,
							method: "POST",
							dataType: 'json',
							data: {
								old_history_entry: $('#old-history-entry').val(),
								history_entry: $('#history-entry').val()
							}
						});
					}
				{/if}
			}
			if (!document.hidden) {
				setCookie('tabId', lmsTabId);
			}

			var loginTimeout = parseInt('{ConfigHelper::getConfig('phpui.timeout')}');
			var lastClearLoginTimeout = Date.now();
			var clearLoginTimeoutHandle = null;

			$(window).on('mousemove keypress focus scroll', function(e) {
				if (e.type == 'focus') {
					setCookie('tabId', lmsTabId);

					// check if login timeout condition is met - in newer web browser
					// timers are not active when window is not visible
					if (Date.now() > lms_login_timeout_ts) {
						window.location.assign(window.location.href);
					}
				} else {
					start_login_timeout(loginTimeout);

					if (Date.now() - lastClearLoginTimeout > (loginTimeout * 1000 / 2)) {
						$.ajax({
							url: '?clear_login_timeout=1&api=1',
							method: "POST",
							dataType: 'json'
						});
						lastClearLoginTimeout = Date.now();
					} else {
						if (clearLoginTimeoutHandle) {
							clearTimeout(clearLoginTimeoutHandle);
						}
						clearLoginTimeoutHandle = setTimeout(
							function () {
								$.ajax({
									url: '?clear_login_timeout=1&api=1',
									method: "POST",
									dataType: 'json'
								});
								lastClearLoginTimeout = Date.now();
							},
							loginTimeout * 1000 / 2
						);
					}
				}
			});

		</script>
		<section id="lms-ui-contents" style="display: none;">
			<div id="lms-ui-tool-panels" class="lms-ui-popup no-print">
				{include file="quicksearch-indicators-panel.html"}
				{include file="toolbar-panel.html"}
			</div>
			<div id="lms-ui-module-view">
				{block name=module_content}{/block}
				{/block}
{/if}
