<!-- Main Content -->
<div class="page-wrapper">
    <div class="container-fluid pt-25">
        <div class="row">
            <div class="alert alert-success alert-dismissible" role="alert" <?php if($this->session->flashdata('message')==''){ ?> style="display:none" <?php } ?> >
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <?php echo $this->session->flashdata('message'); ?>
            </div>
            <div class="alert alert-warning alert-dismissible" role="alert" <?php if($this->session->flashdata('emessage')==''){ ?> style="display:none" <?php } ?> >
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <?php echo $this->session->flashdata('emessage'); ?>
            </div>
        </div>
    	<div class="row">
	      <div class="col-md-12">
	        <div class="panel panel-default card-view">
	          <div class="panel-heading">
	            <div class="pull-left">
					<h6 class="panel-title txt-dark">Category List</h6>
				</div>
				<div class="clearfix"></div>
	          </div>
	          <div class="panel-wrapper collapse in">
		          <div class="panel-body">	
                    <?php 
                        if(isset($allcategory) && !empty($allcategory)){	            
                            echo drawMenu($allcategory,0); 
                        }
                    ?>
		          </div>
		      </div>
	        </div>

	      </div>

	    </div>
	</div>
<?php if($this->admin_type=='superadmin' || (in_array('1.3', $this->authority))){ ?>
<div class="modal fade" id="editcategorypopup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">

    <div class="modal-dialog" role="document">

        <div class="modal-content">

            <div class="modal-header">

                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

                <h4 class="modal-title" id="myModalLabel"></h4>

            </div>

            <div class="modal-body">

                <div class="row">

                    <form id="addCategoryForm" method="post" action="<?php echo base_url(A.'/editCategory'); ?>" enctype="multipart/form-data">

                        <div class="panel panel-default text-center">

                            <div class="panel-body">

                                <div class="form-group">
                                    <input type="hidden" name="catid" value="" id="catid"/>
                                    <input class="form-control" type="text" name="" id="cattype" data-type="" data-id="" placeholder="Category">
                                    <input type="hidden" name="old_img" id="old_img" value="" />

                                </div>

                                <div class="form-group" id="cat_img">
                                    <input class="form-control" type="file" name="image" id="imag">
                                    <p>Image must be 320x320 px.</p>
                                </div>

                                <div class="form-group">

                                    <input type="submit" class="btn btn-primary" value="Submit">
                                    
                                </div>

                            </div>

                        </div>

                    </form>

                </div>

            </div>

        </div>

    </div>

</div>
<?php }else{ ?>
    <style>
        .editAuth{display:none;}
    </style>
<?php } ?>
<?php if($this->admin_type=='superadmin' || (in_array('1.4', $this->authority))){}else{ ?>
    <style>
        .deleteAuth{display:none;}
    </style>
<?php } ?>
<?php if($this->admin_type=='superadmin' || (in_array('1.5', $this->authority))){}else{ ?>
    <style>
        .showAuth{display:none;}
    </style>
<?php } ?>
<script type="text/javascript">
var site_url = "<?php echo base_url(); ?>";
var urlLink = "<?php echo A; ?>";
$(".showonfront").on("click",function(){

    var id = $(this).val();

    if($(this).is(":checked"))

    {

        val = 1;

    }else{

        val = 0;

    }

    $.ajax({

        url  : site_url+urlLink+"/checkCategory",

        type : 'POST',

        data : 'val='+val+'&id='+id,

        success : function(data){

            if(data==1)

            {

                if(val==1)

                {

                    alert("Category displayed on website");

                }else{

                    alert("Category hidden from website");

                }

            }else{

                alert("error");

            }

        }

    });

});
$(".isFeatured").on("click",function(){

    var id = $(this).val();

    if($(this).is(":checked"))

    {

        val = 1;

    }else{

        val = 0;

    }

    $.ajax({

        url  : site_url+urlLink+"/checkCategoryFeatured",

        type : 'POST',

        data : 'val='+val+'&id='+id,

        success : function(data){

            if(data==1)

            {

                alert("Status Updated");

            }else{

                alert("error");

            }

        }

    });

});

$(".edit_category").on("click",function(){

    var id = $(this).attr('data-id');

    var type = $(this).attr('data-type');

    var img = $(this).attr('data-image');


    if(type=="category")

    {

        $("#myModalLabel").html("Edit Category");

        $("#tex_percentage").parent().parent().hide();

        var val = $("#category_"+id).attr('data-val');

    }

    //alert(val);
    $("#catid").val(id);
    $("#cattype").attr("name",type);

    $("#old_img").val(img);

    $("#cattype").val(val);

    $("#cattype").attr('data-id',id);

});

$(".deleteCategory").on("click",function(){

    var type = $(this).data('type');

    var id = $(this).data('id');

    var ok = confirm("Are you sure you want to delete?");

    if (ok) {

        $.ajax({

            url: site_url+urlLink+'/deleteCategory',

            type:'POST',

            data:'type='+type+'&id='+id,

            success: function(data){

                if(data==1)

                {

                    location.reload();

                }

            },

        });

    }

});


  $(function() {
      $('.panel-body').sortable({
        delay: 150,
        stop: function() {
          var div = [];
          $('.orderby').each(function() {
            var id = $(this).attr('data-order');
            if(id!='undefined'){
              div.push(id);
            }
          });
            var site_url = '<?php echo base_url(); ?>';
            $.ajax({
              url: site_url+urlLink+"/updateCategoryOrder",
              type: "POST",
              dataType:"json",
              data: "div="+div,
              success: function(result){
                
              }
            });
        }
      });
      $('.panel-collapse').sortable({

        delay: 150,

        stop: function() {

          var div = [];

          $('.orderby').each(function() {

            var id = $(this).attr('data-order');

            if(id!='undefined'){

              div.push(id);

            }

          });

            var site_url = '<?php echo base_url(); ?>';

            $.ajax({

              url: site_url+urlLink+"/updateCategoryOrder",

              type: "POST",

              dataType:"json",

              data: "div="+div,

              success: function(result){

                

              }

            });

        }

      });
  });

</script>

<style>
	img{vertical-align: middle;}
	.panel .panel-heading .pull-right i{vertical-align:middle;;}
    .card-view.panel .panel-heading
    {
        border-radius: 3px!important;

    }
    .btn:hover i
    {
        color: #ed1c24!important ;
        border-color: #ed1c24 ;
    }
    .panel-body, .panel
    {
        border: transparent;
        box-shadow: none;
    }
    .orderby .in .panel-group{padding: 10px 5px 10px 40px;}
</style>