
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
  						 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import com.CellFusion.ECToolbox.*;
import com.CellFusion.Relational.*;
import com.CellFusion.Relational.RelBO.*;
 
public class Login extends HttpServlet implements SingleThreadModel
{ 
 
 	private Session ses=null;
	private RelTransaction ta=null;
	private HttpSession hs=null;
	PrintWriter out;
	 static PrintStream mPs;
	  	
  	public Login() 
  	{    
  		System.out.println(" With in the constructor   ");  
  		try {
     			System.out.println("*******Before class.forName*******");
     			//Class.forName("com.CellFusion.Relational.RelBO.LocationVector");
     			//Class.forName("com.CellFusion.Relational.RelBO.LLLocation");
     			//Class.forName("com.CellFusion.Relational.RelBO.Location");
     			Class.forName("com.CellFusion.Relational.RelConnection");
     		} catch (Exception e) { System.out.println("Class Error");};
  				     		 
  	}  
  	  	
  	public static void setSystemOutFile()
	{
	if  (mPs == null) {

	try {
		FileOutputStream fos =
           		new FileOutputStream("c:\\2.txt");
        BufferedOutputStream bos =
                new BufferedOutputStream(fos, 1024);
          //  PrintStream mPs;
        mPs  = new PrintStream(bos, true);

        	// redirect System.out to it

		if  (System.out != null)
        	System.setOut(mPs);
    	if  (System.err != null)
    		System.setErr(mPs);
        } catch (Exception e) {

        		System.out.println("couldnt create outfile");
        	}
    	}
    }
  	  	    
    public synchronized void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {   
    		
    		System.out.println("--------------->Inside doGet<--------------------------");
    
      		 	setSystemOutFile();
     		
     		
     		
    		this.ses = new Session();
    		Util.log("*****  creating Session Object **** LOGIN ***** ");
    		this.hs = request.getSession(true);
    		if(this.hs  != null )
    		{
    			Util.log("  Session     Object is not null ");
    		 
    		}
    		else
    		{
    			Util.log("  Session is not null  ");
    		}
    		     		       		        		  
    		// Initialize all the data base files ....
    		Util.log("  ----- servlet ----    Setting the file Name ");

    		Util.log(" ----- servlet ----   before getCFProperty(\"environment\") ");
    		
    		String environment = Util.getCFProperty("environment");
    		Util.log(" ----- servlet ---- environment  :"+environment);
		 	if (environment == null || environment.length() <= 0) 
		    {
		    	Util.log(" ----- servlet ---- environment == null or <= 0 :"+environment);

				Util.setEnvironment( environment );
			}
			Util.log(" ----- servlet ---- Before setEnvironment  :"+environment);
			Util.setEnvironment( environment );
			
			Util.log(" ----- servlet ----  Before Database creation for the Environment "+environment);
	 
	 		 if(! (this.ses.getDatabseInstnce()) )
	 		 {
	 			this.ses.setDatabseInstnce(true);
			 	if (dbCF.testDboCF())
			 	{
					Util.log(" ----- servlet ----  Database files got Created ");
				} 
			
			}    //Sathish Remove this To Make   Database UP
		      
			try
			{
			
				Util.log(" ----- servlet ---- RelTransaction for the Database ");
			
			 	this.ta = RelTransaction.beginNewTransaction();
				if (this.ta== null) 
				{
					Util.log("  ----- servlet ----  RelTransaction object is null ");
				}
				else
				{
					Util.log("  ----- servlet ----  RelTransaction object is Not null ");
					this.ses.setTransaction(this.ta);
					Util.log("  ----- servlet ---- After  ses.setTransaction ");
				}								   
								
			}catch(Exception e)
			{
				Util.log("  ----- servlet ---- Exception While creting the RelTran Object  "+e);
			}
			 		
    		response.setContentType("text/html");
        	this.out = response.getWriter();
        	
        	this.hs.putValue("Session",this.ses);
        	
        	System.out.println("**********      CHECK1   **************");
                   
//****************************************************************************************************   
                      	
//	New Html file ...

		 PrintTheOMSPageToBrowser(response, null ) ;                           	
     }
     
     public synchronized void PrintTheOMSPageToBrowser(HttpServletResponse response ,String error )  {
               	
               	
             try  
    	{
    		response.setContentType("text/html");
       		this.out= response.getWriter();
       	  		
		this.out.println("<HTML> ");
		this.out.println("<HEAD>");

		this.out.println("<TITLE>CellFusion : Login for Electronic OMS</TITLE>");

		this.out.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">");
		this.out.println("<link rel=\"stylesheet\" href=\"../images/size_gral.css\" type=\"text/css\">");
		this.out.println("<link rel=\"stylesheet\" href=\"../images/back_over.css\" type=\"text/css\">");
		this.out.println("</HEAD>");
		this.out.println("<BODY BGCOLOR=#607780 topmargin=\"0\" leftmargin=\"0\" scroll=\"no\">");
		this.out.println("<table border=0 cellpadding=0 cellspacing=0 width=\"100%\" height=\"100%\" class=\"size_gral\">");
		 this.out.println(" <tr> ");
		 this.out.println("   <td background=\"../images/gif/index/index_07.gif\" height=\"2\" width=\"3%\"><img src=\"../images/gif/general/logo_cell.gif\" width=\"34\" height=\"15\"></td>");
		   this.out.println(" <td height=\"2\" colspan=\"2\" background=\"../images/gif/index/index_04a.gif\"> ");
		   this.out.println("   <table width=\"0\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"right\">");
		      this.out.println("  <tr> ");
		      this.out.println("    <td width=\"263\" height=\"2\"> ");
		       this.out.println("     <div align=\"right\"><font size=\"1\" face=\"Arial, Helvetica, sans-serif\" color=\"#000000\">&copy; ");
		       this.out.println("       2001 CellFusion, Inc. - All rights reserved&nbsp;&nbsp;&nbsp;</font></div>");
		       this.out.println("   </td>");
		       this.out.println("   <td height=\"2\" width=\"23\"> ");		       
		       
		      this.out.println("  </td>");
		      this.out.println("  </tr>");
		      this.out.println("</table>");
		   this.out.println(" </td>");  
		 this.out.println(" </tr>");  
		  this.out.println("<tr> ");
		  this.out.println("  <td background=\"../images/gif/index/index_07.gif\" height=\"6\" width=\"3%\">&nbsp; </td>");
		   this.out.println(" <td height=\"6\" width=\"55%\">&nbsp; </td>");
		   this.out.println(" <td height=\"6\" width=\"42%\"> ");
		   this.out.println("   <div align=\"right\"><img src=\"../images/gif/index/index_03a.gif\" width=315 height=83></div>");
		   this.out.println(" </td>");
		 this.out.println(" </tr>");
		 this.out.println(" <tr> ");
		 this.out.println("   <td colspan=2 background=\"../images/gif/index/index_05a.gif\" height=\"25\"> <img src=\"../images/gif/index/index_05.gif\" width=377 height=43></td>");
		  this.out.println("  <td background=\"../images/gif/index/index_05a.gif\" height=\"25\" width=\"42%\"> ");
		  this.out.println("    <div align=\"right\"><img src=\"../images/gif/index/index_06.gif\" width=275 height=43></div>");
		  this.out.println("  </td>");
		  this.out.println("</tr>");
		 this.out.println(" <tr> ");
		  this.out.println("  <td rowspan=4 background=\"../images/gif/index/index_07.gif\" width=\"3%\">&nbsp; </td>");		  				  	
		  
		   this.out.println(" <td rowspan=4 width=\"55%\" valign=\"bottom\" class=\"size_gral\"> ");		   
		   this.out.println("   <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" height=\"122\">");		   			   
		    this.out.println("    <tr> ");
		    this.out.println("      <td height=\"73\" valign=\"top\"> ");
		    this.out.println("        <p class=\"size_gral\">Costumer Service<br>");
		     this.out.println("         Toll Free: 1-866-CELLFUSION (1-866-2355387466)<br>");
		             this.out.println(" <a href=\"mailto:getmore@cellfusion.com\" class=\"back_over\">getmore@cellfusion.com ");
		             this.out.println(" </a></p>");
		         this.out.println(" </td>");
		       this.out.println(" </tr>");
		     this.out.println(" </table>");
		   this.out.println(" </td>");
		    this.out.println("<td valign=\"top\" height=\"8\" width=\"42%\"> ");		    
		    
		     this.out.println(" <form name=\"Search\" method=\"post\" action=\"Search\">");
		       this.out.println(" <table width=\"249\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"right\" height=\"92\">");
		       
		       /*******************/
			if(error != null) {
			
				this.out.println(" <tr>");
			       this.out.println("<td height=\"14\" align=\"center\" colspan=\"6\"><font color=\"#FFFFFF\" size=\"4\" face=\"Arial, Helvetica, sans-serif\">" + error ); 
			     //  this.out.println("<td height=\"14\" align=\"center\" colspan=\"2\"><font color=\"#FFFFFF\" size=\"4\" face=\"Arial, Helvetica, sans-serif\">" + error ); 
			         this.out.println("  </font></td>");       
			         this.out.println(" </tr>");   
		         }  
			 /*******************/	
		       
		          this.out.println("<tr> ");
		          this.out.println("  <td width=\"74\"><b><font size=\"2\" color=\"#FFFFFF\" face=\"Arial, Helvetica, sans-serif\">Name</font></b></td>");
		           this.out.println(" <td width=\"150\"> ");
		            this.out.println("  <input type=\"text\" name=\"username\">");
		           this.out.println(" </td>");
		         this.out.println(" </tr>");
		         this.out.println(" <tr> ");
		         
 		           this.out.println(" <td width=\"74\"><b><font size=\"2\" color=\"#FFFFFF\" face=\"Arial, Helvetica, sans-serif\">Password</font></b></td>");
		            this.out.println("<td width=\"150\"> ");
		            this.out.println("  <input type=\"password\" name=\"password\">");
		           this.out.println(" </td>");  
		         this.out.println("</tr>");
		          this.out.println("<tr> ");
		            this.out.println("<td width=\"74\">&nbsp;</td>");

this.out.println("<td width=\"150\"><input type=\"image\" border=\"0\" name=\"imageField\"   src=\"../images/gif/index/index_15.gif\" width=\"69\" height=\"14\" border=\"0\">");		         
		         
		            this.out.println("</td>");  
		          this.out.println("</tr>");		          	 
		          ////		         				          
		        this.out.println("</table>");
		        this.out.println("<div align=\"right\"></div>");
		      this.out.println("</form>");
		   this.out.println(" </td>");
		  this.out.println("</tr>");		  	 
		  
		 this.out.println(" <tr>");
	   this.out.println(" <td width=\"42%\" height=\"110\"> ");
	   this.out.println(" <div align=\"right\"><img src=\"../images/gif/index/index_08.gif\" width=\"280\" height=\"91\"></div>");
	   this.out.println("</td>");  
		 this.out.println(" </tr>");   
		 			 
		 this.out.println(" <tr> ");			 	
	
		   this.out.println(" <td width=\"42%\" height=\"58\">");
		this.out.println("<table width=\"305\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\" align=\"right\">");
		       this.out.println(" <tr> ");
		         this.out.println(" <td> ");
		          this.out.println("  <p align=\"right\"><font size=\"1\"><span class=\"size_gral\">Value Stream ");
		            this.out.println("  Technology Development Center&nbsp;&nbsp;</span></font></p>");
		            this.out.println("<p class=\"size_gral\" align=\"right\"><span class=\"size_gral\">111 Anza ");
		            this.out.println("  Boulevard, Suite 205&nbsp;&nbsp; <br>");
		             this.out.println(" Burlingame - CA 94010 - USA&nbsp;&nbsp; <br>");
		             this.out.println(" Phone: +1.650.347.4000&nbsp;&nbsp;<br>");
		             this.out.println(" Fax: +1.650.347.4036&nbsp;&nbsp;</span><br>");
		            this.out.println("  <a href=\"mailto:getmore.com\" class=\"back_over\">support@cellfusion.com</a><span class=\"size_gral\">&nbsp;&nbsp;</span><span class=\"size_gral\"><br>");
		            this.out.println("  <a href=\"http://www.celfusion.com\" class=\"back_over\">www.cellfusion.com</a>&nbsp;</span><a href=\"mailto:getmore@cellfusion.com\" class=\"back_over\">&nbsp; ");
		            this.out.println("  </a></p>");
		         this.out.println(" </td>");
		        this.out.println("</tr>");
		     this.out.println(" </table>");
		    this.out.println("  <p align=\"right\"><font size=\"1\"><span class=\"size_gral\"> </span></font></p>");
		   this.out.println(" </td>");
		  this.out.println("</tr>");
		  this.out.println("<tr> ");
		   this.out.println(" <td width=\"42%\">&nbsp; </td>");
		this.out.println("  </tr>");
		this.out.println("</table>");
		this.out.println("</BODY>");
		this.out.println("</HTML>");
		
	}catch(java.io.IOException e)
		{
			Util.log("Exception in Login "+e.toString());
		}	
     
     }
    
 }
