<%-- 
    Document   : asignaturas
    Created on : jun 7, 2017, 9:24:22 p.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>Asignatura</title>
        <link rel="stylesheet" href="css.css"/>
        <script>
            function cambiarCurso() {
                document.getElementById("asignar").submit();
            }
        </script>
    </head>
    <body>
        <ul>
            <li><a href="ActividadServlet">Actividades</a></li>
            <li style="float:right"><a href="CursosServlet">Volver</a></li>
        </ul>

        <div class="bottom">
            <div class="query">
                <form action="AsignaturaServlet" method="get" id="asignar">
                    <table>
                        <tr>
                            <td>Curso</td>
                        </tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="selected" onchange="cambiarCurso.call(this, event)">
                                        <c:forEach items="${cursos}" 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">Profesor</th>
                    </tr>
                    <c:forEach items="${asignaturas}" var="asignatura">
                        <tr>
                            <td class="td"><c:out value="${asignatura.nombre}"/></td>
                            <td class="td"><c:out value="${asignatura.profesor_id_fk.nombre}"/></td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
            <div class="query">
                <form action="CrearAsignatura" method="post">
                    <table style="width:20em">
                        <tr>
                            <td>Nombre</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="nombre"/></td>
                        </tr>
                        <tr>
                            <td>Curso</td>
                        </tr>
                        <tr><td> 
                                <div class="select">
                                    <select name="curso">
                                        <c:forEach items="${cursos}" 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>
                        <tr>
                            <td>Profesor</td>
                        </tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="profesor">
                                        <c:forEach items="${profesores}" var="profesor">
                                            <option value="${profesor}"><c:out value="${profesor}"/></option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td><button type="submit">Crear</button></td>
                        </tr>
                        <tr>
                            <td><c:out value="${errorCrear}"/></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="query">
                <form action="EliminarAsignatura" method="post">
                    <table style="width:20em">
                        <tr>
                            <td>Nombre</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="nombre"/></td>
                        </tr>
                        <tr>
                            <td>Curso</td>
                        </tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="curso">
                                        <c:forEach items="${cursos}" 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>
                        <tr>
                            <td><button type="submit">Eliminar</button></td>
                        </tr>
                        <tr>
                            <td><c:out value="${errorEliminar}"/></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </body>
</html>
