<?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">CPE Provisioning</li>
            </ol>
          </div>
          <h4 class="page-title">CPE Provisioning</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("Cpeprovisioning")?>">
              <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(NetworkModel::getAll() 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_routerconfig_finished">Provisioningstatus</label>
                  <select name="filter[routerconfig_finished]" id="filter_routerconfig_finished" class="form-control">
                    <option value="0" <?=($filter['routerconfig_finished'] == 0) ? "selected='selected'" : ""?>>Offen</option>
                    <option value="1" <?=($filter['routerconfig_finished'] == 1) ? "selected='selected'" : ""?>>Abgeschlossen</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-2">
                  <label class="form-label" for="filter_owner">Kunde</label>
                  <input type="text" class="form-control" name="filter[owner]" id="filter_owner" value="<?=$filter['owner']?>" />
                </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("Cpeprovisioning")?>">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">CPE Provisioning</h4>
            </div>
            
            <div class="pagination justify-content-center">
              <?php if(count($products)): ?>
                Zu provisionierende CPEs 1 bis <?=count($products)?>
              <?php else: ?>
                Keine zu provisionierende CPEs gefunden
              <?php endif; ?>
            </div>
            
            <table class="table">
              <?php $prov_count = 0; ?>
              <?php foreach($products as $product): ?>
              <tr class="<?=($prov_count % 2 == 0) ? "table-bg-even" : "table-bg-odd"?> bottom-no-border">
                <th>Netzgebiet</th>
                <th>Service PIN</th>
                <th>Kunde</th>
                <th>Produkt</th>
                <th>Access Type</th>
                <th>VLANs</th>
                <th></th>
              </tr>
              <tr class="<?=($prov_count % 2 == 0) ? "table-bg-even" : "table-bg-odd"?>  top-no-border bottom-no-border">
                <td class="pb-0">
                  <?=($product->termination_id) ? $product->termination->building->network->name : $product->order->owner->zip." ".$product->order->owner->city?>
                </td>
                <td class="text-pink pb-0"><?=$product->order->owner->spin?></td>
                <td class="pb-0"><?=$product->order->owner->getCompanyOrName()?></td>
                <td class="pb-0"><?=$product->product->name?><?=($product->termination_id) ? " <small class='text-pink'>".$product->termination->code."</small>" : ""?></td>
                <td class="pb-0"><?=$product->product->attributes['bras_type']->value?> - Down: <?=$product->product->attributes["bw_down"]->value?> / Up: <?=$product->product->attributes["bw_up"]->value?></td>
                <td class="text-monospace pb-0">
                  <?php if($product->termination_id): ?>
                    <?php if($product->termination->getPop()->vlan_public): ?>
                      <label class="order-date-pill active pointer mb-0">
                        Public: <strong><?=$product->termination->getPop()->vlan_public?></strong>
                        <input type="checkbox" name="vlan_public" form="cpeprovform-<?=$product->id?>" value="<?=$product->termination->getPop()->vlan_public?>" <?=($product->cpeprovisioning->vlan_public) ? "checked='checked'" : ""?> />
                      </label>
                    <?php endif; ?>
                    <?php if($product->termination->getPop()->vlan_nat): ?>
                      <label class="order-date-pill active pointer mb-0">
                        NAT: <strong><?=$product->termination->getPop()->vlan_nat?></strong>
                        <input type="checkbox" name="vlan_nat" form="cpeprovform-<?=$product->id?>" value="<?=$product->termination->getPop()->vlan_nat?>" <?=($product->cpeprovisioning->vlan_nat) ? "checked='checked'" : ""?> />
                      </label>
                    <?php endif; ?>
                    <?php if($product->termination->getPop()->vlan_ipv6): ?>
                      <label class="order-date-pill active pointer mb-0">
                        IPv6: <strong><?=$product->termination->getPop()->vlan_ipv6?></strong>
                        <input type="checkbox" name="vlan_ipv6" form="cpeprovform-<?=$product->id?>" value="<?=$product->termination->getPop()->vlan_ipv6?>" <?=($product->cpeprovisioning->vlan_ipv6) ? "checked='checked'" : ""?> />
                      </label>
                    <?php endif; ?>
                  <?php else: ?>
                    <?php if($product->product->attributes['vlan_default_public']->value): ?>
                      <label class="order-date-pill active pointer mb-0">
                        Public: <strong><?=$product->product->attributes['vlan_default_public']->value?></strong>
                        <input type="checkbox" name="vlan_public" form="cpeprovform-<?=$product->id?>" value="<?=$product->product->attributes['vlan_default_public']->value?>" <?=($product->cpeprovisioning->vlan_public) ? "checked='checked'" : ""?> />
                      </label>
                    <?php endif; ?>
                    <?php if($product->product->attributes['vlan_default_nat']->value): ?>
                      <label class="order-date-pill active pointer mb-0">
                        NAT: <strong><?=$product->product->attributes['vlan_default_nat']->value?></strong>
                        <input type="checkbox" name="vlan_nat" form="cpeprovform-<?=$product->id?>" value="<?=$product->product->attributes['vlan_default_nat']->value?>" <?=($product->cpeprovisioning->vlan_public) ? "checked='checked'" : ""?> />
                      </label>
                    <?php endif; ?>
                    <?php if($product->product->attributes['vlan_default_ipv6']->value): ?>
                      <label class="order-date-pill active pointer mb-0">
                        IPv6: <strong><?=$product->product->attributes['vlan_default_ipv6']->value?></strong>
                        <input type="checkbox" name="vlan_ipv6" form="cpeprovform-<?=$product->id?>" value="<?=$product->product->attributes['vlan_default_ipv6']->value?>" <?=($product->cpeprovisioning->vlan_public) ? "checked='checked'" : ""?> />
                      </label>
                    <?php endif; ?>
                  <?php endif; ?>
                </td>
                <td class="pb-0" style="cursor:pointer; min-width: 180px;">
                  <?php
                  
                  $vot = false;
                  $vo_termin = false;
                  $hw = false;
                  $voip = false;
                  
                  foreach($product->order->products as $prod) {
                    if(is_array($prod->product->attributes) && count($prod->product->attributes)) {
                      if(array_key_exists("hw_only", $prod->product->attributes)) {
                        if($prod->product->attributes["hw_only"]->value) {
                          $hw = true;
                        }
                      }
                      if(array_key_exists("voip_chan", $prod->product->attributes)) {
                        if($prod->product->attributes["voip_chan"]->value) {
                          $voip = true;
                        }
                      }
                      if(array_key_exists("vot", $prod->product->attributes)) {
                        if($prod->product->attributes["vot"]->value) {
                          $vot = true;
                        }
                      }
                      if($product->order->install_date) {
                        $vo_termin = $product->order->install_date;
                      }
                      if($hw && $voip_chan) {
                        break;
                      }
                    }
                  }
                  ?>
                  <?=($vot || $vo_termin) ? "<i class='fas fa-tools text-purple mr-2' title='Vorortinstallation'></i>" : ""?>
                  <?=($hw) ? "<i class='fas fa-shopping-bag text-purple mr-2' title='Zusatzprodukt vorhanden'></i>" : ""?>
                  <?=($voip) ? "<i class='fas fa-phone text-purple mr-2' title='Voice Produkt vorhanden'></i>" : ""?>
                  <?=($product->order->note) ? "<i class='fas fa-clipboard-list text-purple' title='Kommentar: ".str_replace('"', '&#34;', $product->order->note)."'></i>" : ""?>
                </td>
              </tr>
              <tr class="<?=($prov_count % 2 == 0) ? "table-bg-even" : "table-bg-odd"?> bottom-no-border top-no-border">
                <td>
                  <?php if($product->termination_id && $product->termination->getPop()): ?>
                    <strong>POP</strong>: <?=$product->termination->getPop()->name?>
                  <?php endif; ?>
                </td>
                <td><strong>Telefon:</strong> <?=$product->order->owner->phone?></td>
                
                <td><strong>Email:</strong> <?=$product->order->owner->email?></td>
                <td><a target="_blank" href="<?=self::getUrl("Order", "Index", ["id" => $product->order_id, "addJournal" => 1])?>"><i class="fas fa-scroll"></i> Bestelljournal</a></td>
                <td colspan="3"></td>
                  
              <tr class="<?=($prov_count % 2 == 0) ? "table-bg-even" : "table-bg-odd"?> bottom-no-border">
                <td colspan="6">
                  
                  <form method="post" id="cpeprovform-<?=$product->id?>" action="<?=self::getUrl("Cpeprovisioning", "Save", ["filter" => $filter])?>">
                    <input type="hidden" name="id" value="<?=$product->cpeprovisioning->id?>" />
                    <input type="hidden" name="order_id" value="<?=$product->order_id?>" />
                    <input type="hidden" name="orderproduct_id" value="<?=$product->id?>" />
                    <input type="hidden" name="termination_id" value="<?=$product->termination_id?>" />
                    
                    <div class="row">
                      <div class="col-md-2">

                        <div class="form-group">
                          <label for="routertype-<?=$product->id?>">Router</label>
                          <select class="form-control" name="routertype" id="routertype-<?=$product->id?>">
                            <option></option>
                            <option value="eigener Router" <?=($product->cpeprovisioning->routertype == "eigener Router") ? "selected='selected'" : ""?>>Eigener Router</option>
                            <option value="anderes CPE" <?=($product->cpeprovisioning->routertype == "anderes CPE") ? "selected='selected'" : ""?>>Anderes CPE</option>
                            <?php if(preg_match('/^(pppoe|dhcp)$/', $product->product->attributes['bras_type']->value)): ?>
                            <option value="TP-Link Archer C80" <?=($product->cpeprovisioning->routertype == "TP-Link Archer C80") ? "selected='selected'" : ""?>>TP-Link Archer C80 (Inet, IPTV)</option>
                            <option value="FritzBox 4040" <?=($product->cpeprovisioning->routertype == "FritzBox 4040") ? "selected='selected'" : ""?>>FritzBox 4040 (Inet, IPTV)</option>
                            <option value="FritzBox 7530" <?=($product->cpeprovisioning->routertype == "FritzBox 7530") ? "selected='selected'" : ""?>>FritzBox 7530 (Inet, Phone, IPTV)</option>
                            <option value="FritzBox 7590" <?=($product->cpeprovisioning->routertype == "FritzBox 7590") ? "selected='selected'" : ""?>>FritzBox 7590 (Inet, Phone, IPTV)</option>
                            <?php elseif($product->product->attributes['bras_type']->value = "static"): ?>
                            <option value="Mikrotik HAP AC" <?=($product->cpeprovisioning->routertype == "Mikrotik HAP AC") ? "selected='selected'" : ""?>>Mikrotik HAP AC (Inet, IPTV)</option>
                            <option value="Mikrotik HEX S" <?=($product->cpeprovisioning->routertype == "Mikrotik HEX S") ? "selected='selected'" : ""?>>Mikrotik HEX S (Inet, IPTV)</option>
                            <option value="Mikrotik RB3011" <?=($product->cpeprovisioning->routertype == "Mikrotik RB3011") ? "selected='selected'" : ""?>>Mikrotik RB3011 (Inet, IPTV)</option>
                            <?php elseif($product->product->attributes['bras_type']->value == "cmts"): ?>
                            <option value="FritzBox 6490 Cable" <?=($product->cpeprovisioning->routertype == "FritzBox 6490 Cable") ? "selected='selected'" : ""?>>FritzBox 6490 Cable (Inet, Phone, IPTV)</option>
                            <?php endif; ?>
                          </select>
                        </div>

                      </div>

                      <div class="col-md-1">
                        <div class="form-group">
                          <label class="form-label" for="wifi_ssid-<?=$product->id?>">WLAN SSID</label>
                          <input class="form-control" type="text" name="wifi_ssid" id="router_wifi_ssid-<?=$product->id?>" value="<?=$product->cpeprovisioning->wifi_ssid?>" />
                        </div>
                      </div>

                      <div class="col-md-1">
                        <div class="form-group">
                          <label class="form-label" for="wifi_pass-<?=$product->id?>">WPA Key</label>
                          <input class="form-control" type="text" name="wifi_pass" id="router_wifi_pass-<?=$product->id?>" value="<?=$product->cpeprovisioning->wifi_pass?>" />
                        </div>
                      </div>

                      <?php if($vot || $vo_termin): ?>
                      <div class="col-md-5"></div>
                      <?php else: ?>
                      <div class="col-md-1">
                        <div class="form-group text-center">
                          <label class="form-label" for="shipping-<?=$product->id?>">Versandauftrag</label>
                          <input class="form-control" type="checkbox" value="1" name="shipping" id="shipping-<?=$product->id?>" <?=($vot) ? "disabled='disabled' title='Vorortinstallation bestellt'" : ""?> <?=($product->cpeprovisioning->shipping) ? "checked='checked'" : ""?> />
                        </div>
                      </div>


                      <div class="col-md-1">
                        <div class="form-group">
                          <label class="form-label" for="ship_weight-<?=$product->id?>">Gewicht</label>
                          <input class="form-control" type="text" name="ship_weight" id="ship_weight-<?=$product->id?>" value="<?=$product->cpeprovisioning->ship_weight?>" <?=($vot) ? "disabled='disabled' title='Vorortinstallation bestellt'" : ""?> />
                        </div>
                      </div>
                      <div class="col-md-1">
                        <div class="form-group">
                          <label class="form-label" for="ship_length-<?=$product->id?>">Länge</label>
                          <input class="form-control" type="text" name="ship_length" id="ship_length-<?=$product->id?>" value="<?=$product->cpeprovisioning->ship_length?>" <?=($vot) ? "disabled='disabled' title='Vorortinstallation bestellt'" : ""?> />
                        </div>
                      </div>
                      <div class="col-md-1">
                        <div class="form-group">
                          <label class="form-label" for="ship_width-<?=$product->id?>">Breite</label>
                          <input class="form-control" type="text" name="ship_width" id="ship_width-<?=$product->id?>" value="<?=$product->cpeprovisioning->ship_width?>" <?=($vot) ? "disabled='disabled' title='Vorortinstallation bestellt'" : ""?> />
                        </div>
                      </div>
                      <div class="col-md-1">
                        <div class="form-group">
                          <label class="form-label" for="ship_height-<?=$product->id?>">Höhe</label>
                          <input class="form-control" type="text" name="ship_height" id="ship_height-<?=$product->id?>" value="<?=$product->cpeprovisioning->ship_height?>" <?=($vot) ? "disabled='disabled' title='Vorortinstallation bestellt'" : ""?> />
                        </div>
                      </div>
                      <?php endif; ?>


                      <div class="col-md-1">
                        <div class="form-group text-center">
                          <label class="form-label text-success" for="routerconfig_finished-<?=$product->id?>">Routerkonfig <i class="fas fa-check"></i></label>
                          <input class="form-control" type="checkbox" value="1" name="routerconfig_finished" id="routerconfig_finished-<?=$product->id?>" <?=($product->cpeprovisioning->routerconfig_finished) ? "checked='checked'" : ""?> />
                        </div>
                      </div>


                    </div>
                  </form>
                  
                </td>
                <td></td>
              </tr>
              <tr class="<?=($prov_count % 2 == 0) ? "table-bg-even" : "table-bg-odd"?> top-no-border">
                <td colspan="6">
                  <div class="row">
                    <div class="col-md-2">
                      <div class="form-group">
                        <label class="form-label" for="mac-<?=$product->id?>">Router MAC Adresse</label>
                        <input class="form-control" form="cpeprovform-<?=$product->id?>" type="text" name="mac" id="mac-<?=$product->id?>" value="<?=$product->cpeprovisioning->mac?>" />
                      </div>
                    </div>
                    
                    <div class="col-md-2">
                      <?php if($product->termination_id): ?>
                        <div class="form-group">
                          <label class="form-label" for="mac-<?=$product->id?>">ONT montiert / ONT SN</label>
                          <div class="input-group">
                            <div class="input-group-prepend">
                              <?php if($product->termination->getWorkflowValue("ont_deployed", "int")): ?>
                                <button type="button" class="btn btn-outline-success" disabled="disabled"><i class="fas fa-check"></i></button>
                              <?php else: ?>
                                <button type="button" class="btn btn-outline-secondary" disabled="disabled"><i class="fas fa-times"></i></button>
                              <?php endif; ?>
                            </div>
                            <input class="form-control" form="cpeprovform-<?=$product->id?>" type="text" name="ont_sn" id="ont_sn-<?=$product->id?>" value="<?=($product->termination_id) ? $product->termination->getWorkflowValue("ont_sn", "string") : ""?>" />
                          </div>
                        </div>
                      <?php endif; ?>
                    </div>

                    
                    <div class="col-md-1"></div>
                    
                    <div class="col-md-4">
                      <div class="form-group">
                        <label class="form-label" for="note-<?=$product->id?>">Kommentar</label>
                        <textarea class="form-control" form="cpeprovform-<?=$product->id?>" name="note" id="note-<?=$product->id?>"><?=htmlentities($product->cpeprovisioning->note)?></textarea>
                      </div>
                    </div>
                    <div class="col-md-1"></div>
                    <div class="col-md-2">
                      <div class="form-group">
                        <label class="form-label">&nbsp;</label>
                        <button class="form-control btn btn-primary" form="cpeprovform-<?=$product->id?>" type="submit"><i class="fas fa-save"></i> Speichern</button>
                      </div>
                    </div>
                    
                  </div>
                  
                </td>
                <td></td>
              </tr>
              <?php $prov_count++ ?>
              <?php endforeach; ?>
            </table>
            
            <div class="pagination justify-content-center">
              <?php if(count($products)): ?>
                Zu provisionierende CPEs 1 bis <?=count($products)?>
              <?php endif; ?>
            </div>
          </div>
        </div>
        
      </div>
    </div>

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