<!DOCTYPE HTML>
<html lang="la">
<head>
	<title>Index generalis Societatis Latinae – Index auctorum symbolarum</title>
	<meta name="author" content="Bernd Platzdasch"><!-- 7.4.2015 // 20.7.2015 // 4.11.2018 // 2.9.2020 -->
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<link rel="stylesheet" type="text/css" href="css/idx.css">
	<script src="js/store.js" type="text/javascript"></script>
	<?php
		include("php/betacode.inc.php");
		$PHP_SELF = $_SERVER ["PHP_SELF"];
		$bu = (isset($_POST ["bu"])) ? $_POST ["bu"] : "✳";
		//
		$gbu = array_search($bu, $betacode);
		$sql_bu = "((Autor LIKE '$bu%') OR (Autor LIKE '«$bu%') OR (Autor LIKE '$gbu%') OR (Autor LIKE '«$gbu%'))";
		//
// 		$auctor = (isset($_POST ["auctor"])) ? $_POST ["auctor"] : "";
		$titulus = (isset($_POST ["titulus"])) ? $_POST ["titulus"] : "";
		$genlit = (isset($_POST ["genlit"])) ? $_POST ["genlit"] : "";
		$res = (isset($_POST ["res"])) ? $_POST ["res"] : "";
		$fasc1 = (isset($_POST ["fasc1"])) ? $_POST ["fasc1"] : "";
		$fasc2 = (isset($_POST ["fasc2"])) ? $_POST ["fasc2"] : "";
		$dig1 = (isset($_POST ["dig1"])) ? $_POST ["dig1"] : "";
		$dig2 = (isset($_POST ["dig2"])) ? $_POST ["dig2"] : "";
		$ord = (isset($_POST ["ord"])) ? $_POST ["ord"] : "ASC";
		//
		$sel = (isset($_POST ["sel"])) ? $_POST ["sel"] : 1;
		$bl = (isset($_POST ["bl"])) ? $_POST ["bl"] : "";
		$anf = (isset($_POST ["anf"])) ? $_POST ["anf"] : "";
		$zur = (isset($_POST ["zur"])) ? $_POST ["zur"] : "";
		$vor = (isset($_POST ["vor"])) ? $_POST ["vor"] : "";
		$end = (isset($_POST ["end"])) ? $_POST ["end"] : "";
		//
		if (($bl == "l◄") AND ($anf != "")) { $sel = 1; }
		if (($bl == "►") AND ($vor != "")) { $sel = $vor; }
		if (($bl == "◄") AND ($zur != "")) { $sel = $zur; }
		if (($bl == "►l") AND ($end != "")) { $sel = $end; }
		//
		require_once $_SERVER['DOCUMENT_ROOT'] . '/db_connection.php';
		//
		$sql_select = "SELECT DISTINCT(Autor) FROM societaslatina WHERE ". $sql_bu . " AND (Autor <> '') ORDER BY Autor";
		$sql_result = $db->query($sql_select);
		$insgesamt = $sql_result->num_rows;
		switch ($insgesamt) {
			case 0:
				$treffer = "ne unum quidem nomen";
				break;
			case 1:
				$treffer = "1 nomen";
				break;
			default:
				$treffer = $insgesamt . " nomina";
		}
	?>
	<script>
		var optionen = new Array();
		function createDatenseiten() {
			var insgesamt = "<?php echo $insgesamt ?>" ;
			if (insgesamt > 10) var range = 30;
			var rest = insgesamt % range;
			var divi = insgesamt / range;
			if (rest == 0) {
				var ganz = insgesamt / range;
			} else {
				var ganz = vorkomma(divi);
				ganz = ganz - 0; // wieder in Zahl umwandeln
			}
				for (var i=1; i<=ganz; i++) {
				var wert1 = ((i * range) - range) + 1;
				optionen.push(wert1);
				var wert2 = (i * range);
				optionen.push(wert2);
			}
			if (rest != 0) {
				wert1 = (ganz * range) + 1;
				optionen.push(wert1);
				wert2 = (ganz * range) + rest;
				optionen.push(wert2);
			}
			var laenge = optionen.length;
			for (var i=0; i < laenge; i++) {
				var newOpt = document.createElement("option");
				var f1 = optionen[i];
				var f2 = optionen[i+1];
				f1 != f2 ? txt = f1 + "-" + f2 : txt = f1;
				var newOpt = document.createElement("option");
				var newTxt = document.createTextNode(txt);
				newOpt.setAttribute("value", optionen[i]);
				document.form1.sel.appendChild(newOpt);
				newOpt.appendChild(newTxt);
				i++;
			}
			for (var i=0; i < laenge; i++) {
				var newOpt = document.createElement("option");
				var f1 = optionen[i];
				var f2 = optionen[i+1];
				f1 != f2 ? txt = f1 + "-" + f2 : txt = f1;
				var newTxt = document.createTextNode(txt);
				newOpt.setAttribute("value", optionen[i]);
				document.form2.sel.appendChild(newOpt);
				newOpt.appendChild(newTxt);
				i++;
			}
			for (i = 0; i < optionen.length; i++) {
				if(optionen[i] == "<?php echo $sel ?>") {
					break;
				}
			}
			document.form1.sel[i/2].selected = "true";
			document.form2.sel[i/2].selected = "true";
		}
		function vorkomma(z) {
			var s = z.toString();
			var p = s.indexOf(".");
			return s.substr(0, p);
		}
		function storeSS(id) {
			var value = document.getElementById(id).innerHTML;
			value = value.replace(/&amp;/g, '&');
			sessionStorage.setItem("ID", "symbolae");
			sessionStorage.setItem("auctor", value);
			document.location.href = "symbolae.php";
		}
	</script>
</head>
<body onload="store_mnu();">
	<?php
		include("header.inc.php");
	?>
	<div class="border">
		<div id="main">
			<h1>Symbolae · Index auctorum</h1>
			<table class="abc">
				<tr>
					<td class="abc">
						<form action="<?php echo $PHP_SELF ?>" method="post">
							<?php
								echo "<input class='abc' type='submit' name='bu' value='✳'>";
								foreach (range('A', 'Y') as $char) {
									echo "<input class='abc' type='submit' name='bu' value=$char>";
								}
								echo "<input class='abc' id='Z' type='submit' name='bu' value='Z'>";
							?>
						</form>
					</td>
				</tr>
			</table>
			<p id="treffer"><?php echo "&#160; " . $bu ?> = <?php echo $treffer ?></p>
			<form name="form1" style="visibility: hidden;" action="<?php echo $PHP_SELF ?>" method="post">
					<input class="inp_nav" type="submit" name="bl" value="l◄">
					<input class="inp_nav" type="submit" name="bl" value="◄">
					<input class="inp_nav" type="submit" name="bl" value="►">
					<input class="inp_nav" type="submit" name="bl" value="►l">
					<input type="hidden" name="bu" value="<?php echo $bu ?>">
					<input type="hidden" name="anf">
					<input type="hidden" name="zur">
					<input type="hidden" name="vor">
					<input type="hidden" name="end">
					<select name="sel" onChange="document.form1.submit()"></select>
			</form>
 			<?php
				$anz_angezeigte = 0;
				if ($insgesamt > 0) {
					if ($insgesamt <= 30) { $range = 0; }
					if ($insgesamt > 10) { $range = 30; }
					$sel = $sel-1;
					if ($insgesamt > 10) { $sql_limit = "LIMIT $sel, $range"; } else { $sql_limit =""; }
					$sql_select = "$sql_select $sql_limit";
					$sql_result = $db->query($sql_select);
					$anz_angezeigte = $sql_result->num_rows;
					$zaehler = $sel;
					echo "<table id='daten'>";
					while ($row = $sql_result->fetch_object()) {
						$autor = trim($row->Autor);
						if ($autor !="") {
							$zaehler++;
							echo "<tr><td class='zaehler'>$zaehler.</td><td class='zeile'>
								<a href='#' id='$zaehler' onClick='storeSS($zaehler); return false;'>$autor</a>
							</td></tr>";
						}
					}
					echo "</table>";
				}
				$db->close();
			?>
			<p>&#160;</p>
			<form name="form2" style="visibility: hidden;" action="<?php echo $PHP_SELF ?>" method="post">
				<input class="inp_nav" type="submit" name="bl" value="l◄">
				<input class="inp_nav" type="submit" name="bl" value="◄">
				<input class="inp_nav" type="submit" name="bl" value="►">
				<input class="inp_nav" type="submit" name="bl" value="►l">
				<input type="hidden" name="bu" value="<?php echo $bu ?>">
				<input type="hidden" name="anf">
				<input type="hidden" name="zur">
				<input type="hidden" name="vor">
				<input type="hidden" name="end">
				<select name="sel" onChange="document.form2.submit()"></select>
			</form>
			<?php
				if ($anz_angezeigte > 20) {
					echo "<p id='sursum'><a href='javascript:window.scrollTo(0, 0);'>sursum</a></p>";
				}
			?>
			<p>&#160;</p>
			<script type="text/javascript">
				createDatenseiten();
			</script>
			<script type="text/javascript">
				document.form1.anf.value = 0;
				document.form2.anf.value = 0;
				// nicht über Ende hinaus beim Vorblättern:
				var end = <?php echo $sel ?> + <?php echo $range ?> + 1;
				if (end > optionen[optionen.length-2]) { end = 1; }
				document.form1.vor.value = end ;
				document.form2.vor.value = end ;
				// nicht über Anfang hinaus beim Zurückblättern:
				var zur = <?php echo $sel ?> - <?php echo $range ?> + 1;
				if (zur < 0) { zur = 1; }
				document.form1.zur.value = zur;
				document.form2.zur.value = zur;
				// damit "Alle" ausgeschlossen bleibt:
				document.form1.end.value = optionen[optionen.length-2];
				document.form2.end.value = optionen[optionen.length-2];
				if ( "<?php echo $insgesamt ?>" > 30) {
					document.form1.style.visibility="visible";
				}
				if(("<?php echo $insgesamt ?>" > 30) && ("<?php echo $anz_angezeigte ?>" > 20)) {
					document.form2.style.visibility="visible";
				}
				if(("<?php echo $insgesamt ?>" <= 30) && ("<?php echo $anz_angezeigte ?>" > 20)) {
					document.getElementById("sursum").style.paddingTop = "0";
					document.form2.style.height = "0px";
				}
			</script>
		</div>
	</div>
	<?php include("footer.inc.php");?>
</body>
</html>
