<?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="javascript: void(0);">the-tool</a></li>
              <li class="breadcrumb-item"><a href="javascript: void(0);">Personen & Firmen</a></li>
              <li class="breadcrumb-item active"><?=($address->id) ? "bearbeiten" : "Neu" ?></li>
            </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">
            <h4 class="header-title mb-2"><?=($address->id) ? "Person/Firma bearbeiten" : "Neue Person/Firma"?></h4>
            
            <form class="form-horizontal" method="post" action="<?=self::getUrl("Address", "save")?>">
              <div class="card">
                <div class="card-body">
                  
                  <input type="hidden" name="id" value="<?=$address->id?>" />
                  
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="parent_id">Zugeordnet zu</label>
                    <div class="col-lg-10">
                      <select class="select2 form-control " name="parent_id" id="parent_id">
                        <option></option>
                        <?php foreach($parents as $parent): if($parent->id == $address->id) continue; ?>
                          <option value="<?=$parent->id?>" <?=($address->parent_id == $parent->id) ? "selected='selected'" : ""?>><?=($parent->company) ? $parent->company : $parent->getFullName()?></option>
                        <?php endforeach; ?>
                      </select>
                    </div>
                  </div>
                  
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="customer_number">Kundennummer</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" name="customer_number" id="customer_number" value="<?=$address->customer_number?>" disabled="disabled" />
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="company">Firmenname</label>
                    <div class="col-lg-10">
                      <textarea name="company" id="company" class="form-control" rows="2"><?=$address->company?></textarea>
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="firstname">Vorname</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" name="firstname" id="firstname" value="<?=$address->firstname?>">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="lastname">Nachname</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" name="lastname" id="lastname" value="<?=$address->lastname?>">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="street">Strasse</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" name="street" id="street" value="<?=$address->street?>">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="zip">PLZ / Ort</label>
                    <div class="col-lg-10">
                      <div class="row">
                        <div class="col-md-4">
                          <input type="text" class="form-control" name="zip" id="zip" placeholder="PLZ" value="<?=$address->zip?>">
                        </div>
                        <div class="col-md-8">
                          <input type="text" class="form-control" name="city" id="city" placeholder="Ort" value="<?=$address->city?>">
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="country">Land</label>
                    <div class="col-lg-10">
                      <input type="text" class="form-control" name="country" id="country" value="<?=$address->country?>">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="phone">Telefon</label>
                    <div class="col-lg-10">
                      <input type="tel" class="form-control" name="phone" id="phone" value="<?=$address->phone?>">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="mobile">Mobil</label>
                    <div class="col-lg-10">
                      <input type="tel" class="form-control" name="mobile" id="mobile" value="<?=$address->mobile?>">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="fax">Fax</label>
                    <div class="col-lg-10">
                      <input type="tel" class="form-control" name="fax" id="fax" value="<?=$address->fax?>">
                    </div>
                  </div>
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="email">Email</label>
                    <div class="col-lg-10">
                      <input type="email" class="form-control" name="email" id="email" value="<?=$address->email?>">
                    </div>
                  </div>
                  
              
                </div>
              </div>
              
              <div class="card">
                <div class="card-body">
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="spin">Service PIN</label>
                    <div class="col-lg-10">
                      <input type="spin" class="form-control" name="spin" id="spin" value="<?=$address->spin?>" disabled="disabled">
                    </div>
                  </div>
                </div>
              </div>
              
              <div class="card">
                <div class="card-body">
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="addresstypes">Rolle</label>
                    <div class="col-lg-10">
                      <select class="select2 form-control select2-multiple" name="addresstypes[]" id="addresstypes" multiple="multiple" data-placeholder="Choose ...">
                        <option value="systemowner" <?=(array_key_exists("systemowner", $address->types)) ? "selected='selected'" : ""?>><?=__("systemowner")?></option>
                        <option value="netowner" <?=(array_key_exists("netowner", $address->types)) ? "selected='selected'" : "netowner"?>><?=__("netowner")?></option>
                        <option value="salespartner" <?=(array_key_exists("salespartner", $address->types)) ? "selected='selected'" : "salespartner"?>><?=__("salespartner")?></option>
                        <option value="pipeworker" <?=(array_key_exists("pipeworker", $address->types)) ? "selected='selected'" : "pipeworker"?>><?=__("pipeworker")?></option>
                        <option value="lineworker" <?=(array_key_exists("lineworker", $address->types)) ? "selected='selected'" : "lineworker"?>><?=__("lineworker")?></option>
                        <option value="pipeplanner" <?=(array_key_exists("pipeplanner", $address->types)) ? "selected='selected'" : "pipeplanner"?>><?=__("pipeplanner")?></option>
                        <option value="lineplanner" <?=(array_key_exists("lineplanner", $address->types)) ? "selected='selected'" : "lineplanner"?>><?=__("lineplanner")?></option>
                        <option value="netoperator" <?=(array_key_exists("netoperator", $address->types)) ? "selected='selected'" : "netoperator"?>><?=__("netoperator")?></option>
                        <option value="support" <?=(array_key_exists("support", $address->types)) ? "selected='selected'" : "support"?>><?=__("support")?></option>
                        <option value="billing" <?=(array_key_exists("billing", $address->types)) ? "selected='selected'" : ""?>><?=__("billing")?></option>
                        <option value="employee" <?=(array_key_exists("employee", $address->types)) ? "selected='selected'" : ""?>><?=__("employee")?></option>
                        <option value="customer" <?=(array_key_exists("customer", $address->types)) ? "selected='selected'" : ""?>><?=__("customer")?></option>
                        <option value="supplier" <?=(array_key_exists("supplier", $address->types)) ? "selected='selected'" : ""?>><?=__("supplier")?></option>
                        <option value="contact" <?=(array_key_exists("contact", $address->types)) ? "selected='selected'" : ""?>><?=__("contact")?></option>
                        
                      </select>
                    </div>
                  </div>
                </div>
              </div>

              <h4 class="header-title mb-2">Zusatzdaten</h4>
              <div class="card">
                <div class="card-body">
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="rtrcode">RTR Betreiber ID</label>
                    <div class="col-lg-10">
                      <input class="form-control" name="attributes[rtrcode]" id="rtrcode" value="<?=$address->attributes['rtrcode']->value?>">
                    </div>
                  </div>
                </div>
              </div>
              
              <div class="card">
                <div class="card-body">
                  <div class="form-group row">
                    <label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
                    <div class="col-lg-10">
                      <textarea id="note" class="form-control" name="note" rows="5"><?=$address->note?></textarea>
                    </div>
                  </div>
                </div>
              </div>
              
              <div class="form-group row">
                <label class="col-lg-2"></label>
                <div class="col-lg-10">
                  <button type="submit" class="btn btn-primary">Speichern</button>
                </div>
              </div>
              
              
              
            </form>
          </div>
        </div>
        
      </div>
    </div>


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

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