<!DOCTYPE HTML>
<html lang="la">
<head>
	<title>Index generalis Palaestrae Latinae – Index fasciculi</title>
	<meta name="author" content="Bernd Platzdasch"><!-- 27.8.2017 // 23.12.2017 // 1.10.2020 -->
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<script src="js/store.js" type="text/javascript"></script>
	<style type="text/css">
		table { border-top: 1px solid lightgrey; border-collapse: collapse; margin-top: 0.5em; width: 100%; clear: both; }
		td { text-align: left; border-bottom: 1px solid lightgray; padding: 0.6em; }
		td.zaehler { text-align: right; vertical-align: top; color: gray; }
		td.stelle { vertical-align: middle; }
		h1#ix { padding: 29px 0 2em 0; float: left; }
		a.nav {border: 1px solid lightgrey; padding: 0 0.3em 0 0.3em;}
		a.nav:hover { text-decoration: none; background-color: gray; color: #fff; }
		span#erg { color: gray; font-weight: normal; }
		span.pointer { cursor: pointer; }
		div.vor_zur { text-align: right; margin: 29px 0 0 0; float: right; width: 200px; color: darkgray; }
		p#sursum { text-align: right; padding-top: 1.5em; clear: both; font-weight: bold; }
		p.tipp { font-size: smaller; color: gray; }
	</style>
</head>
<body onload="store_mnu();">
<?php
// Debugging:
// error_reporting(E_ALL);
// ini_set('display_errors', true);
	include("header.inc.php");	
	include("php/faszikel.inc.php");
	include("php/namen.inc.php");
	require_once $_SERVER['DOCUMENT_ROOT'] . '/db_connection.php';
?>
<div class="border">
	<div id="main">
		<?php
		// Fask.-Nr. einlesen
			$fasc = $_GET["f"];
			if (!strpos($fasc, ".")) {$fasc = $fasc . ".0";}
		// DB lesen
			$sql_select = "SELECT * FROM palaestralatina WHERE Faszikel LIKE $fasc ORDER BY Objektzaehler";
			$sql_result = $db->query($sql_select);
		// Erg. Faszikelbeschreibung
			$erg = $sql_result->fetch_object();
			$annus = $erg->Jahr;
			$monat = $erg->Monat;
			$band = $erg->Band;
			$bandteil = $erg->Bandteil;
			$sql_result->data_seek(0);
		// Navigation definieren
			$seq_neu = "";
			for($i = 0; $i < count($arr_fasc); $i++) {
				$seq = $arr_fasc[$i];
				$seq = substr($seq, 4);
				$seq = str_replace("-x", "", $seq);
				$seq_neu = $seq_neu . $seq;
			}
			$seq_neu = substr($seq_neu, 1);
			$arr_seq = explode("-", $seq_neu);
			$pos = array_search($fasc, $arr_seq);
			$zurueck = $arr_seq[$pos-1];
			$vor = $arr_seq[$pos+1];
			if (($fasc >1) && ($fasc < $ultimus)) {
				$navigation =	"<div class='vor_zur'>
									<a class='nav' href='contenta.php?f=$zurueck'>◄ $zurueck&#160;</a>&thinsp;<a class='nav' href='idx_fas.php'>&#160;Index&#160;</a>&thinsp;<a class='nav' href='contenta.php?f=$vor'>&#160;$vor ►</a>
								</div>";
			} else if ($fasc == 1) {
				$navigation = 	"<div class='vor_zur'>
									<a class='nav' href='idx_fas.php'>&#160;Index&#160;</a>&thinsp;<a class='nav' href='contenta.php?f=$vor'>&#160;$vor ►</a>
								</div>";
			} else {
				$navigation =	"<div class='vor_zur'>
									<a class='nav' href='contenta.php?f=$zurueck'>◄ $zurueck&#160;</a>&thinsp;<a class='nav' href='idx_fas.php'>&#160;Index&#160;</a>
								</div>";
			}
			
		// Überschrift u. Navigation oben anzeigen
			$bdbt = "";
			if (substr($fasc,-2) == ".0") {$fasc = substr($fasc, 0, -2);}
			if($fasc == "33") {$fasc = "33/4";$bandteil="6-7";}
			if($fasc == "63") {$fasc = "63/4";$bandteil="";}
			if($fasc == "77") {$fasc = "77/8";$bandteil="1-2";}
			if($fasc == "175") {$fasc = "175/6";$bandteil="3-4";}
			$bdbt = $monat . " ". $annus . "; a. " . $band . ", f. " . $bandteil;
			
			if ($bandteil == 0) {$bdbt = "a. " . $band . ", " . $annus;}
			
			
			if(($fasc >= 53) AND ($fasc <= 157) OR ($fasc == 200) OR ($fasc == 222) OR ($fasc == 223)) {
				$pal_url = rtrim($pal_url, "-"); 
				$pal_url = $pal_url . "_";
			}
			$ueberschrift = "<h1 id='ix'>Index fasciculi: n. $fasc<span id='erg'> (" . $bdbt. ")</span></h1>";
			echo $ueberschrift . $navigation;
		// Anpassen für Links
			if($fasc == "33/4") {$fasc = "33 et 34";}
			if($fasc == 53.1){$fasc = "53a";}
			if($fasc == 53.2){$fasc = "53b";}
			if($fasc == 54.1){$fasc = "54a";}
			if($fasc == 54.2){$fasc = "54b";}
			if($fasc == "63/4") {$fasc = "63_64";}
			if($fasc == "77/8") {$fasc = "77_78";}
			if($fasc == "175/6") {$fasc = "175-6";}
			if(($fasc >= 1) AND ($fasc <= 9)) {$fasc = "0".$fasc;}
			// Inhaltsverzeichnis erstellen
			$zaehler = 0;
			echo "<table>";
		// Ausgabeschleife
			while ($row = $sql_result->fetch_object()) {
				$zaehler++;
				$titel = $bis = $seite = $PDFseite = $ort = $ort_ganz = $empfaenger = $empfaenger_ganz = $textgattung = $uebersetzung = $autor = $autor_ganz = $briefdatum = "";
				//
				$sql_select = "SELECT * FROM palaestralatina_namen WHERE NameID = $row->AutorID";
				$sql_result_a = $db->query($sql_select);
				$rowAutor = $sql_result_a->fetch_object();
				//
				$sql_select = "SELECT * FROM palaestralatina_namen WHERE NameID = $row->BriefempfaengerID";
				$sql_result_b = $db->query($sql_select);
				$rowBriefempfaenger = $sql_result_b->fetch_object();
				//
				$sql_select = "SELECT * FROM palaestralatina_namen WHERE NameID = $row->OriginalautorID";
				$sql_result_o = $db->query($sql_select);
				$rowOriginalautor = $sql_result_o->fetch_object();
				//
				$PDFseite = $row->PDFseite;
				if (!empty($row->Titel)) {
					$titel = $row->Titel;
					$titel = "<span style='color: #333; font-weight: bold;'>" . $titel . "<br></span>";
				}
				if (!empty($row->Bis)) {
					$bis = $row->Bis;
					$bis = "-" . $bis;
				}
				if (!empty($row->Seite)) {
					$seite = $row->Seite;
				}
				if (!empty($rowBriefempfaenger->Name)) {
					$empfaenger_ganz = $rowBriefempfaenger->Name;
					$empfaenger = erster_name($empfaenger_ganz);
					$empfaenger = vorname_nachname($empfaenger);
					$empfaenger_ganz = alle_namen($empfaenger, $rowBriefempfaenger->Name);
				}
				if (!empty($row->Briefdatum)) {
					$briefdatum = str_replace("00.", "", $row->Briefdatum);
					$briefdatum = ", " . $briefdatum;
				}
				if (!empty($row->Textgattung)) {
					$textgattung = "[" . $row->Textgattung . "]";
				}
				if (!empty($row->Ort)) {
					$ort_ganz = $row->Ort;
					$ort = erster_name($row->Ort);
					$ort = ": ". $ort;
				}
				if ($row->Textgattung == "Epistula") {
					$textgattung = "[" . $row->Textgattung . "<span class='pointer' title='$ort_ganz'>" . $ort . "</span>" . $briefdatum . "]";
				}
				if ($row->Textgattung == "Diploma") {
					$textgattung = "[" . $row->Textgattung . "<span class='pointer' title='$ort_ganz'>" . $ort . "</span>" . $briefdatum . "]";
				}
				if ($row->Uebersetzung == "1") {
					if (!empty($rowOriginalautor->Name)) {
							$originalautor_ganz = $rowOriginalautor->Name;
							$originalautor = erster_name ($originalautor_ganz);
							$originalautor = vorname_nachname($originalautor);
							$originalautor_ganz = alle_namen($originalautor, $rowOriginalautor->Name);
					}
					if (!empty($rowOriginalautor->Name)) {
							$uebersetzung = " [Versio: " . "<span class='pointer' title='$originalautor_ganz'>" . $originalautor ." </span>]";
					}
					if ((!empty($rowOriginalautor->Name)) && (!empty($row->Originaltitel))) {
							$uebersetzung = " [Versio: " . "<span class='pointer' title='$originalautor_ganz'>" . $originalautor . "</span>: «" . $row->Originaltitel . "»]";
					}
					if ((empty($rowOriginalautor->Name)) && (!empty($row->Originaltitel))) {
								$uebersetzung = " [Versio: «" . $row->Originaltitel . "»]";
					}
				}
				if (!empty($rowAutor->Name)) {
					$autor_ganz = $rowAutor->Name;
					$autor = erster_name($autor_ganz);
					$autor = vorname_nachname($autor);
					$autor_ganz = alle_namen($autor, $rowAutor->Name);
					if ($empfaenger != "") {
						$autor = $autor . " &rarr; <span class='pointer' title='" . $empfaenger_ganz . "'>" . $empfaenger . "</span><br>";
					} else {
						$autor = $autor .":<br>";
					}
				}
				// PDF-Link
				$lnk = "<a target='_blank' href='$pal_url$fasc.pdf#page=$PDFseite'>";
				if($PDFseite == "0") {$lnk = "";}
				echo "<tr>
						<td class='zaehler'>" . $zaehler . ".</td>
						<td><span class='pointer' title='". $autor_ganz ." '>". $autor ."</span>" . $titel . $textgattung . $uebersetzung . "</td>	
						<td class='stelle'><span style='white-space: nowrap'>$lnk" . $seite . $bis . "</a></span></td>
					</tr>";
		// Ende Ausgabeschleife
			}
			echo "</table>";
			$db->close();
		
		// Navigation unten anzeigen
			echo $navigation;
		?>
		<p id="sursum"><a href="javascript: window.scrollTo(0, 0);">sursum</a></p>
		<p class="tipp">Si nomen auctoris indice muris tangis, omnia nomina eidem imposita offeruntur.</p>
	</div>
</div>
<?php include("footer.inc.php");?>
</body>
</html>
