<%@ page language="java" import="iDSS.*,iDSS.utils.*,iDSS.webBeans.*,iDSS.beans.*" errorPage="error/error.jsp"%>


<%!
    String emailValue;
    String nameValue;
    boolean success = false;
    UserJBean user;
%>


<html>
<head>
<title><%=IDSSAppConstants.programTitle%></title>
</head>



<jsp:useBean id="logBean" scope="session" class="iDSS.webBeans.LogJBean"/>
<jsp:useBean id="monitor" scope="application" class="java.util.Hashtable"/>


<body>
<jsp:include page="templates/header.jsp" flush="true"/>

<h1>Registration Page</h1>

<p>Please register to use the system.
</p>



<hr>
<form method="post">

    <table border="0">


        <tr>
            <td>Name:</td>
            <td><input type="text" size="20" name="name"></td>
        </tr>

        <tr>
            <td>Email:</td>
            <td><input type="text" size="20" name="email"></td>
        </tr>


        <tr>
            <td><input type="submit" value="Register"></td>
        <tr>

    </table>

</form>

<%

    if(request.getParameter("email") != null && request.getParameter("name") != null) {

        emailValue = request.getParameter("email");
        nameValue = request.getParameter("name");

        if((emailValue.length() < 1) || (nameValue.length() < 1) || emailValue.indexOf('@') == -1) {

%>
            <p>Plese enter a valid name and an email address.</p>
<%

        } //if(request.getParameter("email").equals(""))

        else {

%>

            <p>You have entered </p>
            <p>Name : <%=nameValue%>.</p>
            <p>Email : <%=emailValue%>.</p>
            <p>Checking if email is available...</p>
        
<%

            boolean logOnSuccess = logBean.logOn(emailValue);

            if(!logOnSuccess) {

                boolean registerSuccess = logBean.register(nameValue,emailValue);

                if(registerSuccess) {
%>
                    <p>Registered successfully : <%=registerSuccess%></P>

<%
                    user = logBean.getUser();
                    session.setAttribute(IDSSAppConstants.user,user);
                    monitor.put(user,session);
%>


                    <P>
                        Name                        : <%=user.getName()%><BR>
                        Email                       : <%=user.getEmail()%><BR>
                        Last visit date             : <%=user.getLastVisited().toString()%><BR>
                        Total time spent (millisec) : <%=user.getTotalTimeSpent()%><BR>
                    </P>

<%

                } //if(registerSuccess)

            } //if(!logOnSuccess)

            else {
%>

                <P>
                    This email addressed is in use. Please use another email address.
                </P>

<%
            } //else


        } //else


    } //if(request.getParameter("email") != null .....)



%>


<hr>
<jsp:include page="templates/footer.jsp" flush="true"/>

</body>

</html>

