<style>
input[type="checkbox"], input[type="radio"] {  
  margin-top: 9px; 
}
</style>
<script>
function showPartnerButtons(catid){
	/*var div = document.getElementById("cat-btn"+catid);
	var checkBox = document.getElementById('cat-'+catid);
	if (checkBox.checked == true){
	    div.style.display = "block";
	} else {
	    div.style.display = "none";
	}*/
}
</script>
<div class="page-content-wrapper">
                <div class="page-content">
                    <div class="page-bar">
                        <div class="page-title-breadcrumb">
                            <div class=" pull-left">
                                <div class="page-title"><?php echo 'Assign Category'; ?></div>
                            </div>
                            <ol class="breadcrumb page-breadcrumb pull-right">
                                <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="index.php?page=home">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                                </li>
                                <li><a class="parent-item" href="index.php?page=view_purchase_partner&id=<?php echo $shopId; ?>">Shop</a>&nbsp;<i class="fa fa-angle-right"></i></li><li class="active">Assign Category</li>
                            </ol>
                        </div>
                    </div>
<div class="row">
                        <div class="col-md-12 col-sm-12">
                            <div class="card card-box">
                                <div class="card-head">
                                    <header><?php echo 'Assign Category to '.getShopName($shopId); ?></header>                                    
                                </div>
                                <div class="card-body" id="bar-parent1">
                                	<?php if(isset($error) && $error!='') { ?> 
                                	<div class="alert alert-danger"><?php echo $error; ?></div>
                                	<?php } else if(isset($success) && $success!=''){ ?>                                		
                                		<div class="alert alert-success"><?php echo $success; ?></div>
                                	<?php } else if(isset($_REQUEST['success'])){ ?>                                		
                                		<div class="alert alert-success"><?php echo urldecode($_REQUEST['success']); ?></div>
                                	<?php } ?>
                                    <form action="" id="form_staff_add" class="form-horizontal" method="post">
                                        <div class="form-body">
                                        	     
                                            <?php if(mysqli_num_rows($catRs)>0){
                                                  while($catRec = mysqli_fetch_array($catRs)){
                                                  	$showMake = $showRemove = FALSE;
                                                  	//check if the category already set as partner category for this shop
                                                  	$chkRs = mysqli_query($con, "SELECT id FROM tbl_partner_category WHERE partner_id = '".$shopId."' AND category_id = '".$catRec['id']."'");
													if(mysqli_num_rows($chkRs)>0){
														$showRemove = TRUE;
													} else {
														//check if any other shop in the location has been set as partner for this category
														$chkCatRs = mysqli_query($con, "SELECT id FROM tbl_partner_category WHERE location = '".$shopPlace."' AND category_id = '".$catRec['id']."'");
														if(mysqli_num_rows($chkCatRs)>0){
															//hide all buttons
														} else {
															$showMake = TRUE;
														}
													}                                                  	
                                                  	?> 
		                                            <div class="form-group row">
		                                                <label class="control-label col-md-3"><?php echo $catRec['name'];?></label>
		                                                <div class="col-md-4">                                                    
		                                                    <input type="checkbox" onclick="showPartnerButtons(<?php echo $catRec['id'];?>)" name="category[]" id="cat-<?php echo $catRec['id'];?>" value="<?php echo $catRec['id'];?>" <?php if(isset($_POST['category']) && in_array($catRec['id'], $_POST['category'])){ echo 'checked'; } else if(isset($editCatArray) && in_array($catRec['id'], $editCatArray)){ echo 'checked'; }?> >
		                                                </div>
		                                                <div <?php if(isset($_POST['category']) && in_array($catRec['id'], $_POST['category'])){ echo 'style="display: block;"'; } else if(isset($editCatArray) && in_array($catRec['id'], $editCatArray)){ echo 'style="display: block;"'; } else { echo 'style="display: none;"'; }?> id="cat-btn<?php echo $catRec['id'];?>" class="col-md-4">
		                                                	<?php if($showMake){ ?>                                                    
		                                                    	<a style="padding: 3px 15px;" class="badge badge-info" href="index.php?page=shop_assign_category&shop_id=<?php echo $shopId; ?>&cat_id=<?php echo $catRec['id']; ?>&action=make_partner">Make Partner</a>
		                                                    	  (<?php echo $shopPlace; ?>)
		                                                    <?php } else if($showRemove){ ?>                                                    
		                                                    	<a style="padding: 3px 15px;" class="badge badge-danger" href="index.php?page=shop_assign_category&shop_id=<?php echo $shopId; ?>&cat_id=<?php echo $catRec['id']; ?>&action=rem_partner">Remove Partner</a>
		                                                    <?php } ?>
		                                                </div>                                                  
		                                            </div>    
                                            <?php } }  ?>                                     
                                                                                     
                                            
                                        </div>
                                      <div class="form-group">
                                            <div class="offset-md-3 col-md-9">
                                            	<?php if(isset($editId)){ ?>
                                            		<button type="submit" name="update" class="btn btn-info">Update</button>
                                            	<?php } else { ?>
                                            		<button type="submit" name="submit" class="btn btn-info">Submit</button>
                                            	<?php } ?>                                                                                                
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
	</div>
</div>
