/*
 * 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.sql.Timestamp;
import java.text.SimpleDateFormat;
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 AcceptedMeetings 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 {
        String id=(String)request.getSession().getAttribute("id");
        String[]details=new String[5];
        try {
            String agenda=request.getParameter("agenda");
            Connection con = DataBase.getConnection();
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery("select * from scheduledmeetings where empid='"+id+"' " +
                    "and status = 1 and agenda='"+agenda+"'");
            while(rs.next()){
                int meetid=rs.getInt("meetingid");
                details[0]=meetid+"";
                String topic=rs.getString("agenda");
                details[1]=topic;
                Timestamp start=rs.getTimestamp("startDateTime");
                Timestamp end=rs.getTimestamp("endDateTime");
                SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy [HH:mm]");
                String temp = sdf.format(start);
                details[2]=temp;
                String tmp = sdf.format(end);
                details[3]=tmp;
                details[4]="Accepted";
            }
            request.getSession().setAttribute("acceptedmeetingdetails", details);
            response.sendRedirect("AcceptedMeetingDetails.jsp");
         } catch (SQLException ex) {
            Logger.getLogger(AcceptedMeetings.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>

}
