
<!-- Author : Jagbir Singh -->
<!-- Debug : Amanbir Singh -->
<!-- Tested by : Swapnil Sarode  -->

  <%@page import="java.util.ArrayList"%>
<%
    response.setHeader("Cache-Control","no-store");
    response.setHeader("Pragma","no-cache");
    response.setDateHeader ("Expires", 0);
    %>
     <%@ page language="java" import="java.sql.*, javax.sql.DataSource, javax.naming.*" errorPage="" %>
    <%
    DataSource pool;
    Connection conn = null;
    PreparedStatement pstmt = null;
    String spclQuery = null;
    ArrayList<String> spcl = new ArrayList<String>();    
    ArrayList<String> fname = new ArrayList<String>();
    ArrayList<String> drId = new ArrayList<String>();
    
    String radioInJSP = null;
    radioInJSP=request.getParameter("active");
    ResultSet rs = null;
    int j=0;
    try{
    	InitialContext ctx = new InitialContext();
    	pool = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
    	if (pool == null)
            throw new SQLException("Unknown DataSource 'jdbc/TestDB'");
    	conn = pool.getConnection();
    	
    	if(radioInJSP.equals("actpatient")){		//for getting details of various patients registered
    		
    		spclQuery = "SELECT firstName, spclZtion, doc_Id from drInfo";
    	       pstmt = conn.prepareStatement(spclQuery);   
    	        rs = pstmt.executeQuery();
    	       while(rs.next()){
    	 		fname.add(rs.getString("firstName"));
   	    		spcl.add(rs.getString("spclZtion"));
   	    		drId.add(rs.getString("doc_Id"));
   	    		
   	    		
   	    	 }
    	} else {				//getting specializations from the DB
			
    	    	 spclQuery = "SELECT specialization from specialization";
    	    	 pstmt = conn.prepareStatement(spclQuery); 
    	    	 rs = pstmt.executeQuery();
    	    	 while(rs.next()){
    	    		spcl.add(rs.getString("specialization"));
    	    		
    	    	
    	    	 }
    	}
    	rs.close();
        pstmt.close();
        conn.close();     
    	
    }catch(SQLException se){
    	se.printStackTrace();
    }catch(Exception e){
        //Handle errors for Class.forName
        e.printStackTrace();
     }finally{
        //finally block used to close resources
        try{
           if(pstmt!=null)
              pstmt.close();
        }catch(SQLException se2){
        }// nothing we can do
        try{
           if(conn!=null)
           conn.close();
        }catch(SQLException se){
           se.printStackTrace();
        }//end finally try
     } //end try
    
    %>
    
       <html>
       
<body>
<TABLE BORDER="0" cellpadding="0" CELLSPACING="0">
<TR>

<TD WIDTH="940" HEIGHT="345" BACKGROUND="main_banner_consumed.png" VALIGN="top">

<FONT SIZE="5" COLOR="black">One step Toward Healthier Life<br><br></FONT>
<FONT SIZE=3" COLOR="black">I love that it records<br>
everything - from sunrise<br>
to sunset and beyond.
</FONT>
</TD>

</TR>
</TABLE>



    <% radioInJSP=request.getParameter("active"); 
   
    if(radioInJSP.equals("actpatient"))
    {
    %>

<form action="RegisterDb.jsp" method=post>
<table cellpadding=4 cellspacing=2 border=0>
<th bgcolor="#FFFFFF" colspan=2>
<font size=4>REGISTRATION</font>
<br><font size=1><sup></sup></font><hr>
</th><tr bgcolor="#FFFFFF"><td valign=top> 

<b>First Name<sup>*</sup></b> 
<br><input type="text" name="firstname" value="" size=15 maxlength=20>
</td><td  valign=top>

<b>Last Name<sup>*</sup></b>
<br><input type="text" name="surname" value="" size=15 maxlength=20></td>
</tr><tr bgcolor="#FFFFFF">
<td valign=top>

<b>E-Mail<sup>*</sup></b> 
<br><input type="text" name="email" value="" size=25  
maxlength=125><br></td><td  valign=top>

<b>Zip Code<sup>*</sup></b> <br>
<input type="text" name="zipcode" value="" size=5 maxlength=6></td>
</tr><tr bgcolor="#FFFFFF"><td valign=top colspan=2>

<b>User Name<sup>*</sup></b><br>
<input type="text" name="userId" size=10 value=""  maxlength=10>
</td></tr><tr bgcolor="#FFFFFF">
<td valign=top>

<b>Password<sup>*</sup></b> 
<br><input type="password" name="pswd1" size=10 value=""  
maxlength=10></td><td  valign=top>


<b>SEX(M/F):<sup>*</sup></b>
<br>Male <input type="radio" name="sex" value="M"/>
Female <input type="radio" name="sex" value="F"/>
Other <input type="radio" name="sex" value="O"/>
</td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Temp Add:<sup>*</sup></b>
<br><input type="text" name="address1" size=50 value=""  
maxlength=100></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Perm Add:<sup>*</sup></b>
<br><input type="text" name="address2" size=50 value=""  
maxlength=100></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Age:<sup>*</sup></b>
<br><select name = "age">
<% for(int i=0;i<=100;i++){%>

<option value="<%=i%>"><%=i%></option>

<%} %>
</select>

</td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>
<b>DoctorName:<sup>*</sup></b>
<br><select name="drName">
<%
for(int i = 0;i<fname.size();i++){ 
	String drname = drId.get(i)+" | "+fname.get(i)+" | "+spcl.get(i);
%>

<option value="<%=drId.get(i)%>"><%=drname%></option>
<% }%>

</select>
</td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Contact Number:<sup>*</sup></b>
<br><input type="text" name="phNumber" size=10 value=""  
maxlength=15></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Height(in cms):<sup>*</sup></b>
<br><input type="text" name="height" size=3 value=""  
maxlength=3></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Weight(in lbs):<sup>*</sup></b>
<br><input type="text" name="weight" size=3 value=""  
maxlength=3></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Occupation:<sup>*</sup></b>
<br><input type="text" name="Occupation" size=10 value=""  
maxlength=15></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<input type="hidden" name="active" value="actpatient">

<hr>
<input type="submit" value="Submit"></td></tr></table></center></form>


<%}
    else { %>

<form action="RegisterDb.jsp" method=post>
<table cellpadding=4 cellspacing=2 border=0>
<th bgcolor="#FFFFFF" colspan=2>

<font size=4>REGISTRATION</font>
<br><font size=1><sup></sup></font><hr>
</th><tr bgcolor="#FFFFFF"><td valign=top> 

<b>First Name<sup>*</sup></b> 
<br><input type="text" name="firstname" value="" size=15 maxlength=20>
</td><td  valign=top>

<b>Last Name<sup>*</sup></b>
<br><input type="text" name="surname" value="" size=15 maxlength=20></td>
</tr><tr bgcolor="#FFFFFF">
<td valign=top>

<b>E-Mail<sup>*</sup></b> 
<br><input type="text" name="email" value="" size=25  
maxlength=125><br></td><td  valign=top>

<b>User Name<sup>*</sup></b><br>
<input type="text" name="userId" size=10 value=""  maxlength=10>
</td></tr><tr bgcolor="#FFFFFF">
<td valign=top>

<b>Password<sup>*</sup></b> 
<br><input type="password" name="pswd1" size=10 value=""  
maxlength=10></td><td  valign=top>
<b>


<b>SEX(M/F):<sup>*</sup></b>
<br>Male <input type="radio" name="sex" value="M"/>
Female <input type="radio" name="sex" value="F"/>
Other <input type="radio" name="sex" value="O"/>
</td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>


<b>Perm Add:<sup>*</sup></b>
<br><input type="text" name="address2" size=50 value=""  
maxlength=100></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Age:<sup>*</sup></b>

<br><select name = "age" >

<%for(int i=0; i<=100; i++) { %>

<option value="<%=i%>"><%=i%></option>

<%} %>
</select></td><br>

</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Specialization:<sup>*</sup></b>
<br>
<select name = "spcl">
<%for(int i = 0;i<spcl.size();i++){ %>
<option value="<%=spcl.get(i)%>"><%=spcl.get(i)%> </option>

<% }%>
</select>
</td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<b>Contact Number:<sup>*</sup></b>
<br><input type="text" name="phNumber" size=10 value=""  
maxlength=15></td><br>
</tr><tr bgcolor="#FFFFFF">
<td  align=top colspan=2>

<input type="hidden" name="active" value="actdoctor">

<hr>
<input type="submit" value="Submit"></td></tr></table></center></form>

<%}
%>

</body>
</html>