<?php include "header.php"; 
$banner_post = getALL('ktbannerset','','bn_id ASC');
?>

<div id="content" class="main-content">

	<div class="layout-px-spacing">
		<div class="row layout-top-spacing" id="cancel-row">
  
			<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing m-auto">
			
			<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 ">
				<h1 class="title-4">Home Banner</h1>
			</div>

			<div class="row">
				<div class="col-12 m-auto">
					
					<div class="widget-content widget-content-area br-6">	
						<div class="table-responsive mb-4 mt-4">
                                <table id="recordFetchex" class="table table-hover" style="width:100%">
                                    
									<thead>
                                            <tr>
                                                <th width="30%">Image</th>
                                                <th width="30%" class="text-center">Caption</th>
                                                <th width="20%" class="text-center">Action</th>
											</tr>
									</thead>
                                    <tbody>
									
											<?php
											$i = 0;
											if(!empty($banner_post))
											{
											foreach($banner_post as $cat)
												{
													$i++;
												$bl_id = $cat['bn_id'];
												$psc = ($cat['position'] > 0 ) ? 'bg-success' : 'bg-danger'; 
												$prd_img = (!empty($cat['bannername']) && file_exists('../kmart-banner/'.$cat['bannername'])) ? $cat['bannername'] : 'kmart-icon.png';
											?>
											<tr  class="tritem">
                                                <td>
													<img src="../kmart-banner/<?= $prd_img; ?>" alt="home page banner" class="img-fluid" width="20%"/>
												</td>
												
												<td>
													<h4 class="text-center"><?= (!empty($cat['maincap'])) ? $cat['maincap'] : '-'; ?></h4>
												</td>
                                                
												<td>
                                                    <div class="table-data-feature text-center">
                                                     
														<button class="bg-primary recedt text-white bs-tooltip border-0 btn rounded-circle" id="rec_<?= $bl_id; ?>"  title="Edit">
                                                            <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-refresh-ccw">
															<polyline points="1 4 1 10 7 10"></polyline><polyline points="23 20 23 14 17 14"></polyline><path d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15"></path></svg>
                                                        </button>
														
														<button class="<?= $psc; ?> recshw text-white bs-tooltip border-0 btn rounded-circle" id="rsc_<?= $bl_id; ?>"  title="Dispaly">
                                                           <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-toggle-right">
														   <rect x="1" y="5" width="22" height="14" rx="7" ry="7"></rect><circle cx="16" cy="12" r="3"></circle></svg>
                                                        </button>
                                                    </div>
                                                </td>
                                            </tr>
											<?php
												}
											}
											?>
                                        
                                    </tbody>
                                </table>
                            </div>
					</div>
				
				</div>	
			</div>
		
			</div>

		</div>

	</div>

</div>

<div class="modal fade" id="reviewPst_Modal" tabindex="-1" role="dialog" aria-labelledby="catModalLabel" aria-hidden="true"  data-backdrop="static">
    <div class="modal-dialog" role="document">
	<form method="post" id="crtsub_form"  enctype="multipart/form-data">
      
	  <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="ctsub">Banner Post</h5>
          <button class="close closecats" type="button" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
        <div class="modal-body" >
		
		<div class="form-group">
			<label class="text-dark font-weight-bold">Upload Image [Full Screen]<code>*</code></label>
			<input type="file"  name="pics_a"  id="pic_a" class="form-control" accept="image/jpeg, image/png, image/jpg" />
			<span id="img_error" class="error_here"></span>
		</div>
		
		<div class="form-group">
			<label class="text-dark font-weight-bold">Upload Image [Phone Screen]<code>*</code></label>
			<input type="file"  name="pics_ap"  id="pic_p" class="form-control" accept="image/jpeg, image/png, image/jpg" />
			<span id="img_error" class="error_here"></span>
		</div>
		
		<div class="form-group">
			<label class="text-dark font-weight-bold">Caption</label>
			<input type="text"  name="capbns" class="form-control" />
			<span class="error_here"></span>
		</div>
		
		<div class="form-group">
			<label class="text-dark font-weight-bold">Url <small>Leave Empty if No Link</small></label>
			<input type="text"  name="lnkbns" class="form-control" placeholder="Link to product or category page "/>
			<span class="error_here"></span>
		</div>
		
		</div>
		
		<input type="hidden" id="bana" name="valbana" value="" />
        <div class="modal-footer">
          <button class="btn btn-danger" type="button" data-dismiss="modal">Close/Cancel</button>
		  <button id="button_subbtn" name="button_subbtn"  type="submit" class="btn btn-secondary"> Save </button>
        </div>
      </div>
	  
	</form>
    </div>
</div>

<script type="text/javascript" language="javascript" >

$(document).ready(function(){

$(document).on('click', '.recedt', function(){ var id = this.id;   var split_id = id.split("_"); var postid = split_id[1];	$("#bana").val(postid); $("#reviewPst_Modal").modal("show"); });

$(document).on('click', '.recshw', function(){
		var id = this.id;    var split_id = id.split("_"); var postid = split_id[1];
		$.ajax({
		url: 'actions/bannersspost.php', type: 'POST', data:{ 'mkup_bannerstatus':1, 'urecm':postid }, dataType:"json",
		beforeSend: function() { $("#rsc_"+postid).attr('disabled', 'disabled'); },
		success: function(data){ donejob(data.runstt,data.errorreason);	$("#rsc_"+postid).attr('disabled', false); setTimeout( function(){ window.location.reload(); },4000); }
		});
});

$("#crtsub_form").on('submit',function(e) {
		e.preventDefault();	 
		$.ajax({ url: 'actions/bannersspost.php',type: 'POST',data:  new FormData(this),contentType: false,cache: false,processData:false,dataType:"json",
		beforeSend: function(){		$("#button_subbtn").html('saving <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-loader spin mr-2"><line x1="12" y1="2" x2="12" y2="6"></line><line x1="12" y1="18" x2="12" y2="22"></line><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line><line x1="2" y1="12" x2="6" y2="12"></line><line x1="18" y1="12" x2="22" y2="12"></line><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line></svg>');
		$("#button_subbtn").attr('disabled', 'disabled');},
		success: function(data)	{ donejob(data.runstt,data.errorreason); $("#button_subbtn").html('Save'); $("#button_subbtn").attr('disabled', false);
		if(data.runstt == "grant"){	$('#crtsub_form').trigger('reset');	$("#reviewPst_Modal").modal("hide"); setTimeout( function(){ window.location.reload(); },4000);		}
		else if(data.errorform != ""){ $("#pic_"+data.errorform).siblings("span").text(data.errorreason); } }
		});
    });	
})
</script>

<?php include "footer.php"; ?>