<%--
    Document   : admin
    Created on : 20.4.2010, 16:11:51
    Author     : Pavel Jandera
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

<c:if test="${RequestData.admin != true}">
    <c:redirect url="index.jsp" />
</c:if>

<sql:setDataSource
  var="dataSource"
  driver="com.mysql.jdbc.Driver"
  url="jdbc:mysql://localhost:3306/videokonference?characterEncoding=latin2"
  user="videokonf"
  password="Purk118*"
/>

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Admin</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
        <div id="header"></div>
        <div id="content" style="min-width: 1000px">
        <div id="menu">
            <a style="float: right" href="logout.jsp">Odhlásit</a>
            <a style="float: right" href="profile.jsp">Zpět na profil</a>
        </div>
        <h1>Administrace</h1>

<%--********************************* ZOBRAZENI UZIVATELU VE SKUPINACH *******************************************--%>

        <sql:query var="skupiny" dataSource="${dataSource}">
            SELECT * FROM skupiny
        </sql:query>
            
        <form style="padding: 0;float: left; width: 400px" action="" name="formSkupiny" method="GET">
            Zobrazit uživatele ve skupině
            <select name="skupiny">
                <c:forEach var="skupina" items="${skupiny.rows}">
                    <c:choose>
                        <c:when test="${skupina.nazev == param.skupiny}">
                            <option value="${skupina.nazev}" selected>${skupina.nazev}</option>
                        </c:when>
                        <c:otherwise>
                            <option value="${skupina.nazev}">${skupina.nazev}</option>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
            </select>
            <input type="submit" name="zobrazit" value="Zobrazit">
        </form>

        <form style="padding: 0; float: right;width: 600px" action="" name="formHledat" method="GET">
            Hledat podle jména
            <input type="text" name="jmeno" size="20" >, příjmení
            <input type="text" name="prijmeni" size="20">
            <input type="submit" name="hledej" value="Hledej">
        </form>

        <br /><br />
        <h3 style="clear: both">Nalezení uživatelé:</h3>
        <c:if test="${not empty param.zobrazit}">
        <sql:query var="uzivatele" dataSource="${dataSource}">
            SELECT uzivatele.jmeno, uzivatele.prijmeni, uzivatele.login FROM prirazeni, skupiny, uzivatele
            WHERE skupiny.nazev='${param.skupiny}' AND prirazeni.skupina=skupiny.id AND prirazeni.uzivatel=uzivatele.login
        </sql:query>
        <c:forEach var="row" items="${uzivatele.rows}">
            <p>
                <a href="adminEditUser.jsp?login=${row.login}">${row.jmeno} ${row.prijmeni}</a>
            </p>
        </c:forEach>
        </c:if>


        <c:if test="${not empty param.hledej}" >
            <c:if test="${not empty param.jmeno && not empty param.prijmeni}">
                <sql:query var="hledatUzivatele" dataSource="${dataSource}">
                    SELECT jmeno, prijmeni, login FROM uzivatele
                    WHERE jmeno LIKE '%${param.jmeno}%' AND prijmeni LIKE '%${param.prijmeni}%'
                </sql:query>
            </c:if>
            <c:if test="${not empty param.jmeno && empty param.prijmeni}">
                <sql:query var="hledatUzivatele" dataSource="${dataSource}">
                    SELECT jmeno, prijmeni, login FROM uzivatele
                    WHERE jmeno LIKE '%${param.jmeno}%'
                </sql:query>
            </c:if>
            <c:if test="${empty param.jmeno && not empty param.prijmeni}">
                <sql:query var="hledatUzivatele" dataSource="${dataSource}">
                    SELECT jmeno, prijmeni, login FROM uzivatele
                    WHERE prijmeni LIKE '%${param.prijmeni}%'
                </sql:query>
            </c:if>

            <c:forEach var="row" items="${hledatUzivatele.rows}">
            <p>
                <a href="adminEditUser.jsp?login=${row.login}">${row.jmeno} ${row.prijmeni}</a>
            </p>
            </c:forEach>
        </c:if>

        </div>
    </body>
</html>
