<?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"><a href="<?=self::getUrl("User")?>">Benutzer</a></li>
              <li class="breadcrumb-item"><?=($action == "edit") ? "bearbeiten" : "neu"?></li>
            </ol>
          </div>
          <h4 class="page-title">Benutzer</h4>
        </div>
      </div>
    </div>
    <!-- end page title -->

    <!-- Main content -->
    <div class="row">
      <div class="col-lg">
        <div class="card">
          <div class="card-body">
            <h4 class="header-title mb-3">Benutzer bearbeiten</h4>

            <form method="post" action="<?=$this->getUrl("User","save")?>">
              <input type="hidden" name="id" value="<?=$user->id?>" />
              <div class="form-group">
                <label for="username">Username:</label>
                <input type="text" id="username" name="username" class="form-control" value="<?=$user->username?>" />
              </div>
              <div class="form-group">
                <label for="name">Name:</label>
                <input type="text" id="name" name="name" class="form-control" value="<?=$user->name?>" />
              </div>
              <div class="form-group">
                <label for="email">Email:</label>
                <input type="text" id="email" name="email" class="form-control" value="<?=$user->email?>" />
              </div>
              <div class="form-group">
                <label for="address_id">Firma/Person:</label>
                <select name="address_id" id="address_id" class="form-control">
                  <option value=""></option>
                  <?php foreach($addresses as $address): ?>
                  <option value="<?=$address->id?>" <?=($address->id == $user->address_id || $address->id == $address_id) ? "selected='selected'" : ""?>><?=($address->company) ? $address->company : $address->getFullName()?></option>
                  <?php endforeach; ?>
                </select>
              </div>
              <div class="form-group">
                <label for="admin">Admin:</label>
                <select name="admin" class="form-control" <?=($user->id == 1) ? "disabled='disabled'" : ""?>>
                  <option value="false" <?=(isset($user) && !$user->isAdmin()) ? "selected='selected'" : ""?>>No</option>
                  <option value="true" <?=(isset($user) && $user->isAdmin() || $user->id == 1) ? "selected='selected'" : ""?>>Yes</option>
                </select>
              </div>
              <div class="form-group">
                <label for="password">Password:</label>
                <input type="password" id="password" name="password" class="form-control" value="" />
              </div>
              <div class="form-group">
                <label for="password2">Repeat Password:</label>
                <input type="password" id="password2" name="password2" class="form-control" value="" />
              </div>

              <div class="form-group">
                <input type="submit" name="submit" value="Speichern" class="btn btn-primary" />
              </div>
            </form>
          </div>

        </div>
      </div>
    </div>

<script type="text/javascript">
  $("#address_id").select2({
    allowClear: true,
    placeholder: ""
  });

</script>

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