<?php
    // Set up page title:
    $this->headTitle($this->translate('My Profile'));

    // Set up breadcrumbs:
    $this->layout()->breadcrumbs = '<li><a href="' . $this->url('myresearch-home') . '">' . $this->transEsc('Your Account') . '</a></li> <li class="active">' . $this->transEsc('Profile') . '</li>';

    // Only display home library form if we have multiple pickup locations:
    $showHomeLibForm = (isset($this->pickup) && count($this->pickup) > 1);

    // Template for use by the renderArray helper:
    $arrTemplate = '<tr><th>%%LABEL%%:</th><td> %%VALUE%%</td></tr>';
?>
<div class="<?=$this->layoutClass('mainbody')?>">
  <h2><?=$this->transEsc('Your Profile')?></h2>
  <?=$this->flashmessages();?>

  <?=$this->context($this)->renderInContext('librarycards/selectcard.phtml', ['user' => $this->auth()->isLoggedIn()]); ?>

  <table class="table table-striped">
    <?
      echo $this->renderArray(
        $arrTemplate, $this->profile,
        [
          $this->transEsc('First Name') => 'firstname',
          $this->transEsc('Last Name') => 'lastname'
        ]
      );
     ?>
    <?php if ($showHomeLibForm): ?>
      <tr><th><?=$this->transEsc('Preferred Library')?>:</th>
      <?
        $selected = (isset($this->profile['home_library']) && $this->profile['home_library'] != "")
            ? $this->profile['home_library'] : $this->defaultPickupLocation
      ?>
      <td>
        <form id="profile_form" class="form-inline" method="post">
          <select id="home_library" name="home_library" class="form-control">
            <?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>
          <input class="btn btn-default" type="submit" value="<?=$this->transEsc('Save')?>" />
        </form>
      </td>
    <?php endif; ?>
    <?

    $profile = $this->profile;  
    $profile['phone'] = $this->translate($this->profile['phone']) ; 
    $profile['zip']   = $this->translate($this->profile['zip']) ;
    $profile['group'] = $this->translate("BIBBRoles::" .$this->profile['group']) ;
/*    switch ($profile['group']) {
	case "HB"    : $profile['group'] = "BIBB-Mitarbeiter"; break;
	case "EM"    : $profile['group'] = "Ehemaliger Mitarbeiter"; break;
	case "GAST"  : $profile['group'] = "Gastwissenschaftler"; break;
	case "HOE"   : $profile['group'] = "Hoehns"; break; 
	case "L"     : $profile['group'] = "Bibliothek"; break;
	case "S"     : $profile['group'] = "Bibliotheksmitarbeiter"; break;
	default : $profile['group'] = "Daten nicht erfasst"; 
}  */

      echo $this->renderArray(
        $arrTemplate, $profile,
        [
          $this->transEsc('Address') . ' 1' => 'address1',
          $this->transEsc('Address') . ' 2' => 'address2',
	  $this->transEsc('Department')     => 'department',
          $this->transEsc('Roomnumber')     => 'roomnumber',
          $this->transEsc('Zip') => 'zip',
          $this->transEsc('City') => 'city',
          $this->transEsc('Country') => 'country',
          $this->transEsc('Phone Number') => 'phone',
          $this->transEsc('Group') => 'group',
          $this->transEsc('Expires') => 'expiration_date'
        ]
      );
    ?>
  </table>
</div>

<div class="<?=$this->layoutClass('sidebar')?>">
  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", ['active' => 'profile'])?>
</div>
