<?php include "header.php"; 
$ftch_post = getALL('kmt_featuresd','','id ASC');


$dsct_post = getOne('pgs_settings'," st_rec = 'gndiscount' ",'st_value');
?>

<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">Featured Post</h1>
				
				<div class="btn-toolbar mb-2 mb-md-0">
					<div class="btn-group mr-2">
						<a href="javascript:void(0);" data-toggle="modal" data-target="#mkbnna_Modal" class="btn btn-icon bg-warning text-white">
						<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-percent"><line x1="19" y1="5" x2="5" y2="19"></line><circle cx="6.5" cy="6.5" r="2.5"></circle><circle cx="17.5" cy="17.5" r="2.5"></circle></svg>
						&nbsp; General Discount </a>
					</div>
				</div>
			</div>
<?php
if($setup == "edit"){
	?>
	<form class="text-left" method="post" action="" id="mksikkaprds_form" autocomplete="" enctype="multipart/form-data">
		<div class="row">
			<div class="col-md-6 mx-auto">
				<div class="widget-content widget-content-area bg-light br-6 mb-3">	
					<h5 class="mb-4 font-weight-bold text-warning">Product Info</h5>
					<div>
						<div class="row">
							<div class="col-md-4 form-group">
								<label class="text-dark font-weight-bold">Image Set</label>
								<select name="pcgrw" class="form-control" >
									<option value="maintain">Maintain Image</option>
									<option value="clear">Clear Image</option>
								</select>
								<span id="" class="error_here"></span>
							</div>
							
							<div class="col-md-8 form-group">
								<label class="text-dark font-weight-bold">Stand Out Photo</label>
								<input type="file" name="pics_a" class="form-control" />
								<span id="" class="error_here"></span>
							</div>
							
							
							<input type="hidden" value="<?= $prd; ?>" name="post_info" />
						</div>
						<div class="row mb-3">
						
							<div class="col-md-6">
								<label class="text-dark font-weight-bold">Selling Price <code>*</code> </label>
								<div class="input-group">
									<div class="input-group-prepend">
										<div class="input-group-text font-weight-bold">
										<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-activity text-primary"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline></svg>
										</div>
									</div>
									<input type="text" class="form-control" name="jewsell"  placeholder="0.00" value="<?= (!empty($prd_ft)) ? $prd_ft['psell']:''; ?>"/>
									
								</div>
							</div>
							
							<div class="col-md-6">
								<label class="text-dark font-weight-bold">Discount Price </label>
								<div class="input-group">
									<div class="input-group-prepend">
										<div class="input-group-text font-weight-bold">
										<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-percent text-danger"><line x1="19" y1="5" x2="5" y2="19"></line><circle cx="6.5" cy="6.5" r="2.5"></circle><circle cx="17.5" cy="17.5" r="2.5"></circle></svg>
										</div>
									</div>
									<input type="text" class="form-control" name="jecdiscount"  placeholder="0.00" value="<?= (!empty($prd_ft)) ? $prd_ft['pdiscount']:'0.00'; ?>"/>
									
								</div>
							</div>
						</div>
						
						<div class="form-group w-100 text-center mt-5 ">
							<button class="btn bg-warning text-white rounded w-75 font-weight-bold" id="mksubion" type="submit"><i class="far fa-paper-plane"></i> Submit</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
	<script>
	$("#mksikkaprds_form").on('submit',function(e) {
		e.preventDefault();
		var rev = $('#mksikkaprds_form');
			$.ajax({
				url: 'actions/pageftchr.php', type: 'POST', data:  new FormData(this), contentType: false, cache: false, processData:false, dataType:"json",
				beforeSend: function() { $("#mksubion").html('submiting <span class="spinner-grow-sm text-white ml-2 align-self-center loader-sm"></span>'); $("#mksubion").attr('disabled', 'disabled'); },
				success: function(data){
					donejob(data.runstt,data.errorreason); $("#mksubion").html('<i class="far fa-paper-plane"></i> Submit'); $("#mksubion").attr('disabled', false);
				}
			});
    });
	</script>
	<?php
}
else{
?>
<div class="row">
	<div class="col-md-8 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%">Item</th>
									<th width="20%" class="text-center">Action</th>
								</tr>
						</thead>
						<tbody>
						
								<?php
								$i = 0;
								if(!empty($ftch_post))
								{
									foreach($ftch_post as $cat)
									{
										
										if($cat['rec_nm'] == "hometab"){
											$chk_nm = getOne("ktmmenu_name"," mn_id = '$cat[rec_id]' ","mname");
											$ctnam = "Home Category Tab";
										}
										elseif($cat['rec_nm'] == "prodtab"){
											$chk_nm = getOne("kmartstockprds"," ksp_id = '$cat[rec_id]' ","pname");
											$ctnam = "Product Home Tab";
										}
										elseif($cat['rec_nm'] == "categoryshop"){
											$chk_nm = getOne("kmartstockprds"," ksp_id = '$cat[rec_id]' ","pname");
											$chk_ctid = getOne("kmartstockprds"," ksp_id = '$cat[rec_id]' ","mn_id");
											$chk_ctnm = getOne("ktmmenu_name"," mn_id = '$chk_ctid' ","mname");
											$ctnam = "Category <b>".$chk_ctnm."</b> Page";
										}
										elseif($cat['rec_nm'] == "featuredshop"){
											$chk_nm = getOne("kmartstockprds"," ksp_id = '$cat[rec_id]' ","pname");
											$ctnam = "Shop Featured";
										}
										elseif($cat['rec_nm'] == "homepromo"){
											$chk_nm = getOne("kmartstockprds"," ksp_id = '$cat[rec_id]' ","pname");
											$ctnam = "Promo Feature";
										}
										
								?>
								<tr  class="tritem">
									<td>													
										<div class="smlinf">
											<div class="prdinfo">
												<div class="image d-flex align-item-center">
													<a href="javascript:void(0);" target="t_blank">
														<img src="../img/kmart-icon.png" alt="logo" class="img-fluid" />
													</a>
												</div>
												
												<div class="content py-0">
													<h5 class="name">
														<a href="<?= ($cat['rec_nm'] == "homepromo") ? '?setup=edit&prd='.$cat['id'] : 'javascript:void(0);' ; ?>" class="<?= ($cat['rec_nm'] == "homepromo") ? 'text-primary' : 'text-dark'; ?> font-weight-bold" ><?= $chk_nm; ?></a>
													</h5>
													<span class="email text-dark font-weight-bold"><?= $ctnam; ?></span>
												</div>
											</div>
										</div>
									</td>
									
									<td>
										<div class="table-data-feature text-center">
											<button class="bg-danger text-white bs-tooltip border-0 btn rounded-circle" id="del_<?= $cat['id']; ?>" onClick="takeoff(<?= $cat['id']; ?>,'kmt_featuresd')"  title="Delete">
												<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-trash-2">
												<polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line>
												</svg>
											</button>
										</div>
									</td>
								</tr>
								<?php
									}
								}
								?>
							
						</tbody>
					</table>
				</div>
		</div>
	
	</div>	
</div>
<?php
}
?>
			</div>

		</div>

	</div>

</div>


<div class="modal fade" id="mkbnna_Modal" tabindex="-1" role="dialog" aria-labelledby="catModalLabel" aria-hidden="true"  data-backdrop="static">
    <div class="modal-dialog" role="document">
	<form method="post" id="updpost_form" role="form">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title">Set General Discount</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">Discount Pecentage<code>*</code></label>
			<input type="number" id="dsctptg" name="dsctptg" value="<?= $dsct_post; ?>" class="form-control" required min="0" max="100" />
			<span id="img_error" class="error_here"></span>
		</div>
		
				
		</div>
        <div class="modal-footer">
		  <button id="create_bna" name="button_action"  type="submit" class="btn btn-primary"> Update </button>
        </div>
      </div>
	  
	  </form>
	  
    </div>
  </div>
  
<script>
	$("#updpost_form").on('submit',function(e) {
		e.preventDefault(); var stpi = $("#dsctptg").val();
			$.ajax({
				url: 'actions/pageftchr.php', type: 'POST', data: {'addgenDiscount':1, 'inpam':stpi}, dataType:"json",
				beforeSend: function() { $("#create_bna").html('submiting <span class="spinner-grow-sm text-white ml-2 align-self-center loader-sm"></span>'); $("#create_bna").attr('disabled', 'disabled'); },
				success: function(data){
					donejob(data.runstt,data.errorreason); $("#create_bna").html('Update'); $("#create_bna").attr('disabled', false);
				}
			});
    });
	</script>

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