<?php include("_config/dbconfig.php");
include("_includes/head.php");?>
<title>Categories</title>
<?php include("_includes/header.php");

    $all_cats = $obj_category_class->getCategories();
      
    $all_cats2 = $obj_category_class->getAllCategories();
    
    /*echo '<pre>';
    print_r($all_cats2); 
    echo '</pre>'; */
?>
    

<div class="col-sm-12 right_form">
        <div class="title">
            <div class="row">
                <div class="col-md-8 col-sm-12">
                    <h1>Categories</h1>
                </div>
                
                 <div class="col-md-4 col-sm-12">
			        <a href="category_controls.php" style="cursor: pointer;" class="btn btn-primary btn-o add-event"> Add New </a>
                </div>
                
            </div>
        </div>

        
    <ol class="breadcrumb white">
      <li><a href="dashboard.php">Dashboard</a></li>
      <li class="active">Categories</li>
    </ol>

</div>

    



<?php 
/*        echo "<pre>";
        print_r($_SESSION);
        echo '</pre>';
   */     
?>
  	<div class="col-sm-12 form_inner">
			<div class="col-md-12 table_inner" style="padding:0;">
                <div class="table-responsive">
                    <table id="example" class="display nowrap lisitng_table" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                            	<th>Sr. </th>
                                <th>Category</th>
                                <th>Description</th>
                                <th>Main Category</th>
                                <th>Status</th>
                                <th>Modify</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php $i=1; foreach($all_cats2 as $cat){ ?>    
                            <tr>
                            	<td><?php echo $i++;?></td>
                                <td><?php echo $cat['category']?> </td>
                                <td><?php echo $cat['desc']?></td>
                                <td> - </td>
                                <td>    <?php 
                                                if($cat['status']==1) echo 'Active';
                                                else if($cat['status']==2) echo 'Pending';
                                                else if($cat['status']==0) echo 'Disable';
                                ?>
                                
                                </td>
                                <td>
                                        <a href="category_controls.php?edit=<?php echo base64_encode($cat['cat_id'])?>"> Edit  </a> | 
                                        <a href="#"> Delete  </a>
                                </td>
                                <td></td>
                            </tr>
                            
                                    <?php 
                                    if(count($cat['sub_cat'])>0){
                                    foreach($cat['sub_cat']  as $sub_cat){ ?>    
                                        <tr>
                                            <td><?php echo $i++;?></td>
                                            <td><?php echo $sub_cat['category']?> </td>
                                            <td><?php echo $sub_cat['desc']?></td>
                                            <td><?php echo $sub_cat['main']?></td>
                                            <td>    <?php 
                                                            if($sub_cat['status']==1) echo 'Active';
                                                            else if($sub_cat['status']==2) echo 'Pending';
                                                            else if($sub_cat['status']==0) echo 'Disable';
                                            ?>

                                            </td>
                                            <td>
                                                    <a href="category_controls.php?edit=<?php echo base64_encode($sub_cat['cat_id'])?>"> Edit  </a> | 
                                                    <a href="#"> Delete  </a>
                                            
                                            </td>
                                            <td></td>
                                        </tr>
                                    <?php  } } ?>
                            
                            
                            
                        <?php  } ?> 
                        </tbody>
    				</table>
                </div>
            </div>
		</div>


<?php include("_includes/footer.php"); ?>
<script>
$(document).ready(function() {
    $('#example').DataTable( {
        responsive: {
            details: {
                type: 'column',
                target: -1
            }
        },
        columnDefs: [ {
            className: 'control',
            orderable: false,
            targets:   -1
        }]
    });
	
	<!-- Slide Push Menus Start  -->
	
	var menuLeft = document.getElementById( 'cbp-spmenu-s1' ),
		menuRight = document.getElementById( 'cbp-spmenu-s2' ),
		showLeft = document.getElementById( 'showLeft' ),
		showRight = document.getElementById( 'showRight' ),
		
		body = document.body;

	showLeft.onclick = function() {
		classie.toggle( this, 'active' );
		classie.toggle( menuLeft, 'cbp-spmenu-open' );
		disableOther( 'showLeft' );
	};
	showRight.onclick = function() {
		classie.toggle( this, 'active' );
		classie.toggle( menuRight, 'cbp-spmenu-open' );
		disableOther( 'showRight' );
	};
	

	function disableOther( button ) {
		if( button !== 'showLeft' ) {
			classie.toggle( showLeft, 'disabled' );
		}
		if( button !== 'showRight' ) {
			classie.toggle( showRight, 'disabled' );
		}
	}
	
	<!-- Slide Push Menus Ends  -->
	
	$(window).scroll(function () {
			if ($(this).scrollTop() > 100) {
				$('.scrollup').fadeIn();
			} else {
				$('.scrollup').fadeOut();
			}
		});
	
		$('.scrollup').click(function () {
			$("html, body").animate({
				scrollTop: 0
			}, 600);
			return false;
	});
	
});
</script>