<?php
  $heading = $this->driver->getTitle();
  if (empty($heading)) {
    $heading 	= $this->translate('Heading unavailable.');
  }
  $id 		= $this->driver->getID();
  $seeAlso 	= $this->driver->getSeeAlso();
  $useForText 	= $this->driver->getUseForText();
  $useFor	= $this->driver->getUseFor();
  $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 = [	"Authority type"=> $authorityType,
			"Scopenote"	=> $scopeNote,
			"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"
		  ]; 

// print_r($useFor); 

			
?>

<input type="hidden" value="<?=$this->escapeHtmlAttr($this->driver->getUniqueID())?>" class="hiddenId" />
<input type="hidden" value="<?=$this->escapeHtmlAttr($this->driver->getSourceIdentifier())?>" class="hiddenSource" />

<div class="media-body">
    <div class="result-body">
	<div class="title-container">
	   <a class="title" href="https://lit.bibb.de/vufind/Search/Results?lookfor=<?= rawurlencode('"' .$heading .'"') ?>&type=<?= $searchFields[ $authorityType] ?>&limit=20&sort=year"><?= $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 ; ?>

   	   <?php $c= empty($coreFields['See also']) && empty($coreFields['Related term']) && empty($coreFields['Narrower term']) && empty($coreFields['Broader term']) && empty($coreFields['Used later']) && empty($coreFields['Used earlier']) ?>
	   <?php if ($c === false) : ?>
             <table class="table table-striped">
		<?//= $c ?>
		    <table width="99%">
            		<tr>
                		<td width="35%"></td>
				<td width="1%"></td>
                		<td width="*"></td>
            		</tr>
            		<tbody class="result-table">
            			<tr>
                			<th><?=$this->transEsc("Relation")?></th>
                			<th>&nbsp;</th>
                			<th><?=$this->transEsc("Term")?></th>
            			</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?>" class="title"><?=$this->escapeHtml($text)?></a><p>
						<?php endforeach; ?>
						</td></tr>
					<?php endif ; ?>	
				<?php endforeach ;?>
                                </tr>
			</tbody>
		   </table>
	      <?php endif ; ?>
	</table>
        </div>
    <?/* End Main Details */?>
    </div>
</div>
