<?php include(realpath(dirname(__FILE__)."/../")."/header.php"); ?>

    <!-- start page title -->
    <div class="row">
      <div class="col-12">
        <div class="page-title-box">
          <div class="page-title-right">
            <ol class="breadcrumb m-0">
              <li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>">the-tool</a></li>
              <?php if(is_array($filter['addresstype']) && count($filter['addresstype'])): ?>
              <li class="breadcrumb-item"><a href="<?=self::getUrl("Address")?>">Personen & Firmen</a></li>
              <li class="breadcrumb-item active">
                <?php foreach($filter['addresstype'] as $type) { $types[] = __($type); } ?>
                <?=implode(", ", $types)?>
              </li>
              <?php else: ?>
              <li class="breadcrumb-item active">Personen & Firmen</li>
              <?php endif; ?>
            </ol>
          </div>
          <h4 class="page-title">Personen & Firmen</h4>
        </div>
      </div>
    </div>
    <!-- end page title -->

    <div class="row">
      <div class="col-lg-12">
        
        <div class="card">
          <div class="card-body mb-3">
            <div class="float-left">
              <h4 class="header-title">Liste aller Personen & Firmen</h4>
              <?php if(is_array($filter) && count($filter)): ?>
              <p class="sub-header">
                <?php if(array_key_exists("parents_only", $filter) && $filter['parents_only'] == 1): ?>
                Zeige nur Personen und Firmen ohne Zugehörigkeit an. <a href="<?=self::getUrl("Address", "Index", ['filter' => array_merge($filter, ["parents_only" => 0])])?>">Alle anzeigen</a><br />
                <?php else: ?>
                  Zeige alle Personen und Firmen<br />
                <?php endif; ?>
                <?php if(is_array($filter['addresstype']) && count($filter['addresstype'])): ?>
                  Gefiltert nach Rolle: <?=implode(", ", $types)?><br />
                <?php endif; ?>
              </p>
              <?php endif; ?>
            </div>
            <div class="float-right">
              <a class="btn btn-primary" href="<?=self::getUrl("Address", "add")?>"><i class="fas fa-plus"></i> Neue Person/Firma anlegen</a>
            </div>
            
            <table class="table table-striped table-hover">
              <tr>
                <th>Typ</th>
                <th>Kundennummer</th>
                <th>Firma</th>
                <th>Name</th>
                <th>Adresse</th>
                <th>Telefon</th>
                <th>Email</th>
                <th></th>
              </tr>
              <?php foreach($addresses as $address): ?>
              <tr>
                <?php if(is_array($address->types)):?>
                  <?php
                    $types = array_keys($address->types); 
                    $l7d_types = [];
                    foreach($types as $type):
                      $l7d_types[] = __($type);
                    endforeach;
                  ?>
                  <td title="<?=implode(", ", $l7d_types)?>">
                  <?=$l7d_types[0]?><?=(count($types) > 1) ? ", ..." : ""?>
                  </td>
                <?php endif; ?>
                <td>
                  <?=$address->customer_number?>
                  <?=($address->spin) ? "<br /><span class='text-pink'>".$address->spin."</span>" : ""?>
                </td>
                <td><?=nl2br($address->company)?></td>
                <td><?=$address->getFullName()?></td>
                <td>
                  <?=$address->street?><br />
                  <?=$address->zip?> <?=$address->city?>
                </td>
                <td><?=$address->phone?></td>
                <td><?=$address->email?></td>
                <td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
                  <a href="<?=self::getUrl("User", "Index", ["filter" => ["address_id" => $address->id]])?>" title="Benutzer anzeigen"><i class="fas fa-users"></i></a>
                  <a href="<?=self::getUrl("Address", "edit", ["id" => $address->id])?>"><i class="far fa-edit"  title="Bearbeiten"></i></a>
                  <a href="<?=self::getUrl("Address", "delete", ["id" => $address->id])?>" onclick="if(!confirm('Person/Firma wirklich löschen?')) return false;" class="text-danger" title="Löschen"><i class="fas fa-trash"></i></a>
                </td>
              </tr>
              <?php endforeach; ?>
            </table>
          </div>
        </div>
        
      </div>
    </div>

<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>