<?php session_start();
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
include("includes/db_config.php");
if (isset($_POST['register'])) {
  extract($_POST);
  $logo = "https://orangegroceries.com/img/logo.png";
    $logo_width = "100%";
    $logo_height = "";
    // All CSS
    // Body
    $body_title = "Orange Groceries";
    $width_of_mail_body = "80%"; // Please write in % percentage for better view...
    $padding_of_mail_body = "20px";
    $body_background_color = "";
    $body_text_color = "";
    // Header
    $header_background_color = "";
    $header_text_color = "";
    $header_font_size = "";
    $header_font_family = "";
    // Footer
    $footer_background_color = "#2F3B59";
    $footer_text_color = "white";
    $footer_font_size = "10px";
    $footer_font_family = "monospace";
    // Button
    $button_background_color = "#4db7fe";
    $button_text_color = "white";
    $button_font_size = "20px";
    $button_font_family = "monospace";
    $button_padding = "15px";
    $button_border_radius = "10px";
    // Highlight
    $highlight_color = "#4db7fe";
    $highlight_font_size = "25px";
    $highlight_font_family = "monospace";
    // Heading
    $heading_color = "#4db7fe";
    $heading_font_size = "25px";
    $heading_font_family = "monospace";
    
$email = mysqli_real_escape_string($conn,$_POST['email']);
$password = mysqli_real_escape_string($conn,$_POST['password']);
$sql ="SELECT count(*) as num FROM user_profile WHERE email = '".$email."'";
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
$res= mysqli_fetch_array($result);
 $count=$res['num']; 
if($count == 0 )
{ 
date_default_timezone_set('Asia/Kolkata');
$date = date('Y-m-d H:i:s');
    $sql="INSERT into user_profile(fname,mob_no,email,password,created_date) values ('$fname','$mobile_no','$email','$password','$date')";
$result = mysqli_query($conn, $sql);
$last_id= mysqli_insert_id($conn);
if($result) {
$sqll ="SELECT * FROM user_profile WHERE id = '".$last_id."'";
$resultt = mysqli_query($conn, $sqll) or die(mysqli_error($conn));
$ress= mysqli_fetch_array($resultt);
$name=$ress['fname'];
$email=$ress['email'];
$date = date("d-m-Y");
    $from_team = "Orange Groceries";
    $from_website = "https://orangegroceries.com/index.php";
    $to = $email;
    $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi $name,
                                    </span> 
                                    <br/>
                                    Welcome to <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $from_team</span>, Your Registration Completed , Shop With Exciting Offer With Orange Groceries <br/> Thankyou!!!
                                </p>
                                <br/><br/><br/><br/>
                                <div style='width: 100%; background-color: $footer_background_color; color: $footer_text_color; font-family: $footer_font_family; font-size: $footer_font_size; padding-top: 30px; padding-bottom: 30px;'>
                                    Thanks And Regards
                                    <br/>
                                    <span style='color: white;'>$from_website</span>
                                </div>
                            </div>
                        </center>
                    </body>
                </html>";


$email = new PHPMailer();
$email->Body      =  ($message);
$email->SetFrom('support@orangegroceries.com', 'Orange Groceries'); //Name is optional
$email->Subject   = $name . "Your Registration successfully Completed";
$email->IsHTML(true);
$email->Body      =  ($message);
$email->AddAddress($t);
   if (! $email->Send()) {
       //echo "<script>alert('Problem in sending email!');</script>";
    } else {
  echo '<script>alert("Registration successfully Completed")</script>'; 
  echo "<script>window.location.href='login.php'</script>";
    }

     }
}else{
    echo '<script>alert("Email Id Already Exits! Please Login")</script>';  
}
}
?>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content=" ">
    <meta name="author" content="">
    <title>Orange Groceries</title>
    <?php include("includes/css.php");?>
    <style>
        .form-logins .form-control {
            padding: 2px 10px;
            height: 35px;
            line-height: 22px;
        }

    </style>
</head>

<body style="background-color:#f9f9f9;">
    <?php include("includes/header.php");?>
    <section class="shop-list section-padding">
        <div class="container">
            <div class="row">
                <div class="col-md-2 hidden-xs"></div>
                <div class="col-md-8 col-sm-8 col-xs-12">
                    <div class="row loginsignbox">

                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <div class="mb-0">
                                <div class="row">
                                    <div class="col-md-12">
                                        <h2 class="text-center text-uppercase pt-5">Registration Form</h2>
                                    </div>
                                    <div class="signupbox-form form-logins pt-0" style="width:100%;">
                                        <form class="login-form" method="POST" action="">
                                            <div class="form-group">
                                                <div class="col-md-12 col-xs-12 mb-15">
                                                    <label style="font-size:15px;color:#000;">Enter Full Name</label>
                                                    <input type="text" name="fname" id="fname" class="form-control" placeholder="Enter Full Name" required="">
                                                </div>

                                                <div class="col-md-12 col-xs-12 mb-15">
                                                    <label style="font-size:15px;color:#000;">Enter Mobile No.</label>
                                                    <input type="tel" name="mobile_no" id="mobile_no" class="form-control" placeholder="Enter Contact No." required="">
                                                </div>
                                                <div class="col-md-12 col-xs-12 mb-15">
                                                    <label style="font-size:15px;color:#000;">Enter Email-Id</label>
                                                    <input type="email" name="email" id="email" class="form-control email-search" placeholder="Enter Email-Id" required="">
                                                    <div class="alert alert-warning" id="result2" style="display: none;"> </div>
                                                </div>
                                                <div class="col-md-12 col-xs-12 mb-15">
                                                    <label style="font-size:15px;color:#000;">Password</label>
                                                    <input type="password" onkeyup="checkPass()" id="chpassword" name="password" placeholder="Enter Password" class="form-control" required="">
                                                </div>
                                                <div class="col-md-12 col-xs-12 mb-15">
                                                    <label style="font-size:15px;color:#000;">Confirm Password</label>
                                                    <input type="password" onkeyup="checkPass()" id="cchpassword" name="cpassword" placeholder="Enter Confirm Password" class="form-control">
                                                    <span id="error-nwl"></span>
                                                </div>
                                                <div class="col-md-12 col-xs-12 mt-10 mb-15">
                                                    <div class="dloginhide hidden">
                                                        <div class="clearfix"></div>
                                                        <div class="product_details_box product-add-to-cart-btn">
                                                            <a style="width:100%; text-align:center; font-size:16px;padding:0px;">
                                                                <button type="submit" class="btn btn-lg btn-block inpt-control" name="register" style="border-radius: 40px;background-color:#ed1d24;color:#fff;font-weight:600;">Sign Up Here</button>
                                                            </a>
                                                        </div>

                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                        <div class="col-md-12">
                                            <h6 class="text-center text-black" style="margin-top:2px;">Already Account?<a href="https://orangegroceries.com/login.php" style="color:#000;"> <strong>Login Here</strong></a></h6>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <div class="loginbody_right">
                                <div class="text-center mb-20 mt-20">
                                    <img src="https://orangegroceries.com/img/logo.png" width="200px;" alt="">
                                </div>
                                <div class="lgoinleft_des mt-20">
                                    <div class="left_desimg"><img src="https://orangegroceries.com/img/login_watch.png" alt=""></div>
                                    <div class="left_descont">Manage your Order Easily Track Order, Hassle Free Return.</div>
                                </div>
                                <div class="lgoinleft_des" style="margin-top:30px">
                                    <div class="left_desimg"><img src="https://orangegroceries.com/img/track_icon.png" alt=""></div>
                                    <div class="left_descont">OG Express Delivery for Daily Needs Products.</div>
                                </div>
                                <div class="lgoinleft_des">
                                    <div class="left_desimg"><img style="height: 24px;width: 23px;" src="https://orangegroceries.com/img/my_wallet_logo.png" alt=""></div>
                                    <div class="left_descont">OG Wallet for making Payments and getting Cash Back.</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <?php include("includes/footer.php");?>
    <?php include("includes/js.php");?>

    <!-- <script>
 jQuery(function() {
            jQuery('#in1').fastLiveFilter('#f1');
        });

    </script> -->
</body>
<script type="text/javascript">
    function checkPass() {
        var pass1 = document.getElementById('chpassword');
        var pass2 = document.getElementById('cchpassword');
        var message = document.getElementById('error-nwl');
        var goodColor = "#66cc66";
        var badColor = "#ff6666";

        if (pass1.value.length > 5) {
            pass1.style.backgroundColor = goodColor;
            message.style.color = goodColor;
            message.innerHTML = "character number ok!"
        } else {
            pass1.style.backgroundColor = badColor;
            message.style.color = badColor;
            message.innerHTML = " you have to enter at least 6 digit!"
            return;
        }

        if (pass1.value == pass2.value) {
            pass2.style.backgroundColor = goodColor;
            message.style.color = goodColor;
            message.innerHTML = "Password Match!"
        } else {
            pass2.style.backgroundColor = badColor;
            message.style.color = badColor;
            message.innerHTML = " These passwords don't match"
        }
    }

    $(document).ready(function() {
        $(".email-search").keyup(function() {
            searchid = $(this).val();
            //alert(searchid);
            dataString = 'search2=' + searchid;
            if (searchid != '') {
                $.ajax({
                    type: "POST",
                    url: "reg_validation.php",
                    data: dataString,
                    cache: false,
                    success: function(html) {
                        $("#result2").html(html).show();
                    }
                });
            }
            return false;
        });
    });
    $(document).ready(function() {
        $(".email-login").keyup(function() {
            searchid = $(this).val();
            dataString = 'search=' + searchid;
            if (searchid != '') {
                $.ajax({
                    type: "POST",
                    url: "reg_validation.php",
                    data: dataString,
                    cache: false,
                    success: function(html) {
                        $("#result").html(html).show();
                    }
                });
            }
            return false;
        });
    });

</script>

</html>
