commit 7a7b805fd21db70c212d7526969233b985f1316f
Author: Ondrej Drtina <drtinao@students.zcu.cz>
Date:   Fri Apr 9 19:11:56 2021 +0200

    Opraveny mezní stavy + nejde zadat nesmysl. Povolujeme 1-500 položek na stránku, je ošetřeno, nelze zadat:
    - desetinné číslo
    - písmena
    - záporná čísla
    - prázdno
    
    + kontrola při změně čísla v poli i při submitu dat
    + nastavení je zobrazeno jen pokud jsem ve vyhledávání

diff --git a/application/view/menu.php b/application/view/menu.php
index 23d5f22..606556f 100644
--- a/application/view/menu.php
+++ b/application/view/menu.php
@@ -6,6 +6,6 @@
         <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'], '/index.php') ? 'active' : '');?>" href="index.php">Úvodní info</a>
         <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'],'/search.php') ? 'active' : '');?>" href="search.php">Vyhledávání</a>
         <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'],'/login.php') ? 'active' : '');?>" href="#" data-toggle="modal" data-target="#login-modal">Přihlášení</a>
-        <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'],'/settings.php') ? 'active' : '');?>" href="#" data-toggle="modal" data-target="#settings-modal">Nastavení</a>
+        <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'],'/settings.php') ? 'active' : '');?>" href="#" data-toggle="modal" data-target="#settings-modal" id="modalSettingsHref">Nastavení</a>
     </div>
 </div>
\ No newline at end of file
diff --git a/application/view/modals/settingsModal.html b/application/view/modals/settingsModal.html
index 89d2531..171f78c 100644
--- a/application/view/modals/settingsModal.html
+++ b/application/view/modals/settingsModal.html
@@ -1,3 +1,7 @@
+<script>
+	var visibleItemCount = document.getElementById("itemsPerPage");
+	visibleItemCount.value = itemPerPage;      
+</script>
 <div id="settings-modal" class="modal fade" role="dialog">
 	<div class="modal-dialog modal-dialog-centered" role="document">
 		<div class="modal-content">
@@ -12,7 +16,7 @@
                             <label for="itemsPerPage">Počet záznamů na stránku: </label>
                         </div>
                         <div class="col-xs-12 col-sm-7">
-                            <input type="number" id="itemsPerPage"  onshow="viewItemsPerPage()">
+                            <input type="number" id="itemsPerPage" onchange="checkValidItemsPerPage()">
                         </div>
                     </div>
 				</div>
@@ -23,4 +27,14 @@
             </div>
 		</div>
 	</div>
-</div>
\ No newline at end of file
+</div>
+<!-- init modal with items per page value -->
+<script>
+	var visibleItemCount = document.getElementById("itemsPerPage");
+	//when itemPerPage undefined - user is not on search page (make settings invisible on other pages)
+	if(typeof itemPerPage === 'undefined'){
+		document.getElementById("modalSettingsHref").style.display = "none";
+	}else{ //user is on search page, ok, get valid count
+		visibleItemCount.value = itemPerPage;
+	}      
+</script>
\ No newline at end of file
diff --git a/application/view/searchContent.php b/application/view/searchContent.php
index 25bfa24..ee6d946 100644
--- a/application/view/searchContent.php
+++ b/application/view/searchContent.php
@@ -559,14 +559,24 @@
     <h3 id="no-data-label" class="mx-auto text-center font-italic">Žádná data nebyla nalezena</h3>
 
     <script>
-        function viewItemsPerPage(){
+        function checkValidItemsPerPage(){
             var visibleItemCount = document.getElementById("itemsPerPage");
-            visibleItemCount.value = itemPerPage;
+            if(!isNaN(visibleItemCount.value) && visibleItemCount.value % 1 === 0 && parseInt(visibleItemCount.value) >= 1 && parseInt(visibleItemCount.value) <= 500){
+                return true;
+            }else{
+                alert("Zadaný počet není validní, zkuste to znovu.\nPlatný rozsah: 1 - 500 položek na stránku.");
+                visibleItemCount.value = itemPerPage;
+                return false;
+            }
         }
 
         function changeItemsPerPage(){
-            pageIndex = 0;
+            //if there is no valid input, return and dont save
+            if(checkValidItemsPerPage() === false){
+                return;
+            }
 
+            pageIndex = 0;
             var visibleItemCount = document.getElementById("itemsPerPage").value;
             itemPerPage = visibleItemCount;
             fetchData(true);
