<?
  $coverDetails = $this->record($this->driver)->getCoverDetails('result-list', 'medium', $this->recordLink()->getUrl($this->driver));
  $cover = $coverDetails['html'];
  $thumbnail = false;
  $thumbnailAlignment = $this->record($this->driver)->getThumbnailAlignment('result');
  if ($cover):
    ob_start(); ?>


    <div class="media-<?=$thumbnailAlignment ?> <?=$this->escapeHtmlAttr($coverDetails['size'])?>">
      <?=$cover ?>
    </div>
    <? $thumbnail = ob_get_contents(); ?>
  <? ob_end_clean(); ?>
<? endif; ?>
<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">
  <? if ($thumbnail && $thumbnailAlignment == 'left'): ?>
    <?=$thumbnail ?>
  <? endif ?>
  <div class="media-body">
    <div class="result-body">

        <div class="title-container">
            <a href="<?=$this->recordLink()->getUrl($this->driver)?>" class="title getFull" data-view="<?=$this->params->getOptions()->getListViewOption() ?>">
                <?=$this->record($this->driver)->getTitleHtml()?>
            </a>
        </div>

        <div class="author">
            <? $summAuthors = $this->driver->getPrimaryAuthorsWithHighlighting(); if (!empty($summAuthors)): ?>
                <?=$this->transEsc('by')?>
                <? $authorCount = count($summAuthors); foreach ($summAuthors as $i => $summAuthor): ?>
                    <a href="<?=$this->record($this->driver)->getLink('author', $this->highlight($summAuthor, null, true, false))?>"><?=$this->highlight($summAuthor)?></a><?=$i + 1 < $authorCount ? ';' : ''?>
                <? endforeach; ?>
            <? endif; ?>
        </div>

        <table class="result-table">
            <tr>
                <th>Format</th>
                <th><?=$this->transEsc("Location")?></th>
                <th><?=$this->transEsc('Call Number')?></th>
                <th><?=$this->transEsc("Availability")?></th>
            </tr>
            <tr>
                <td><?=$this->record($this->driver)->getFormatList() ?></td>
                <td>
                    <div class="callnumAndLocation ajax-availability hidden">
                        <? if ($this->driver->supportsAjaxStatus()): ?>
                            <span class="location ajax-availability hidden">
                                <?=$this->transEsc('Loading')?>...
                            </span>
                            <div class="locationDetails"></div>
                        <? endif; ?>
                    </div>
                </td>
                <td>
                    <? $summCallNo = $this->driver->getCallNumber(); if (!empty($summCallNo)): ?>
                        </strong> <?=$this->escapeHtml($summCallNo)?>
                    <? endif; ?>
                </td>

                <td>
                    <? if (!$openUrlActive && empty($urls) && $this->driver->supportsAjaxStatus()): ?>
                        <span class="status ajax-availability hidden">
                        <span class="label label-default"><?=$this->transEsc('Loading')?>...</span>
                      </span>

                    <? endif; ?>
                </td>
            </tr>
        </table>

      <div class="published">
        <? if($this->driver->isCollection()): ?>
          <?=implode('<br>', array_map(array($this, 'escapeHtml'), $this->driver->getSummary())); ?>
        <? else: ?>

          <? $journalTitle = $this->driver->getContainerTitle(); $summDate = $this->driver->getPublicationDates(); ?>
          <? if (!empty($journalTitle)): ?>
            <?=!empty($summAuthor) ? '<br />' : ''?>
            <?=$this->transEsc('Published in')?>
            <? $containerSource = $this->driver->getSourceIdentifier(); ?>
            <? $containerID = $this->driver->getContainerRecordID(); ?>
            <? /* TODO: handle highlighting more elegantly here: */?>
            <a href="<?=($containerID ? $this->recordLink()->getUrl("$containerSource|$containerID") : $this->record($this->driver)->getLink('journaltitle', str_replace(array('{{{{START_HILITE}}}}', '{{{{END_HILITE}}}}'), '', $journalTitle)))?>"><?=$this->highlight($journalTitle) ?></a>
            <?=!empty($summDate) ? ' (' . $this->escapeHtml($summDate[0]) . ')' : ''?>
          <? elseif (!empty($summDate)): ?>
            <?=!empty($summAuthor) ? '<br />' : ''?>
            <?=$this->transEsc('Published') . ' ' . $this->escapeHtml($summDate[0])?>
          <? endif; ?>
          <? $summInCollection = $this->driver->getContainingCollections(); if (!empty($summInCollection)): ?>
            <? foreach ($summInCollection as $collId => $collText): ?>
              <div>
                <b><?=$this->transEsc("in_collection_label")?></b>
                <a class="collectionLinkText" href="<?=$this->url('collection', array('id' => $collId))?>?recordID=<?=urlencode($this->driver->getUniqueID())?>">
                  <?=$this->escapeHtml($collText)?>
                </a>
              </div>
            <? endforeach; ?>
          <? endif; ?>
        <? endif; ?>
      </div>

      <? if(!$this->driver->isCollection()): ?>
        <? if ($snippet = $this->driver->getHighlightedSnippet()): ?>
          <? if (!empty($snippet['caption'])): ?>
            <strong><?=$this->transEsc($snippet['caption']) ?>:</strong> ';
          <? endif; ?>
          <? if (!empty($snippet['snippet'])): ?>
            <span class="quotestart">&#8220;</span>...<?=$this->highlight($snippet['snippet']) ?>...<span class="quoteend">&#8221;</span><br/>
          <? endif; ?>
        <? endif; ?>
      <? endif; ?>

      <?
      /* Display information on duplicate records if available */
      if ($dedupData = $this->driver->getDedupData()): ?>
        <div class="dedupInformation">
        <?
          $i = 0;
          foreach ($dedupData as $source => $current) {
            if (++$i == 1) {
              ?><span class="currentSource"><a href="<?=$this->recordLink()->getUrl($this->driver)?>"><?=$this->transEsc("source_$source", array(), $source)?></a></span><?
            } else {
              if ($i == 2) {
                ?> <span class="otherSources">(<?=$this->transEsc('Other Sources')?>: <?
              } else {
                ?>, <?
              }
              ?><a href="<?=$this->recordLink()->getUrl($current['id'])?>"><?=$this->transEsc("source_$source", array(), $source)?></a><?
            }
          }
          if ($i > 1) {
            ?>)</span><?
          }?>
        </div>
      <? endif; ?>

      <? /* We need to find out if we're supposed to display an OpenURL link ($openUrlActive),
            but even if we don't plan to display the link, we still want to get the $openUrl
            value for use in generating a COinS (Z3988) tag -- see bottom of file.
          */
        $openUrl = $this->openUrl($this->driver, 'results');
        $openUrlActive = $openUrl->isActive();
        // Account for replace_other_urls setting
        $urls = $this->record($this->driver)->getLinkDetails($openUrlActive);

        if ($openUrlActive || !empty($urls)): ?>
        <? if ($openUrlActive): ?>
          <br/>
          <?=$openUrl->renderTemplate()?>
        <? endif; ?>
        <? if (!is_array($urls)) $urls = array();
          if(!$this->driver->isCollection()):
            foreach ($urls as $current): ?>
	  <? if (strncmp("https://bibb-dspace.bibb.de/jspui/handle/BIBB", $this->proxyUrl($current['url']), strlen("https://bibb-dspace.bibb.de/jspui/handle/BIBB")) == 0)    continue; ?>
	  <? if (($start = strpos($this->proxyUrl($current['url']), "(")) !== false) : ?> 
	     <a href="<?=$this->escapeHtmlAttr(trim(substr($this->proxyUrl($current['url']),0, $start-1)))?>" class="fulltext" target="new"><i class="fa fa-external-link" aria-hidden="true"></i> <?=($current['url'] == $current['desc']) ? $this->transEsc(trim(substr($this->proxyUrl($current['url']),$start+1,strlen($this->proxyUrl($current['url']))-($start+2)))) : $this->escapeHtml($current['desc'])?></a><br/>
	  <? endif; ?>   

	  <? if (($start = strpos($this->proxyUrl($current['url']), "(")) === false) : ?>
              <a href="<?=$this->escapeHtmlAttr($this->proxyUrl($current['url']))?>" class="fulltext" target="new"><i class="fa fa-external-link" aria-hidden="true"></i> <?=($current['url'] == $current['desc']) ? $this->transEsc('Get full text') : $this->escapeHtml($current['desc'])?></a><br/>
	  <? endif ; ?>
          <? endforeach; ?>
        <? endif; ?>
      <? endif; ?>

      <div class="result-previews">
        <?=$this->record($this->driver)->getPreviews()?>
      </div>
    </div>

      <div class="add-result">
          <div class="favorites">
              <? if ($this->userlist()->getMode() !== 'disabled'): ?>
                  <? /* Add to favorites */ ?>
                  <a href="<?=$this->recordLink()->getActionUrl($this->driver, 'Save')?>" data-lightbox class="save-record result-link-label" data-id="<?=$this->escapeHtmlAttr($this->driver->getUniqueId()) ?>"><?=$this->transEsc('Add to favorites')?></a>
                  <i class="result-link-icon fa fa-fw fa-star" aria-hidden="true"></i><br/>
                  <? /* Saved lists */ ?>
                  <div class="savedLists">
                      <strong><?=$this->transEsc("Saved in")?>:</strong>
                  </div>
              <? endif; ?>
          </div>

          <div class="result-links hidden-print">
              <? /* Display qrcode if appropriate: */ ?>
              <? if ($QRCode = $this->record($this->driver)->getQRCode("results")): ?>
                  <?
                  // Add JS Variables for QrCode
                  $this->jsTranslations()->addStrings(array('qrcode_hide' => 'qrcode_hide', 'qrcode_show' => 'qrcode_show'));
                  ?>
                  <span class="hidden-xs">
          <a href="<?=$this->escapeHtmlAttr($QRCode);?>" class="qrcodeLink"><?=$this->transEsc('qrcode_show')?></a><i class="fa fa-fw fa-qrcode" aria-hidden="true"></i>
          <div class="qrcode hidden">
            <script type="text/template" class="qrCodeImgTag">
              <img alt="<?=$this->transEsc('QR Code')?>" src="<?=$this->escapeHtmlAttr($QRCode);?>"/>
            </script>
          </div><br/>
        </span>
              <? endif; ?>

              <? if ($this->cart()->isActiveInSearch() && $this->params->getOptions()->supportsCart() && $this->cart()->isActive()): ?>
                  <?=$this->render('record/cart-buttons.phtml', ['id' => $this->driver->getUniqueId(), 'source' => $this->driver->getSourceIdentifier()]); ?><br/>
              <? endif; ?>



              <? /* Hierarchy tree link */ ?>
              <? $trees = $this->driver->tryMethod('getHierarchyTrees'); if (!empty($trees)): ?>
                  <? foreach ($trees as $hierarchyID => $hierarchyTitle): ?>
                      <div class="hierarchyTreeLink">
                          <input type="hidden" value="<?=$this->escapeHtmlAttr($hierarchyID)?>" class="hiddenHierarchyId" />

                          <a class="hierarchyTreeLinkText result-link-label" data-lightbox href="<?=$this->recordLink()->getTabUrl($this->driver, 'HierarchyTree')?>?hierarchy=<?=urlencode($hierarchyID)?>#tabnav" title="<?=$this->transEsc('hierarchy_tree')?>" data-lightbox-href="<?=$this->recordLink()->getTabUrl($this->driver, 'AjaxTab')?>?hierarchy=<?=urlencode($hierarchyID)?>" data-lightbox-post="tab=hierarchytree">
                              <?=$this->transEsc('hierarchy_view_context')?><? if (count($trees) > 1): ?>: <?=$this->escapeHtml($hierarchyTitle)?><? endif; ?>
                          </a>
                          <i class="result-link-icon fa fa-fw fa-sitemap" aria-hidden="true"></i>
                      </div>
                  <? endforeach; ?>
              <? endif; ?>

              <?=$this->driver->supportsCoinsOpenUrl()?'<span class="Z3988" title="'.$this->escapeHtmlAttr($this->driver->getCoinsOpenUrl()).'"></span>':''?>
          </div>
      </div>
  </div>
  <? if ($thumbnail && $thumbnailAlignment == 'right'): ?>
    <?=$thumbnail ?>
  <? endif ?>
</div>
