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

package web;

import ejb.SeyirDefteri;
import ejb.SeyirDefteriFacade;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author zwergnase
 */
@WebServlet(name="modifyBilet", urlPatterns={"/modifyBilet"})
public class modifyBilet extends HttpServlet {

    @EJB
    private SeyirDefteriFacade seyirDefteriFacade;



   
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {


        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

      try{
        
         HttpSession session=request.getSession(true);

         String biletIndices[] = request.getParameterValues("bilets");
         if(biletIndices==null || biletIndices.length==0)
         {

            out.println("<html>");
            out.println("<head>");
            out.println("<link href=\"design/css/logout.css\" type=\"text/css\" rel=\"stylesheet\" />");
            out.println("<title>Bilet İptali</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<table id=\"success\"><tr>");
            out.println("<td rowspan=\"2\" ><img src=\"design/Pictures/info.png\" /></td>");
            out.println("<td align=\"center\" id=\"rightcell\"> Lütfen Bilet Seçiniz! </td></tr>");
            out.println("<tr><td align=\"center\" id=\"rightcell\">Seferlere geri dönmek için <a href=\"SeyirDefteri\">tıklayınız!</a> </td></tr></table>");
            out.println("<a href=\"jsps/PassengerHome.jsp\"><img id=\"home\" src=\"design/Pictures/home.png\"></a>");
            out.println("</body>");
            out.println("</html>");
            return;
         }


         int size=biletIndices.length;


         for(int i=0;i<size;i++)
         {
             SeyirDefteri todelete=seyirDefteriFacade.find(Long.parseLong(biletIndices[i]));
             seyirDefteriFacade.remove(todelete);
         }

          out.println("<html>");
            out.println("<head>");
            out.println("<link href=\"design/css/logout.css\" type=\"text/css\" rel=\"stylesheet\" />");
            out.println("<title>Bilet İptali</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<table id=\"success\"><tr>");
            out.println("<td rowspan=\"2\" ><img src=\"design/Pictures/info.png\" /></td>");
            out.println("<td align=\"center\" id=\"rightcell\"> Biletleriniz başarıyla iptal edildi! </td></tr>");
            out.println("<tr><td align=\"center\" id=\"rightcell\">Seferlere geri dönmek için <a href=\"SeyirDefteri\">tıklayınız!</a> </td></tr></table>");
            out.println("<a href=\"jsps/PassengerHome.jsp\"><img id=\"home\" src=\"design/Pictures/home.png\"></a>");
            out.println("</body>");
            out.println("</html>");
            return;



        
        } 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
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    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
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

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

}
