<?php
  // Account for replace_other_urls setting
  $urls = $this->driver->getOnlineLinks($expand=true); // extend links with PIDs in case links are empty
//  print_r($urls);
  $displayDownloadButton = false;
  if (isset($urls))  {
        foreach($urls as $current)  {
                if (strcmp($current['desc'], "Inhaltsverzeichnis") == 0 || strncmp($current['desc'],"Volltext über anderen Anbieter", strlen("Volltext über anderen Anbieter")) == 0)    continue;
                $displayDownloadButton = true;
                break;
        }
  }

  $title = $this->driver->getMainTitle() ;
  $id   =  $this->driver->getUniqueID(); 
  $data = $this->driver->getRawData();
/*  $license = '';
  if (isset($data['rightsuri']))    {
        if (is_array($data['rightsuri']))  {
                $license = $data['rightsuri'][0];
            } else {
                $license = $data['rightsuri'];
        }
     } else {
	$license = [];
  }
*/ 

  $license =  isset($data['rightsuri']) ? $data['rightsuri'] : [] ;
  $parts = @explode("/", $license[0]);
  $rightsImage = $rightsLink = '';
  $aLinks = $this->driver->getAdditionalLinks(); 
  $additionalLinks= []; 
  foreach ($aLinks as $aLink)  {
	$x = explode("|",$aLink); 
	$additionalLinks[] = [ "link" => $x[0], "description" => $x[1] ] ;
  } 
  $filetypes = $this->driver->getFileType();
  $filetype  = isset($filetypes[0]) ? $filetypes[0] : 'PDF';
  if (strlen($filetype) == 0) $filetype = "PDF"; 
  if (strcmp(trim(strtoupper($filetype)), "ADOBE PDF") == 0) $filetype = "PDF";
 
  if (isset($parts) && count($parts) > 1)   {
          $rightsImage = "/vufind/themes/bibb/images/" .$parts[4].".png";
	  $rightsLink   = $license[0];
  }

  $pdfLogo = "/vufind/themes/bibb/images/pdf.png"; 
  if (strlen($rightsLink == 0))  {
	$right = isset($data['license'][0])  ? $data['license'][0] : '' ;
	if (strcmp($right,"Urheberrecht") == 0 || strcmp($right,"Deutsches Urheberrecht") == 0)  {
		$rightsLink = "http://www.gesetze-im-internet.de/urhg"; 
		$rightsImage = "/vufind/themes/bibb/images/urheberrechtDe.png";
	}
  }

?>

<?php if (!empty($urls) || $openUrlActive): ?>
  <?php foreach ($urls as $current): ?>
        <?php if (strlen($rightsImage))  : ?>
                &nbsp;&nbsp;
                        <a href="<?= $rightsLink ?>"><img src="<?= $rightsImage ?>" alt="License" style="height:35px" name="<?php echo $this->escapeHtmlAttr($this->driver->getUniqueID()); ?>"></a>
                <?php $rightsImage = ''; ?>
                <br />
        <?php endif; ?>

	<?php if ($displayDownloadButton) : ?>
	<?php // if ((strcmp($current['desc'], "Inhaltsverzeichnis") != 0) &&  strcmp(strcmp($current['desc'],"Volltext über anderen Anbieter") !=0)) : ?> 
               <form action="<?=$this->escapeHtmlAttr(trim($this->proxyUrl($current['url'])))?>">
                <button type="submit" class="btn btn-lg" style="height:30px;width:130px; background-color:#ffce53;color:#5e6c78;">
		<!-- RKE: Änderung wegen PDF auf Downloadbutton siehe https://mantis.conlicom.de/view.php?id=98 -->
                <?php if (strlen($current['desc']) <=5 ||  strcmp($current['desc'], "Volltext") == 0) : ?>
                        <i class="fa fa-download" aria-hidden="true"></i> - <?=$filetype?></button>
                <?php else : ?>
                        <i class="fa fa-download" aria-hidden="true"></i></button>
                <?php endif; ?>

	<?php if (strncmp($current['desc'], "DESC", strlen("DESC")) == 0) : ?>
		<?php $current['desc'] = "(" .substr($current['desc'], strlen("DESC:")) .")" ?>
	<?php endif ; ?>
		<span style="color: #14416b; font-size: 15px;"><?= $this->escapeHtml($current['desc'])?></span>

		</form>
   	  <?php else : ?>
		<a href="<?=$this->escapeHtmlAttr(trim($this->proxyUrl($current['url'])))?>" target="_blank"><?=$this->escapeHtml($current['desc'])?></a>
		<br />
	<?php endif; ?>

<!--		<a><button type="submit" style="background:#fff; border:none;"><span style="color: #14416b; font-size: 20px"><?=$this->escapeHtml($current['desc'])?></span>&nbsp;&nbsp;<img src='/vufind/themes/bibb_new/images/pdf.png' style="no-repeat; float right"></button> </a>
-->
    	&nbsp;&nbsp; 
        <a class="feedbackLink" style="color: #14416b; font-size: 13px;" data-lightbox onclick='Copy2Clipboard("<?=$this->escapeHtmlAttr(trim($this->proxyUrl($current['url'])))?>" )'><i class="fa fa-clipboard" aria-hidden="true">&nbsp; </i><?=$this->transEsc('Copy to Clipboard')?></a>
	<br />
	&nbsp;&nbsp;
    	<a class="feedbackLink" style="color: #14416b; font-size: 13px;" data-lightbox href="<?=$this->url('feedback-home') ."?function=feedback&comments=Titel: " .urlencode($title) ." (ID: " .$id ."): Link ist nicht korrekt!" ?>"> <i class="fa fa-chain-broken" aria-hidden="true"></i> <?=$this->transEsc('Report broken link')?></a>
    	<br />
    	<br />
  <?php endforeach; ?>

  <?php if (count($additionalLinks) > 0) : ?>
      	<span style="color: #14416b; font-size: 15px;">Weitere Links</span><br />
  	<?php foreach ($additionalLinks as $additionalLink): ?>
		&nbsp;&nbsp;
       		<a class="feedbackLink" target="new" style="color: #14416b; font-size: 13px;" href="<?=$this->escapeHtmlAttr($this->proxyUrl($additionalLink['link']))?>"><i class="fa fa-link" aria-hidden="true">&nbsp; </i><?= $additionalLink['description'] ?></a>
       		<br />
	<?php endforeach; ?>
  <?php endif ; ?>

  <?php if ($openUrlActive): ?>
    <?=$openUrl->renderTemplate()?><br/>
  <?php endif; ?>
<?php endif; ?>

<script>
function Copy2Clipboard(CopyText) {

 navigator.clipboard.writeText(CopyText);

}
</script>
