<%-- 
    Document   : estudiantes
    Created on : jun 6, 2017, 2:51:52 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>Estudiantes</title>
        <link rel="stylesheet" href="css.css"/>
        <script>
            function cambiar() {
                document.getElementById("asignar").submit();
            }
            function crear() {
                var form = document.getElementById("crear");
                var curso = document.createElement("input");
                curso.type = "hidden";
                curso.value = document.getElementById("curso").value;
                curso.name = "cursoCrear";
                form.appendChild(curso);
                document.getElementById("crear").submit();
            }
        </script>    
    </head>
    <body>
        <ul>
            <li><a href="NotasServlet">Notas</a></li>
            <li><a href="AnotacionesServlet">Anotaciones</a></li>
            <li><a href="AsistenciasServlet">Asistencia</a></li>
            <li style="float:right"><a href="index.jsp">Volver</a></li>
        </ul>
        <div class="bottom">
            <div class="query">
                <form action="EstudiantesServlet" method="get" id="asignar">
                    <table style="width:10em"/>
                    <tr>
                        <td>Curso</td>
                    </tr>
                    <tr>
                        <td>
                            <div class="select">
                                <select name="cursoSelected" onchange="cambiar.call(this, event)" id="curso">
                                    <c:forEach items="${listaCursos}" var="curso">
                                        <c:choose> 
                                            <c:when test = "${selected==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>
                    </tr>
                    </table>
                </form>
            </div>
            <div class="overflow">
                <table class="table">
                    <tr>
                        <th class="th">Nombre</th>
                        <th class="th">Rut</th>
                    </tr>
                    <c:forEach items="${tablaEstudiantes}" var="estudiante">
                        <tr>
                            <td class="td"><c:out value="${estudiante.nombre}"/></td>
                            <td class="td"><c:out value="${estudiante.rut}"/></td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
            <div class="query">
                <form action="CrearEstudiante" method="post" id="crear">
                    <table style="width: 15em">
                        <tr><td>Nombre</td></tr>
                        <tr>
                            <td><input type="text" name="nombre"/></td>
                        </tr>
                        <tr><td>Rut</td></tr>
                        <tr>
                            <td><input type="text" name="rut"/></td>
                            <td><input type="text" name="id" maxlength="1" style="width: 5em"/></td>
                        </tr>
                        <tr><td>Apoderado</td></tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="apoderado">
                                        <c:forEach items="${listaApoderados}" var="apoderado">
                                            <option value="${apoderado[1]}"><c:out value="${apoderado[1]}"/></option>
                                        </c:forEach>
                                    </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="EliminarEstudiante" method="post" id="eliminar">
                    <table style="width: 15em">
                        <tr><td>Rut</td></tr>
                        <tr>
                            <td><input type="text" name="rut"/></td>
                            <td><input type="text" name="id" maxlength="1" style="width: 5em"/></td>
                        </tr>
                        <tr>
                            <td><button type="submit">Eliminar</button></td>
                        </tr>
                        <tr>
                            <td><c:out value="${errorEliminar}"/></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </body>
</html>
