<?php
    // Set page title.
    $this->headTitle($this->translate('request_place_text') . ': ' . $this->driver->getBreadcrumb());

    // Set up breadcrumbs:
    $this->layout()->breadcrumbs = '<li>' . $this->searchMemory()->getLastSearchLink($this->transEsc('Search'), '', '</li> ')
        . '<li>' . $this->recordLinker($this->results)->getBreadcrumb($this->driver) . '</li> '
        . '<li class="active">' . $this->transEsc('request_place_text') . '</li>';
?>
<h2><?=$this->transEsc('request_place_text')?></h2>
<p class="helptext" style="color:red">Bestellen/Vormerken von Büchern: über den Bibliothekskatalog der Literatursuche eingehende Bestellungen und Vormerkungen werden wieder bearbeitet. Die Bereitstellung kann jedoch aufgrund der stark eingeschränkten Öffnungszeiten länger als in den Vor-Corona-Zeiten dauern. Sobald Medien für Sie zur Abholung bereitstehen, erhalten Sie wie gewohnt eine automatische Nachricht.</p>
<p style="color:red"> Sollte es Ihnen nicht möglich sein, diese Medien innerhalb von 5 Öffnungstagen im Lesesaal abzuholen, nehmen Sie bitte Kontakt mit der Bibliothek auf. </p><p>&nbsp;</p>
<?php if ($this->helpText): ?>
<p class="helptext"><?=$this->helpText?></p>
<?php endif; ?>

<form class="form-record-hold" method="post" name="placeHold">
  <?=$this->flashmessages()?>
  <label class="control-label"><?=$this->transEsc('Title')?></label>
  <p class="form-control-static"><?=$this->driver->getBreadcrumb() ?></p>
  <?php if (in_array("comments", $this->extraHoldFields)): ?>
    <div class="form-group hold-comment">
      <label class="control-label"><?=$this->transEsc("Comments")?>:</label>
      <textarea rows="3" cols="20" name="gatheredDetails[comment]" class="form-control"><?=isset($this->gatheredDetails['comment']) ? $this->escapeHtml($this->gatheredDetails['comment']) : ''?></textarea>
    </div>
  <?php endif; ?>

  <?php if (in_array("requiredByDate", $this->extraHoldFields)): ?>
    <div class="form-group hold-required-by">
      <label class="control-label"><?=$this->transEsc("hold_required_by")?>:</label>
      <input id="requiredByDate" type="text" name="gatheredDetails[requiredBy]" value="<?=(isset($this->gatheredDetails['requiredBy']) && !empty($this->gatheredDetails['requiredBy'])) ? $this->escapeHtmlAttr($this->gatheredDetails['requiredBy']) : $this->escapeHtmlAttr($this->defaultRequiredDate)?>" size="8" class="form-control"/>
      (<?=$this->dateTime()->getDisplayDateFormat()?>)
    </div>
  <?php endif; ?>

  <?php if ($this->requestGroupNeeded): ?>
    <div class="form-group hold-request-group">
      <?
        if (isset($this->gatheredDetails['requestGroupId']) && $this->gatheredDetails['requestGroupId'] !== "") {
            $selected = $this->gatheredDetails['requestGroupId'];
        } else {
            $selected = $this->defaultRequestGroup;
        }
     ?>
      <label class="control-label"><?=$this->transEsc("hold_request_group")?>:</label>
      <select id="requestGroupId" name="gatheredDetails[requestGroupId]" class="form-control">
        <?php if ($selected === false): ?>
          <option value="" selected="selected">
            <?=$this->transEsc('select_request_group')?>
          </option>
        <?php endif; ?>
        <?php foreach ($this->requestGroups as $group): ?>
          <option value="<?=$this->escapeHtmlAttr($group['id'])?>"<?=($selected == $group['id']) ? ' selected="selected"' : ''?>>
            <?=$this->transEsc('request_group_' . $group['name'], null, $group['name'])?>
          </option>
        <?php endforeach; ?>
      </select>
    </div>
  <?php endif; ?>

  <?php if (in_array("pickUpLocation", $this->extraHoldFields)): ?>
    <?
      if (isset($this->gatheredDetails['pickUpLocation']) && $this->gatheredDetails['pickUpLocation'] !== "") {
        $selected = $this->gatheredDetails['pickUpLocation'];
      } elseif (isset($this->homeLibrary) && $this->homeLibrary !== "") {
        $selected = $this->homeLibrary;
      } else {
        $selected = $this->defaultPickup;
      }
    ?>
    <?php if ($this->requestGroupNeeded): ?>
      <div class="form-group hold-pickup-location">
        <label id="pickUpLocationLabel" class="control-label"><i></i> <?=$this->transEsc("pick_up_location")?>:
          <?php if (in_array("requestGroup", $this->extraHoldFields)): ?>
            <noscript> (<?=$this->transEsc("Please enable JavaScript.")?>)</noscript>
          <?php endif; ?>
        </label>
        <select id="pickUpLocation" name="gatheredDetails[pickUpLocation]" data-default="<?=$this->escapeHtmlAttr($selected)?>" class="form-control">
          <?php if ($selected === false): ?>
          <option value="" selected="selected">
            <?=$this->transEsc('select_pickup_location')?>
          </option>
          <?php endif; ?>
        </select>
      </div>
    <?php elseif ($this->pickup): ?>
      <div class="form-group hold-pickup-location">
        <label class="control-label"><?=$this->transEsc("pick_up_location")?>:</label>
        <select id="pickUpLocation" name="gatheredDetails[pickUpLocation]" class="form-control">
          <?php if ($selected === false && count($this->pickup) > 1): ?>
            <option value="" selected="selected">
              <?=$this->transEsc('select_pickup_location')?>
            </option>
          <?php endif; ?>
          <?php foreach ($this->pickup as $lib): ?>
            <option value="<?=$this->escapeHtmlAttr($lib['locationID'])?>"<?=($selected == $lib['locationID']) ? ' selected="selected"' : ''?>>
              <?=$this->transEsc('location_' . $lib['locationDisplay'], null, $lib['locationDisplay'])?>
            </option>
          <?php endforeach; ?>
        </select>
      </div>
    <?php else: ?>
      <input type="hidden" name="gatheredDetails[pickUpLocation]" value="<?=$this->escapeHtmlAttr($this->defaultPickup)?>" />
    <?php endif; ?>
  <?php endif; ?>
  <div class="form-group">
    <input class="btn btn-primary" type="submit" name="placeHold" value="<?=$this->transEsc('request_submit_text')?>"/>
  </div>
</form>

<?
    // Set up hold script; we do this inline instead of in the header for lightbox compatibility:
    $this->inlineScript()->appendFile('hold.js');

    $js = <<<JS
        if ($.isReady) {
            setUpHoldRequestForm("{$this->escapeHtml($this->driver->getUniqueId())}");
        } else {
            $(document).ready(function(){
                setUpHoldRequestForm("{$this->escapeHtml($this->driver->getUniqueId())}");
            });
        }
JS;

    echo $this->inlineScript()->appendScript($js);
?>
