/*
 * 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.Hashtable;
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 GetMeetingResults 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 {

            Connection con = DataBase.getConnection();
            Statement st = con.createStatement();
            String id = (String) request.getSession().getAttribute("id");
            ResultSet rs = st.executeQuery("select * from scheduledmeetings where empid='" + id + "' and status <> 5 and status <> 2");
            System.out.println("select * from scheduledmeetings where empid='" + id + "' and status <> 5 and status <> 2 and status <> 4");
            Hashtable<String,String> ht=new Hashtable<String,String>();
            while(rs.next()){
                System.out.println("In while loop");
                int status=rs.getInt("status");
                String Status="";
                String url="";
                String agenda=rs.getString("agenda");
                switch(status){
                    case 0:
                        Status="Invited";
                        url="ViewInvites?agenda="+agenda;
                        break;
                    case 1:
                        Status="Accepted";
                        url="AcceptedMeetings?agenda="+agenda;
                        break;
                    case 3:
                        Status="Renegotiated";
                        url="Renegotiated?agenda="+agenda;
                        break;
                    
                }
                
                ht.put(Status,url);
                
            }
            request.getSession().setAttribute("urls", ht);
            request.getSession().setAttribute("id", id);
            response.sendRedirect("search.jsp");
        } catch (SQLException ex) {
            Logger.getLogger(GetMeetingResults.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>

}
