<?php
  $addThis = $this->addThis();
  if (!empty($addThis)) {
    $this->headScript()->appendFile('https://s7.addthis.com/js/250/addthis_widget.js?pub=' . urlencode($addThis));
  }
?>
<?php    $offlineMode = $this->ils()->getOfflineMode();
    try {
        $holdings = $this->driver->getRealTimeHoldings();
    } catch (\VuFind\Exception\ILS $e) {
        $holdings = ['holdings' => []];
        $offlineMode = 'ils-offline';
    }
    $availableLinks = [] ;
    $checkedOutLinks = [] ; 
    foreach ($holdings['holdings'] as $holding)  {
	    foreach ($holding['items'] as $row)   {
		if (strtolower($row['reserve']) == 'x')   continue;
		if (! isset($row['barcode']) || $row['barcode'] == "") continue; 
		if (! isset($row['link']) || $row['link'] == '') 	continue;

		$check = isset($row['check']) && $row['check'];
	    	if ((strcmp($row['status'], "Available") != 0) &&  (strcmp($row['status'], "Checked Out") != 0))    continue; 
		$link = ' class="'; 
		if ($check) $link .= 'checkRequest ';
		$link .= 'placehold" ' ; 
		if (!empty($row['linkLightbox'])) $link .= 'data-lightbox ';  
		$link .= "href=\""  .$this->recordLinker($this->results)->getRequestUrl($row['link']) ."\">"; 
		if ($check) { 
			$link .= $this->transEsc("Check Hold") ;  
		  } else {
			if (strcmp($row['status'], "Available") == 0)  {
				$link .= $this->transEsc("Place a Hold") ; 
				$availableLinks[] = $link ; 
			  } else {
				$link .= $this->transEsc("Recall This") ;
                                $checkedOutLinks[] = $link ;
			}
		}
	    }
    }
?>

<?php  // Collect data for the article requestform
  $formatArray = $this->driver->getFormats();
  (! in_array("Electronic resource", $formatArray) && (in_array("Journal article", $formatArray) || in_array("Paper in edited volumes", $formatArray))) ?  $displayRequestForm = 1 : $displayRequestForm = 0  ;
  if ($displayRequestForm == 1)  {
          if (in_array("Journal article", $formatArray)) $orderText = 'Artikel';
          if (in_array("Paper in edited volumes", $formatArray)) $orderText = 'Beitrag';
	  $articleTitle                 = $this->record($this->driver)->getTitleHtml();
	  $journalTitle         = $this->driver->getContainerTitle();
	  $journalVolume        = $this->driver->getContainerVolume();
	  $journalIssue         = $this->driver->getContainerIssue();
	  $journalStartPage     = $this->driver->getContainerStartPage();
	  $outText = '';
	  if (strlen($journalTitle))            $outText .= "erschienen in : " .$journalTitle;
	  if (strlen($journalVolume))           $outText .= " / " .$journalVolume;
	  if (strlen($journalIssue))            $outText .= ", " .$journalIssue ;
	  if (strlen($journalStartPage))        $outText .= " (" .$journalStartPage .")";
  }
?>




<div id="ergebnisfunktion" class="ergebnisfunktion hidden-print">
    <span><?=$this->transEsc("Result Selection")?></span>
</div>
<div id="suchauswahl" class="show-content suchauswahl hidden-print">
<ul class="record-nav nav nav-pills hidden-print">
  <?php if (count($this->driver->getCitationFormats()) > 0): ?>
    <li><a class="cite-record" data-lightbox href="<?=$this->recordLinker($this->results)->getActionUrl($this->driver, 'Cite')?>" rel="nofollow"><i class="fa fa-asterisk" aria-hidden="true"></i> <?=$this->transEsc('Cite this')?></a></li>
  <?php endif; ?>
  <?php if ($this->accountCapabilities()->getSmsSetting() !== 'disabled'): ?>
    <li><a class="sms-record" data-lightbox href="<?=$this->recordLinker($this->results)->getActionUrl($this->driver, 'SMS')?>" rel="nofollow"><i class="fa fa-mobile" aria-hidden="true"></i> <?=$this->transEsc('Text this')?></a></li>
  <?php endif; ?>
  <li><a class="mail-record" data-lightbox href="<?=$this->recordLinker($this->results)->getActionUrl($this->driver, 'Email')?>" rel="nofollow"><i class="fa fa-envelope" aria-hidden="true"></i> <?=$this->transEsc('Email this')?></a></li>

  <?php $exportFormats = $this->export()->getFormatsForRecord($this->driver); ?>
  <?php if(count($exportFormats) > 0): ?>
    <li class="dropdown">
      <a class="export-toggle dropdown-toggle" data-toggle="dropdown" href="<?=$this->recordLinker($this->results)->getActionUrl($this->driver, 'Export')?>" rel="nofollow"><i class="fa fa-list-alt" aria-hidden="true"></i> <?=$this->transEsc('Export Record') ?></a>
      <ul class="dropdown-menu" role="menu">
        <?php foreach ($exportFormats as $exportFormat): ?>
          <li><a <?php if ($this->export()->needsRedirect($exportFormat)): ?>target="<?=$this->escapeHtmlAttr($exportFormat)?>Main" <?php endif; ?>href="<?=$this->recordLinker($this->results)->getActionUrl($this->driver, 'Export')?>?style=<?=$this->escapeHtmlAttr($exportFormat)?>" rel="nofollow"><?=$this->transEsc('Export to')?> <?=$this->transEsc($this->export()->getLabelForFormat($exportFormat))?></a></li>
        <?php endforeach; ?>
      </ul>
    </li>
  <?php endif; ?>

  <?php if ($this->userlist()->getMode() !== 'disabled'): ?>
    <li><a class="save-record" data-lightbox href="<?=$this->recordLinker($this->results)->getActionUrl($this->driver, 'Save')?>" rel="nofollow"><i class="fa fa-star" aria-hidden="true"></i> <?=$this->transEsc('Add to favorites')?></a></li>
  <?php endif; ?>
  <?php if (!empty($addThis)): ?>
    <li><a class="addThis addthis_button" href="https://www.addthis.com/bookmark.php?v=250&amp;pub=<?=urlencode($addThis)?>"><i class="fa fa-bookmark" aria-hidden="true"></i> <?=$this->transEsc('Bookmark')?></a></li>
  <?php endif; ?>

  <?=$this->render('record/cart-buttons.phtml', ['id' => $this->driver->getUniqueId(), 'source' => $this->driver->getSourceIdentifier()]); ?>

  <?php if (!empty($availableLinks)) : ?> 
    <li><a class="save-record" <?=$availableLinks[0] ?></a></li>
  <?endif; ?>
  <?php if (empty($availableLinks) && !empty($checkedOutLinks)) : ?>
    <li><a <?=$checkedOutLinks[0] ?></a></li>
  <?endif; ?>

  <?php if ($displayRequestForm > 0) : ?>
	<?php if ($orderText == 'Artikel')  : ?>
		<li>
                <a class="feedbackLink" data-lightbox href="<?=$this->url('feedback-home') ."?function=requestArticle&comments=Artikel: " .urlencode($articleTitle) .", " .urlencode($outText) ?>"><?=$this->transEsc('Request article')?></a>
		</li>
	<?php endif; ?>
        <?php if ($orderText == 'Beitrag')  : ?>
		<li>
                <a class="feedbackLink" data-lightbox href="<?=$this->url('feedback-home') ."?function=requestPaper&comments=Beitrag: " .urlencode($articleTitle) .", " .urlencode($outText) ?>"><?=$this->transEsc('Request Paper in edited volumes')?></a>
		</li>
        <?php endif; ?>
  <?endif; ?>



</ul>
</div>
