<?php
session_start();
include '../conexao.inc.php';
$sql = "select i.*, substr(data_prova,1,10) dt_prova from inscricoes i where id=" . $_SESSION["id"];
$res = mysqli_query($conexao, $sql);
$rowInscricao = mysqli_fetch_array($res);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="../css/bootstrap-theme.min.css" rel="stylesheet" type="text/css" />


        <script src="../js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
        <script src="../js/prefixfree-1.0.7.js" type="text/javascript"></script>
        <script src="../js/vendor/jquery-1.11.1.js" type="text/javascript"></script>
        <script src="../js/bootstrap.min.js"></script>
      <!--  <script src="../js/main.js"></script> -->
        <script type="text/javascript">

            $(document).ready(function (e) {
                $("#unidade").change(function (event) {
                    var $unidade = $('#unidade').val();
//                    alert("Unidade escolhida:" + $unidade);
                    $('#serie_ano').load('../sql_listaSerieAno.php?u=' + $unidade);

                });
            });
        </script>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

        <meta charset="UTF-8"/>

        <title>Bolsão Colégio Força Máxima</title>

        <link href="../style.css" rel="stylesheet" type="text/css" />

        <script type="text/javascript">

            function exibe(mostra, oculta) {
                document.getElementById(mostra).style.display = "inline";
                document.getElementById(oculta).style.display = "none";
                if (mostra == 'sel_unidade') {
                    document.getElementById('txt_ealuno').style.display = "inline";
                    document.getElementById('txt_nealuno').style.display = "none";
                } else {
                    document.getElementById('txt_ealuno').style.display = "none";
                    document.getElementById('txt_nealuno').style.display = "inline";
                }
            }
        </script>
        <script language='JavaScript'>

            function SomenteNumero(e) {

                var tecla = (window.event) ? event.keyCode : e.which;

                if ((tecla > 47 && tecla < 58))
                    return true;

                else {

                    if (tecla != 8)
                        return false;

                    else
                        return true;

                }

            }

        </script>
        <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
      <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
      <!--<script src="../../assets/js/ie-emulation-modes-warning.js"></script>-->

        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
        <?php
        $sqlDiaSemana = "select 'Segunda' dia_semana"
                . " union all"
                . " select 'Terça' dia_semana"
                . " union all"
                . " select 'Quarta' dia_semana"
                . " union all"
                . " select 'Quinta' dia_semana"
                . " union all"
                . " select 'Sexta' dia_semana"
                . " union all"
                . " select 'Sábado' dia_semana";
        $resDiaSemana = mysqli_query($conexao, $sqlDiaSemana);
        $ds = 0;
        $diaSemana = [];
        while ($rowDiaSemana = mysqli_fetch_array($resDiaSemana)) {
            $diaSemana[$ds] = [
                "diaSemana" => $rowDiaSemana["dia_semana"]
            ];
            $ds++;
            next($rowDiaSemana);
        }
        $sqlDiaHoraProva = "select * from dia_horario_prova where data_prova > curdate()"
                . " and data_prova < '2020-12-31' order by data_prova";
        $resDiaHoraProva = mysqli_query($conexao, $sqlDiaHoraProva);
        $diaHoraProva = [];
        $dhp = 0;
        while ($rowDiaHoraProva = mysqli_fetch_array($resDiaHoraProva)) {
            $diaHoraProva[$dhp] = [
                "seqDiaHoraProva" => $rowDiaHoraProva["seq_dia_horario_prova"],
                "diaSemana" => $rowDiaHoraProva["dia_semana"],
                "dataProva" => $rowDiaHoraProva["data_prova"],
                "horarioProva" => $rowDiaHoraProva["horario_prova"]
            ];
            $dhp++;
            next($rowDiaHoraProva);
        };
        echo "
            <script language='javascript' type='text/javascript'>
            $(document).ready(function (e) {
             
            $('#diaDaSemana').change(function(e) {
            var option = '<option value=" . '""' . ">Selecione</option>';
            var diaSemanaSelecionado = $(this).val();";
        foreach ($diaHoraProva as $value) {

            echo " if(diaSemanaSelecionado == '" . $value["diaSemana"] . "'){

                    option += '<option value=" . '"' .$value["dataProva"]. " - " . $value["horarioProva"] . '"' . ">" . date('d/m/Y', strtotime($value["dataProva"])) . " - " . $value["horarioProva"] . "</option>';
            }";
        }

        echo " $('#dataHoraProva').html(option).show();
            });
            });
            </script>";
        ?>

    </head>

    <body>
        <div class="container">
            <div >
                <form action="inscricaoUpdate.php" method="post" name="form">

                    <div class="panel panel-default">
                        <div class="panel-body">
                            <h3 class="texto_centro">Atenção</h3>
                            <b class="texto_centro"><p>- Ao escolher a unidade, esteja ciente de que você está concorrendo somente a vagas do bolsão referente a Unidade escolhida.</p>
                                <p>ESTE BOLSÃO É EXCLUSIVO PARA ALUNOS EXTERNOS, NÃO TENDO VALIDADE PARA ALUNOS INTERNOS.  CASO ALGUM ALUNO INTERNO FAÇA ESTE BOLSÃO, O RESULTADO SERÁ DESCONSIDERADO.</p>
                                <div class="col-md-12"><input type="number" id="idInscricao" name="idInscricao" hidden value="<?php echo $rowInscricao['id'] ?>"/>     </div>

                                <div class="col-md-12">

                                    <label for="nome" class="control-label">Nome</label>

                                    <input  class="form-control" name="nome" type="text" id="nome" value="<?php echo $rowInscricao['nome']; ?>" maxlength="150" placeholder="Nome" required />

                                </div>


                                <div class="col-md-6">

                                    <label for="email" class="control-label">Email</label>

                                    <input  class="form-control" name="email" value="<?php echo $rowInscricao['email']; ?>" type="email" id="email"  maxlength="250" placeholder="E-mail" required/>

                                </div>
                                <div class="col-md-2">
                                    <label for="ddd" class="control-label">DDD</label>
                                    <select name="ddd" required class="form-control" id="ddd" required>
                                        <option value="">Selecione</option>
                                        <option value="21" <?php echo ($rowInscricao['ddd'] == '21' ? 'selected' : '') ?>>21</option>
                                        <option value="22" <?php echo ($rowInscricao['ddd'] == '22' ? 'selected' : '') ?>>22</option>
                                        <option value="24" <?php echo ($rowInscricao['ddd'] == '24' ? 'selected' : '') ?>>24</option>
                                    </select>
                                </div>
                                <div class="col-md-4">

                                    <label for="tel" class="control-label">Telefone</label>

                                    <input  class="form-control" name="tel" type="text" id="tel" value="<?php echo $rowInscricao['tel']; ?>"  maxlength="9" onkeypress='return SomenteNumero(event)'  required/>

                                </div>

                                <!--<div >
                                    <div class="col-md-9">

                                        <label for="endereco" class="control-label">Endereço</label>

                                        <input  class="form-control" name="endereco" value="<?php echo $rowInscricao['endereco']; ?>" type="text" id="endereco"  maxlength="250" placeholder="Endereço" required/>
                                    </div>	
                                    <div class="col-md-3">	

                                        <label for="cep" class="control-label">Cep</label>

                                        <input  class="form-control" value="<?php echo $rowInscricao['cep']; ?>" name="cep" type="text" id="cep" onkeypress='return SomenteNumero(event)'  maxlength="8" placeholder="Cep" required/>
                                    </div>

                                </div>-->


                                <div class="col-md-6">				
                                    <label for="unidade" class="control-label">Unidade Pretendida</label>


                                    <select class="form-control"  name="unidade" id="unidade"  required>
                                        <option value="">Selecione</option>
                                        <?php
                                        $query = "select * from unidade order by nome";
                                        $uni = mysqli_query($conexao, $query);
                                        while ($row = mysqli_fetch_array($uni)) {
                                            $selected = ( $row['id'] == $rowInscricao['unidade'] ) ? ' selected="selected"' : '';
                                            echo '<option value="' . $row['id'] . '"' . $selected . '>' . $row['nome'] . '</option>' . "\n";
                                        }
                                        ?>
                                    </select>




                                </div>
                                <div class="col-md-6" >

                                    <label for="serie_ano" class="control-label">Série Pretendida</label>

                                    <select  class="form-control" name="serie_ano"  type="text" id="serie_ano"   required >
                                        <option value="" >Selecione</option>
                                        <?php
                                        $query = "select * from serie_ano_mensalidade where id_unidade=" . $rowInscricao['unidade'] . "  order by serie_ano";
                                        $rowSerie = mysqli_query($conexao, $query);
                                        while ($row = mysqli_fetch_array($rowSerie)) {
                                            $selected = ( $row['id'] == $rowInscricao['id_serie_ano'] ) ? ' selected="selected"' : '';
                                            echo '<option value="' . $row['id'] . '"' . $selected . '>' . $row['descricao'] . '</option>' . "\n";
                                        }
                                        ?>

                                    </select>
                                </div>

                                <div>
                                    <div class="col-md-6">	
                                        <label class="control-label">Dia da Semana</label>
                                        <select class="form-control" type="text" name="diaDaSemana" id="diaDaSemana" required >
                                            <option value="">Selecione</option>
                                            <?php
                                            foreach ($diaSemana as $value) {
                                                echo "<option  value='" . $value["diaSemana"] . "'";
                                                if ($value["diaSemana"] == $rowInscricao["dia_semana"]) {
                                                    echo "selected";
                                                }

                                                echo ">" . $value["diaSemana"] . "</option>\n";
                                            }
                                            ?>                                                           
                                        </select>
                                    </div>
                                    <div class="col-md-6">	
                                        <label class="control-label">Data da Prova</label>
                                        <select class="form-control" type="text" name="dataHoraProva"  id="dataHoraProva" required>
                                            <option value="">Selecione</option>
                                            <?php
                                            $sqlDiaHoraProva = "select * from dia_horario_prova where data_prova > curdate()"
                                                    . " and data_prova < '2020-12-31' and dia_semana='".$rowInscricao["dia_semana"]."' order by data_prova";
                                            $resDhp = mysqli_query($conexao, $sqlDiaHoraProva);
                                            while($rowDhp= mysqli_fetch_array($resDhp)){
                                            $selected = ( $rowDhp['data_prova'] == $rowInscricao['dt_prova'] ) ? ' selected="selected"' : '';
                                            echo '<option value="'.$rowDhp["data_prova"]. " - " . $rowDhp["horario_prova"] . '"' . $selected . '>' . date('d/m/Y', strtotime($rowDhp["data_prova"])) . " - " . $rowDhp["horario_prova"]  . '</option>' . "\n";
                                                next($rowDhp);
                                            }
                                            
                                            ?>
                                        </select>
                                    </div>

                                </div>

<!--	 <strong id="vagas" style="color:red; display: none " >Vagas somente neste turno</strong></td> -->
                        </div>
                    </div>
                    <div class="texto_centro">
                        <input class="btn btn-default" type="submit" name="enviar" id="enviar" value="Gravar" />
                        <a href="branco.php"><input class="btn btn-default" type="button" name="cancelar" id="enviar" value="Cancelar" /></a>
                    </div>		
                </form>



            </div><!-- HEADER -->

        </div><!--BOX-->
    </body>
</html>