/**
 * SchedSelect.java
 * This is the view.  It takes the input from the Sched class and outputs
 *  it to a webpage using JSP.
 */

package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class SchedSelect extends HttpServlet {

  public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
                   throws IOException, ServletException {

    Sched group3 = new Sched();

    String m1 = request.getParameter("user1Mon");
    String t1 = request.getParameter("user1Tues");
    String w1 = request.getParameter("user1Wed");
    String h1 = request.getParameter("user1Thur");
    String f1 = request.getParameter("user1Fri");

    String m2 = request.getParameter("user2Mon");
    String t2 = request.getParameter("user2Tues");
    String w2 = request.getParameter("user2Wed");
    String h2 = request.getParameter("user2Thur");
    String f2 = request.getParameter("user2Fri");

    String m3 = request.getParameter("user3Mon");
    String t3 = request.getParameter("user3Tues");
    String w3 = request.getParameter("user3Wed");
    String h3 = request.getParameter("user3Thur");
    String f3 = request.getParameter("user3Fri");

    String m4 = request.getParameter("user4Mon");
    String t4 = request.getParameter("user4Tues");
    String w4 = request.getParameter("user4Wed");
    String h4 = request.getParameter("user4Thur");
    String f4 = request.getParameter("user4Fri");

    String res = request.getParameter("restrictions");

    group3.putSched(0, 0, m1);
    group3.putSched(0, 1, t1);
    group3.putSched(0, 2, w1);
    group3.putSched(0, 3, h1);
    group3.putSched(0, 4, f1);

    group3.putSched(1, 0, m2);
    group3.putSched(1, 1, t2);
    group3.putSched(1, 2, w2);
    group3.putSched(1, 3, h2);
    group3.putSched(1, 4, f2);

    group3.putSched(2, 0, m3);
    group3.putSched(2, 1, t3);
    group3.putSched(2, 2, w3);
    group3.putSched(2, 3, h3);
    group3.putSched(2, 4, f3);

    group3.putSched(3, 0, m4);
    group3.putSched(3, 1, t4);
    group3.putSched(3, 2, w4);
    group3.putSched(3, 3, h4);
    group3.putSched(3, 4, f4);

    group3.putRestrictions(res);

    String[] result = new String[5];
    result = group3.getFreeTimes();
  
    List<String> final_result = new ArrayList<String>();

    for (int x = 0; x < 5; x++)
       final_result.add(result[x]);

    request.setAttribute("available", final_result);
    
    RequestDispatcher view = 
         request.getRequestDispatcher("result.jsp");
    view.forward(request, response);
  }
}  
