<?
ob_start();
session_start();
 include("../include/db.inc.php"); 
  include("../include/bit_functions.inc.php");
   include("../include/mail.php");
   $db1=new db;
   $db1->open();
    mysql_query("SET NAMES 'utf8'");
   if($_SESSION['uname']=='' || $_SESSION['pwd']=='')
		{
			header("location:login.php");
		}
  $headermsg="Create USer Account";    
   if(isset($_POST['submit']))
   { 
     extract($_POST); 	 
     $sql_chk="select * from user where email='$email'";
     $res_chk=mysql_query($sql_chk);
	if(mysql_num_rows($res_chk)>0)
	 {
  ?>
<script type=text/javascript language=javascript>
	    alert("Sorry! This email address is already available! Please try for a different email!");
	    window.location.href="add_user.php";
	   </script>
<?
	 } 
	 
else 
		 { 
		 
		  
		  $ccode=substr(md5($email),0,10);
  		  $sql="insert into user (id,gender,first_name,last_name,uname,password,email,ccode)
		  values('','$gender','$fname','$lname','$uname','$password','$email','$ccode')";
 		 $res=mysql_query($sql) or die(mysql_error().$sql);
		 $i_id=mysql_insert_id();		
		 mysql_query("insert into friends set user_id='1', fr_id='$i_id', status='1'");
		$reg = "yes";
		}
		
  if($reg ==="yes")
   {  
   			register_mail($fname,$email,$ccode,$i_id); 	
		  mysql_query("insert into newsletter_subscribe set email='".$email."',uid='$i_id'");
			confirm_newsletter($email,$i_id); 
			
          $msg="<font color=\"red\">User Registration Successfully</font><br />";
		  header("location:add_user.php?msg='$msg'");
   }
 
  }   
 
	
   
?>


<!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>

<title>Money-Auctions Administion Console</title>
<script src="../include/validation.js"></script>
<!--<script src="../js/normal.js"></script>
-->
<script language="javascript">
function validate()
{
	
	var fname=trim(document.form1.fname.value);
	if(is_empty(fname))
	{
		alert("Please enter your First name!");
		document.form1.fname.focus();
		return false;
	}
	var lname=trim(document.form1.lname.value);
	if(is_empty(lname))
	{
		alert("Please enter your Lastname!");
		document.form1.lname.focus();
		return false;
	}
	
	
	
	
	var uname=trim(document.form1.uname.value);
	if(is_empty(uname))
	{
		alert("Please enter your Username!");
		document.form1.uname.focus();
		return false;
	}
	
	var password=trim(document.form1.password.value);
	if(is_empty(password))
	{
		alert("Please enter your Password!");
		document.form1.password.focus();
		return false;
	}
	
	if(document.form1.password.value=='')
	{
	alert("Pasword field can't be blank.");
	return false;
	}
	
	if(document.form1.password.value != document.form1.cpassword.value)
	{
	alert("Password and confirm password fields are not matching.");
	return false;
	}
	
	
	
	var email=document.form1.email;
	if (trim(email.value) == 0) {
		alert("Please enter your email address!");
		email.focus();
		return false;
	} else if (email.value.indexOf("@") < 0) {
		alert("Incorrect email address. Please re-enter.");
		email.focus();
		return false;
	} else if (email.value.indexOf(".") < 0) {
		alert("Incorrect email address. Please re-enter.");
		email.focus();
		return false;
	} else if (trim(email.value).indexOf(" ") >= 0) {
		alert("Incorrect email address. Please re-enter.");
		email.focus();
		return false;
	}
	
		if(document.form1.email.value != document.form1.cemail.value)
	{
	alert("Email and confirm email fields are not matching.");
	return false;
	}
	
	

return true;
}

</script>
</head>
<body bgcolor="#ffffff">
<div class="admin_wrapper">
<div class="logo_show"><? include("minorlogout.php");?></div>
<div style="float:left; width:200px">
<div class="topg_links_show"><? include("left.php");	?></div>
<div class="top_links_show"><? include("belowleft1.php");	?></div></div>
<div style="float:left; width:800px">
<div class="maximum">
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse; border-color:#ffffff">
  <tr>
    <td><? //include("header.php");?></td>
  </tr>
</table>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::header ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->

<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<div style="margin-top:5px">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%" style="border-collapse:collapse; border-color:#404193">
  <tr height="417">
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->   
    
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::left ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->    
<td width="85%" bgcolor="#FFFFFF" valign="top">
<table width="98%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
        <tr>
          <td width="10" align="center" valign="top">&nbsp;</td>
          <td align="center" valign="top"><table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr>
                <td width="1" valign="top">&nbsp;</td>
                <td valign="top"><br>
                  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
                    <tr>
                      <td width="33" valign="top"><img src="img/03.gif" width="33" height="23"></td>
                      <td background="img/bg01.gif"><strong>&nbsp;NEW USER</strong></td>
                      <td width="35"><img src="img/04.gif" width="35" height="23"></td>
                    </tr>
                  </table>
                  <table  width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
                    <tr>
                      <td width="22" valign="top" background="img/tbl-left04.gif"><img src="img/tbl-left04.gif" width="22" height="13"></td>
                      <td valign="top" align="center">
                        
                       <form name="form1" action="" method="post" id="form1" onSubmit="return validate();">
     <? if($_GET['msg'])
	 echo $_GET['msg'];
	 ?>
<table width="33%" border="0" cellspacing="2" cellpadding="2" align="center">
  <tr>
    <td colspan="2"  align="center" class="normaltextgreenbold13 tal"><u>Enter User Details:</u></td>
    </tr>
  <tr>
    <td width="123" align="right" valign="top">&nbsp;</td>
    <td width="144" align="left" valign="top">&nbsp;</td>
    
  </tr>
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">First Name:</td>
    <td align="left" valign="top"><input name="fname" type="text" class="inputtextgrey"  ></td>
    
  </tr>
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">Last Name:</td>
    <td align="left" valign="top">
      <input name="lname" type="text" class="inputtextgrey"   />    </td>
    
  </tr>
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">Gender:</td>
    <td align="left" valign="top"><input type="radio" name="gender" value='male' checked="checked" />Male&nbsp;&nbsp;&nbsp;
	<input type="radio" name="gender" value='female'  />Female</td>
   
  </tr>
  
  
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">Username:</td>
    <td align="left" valign="top">
      <input name="uname" type="text" class="inputtextgrey"   />    </td>
    
  </tr>
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">Password:</td>
    <td align="left" valign="top">
      <input name="password" type="password" class="inputtextgrey"  />    </td>
    
  </tr>
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">Confirm-Password:</td>
    <td align="left" valign="top">
      <input name="cpassword" type="password" class="inputtextgrey"  />    </td>
    
  </tr>
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">Email:</td>
    <td align="left" valign="top">
      <input name="email" type="text" class="inputtextgrey"  />    </td>
    
  </tr>
  <tr>
    <td align="left" valign="top" class="normaltextgreybold13">Re-confirm Email:</td>
    <td align="left" valign="top"> <input name="cemail" type="text" class="inputtextgrey"  /></td>
  </tr>
  <tr>
    <td align="right" valign="top"></td>
    <td align="left" valign="top"><div  align="center">
            <input type="submit" name="submit" value="Register" class="inputsubmit"  /></div></td>
    
  </tr>
  
</table>
</form>

                        
                      </td>
             <td width="19" valign="top" background="img/tbl-right04.gif"><img src="img/tbl-right04.gif" width="19" height="9"></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="bodytxt">
              <tr> 
                <td width="33"><img src="img/tbl-bot01.gif" width="33" height="12"></td>
                <td  width="709" align="right" background="img/tbl-bg.gif"></td>
                <td width="33"><img src="img/tbl-right05.gif" width="35" height="12"></td>
              </tr>
            </table></td>
                <td width="20" valign="top">&nbsp;</td>
              </tr>
            </table>
          
          </td>
        </tr>
      </table>
        </td>
  </tr>
</table>
</div>


<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::center ends:::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer starts:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</div></div>
<div class="bottom_links_show"><? include("footer.php");	?></div>
</div>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::footer ends:::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
