<?php
include("sess_page.php");
include("include/dbconnect.php");
extract($_POST);
$msg="";

$ip = $_SERVER['REMOTE_ADDR'];
//////MAC Address////////
ob_start();
//Get the ipconfig details using system commond
system('ipconfig /all');

// Capture the output into a variable
$mycom=ob_get_contents();
// Clean (erase) the output buffer
ob_clean();

$findme = "Physical";
//Search the "Physical" | Find the position of Physical text
$pmac = strpos($mycom, $findme);

// Get Physical Address
$mac=substr($mycom,($pmac+36),17);
////////////////////////////////////////////
if(isset($register))
{
 if(trim($name)=="") { $msg = "Enter the Name..."; }
 else if(trim($contact)=="") { $msg = "Enter the Contact No."; }
 else if(trim($email)=="") { $msg = "Enter the E-mail..."; }
 else if(trim($uname)=="") { $msg = "Enter the Username"; }
 else if(trim($pwd)=="") { $msg = "Enter the Password"; }
 else if(trim($cpass)=="") { $msg = "Enter the Confirm Password"; }
 else if($pwd!=$cpass) { $msg = "Both Password are not equal!"; }
	else
	{
	$max_qry = mysql_query("select max(id) maxid from register");
	$max_row = mysql_fetch_array($max_qry);
	$id=$max_row['maxid']+1;
	$rdate=date("Y-m-d");
	$keys=md5($uname);
   $secretkey=substr($keys,0,8);
		$uqry="insert into register(id,name,gender,address,pincode,contact,email,credit,secretkey,username,password,macaddress,rdate) values($id,'$name','$gender','$address','$pincode',$contact,'$email','$credit','$secretkey','$uname','$pwd','$mac','$rdate')";
		$res=mysql_query($uqry);	
		if($res)
		{
		include("email2.php");
		$objEmail	=	new CI_Email();
		//$objEmail->from('cloudservice@gmail.com', "Cloud Service");
		$objEmail->from('service@gmail.com', "Clod Service");
		$objEmail->to("$email");
		//$objEmail->cc($txt_cc);
		//$objEmail->bcc($txt_bcc);
		$objEmail->subject("Key Information");
		
		$objEmail->message("OTP Key:".$secretkey." ".$prkey);

			if ($objEmail->send())
			{	
			//echo 'mail sent successfully';
			}
			else
			{	
			//echo 'failed';
			}	
			
		//header("location:register2.php");
		$_SESSION['username'] = $uname;
			?>
			<script language="javascript">
			alert("Your account has been created");
			window.location.href="register2.php";
			</script>
			<?php
		}
		else
		{
		$msg="Could not be stored!";
		}
	}	
	
}
?>
<html>
<head>
<title><?php include("include/title.php"); ?></title>
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style2 {
	color: #990000
}
-->
</style>
<link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon">
	

    <link rel="apple-touch-icon" href="../images/apple-touch-icon.png">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <!-- Site CSS -->
    <link rel="stylesheet" href="../css/style.css">
    <!-- Responsive CSS -->
    <link rel="stylesheet" href="../css/responsive.css">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="../css/custom.css">

<script language="javascript">
function validate()
{

	if(document.form1.name.value=="")
	{
	alert("Enter the Name...");
	document.form1.name.focus();
	return false;
	}
	if(document.form1.gender[0].checked==false && document.form1.gender[1].checked==false)
	{
	alert("Select the Gender");
	return false;
	}
	if(document.form1.address.value=="")
	{
	alert("Enter the Address...");
	document.form1.address.focus();
	return false;
	}
	if(document.form1.pincode.value=="")
	{
	alert("Enter the Pincode...");
	document.form1.pincode.focus();
	return false;
	}
	if(isNaN(document.form1.pincode.value))
	{
	alert("Invalid Pincode!");
	document.form1.pincode.select();
	return false;
	}
	if(document.form1.contact.value=="")
	{
	alert("Enter the Contact No...");
	document.form1.contact.focus();
	return false;
	}
	if(isNaN(document.form1.contact.value))
	{
	alert("Invalid Mobile No!");
	document.form1.contact.select();
	return false;
	}
	if(document.form1.email.value=="")
	{
	alert("Enter the E-mail ID...");
	document.form1.email.focus();
	return false;
	}
	reEmail=/^[\w-|+|'|]+(\.[\w-|+|'|]+)*@([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*?\.[a-zA-Z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/
	if(!(reEmail.test(document.form1.email.value))){
     alert("E-Mail Invalid");
        return false;
	} 
	if(document.form1.uname.value=="")
	{
	alert("Enter the username!");
	document.form1.uname.focus();
	return false;
	}
	if(document.form1.pwd.value=="")
	{
	alert("Enter the Password...");
	document.form1.pwd.focus();
	return false;
	}
	if (document.form1.pwd.value!=document.form1.cpass.value)
	{
	alert("Both passwords are not equal!")
	document.form1.cpass.select();
	return false;
	}
return true;	
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
 <header class="main-header">
        <!-- Start Navigation -->
        <nav class="navbar navbar-expand-lg navbar-light bg-light navbar-default bootsnav">
            <div class="container">
                <!-- Start Header Navigation -->
                <div class="navbar-header">
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-menu" aria-controls="navbars-rs-food" aria-expanded="false" aria-label="Toggle navigation">
                    <i class="fa fa-bars"></i>
                </button>
                    <a class="navbar-brand" href="index.html"><img src="images/logo.png" class="logo" alt=""></a>
                </div>
                <!-- End Header Navigation -->

                <!-- Collect the nav links, forms, and other content for toggling -->
				  <div class="collapse navbar-collapse" id="navbar-menu">
                    <ul class="nav navbar-nav ml-auto" data-in="fadeInDown" data-out="fadeOutUp">
                        <li class="nav-item active"><a class="nav-link" href="../index.html">Home</a></li>
                        <li class="nav-item"><a class="nav-link" href="login.php">Admin</a></li>
                        
                        <li class="nav-item"><a class="nav-link" href="login.php">User</a></li>
                        <li class="nav-item"><a class="nav-link" href="register3.php">CreateAccount</a></li>
                    </ul>
                </div>
                <!-- /.navbar-collapse -->

                <!-- Start Atribute Navigation -->
                
                <!-- End Atribute Navigation -->
            </div>
            <!-- Start Side Menu -->
            
            <!-- End Side Menu -->
        </nav>
        <!-- End Navigation -->
    </header>
    <!-- End Main Top -->
  <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
       <div  style="background-image:url(../images/bg3.jpg);height:50%; text-align: center;">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <h2>New Account Create</h2>
                    <ul class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active"> Account Create </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <!-- End All Title Box -->
    <tr>
      <td align="center"><p>&nbsp;</p>
        <p class="style1 style2"><?php echo $msg; ?></p>
        <table width="405" height="360" border="0" cellpadding="0" cellspacing="0">
           <div class="row">
                <div class="col-lg-8 col-sm-12">
          <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <input type="text" class="form-control" name="name" placeholder="Your Name" required data-error="Please enter your name">
                                        <div class="help-block with-errors"></div>
                                    </div>
                                </div>
         
           
          
          
		 
		 
           <div class="col-md-12">
                                    <div class="form-group">
            <textarea name="address" class="form-control" placeholder="Your Address" ></textarea>
           </div>
		 </div>
           <div class="col-md-12">
                                    <div class="form-group">
            <input type="text" name="pincode" class="form-control" placeholder="Your Pincode">
           </div>
		 </div>
         <div class="col-md-12">
                                    <div class="form-group">
            <input type="text" name="contact" class="form-control" placeholder="Your Mobile No">
           </div>
		 </div>
          <div class="col-md-12">
                                    <div class="form-group">
            <input type="text" name="email" id="email" class="form-control" placeholder="Your Email">
          </div>
		 </div>
		  <div class="col-md-12">
                                    <div class="form-group">
            <input type="text" name="credit"  class="form-control" placeholder="Your Credit no">
          </div>
		 </div>
          <div class="col-md-12">
                                    <div class="form-group">
            <input type="text" name="uname" class="form-control" placeholder="Enter Username..." />
           </div>
		 </div>
         <div class="col-md-12">
                                    <div class="form-group">
           <input type="password" name="pwd" class="form-control" placeholder="Your Password.." />
          </div>
		 </div>
            <div class="col-md-12">
                                    <div class="form-group">
            <input type="password" name="cpass" class="form-control" placeholder="Retype Password">
           </div>
		 </div>
		  <div class="col-md-12">
                                    <div class="form-group">
         <input type="submit" name="register" value="Register" onClick="return validate()" class="btn hvr-hover" />
            <input type="reset" name="Reset" value="Clear" class="btn hvr-hover">
          </div>
		 </div>
		  </div>
		  </div>
		  </div>
        </table>
        <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    </tr>
    <tr>
      <td align="center" >&nbsp;</td>
    </tr>
  </table>
      <!-- Start copyright  -->
    <div class="footer-copyright">
        <p class="footer-company">&nbsp;</p>
    </div>
    <!-- End copyright  -->
</form>
</body>
 <!-- ALL JS FILES -->
    <script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/popper.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <!-- ALL PLUGINS -->
    <script src="../js/jquery.superslides.min.js"></script>
    <script src="../js/bootstrap-select.js"></script>
    <script src="../js/inewsticker.js"></script>
    <script src="../js/bootsnav.js."></script>
    <script src="../js/images-loded.min.js"></script>
    <script src="../js/isotope.min.js"></script>
    <script src="../js/owl.carousel.min.js"></script>
    <script src="../js/baguetteBox.min.js"></script>
    <script src="../js/form-validator.min.js"></script>
    <script src="../js/contact-form-script.js"></script>
    <script src="../js/custom.js"></script>
</html>
