<?php
  // Set up standard record scripts:
  $this->headScript()->appendFile("record.js");
  $this->headScript()->appendFile("check_save_statuses.js");
  $this->headScript()->appendFile("accordion.js");

  $heading = $this->driver->getTitle();
  if (empty($heading)) {
    $heading    = $this->translate('Heading unavailable.');
  }
  $id           = $this->driver->getID();
  $seeAlso      = $this->driver->getSeeAlso();
  $useFor       = $this->driver->getUseFor();
  $useForText   = $this->driver->getUseForText();
  $relatedTerm  = $this->driver->getRelatedTerm();
  $narrowerTerm = $this->driver->getNarrowerTerm();
  $broaderTerm  = $this->driver->getBroaderTerm();
  $usedEarlier  = $this->driver->getUsedEarlier();
  $usedLater    = $this->driver->getUsedLater();
  $scopeNote    = $this->driver->getScopeNote();
  $authorityType =$this->driver->getRecordType();
  $occurance 	= $this->driver->getOccurance();

  $coreFields = [       "Scopenote"     => $scopeNote,
                        "Authority type"=> $authorityType,
                        "See also"      => $seeAlso,
                        "Use for"       => $useFor,
                        "Related term"  => $relatedTerm,
                        "Narrower term" => $narrowerTerm,
                        "Broader term"  => $broaderTerm,
                        "Used earlier"  => $usedEarlier,
                        "Used later"    => $usedLater
                ];

  $searchFields = [     "Corporate"     => "Author",
                        "Subject"       => "topicExact",
                        "Classification"=> "Classification",
                        "Publisher"     => "Publisher",
                        "Person"        => "Author"
                  ];

  $this->layout()->title = $this->driver->getShortTitle();
?>

<div class="record source<?=$this->escapeHtmlAttr($this->driver->getSourceIdentifier())?>">
	<div class="<?=$this->layoutClass('mainbody')?>">

		<?php if (isset($this->scrollData) && ($this->scrollData['previousRecord'] || $this->scrollData['nextRecord'])): ?>
          		<ul class="pager hidden-print">
              			<?php if ($this->scrollData['previousRecord']): ?>
                  			<?php if ($this->scrollData['firstRecord']): ?>
                      				<li>
                          				<a href="<?=$this->recordLinker($this->results)->getUrl($this->scrollData['firstRecord'])?>" title="<?=$this->transEsc('First Search Result')?>" rel="nofollow">&laquo; <?=$this->transEsc('First')?></a>
                      				</li>
                  			<?php endif; ?>
                  			<li>
                      				<a href="<?=$this->recordLinker($this->results)->getUrl($this->scrollData['previousRecord'])?>" title="<?=$this->transEsc('Previous Search Result')?>" rel="nofollow">&laquo; <?=$this->transEsc('Prev')?></a>
                  			</li>
              			<?php else: ?>
                  			<?php if ($this->scrollData['firstRecord']): ?>
                      				<li class="disabled"><a href="#">&laquo; <?=$this->transEsc('First')?></a></li>
                  			<?php endif; ?>
                  			<li class="disabled"><a href="#">&laquo; <?=$this->transEsc('Prev')?></a></li>
              			<?php endif; ?>
              			<?=$this->transEsc('of_num_results', [
                  			'%%position%%' => $this->localizedNumber($this->scrollData['currentPosition']),
                  			'%%total%%' => $this->localizedNumber($this->scrollData['resultTotal'])
              			]) ?>
              			<?php if ($this->scrollData['nextRecord']): ?>
                  			<li>
                      				<a href="<?=$this->recordLinker($this->results)->getUrl($this->scrollData['nextRecord'])?>" title="<?=$this->transEsc('Next Search Result')?>" rel="nofollow"><?=$this->transEsc('Next')?> &raquo;</a>
                  			</li>
                  			<?php if ($this->scrollData['lastRecord']): ?>
                      				<li>
                          				<a href="<?=$this->recordLinker($this->results)->getUrl($this->scrollData['lastRecord'])?>" title="<?=$this->transEsc('Last Search Result')?>" rel="nofollow"><?=$this->transEsc('Last')?> &raquo;</a>
                      				</li>
                  			<?php endif; ?>
              			<?php else: ?>
                  			<li class="disabled"><a href="#"><?=$this->transEsc('Next')?> &raquo;</a></li>
                  			<?php if ($this->scrollData['lastRecord']): ?>
                      				<li class="disabled"><a href="#"><?=$this->transEsc('Last')?> &raquo;</a></li>
                  			<?php endif; ?>
              			<?php endif; ?>
          		</ul>
      		<?php endif; ?>

		<div class="clear"></div>

      		<?//=$this->record($this->driver)->getToolbar()?>
    		<input type="hidden" value="<?=$this->escapeHtmlAttr($this->driver->getUniqueId())?>" class="hiddenId" />
    		<input type="hidden" value="<?=$this->escapeHtmlAttr($this->driver->getSourceIdentifier()) ?>" class="hiddenSource" />
    		<?=$this->flashmessages()?>
    		<?//=$this->record($this->driver)->getCoreMetadata()?>

		<div class="media-body">
    			<div class="result-body">
        			<div class="title-container">
           				<!-- https://lit.bibb.de/vufind/Search/Results?lookfor=keck&type=Subject&limit=20&sort=year -->
           				<a href="https://lit.bibb.de/vufind/Search/Results?lookfor=<?=urlencode('"' .$heading .'"') ?>&type=<?=$searchFields[$authorityType]?>&limit=20&sort=year" class="title"><?=$this->escapeHtml($heading)?></a>
					<span style="font-size:17px">(<?= $this->transEsc($authorityType) ?>)</span>
					<?php //if($authorityType == "Subject") : ?>
					<!--	<span style="font-size:17px">(<?php // = $occurance ?>)</span> -->
					<?php //endif ; ?>
				        <?php if (!empty($coreFields['Scopenote'])) : ?>
                				<p>
                				<span style="font-size:17px;font-weight:normal"><?=$this->escapeHtml($coreFields['Scopenote'])?></span>
                				<p>
           				<?php endif ; ?>
           				<?php if (!empty($useForText)) : ?>
                				<p><span style="font-size:17px;font-weight:bold"><?= $this->transEsc('Use for') ?>: </span>
                        			<span style="font-size:17px;">  <?= $useForText ?> </span>
           				<?php endif ; ?>
        			</div>

				<table class="table table-striped">
				<tr>
                                	<td width="35%"></td>
                                	<td width="1%"></td>
                                	<td width="*"></td>
                        	</tr>

					<?php  foreach ($coreFields as $key => $current): ?>
                                	        <?php $displayed = false ?>
                                        	<?php if ($key  != "Scopenote" && $key != "Use for" && $key != "Authority type") : ?>
                                                	<?php if ($displayed === false) : ?>
                                                        	<?php if (!empty ($coreFields[$key] )) : ?>
                                                                	<tr><td><?=$this->transEsc($key)?>:</td><td></td><td>
                                                                	<?php $displayed = true; ?>
                                                        	<?php endif; ?>
                                                	<?php endif ; ?>
                                               		<?php foreach($current as $entry) : ?>
                                                        	<?php $tmp = explode("|", $entry) ; list($id, $text) = $tmp; ?>
                                                        	<a href="<?=$id?>"><?=($text)?></a><p>
                                                	<?php endforeach; ?>
                                                	</td></tr>
                                        	<?php endif ; ?>
                                	<?php endforeach ;?>
				</table>
    				<?/* End Main Details */?>
    			</div>
		</div>
	</div>
</div>
