/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import com.HotelServices.model.dto.impl.Bejelentkezik;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author Sensei
 */
public class MainServlet extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            if (request.getParameter("bejelentkezik") != null && request.getParameter("bejelentkezik").equals("Bejelentkezes")) {
                if (request.getParameter("felhasznalonev") != null && request.getParameter("jelszo") != null) {
                    int i = new Bejelentkezik().felhasznalo(request.getParameter("felhasznalonev"), request.getParameter("jelszo"));
//                System.out.println(i);
//                response.sendRedirect("vendeg_index.jsp");

//                    System.out.println("---" + request.getSession().getAttribute("fnev") + "---");
                    switch (i) {
                        case 1: {
                            response.sendRedirect("vendeg_index.jsp");
                            String fNev = request.getParameter("felhasznalonev");
                            request.getSession().setAttribute("fnev", fNev);
                            break;
                        }
                        case 2: {
                            response.sendRedirect("szakacs_index.jsp");
                            String fNev = request.getParameter("felhasznalonev");
                            request.getSession().setAttribute("fnev", fNev);
                            break;
                        }
                        case 3: {
                            response.sendRedirect("szallodavezeto_index.jsp");
                            String fNev = request.getParameter("felhasznalonev");
                            request.getSession().setAttribute("fnev", fNev);
                            break;
                        }
                        case 4: {
                            response.sendRedirect("recepcios_index.jsp");
                            String fNev = request.getParameter("felhasznalonev");
                            request.getSession().setAttribute("fnev", fNev);
                            break;
                        }
                        case 5: {
                            response.sendRedirect("takarito_index.jsp");
                            String fNev = request.getParameter("felhasznalonev");
                            request.getSession().setAttribute("fnev", fNev);
                            break;
                        }
                        default: {
                            response.sendRedirect("hiba01.jsp");
                            break;
                        }
                    }
                }
            }
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
