<?php
session_start();
if(!isset($_SESSION['user'])) {
	header("location: ../index.php");
	exit;
}

include"../header.php";
?>

<style>
#primaryModal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
#primaryModal .modal-content {
    background-color: #fefefe;
    /* margin: 10% auto; */ /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 40%; /* Could be more or less, depending on screen size */
}
#primaryModal .modal-header {
    display: block;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
	border-bottom: none;
}
/* The Close Button */
#primaryModal .close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
	position: relative;
    text-align: right;
}

#primaryModal .close:hover,
#primaryModal .close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}


#itemModal1 {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
#itemModal1 .modal-content {
    background-color: #fefefe;
    /* margin: 10% auto; */ /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 40%; /* Could be more or less, depending on screen size */
}
#itemModal1 .modal-header {
    display: block;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
	border-bottom: none;
}
/* The Close Button */
#itemModal1 .close1 {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
	position: relative;
    text-align: right;
}

#itemModal1 .close1:hover,
#itemModal1 .close1:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}
#itemModal1 .close1{
	margin-top:-12;
	
}
.btn{
	    padding: 1px 0.75rem;
}
.btn1{
	    padding: .5rem 0.75rem;
}

</style>
		 
		  <link rel="stylesheet" href="../css/zomato.css">
		 
	<div class="row">
		<div class="col-md-12 col-lg-8">
			<div class="card">
				<div class="card-header">
					<div class="row">
						<div class="col-lg-6 col-sm-6">Web Categories</div>
						
						<div class="col-lg-3 col-sm-3">
						<button type = "button" class="btn btn-success " id="addCat" align="right" style="margin-top:0px;">Add Category</button>
						</div>
						<div class="col-lg-3 col-sm-3"><button class="btn btn-success " id="addItem" align="right" style="margin-top:0px;">Add Item</button></div>
					</div>
				</div>
				<div class="card-body">
					<?php 
					$qry = mysql_query("select category_id, category_name from web_categories where category_is_active = '1'");
					while($row = mysql_fetch_array($qry,  MYSQL_ASSOC)){
						$cat_id = $row['category_id'];
						?>
						<h1 class="accordion" ><?php echo $row['category_name']; ?></h1>
						<div class="panel">
						
							<?php
							$qry1 = mysql_query("select * from web_items where item_cat_type_id = '$cat_id'");
							while($row1 = mysql_fetch_array($qry1,  MYSQL_ASSOC)){
							?>
								<h5 class="itembox item<?php echo $row1['item_id']; ?>"><?php echo $row1['item_name']; ?>
								<button class = "btn btn-success" style="border-radius:20px 20px 20px 20px;"><a style="color:white;" href = "item.php?upid=update&itemid=<?php echo $row1['item_id']; ?>">Edit</a></button>
								<button class = "btn btn-success" style="border-radius:20px 20px 20px 20px;"><a style="color:white;" href = "item.php?act=active&itemid1=<?php echo $row1['item_id']; ?>">Active</a></button>
								
								
								<label class="switch switch-3d switch-success">
									<input type="checkbox" class="switch-input" name = "switch<?php echo $row1['item_id']; ?>" onchange = "changeCategory( <?php echo $row1['item_id']; ?> )" checked="">
									<span class="switch-label"></span>
									<span class="switch-handle"></span>
								</label>
								
								</h5>
								<?php
							}
							?>
							
						</div>
						<?php
					}
					?>
					
					
				</div>
			</div>
		</div>

		<?php
		/**********************/
		$itemid1 = $_GET['itemid1'];
		$qry_act = mysql_query("select * from web_items where item_id = '$itemid1'");
		$fetch1 = mysql_fetch_array($qry_act);
		/********************/
		
		$update_id = $_GET['itemid'];
		$qry_update = mysql_query("select * from web_items where item_id = '$update_id'");
		$fetch = mysql_fetch_array($qry_update);
		if($_GET['upid']=='update' && $fetch['item_id'] == $update_id){
			?>
			<div class="col-lg-4">
			
				<div class="card">
					<div class="card-header">
						<div class="row">
							<div class="col-lg-12 col-sm-12">Update Item </div>
						</div>
					</div>
					<div class="card-body">
					
						<form method="post" action="save_item_data.php" name="update-item" role="form" id="" enctype="multipart/form-data">
							<div class="row">
								<div class="col-lg-6">	
									<div class="form-group">
										<label>Item Id</label>
										<input type="number"  value = "<?php  echo $fetch['item_id']; ?>" name="id_item" class="form-control read-only" >
									</div>
								</div>
								<div class="col-lg-6">	
									<div class="form-group">
										<label>Item Name</label>
										<input type="text" value = "<?php  echo $fetch['item_name']; ?>"  name="name_of_item" class="form-control">
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-lg-6">	
									<div class="form-group">
										<label>Select Outlet</label>
										<select name="outlet"  class="form-control">
											<option value="Gurgaon" >Gurgaon</option>
											<option value="VasantKunj">VasantKunj</option>
										</select>
									</div>
								</div>
								<div class="col-lg-6">	
									<div class="form-group">
										<label>Item Price</label>
										<input type="text" value = "<?php  echo $fetch['item_final_price']; ?>"  name="item_price" class="form-control">
									</div>
								</div>
							</div>	
							<div class="form-group">
								<label>Item Description</label>
								<textarea name="item_description" class="form-control" rows="5"><?php  echo $fetch['item_long_description']; ?></textarea>
							</div>
							<div class="row">
								<div class="col-lg-6">	
									<div class="form-group">
										<label>Is Active?</label>
										<select name="is_active_item" value = "<?php  echo $fetch['item_is_active']; ?>" class="form-control">
											<option value="1" selected>yes</option>
											<option value="0">No</option>
										</select>
									</div>
								</div>
								<div class="col-lg-6">	
									<div class="form-group">
										<label>Itemp image update</label>
										<input type="file" value = "<?php  echo $fetch['item_image_url']; ?>"  name="image_update" class="form-control">
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-lg-6">
									<div class="form-group">
										<label>Item Tags</label>
										<input type="text" value = "<?php  echo $fetch['item_tags']; ?>"  name="upd_item_tags" class="form-control">
									</div>
								</div>
								<div class="col-lg-6">
									<div class="form-group">
										<label>Item Updated?</label>
										<input type="text" value = "<?php  echo $fetch['is_item_updated']; ?>"  name="upd_item" class="form-control">
									</div>
								</div>
							</div>
							
							<div class="form-group">
								<button type="submit" name="update" class="btn btn-primary px-4" id="update">Update</button>
							</div>
						</form>
					</div>
				</div>
			</div>
			<?php 
		} else if($_GET['act']=='active' && $fetch1['item_id'] == $itemid1) {
			?>
			<div class="col-lg-4">

				<div class="card">
					<div class="card-header">
						<div class="row">
							<div class="col-lg-12 col-sm-12">Avtive Outlet </div>
						</div>
					</div>
					<div class="card-body">
				
						<form method="post" action="save_item_data.php" name="-item" role="form" id="" enctype="multipart/form-data">
							<div class="row">
								<div class="col-lg-6">	
									<div class="form-group">
										<label>Select Outlet</label>
										<input type="hidden" name="itemid" value="<?php echo $fetch1['item_id']; ?>">
										<select name="outlet" value="<?php echo $fetch['UnitName']; ?>" class="form-control">
											<?php
											$qry_unit = mysql_query("select * from unit_master");
											while($row_unit = mysql_fetch_array($qry_unit)) {
												?>
												<option value="<?php echo $row_unit['UnitId']; ?>"><?php echo $row_unit['UnitName']; ?></option>
												<?php
											}
											?>
										</select>
									</div>
								</div>
							</div>	
							<div class="row">
								<div class="col-lg-8">	
									<div class="form-group">
										<label class="radio-inline" for="inline-radio1">
										  <input type="radio" id="inline-radio1" name="inline-radios" value="1" <?php if($fetch1['item_is_active']==1){echo 'checked'; }?>> Enable
										</label>
										<label class="radio-inline" for="inline-radio1">
										  <input type="radio" id="inline-radio2" name="inline-radios" value="0" <?php if($fetch1['item_is_active']==0){echo 'checked'; }?>> Disable
										</label>
									</div>
								</div>
								
							</div>
							<div class="form-group">
								<button type="submit" name="active" class="btn btn-primary px-4" id="update">Update</button>
							</div>
						</form>	
					
					</div>
				</div>
			</div>
			<?php
		}
		?>
	</div>


<!-- for select outlet-->

	
	

<!-- The Modal -->
<div id="primaryModal" class="modal">

	<!-- Modal content -->
	<div class="modal-content">
		<div class="modal-header">
			<span class="close">&times;</span>
			<h4>Add New Category</h4>
		</div>
		<div class="modal-body">
			<form method="post" action="save_item_data.php" name="web-cat" role="form" id="web-cat-form" enctype="multipart/form-data">
											
				<div class="form-group">
					<label>Category Name</label>
					<input type="text" name="cat_name" class="form-control">
				</div>
				<div class="form-group">
					<label>Category Description</label>
					<textarea name="cat_desc" class="form-control" rows="5"></textarea>
				</div>
				<div class="row">
					<div class="col-lg-4">
						<div class="form-group">
							<label>Is Active?</label>
							<select name="is_active" class="form-control">
								<option value="1" selected>Yes</option>
								<option value="0">No</option>
							</select>
						</div>
					</div>
					<div class="col-lg-8">
						<div class="form-group">
							<label>Category Image</label>
							<input type="file" name="cat_image" class="form-control">
							<div class="text-danger"><?php echo $image; ?></div>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label>Subcategory</label>
					<input type="text" name="subcat" class="form-control">
				</div>
				<div class="row">
					<div class="col-lg-4">
						<div class="form-group">
							<label>Category Tags</label>
							<input type="text" name="cat_tags" class="form-control">
						</div>
					</div>
					<div class="col-lg-4">
						<div class="form-group">
							<label>Order By</label>
							<input type="text" name="order_by" class="form-control">
						</div>
					</div>
					<div class="col-lg-4">
						<div class="form-group">
							<label>Item Updated?</label>
							<input type="text" name="item_update" class="form-control">
						</div>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" name="cat_submit" class="btn btn-primary px-4" id="cat-submit">Submit</button>
				</div>
				
			</form>
		</div>
	</div>
</div>
	
<!-- The Modal -->
<div id="itemModal1" class="modal">

	<!-- Modal content -->
	<div class="modal-content">
		<div class="modal-header">
			<span class="close1">&times;</span>
			<h4>Add New Item</h4>
		</div>
		<div class="modal-body">
			<form method="post" action="save_item_data.php" name="web-item" role="form" id="web-item-form" enctype="multipart/form-data">
											
				<div class="form-group">
					<label>Item Name</label>
					<input type="text" name="item_name" class="form-control">
				</div>
				<div class="form-group">
					<label>Item Description</label>
					<textarea name="item_desc" class="form-control" rows="5"></textarea>
				</div>
				<div class="row">
					<div class="col-lg-4">
						<div class="form-group">
							<label>Is Active?</label>
							<select name="is_active-item" class="form-control">
								<option value="1" selected>Yes</option>
								<option value="0">No</option>
							</select>
						</div>
					</div>
					<div class="col-lg-8">
						<div class="form-group">
							<label>Item Image</label>
							<input type="file" name="item_image" class="form-control">
							<div class="text-danger"><?php echo $image; ?></div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-6">
						<div class="form-group">
							<label>Sub Item</label>
							<input type="text" name="sub_item" class="form-control">
						</div>
					</div>
					<div class="col-lg-6">
						<div class="form-group">
							<label>Select Category</label>
							<select name="is_active-item" class="form-control">
								<option value="1" selected>Yes</option>
								<option value="0">No</option>
							</select>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-6">
						<div class="form-group">
							<label>Item Tags</label>
							<input type="text" name="item_tags" class="form-control">
						</div>
					</div>
					<div class="col-lg-6">
						<div class="form-group">
							<label>Item Updated?</label>
							<input type="text" name="update_item" class="form-control">
						</div>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" name="item_submit" class="btn btn-primary px-4" id="item-submit">Submit</button>
				</div>
				
			</form>
		</div>
	</div>
</div>
	
	
	
<?php include"../footer.php"; ?>
<script>
	var acc = document.getElementsByClassName("accordion");
	var i;

	for (i = 0; i < acc.length; i++) {
	  acc[i].addEventListener("click", function() {
		this.classList.toggle("active");
		var panel = this.nextElementSibling;
		if (panel.style.maxHeight){
		  panel.style.maxHeight = null;
		} else {
		  panel.style.maxHeight = panel.scrollHeight + "px";
		} 
	  });
	}
	

var modal = document.getElementById('primaryModal');

// Get the button that opens the modal
var btn = document.getElementById("addCat");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}

var modal1 = document.getElementById('itemModal1');

// Get the button that opens the modal
var btn1 = document.getElementById("addItem");

// Get the <span> element that closes the modal
var span1 = document.getElementsByClassName("close1")[0];

// When the user clicks on the button, open the modal 
btn1.onclick = function() {
    modal1.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span1.onclick = function() {
    modal1.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal1) {
        modal1.style.display = "none";
    }
}


</script>

<script>
 function changeCategory(item_id){
	// alert(item_id);
	//if($('.switch'+item_id).is(":checked")){
	if($("input[name=switch"+item_id+"]:checkbox").is(":checked")){
		var mode = $("input[name=switch"+item_id+"]:checkbox").prop("checked");
		$(".item"+item_id).removeAttr("disabled");
		$(".item"+item_id).removeAttr("style");
		
		
		$.ajax({
			url: 'save_item_data.php',
			type: 'post', 
			data: 'act=item_on&mode='+mode+'&itemid='+item_id,
			success: function(data){
				console.log(data);
			}
		});
	}
	if($("input[name=switch"+item_id+"]:checkbox").is(":not(:checked)")){
		$(".item"+item_id).attr("disabled","disabled");
		$(".item"+item_id).css("color","#ccc");
	}
} 
/* $("input[name=switch111]:checkbox").change(function(){
	if($(this).is(":checked")){
		$(".itembox1").removeAttr("disabled");
		$(".itembox1").removeAttr("style");
	}
	else{
		$(".itembox1").attr("disabled","disabled");
		$(".itembox1").css("color","#ccc");
	}
}); */
</script>
