<?php

//###### zugehörige Daten anhand des Page-Namens ermitteln
$currentPageNamespacePathArray = explode(':', $_GET["id"]);
array_pop($currentPageNamespacePathArray);
$currentSaveFilePath = phpConvertNamespaceToFilesystemPath(implode(':', $currentPageNamespacePathArray));
$currentPageFilePath = phpConvertNamespaceToFilesystemPath(implode(':', $currentPageNamespacePathArray) . ':gliederung');
$currentPageId = end(explode( ':', htmlspecialchars($_GET["id"]) ));
//###### CSS-Datei inkludieren
//##################################################################################
include($includeCss);
$starttime = microtime(true); // Top of page
if (file_exists($currentSaveFilePath . '/index_generated.txt')) {
  $bookStructure = json_decode(file_get_contents($currentSaveFilePath . '/index_generated.txt'), true);
  $arraySource = 'Datei';
} else {    
  $bookStructure = recursiveScanBookStructure($currentPageFilePath);
  $arraySource = 'Verzeichnis';
}
$endtimeArray = microtime(true); // Bottom of page

//###### HTML-Tag öffnen
//##################################################################################
echo '<html>';

echo '

  <div class="parentbox"><!-- ###### parentbox umspannender Inhalts-Container (öffnen) -->
      <div class="parentbox-column-left"><!-- ###### Linke Spalte (öffnen) -->
        <div class="titlebox"><!-- ###### titlebox (Projektname) (öffnen)-->
          <div class="titlebox-top"></html>' . $title . '<html></div>
          <div class="titlebox-bottom"></html>' . $title2 . '<html></div>
        </div><!-- ###### titlebox (Produktname) (schließen)-->
        <div class="sectionbox-row"><!-- ###### Sectionbox für Spalten im umspannenden Inhalts-Container (öffnen) -->
          <div class="sectionbox-left-column"><!-- ###### Sectionbox für Spalten im umspannenden Inhalts-Container (öffnen) -->
            <div class="coverbox-image"></html>{{' . $cover . '?nolink}}<html></div>
            <div class="contentbox-beneath-image">
              <div class="contentbox-title">Genre</div>
              <div class="contentbox-content"></html>' . $genre . '<html></div>
            </div>
          </div>
          <div class="sectionbox-right-column"><!-- ###### Sectionbox für Spalten im umspannenden Inhalts-Container (öffnen) -->
            <div class="contentbox-beside-cover">
              <div class="normpagebox">
                <div class="normpagebox-title"> Zusammenfassung</div>
                <div class="normpagebox-content">' . $summary . '</div>
              </div>
            </div>
          </div>
        </div>
        <div class="sectionbox-row"><!-- ###### sectionbox (Vorwort) (öffnen)-->
          <div class="contentbox">
            <div class="contentbox-title">Anmerkungen</div>
            <div class="contentbox-content"></html>' . $information . '<html></div>
          </div>
        </div>

';

$bookCounter = 0;
$bookStructureArrayCounter=0;
while ($bookStructureArrayCounter < sizeof($bookStructure)) {
  if ($bookStructure[$bookStructureArrayCounter]['type'] == '0') {
    $bookCounter ++;
    echo'
        <div class="tocBox">
          <div class="tocBoxFirstColumn">
            <div class="tocBoxBookNumber">' . $bookCounter . '</div>
          </div>
          <div class="tocBoxSecondColumn"></div>
          <div class="tocBoxThirdColumn"></div>
          <div class="tocBoxFourthColumn">
            <details' . (($bookStructureArrayCounter==0) ? ' open' : '') . '>
              <summary class="tocBoxHiddenBlock">
                <div class="tocBoxHiddenBlockTitle">' . $bookStructure[$bookStructureArrayCounter]['title'] . '</div>
              </summary>
              <div class="legendRow">
                <div class="legendColumnIcon">&#215;</div>
                <div class="legendColumnText" style="background: mistyrose;">Leer</div>
                <div class="legendColumnIcon">&#9998;</div>
                <div class="legendColumnText" style="background: sandybrown;">Entwurf</div>
                <div class="legendColumnIcon">&#9997;</div>
                <div class="legendColumnText" style="background: khaki;">Korrektur</div>
                <div class="legendColumnIcon">&#10004;</div>
                <div class="legendColumnText" style="background: ghostwhite;">Fertig</div>
              </div>
              <div class="tocBoxHiddenBlockChapterStructure">
                <div class="tocBoxHiddenBlockRowHeadline">
                  <div class="tocBoxBookStructureFirstColumnChapter">Akt</div>
                  <div class="tocBoxBookStructureSecondColumnChapter">Kapitel</div>
                  <div class="tocBoxBookStructureThirdColumnChapter">Titel</div>
                </div>';
    $bookStructureArrayCounter++;
    while ( ($bookStructure[$bookStructureArrayCounter]['type'] == '1') || ($bookStructure[$bookStructureArrayCounter]['type'] == '2') ) {
      //###### Tabelle fuer Buchueberschrift
      echo '
                <div class="tocBoxHiddenBlockRow"">
                  <div class="' . (($bookStructure[$bookStructureArrayCounter]['type'] == '1') ? 'tocBoxBookStructureFirstColumnAct' : 'tocBoxBookStructureFirstColumnChapter') . '">' . (($bookStructure[$bookStructureArrayCounter]['type'] == '1') ? $bookStructure[$bookStructureArrayCounter]['structureName'] : '&nbsp;') . '</div>
                  <div class="' . (($bookStructure[$bookStructureArrayCounter]['type'] == '1') ? 'tocBoxBookStructureSecondColumnAct' : 'tocBoxBookStructureSecondColumnChapter') . '">' . (($bookStructure[$bookStructureArrayCounter]['type'] == '2') ? $bookStructure[$bookStructureArrayCounter]['structureName'] : '&nbsp;') . '</div>
                  <div class="' . (($bookStructure[$bookStructureArrayCounter]['type'] == '1') ? 'tocBoxBookStructureThirdColumnAct' : 'tocBoxBookStructureThirdColumnChapter') . '"></html>[[' . $bookStructure[$bookStructureArrayCounter]['wikiPath'] . '|' . $bookStructure[$bookStructureArrayCounter]['title'] . ']]<html></div>
                </div>';
      $bookStructureArrayCounter++;
    }
    echo '      
              </div>
            </details>
          </div>
          <div class="tocBoxFifthColumn"></div>
        </div>';
  }
}
echo'
      </div><!-- ###### Linke Spalte (schließen) -->
      <div class="parentbox-column-right"><!-- ###### ###### Rechte Spalte (öffnen) -->
';
include($sidebarRight);
echo'
      </div><!-- ###### ###### Rechte Spalte (schließen) -->
  </div><!-- ###### parentbox umspannender Inhalts-Container (schließen) -->';

//###### HTML-Tag schließen
//##################################################################################
echo '</html>';
$endtimePage = microtime(true); // Bottom of page

echo 'Array wurde in ' . round($endtimeArray - $starttime, 4) . ' Sekunden aus ' . $arraySource . ' eingelesen; Page wurde in ' . round($endtimePage - $starttime, 4) . ' Sekunden generiert'; ?>