<?php
function getUserIP()
{
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }
    return $ip;
}
 $user_ip = getUserIP();
 
if(isset($_POST["submit"]))
{
include('includedbs/db_config.php');

	//$product_cat=$_POST["product_cat"];
	$name=$_POST["name"];
	$phone=$_POST["phone"];
	$state=$_POST["state"];
	//$email=$_POST["email"];
	$address=$_POST["address"];
    date_default_timezone_set('Asia/Kolkata');
	$date1=date('Y-m-d H:i:s');
	$date2=date('Y-m-d');
	$duplicate="0";
	$duplicate2="1";
	$source="HindiNov24Testo";
	$product_id=8;
	
include('includedbs/db_config.php');
date_default_timezone_set('Asia/Kolkata');
$date3=date('Y-m-d');
$date7=date('Y-m-d', strtotime($date. ' - 2 days'));

// $emails = substr($mail, 0, strpos($mail, '@'));
	/*------------------------------------------------------------Filter Data-------------------------------------------------------------*/

	$result = mysqli_query($CONN,"select count(*) as counts from filterabouse where abusing_words LIKE '%$name%' OR abusing_words LIKE '%$phone%' OR abusing_words LIKE '%$address%' OR abusing_words LIKE '%$user_ip%' ");
	$row = mysqli_fetch_array($result);
	$total = $row[0];
	// echo "Total rows: " . $total;
	// exit();
	if($total>=1){
		echo "<script>alert('sorry this name is not exists ')</script>";
		echo "<script>window.open('https://sheopals.in/hin-nov-24-t/','_self')</script>";
	    exit();	
	}
	/*------------------------------------------------------------Filter Data-------------------------------------------------------------*/

    include('includedbs/db_config.php');

        $queryget="SELECT * FROM enquiry e WHERE e.en_mobile='$phone' AND e.date_recieved BETWEEN '$date7 00:00:00' AND '$date3 23:59:59'";     // Mobile number filter
       //$queryget1="SELECT * FROM enquiry e WHERE e.ip='$user_ip' AND e.date_recieved BETWEEN '$date7 00:00:00' AND '$date3 23:59:59'";         // IP number filter
       //$queryget2="SELECT * FROM enquiry e WHERE e.en_name='$name' AND e.date_recieved BETWEEN '$date7 00:00:00' AND '$date3 23:59:59'";       // Name number filter
       //$queryget3="SELECT * FROM enquiry e WHERE e.en_address='$address' AND e.date_recieved BETWEEN '$date7 00:00:00' AND '$date3 23:59:59'"; // Address number filter

       $result = mysqli_query($CONN, $queryget) or die("error in insert");
       //$result1 = mysqli_query($CONN, $queryget1) or die("error in insert");
      //$result2 = mysqli_query($CONN, $queryget2) or die("error in insert");
      //$result3 = mysqli_query($CONN, $queryget3) or die("error in insert");
       
       $rows=mysqli_num_rows($result);
       //$rows1=mysqli_num_rows($result1);
       //$rows2=mysqli_num_rows($result2);
       //$rows3=mysqli_num_rows($result3);
    if($rows==0 && strlen($phone)=='10'){
        $QUERY="insert into enquiry(product_id,en_name,en_mobile,en_address,en_state,duplicate,ip,source,source2) VALUES('$product_id','$name','$phone','$address','$state','$duplicate','$user_ip','$source','$source')";
        include('includedbs/db_config.php');
        $RES = mysqli_query($CONN, $QUERY) or die("error in insert3");
        mysqli_close($CONN);
        $fname=ucfirst($name);
        echo"<script>window.open('thank-you.php?name=$fname','_self');</script>";
    }
    else{
		echo "<script>window.open('https://sheopals.in/hin-nov-24-t/','_self')</script>";
    }
}
?>