<?php 
include('common/header.php');

if (isset($_SESSION['temp_user_cey']) && isset($_SESSION['guest_user_cey'])) {
  $user_id = htmlspecialchars(strip_tags(trim($_SESSION['temp_user_cey'])), ENT_QUOTES, 'UTF-8');
  $whr = 'tmp_id';

  if(empty($user_id)) {
    $redirectUrl = "my-cart.php";
    echo "<script type=\"text/javascript\">";
    echo "window.location.href = '$redirectUrl'";
    echo "</script>";

  } else {
    $sqlt = mysqli_query($conn, "SELECT * FROM live_cart WHERE tmp_id=$user_id"); //  AND User_ID='tmp_".$user_id."'
    if(mysqli_num_rows($sqlt) > 0) {
      $row_inv = mysqli_fetch_assoc($sqlt);
      $g_inv = $row_inv['inv_id'];
      $sql_up = mysqli_query($conn, "UPDATE live_cart SET User_ID='G$g_inv', inv_id='$g_inv' WHERE tmp_id=$user_id");
    }
  }
  
  $sql = mysqli_query($conn, "SELECT id FROM live_cart WHERE $whr=$user_id");
  if(mysqli_num_rows($sql) == 0) {
    $redirectUrl = "my-cart.php";
    echo "<script type=\"text/javascript\">";
    echo "window.location.href = '$redirectUrl'";
    echo "</script>";
  }

} else {
  if (!isset($_SESSION['normal_user_cey']) || empty($_SESSION['normal_user_cey'])) {
    $redirectUrl = "sign-in.php";
    echo "<script type=\"text/javascript\">";
    echo "window.location.href = '$redirectUrl'";
    echo "</script>";

  } else {
    $user_id = htmlspecialchars(strip_tags(trim($_SESSION['normal_user_cey'])), ENT_QUOTES, 'UTF-8');
    $whr = 'User_ID';
  }
}

?>

<!-- Header Wrap Ends -->

<?php include "common/navbar.php"; ?> 

<!-- Main Container Starts -->
<div class="main-container" >
  <!-- Product Container Starts -->
  <div id="product-product" class="container" style="background-image: url(image/bg.jpg); ">
    <!-- Row Starts -->  
    <div class="row col-sm-12">

      <!-- Content Area Starts -->
      <div id="content" class="login">

       <h3 class="page-heading-1">RECIPIENT INFORMATION</h3>

       <form class="mt-4" id="chk_form" method="post" action="javascript:void(0);">
        <div class="row">
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">First Name<font color="#FF3300">*</font></label>
            <input type="text" class="form-control clr" id="fname" name="fname" placeholder="First Name" required autocomplete="off"><span class="help-block"></span>
          </div>
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">Last Name<font color="#FF3300">*</font></label>
            <input type="text" class="form-control clr" id="lname" name="lname" placeholder="Last Name" required autocomplete="off"><span class="help-block"></span>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">Contact No<font color="#FF3300">*</font></label>
            <input type="text" class="form-control clr" id="tel_no" name="tel_no" maxlength=10 placeholder="Contact No" required autocomplete="off"><span class="help-block"></span>
          </div>
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">Email Address<font color="#FF3300">*</font></label>
            <input type="email" class="form-control clr" id="email" name="email" placeholder="Email Address" required autocomplete="off"><span class="help-block"></span>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">Address Line1<font color="#FF3300">*</font></label>
            <input type="text" class="form-control clr" id="address_1" name="address_1" placeholder="Address Line1" required autocomplete="off"><span class="help-block"></span>
          </div>
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">Address Line2</label>
            <input type="text" class="form-control clr" id="address_2" name="address_2" placeholder="Address Line2" autocomplete="off"><span class="help-block"></span>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">City<font color="#FF3300">*</font></label>
            <input type="text" class="form-control clr" id="city" name="city" placeholder="City" required autocomplete="off"><span class="help-block"></span>
          </div>
          <div class="form-group col-lg-6 mb-3">
            <label class="mb-1">Postcode / ZIP</label>
            <input type="text" class="form-control clr" id="postal_code" name="postal_code" placeholder="Postcode / ZIP" autocomplete="off"><span class="help-block"></span>
          </div>
        </div>
       <!--  <div class="row mt-4">
          <div class="form-group col-lg-4">
            <div class="custom-control custom-checkbox">
              <input type="checkbox" class="custom-control-input" id="vatRegChk" name="vatRegChk" value="1">
              <label class="custom-control-label" for="vatRegChk"> &nbsp;VAT Registered</label>
            </div>
            <input type="text" class="form-control clr" id="vat_reg_no" name="vat_reg_no" placeholder="VAT Registered No" autocomplete="off" style="display:none"><span class="help-block"></span>
          </div>
        </div> -->
        <hr>

        <div class="row pt-3">
          <div class="col-lg-12">
            <div class="alert alert-primary" role="alert">
              Special Messages
            </div>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-12 mb-3">
            <label class="mb-1 text-info">Special Instructions: (Optional)</label>
            <input type="text" class="form-control clr" id="s_msg" name="s_msg" placeholder="" autocomplete="off" maxlength="250">
            <i>* Please make your special instructions short and clear.</i> <b>Example: 'Call the recipient before the delivery.'</b>
          </div>
        </div>
        <hr>
        <div id="errorDiv"></div>

        <div class="form-group py-3 m-0">
          <a href="my-cart" class="btn btn-inverse">EDIT CART</a>
          <input type="submit" class="btn btn-inverse" value="NEXT" id="btn_chk" name="btn_checkout" style="float:right">
        </div>
      </form>


    </div>

  </div>
  <!-- Content Area Ends -->    

</div>
<!-- Row Ends -->  
</div>
<!-- Product Container Ends -->

</div>
<!-- Main Container Ends -->
<!-- Footer Starts -->
<?php include "common/footer.php"; ?> 

<!-- Footer Ends -->
<script type="text/javascript">
  $(document).ready(function () {
  // valid email pattern
  var eregex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  $.validator.addMethod("validemail", function (value, element) {
    return this.optional(element) || eregex.test(value);
  });
  
  // contact no validation
  var telregex = /^\d{10}$/;
  $.validator.addMethod("validtel", function (value, element) {
    return this.optional(element) || telregex.test(value);
  }); 
  
  // JavaScript Validation For Checkout Form 
  $("#chk_form").validate({
    rules: {
      email: {
        validemail: true
      },
      tel_no: {
        validtel: true,
      }
    },
    messages: {
      email: {
        validemail: "Please Enter Valid Email Address"
      },
      tel_no: {
        validtel: "Invalid Contact Number"
      }
    },
    errorPlacement: function (error, element) {
      $(element).closest('.form-group').find('.help-block').html(error.html());
    },
    highlight: function (element) {
      $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
    },
    unhighlight: function (element, errorClass, validClass) {
      $(element).closest('.form-group').removeClass('has-error');
      $(element).closest('.form-group').find('.help-block').html('');
    },
    submitHandler: submitForm
  });

  function submitForm() {
    $("#pre_loader").show();

    $.ajax({
      type: 'POST',
      async: false,
      url: 'connection/checkout_conn.php',
      data: $('#chk_form').serialize(),
      dataType: 'json',
      success: function (data) {
        $('input[name=btn_chk]').prop('disabled', true);
        $('input[type=text],input[type=select],input[type=email]').prop('disabled', true);
        setTimeout(function () {
          if (data.status === '1') {
            window.location.href = 'order-summary.php';

          } else if (data.status === '3') {
            alert('Session Expired. Please Try Again!');
            window.location.href = 'sign-in.php';

          } else {
            $("#pre_loader").hide();
            $('#errorDiv').slideDown(200, function () {
              $('#errorDiv').html('<div class="alert alert-danger">' + data.message + '</div>');
              $('#errorDiv').delay(5000).slideUp(100);
              $('input[type=text],input[type=select],input[type=email]').prop('disabled', false);
              $('input[name=btn_chk]').prop('disabled', false);
            });
          }
        }, 1000);
      },
      error: function () {
        $("#pre_loader").hide();
        $('#errorDiv').slideDown(200, function () {
          $('#errorDiv').html('<div class="alert alert-danger">An unknown error occoured, Please try again Later...!</div>');
          $('#errorDiv').delay(5000).slideUp(100);
          $('input[type=text],input[type=select],input[type=email]').prop('disabled', false);
          $('input[name=btn_chk]').prop('disabled', false);
        });
      }
    });
    return false;
  }

  $.post("connection/checkout_conn.php", {'get_chkout_details': "data"}, function( data ) {
    if(data === '') {
      $(".clr").val('');

    } else {
      $("#fname").val(data.f_name);
      $("#lname").val(data.l_name);
      $("#tel_no").val(data.tel_no);
      $("#address_1").val(data.address_1);
      $("#address_2").val(data.address_2);
      $("#city").val(data.city);
      $("#postal_code").val(data.postal_code);
      $("#email").val(data.email);
      $("#s_msg").val(data.special_msg);
      // $("#vat_reg_no").val(data.VAT_No);
      
      // var vatReg = data.vat_reg;
      // if(vatReg == 1) {
      //   $('#vatRegChk').prop('checked',true);
      //   $("#vat_reg_no").show();
      //   $('#vat_reg_no').prop('required',true);

      // } else {
      //   $('#vatRegChk').prop('checked',false);
      //   $("#vat_reg_no").hide();
      //   $('#vat_reg_no').prop('required',false);
      //   $('#vat_reg_no').val('');
      // }
    }

  }, "json");
});

  // $("input[name='vatRegChk']").on('change', function() {
  //   var val = $("input[name='vatRegChk']:checked").val();

  //   if(val === '1') {
  //     $("#vat_reg_no").show();
  //     $('#vat_reg_no').prop('required',true);

  //   } else {
  //     $("#vat_reg_no").hide();
  //     $('#vat_reg_no').prop('required',false);
  //     $('#vat_reg_no').val('');
  //   }
  // });

</script>

</body>
<!-- Mirrored from sainathchillapuram.com/tf/opencart/blackoc/index.php?route=product/product&manufacturer_id=8&product_id=44&sort=pd.name&order=ASC&limit=50 by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 06 Oct 2021 07:22:13 GMT -->
</html> 
