<!DOCTYPE HTML>
<html lang="la">
<head>
	<title>Index generalis Civis Romani et Scriptoris Latini – Collecta</title>
	<meta name="author" content="Bernd Platzdasch"><!-- 22.5.2015 // 24.6.2015 // 20.12.2017 // 4.11.2018 // 2.9.2020  // 8.4.2021 -->
	<meta charset="UTF-8">
	<script src="js/jquery-1.11.2.min.js" type="text/javascript"></script>
	<script src="js/store.js" type="text/javascript"></script>
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<style>
		input { border: none; } 
		input.button { background-color: #fff; border-radius: 2px; border: 1px solid #aaa; border-color: gray; width: 9em; margin-top: 0.5em; }
		table, #resultat, #mnu { width: 730px; }
		#resultat { padding-bottom: 1.5em; }
		td { vertical-align: top; padding: 0.8em 0 0 0; }
		td.chkb { padding: 1.1em 3.5em 0 1em; }
		#beleg { padding: 0; text-indent: -2em; }
		#mnu, .hspace { display: none; }
		#OmNi { padding-top: 1.5em; }
/* 		#sursum { float: right; display: none; } */
		#ajaxBusy { display: none; position: fixed; top: 180px; left: 0; right: 0; margin: auto; width: 32px; height: 32px; }
		@media print {
			div { width: 100%; }
			#banner, #dd_mnu, #menu, #navimnu, h1, #OmNi, input, #menubottom, .hide, #footer { display: none; }
			body { background: none; font-size: 12pt; }
			div.border { border: none; }
			table { width: 100%; margin-left: 1cm; }
			td { padding-top: 8pt; text-indent: -1cm; }
		}
	</style>
	<script>
		function get() {
			var arr = [];
			for (var i = 0 ; i < localStorage.length; i++) { arr.push(localStorage.key(i)); }
			return arr;
		}
		function storeItem(id) {
			if (localStorage.getItem(id) == "1") {
				x = "0";
				$("#"+id).attr("class", "hide");
			} else {
				x = "1";
				$("#"+id).attr("class", "show");
			}
			localStorage.setItem(id, x);
			buttons();
		}
		function buttons() {
			if ($("input[type='checkbox']:checked").length > 0) {
				$("input:submit").prop("disabled", false);
			} else {
				$("input:submit").prop("disabled", true);
			}
		}
		$(document).ready(function() {
		 //
			$("input[type='submit']").hover(
				function(){ $(this).css({"background-color": "lightgrey"}); },
				function(){ $(this).css({"background-color": "white"}); }
			);
			$(document).ajaxStart(function () {
				$("#ajaxBusy").show();
			});
			$(document).ajaxStop(function (){
				$("#ajaxBusy").hide();
			});

			$.ajax({
				url: "php/collecta.inc.php",
				type: "POST",
				data: {
					arr_iid: get()
				},
				success: function(resultat) {
					var res = JSON.parse(resultat);
					var res = res.toString();
					var res = res.split("#");
					// bei leerem Resultat abbrechen:
					if (res == "") { return; }
					var alle_reihen = "";
					for (var i = 0; i < res.length; i++) {
						if (res[i] != "") {
							var id = res[i].substr(res[i].lastIndexOf("_")+1);
							var item = localStorage.getItem(id);
							var chkd = "";
							var clas = "hide";
							if (item == "1") { chkd = "checked"; clas="show"; }
							var beleg = res[i].substr(0, res[i].indexOf("_"));
							if (beleg.indexOf(",") == 0) {beleg = beleg.substring(1);}
							var reihe = "<tr id='" + id + "' class='" + clas +"'><td class='chkb'><input type='checkbox' onChange='storeItem(" + id +");'" + chkd + "></td><td><p id='beleg'" + beleg + "</p></td></tr>";
							alle_reihen = alle_reihen + reihe;
						}
					}
					tabelle = "<table>" + alle_reihen + "</table>";
					if(alle_reihen !="" ) {
						$("#mnu").css("display", "block");
						$("#resultat").html(tabelle);
						buttons();

					}
					if(res.length > 10) {
// 						$("#sursum").css("display", "block");
						$(".hspace").css("display", "block");
					}
				}
			});
			$("#delere").click(function(){
				if (confirm("Visne signata delere?") == true) {
					arr_iid = get();
					for (var i=0 ; i < arr_iid.length; i++) {
						if( (arr_iid[i] > 600000) && (arr_iid[i] < 700000)) {
							var row = document.getElementById(arr_iid[i]);
							if (row.getElementsByTagName("td")[0].getElementsByTagName("input")[0].checked) {
								row.parentNode.removeChild(row);
								localStorage.removeItem(arr_iid[i]);
							}
						}
					}
					var storl = localStorage.length;
					if (storl == 0) {$("#mnu").css("display", "none")};
					$("#mnu_collecta").html("Collecta (" + storl +")");
				}
			});
			$("#omnia").click(function(){
				$(":checkbox").prop( "checked", true );
				for (var i = 0 ; i < localStorage.length; i++) {
					localStorage.setItem(localStorage.key(i), "1");
					var id = localStorage.key(i);
					$("#"+id).attr("class", "show");
					$("input:submit").prop("disabled", false);
				}
			});
			$("#nihil").click(function(){
				$(":checkbox").prop( "checked", false );
				for (var i = 0 ; i < localStorage.length; i++) {
					localStorage.setItem(localStorage.key(i), "0");
					var id = localStorage.key(i);
					$("#"+id).attr("class", "hide");
					$("input:submit").prop("disabled", true);
				}
			});
			$("#exscribere").click(function(){
				window.print();
			});
		});
	</script>
</head>
<body onload="store_mnu();">
	<?php
		include("header.inc.php");
	?>
	<div class="border">
		<div id="main">
			<h1>Collecta</h1>
			<div id="mnu">
				<form>
					<input class="button" type= "submit" id="delere" value="Delere" disabled>
					<input class="button" type= "submit" id="exscribere" value="Typis exscribere" disabled>
				</form>
				<p id="OmNi"><a href="javascript:void(0);" id="omnia">Omnia</a>&thinsp;|&thinsp;<a href="javascript:void(0);" id="nihil">Nihil</a></p>
			</div>
			<div id="resultat"></div>
<!-- 			<p id="sursum"><a href='javascript:window.scrollTo(0,0);'><b>sursum</b></a></p> -->
			<p class="hspace">&#160;</p>
			<img id="ajaxBusy" src="img/ajax-loader.gif" alt="Loader">
		</div>
		&#160;
	</div>
	<?php include("footer.inc.php"); ?>
</body>
</html>
