<%-- 
    Document   : asistencias
    Created on : jun 11, 2017, 3:08:59 a.m.
    Author     : ryuuji
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Asistencias</title>
        <link rel="stylesheet" href="css.css"/>
        <script>
            function cambiar() {
                document.getElementById("asignar").submit();
            }
            function crear() {
                var form = document.getElementById("crear");
                var estudiante = document.createElement("input");
                var curso = document.createElement("input");
                estudiante.type = "hidden";
                estudiante.value = document.getElementById("estudiante").value;
                estudiante.name = "estudianteCrear";
                form.appendChild(estudiante);
                document.getElementById("crear").submit();
            }
            function eliminar() {
                var form = document.getElementById("eliminar");
                var estudiante = document.createElement("input");
                var curso = document.createElement("input");
                estudiante.type = "hidden";
                estudiante.value = document.getElementById("estudiante").value;
                estudiante.name = "estudianteEliminar";
                form.appendChild(estudiante);
                document.getElementById("eliminar").submit();
            }
        </script>     
    </head>
    <body>
        <ul>
            <li style="float:right"><a href="EstudiantesServlet">Volver</a></li>
        </ul>
        <div class="bottom">
            <div class="query">
                <form action="AsistenciasServlet" method="get" id="asignar">
                    <table style="width:20em">
                        <tr>
                            <td>Curso</td>
                            <td>Estudiante</td>
                        </tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="cursoSelected" onchange="cambiar.call(this, event)" id="curso">
                                        <c:forEach items="${listaCurso}" var="curso">
                                            <c:choose> 
                                                <c:when test = "${cursoSelected==curso}">
                                                    <option selected="true" value="${curso}"><c:out value="${curso}"/></option>
                                                </c:when>
                                                <c:otherwise>
                                                    <option value="${curso}"><c:out value="${curso}"/></option>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:forEach>
                                    </select>
                                </div>
                            </td> 
                            <td>
                                <div class="select">
                                    <select name="estudianteSelected" onchange="cambiar.call(this, event)" id="estudiante">
                                        <c:forEach items="${listaEstudiante}" var="estudiante">
                                            <c:choose> 
                                                <c:when test = "${estudianteSelected==estudiante[1]}">
                                                    <option selected="true" value="${estudiante[1]}"><c:out value="${estudiante[1]}"/></option>
                                                </c:when>
                                                <c:otherwise>
                                                    <option value="${estudiante[1]}"><c:out value="${estudiante[1]}"/></option>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:forEach>
                                    </select>
                                </div>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>

            <div class="overflow">
                <table class="table">
                    <tr>
                        <th class="th">Dia</th>
                        <th class="th">Asistio</th>
                    </tr>
                    <c:forEach items="${listaAsistencia}" var="asistio">
                        <tr>
                            <td class="td"><c:out value="${asistio[0]}"/></td>
                            <td class="td"><c:out value="${asistio[1]}"/></td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
            <div class="query">
                <form action="CrearAsistencia" method="post" id="crear">
                    <table>
                        <tr><td>Fecha</td></tr>
                        <tr>
                            <td> 	
                                <input type="date" name="fecha" value="${now}">
                            </td>
                        </tr>
                        <tr><td>Asistio</td></tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="asistio">
                                        <option value="si">Si</option>
                                        <option value="no">No</option>
                                    </select>
                                </div>
                            </td>
                        </tr>
                        <tr><td><button onClick="crear()">Crear</button></td></tr>
                        <tr><td><c:out value="${errorCrear}"/></td></tr>
                    </table>
                </form> 
            </div>
            <div class="query">
                <form action="EliminarAsistencia" method="post" id="eliminar">
                    <table>
                        <tr><td>Fecha</td></tr>
                        <tr>
                            <td> 	
                                <input type="date" name="fecha" value="${now}">
                            </td>
                        </tr>
                        <tr><td>Asistio</td></tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="asistio">
                                        <option value="si">Si</option>
                                        <option value="no">No</option>
                                    </select>
                                </div>
                            </td>
                        </tr>
                        <tr><td><button onClick="eliminar()">Eliminar</button></td></tr>
                        <tr><td><c:out value="${errorEliminar}"/></td></tr>
                    </table>
                </form> 
            </div>
        </div>
    </body>
</html>
