<?php
#   SGT - The SGT for Internet - http://sgt.eti.br
#   Copyright (c) 2016-2018, Jean Azevedo. All rights reserved.

#   This file is part of SGT.

#   SGT is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   any later version.

#   SGT is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

    include"../seguranca_aux_unid.php";
    include "../var_sub.php";
    $local_f = $_SESSION['usuarioTemp_2'];
    if($local_f != $temp['temp_2']){
        $local_f = $temp['temp_2'];
    }
    $sw_f = $_SESSION['usuarioTemp_3'];
    if($sw_f != $temp['temp_3']){
        $sw_f = $temp['temp_3'];
    }
    $pp_f = $_SESSION['usuarioTemp_4'];
    if($pp_f != $temp['temp_4']){
        $pp_f = $temp['temp_4'];
    }
    $valor_local = 'a';
    $valor_sw_ = 'a';
    $valor_pp_ = 'a';
    $cont = 0;
    $pt = 0;
?>
<!doctype html>
<html>
<head>
    <?php
        include '../css.html';
    ?>
    <meta charset="UTF-8">
    <title>Gestão de Canais - SGT</title>
    <script type="text/javascript">
        function proximoCampo(atual,proximo){
            if(atual.value.length >= atual.maxLength){
                document.getElementById(proximo).focus();
            }
        }
        $(function() {
            $(‘ul li a’).bind(‘click’,function(event){
                var $anchor = $(this);
                $(‘html, body’).stop().animate({
                    scrollLeft: $($anchor.attr(‘href’)).offset().left
                }, 1000);
                event.preventDefault();
            });
        })
    </script>
</head>
<body>
    <div class="main_sgt">
        <?php
            include '../menu.html';
        ?>
        <div class="container-fluid">
            <div class="tb_div_unid_comp_f">
                <form class="form-inline" action="cad_canal_.php" method="POST">
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Unidade:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="unidade">
                        <option value = \"0\">Sem Seleção</option>
                            <?php
                                if($unid_temp == 1){
                                    $sqlu = "SELECT * FROM tb_unidades ORDER BY unidade";
                                } else {
                                    $sqlu = "SELECT * FROM tb_unidades WHERE id='".$unid_master."' ORDER BY unidade";
                                }
                                $busca_uni = $pdo_sgt->prepare($sqlu);
                                $busca_uni->execute();
                                while ($linha = $busca_uni->fetch(PDO::FETCH_ASSOC)){
                                    $valor = $linha['id']; 
                                    echo "<option value = \"$valor\""; if($unid_master == $valor){echo ' selected';} echo ">$linha[unidade]</option>";
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Local:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="local">
                        <option value = \"0\">Sem Seleção</option>
                            <?php
                                $busca_local = $pdo_sgt->query("SELECT * FROM tb_local ORDER BY local");
                                while ($linha_local = $busca_local->fetch(PDO::FETCH_ASSOC)){
                                    $valor_local = $linha_local['id']; 
                                    echo "<option value = \"$valor_local\""; if($local_f == $valor_local){echo ' selected';} echo ">$linha_local[local]</option>";
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Switch:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="sw">
                        <option value = \"0\">Sem Seleção</option>
                            <?php
                                $sw_c = 1;
                                while ($sw_c < 21){
                                    echo "<option value = \"$sw_c\""; if($sw_f == $sw_c){echo ' selected';} echo ">".$sw_c." - Switch</option>";
                                    $sw_c ++;
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Porta do Switch:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="sw_pt">
                        <option value = \"0\">Sem Seleção</option>
                            <?php
                                $sw_pt_c = 1;
                                while ($sw_pt_c < 53){
                                    echo "<option value = \"$sw_pt_c\" >".$sw_pt_c." - Porta</option>";
                                    $sw_pt_c ++;
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Patch Panel:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="pp">
                        <option value = \"0\">Sem Seleção</option>
                            <?php
                                $pp_c = 1;
                                while ($pp_c < 41){
                                    echo "<option value = \"$pp_c\""; if($pp_f == $pp_c){echo ' selected';} echo ">".$pp_c." - Patch Panel</option>";
                                    $pp_c ++;
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Porta do Patch Panel:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="pp_pt">
                        <option value = \"0\">Sem Seleção</option>
                            <?php
                                $pp_pt_c = 1;
                                while ($pp_pt_c < 25){
                                    echo "<option value = \"$pp_pt_c\" >".$pp_pt_c." - Porta</option>";
                                    $pp_pt_c ++;
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Medida do Link:</label>
                        <input class="form-control form-control-sm mx-sm-1" type="text" name="link" value="0,1" required>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Descrição:</label>
                        <input class="form-control form-control-sm mx-sm-1" type="text" name="desc" required>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Cor:</label>
                        <input class="mx-sm-1" type="color" name="cor" value="#ffffff">
                    </div>
                    <button type="submit" class="btn btn-sm btn-primary mx-sm-1">Cadastrar</button>
                </form>
            </div>
            <div class="tb_div_unid_comp_f">
                <form class="form-inline" action="alt_filtro_.php" method="POST">
                    <input style="display: none" type="text" readonly name="id" value="<?php echo $id_temp; ?>" />
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Local:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="local_f">
                        <option value = "a">Sem Seleção</option>
                            <?php
                                $busca_local=$pdo_sgt->prepare("SELECT * FROM tb_local ORDER BY local");
                                $busca_local->execute();
                                while ($linha_local = $busca_local->fetch(PDO::FETCH_ASSOC)){
                                    $valor_local = $linha_local['id']; 
                                    echo "<option value = \"$valor_local\""; if($local_f == $valor_local){echo ' selected';} echo ">$linha_local[local]</option>";
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Switch:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="sw_f">
                        <option value = "a">Sem Seleção</option>
                            <?php
                                if($unid_master == 1){
                                    if($local_f != 'a'){
                                        $qry_sw=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE  local=:local ORDER BY sw");
                                        $qry_sw->bindValue(":local",$local_f);
                                        $qry_sw->execute();
                                    } else {
                                        $qry_sw=$pdo_sgt->prepare("SELECT * FROM tb_map_canal ORDER BY sw");
                                        $qry_sw->execute();
                                    }
                                } else {
                                    if($local_f != 'a'){
                                        $qry_sw=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND local=:local  ORDER BY sw");
                                        $qry_sw->bindValue(":unidade",$unid_master);
                                        $qry_sw->bindValue(":local",$local_f);
                                        $qry_sw->execute();
                                    } else {
                                        $qry_sw=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade ORDER BY sw");
                                        $qry_sw->bindValue(":unidade",$unid_master);
                                        $qry_sw->execute();
                                    }
                                }
                                while ($linha_sw=$qry_sw->fetch(PDO::FETCH_ASSOC)){
                                    $valor_sw = $linha_sw['sw']; 
                                    if($valor_sw_ === $valor_sw){
                                        $valor_sw_ = $valor_sw;
                                    } else {
                                        echo "<option value = \"$valor_sw\""; if($sw_f == $valor_sw){echo ' selected';} echo ">$valor_sw</option>";
                                        $valor_sw_ = $valor_sw;
                                    }
                                }
                            ?>
                        </select>
                    </div>
                    <div class="form-group mx-sm-1 mb-1">
                        <label>Patch Panel:</label>
                        <select class="custom-select form-control-sm mx-sm-1" name="pp_f">
                        <option value = "a">Sem Seleção</option>
                            <?php
                                if($unid_master == 1){
                                    if($local_f != 'a'){
                                        $qry_pp=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE local=:local ORDER BY pp");
                                        $qry_pp->bindValue(":local",$local_f);
                                        $qry_pp->execute();
                                    } else {
                                        $qry_pp=$pdo_sgt->prepare("SELECT * FROM tb_map_canal ORDER BY pp");
                                        $qry_pp->execute();
                                    }
                                } else {
                                    if($local_f != 'a'){
                                        $qry_pp=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND local=:local  ORDER BY pp");
                                        $qry_pp->bindValue(":unidade",$unid_master);
                                        $qry_pp->bindValue(":local",$local_f);
                                        $qry_pp->execute();
                                    } else {
                                        $qry_pp=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade ORDER BY pp");
                                        $qry_pp->bindValue(":unidade",$unid_master);
                                        $qry_pp->execute();
                                    }
                                }
                                while ($linha_pp=$qry_pp->fetch(PDO::FETCH_ASSOC)){
                                    $valor_pp = $linha_pp['pp']; 
                                    if($valor_pp_ === $valor_pp){
                                        $valor_pp_ = $valor_pp;
                                    } else {
                                        echo "<option value = \"$valor_pp\""; if($pp_f == $valor_pp){echo ' selected';} echo ">$valor_pp</option>";
                                        $valor_pp_ = $valor_pp;
                                    }
                                }
                            ?>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-sm btn-primary mx-sm-1">Aplica filtro</button>
                </form>
            </div>
            <div class="table-responsive-sm  tab_sgt content_tb_sgt">
                <table class="table-responsive-xl table-hover table-condensed table-bordered" width=2000>
                    <thead>
                        <tr align="center" bgcolor=#B8DAFF>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Unidade
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Local
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Switch
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Porta
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Patch Panel
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Porta
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Ponto
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Patch Cord Início
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Medida do Link
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Patch Cord Fim
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Total
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Descrição
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Cor
                                </div>
                            </th>
                            <th scope="col">
                                <div class="mx-sm-1">
                                    Apagar
                                </div>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                        if($unid_master == 1){
                            if ($local_f === 'a'){
                                if ($sw_f === 'a'){
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                } else {
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE sw=:sw ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE sw=:sw AND pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                }
                            } else {
                                if ($sw_f === 'a'){
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE local=:local ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE local=:local AND pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                } else {
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE local=:local AND sw=:sw ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE local=:local AND sw=:sw AND pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                }
                            }
                        } else {
                            if ($local_f === 'a'){
                                if ($sw_f === 'a'){
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                } else {
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND sw=:sw ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND sw=:sw AND pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                }
                            } else {
                                if ($sw_f === 'a'){
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND local=:local ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND local=:local AND pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                } else {
                                    if ($pp_f === 'a'){
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND local=:local AND sw=:sw ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->execute();
                                    } else {
                                        $buscar=$pdo_sgt->prepare("SELECT * FROM tb_map_canal WHERE unidade=:unidade AND local=:local AND sw=:sw AND pp=:pp ORDER BY unidade,local,pp,pp_pt");
                                        $buscar->bindValue(":unidade",$unid_master);
                                        $buscar->bindValue(":local",$local_f);
                                        $buscar->bindValue(":sw",$sw_f);
                                        $buscar->bindValue(":pp",$pp_f);
                                        $buscar->execute();
                                    }
                                }
                            }
                        }
                        $cont = $buscar->rowCount();
                        if($cont > 0){
                            while($ver = $buscar->fetch(PDO::FETCH_ASSOC)){
                                if($ver['unidade'] != 0){
                                    $buscar_unid=$pdo_sgt->prepare("SELECT * FROM tb_unidades WHERE id=:id");
                                    $buscar_unid->bindValue(":id",$ver['unidade']);
                                    $buscar_unid->execute();
                                    $dados_unid=$buscar_unid->fetch(PDO::FETCH_ASSOC);
                                    $unid_tb=$dados_unid['unidade'];
                                } else {
                                    $unid_tb = "Geral";
                                }
                                $buscar_local=$pdo_sgt->prepare("SELECT * FROM tb_local WHERE id=:id");
                                $buscar_local->bindValue(":id",$ver['local']);
                                $buscar_local->execute();
                                $dados_local=$buscar_local->fetch(PDO::FETCH_ASSOC);
                                $local_tb=$dados_local['local'];
                                if($ver['sw'] < 10){
                                    if($ver['sw_pt'] < 10){
                                        if($ver['pp'] < 10){
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/0'.$ver['sw_pt'].'-0'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/0'.$ver['sw_pt'].'-0'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        } else {
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/0'.$ver['sw_pt'].'-'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/0'.$ver['sw_pt'].'-'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        }
                                    } else {
                                        if($ver['pp'] < 10){
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/'.$ver['sw_pt'].'-0'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/'.$ver['sw_pt'].'-0'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        } else {
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/'.$ver['sw_pt'].'-'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_0'.$ver['sw'].'/'.$ver['sw_pt'].'-'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        }
                                    }
                                } else {
                                    if($ver['sw_pt'] < 10){
                                        if($ver['pp'] < 10){
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_'.$ver['sw'].'/0'.$ver['sw_pt'].'-0'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_'.$ver['sw'].'/0'.$ver['sw_pt'].'-0'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        } else {
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_'.$ver['sw'].'/0'.$ver['sw_pt'].'-'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_'.$ver['sw'].'/0'.$ver['sw_pt'].'-'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        }
                                    } else {
                                        if($ver['pp'] < 10){
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_'.$ver['sw'].'/'.$ver['sw_pt'].'-0'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_'.$ver['sw'].'/'.$ver['sw_pt'].'-0'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        } else {
                                            if($ver['pp_pt'] < 10){
                                                $pt = $ver['local'].'_'.$ver['sw'].'/'.$ver['sw_pt'].'-'.$ver['pp'].'/0'.$ver['pp_pt'];
                                            } else {
                                                $pt = $ver['local'].'_'.$ver['sw'].'/'.$ver['sw_pt'].'-'.$ver['pp'].'/'.$ver['pp_pt'];
                                            }
                                        }
                                    }
                                }
                                echo'<tr align="center" bgcolor='.$ver['cor'].' id="id'.$pt.'">'
                                    . '<td class="align-middle" scope="row" title="Unidade">'
                                        . '<div class="mx-sm-1">'
                                            .$unid_tb
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Local">'
                                        . '<div class="mx-sm-1">'
                                            .$local_tb
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Switch">'
                                        . '<div class="inp_div mx-sm-1">'
                                            . '<form action="alt_canal_sw_.php" method="POST">'
                                                . '<input style="display: none" type="text" readonly name="id" value="'.$ver['id'].'" />'
                                                . '<input style="display: none" type="text" readonly name="unidade" value="'.$ver['unidade'].'" />'
                                                . '<input style="display: none" type="text" readonly name="pt" value="'.$pt.'" />'
                                                . '<input style="display: none" type="text" readonly name="local" value="'.$ver['local'].'" />'
                                                . '<input style="display: none" type="text" readonly name="sw_pt" value="'.$ver['sw_pt'].'" />'
                                                . '<select class="custom-select form-control-sm" name="sw">';
                                                    echo "<option value = \"a\">Sem Seleção</option>";
                                                    $sw_a = 1;
                                                    while ($sw_a < 21){
                                                        echo "<option value = \"$sw_a\""; if($sw_a == $ver['sw']){echo ' selected';} echo "> Switch - ".$sw_a." </option>";
                                                        $sw_a ++;
                                                    }
                                                echo '</select>'
                                                . '<button type="submit" class="btn btn-sm btn-primary mx-sm-1" title="Salvar">Salvar</button>'
                                            . '</form>'
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Porta do Switch">'
                                        . '<div class="inp_div mx-sm-1">'
                                            . '<form action="alt_canal_sw_pt_.php" method="POST">'
                                                . '<input style="display: none" type="text" readonly name="id" value="'.$ver['id'].'" />'
                                                . '<input style="display: none" type="text" readonly name="unidade" value="'.$ver['unidade'].'" />'
                                                . '<input style="display: none" type="text" readonly name="pt" value="'.$pt.'" />'
                                                . '<input style="display: none" type="text" readonly name="local" value="'.$ver['local'].'" />'
                                                . '<input style="display: none" type="text" readonly name="sw" value="'.$ver['sw'].'" />'
                                                . '<select class="custom-select form-control-sm" name="sw_pt">';
                                                    echo "<option value = \"a\">Sem Seleção</option>";
                                                    $sw_pt_a = 1;
                                                    while ($sw_pt_a < 53){
                                                        echo "<option value = \"$sw_pt_a\""; if($sw_pt_a == $ver['sw_pt']){echo 'selected';} echo "> Porta - ".$sw_pt_a." </option>";
                                                        $sw_pt_a ++;
                                                    }
                                                echo '</select>'
                                                . '<button type="submit" class="btn btn-sm btn-primary mx-sm-1" title="Salvar">Salvar</button>'
                                            . '</form>'
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Patch Panel">'
                                        . '<div class="mx-sm-1">'
                                            .$ver['pp']
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Ponto do Patch Panel">'
                                        . '<div class="mx-sm-1">'
                                            .$ver['pp_pt']
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Ponto de Rede">'
                                        . '<div class="mx-sm-1">'
                                            .$ver['pp'].'/'.$ver['pp_pt']
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" scope="row" title="Patch Cord Início">'
                                        . '<div class="inp_div mx-sm-1">'
                                            . '<form action="alt_canal_pc_s_.php" method="POST">'
                                                . '<input style="display: none" type="text" readonly name="id" value="'.$ver['id'].'" />'
                                                . '<input style="display: none" type="text" readonly name="pt" value="'.$pt.'" />'
                                                . '<input type="text" class="form-control-plaintext" border: none; background-color:'.$ver['cor'].';" size="10" name="pc_s" value="'.number_format($ver['pc_s'], 2, ',', '.').'">'
                                                . '<input style="display: none" type="submit" name="ok" value="" />'
                                            . '</form>'
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" scope="row" title="Medida do Link">'
                                        . '<div class="inp_div mx-sm-1">'
                                            . '<form action="alt_canal_link_.php" method="POST">'
                                                . '<input style="display: none" type="text" readonly name="id" value="'.$ver['id'].'" />'
                                                . '<input style="display: none" type="text" readonly name="pt" value="'.$pt.'" />'
                                                . '<input type="text" class="form-control-plaintext" border: none; background-color:'.$ver['cor'].';" size="10" name="link" value="'.number_format($ver['link'], 2, ',', '.').'">'
                                                . '<input style="display: none" type="submit" name="ok" value="" />'
                                            . '</form>'
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" scope="row" title="Patch Cord Fim">'
                                        . '<div class="inp_div mx-sm-1">'
                                            . '<form action="alt_canal_pc_d_.php" method="POST">'
                                                . '<input style="display: none" type="text" readonly name="id" value="'.$ver['id'].'" />'
                                                . '<input style="display: none" type="text" readonly name="pt" value="'.$pt.'" />'
                                                . '<input type="text" class="form-control-plaintext" border: none; background-color:'.$ver['cor'].';" size="10" name="pc_d" value="'.number_format($ver['pc_d'], 2, ',', '.').'">'
                                                . '<input style="display: none" type="submit" name="ok" value="" />'
                                            . '</form>'
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Ponto de Rede">'
                                        . '<div class="mx-sm-1">'
                                            .number_format($ver['pc_s'] + $ver['link'] + $ver['pc_d'], 2, ',', '.')
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" scope="row" title="Descrição">'
                                        . '<div class="inp_div mx-sm-1">'
                                            . '<form action="alt_canal_desc_.php" method="POST">'
                                                . '<input style="display: none" type="text" readonly name="id" value="'.$ver['id'].'" />'
                                                . '<input style="display: none" type="text" readonly name="pt" value="'.$pt.'" />'
                                                . '<input type="text" class="form-control-plaintext" border: none; background-color:'.$ver['cor'].';" maxlength="50" size="20" name="desc" value="'.$ver['descricao'].'">'
                                                . '<input style="display: none" type="submit" name="ok" value="" />'
                                            . '</form>'
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" scope="row" title="Cor">'
                                        . '<div class="inp_div mx-sm-1">'
                                            . '<form action="alt_canal_cor_.php" method="POST">'
                                                . '<input style="display: none" type="text" readonly name="id" value="'.$ver['id'].'" />'
                                                . '<input style="display: none" type="text" readonly name="pt" value="'.$pt.'" />'
                                                . '<input border: none; background-color:'.$ver['cor'].';" type="color" name="cor" value="'.$ver['cor'].'">'
                                                . '<button type="submit" class="btn btn-sm btn-primary mx-sm-1" title="Salvar">Salvar</button>'
                                            . '</form>'
                                        . '</div>'
                                    . '</td>'
                                    . '<td class="align-middle" title="Apagar">'
                                        . '<div class="mx-sm-1">'
                                            . '<a href="del_canal.php?id='.$ver['id'].'">'
                                                . '<img title="Apagar" src="../img/lixo.png" height="15" width="15">'
                                            . '</a>'
                                        . '</div>'
                                    . '</td>'
                                . '</tr>';
                            }
                        }else{
                            echo'Sem dados cadastrais<br>';
                        }
                        echo "</tbody>"
                        . "<tfoot>Contagem de Canais ".$cont."</tfoot>";
                    ?>
                </table>
            </div>
        </div>
        <?php
            include '../roda_pe.html';
        ?>
    </div>
</body>
</html>