// A. Toy, A10 for CISC474, Spring 2006
// ScheduleLookup class
// Modified: 5/15/06

package com.gmscheduler.web;

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

public class ScheduleLookup extends HttpServlet {

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

    String user = request.getParameter("user");
    String password = request.getParameter("password");
    String otherperson = request.getParameter("one");
    String result = new String();
    DatabaseManager dm = new DatabaseManager();
    
    List sched = dm.loadScheduleByPersonName(otherperson);
    ListIterator lr = sched.listIterator();
    
    Schedule s = new Schedule();
    
    while(lr.hasNext()) {
    	s = (Schedule)lr.next();
    	
    	result += "Schedule: " + s.getId() + " " + s.getDescription() + "<br />";
    	result += s.toString() + "<hr />";
    	
    }
    
    
    request.setAttribute("result",result);
    request.setAttribute("user", user);
    request.setAttribute("password", password);
    
    

    RequestDispatcher view = request.getRequestDispatcher("schedulelookup.jsp");

    view.forward(request, response);
  }
}

