/*
* Code by George Kichukov for SAS 12/05/2002
* This class is used to execute user modifications on the database
* depending on the parameters passed to it for ModifyMajorList and ModifyReq only the Courses part
*/
package admin;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import utilities.*;
public class QueryList extends HttpServlet
{
private String errorTarget = "../admin/index.jsp";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// If it is a get request forward to doPost()
doPost(request, response);
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
//name of the user
String name="";
PrintWriter out = response.getWriter();
response.setContentType("text/html");
//first thing that every servlet or jsp should do is check if user is logged in
HttpSession session = request.getSession(false);
//if not logged in redirect to login
if(session == null)
{
HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", errorTarget);
return;
}
//else if logged in take the name from the session
else
{
name=(String)session.getAttribute("user");
//if the name is null
if(name == null)
{
HTMLUtils.printRedirectPage(out, "You must login to the system prior to viewing this page.", errorTarget);
return;
}
}
HTMLUtils.printAdminHeader(out);
//display welcome message to the user
out.println("
Welcome " + name + "
");
//get the parameters
String table=request.getParameter("table");
String oper=request.getParameter("oper");
String id=request.getParameter("id");
String mID=request.getParameter("mID");
//display operation summary
out.println ("Operation: " + oper + " " + table + "
");
String primaryKey="";
//case 1: Minors
if(table.equals("MINORS"))
{
primaryKey="MinorID";
String sql="select * from " + table + " where " + primaryKey + "=" + id;
//out.println(sql);
try
{
ResultSet rs = Retriever.executeSQL(sql);
try
{
String dataIn=request.getParameter("NotAvailableList");
if(!dataIn.equals("none"))
{
//parse the requirment string
dataIn=RequirementParser.toMajorDatabaseString(dataIn);
}
rs.updateString("NotAvailableList",dataIn);
rs.updateRow();
out.println("Major List Modified Successfully!");
}
catch (RequirementParserException e)
{
out.println(e.getMessage());
}
} //end try
catch(SQLException e) {out.println("SQLException " + e.getMessage());}
}
//CASE 2: COURSES
else
{
primaryKey="CourseID";
String fieldID="";
String sql="select * from " + table + " where " + primaryKey + "=" + id;
//out.println(sql);
Enumeration keys;
String key1;
String value;
//get enumeration of all paramters passed
keys = request.getParameterNames();
//loop through all parameters
while (keys.hasMoreElements())
{
key1 = (String) keys.nextElement();
value = request.getParameter(key1);
//make sure it picks up only the List field
if( (key1.equals("oper")) || (key1.equals("id")) || (key1.equals("mID")))
{
//don nothing
}
else if ((key1.substring(key1.length()-4,key1.length()).equals("List")) )
{
fieldID=key1;
}
else
{
//do nothing
}
}
try
{
ResultSet rs = Retriever.executeSQL(sql);
//out.println(fieldID + " " + request.getParameter(fieldID));
try
{
String dataIn=request.getParameter(fieldID);
if(!dataIn.equals("none"))
{
//parse the requirment string
dataIn=RequirementParser.toCourseDatabaseString(dataIn);
}
rs.updateString(fieldID, dataIn );
rs.updateRow();
out.println("Course List Modified Successfully!");
}
catch (RequirementParserException e)
{
out.println(e.getMessage());
}
} //end try
catch(SQLException e) {out.println("SQLException " + e.getMessage());}
} //end else any other table
HTMLUtils.printAdminFooter(out);
} //end method doPost
} //end Query servlet