<?php
session_start();
ob_start();
$session_id=session_id();
require("includes/config.php");
require("includes/dbcon.php");

if($_REQUEST['Submit']=="Done")
{
	$fisrt_name=trim($_REQUEST['fisrt_name']);
	$middle_name=trim($_REQUEST['middle_name']);
	$last_name=trim($_REQUEST['last_name']);
	$username=trim($_REQUEST['uname']);
	$password=trim($_REQUEST['pwd']);
	$email=trim($_REQUEST['email']);
	
	$userSql="select * from enrollee where username = '".$username."' or email = '".$email."'";
	$userRs=mysql_query($userSql);
	$totRows=mysql_num_rows($userRs);	
    if($totRows>0)
	{
		$err_msg1="SORRY! USERNAME/EMAIL ALREADY EXISTS";
	}
	else
	{		
		$insert_enrollee_sql="insert into enrollee SET curDate=now(),
					fisrt_name='".mysql_escape_string($fisrt_name)."',
					middle_name='".mysql_escape_string($middle_name)."',
					last_name='".mysql_escape_string($last_name)."',
					email='".mysql_escape_string($email)."',				
					username='".mysql_escape_string($username)."',
					password='".mysql_escape_string($password)."'";
		mysql_query($insert_enrollee_sql);
		$insrt_id= mysql_insert_id();
		if($insrt_id)
		{
			$msg="Thank You! <br> Your activation link already sent to you.<br>Please Check Your mail. ";
	
			$path = "./upload/"."$insrt_id";
			mkdir("$path");
			chmod("$path",0767);
	
			$insert_sessions_sql="insert into sessions SET 
					enrollee_id=".$insrt_id.",
					session_key='".$session_id."',
					session_date=now(),
					ip_address ='".$_SERVER['REMOTE_ADDR']."',				
					browser_name='".$_SERVER['HTTP_USER_AGENT']."',
					operating_system='".$_SERVER['HTTP_USER_AGENT']."'";		
	
			mysql_query($insert_sessions_sql);
	
			$fromNm="Reliable-ID Security Team";
			$fromMail="securit@reliableid.com";
	
			$txt="Thank You!<br>To activate your registration please click <a href='http://reliableid.com/login/activation.php?nda=$insrt_id'>HERE</a>";
	
			$headers  = "From: ".$fromNm."<".$fromMail.">\r\n";
			$headers  .= "MIME-Version: 1.0\r\n";
			$headers  .= "Content-Type: text/html";
			
			$body = "
			<HTML>
				<BODY>
				<CENTER>
					<TABLE BORDER='1'>
						<TR>
							<TD align='center'>
								<FONT COLOR='MAROON'><B><BIG>".$txt."</BIG></B></FONT>
							</TD>
						</TR>
					</TABLE>
				</CENTER>
				</BODY>
			</HTML>";
			
			mail($email, "Registration Mail", $body, $headers);
		}
		else
		{
			$err_msg="SORRY! TRY AGAIN";
		}
	}
}
ob_end_flush();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="./style/design.css" rel="stylesheet" type="text/css" />

<style type="text/css">
<!--
.style1 {font-size: 0.8em}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Register Page</title>
<script language="JavaScript" src="includes/js/common.js"></script>
<script language="JavaScript">
function validate()
{
	var is_valid=true
	is_valid = blank_check( document.frm.fisrt_name.value, "PLEASE INPUT FIRST NAME" )
		if( is_valid == false ) { document.frm.fisrt_name.focus(); return is_valid }

	is_valid = blank_check( document.frm.last_name.value, "PLEASE INPUT LAST NAME" )
		if( is_valid == false ) { document.frm.last_name.focus(); return is_valid }
		
	is_valid = blank_check( document.frm.uname.value, "PLEASE INPUT USERNAME" )
		if( is_valid == false ) { document.frm.uname.focus(); return is_valid }

	is_valid = blank_check( document.frm.email.value, "PLEASE INPUT EMAIL" )	
    if( is_valid == false ) { document.frm.email.focus(); return is_valid }
	
	is_valid = email_check( document.frm.email.value, "PLEASE INPUT CORRECT EMAIL" )
    if( is_valid == false ) { document.frm.email.focus(); return is_valid }	

	is_valid = blank_check( document.frm.pwd.value, "PLEASE INPUT YOUR PASSWORD" )	
    if( is_valid == false ) { document.frm.pwd.focus(); return is_valid }
	
	is_valid = length_check( document.frm.pwd.value.length, 8, "PASSWORD MUST BE AT LEAST 8 CHARACTERS LONG" )
    if( is_valid == false ) { document.frm.pwd.focus(); return is_valid }
	
	is_valid = blank_check( document.frm.pwd2.value, "PLEASE RE-ENTER PASSWORD" )	
    if( is_valid == false ) { document.frm.pwd2.focus(); return is_valid }

	is_valid = same_check( document.frm.pwd.value, document.frm.pwd2.value, "PLEASE CHECK PASSWORD" )	
    if( is_valid == false ) { document.frm.pwd2.focus(); return is_valid }

	return is_valid
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td align="center" valign="top">		
<?php
include_once("includes/header.php");
?>
<?php
if( !$msg )
{
?>
<form name="frm" method="post" action="" onSubmit="return validate()">
	<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">	 
	 <tr>
	   <td width="30%" valign="top">
		<div class="bodySubHeader">
		<span class="bsht03">User Registration</span>		
		</div>
		</td>
	 </tr> 
	</table>	

	<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0" class="DarkLightBox">
	 <tr>
	   <td height="30" align="center" valign="top" colspan="3" class="ErrorMessage"><strong><?=$err_msg1?></strong></td>	   
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>First Name:</strong><font color="red"><strong>*</strong></font></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="fisrt_name" type="text"/></td>
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Middle Name:</strong></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="middle_name" type="text"/></td>
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Last Name:</strong><font color="red"><strong>*</strong></font></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="last_name" type="text"/></td>
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Username:</strong><font color="red"><strong>*</strong></font></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="uname" type="text"/></td>
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>E-mail:</strong><font color="red"><strong>*</strong></font></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="email" type="text"/></td>
	 </tr>
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Password:</strong><font color="red"><strong>*</strong></font></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="pwd" type="password"/></td>
	 </tr>		
	 <tr>
	   <td height="30" align="left" valign="top" class="browseEventContents"><strong>Re-Enter Password:</strong><font color="red"><strong>*</strong></font></td>
	   <td height="30" align="left" valign="top">&nbsp;</td>
	   <td height="30" align="left" valign="top"><input name="pwd2" type="password"/></td>
	 </tr>		 
	 <tr>
	   <td height="35" align="left" valign="bottom">&nbsp;</td>
	   <td width="30" height="35" align="left" valign="bottom">&nbsp;</td>
	   <td height="35" align="left" valign="bottom"><input name="Submit" type="submit" value="Done" /></td>
	 </tr>
	</table>
</form>
<?php
}
if( !empty($_POST) )
{
?>
	<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">		 
	 <tr>
	   <td height="30" align="center" valign="top"><strong><br /><br /><?=$msg?></strong></td>	   
	 </tr>
	</table>
<?php
}
?>
<?php
include_once("includes/footer.php");
?>
		</td>
	</tr>
</table>
</body>
</html>