<?php
  $siteTitle = "Benutzer";
?>
<?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>
              <li class="breadcrumb-item active">Benutzer</li>
            </ol>
          </div>
          <h4 class="page-title">Benutzer</h4>
        </div>
      </div>
    </div>
    <!-- end page title -->

    <!-- Main content -->
    <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">Benutzerliste</h4>
              <p class="sub-header">
              <?php if(is_array($filter) && count($filter)): ?>
                <?php if($filter['address_id']): ?>
                  Zugehörig zu <?=(AddressModel::getOne($filter["address_id"])->getCompanyOrName())?><br />
                <?php endif; ?>
              <?php else: ?>
              Zeige alle Benutzer
              <?php endif; ?>
              </p>
            </div>
            <div class="float-right">
              <?php if(is_array($filter) && count($filter) && is_numeric($filter['address_id'])): ?>
              <a class="btn btn-primary" href="<?=self::getUrl("User", "add", ['address_id' => $filter['address_id']])?>"><i class="fas fa-plus"></i> Neuen Benutzer anlegen</a>
              <?php else: ?>
              <a class="btn btn-primary" href="<?=self::getUrl("User", "add")?>"><i class="fas fa-plus"></i> Neuen Benutzer anlegen</a>
              <?php endif; ?>
            </div>
            <table class="table table-striped table-hover">
              <tr>
                <th>Username</th>
                <th>Name</th>
                <th>Firma / Person</th>
                <th>Email</th>
                <th>Admin</th>
                <th></th>
              </tr>
              <?php foreach($users as $user): ?>
              <tr>
                <td><?=$user->username?></td>
                <td><?=$user->name?></td>
                <td><?=($user->address->company) ? $user->address->company : $user->address->getFullName()?></td>
                <td><?=$user->email?></td>
                <td><?=($user->isAdmin()) ? "Ja" : "Nein"?></td>
                <td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
                  <a href="<?=self::getUrl("User","edit", ['id' => $user->id])?>" title="User bearbeiten"><i class="far fa-edit"></i></a>
                  <?php if($user->id > 1): ?>
                  <a href="<?=self::getUrl("User","delete", ['id' => $user->id])?>" class="text-danger" title="User löschen" onclick="if(!confirm('Benutzer wirklich löschen?')) return false;"><i class="far fa-trash-alt"></i></a>
                  <?php endif; ?>
                </td>
              </tr>
              <?php endforeach; ?>
            </table>
          </div>
        </div>
      </div>
    </div>
        
    
  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->


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