import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.sql.*;
import java.util.*;
import java.util.StringTokenizer;


public class SupervisorRequests extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
	try{
	    String from_firstpage=null;
	    String from_complaintpage=null;
	    String from_workerpage=null;
	    String from_assignpage=null;
	    String from_chngstatuspage=null;
	    
	    from_firstpage=request.getParameter("fromfirstpage");
	    from_complaintpage=request.getParameter("fromcomplaintpage");
	    from_workerpage=request.getParameter("fromworkerpage");
	    from_assignpage=request.getParameter("fromassignpage");
	    from_chngstatuspage=request.getParameter("fromchngstatuspage");
	    
	    HttpSession session = request.getSession(true);
	    String name = (String)session.getValue(session.getId());
	    
	    
	    Enumeration all_parameters=request.getParameterNames();
	    System.out.println("all the parameters are");
	    
	     while(all_parameters.hasMoreElements()){
		System.out.println(all_parameters.nextElement());
	    }
	    
	     
	    if(name==null){
		PrintCode.alreadyLoggedout(request,response);
	    }
	    
	    if(!(from_firstpage==null)){
		String show_workers=null;
		String new_complaints=null;
		String assignbutton=null;
		String chng_statusbutton=null;
		String workers_underme=null;
		String logout=null;
		
		new_complaints=request.getParameter("newcomplaints");
		show_workers=request.getParameter("showworkers");
		logout=request.getParameter("logout");
		assignbutton=request.getParameter("assign");
		chng_statusbutton=request.getParameter("chngstatusbutton");
		workers_underme=request.getParameter("workersunderme");
		
		if(!(new_complaints==null)){
		    System.out.println("Here start of servlet supervisor");
		    System.out.println("aaaaaaaaaaaa");
		    PrintCode.showComplaints(request,response);
		}
		else if (!(show_workers==null)){
		    PrintCode.showWorkers(request,response,name);
		}
		else if (!(logout==null)){
		    session.invalidate();
		    PrintCode.pressedLogout(request,response,name); //weite code for invalidate..
		}
		else if(!(assignbutton==null)){
		    PrintCode.assignWorkers(request,response,name);
		}
		else if(!(chng_statusbutton==null)){
		    PrintCode.changeStatus(request,response,name);
		}
		
		else if(!(workers_underme==null)){
		    PrintCode.workersUnderme(request,response,name);
		}
		
	    }

	    
	    else if(!(from_complaintpage==null)){
		String remove_these=null;
		String go_back=null;
		String delete_complaints=null;
		
		delete_complaints=request.getParameter("deletecomplaints");
		go_back=request.getParameter("goback");
		
		
		if(!(go_back==null)){
		    PrintCode.firstPage(request,response);
		}		
		else if(!(delete_complaints==null)){
		    PrintCode.afterRefresh(request,response);
		}
		
	    }
	    else if(!(from_workerpage==null)){
		String go_back=null;
		go_back=request.getParameter("goback");
		
		if(!(go_back==null))
		    PrintCode.firstPage(request,response);
	    }
	    else if(!(from_assignpage==null)){
		String go_back=null;
		go_back=request.getParameter("goback");
		String assign_worker=null;
		assign_worker=request.getParameter("assignworker");
		if (!(go_back==null)) {
		    PrintCode.firstPage(request,response);
		}
		else if (!(assign_worker==null)) {
		    PrintCode.assignexec(request,response,name);
		}
	    }
	    
	    else if(!(from_chngstatuspage==null)){
		String go_back=null;
		go_back=request.getParameter("goback");
		String make_changes=null;
		make_changes=request.getParameter("makechanges");
		if(!(go_back==null)) {
		    PrintCode.firstPage(request,response);
		}
		else if (!(make_changes==null)) {
		    PrintCode.afterStatusChange(request,response,name);
		}
	    }
	}catch(IOException e){ System.out.println("IO exception caught");}
    }
}


class PrintCode{
    public static void firstPage(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
	try{
	    HttpSession session = request.getSession(true);
	    System.out.println("in show firstpage");
	    PrintWriter out;
	    String title; 
	    response.setContentType("text/html");
	    out = response.getWriter();
	
	
	    String logout = request.getParameter("logout");  //if logged out for first time.
	    if (!(logout==null)){
		title = "logout page";
		session.invalidate();
		out.println("<HTML><HEAD><TITLE>");
		out.println(title);
		out.println("</TITLE></HEAD><BODY>");
		out.println("<h3> You have logged out successfully </br><h3>");
		out.println("</BODY> </HTML>"); 
	    }
	    else{
		title = "view complaints";
		
		out.println("<HTML><HEAD><TITLE>");
		out.println(title);
		out.println("</TITLE></HEAD><BODY>");
		out.println("<table cellpadding=4 border=2>");
		
		out.println("<FORM ACTION=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\" method =\"GET\">");
		
		EasyPrint.printButton("submit","newcomplaints","Show new Complaints",out);
		EasyPrint.printButton("submit","showworkers","Show Workers",out);
		EasyPrint.printButton("submit","assign","Assign Workers",out);
		EasyPrint.printButton("submit","chngstatusbutton","Change Status",out);
		EasyPrint.printButton("submit","workersunderme","Show Workers Under Me",out);
		EasyPrint.printButton("submit","logout","logout",out);
		EasyPrint.printButton("hidden","fromfirstpage","fromfirstpage" , out);
		
		out.println("</TABLE></BODY> </HTML>"); 
		  
	    }
	    
	    out.close();
	}catch(IOException e){ System.out.println("IO exception caught");}
	catch(SQLException sqle){System.out.println("afasdfaksjdfhaskj");}
    }




    public static void showComplaints(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
	try{
	    HttpSession session = request.getSession(true);
	    String query = "select  complaint.complaint_id CID,description,status, date_lodged, location from complaint where  start_date is null and complaint.complaint_id not in (select complaint_id from resolve)";

	    System.out.println("in HSOW COMPLAINTS");
	    System.out.println(query);
	    
	    PrintWriter out;
	    String title; 
	    response.setContentType("text/html");
	    out = response.getWriter();
	
	    
	    String logout = request.getParameter("logout");  //if logged out for first time.
	    if (!(logout==null)) {
		title = "logout page";
		session.invalidate();
		out.println("<HTML><HEAD><TITLE>");
		out.println(title);
		out.println("</TITLE></HEAD><BODY>");
		out.println("<h3> You have logged out successfully </br><h3>");
		out.println("</body> </html>"); 
	    }
	    else{
		title = "view complaints";
		out.println("<HTML><HEAD><TITLE>");
		out.println(title);
		out.println("</TITLE></HEAD><BODY>");
		out.println("<table cellpadding=4 border=2>");
		out.println("<FORM ACTION=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\" method =\"GET\">");
	
		Statement stmt=MakeConnection.toDatabase();
		System.out.println("statemetn created");
		
		ResultSet rs = stmt.executeQuery(query);
		System.out.println("statemetn exexcted");
		
		ResultSetMetaData rsmd = rs.getMetaData();
	
		if( !(rs==null)){System.out.println("succseful query");}
		
		//start of print of headings of cloumns
		 EasyPrint.printHeadings(rsmd,out);
		
		  
		 /*while(rs.next()){
		    EasyPrint.printColumns(rs,rsmd,out);                    		  
		    }*/
		
		while(rs.next()){
		    EasyPrint.printColumns(rs,rsmd,out);                    		  
		    EasyPrint.printSimilar(rs,rsmd,out,stmt);
		}
		
		EasyPrint.printButton("text","removethese","fill in the complaint_id's here",out);		
		EasyPrint.printButton("submit","deletecomplaints","Delete Complaints",out);
	       
		EasyPrint.printButton("submit","goback","goback",out);
		EasyPrint.printButton("hidden","fromcomplaintpage","fromcomplaintpage",out);
		out.println("</table> </body> </html>"); 
		
	     
		out.close();
	    } 
	
    
	   		    
	}catch(SQLException sqle){System.out.println("sql exception caught here"); System.out.println(sqle);}
	catch(IOException e){ System.out.println("IO exception caught");}

    }





    public static void afterRefresh(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
	try{
	    HttpSession session = request.getSession(true);
	    //String remove_these=null;
	    /*	    String query = "select  complaint.complaint_id CID,description,status, date_lodged, location from complaint where  start_date is null";*/
	    String query = "select  complaint.complaint_id CID,description,status, date_lodged, location from complaint where  start_date is null and complaint.complaint_id not in (select complaint_id from resolve)";

	    
	    System.out.println("IND AFTER RESRESH");
	    String remove_these=request.getParameter("removethese");
	    StringTokenizer st ;
	    st= new StringTokenizer(remove_these,",");
	    String append_string="";
	    int count =st.countTokens()-1;
	    
	    while (count>0){
		append_string= append_string + " complaint_id=" + st.nextToken() + " or ";
		count-- ;
	    }
          append_string= append_string + " complaint_id=" + st.nextToken() ;
	    
	    System.out.println(append_string);
	    System.out.println("tokens are"+count);
	    String remove_query0="delete from register where " + append_string ;
	    String remove_query="delete from complaint where " + append_string ;  
	    System.out.println(remove_query);
	    PrintWriter out;
	    String title; 
	    response.setContentType("text/html");
	    out = response.getWriter();
	   
	    
	    String logout = request.getParameter("logout");  //if logged out for first time.
	    
	    
	    if (!(logout==null)) {
		title = "logout page";
		session.invalidate();
		out.println("<HTML><HEAD><TITLE>");
		out.println(title);
		out.println("</TITLE></HEAD><BODY>");
		out.println("<h3> You have logged out successfully </br><h3>");
	    }
	    else{
		title = "view complaints";
		out.println("<HTML><HEAD><TITLE>");
		out.println(title);
		out.println("</TITLE></HEAD><BODY>");
		out.println("<table cellpadding=4 border=2>");
		out.println("<FORM ACTION=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\" method =\"GET\">");
	
		Statement stmt = MakeConnection.toDatabase();
		System.out.println("sssssssssssssssssstatemetn created");
		ResultSet rs0 = stmt.executeQuery(remove_query0);
		ResultSet rs = stmt.executeQuery(remove_query);
		if(!(rs==null)){
		    
		    System.out.println("statemetn exexcted and removed");
		}
		System.out.println("aaaaaaaaaaaaaaaaaaa");
		rs = stmt.executeQuery(query);
	  
		ResultSetMetaData rsmd = rs.getMetaData();
		System.out.println("bbbbbbbbbbbbbbbbb");

		
		if( !(rs==null)){System.out.println("succseful query");}
	       System.out.println("aaaaaaaaaaaaaaaaaaaccccccccccccc");

		
		EasyPrint.printHeadings(rsmd,out);
		while(rs.next()){
		    EasyPrint.printColumns(rs,rsmd,out);                    		  
		    EasyPrint.printSimilar(rs,rsmd,out,stmt);
		}    
		    EasyPrint.printButton("text","removethese","fill in the complaint_id's here",out);
		    EasyPrint.printButton("submit","deletecomplaints","Delete Complaints",out);
		    EasyPrint.printButton("submit","goback","goback",out);
		    EasyPrint.printButton("hidden","fromcomplaintpage","fromcomplaintpage",out);
		
		out.println("</table> </body> </html>"); 
		out.close();
	    } 
	

	   		    
	}catch(SQLException sqle){System.out.println("sql exception caught here"); System.out.println(sqle);}
	catch(IOException e){ System.out.println("IO exception caught");}

    }



    public static void alreadyLoggedout(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
	try{
	    PrintWriter  out;
	    String TITLE= "ANLALYST";
	    response.setContentType("text/html"); 
	    out = response.getWriter();
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(TITLE);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<B>Sorry </BLINK><B>");
	    out.println("<h3>you have already logged out</br><h3>");
	    out.println("</TABLE></FORM></BODY></HTML>");
	    out.close();
	    
	}catch (Exception sqle){System.out.println( "exception in get111111111 " );
	System.out.println(sqle);
	}
    }




    public static void pressedLogout(HttpServletRequest request, HttpServletResponse response ,String name) throws ServletException,IOException{
	try{
	    PrintWriter  out;
	    String TITLE= "LOGOUT";
	    response.setContentType("text/html"); 
	    out = response.getWriter();
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(TITLE);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<B>Dear"+"    "+ name+ "   " + "<B>");
	    out.println("<h3>you have  logged out Succesfully</br><h3>");
	    out.println("</TABLE></FORM></BODY></HTML>");
	    out.close();
	    
	}catch (Exception sqle){System.out.println( "exception in get111111111 " );
	System.out.println(sqle);
	}
    }

  
    public static void showWorkers(HttpServletRequest request, HttpServletResponse response,String supervisor_id) throws ServletException,IOException{
	try{
	    
	    String query="select worker.worker_id , worker.name name , worker_type.type_id, complaint.complaint_id,complaint.description from worker,complaint,resolve ,works_for ,worker_type  where  works_for.supervisor_id='"+supervisor_id +"'"+ "and works_for.worker_id=worker.worker_id and works_for.worker_id=worker_type.worker_id and worker.worker_id=resolve.worker_id and resolve.complaint_id=complaint.complaint_id"; 
		    
	    System.out.println("in SHOW workers");
	    System.out.println(query);
	    PrintWriter out;
	    String title; 
	    response.setContentType("text/html");
	    out = response.getWriter();
	
	    title = "View Workers";
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(title);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<table cellpadding=4 border=2>");
	    out.println("<FORM ACTION=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\" method =\"GET\">");
	    
	    Statement stmt=MakeConnection.toDatabase();
	    System.out.println("statemetn created");
	    ResultSet rs = stmt.executeQuery(query);
	    System.out.println("statemetn exexcted");
	    ResultSetMetaData rsmd = rs.getMetaData();
	    if(!(rs==null)){System.out.println("succseful query");}
	    
	    //prints column headings
	    EasyPrint.printHeadings(rsmd,out);
	    
	    while(rs.next()){
		System.out.println("adfadfasdfas");
		EasyPrint.printColumns(rs,rsmd,out);                    		  
	    }
	    
	    EasyPrint.printButton("submit","goback","goback",out);
	    EasyPrint.printButton("hidden","fromworkerpage","fromworkerpage",out);
	    out.println("</table> </body> </html>");
	    out.close();
	    
	}catch(SQLException sqle){System.out.println("sql exception caught here"); System.out.println(sqle);}
	catch(IOException e){ System.out.println("IO exception caught");}
	
    }
 
 
    public static void workersUnderme(HttpServletRequest request, HttpServletResponse response,String name) throws ServletException,IOException{
	try{
	    String query="select worker.worker_id, worker.name , worker_type.type_id from worker,works_for,worker_type where  worker.worker_id=works_for.worker_id and worker.worker_id=worker_type.worker_id and works_for.supervisor_id='" + name + "'";

	 /*String query="select worker.worker_id , worker.name name , worker_type.type_id, complaint.complaint_id,complaint.description from worker,complaint,resolve ,works_for ,worker_type  where  works_for.supervisor_id='"+supervisor_id +"'"+ "and works_for.worker_id=worker.worker_id and works_for.worker_id=worker_type.worker_id and worker.worker_id=resolve.worker_id and resolve.complaint_id=complaint.complaint_id";*/
 
		    
	    System.out.println("in SHOW workers");
	    System.out.println(query);
	    PrintWriter out;
	    String title; 
	    response.setContentType("text/html");
	    out = response.getWriter();
	
	    title = "View Workers";
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(title);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<table cellpadding=4 border=2>");
	    out.println("<FORM ACTION=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\" method =\"GET\">");
	    
	    Statement stmt=MakeConnection.toDatabase();
	    System.out.println("statemetn created");
	    ResultSet rs = stmt.executeQuery(query);
	    System.out.println("statemetn exexcted");
	    ResultSetMetaData rsmd = rs.getMetaData();
	    if(!(rs==null)){System.out.println("succseful query");}
	    
	    //prints column headings
	    EasyPrint.printHeadings(rsmd,out);
	    
	    while(rs.next()){
		System.out.println("adfadfasdfas");
		EasyPrint.printColumns(rs,rsmd,out);                    		  
	    }
	    
	    EasyPrint.printButton("submit","goback","goback",out);
	    EasyPrint.printButton("hidden","fromworkerpage","fromworkerpage",out);
	    out.println("</table> </body> </html>");
	    out.close();
	    
	}catch(SQLException sqle){System.out.println("sql exception caught here"); System.out.println(sqle);}
	catch(IOException e){ System.out.println("IO exception caught");}
	
    }
 





    public static void assignWorkers(HttpServletRequest request,HttpServletResponse response,String name) throws ServletException,IOException{
	try{ 
	    Statement stmt=null;
	    Statement stmt1=null;
	    Statement stmt2=null;
	    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
	    
	
	    Connection myCom = DriverManager.getConnection(Configure.HOST_NAME,Configure.LOGIN,Configure.PASSWD);
	    String query = 
		"select complaint_id,location,description from complaint where end_date is null";
	    String query2 =
		"select works_for.worker_id,worker_type.type_id from works_for,worker_type where worker_type.worker_id=works_for.worker_id and supervisor_id='" + name + "'";
	    //	System.out.println("query is " + query);
	    PrintWriter out;
	    String title;
	    response.setContentType("text/html");
	    out = response.getWriter();
	    
	    title = "View jobs";
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(title);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<table cellpadding=4 border=2>");
	    out.println("<FORM ACTION=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\" method =\"GET\"><h2> Assign Workers</h2><pre> Select Complaint  <select name=\"complaint_no\">");
			
	    stmt = myCom.createStatement();
	    ResultSet rs = stmt.executeQuery(query);
	    ResultSetMetaData rsmd = rs.getMetaData();
	    String number=null;
	    while (rs.next()) {
		out.print("<option value=\"");
		number=rs.getString(1);
		out.print(number + "\">" + number + "," +rs.getString(2) +"," + rs.getString(3));
		out.print("</option>");
	    }
	    out.println("</select></pre><pre> Select Worker <select name=\"worker_no\">");
	    stmt2 = myCom.createStatement();
	    ResultSet rs2 = stmt2.executeQuery(query2);
	    ResultSetMetaData rsmd2 = rs2.getMetaData();
	    String number2=null;
	    while (rs2.next()) {
		out.print("<option value=\"");
		number=rs2.getString(1);
		out.print(number + "\">" + number + "," + rs2.getString(2));
		out.print("</option>");
	    }
		
	    out.println("</select></pre>");
	    out.println("<pre><input type=\"submit\" value=\"Assign\" name=\"assignworker\"></pre>");
	    out.println("<INPUT TYPE=\"submit\" NAME=\"goback\" VALUE=\"Go Back\" ><br>");
	    out.println("<INPUT TYPE=\"hidden\" NAME=\"fromassignpage\" VALUE=\"fromassignpage\" ><br>");
	    out.println("</form></table></body> </html>"); 
	    out.close();
	    
	}catch (SQLException sqle) {
	    sqle.printStackTrace();
	}
    }


    public static void assignexec(HttpServletRequest request,HttpServletResponse response,String name) throws ServletException,IOException{
	try{ 
	    Statement stmt=null;
	    Statement stmt1=null;
	    Statement stmt2=null;
	    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
	    
	
	    Connection myCom = DriverManager.getConnection(Configure.HOST_NAME,Configure.LOGIN,Configure.PASSWD);
	    String query = 
		"select complaint_id,location,description from complaint where end_date is null";
	    String query2 =
		"select works_for.worker_id,worker_type.type_id from works_for,worker_type where worker_type.worker_id=works_for.worker_id and supervisor_id='" + name + "'";
	    //	System.out.println("query is " + query);
	    PrintWriter out;
	    String title;
	    response.setContentType("text/html");
	    out = response.getWriter();
	    String cn = request.getParameter("complaint_no");
	    String worker = request.getParameter("worker_no");
	    String update = "insert into resolve values ('" + worker + "','" + cn + "')";
        //      System.out.print(update);
        //      System.out.println("xx");
	    stmt1 = myCom.createStatement();
            stmt1.executeUpdate(update);
               
	    title = "View jobs";
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(title);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<table cellpadding=4 border=2>");
	    out.println("<FORM ACTION=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\" method =\"GET\"><h2> Assign Workers</h2><pre> Select Complaint  <select name=\"complaint_no\">");
			
	    stmt = myCom.createStatement();
	    ResultSet rs = stmt.executeQuery(query);
	    ResultSetMetaData rsmd = rs.getMetaData();
	    String number=null;
	    while (rs.next()) {
		out.print("<option value=\"");
		number=rs.getString(1);
		out.print(number + "\">" + number + "," +rs.getString(2) +"," + rs.getString(3));
		out.print("</option>");
	    }
	    out.println("</select></pre><pre> Select Worker <select name=\"worker_no\">");
	    stmt2 = myCom.createStatement();
	    ResultSet rs2 = stmt2.executeQuery(query2);
	    ResultSetMetaData rsmd2 = rs2.getMetaData();
	    String number2=null;
	    while (rs2.next()) {
		out.print("<option value=\"");
		number=rs2.getString(1);
		out.print(number + "\">" + number + "," + rs2.getString(2));
		out.print("</option>");
	    }
		
	    out.println("</select></pre>");
	    out.println("<pre><input type=\"submit\" value=\"Assign\" name=\"assignworker\"></pre>");
	    out.println("<INPUT TYPE=\"submit\" NAME=\"goback\" VALUE=\"Go Back\" ><br>");
	    out.println("<INPUT TYPE=\"hidden\" NAME=\"fromassignpage\" VALUE=\"fromassignpage\" ><br>");
	    out.println("</form></table></body> </html>"); 
	    out.close();
	    
	}catch (SQLException sqle) {
	    sqle.printStackTrace();
	}
    }
    
    public  static void changeStatus(HttpServletRequest request,HttpServletResponse response,String name) throws ServletException,IOException{
	try {
	    Connection myCom;
	    Statement stmt=null;
	    Statement stmt1=null;
	    Statement stmt2=null;
	   
	    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
	    myCom = DriverManager.getConnection(Configure.HOST_NAME,Configure.LOGIN,Configure.PASSWD);
	
	    String query="select complaint.complaint_id, resolve.worker_id ,complaint.title,complaint.description, complaint.status , start_date ,end_date from complaint,works_for,resolve,worker where  complaint.complaint_id=resolve.complaint_id and resolve.worker_id=worker.worker_id and worker.worker_id=works_for.worker_id and works_for.supervisor_id='"+name+"'";
	    	    
	    PrintWriter out;
	    String title;
	    response.setContentType("text/html");
	    out = response.getWriter();
	
	    title = "View jobs";
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(title);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<h3>Complaints</h3>");
		    
	    out.println("<table cellpadding=4 border=2>");
	
	    stmt = myCom.createStatement();
	    ResultSet rs = stmt.executeQuery(query);
	    ResultSetMetaData rsmd = rs.getMetaData();
	    for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
		out.print("<th>" + "\n" + "  ");
		out.print( rsmd.getColumnName(i)  + "</th>" );
	    }
	    while (rs.next()) {
		out.print("<tr>");
		for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
		    out.print( "<td>" + rs.getString(i) + "</td>" );
		}
		out.print("</tr>");
	    }
	    out.println("</table><table>");
	    stmt2 = myCom.createStatement();
	
	    ResultSet rs2 = stmt2.executeQuery(query);
	    ResultSetMetaData rsmd2 = rs2.getMetaData();
	    String number=null;
	    out.println("<tr><td valign=\"top\" height=\"360\"><form name=\"mainform\" method=\"GET\" action=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\"><h2> Change Status</h2><pre> Select Complaint  <select name=\"complaint_no\">");

	    while (rs2.next()) {
		out.print("<option value=\"");
		number=rs2.getString(1);
		out.print(number + "\">" + number);
		out.print("</option>");
	    }
	    out.println("</select></pre>");
	    out.println("<pre>");
	    out.print("Enter the start date  "); 
	    out.print("<select name=\"day\"><option value=\"01\">01</option><option value=\"02\">02</option><option value=\"03\">03</option><option value=\"04\">04</option><option value=\"05\">05</option><option value=\"06\">06</option><option value=\"07\">07</option><option value=\"08\">08</option><option value=\"09\">09</option><option value=\"10\">10</option><option value=\"11\">11</option><option value=\"12\">12</option><option value=\"13\">13</option><option value=\"14\">14</option><option value=\"15\">15</option><option value=\"16\">16</option><option value=\"17\">17</option><option value=\"18\">18</option><option value=\"19\">19</option><option value=\"20\">20</option><option value=\"21\">21</option><option value=\"22\">22</option><option value=\"23\">23</option><option value=\"24\">24</option><option value=\"25\">25</option><option value=\"26\">26</option><option value=\"27\">27</option><option value=\"28\">28</option><option value=\"29\">29</option><option value=\"30\">30</option><option value=\"31\">31</option></select>");
	    out.print("<select name=\"month\"><option value=\"JAN\">January</option><option value=\"FEB\">February</option><option value=\"MAR\">March</option><option value=\"APR\">April</option><option value=\"MAY\">May</option><option value=\"JUN\">June</option><option value=\"JUL\">July</option><option value=\"AUG\">August</option><option value=\"SEP\">September</option><option value=\"OCT\">October</option><option value=\"NOV\">November</option><option value=\"DEC\">December</option></select>");
	    out.print("<select name=\"year\"><option value=\"2001\">2001</option><option value=\"2002\">2002</option><option value=\"2003\">2003</option><option value=\"2004\">2004</option><option value=\"2005\">2005</option></select>");
	    out.println("</pre>");
	    out.println("<pre>");
	    out.print("Enter the end date  "); 
	    out.print("<select name=\"day1\"><option value=\"01\">01</option><option value=\"02\">02</option><option value=\"03\">03</option><option value=\"04\">04</option><option value=\"05\">05</option><option value=\"06\">06</option><option value=\"07\">07</option><option value=\"08\">08</option><option value=\"09\">09</option><option value=\"10\">10</option><option value=\"11\">11</option><option value=\"12\">12</option><option value=\"13\">13</option><option value=\"14\">14</option><option value=\"15\">15</option><option value=\"16\">16</option><option value=\"17\">17</option><option value=\"18\">18</option><option value=\"19\">19</option><option value=\"20\">20</option><option value=\"21\">21</option><option value=\"22\">22</option><option value=\"23\">23</option><option value=\"24\">24</option><option value=\"25\">25</option><option value=\"26\">26</option><option value=\"27\">27</option><option value=\"28\">28</option><option value=\"29\">29</option><option value=\"30\">30</option><option value=\"31\">31</option></select>");
	    out.print("<select name=\"month1\"><option value=\"JAN\">January</option><option value=\"FEB\">February</option><option value=\"MAR\">March</option><option value=\"APR\">April</option><option value=\"MAY\">May</option><option value=\"JUN\">June</option><option value=\"JUL\">July</option><option value=\"AUG\">August</option><option value=\"SEP\">September</option><option value=\"OCT\">October</option><option value=\"NOV\">November</option><option value=\"DEC\">December</option></select>");
	    out.print("<select name=\"year1\"><option value=\"2001\">2001</option><option value=\"2002\">2002</option><option value=\"2003\">2003</option><option value=\"2004\">2004</option><option value=\"2005\">2005</option></select>");
	    out.println("</pre>");
	    out.print("<pre>Change Start date<input type=checkbox name=\"start\" value=\"change start\"></pre>");
	    out.print("<pre>Change End date<input type=checkbox name=\"end\" value=\"change end\"></pre>");
	    
	    
	    out.println("<pre> Enter the new status  <input type=\"text\" name=\"status\" size=\"20\" maxlength=\"50\"> </pre>");
	    out.println("<pre> Enter the new titl  <input type=\"text\" name=\"titl\" size=\"20\" maxlength=\"50\"> </pre>");
	   
	    out.println("<pre><input type=\"submit\" name=\"makechanges\" value=\"Change Status\"></pre>");
	    
	    out.println("<pre><input type=\"hidden\" name=\"fromchngstatuspage\" value=\"\"></pre>");
	    
	    out.println("<pre><input type=\"submit\" name=\"goback\" value=\"Go Back\"></pre>");
	
		    out.println("</td></tr></table></body> </html>"); 
	    out.close();
	
	} catch (SQLException sqle) {
	    sqle.printStackTrace();
	}
    }


 
    
    public  static void afterStatusChange(HttpServletRequest request,HttpServletResponse response,String name) throws ServletException,IOException{
	try {
	    Connection myCom;
	    Statement stmt=null;
	    Statement stmt1=null;
	    Statement stmt2=null;
	   
	    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
	    myCom = DriverManager.getConnection(Configure.HOST_NAME,Configure.LOGIN,Configure.PASSWD);
	
	    String query="select complaint.complaint_id, resolve.worker_id ,complaint.title,complaint.description ,complaint.status,start_date,end_date from complaint,works_for,resolve,worker where  complaint.complaint_id=resolve.complaint_id and resolve.worker_id=worker.worker_id and worker.worker_id=works_for.worker_id and works_for.supervisor_id='"+name+"'";
	    	    
	    PrintWriter out;
	    String title;
	    response.setContentType("text/html");
	    out = response.getWriter();
	
	    String complaint_no = request.getParameter("complaint_no");
	    String day = request.getParameter("day");
	    String month = request.getParameter("month");
	    String year = request.getParameter("year");
	    String day1 = request.getParameter("day1");
	    String month1 = request.getParameter("month1");
	    String year1 = request.getParameter("year1");
	    String status = request.getParameter("status");
	    String titl=request.getParameter("titl");
	    String start = request.getParameter("start");
	    String end = request.getParameter("end");

	    String update = "update complaint set status='" + status + "',title='" + titl + "',start_date='" + day + "-" + month + "-" + year + "',end_date='" + day1 + "-" + month1 + "-" + year1 + "' where complaint_id=" + complaint_no;
	    String update1 = "update complaint set status='" + status + "',title='" + titl + "',start_date='" + day + "-" + month + "-" + year + "' where complaint_id=" + complaint_no;
	    String update2 = "update complaint set status='" + status + "',title='" + titl + "',end_date='" + day1 + "-" + month1 + "-" + year1 + "' where complaint_id=" + complaint_no;
	
	    stmt1 = myCom.createStatement();
	    if (start==null) {
		stmt1.executeUpdate(update2);
	    }
	    else if (end==null) {
		stmt1.executeUpdate(update1);
	    }
	    else {
		stmt1.executeUpdate(update);
	    }
	

	    title = "View jobs";
	    out.println("<HTML><HEAD><TITLE>");
	    out.println(title);
	    out.println("</TITLE></HEAD><BODY>");
	    out.println("<h3>Complaints</h3>");
	    out.println("<table cellpadding=4 border=2>");
	
	    stmt = myCom.createStatement();
	    ResultSet rs = stmt.executeQuery(query);
	    ResultSetMetaData rsmd = rs.getMetaData();
	    for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
		out.print("<th>" + "\n" + "  ");
		out.print( rsmd.getColumnName(i)  + "</th>" );
	    }
	    while (rs.next()) {
		out.print("<tr>");
		for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
		    out.print( "<td>" + rs.getString(i) + "</td>" );
		}
		out.print("</tr>");
	    }
	    out.println("</table><table>");
	    stmt2 = myCom.createStatement();
	
	    ResultSet rs2 = stmt2.executeQuery(query);
	    ResultSetMetaData rsmd2 = rs2.getMetaData();
	    String number=null;
	    out.println("<tr><td valign=\"top\" height=\"360\"><form name=\"mainform\" method=\"GET\" action=\"" + Configure.SERVLET_SERVER + ":" + Configure.SERVLET_PORT + "/" + Configure.SERVLET_PATH + "/SupervisorRequests\"><h2> Change Status</h2><pre> Select Complaint  <select name=\"complaint_no\">");

	    while (rs2.next()) {
		out.print("<option value=\"");
		number=rs2.getString(1);
		out.print(number + "\">" + number);
		out.print("</option>");
	    }
	    out.println("</select></pre>");
	    out.println("<pre>");
	    out.print("Enter the start date  "); 
	    out.print("<select name=\"day\"><option value=\"01\">01</option><option value=\"02\">02</option><option value=\"03\">03</option><option value=\"04\">04</option><option value=\"05\">05</option><option value=\"06\">06</option><option value=\"07\">07</option><option value=\"08\">08</option><option value=\"09\">09</option><option value=\"10\">10</option><option value=\"11\">11</option><option value=\"12\">12</option><option value=\"13\">13</option><option value=\"14\">14</option><option value=\"15\">15</option><option value=\"16\">16</option><option value=\"17\">17</option><option value=\"18\">18</option><option value=\"19\">19</option><option value=\"20\">20</option><option value=\"21\">21</option><option value=\"22\">22</option><option value=\"23\">23</option><option value=\"24\">24</option><option value=\"25\">25</option><option value=\"26\">26</option><option value=\"27\">27</option><option value=\"28\">28</option><option value=\"29\">29</option><option value=\"30\">30</option><option value=\"31\">31</option></select>");
	    out.print("<select name=\"month\"><option value=\"JAN\">January</option><option value=\"FEB\">February</option><option value=\"MAR\">March</option><option value=\"APR\">April</option><option value=\"MAY\">May</option><option value=\"JUN\">June</option><option value=\"JUL\">July</option><option value=\"AUG\">August</option><option value=\"SEP\">September</option><option value=\"OCT\">October</option><option value=\"NOV\">November</option><option value=\"DEC\">December</option></select>");
	    out.print("<select name=\"year\"><option value=\"2001\">2001</option><option value=\"2002\">2002</option><option value=\"2003\">2003</option><option value=\"2004\">2004</option><option value=\"2005\">2005</option></select>");
	    out.println("</pre>");
	    out.println("<pre>");
	    out.print("Enter the end date  "); 
	    out.print("<select name=\"day1\"><option value=\"01\">01</option><option value=\"02\">02</option><option value=\"03\">03</option><option value=\"04\">04</option><option value=\"05\">05</option><option value=\"06\">06</option><option value=\"07\">07</option><option value=\"08\">08</option><option value=\"09\">09</option><option value=\"10\">10</option><option value=\"11\">11</option><option value=\"12\">12</option><option value=\"13\">13</option><option value=\"14\">14</option><option value=\"15\">15</option><option value=\"16\">16</option><option value=\"17\">17</option><option value=\"18\">18</option><option value=\"19\">19</option><option value=\"20\">20</option><option value=\"21\">21</option><option value=\"22\">22</option><option value=\"23\">23</option><option value=\"24\">24</option><option value=\"25\">25</option><option value=\"26\">26</option><option value=\"27\">27</option><option value=\"28\">28</option><option value=\"29\">29</option><option value=\"30\">30</option><option value=\"31\">31</option></select>");
	    out.print("<select name=\"month1\"><option value=\"JAN\">January</option><option value=\"FEB\">February</option><option value=\"MAR\">March</option><option value=\"APR\">April</option><option value=\"MAY\">May</option><option value=\"JUN\">June</option><option value=\"JUL\">July</option><option value=\"AUG\">August</option><option value=\"SEP\">September</option><option value=\"OCT\">October</option><option value=\"NOV\">November</option><option value=\"DEC\">December</option></select>");
	    out.print("<select name=\"year1\"><option value=\"2001\">2001</option><option value=\"2002\">2002</option><option value=\"2003\">2003</option><option value=\"2004\">2004</option><option value=\"2005\">2005</option></select>");
	    out.println("</pre>");

	    out.println("<pre> Enter the new status  <input type=\"text\" name=\"status\" size=\"20\" maxlength=\"250\"> </pre>");
	    out.print("<pre>Change Start date<input type=checkbox name=\"start\" value=\"change start\"></pre>");
	    out.print("<pre>Change End date<input type=checkbox name=\"end\" value=\"change end\"></pre>");
	    	    
	    out.println("<pre><input type=\"submit\" name=\"makechanges\" value=\"Change Status\"></pre>");

	    out.println("<pre><input type=\"hidden\" name=\"fromchngstatuspage\" value=\"\"></pre>");
	    
	    out.println("<pre><input type=\"submit\" name=\"goback\" value=\"Go Back\"></pre>");

	    
	    out.println("</td></tr></table></body> </html>"); 
	    out.close();
	
	}catch (SQLException sqle) {
	    sqle.printStackTrace();
	}
    }

}
 
   
