import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.Object.*;
import java.sql.*;

public class EMaterjalidAdmin extends HttpServlet{
	static private PrintWriter pw;
	private int ID=0;
	
	public EMaterjalidAdmin(){
		try{
			
		}catch(Exception e){}
	}
	final static private void lisaTeema(String teema,String vanem,HttpServletRequest kysimus)throws Exception{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");			
		Connection cn=DriverManager.getConnection("jdbc:odbc:baas", "", "");		
		Statement st=cn.createStatement();
		String lause="insert into teema(teema,vanem) values('"+teema+"',"+Integer.parseInt(vanem)+");";
		st.executeUpdate(lause);
		pw.println("<a href='"+kysimus.getRequestURI()+"?id=0&lk=0'></a>");
	}
	final static private void kustutaTeema(Connection cn,int ID)throws Exception{
		Statement st=cn.createStatement();
		String lause="delete from teema where ID = '"+ID+"';";
		st.executeUpdate(lause);
	}
	final static private void lisaMaterjal(){
		
	}
	final static private void kustutaMaterjal(){
		
	}
	public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException{	
			
		
		PrintWriter pw=vastus.getWriter();
		try{
			vastus.setContentType("text/html");
			pw.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
			pw.println("<HTML><HEAD>");
			pw.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />");
			pw.println("<TITLE>eMaterjalid</TITLE></HEAD>\n");
			pw.println("<BODY BGCOLOR=#535772 LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 LINK=#FFFFFF VLINK=#FFFFFF><CENTER>");
			String s1=kysimus.getParameter("teemaNimi");
			String s2=kysimus.getParameter("id");
			String s3=kysimus.getParameter("vanem");
			pw.println(s1);
			
			if((s2!=null)&&(s3!=null)){
				if(s2.equals("lisa")){
					lisaTeema(s1,s3,kysimus);
				}
			}
			
			
			pw.println("</CENTER></BODY></HTML>");		
		}catch(Exception e){
			pw.println("viga(doGet):"+e);
		}
		
	}
	public void doPost(HttpServletRequest kysimus,HttpServletResponse vastus)throws ServletException, IOException {
    	doGet(kysimus, vastus);
  	}
}