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


import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author arvind raghavan
 */
public class RejectMeeting 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 {
        try {
            String id = (String) request.getSession().getAttribute("id");
            
            String agenda=request.getParameter("agenda");
            Connection con = DataBase.getConnection();
            Statement st=con.createStatement();
            int[] meetids=new int[2000];
            int count=0;
            System.out.println("Query:");
            System.out.println("select * from scheduledmeetings " +
                    "where empid ='"+id+"'and meetingid in (select a.meetingid " +
                    "from scheduledmeetings a where a.status=5 and a.agenda='"+agenda+"') and status=0");
            
            ResultSet rs=st.executeQuery("select * from scheduledmeetings " +
                    "where empid ='"+id+"'and meetingid in (select a.meetingid " +
                    "from scheduledmeetings a where a.status=5 and a.Agenda='"+agenda+"') and status=0");
            while(rs.next()){
                meetids[count]=rs.getInt("meetingid");
                ++count;
            }
            for(int i=0;i<count;++i){
                st.executeUpdate("delete from equipreq where meetingid="+meetids[i]+" and empid='"+id+"'");
                st.executeUpdate("update scheduledmeetings set status =2 where meetingid="+meetids[i]+" and empid='"+id+"'");
            }
            System.out.println("delete success!!");
            response.sendRedirect("acceptedMeeting.jsp");
        } catch (SQLException ex) {
            Logger.getLogger(RejectMeeting.class.getName()).log(Level.SEVERE, null, ex);
        }
    } 

    // <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>

}
