<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
get_pagesecurity('14','views','R');    
$_SESSION['cuPages']='pro_productlist.php';   
$cuPage='pro_productlist.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
$mhead='product';
$menuh='Product Process';
$phead='prolist';
$page='Product List';
$dtnow = date("Y-m-d h:i:s", time());
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>
<?php 
if(isset($_POST['delitm'])){
$id=$_POST['delitm'];
if(delete_check('tbl_proinvde','itemid',$id)>0 || delete_check('tbl_traproduct','pid',$id)>0){
save_msg('w','Product Depend On Other Table!!!');
echo "<script>window.location='pro_productlist.php'</script>";
return;    
}
$name= get_fild_data('tbl_item',$id,'name');
$sql="DELETE FROM tbl_item WHERE id='$id'";
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
$efid=mysqli_affected_rows($con);     
if($efid>0){
$act =remove_junk(escape('Product name: '.$name));    
write_activity($aid,'ITM','Product has been deleted',$act);        
save_msg('s','Product Successfully Deleted!!!');
}else{
save_msg('w','Product Fail to Delete!!!');    
}    
echo "<script>window.location='pro_productlist.php'</script>";
}
?>
<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
    
<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Product List</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>    
<div class="col-md-12 table-responsive">
<table class="table table-bordered table-striped" id="datarec">
<thead>
<tr>
<th style="width:40px;">SN</th>   
<th>Code</th>
<th>Name</th>
<th>Parent</th>
<th>Category</th>    
<th>Sub-Category</th>
<th>Brand</th>    
<th style="width:40px; text-align:center;">Action</th>    
</tr>
</thead>    
<tbody>
<?php
$sql="SELECT * FROM tbl_item ORDER BY name ASC";    
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($row=mysqli_fetch_array($query)){
$id=$row['id'];
$name = $row['name'];   
?>
<tr>
<td class="center"><?php echo count_id();?></td>
<td><?php echo $row['code'];?></td>
<td><b class="prodetail" id="PI_<?php echo $row['id'];?>" style="cursor: pointer;"><?php echo $name;?></b></td>    
<td><?php if($row['prid']!=''){echo get_fild_data('tbl_parent',$row['prid'],'name');}?></td>
<td><?php if($row['catid']!=''){echo get_fild_data('tbl_category',$row['catid'],'name');}?></td>
<td><?php if($row['scatid']!=''){echo get_fild_data('tbl_subcat',$row['scatid'],'name');}?></td>
<td><?php if($row['brid']!=''){echo get_fild_data('tbl_brand',$row['brid'],'name');}?></td>     
<td nowrap="">
<a class="btn btn-flat bg-purple" href="#" onclick="edit_item('ED_<?php echo $row['id'];?>')"><i class="fa fa-edit"></i>
</a> <a class="btn btn-flat bg-purple" href="#" onclick="remove_item('DL_<?php echo $row['id'];?>')"><i class="fa fa-trash"></i></a>
<form action="pro_productlist.php" id="DL_<?php echo $row['id'];?>" method="post" >
<input type="hidden" name="delitm" value="<?php echo $row['id']; ?>" />
</form>
<form action="pro_productedit.php" id="ED_<?php echo $row['id'];?>" method="post" >
<input type="hidden" name="edititm" value="<?php echo $row['id']; ?>" />
</form>     
</td>    
</tr>    
<?php } ?>    
</tbody>   
</table>
</div>
<div class="clearfix" ></div>  
<div class="row"style="margin-top: 15px" >
<div class="col-md-12 table-responsive">    
<div class="col-md-8"></div>
<div class="col-md-4 text-right" >
<a href="pro_productcreate.php" class="btn btn-flat bg-purple">Add Product</a>
</div>
</div>    
</div>    
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['access']=='1'){echo read_activity($aid,'ITM','A');}else{echo read_activity($aid,'ITM','U');}?>
</div>
</div>
</div>
</div>
</div>
</div> 

<?php include('../layout/quick.php');?>     
</section>
<!-- /.main content -->
<?php include('../layout/details.php'); ?>    
</div>

<?php 
include('../layout/footer.php');
?>
<!-- page script -->
<script src='../plugins/chart/Chart.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$('#datarec').DataTable({stateSave: true});
} );
function edit_item(id) {
document.getElementById(id).submit(); 
}
function remove_item(id) {
bootbox.confirm({
title: "Confirm",
message: "Are you sure to delete ?",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-flat bg-purple'
},
cancel: {
label: 'Cancel',
className: 'btn-flat bg-gray'
}
},
callback: function (result) {
if (result == true) {
document.getElementById(id).submit();
}
}
});

}
    
$(document).on('click', '.prodetail', function(e) { 
id_arr = $(this).attr('id');
id = id_arr.split("_");

$.ajax({
url: 'axe_prodetails.php',
method: "POST",
data:{ prodet: 1,pid: id[1] },
success: function(data){
$('#profile').html(data);    
}
});    
    
$.ajax({
url: 'axe_prodetails.php',
method: "POST",
data:{ details: 1,pid: id[1]},
success: function(data){
$('#details').html(data);   
}
});    
    
$('.right-side-details').toggle('slide', { direction: 'right' }, 300);    
e.preventDefault();    
});
    
$(document).on('click', '#closedet', function() {
$('#profile').html('');
$('#details').html('');    
if($('.right-side-details').is(':visible')) {
$('.right-side-details').toggle('slide', { direction: 'right' }, 300);
}    
});    
</script>    
<!-- /page script -->
</html>    