<?php 
	
    include("../../config/defines.php");
    
    
    
    
    //User Registration..
    if (isset($_POST["user_name"])) {
        $user_name = $_POST["user_name"];
        $user_mobile = $_POST["user_mobile"];
        $user_email = $_POST['user_email'];
        $user_password = $_POST['user_password'];
        $user_passcode = $_POST['user_passcode'];
        $user_type = $_POST['user_type'];
        
        $name = "/^[a-zA-Z ]+$/";
        $emailValidation = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9]+(\.[a-z]{2,4})$/";
        $number = "/^[0-9]+$/";
      
        $user_ip = $_SERVER['REMOTE_ADDR'];
		$ipdat = 'http://ip-api.com/php/'.$user_ip;
		$ress = @unserialize(file_get_contents($ipdat));
		$user_country = $ress["country"];
		$user_city = $ress["city"];

        $sql = "SELECT user_id FROM aalierp_user WHERE user_email = '$user_email' LIMIT 1" ;
        $check_query = mysqli_query($conn,$sql);
        $count_email = mysqli_num_rows($check_query);
        if($count_email > 0){
            echo "Email already exists!";
            exit();
        } else {
            $date = date("Y-m-d H:i:s");
            $user_password = md5($user_password);
            $sql = "INSERT INTO `aalierp_user` (user_name,user_mobile,user_email,user_password,user_passcode,user_type,user_ip,user_city,user_country,user_status,created_on,created_by) 
            VALUES ('$user_name', '$user_mobile', '$user_email', '$user_password', '$user_passcode', 'User', '$user_ip', '$user_city', '$user_country','Approved','$date','$user_name')";
            $run_query = mysqli_query($conn,$sql);
            $last_insert_id = mysqli_insert_id($conn);
            $sql = "UPDATE aalierp_cart SET user_id = '$last_insert_id' WHERE ip_add='$user_ip' AND user_id = -1";

            if(mysqli_query($conn,$sql)){
                
$subjectt = "Email Verification On Getting Registered at eTewish Portal"; 
$fromm = "noreply@tewish.mraalionline.com";
$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'From: '.$fromm."\r\n".'Reply-To: '.$fromm."\r\n" .'X-Mailer: PHP/' . phpversion();
$logo = "https://tewish.mraalionline.com/cms/uploads/logos/logo.png";
$messag = "
<html>
    <head>
        <title>Email Verification On Getting Registered</title>
    </head>
    <body style='background: #ffffff; padding: 10px;'>
        <div style='background: #f0f0f0; width: 100%; height: auto; text-align: center; border-top: 3px dotted #000;'>
            <a href='https://tewish.mraalionline.com'><img src='$logo' style='width: 250px; height: auto;' alt='tewish.mraalionline Logo' /></a><br>
            | <a href='https://tewish.mraalionline.com/products' style='text-decoration: none; color: blue;'> Products</a> | 
            <a href='https://tewish.mraalionline.com/about' style='text-decoration: none; color: blue;'> About</a> | 
            | <a href='https://tewish.mraalionline.com/forum' style='text-decoration: none; color: blue;'> Forum</a> | 
            <a href='https://tewish.mraalionline.com/contact' style='text-decoration: none; color: blue;'> Contact</a> | <br>
        </div>
    <h3>Hi ".$user_name.",</h3>
    <h4 style=''>Congratulation on being registered!</h4>
    <p style='padding: 20px;'>

    Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.<br><br>
                  
    -------------------------------------------<br>
        Username:          ".$user_email."<br>
        Password:          ".$user_password."<br>
        Passcode (words):   ".$user_passcode."<br>
    -------------------------------------------<br>
            
    Please click this link to activate your account:<br><br>
        </p>
        
        <div style='padding: 10px; border: 2px solid blue; border-radius: 20px 20px 20px 20px;'>
            <a href='https://tewish.mraalionline.com/login/?email=".$user_email."&password=".$user_password."' style='text-decoration: none; color: blue; font-size: 2.0em;'> Verify Email </a>
        </div>
        
        <div style='padding: 10px; border: 2px solid green; border-radius: 20px 20px 20px 20px;'>
            <a href='https://tewish.mraalionline.com' style='text-decoration: none; color: green; font-size: 2.0em;'>Visit Website</a>
        </div>

        <p style='padding: 20px;'>
    Feel free to reach out to our team with any questions or for more information on our best material for training.<br><br>

    Sincerely,<br><br>

            <a href='https://tewish.mraalionline.com'><img src='$logo' style='width: 100px; height: auto;' alt='tewish.mraalionline Logo' /></a><br>
            tewish.mraalionline Portal <br>
            A108 Adam Street | Las Vegas, NY 535022 | United States<br>
            | <a href='mailto:info@tewish.mraalionline.com'>info@tewish.mraalionline.com</a> | <a href='tel:+14583425008'>+1 (458) 342 5008</a> | <a href='https://tewish.mraalionline.com'>https://tewish.mraalionline.com</a> | <br><br>
            
        </p>
        <p style='padding: 20px; text-align: center;'>
        | <a href='https://tewish.mraalionline.com'>Home</a> | <a href='https://tewish.mraalionline.com/products'>Products</a> | <a href='https://tewish.mraalionline.com/about'>About</a> | <a href='https://tewish.mraalionline.com/forum'>Forum</a> | <a href='https://tewish.mraalionline.com/contact'>Contact</a> |
        </p>
        

</body></html>";
                                  
    
    mail($user_email, $subjectt, $messag, $header);
                
                
                
                
                
                echo "Registered successfully!";
                exit();
            }
        }  
    }



























?>