<!--
/* Coded by Ing. Ulises Morales Ramirez */
-->
<?php
include 'conexion.php';

$sql = "SELECT * FROM Preescolar";
$result1 = $conn->query($sql);
$sql = "SELECT * FROM Primaria";
$result2 = $conn->query($sql);
$sql = "SELECT * FROM Secundaria";
$result3 = $conn->query($sql);
$sql = "SELECT * FROM Media";
$result4 = $conn->query($sql);
$sql = "SELECT * FROM Superior";
$result5 = $conn->query($sql);

/*
if ($result->num_rows > 0) {
	// output data of each row
	while($row = $result->fetch_assoc()) {
		echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
	}
} else {
	echo "0 results";
}
$conn->close();*/
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Sin titulo</title>
    <link rel="shortcut icon" href="images/cgeo.ico">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
          integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css"
          integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="ownStyle.css" media="screen"/>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</head>

<body>
<!--div class="text-center" style="z-index: -1"><img src="images/header.png" width="800px"></div-->
<div class="ripple-background">
    <div class="circle xxlarge shade1"></div>
    <div class="circle xlarge shade2"></div>
    <div class="circle large shade3"></div>
    <div class="circle mediun shade4"></div>
    <div class="circle small shade5"></div>
</div>


<div class="container h-100">

    <div class="d-flex justify-content-center h-100">
        <div class="user_card">
            <div class="d-flex justify-content-center">
                <div class="brand_logo_container">
                    <img src="images/logo_geo.png" class="brand_logo" alt="Logo">
                </div>
                <div class="brand_logo_container1">
                    <img src="images/g980.png" class="brand_logo1" alt="Logo">
                </div>
                <div class="brand_logo_container2">
                    <img src="images/g1010.png" class="brand_logo1" alt="Logo">
                </div>
            </div>
            <div class=" justify-content-center container form_container">

                <form method="post" action="lenguaje.php">

                    <div class="input-group">
                        <div class="input-group-append">
                            <span class="input-group-text"><i class="fas fa-search"></i></span>
                        </div>
                        <input type="text" autocomplete="on" list="Escuelas" name="escuela" id="input_escuela" class="form-control " value="" placeholder="Seleccione la clave o nombre de su escuela" required ">
                        <input type="hidden"  name="clave_escuela" id="clave_escuela">
                    </div>

                    <datalist id="Escuelas">
                        <?php
                        while($row = $result1->fetch_assoc()) {
	                        echo '<option value="'.utf8_encode($row["CV_CCT"]).'">'.utf8_encode($row["NOMBRECT"]).' <br>de '.utf8_encode($row["C_NOM_LOC"]).'</option>';
	                        //echo '<option value="'.utf8_encode($row["NOMBRECT"]).'">de '.utf8_encode($row["C_NOM_LOC"]).' <br>clave: '.utf8_encode($row["CV_CCT"]).'</option>';
                        }
                        while($row = $result2->fetch_assoc()) {
	                        echo '<option value="'.utf8_encode($row["CV_CCT"]).'">'.utf8_encode($row["NOMBRECT"]).' <br>de '.utf8_encode($row["C_NOM_LOC"]).'</option>';
                        }
                        while($row = $result3->fetch_assoc()) {
	                        echo '<option value="'.utf8_encode($row["CV_CCT"]).'">'.utf8_encode($row["NOMBRECT"]).' <br>de '.utf8_encode($row["C_NOM_LOC"]).'</option>';
                        }
                        while($row = $result4->fetch_assoc()) {
	                        echo '<option value="'.utf8_encode($row["CV_CCT"]).'">'.utf8_encode($row["NOMBRECT"]).' <br>de '.utf8_encode($row["C_NOM_LOC"]).'</option>';
                        }
                        while($row = $result5->fetch_assoc()) {
	                        echo '<option value="'.utf8_encode($row["CV_CCT"]).'">'.utf8_encode($row["NOMBRECT"]).' <br>de '.utf8_encode($row["C_NOM_LOC"]).'</option>';
                        }
                        ?>
                    </datalist>


                    <div class="mt-4">
                        <div class="d-flex text-center justify-content-center links">
                            <h1 id="nombre_escuela"></h1>
                        </div>
                    </div>




                    <div class="d-flex justify-content-center mt-3 login_container">
                        <button type="submit"class="btn login_btn">Siguiente</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="text-center" ><img src="images/g122.png" width="500px" style="margin-bottom: 10px"></div>

<script>
    $("#input_escuela").bind('input', function () {
        $('#clave_escuela').val($('#input_escuela').val());
        document.getElementById('clave_escuela').value=$('#input_escuela').val();
        var valor = checkExists( $('#input_escuela').val());
        //alert(valor);
        var lastword = valor.split(" ").pop();
        document.getElementById('input_escuela').value=valor;
        $('#nombre_escuela').empty();
        $('#nombre_escuela').append(valor);
    });

    function checkExists(inputValue) {
        var x = document.getElementById("Escuelas");
        var i;
        var flag;
        for (i = 0; i < x.options.length; i++) {
            if(inputValue == x.options[i].value){
                flag = x.options[i].text;
            }

        }
        return flag;
    }

</script>
</body>
</html>