<?php

//###### zugehörige Daten anhand des Page-Namens ermitteln
$currentPageFileIndexPath = $currentPageFilePath . '/gliederung';
if (file_exists($currentPageFilePath . '/index_generated.txt')) {
  $bookStructure = json_decode(file_get_contents($currentPageFilePath . '/index_generated.txt'), true);
} else {    
  $bookStructure = phpBookGetStructureRecursive($currentPageFileIndexPath);
}

//###### HTML-Tag öffnen
//##################################################################################
echo '<html>';
$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) && (!isset($closeDetail)))? ' 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>';
  }
}

//###### HTML-Tag schließen
//##################################################################################
echo '</html>';

?>