<?php
    include("config.php");

    
    if(isset($_GET['ref'])){
        $ref = $_GET['ref'];
        $select = $conn->query("SELECT * FROM `main_reg` WHERE `cd`='$ref'");
        if(mysqli_num_rows($select) >= 1){
            $q = mysqli_fetch_array($select);
            $ref_name = strtoupper($q['first_name']);
        }else{
            $ref_name = 'Eagle Winks';
            $ref = '';
        }
        
        
    }else{
        $ref_name = 'Eagle Winks';
        $ref = '';
    }
    
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="Eagle Winks">
    <title>Eagle Winks Cash Flow - It pays to have friends</title>
    <link href="assets/css/themify-icons.css" rel="stylesheet">
    <link href="assets/css/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/flaticon.css" rel="stylesheet">
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/animate.css" rel="stylesheet">
    <link href="assets/css/owl.carousel.css" rel="stylesheet">
    <link href="assets/css/owl.theme.css" rel="stylesheet">
    <link href="assets/css/slick.css" rel="stylesheet">
    <link href="assets/css/slick-theme.css" rel="stylesheet">
    <link href="assets/css/swiper.min.css" rel="stylesheet">
    <link href="assets/css/owl.transitions.css" rel="stylesheet">
    <link href="assets/css/jquery.fancybox.css" rel="stylesheet">
    <link href="assets/css/odometer-theme-default.css" rel="stylesheet">
    <link href="assets/css/nice-select.css" rel="stylesheet">
    <link href="assets/css/signup.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
     <link rel="icon" href="https://eaglewinks.com/assets/images/favicon.png" type="image/png" sizes="16x16">

</head>

<body>
    <!-- start preloader 
    <div class="preloader">
        <div class="sk-folding-cube">
            <div class="sk-cube1 sk-cube"></div>
            <div class="sk-cube2 sk-cube"></div>
            <div class="sk-cube4 sk-cube"></div>
            <div class="sk-cube3 sk-cube"></div>
        </div>
    </div>-->
    <!-- end preloader -->
    <div class="wpo-login-area">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="text-center">
                        <a href="#"><img src="assets/images/logo.png" alt="" width="250px"></a><br><br>
                    </div>
                    <form class="wpo-accountWrapper" id="register" action="">
                        
                        <div class="wpo-accountForm form-style">
                            <div class="fromTitle">
                                <h2>Signup</h2>
                                <p>Create your account</p>
                                <p id="msg">
                                    
                                </p>
                            </div>
                            <div class="row">
                                
                                <div class="col-lg-12 col-md-12 col-12">
                                    <label for="name">Full Name</label>
                                    <input type="text" id="fname" name="fname" placeholder="Your name here..">
                                </div>
                                <div class="col-lg-12 col-md-12 col-12">
                                    <label>Email Address</label>
                                    <input type="text" id="email" name="email" placeholder="Your email here..">
                                </div>
                                <div class="col-lg-12 col-md-12 col-12">
                                    <label>Phone Number</label>
                                    <input type="text" id="phone" name="phone" placeholder="Your Phone Number here..">
                                </div>
                                <div class="col-lg-12 col-md-12 col-12">
                                    <div class="form-group">
                                        <label>Password</label>
                                        <input class="pwd2" type="password" placeholder="Your password here.." value="" name="password">
                                    </div>
                                    <span class="input-group-btn">
                                        <button class="btn btn-default reveal3" type="button"><i class="glyphicon glyphicon-eye-open"></i></button>
                                    </span>
                                </div>
                                <div class="col-lg-12 col-md-12 col-12">
                                    <div class="form-group">
                                        <label>Confirm Password</label>
                                        <input class="pwd3" type="password" placeholder="Your password here.." value="" name="password2">
                                    </div>
                                    <span class="input-group-btn">
                                        <button class="btn btn-default reveal2" type="button"><i class="glyphicon glyphicon-eye-open"></i></button>
                                    </span>
                                </div>
                                <div class="col-lg-12 col-md-12 col-12">
                                    <label>Referred By: </label><br>
                                    <?php echo $ref_name;?>
                                    <input type="hidden" id="ref" name="ref" value="<?php echo $ref;?>">
                                </div>
                                <div class="col-lg-12 col-md-12 col-12">
                                    <button type="submit"  class="wpo-accountBtn submit" >Signup</button>
                                </div>
                            </div>
                           
                            <p class="subText">Already have an account? <a href="login">Login</a></p>
                        </div>
                        
                        <div class="wpo-accountInfo">
                            <div class="wpo-accountInfoHeader">
                                <a href="#"><img src="assets/images/logo.png" alt=""></a>
                                <br>
                                <a class="wpo-accountBtn" href="login" class="btn btn-warning">
                                    <span class="">Log in</span>
                                </a>
                            </div>
                            <div class="image">
                                <img src="assets/images/login.svg" alt="">
                            </div>
                            <div class="back-home">
                                <a class="wpo-accountBtn" href="/">
                                    <span class="">Back To Home</span>
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- All JavaScript files
    ================================================== -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <!-- Plugins for this template -->
    <script src="assets/js/jquery-plugin-collection.js"></script>
    <!-- Custom script for this template -->
    <script src="assets/js/script.js"></script>
    <script>
    $(".reveal").on('click', function() {
        var $pwd = $(".pwd");
        if ($pwd.attr('type') === 'text') {
            $pwd.attr('type', 'password');
        } else {
            $pwd.attr('type', 'text');
        }
    });
    $(".reveal2").on('click', function() {
        var $pwd = $(".pwdr");
        if ($pwd.attr('type') === 'text') {
            $pwd.attr('type', 'password');
        } else {
            $pwd.attr('type', 'text');
        }
    });
    </script>
     
             <script>
            $('#register').on('submit',function(e){
                e.preventDefault();
                $('#pass_msg').html('');
                $('#email_msg').html('');
                var pswd = $('#password').val();
                var cpswd = $('#password2').val();
                var email = $('#email').val();
                //var email1 = $('#email1').val();
                //$(".submit").attr("disabled",true);
                //$("#email1").css("border-color", "#000");
                $("#email").css("border-color", "#000");
                 $("#password").css("border-color", "#000");
                $("#password2").css("border-color", "#000");
                $("#username").css("border-color", "#000");
                $('.submit').html('Please wait.....');
                $('#msg').html('');
                $('#msgc').html('');
                if(cpswd != pswd){
                    //$('.pass_msg').show();
                    $('#pass_msg').html('<span style="font-size: 11px; color: #f00;">');
                    
                   // $('#msg').html('<div class="alert alert-danger" style="width: 100%; background: #b22222; padding: 10px; border-radius: 10px; color: #fff; text-align: center;">Password did not match</div>');
                    //$('#pass_msg').html('');
                    $("#password").css("border-color", "red");
                    $("#password2").css("border-color", "red");
                    $('#msg').html('<div class="alert alert-danger" style="width: 100%; background: #b22222; padding: 10px; border-radius: 10px; color: #fff; text-align: center;">Data input contains error. check the data entered and Try Again</div>');
                    $('.submit').html('REGISTER');
                    
                }else{
                    $('#pass_msg').html('');
                    $('#email_msg').html('');
                    $('#msg').html('');
                    $("#password").css("border-color", "#000");
                    $("#password2").css("border-color", "#000");
                    //$("#email1").css("border-color", "#000");
                    $("#email").css("border-color", "#000");
                    
                    $("#username").css("border-color", "#000");
                    $.ajax({
                        url: 'process.php',
                        type: 'post',
                        data: $("#register").serialize(),
                        beforeSend:function(){
                            $('.submit').html('UPDATING DATA.....');
                        },
                        success: function(data) {
                            //alert(data);
                            //grecaptcha.reset();
                            $('#msg').fadeIn('slow');
                            if(data == 'one'){
                                
                                $('#msg').html('<div class="alert alert-danger" style="width: 100%; background: #b22222; padding: 10px; border-radius: 10px; color: #fff; text-align: center;">Username already exists. choose another username</div>');
                                $("#username").css("border-color", "red");
                                $('#msg').html('<div class="alert alert-danger" style="width: 100%; background: #b22222; padding: 10px; border-radius: 10px; color: #fff; text-align: center;">Email already exists. choose another email</div>');
                            }else if(data == 'three'){
                                $('#msg').html('<div class="alert alert-danger" style="width: 100%; background: #00813d; padding: 10px; border-radius: 10px; color: #fff; text-align: center;">Registration was Successful. Redirecting....</div>');
                                
                                $('#msgc').html('<div class="alert alert-danger" style="width: 100%; background: #00813d; padding: 10px; border-radius: 10px; color: #fff; text-align:; font-size: 12px;">Registration was Successful. Redirecting....<br><br><a class="btn btn-warning" href="login">Login</a></div>');
                                setTimeout(function(){
                                    window.location = "login";
                                }, 20000);
                            }else if(data == 'four'){
                                $('#msg').html('<div class="alert alert-danger">Check internet connection</div>');
                            }else{
                                alert(data);
                            }
                            //grecaptcha.reset();
                            $(".submit").removeAttr("disabled",true);
                            $('.submit').html('Sign Up');
                        } 
                    }); 
                    
                   
                    
                }
                
                
            });
        </script>
</body>
</html>