<?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">Patchungen</li>
            </ol>
          </div>
          <h4 class="page-title">Patchungen</h4>
        </div>
      </div>
    </div>
    <!-- end page title -->

    <div class="row">
      <div class="col-lg-12">
        
        <div class="card">
          <div class="card-body mb-3">
            <h4 class="header-title mb-3">Filter</h4>
            
            <form method="get" action="<?=self::getUrl("Patching")?>">
              <div class="row">
                <div class="col-1">
                  <label class="form-label" for="filter_network_id">Netzgebiet</label>
                  <select name="filter[network_id]" id="filter_network_id" class="form-control">
                    <option></option>
                    <?php foreach($mynetworks as $fnet): ?>
                    <option value="<?=$fnet->id?>" <?=($filter['network_id'] == $fnet->id) ? "selected='selected'" : ""?>><?=$fnet->name?></option>
                    <?php endforeach; ?>
                  </select>
                </div>
                
                <div class="col-2">
                  <label class="form-label" for="filter_pop_id">POP</label>
                  <select name="filter[pop_id]" id="filter_pop_id" class="form-control">
                    <option></option>
                    <?php foreach($mynetworks as $fnet): ?>
                      <?php if(is_array($fnet->pops) && count($fnet->pops)): ?>
                      <optgroup label="<?=$fnet->name?>">
                        <?php foreach($fnet->pops as $pop): ?>
                          <option value="<?=$pop->id?>" <?=($filter['pop_id'] == $pop->id) ? "selected='selected'" : ""?>><?=$pop->name?></option>
                        <?php endforeach; ?>
                      </optgroup>
                      <?php endif; ?>
                    <?php endforeach; ?>
                  </select>
                </div>
                
                <div class="col-2">
                  <label class="form-label" for="filter_patched">Patchstatus</label>
                  <select name="filter[patched]" id="filter_patched" class="form-control">
                    <option value="0" <?=($filter['patched'] < 1) ? "selected='selected'" : ""?>>Nicht gepatched</option>
                    <option value="1" <?=($filter['patched'] == 1) ? "selected='selected'" : ""?>>Gepatched</option>
                    <option value="2" <?=($filter['patched'] == 2) ? "selected='selected'" : ""?>>Vorpatchen</option>
                  </select>
                </div>
                
                <div class="col-2">
                  <label class="form-label" for="filter_hide_delayed_finish">Verzögerte Herstellung</label>
                  <select name="filter[hide_delayed_finish]" id="filter_hide_delayed_finish" class="form-control">
                    <option value="0" <?=(array_key_exists("hide_delayed_finish", $filter) &&$filter['hide_delayed_finish'] != 1) ? "selected='selected'" : ""?>>Anzeigen</option>
                    <option value="1" <?=(!array_key_exists("hide_delayed_finish", $filter) || $filter['hide_delayed_finish'] == 1) ? "selected='selected'" : ""?>>Nicht anzeigen</option>
                  </select>
                </div>
                
                <div class="col-1">
                  <label class="form-label" for="filter_code">Objekt ID</label>
                  <input type="text" class="form-control" name="filter[code]" id="filter_code" value="<?=$filter['code']?>" />
                </div>
                
                <div class="col-2">
                  <label class="form-label" for="filter_street">Straße</label>
                  <input type="text" class="form-control" name="filter[street]" id="filter_street" value="<?=$filter['street']?>" />
                </div>
                
                
                
                
              </div>
              <div class="row mt-2">
                <div class="col">
                  <button type="submit" class="btn btn-primary">Filter anwenden</button>
                  <a class="btn btn-secondary" href="<?=self::getUrl("Patching")?>">Filter zurücksetzen</a>
                </div>
              </div>
            </form>
            
          </div>
        </div>
        
        
        <div class="card">
          <div class="card-body mb-3">
            <div class="float-left">
              <h4 class="header-title">Patchungen</h4>
            </div>
            
            <?php if($pagination['maxItems'] > $pagination['count']): ?>
              <nav>
                <ul class="pagination justify-content-center mb-1">
                  <li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
                  </li>
                  <li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
                  </li>
                  <?php for($i = 0; $i < ($pagination['maxItems'] / $pagination['count']); $i++): ?>
                    <li class="page-item <?=($pagination['start'] == $i*$pagination['count']) ? "disabled font-weight-bold" : ""?>"><a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $i*$pagination['count'], "filter" => $filter])?>"><?=$i+1?></a></li>
                  <?php endfor; ?>
                  <li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count'])  < 1) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Vor</a>
                  </li>
                  <li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count'])  < 1) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
                  </li>
                </ul>
              </nav>
            <?php endif; ?>
            <div class="pagination justify-content-center">
              <?php if($pagination['maxItems']): ?>
                Patchungen <?=$pagination['start']+1?> bis <?=($pagination['start'] + $pagination['count'] > $pagination['maxItems']) ? $pagination['maxItems'] : $pagination['start'] + $pagination['count']?> von <?=$pagination['maxItems']?>
              <?php else: ?>
                Keine Patchungen gefunden
              <?php endif; ?>
            </div>
            
            <table class="table table-striped table-hover">
              <tr class="table-bordered text-center">
                <th colspan="4">Standort</th>
                <th colspan="2">ODF</th>
                <th colspan="5">Abschluss/Device</th>
                <th></th>
              </tr>
              <tr class="table-bordered">
                <th>Netzgebiet</th>
                <th>POP</th>
                <th>Kunde</th>
                <th>Standort</th>
                <th>Patchposition ODF</th>
                <th>ODF Port</th>
                <th>Typ</th>
                <th>Splitter / Gerät</th>
                <th>Port</th>
                <th>Gepatched</th>
                <th>Von</th>
                <th></th>
              </tr>
              <?php foreach($terminations as $term): ?>
              <tr>
                <td><?=$term->building->network->name?></td>
                <td><?=$term->building->pop->name?></td>
                <td><?=($term->order->owner) ? $term->order->owner->customer_number : ""?><br /> <?=($term->order->owner) ? $term->order->owner->getCompanyOrName() : ""?></td>
                <td>
                  <?=$term->building->street?><br />
                  <?=$term->building->zip?> <?=$term->building->city?>
                </td>
                <td class="text-mono text-primary" title="Schrank: <?=$term->workflowitems["schrank"]->value->value_string?> / Baugruppe: <?=$term->workflowitems["baugruppe"]->value->value_string?> / Modul: <?=$term->workflowitems["modul"]->value->value_string?> / Port: <?=$term->workflowitems["ports"]->value->value_string?>">
                  <?=$term->workflowitems["schrank"]->value->value_string?> /
                  <?=$term->workflowitems["baugruppe"]->value->value_string?> /
                  <?=$term->workflowitems["modul"]->value->value_string?> /
                  <?=$term->workflowitems["ports"]->value->value_string?>
                </td>
                <td>
                  <select name="linework_port" form="term-form-<?=$term->id?>" class="form-control">
                    <?php foreach($term->getLineworkportPairs() as $ports): ?>
                      <?php foreach($ports as $p): ?>
                        <option value="<?=$p?>" <?=($term->patching->linework_ports == $p) ? "selected='selected'" : ""?>><?=$p?></option>
                      <?php endforeach; ?>
                    <?php endforeach; ?>
                  </select>
                </td>
                <td>
                  <select name="device_type" form="term-form-<?=$term->id?>" class="form-control">
                    <option></option>
                    <option value="splitter" <?=($term->patching->device_type == "splitter") ? "selected='selected'" : ""?>>Splitter</option>
                    <option value="pon" <?=($term->patching->device_type == "pon") ? "selected='selected'" : ""?>>Shared PON-Port</option>
                    <option value="switch" <?=($term->patching->device_type == "switch") ? "selected='selected'" : ""?>>Switch</option>
                  </select>
                </td>
                <td><input type="text" class="form-control" form="term-form-<?=$term->id?>" name="device_name" value="<?=$term->patching->device_name?>" placeholder="Splitte / Gerät" /></td>
                <td><input type="text" class="form-control" form="term-form-<?=$term->id?>" name="device_port" value="<?=$term->patching->device_port?>" placeholder="Port" /></td>
                <td><input type="checkbox" class="form-control" form="term-form-<?=$term->id?>" name="patched" value="1"  <?=($term->patching->patched == 1) ? "checked='checked'" : ""?> /></td>
                <td <?=($term->patching->patched == 1 && $term->patching->patched_by) ? "title='Gepatched: ".date("d.m.Y H:i",$term->patching->patched_date)." von ".$term->patching->patcher->name." (".$term->patching->patcher->address->getCompanyOrName(true).")'" : ""?>>
                  
                  <?php if($term->patching->patched == 1 && $term->patching->patched_by): ?>
                    <?=($term->patching->patcher) ? $term->patching->patcher->getAbbrName() : ""?>
                  <?php endif; ?>
                </td>
                <td>
                  <form method="post" id="term-form-<?=$term->id?>" action="<?=self::getUrl("Patching","save", ["s" => $pagination['start'], "filter" => $filter])?>">
                    <input type="hidden" name="termination_id" value="<?=$term->id?>" />
                    <input type="submit" class="btn btn-primary" value="Speichern" />
                  </form>
                </td>
              </tr>
              <?php endforeach; ?>
            </table>
            
            <?php if($pagination['maxItems'] > $pagination['count']): ?>
              <nav>
                <ul class="pagination justify-content-center mb-1">
                  <li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
                  </li>
                  <li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
                  </li>
                  <?php for($i = 0; $i < ($pagination['maxItems'] / $pagination['count']); $i++): ?>
                    <li class="page-item <?=($pagination['start'] == $i*$pagination['count']) ? "disabled font-weight-bold" : ""?>"><a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $i*$pagination['count'], "filter" => $filter])?>"><?=$i+1?></a></li>
                  <?php endfor; ?>
                  <li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count'])  < 1) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Vor</a>
                  </li>
                  <li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count'])  < 1) ? "disabled" : ""?>">
                    <a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
                  </li>
                </ul>
              </nav>
            <?php endif; ?>
            <div class="pagination justify-content-center">
              <?php if($pagination['maxItems']): ?>
                Patchungen <?=$pagination['start']+1?> bis <?=($pagination['start'] + $pagination['count'] > $pagination['maxItems']) ? $pagination['maxItems'] : $pagination['start'] + $pagination['count']?> von <?=$pagination['maxItems']?>
              <?php else: ?>
                Keine Patchungen gefunden
              <?php endif; ?>
            </div>
          </div>
        </div>
        
      </div>
    </div>

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