<!DOCTYPE HTML>
<html lang="la">
<head>
	<title>Index generalis Societatis Latinae – Nomen inquirere</title>
	<meta name="author" content="Bernd Platzdasch"><!-- 23.8.2020 -->
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<script type="text/javascript" src="js/jquery-1.11.2.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/jquery-ui-1.11.4.custom/jquery-ui.min.js"></script>
	<link rel="stylesheet" type="text/css" href="js/jquery-ui-1.11.4.custom/jquery-ui.css">
	<script src="js/store.js" type="text/javascript"></script>
	<style type="text/css">
		h1 { padding-bottom: 0.3em; }
		div.suche { border: 1px solid #ccc; width: 100%; height: 7.6em; background-color: #f2f2f2; border-radius: 3px; }
		form#form1 { padding: 1.5em 0 0 2.5em; }
		div#buttons { padding: 1.3em 0 0 0; background-color: #f2f2f2; width: 300px; margin-left: 0px; }
		table#ausg { border: none; padding: 2.5em 0 2em 2em; }
		td { vertical-align: top; }
		td.zaehler { text-align: right; color: gray; padding-right: 0.5em; width: 1em; }
		td.list-style { width: 1.1em; }
		p#treffer { text-align: right; padding-right: 1em; padding-bottom: 1em; }
		p#kein_treffer { width: 100%; font-weight: bold; padding: 2em 0 0 2em; }
		span.label { color: darkgreen; }
		p#sursum { text-align: right; padding-top: 0.3em; font-weight: bold; }
		li.ui-menu-item { font-size: small !important; }
	</style>
	<script>
		$(document).ready(function() {
			$("#inp_anfrage").autocomplete({
				source: 'auto_nom.php',
				minLength: 3,
				delay: 500
			});
			$("input").bind("keydown", function(event) {
				var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
				if (keycode == 13) {
					document.getElementById('defaultActionButton').click();
					return false;
				} else {
					return true;
				}
			});
		});
	</script>
	<?php    
	
// Debugging:
// error_reporting(E_ALL);
// ini_set('display_errors', true);
		// Variablen initialisieren
		$insgesamt = "";
		$treffer = "";
		//
		$PHP_SELF = $_SERVER ["PHP_SELF"];
		$anfrage = (isset($_POST ["anfrage"])) ? $_POST ["anfrage"] : "";
		if ($anfrage != "") {
			$anfrage = trim($anfrage);
			$anfrage = addslashes($anfrage);
			//
			require_once $_SERVER['DOCUMENT_ROOT'] . '/db_connection.php';
			//
			$sql_select = "SELECT * FROM societaslatina_namen WHERE
				((Name LIKE '%$anfrage%') AND (Name NOT LIKE '%/%')) OR (Originalname LIKE '%$anfrage%') ORDER BY Name";
			$sql_result = $db->query($sql_select);
			$insgesamt = $sql_result->num_rows;
			switch ($insgesamt) {
			case 0:
				$treffer = "";
				break;
			case 1:
				$treffer = "1 nomen!";
				break;
			default:
				$treffer = $insgesamt . " nomina!";
			}
		}
	?>
	<script type="text/javascript">
		function init() {
			store_mnu();
			// document.getElementById("inp_anfrage").focus();
			document.getElementById("inp_anfrage").value = "<?php echo $anfrage ?>";
		}
		function submitValidate() {
			var ind = document.getElementById("inp_anfrage").value;
			ind = ind.trim();
			if ((ind.length < 3) ||  (ind.indexOf("_") != -1)) {
				document.getElementById("inp_anfrage").focus();
				alert ("Inde saltem litteras tres!");
				return false;
			}
		}
		function formularNeu() {
			window.location.href = "nomen.php";
		}
	</script>
</head>
<body onLoad="init();">
	<?php
		include("header.inc.php");
		include("php/namen.inc.php");
	?>
	<div class="border">
		<div id="main">
			<h1>Nomen inquirere</h1>
			<div class="suche">
				<form id="form1" onsubmit="return submitValidate();" action="<?php echo $PHP_SELF ?>" method="POST">
					<input type="search" id="inp_anfrage" name="anfrage" class="texteingabe" autofocus style="width: 80%;" placeholder="«cognomen, praenomen» AUT «cognomen» (etiam truncatum)">
					<div id="buttons">
						
						<input type="button" class="button" value="Delere" onClick="formularNeu();">
						<input type="submit" class="button" id="defaultActionButton" value="Inquirere">
					</div>
					<p id="treffer"> <?php echo $treffer ?></p>
				</form>
			</div>
			<?php
				$anfrage = trim($anfrage);
				if (($insgesamt == 0 ) && ($anfrage != "" )) {
					echo "<p id='kein_treffer'>";
					echo "«" . $anfrage . "» non inventum est.";
					echo "</p>";
				}
				function vorname_nachname_str ($value) {
					// nur bei Strings
					$pos = strpos($value, ",");
					if ($pos != false) {
						$cognomen = substr($value, 0, $pos);
						$praenomen = substr($value, $pos+2);
						$value 	= $praenomen . " " . $cognomen;
					}
					return $value;
				}
				$zaehler = 0;
				if (($insgesamt > 0) && ($anfrage != "")) {
					echo "<table id='ausg'>";
					
				// Ausgabeschleife
					while ($row = $sql_result->fetch_object()) {
						$zaehler++;
						// angesetzter Name
						$erster_name = $row->ersterName;
						echo "<tr>
								<td class='zaehler'>" . $zaehler . ".</td>
								<td colspan='2'><b>" . $erster_name ."</b></td>
							</tr>";
						// Synonyma
						if ($erster_name != $row->Name) {
							$alle_namen = $row->Name;
							$alle_namen = explode(" = ", $alle_namen);
							array_walk($alle_namen,"vorname_nachname_arr");
							// erstes Element des Arrays entfernen:
							// $erstes_element = array_shift($alle_namen);
							sort($alle_namen);
							$alle_namen = implode(" = ", $alle_namen);
							// $alle_namen = " = " . $alle_namen;
							echo "<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><span class='label'>Nomina in «Societate Latina»: </span>". $alle_namen . "</td>
								</tr>";
						}
						// Geburtsame
// 						if (($row->Originalname != "" ) && ($row->Originalname != $erster_name)) {
						if ($row->Originalname != "" ) {
						$originalname = vorname_nachname_str($row->Originalname);
						echo 	"<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><span class='label'>Nomen genuinum: </span>" . $originalname . "</td>
								</tr>";
						}
						// externer Link mit Infos über den Namensträger
						$extLink = trim($row->extLink);
						if ($extLink != "" ) {
							echo "<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><a target= '_blank' href='" . $extLink . "'>Scitu digna</a></td>
								</tr>";
						}
						$erster_name = urlencode($erster_name);
						if ($row->symbolae != 0) {
							echo "<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><a target= '_blank' href='symbolae.php?auctor=$erster_name'>Symbolae: $row->symbolae</a></td>
								</tr>";
						}
						if ($row->epist_mis != 0) {
							echo "<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><a target= '_blank' href='symbolae.php?auctor=$erster_name&genlit=Epistula'>Epistulae missae: $row->epist_mis</a></td>
								</tr>";
						}
						if ($row->interpretes != 0) {
							echo "<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><a target= '_blank' href='versiones.php?aucV=$erster_name'>Interpres: $row->interpretes</a></td>
								</tr>";
						}
						if ($row->versiones != 0) {
							echo "<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><a target= '_blank' href='versiones.php?aucO=$erster_name'>Versiones: $row->versiones</a></td>
								</tr>";
						}
						if ($row->diplo_acc != 0) {
							$vor_nach = vorname_nachname_str($row->ersterName);
							$vor_nach = urlencode($vor_nach);
							echo "<tr>
									<td class='zaehler'>&#160;</td>
									<td class='list-style'>–&#160;</td>
									<td><a target= '_blank' href='idx_dip.php?$vor_nach'>Diplomata accepta: $row->diplo_acc</a></td>
								</tr>";
						}
				// 	Ende Ausgabeschleife
					}
					echo "</table>";
					$db->close();
				}
				if ($zaehler >= 5) {
					echo "<p id='sursum'><a href='javascript: window.scrollTo(0, 0);'>sursum</a></p>";
				}
			?>
			<p>&#160;</p>
		</div>
	</div>
	<?php include("footer.inc.php");?>
</body>
</html>
