<?php include "header.php"; 

$reginsz = array('Greater Accra', 'Ashanti', 'Volta', 'Eastern', 'Western', 'Upper West', 'Upper East', 'Oti', 'Northern', 'Brong Ahafo', 'Central', 'Savannah', 'Bono East', 'Ahafo', 'Western North', 'North East');
?>

<style>
.tpntc{
	border:1px solid transparent;
}
.alert {
	position: relative;
	padding: .75rem 1.25rem;
	margin-bottom: 1rem;
	border: 1px solid transparent;
	-webkit-border-radius: 5px;
	-moz-border-radius: 5px;
	border-radius: 5px;
	padding: 0.9375rem;
	text-align: center;
	line-height: 2;
	font-size: 1.7rem;
}

.alert-error {
  border-right: 64px solid;
  color: #e7515a;
  background-color: #ffe1e2;
  border-color: #e7515a;
}

.alert-success {
	border-left: 64px solid;
	color: #212121;
	background-color: #ffca0536;
	border-color: #ffca05;
}

.alert-success::before {
    right: auto;
    left: 0;
    border-right: 0;
    border-left: 8px solid;
    border-left-color: inherit;
    content: '';
    display: inline-block;
    position: absolute;
    top: 50%;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    margin-top: -8px;
}

.alert-error::before {
	left: auto;
	right: 0;
	border-left: 0;
	border-right: 8px solid;
	border-right-color: inherit;
	content: '';
	display: inline-block;
	position: absolute;
	top: 50%;
	border-top: 8px solid transparent;
	border-bottom: 8px solid transparent;
	margin-top: -8px;
}

.alert-error svg,.alert-success svg{
	color: #fff;
	width: 4rem;
	right:-4rem;
	text-align: center;
	position: absolute;
	top: 50%;
	transform: translate(30%, -50%);
	vertical-align: middle;
	font-size: 1.25rem;
	font-weight: 400;
	line-height: 1;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}
.alert-success svg{
	left:-6.5rem;
}
</style>
	
	<div class="hero-section hero-background" style="background-image:url(img/bn3.jpg); height:230px;">
        <div class="container"><h1 class="pg-title text-left">CART</h1></div>
    </div>

	<div class="bcrumb">
    <div class="container">
        <nav class="biolife-nav nav-86px">
            <ul>
                <li class="nav-item"><a href="index" class="permal-link">Home</a></li>
                <li class="nav-item"><span class="current-page">Checkout Cart</span></li>
            </ul>
        </nav>
    </div>
	</div>

    <div class="page-contain checkout">

        <div id="main-content" class="main-content">
            <div class="container sm-margin-top-37px  xs-margin-bottom-80px">
			<?php
				if((!empty($chk_crt)) && (cart_stk("tot_crt") > 0)){
				?>
				
				<div class="tpntc" id="errors_here"></div>
				
				<form action="#" id="cchkregform" method="post">
                <div class="row">

                    <div class="col-lg-7 col-md-7 col-sm-6 col-xs-12">
                        <div class="checkout-progress-wrap width-100percent">
                            <div class="order-summary xs-margin-bottom-33px">
								<div class="title-block">
									<h3 class="title">Billing Details</h3>
								</div>
								<div class="login-on-checkout">
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_fname">First Name</label>
												<input type="text" name="fname" id="input_fname" value="" placeholder="Your first name">
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_lname">Last Name <font class="rd_cl">*</font></label>
												<input type="text" name="lname" id="input_lname" value="" placeholder="Your last name">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
										
										<div class="form-row">
											<label for="input_scrty">Country <font class="rd_cl">*</font></label>
											<input type="text" name="country" id="input_scrty" value="Ghana" placeholder="country" readonly />
											<span id="" class="error_here"></span>
										</div>
										
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_strt">Street Address <font class="rd_cl">*</font></label>
												<input type="text" name="street" id="input_strt" value="" placeholder="House number or Street Name">
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_aprt">Apartment, Suit or Unit (Optional)</label>
												<input type="text" name="optstreet" id="input_aprt" value="" placeholder="Apartment, suit, unit etc (optional)">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
										
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_rgn">Region <font class="rd_cl">*</font></label>
												<select name="region" id="input_rgn" placeholder="Region" required>
													<?php
														foreach($reginsz  as $dlm){  echo '<option>'.$dlm.'</option>'; }
													?>
												</select>
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_ctyst">State / City <font class="rd_cl">*</font></label>
												<input type="text" name="scity" id="input_ctyst" value="" placeholder="enter town or city name">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
										
										<div class="form-row">
											<label for="input_zipcd">Postal Code / Zip (Optional)</label>
											<input type="text" name="postal" id="input_zipcd" value="" placeholder="postal code / zip (optional)">
											<span id="" class="error_here"></span>
										</div>
										
										
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_email">Email Address <font class="rd_cl">*</font></label>
												<input type="email" name="semail" id="input_email" value="" placeholder="Your email">
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_phn">Phone <font class="rd_cl">*</font></label>
												<input type="text" name="sphone" id="input_phn" value="" placeholder="phone number">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
										
										
										
										<div class="row xs-margin-top-50px">
											<div class="col-md-6">
											<p class="form-row" for="input_smaddrs">
												<input type="radio" name="dlvadrs" class="drvdsp" id="input_smaddrs" value="same" checked />
												<label for="input_smaddrs">Delivery to <strong>Same Address</strong></label>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row" for="input_dffadds">
												<input type="radio" name="dlvadrs" class="drvdsp" value="another" id="input_dffadds" >
												<label for="input_dffadds">Delivery to <strong>Different Address</strong></label>
											</p>
											</div>
										</div>
								</div>
							
                            </div>
							
							<div class="order-summary sm-margin-bottom-80px" id="dffdlvy" style="display:none;">
								<div class="title-block">
									<h3 class="title">Delivery Details</h3>
								</div>
								<div class="login-on-checkout">
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_dfname">First Name</label>
												<input type="text" name="dfname" id="input_dfname" value="" placeholder="Your first name">
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_dlname">Last Name <font class="rd_cl">*</font></label>
												<input type="text" name="dlname" id="input_dlname" value="" placeholder="Your last name">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
										
										<div class="form-row">
											<label for="input_comp">Company (optional)</label>
											<input type="text" name="dcompany" id="input_comp" placeholder="company name">
											<span id="" class="error_here"></span>
										</div>
										
										<div class="form-row">
											<label for="input_dscrty">Country <font class="rd_cl">*</font></label>
											<input type="text" name="dcountry" id="input_dscrty" value="Ghana" placeholder="country" readonly />
											<span id="" class="error_here"></span>
										</div>
										
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_dstrt">Street Address <font class="rd_cl">*</font></label>
												<input type="text" name="dstreet" id="input_dstrt" value="" placeholder="House number or Street Name">
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_daprt">Apartment, Suit or Unit (Optional)</label>
												<input type="text" name="doptstreet" id="input_daprt" value="" placeholder="Apartment, suit, unit etc (optional)">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
										
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_drgn">Region <font class="rd_cl">*</font></label>
												<select name="dregion" id="input_drgn" placeholder="Region" required>
													<?php
														foreach($reginsz  as $dlm){  echo '<option>'.$dlm.'</option>'; }
													?>
												</select>
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_dctyst">State / City <font class="rd_cl">*</font></label>
												<input type="text" name="dscity" id="input_dctyst" value="" placeholder="enter town or city name">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
										
										<div class="form-row">
											<label for="input_dzipcd">Postal Code / Zip (Optional)</label>
											<input type="text" name="dpostal" id="input_szipcd" value="" placeholder="postal code / zip (optional)">
											<span id="" class="error_here"></span>
										</div>
										
										
										<div class="row">
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_demail">Email Address <font class="rd_cl">*</font></label>
												<input type="email" name="dsemail" id="input_semail" value="" placeholder="Your email">
												<span id="" class="error_here"></span>
											</p>
											</div>
											<div class="col-md-6">
											<p class="form-row">
												<label for="input_dphn">Phone <font class="rd_cl">*</font></label>
												<input type="text" name="dsphone" id="input_dphn" value="" placeholder="phone number">
												<span id="" class="error_here"></span>
											</p>
											</div>
										</div>
									</div>
							</div>
							
							<div class="order-summary sm-margin-bottom-80px">
								<div class="title-block">
									<h3 class="title">Order Note</h3>
								</div>
								<div class="login-on-checkout">
								<p class="form-row">
									<textarea name="ntpord" id="input_notez" placeholder="Having any specifications or request? ... Type it here"></textarea>
									<span id="" class="error_here"></span>
								</p>
								</div>
							</div>
							
                        </div>
                    </div>


                    <div class="col-lg-5 col-md-5 col-sm-6 col-xs-12 sm-margin-bottom-0 xs-margin-bottom-15px">
                        <div class="order-summary sm-margin-bottom-80px" style="position:sticky; top:0px;">
                            <div class="title-block">
                                <h3 class="title">Order Summary</h3>
                                <a href="cart" class="link-forward rd_cl"><b><i class="fa fa-edit"></i> Edit cart<b></a>
                            </div>
                            <div class="cart-list-box short-type">
                                <span class="number"><?= cart_stk("tot_crt"); ?> item<?= (cart_stk("tot_crt") > 1) ? 's' : ''; ?></span>
                                <ul class="cart-list">
								<?php
									$mainsubt = 0; $cv = 0;
									foreach($chk_crt as $dcv){
										$fdprp = $dcv['pqrcode'];
										
										$gt_prds = gtOne("kmartstockprds","  pqrcode = '$fdprp' ",'ksp_id');
										if(!empty($gt_prds)){
											$cv ++;
										$chk_prdz = $db_con->prepare("SELECT * FROM kmartstockprds WHERE ksp_id = '$gt_prds' ");
										$chk_prdz->execute(); $pdz = $chk_prdz->fetch();	
										
										$chkct = getOne("my_cart"," pqrcode = '$pdz[pqrcode]' AND session_rec = '$set_sess' ","qty");
										
										$gtctnm = gtOne("ktmmenu_name"," mn_id = $pdz[mn_id] ","mname");
										
										$gt_imgs = gtOne("kprdw_imgs"," prd_rec = '$pdz[pqrcode]' ORDER BY kmg_id ASC","pjm_pic");
										
										$chk_mgi = $gt_imgs;     $chk_sl = $pdz['psell'];    $chk_ds = $pdz['pdiscount'];
										if($dcv['prd_attr'] == 'promo'){
										//FROM GENERAL FEATURED SPECIAL PROMO
										$chk_ftp = $db_con->prepare("SELECT * FROM kmt_ft_prds WHERE ksp_id = '$pdz[ksp_id]'  AND delete_status = 0");
										$chk_ftp->execute(); $fpd = $chk_ftp->fetch();
										
										$chk_mgi = (!empty($fpd) && !empty($fpd['prd_img'])) ?  $fpd['prd_img'] : $gt_imgs;
										$chk_sl = (!empty($fpd) && !empty($fpd['km_sell'])) ? $fpd['km_sell'] : $pdz['psell'];
										$chk_ds = (!empty($fpd) && !empty($fpd['km_discount'])) ? $fpd['km_discount'] : $pdz['pdiscount'];
										}
										
										$prd_img = (!empty($chk_mgi) && file_exists('prdimgs/'.$chk_mgi)) ? "prdimgs/".$chk_mgi : 'img/kmart-icon.png';
										
										$shw_pec = calcprcs($chk_sl,$chk_ds,'spc');
										$shw_ds = calcprcs($chk_sl,$chk_ds,'ssl');
										$shw_dsc = calcprcs($chk_sl,$chk_ds,'sds');
										
										
										$imdsubt = ($shw_ds*$chkct);
										$mainsubt += $imdsubt;
									?>
                                    <li class="cart-elem">
                                        <div class="cart-item">
                                            <div class="product-thumb">
                                                <a class="prd-thumb" href="product?kmt=<?= $pdz['purl']; ?>" target="_blank">
                                                    <figure><img src="<?= $prd_img; ?>" width="113" height="113" alt="item image" ></figure>
                                                </a>
                                            </div>
                                            <div class="info">
                                                <span class="txt-quantity"><?= (!empty($chkct)) ? $chkct : 1; ?>X</span>
                                                <a href="product?kmt=<?= $pdz['purl']; ?>" target="_blank" class="pr-name"><?= $pdz['pname'] ?></a>
                                            </div>
                                            <div class="price price-contain">
                                                <ins><span class="price-amount"><span class="currencySymbol">GH₵</span><b class="mprc"><?= $imdsubt; ?></b></span></ins>
                                            </div>
                                        </div>
                                    </li>
									<?php
										}
									}
									?>
                                </ul>
                                <ul class="subtotal">
                                    <li>
                                        <div class="subtotal-line">
                                            <b class="stt-name">total:</b>
                                            <span class="stt-price">GH₵<b><?= $mainsubt; ?></b></span>
                                        </div>
                                    </li>
                                </ul>
                            </div>
							
							<div class="login-on-checkout">
								<p class="form-row xs-margin-top-45px">
									<button type="submit" name="btn-sbmt" id="tkstsubm" class="btn width-100percent">Place Order</button>
								</p>
							</div>
							
                        </div>
						
						<div id="shwerr"> </div>
					
                    </div>

                </div>
				</form>
				
	  
<script src="log_reg/js/jquery-3.1.1.min.js"></script>
<script src="log_reg/js/popper.min.js"></script>
<script src="log_reg/js/bootstrap.min.js"></script>

<script type="text/javascript">
$('document').ready(function(){
	
	$(document).on('change','.drvdsp',function(){var _thisnp = $(this).val(); if(_thisnp == "another"){ $("#dffdlvy").show(); }else{ $("#dffdlvy").hide(); } });
	
	var nameregex = /^[a-zA-Z- ]+$/; $.validator.addMethod("validname", function( value, element ) { return this.optional( element ) || nameregex.test( value ); });
	var numregex = /^([0-9])+$/; $.validator.addMethod("validnum", function( value, element ) { return this.optional( element ) || numregex.test( value ); }); 
	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 ); }); 
	$("#cchkregform").validate({
	rules: {fname:{required:true,validname:true},lname:{required:true,validname:true},country:{required:true,validname:true}, street:{required:true},region:{required:true},
	dscity:{required:true},semail:{required:true,validemail:true},sphone:{required:true,validnum:true}, dfname:{required:true,validname:true},dlname:{required:true,validname:true},dregion:{required:true},
	dsphone:{required:true,validnum:true},dsemail:{required:true,validemail:true},scity:{required:true},dcountry:{required:true,validname:true},dstreet:{required:true}
	},
	messages: { fname:{required:"Required",validname: "Check characters"}, lname:{required:"Required",validname: "Check characters"}, country:{required:"Required",validname: "Check characters"}, 
	street:{required:"Required"}, region:{required:"Required"}, scity:{required:"Required"},semail:{required:"Required",validemail: "Check characters"},dcountry:{required:"Required",validname: "Check characters"},
	dsphone:{required:"Required",validnum: "Numbers Only"},dsemail:{required:"Required",validemail: "Check characters"},dscity:{required:"Required"},dstreet:{required:"Required"},
	sphone:{required:"Required",validnum: "Numbers Only"},dfname:{required:"Required",validname: "Check characters"}, dlname:{required:"Required",validname: "Check characters"},dregion:{required:"Required"}
	},
	errorPlacement : function(error, element) { $(element).closest('.form-row').find('.error_here').html(error.html()); },
	highlight : function(element) { $(element).closest('.form-row').removeClass('has-success').addClass('has-error'); },
	unhighlight: function(element, errorClass, validClass) {
	$(element).closest('.form-row').removeClass('has-error').addClass('has-success');
	$(element).closest('.form-row').find('.error_here').html(''); },
	submitHandler: submitForm
	}); 
	function submitForm(){
	var data = $("#cchkregform").serialize(); 	$.ajax({
	type : 'POST',url  : 'actions/proccheckout.php', data : data,
	beforeSend: function(){	$('#errors_here, #shwerr').html(''); $('#tkstsubm').attr('disabled', 'disabled'); $('#tkstsubm').html('Processing order <i class="fa fa-spinner fa-spin"></i>'); },
	dataType:"json", success :  function(data){
		
	if(data.mkresult != "done"){ $('#errors_here, #shwerr').html(data.runsttinfo); $('#tkstsubm').attr('disabled', false); $('#tkstsubm').html('Place Order'); }
	
	else{ $('#errors_here').html(data.runsttinfo); $("#cchkregform").trigger('reset'); $("#cchkregform").html(''); setTimeout( window.location.href = data.direct ,50000);   }
	
	}  }); return false;  }
});
</script>


	
				<?php
				}else{
		if(isset($_GET['preg']) && isset($_GET['order']) && isset($_GET['ordered'])){
			?>
	<div class="alert alert-success">
		<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-alert-triangle"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12" y2="17"></line></svg>
		<strong>Success!</strong> Order Placed Successful, Will Be Processed.
	</div>
			<?php
		}
		else{
					?>
				<div class="row">
					<div class="col-md-8 float-none mx-auto">
					<div class="content-404 w-100" style="padding-top: 0;margin-top: -25px;">
						<h1 class="heading"><i class="fa fa-shopping-cart"></i></h1>
						<h2 class="title">Oops! Empty Cart</h2>
						<p>Make Selection of Some Items fromOur Shop</p>
						<a class="button" href="shop">Go To Shop</a>
					</div>
					</div>
				</div>
					<?php
		}
				}
				?>
            </div>
        </div>
    </div>
<?php include "footer.php"; ?>
<script type="text/javascript" language="javascript"> $(document).ready(function(){ $("#minicrt").find(".cart-content").hide(); }) </script>

<script src="log_reg/js/validation.min.js" type="text/javascript"></script>
<script src="log_reg/js/jquery.validate.min.js"></script>
