<%
    String action = "main.jsp";
    if ( (request.getParameter("action") != null)) {
        action = request.getParameter("action").toLowerCase()+".jsp";
    }
    if (!action.toLowerCase().equals("login.jsp") && !action.toLowerCase().equals("register.jsp")) {
        if (session.getAttribute("username") == null)
            response.sendRedirect("?action=login");
    }
    else{
        if (session.getAttribute("username") != null)
            response.sendRedirect("?action=main");
    }
    if (session.getAttribute("isAdmin") != null && (Integer)session.getAttribute("isAdmin") == 1) {
        if(action.toLowerCase().equals("main.jsp"))
            response.sendRedirect("?action=users");
    }
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Ένωση Αγροτικών Συνεταιρισμών Λέσβου</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="style.css" type="text/css" />
        <link rel="stylesheet" href="font-awesome.css" type="text/css" />
    </head>
    <body>
        <div class="container">
            <%@include file="header.jsp" %>
            <div class="content">
                <jsp:include page="<%=action%>" flush="true" />
            </div>
        </div>
    </body>
</html>
