<!-- Main Content -->

<div class="page-wrapper">

    <div class="container-fluid pt-25">

    	<div class="row">

    		<div class="col-md-12">

    			<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>

    	</div>

		<!-- Row -->

		<div class="row">

			<div class="col-sm-12">

				<div class="panel panel-default card-view">

					<div class="panel-heading">

						<div class="pull-left">

							<h6 class="panel-title txt-dark">All Baking Classes</h6>

						</div>

						<div class="clearfix"></div>

					</div>

					<div class="panel-wrapper collapse in">

						<div class="panel-body">

							<div class="table-wrap">

								<div class="table-responsive">

									<table id="datable_1-1" class="table table-hover  display  pb-30" >

										<thead align="center">

                                            <tr><td colspan="2"><?php echo (isset($h1)?$h1:""); ?></td>

                                                <td colspan="2">

                                                    <div class="col-md-4">&nbsp;</div>

                                                    <div class="col-md-8">

                                                        <select id="admin_length" class="pull-right form-control">

                                                            <option value="10" <?php echo ($this->perPage==10)?'selected':""; ?>>10</option>

                                                            <option value="20" <?php echo ($this->perPage==20)?'selected':""; ?>>20</option>

                                                            <option value="50" <?php echo ($this->perPage==50)?'selected':""; ?>>50</option>

                                                            <option value="100" <?php echo ($this->perPage==100)?'selected':""; ?>>100</option>

                                                            <option value="250" <?php echo ($this->perPage==250)?'selected':""; ?>>250</option>

                                                            <option value="500" <?php echo ($this->perPage==500)?'selected':""; ?>>500</option>

                                                        </select>

                                                    </div>

                                                </td>

                                            </tr>

                                            <tr><td colspan="2" style="color: red;"><?php echo (isset($h2)?$h2:""); ?></td>

                                                <td colspan="2">

                                                    <!-- <div class="text-center" id="links"><?php echo (isset($links))?$links:""; ?></div> -->

                                                </td>

                                            </tr>

                                        </thead>

										<thead>

							                <tr>

							                  <th>SR.No.</th>

							                  <!-- <th>Id</th>

							                  <th>Publish Date</th> -->

							                  <th>Image</th>

							                  <th>Title</th>
							                  <th>Difficulty</th>
							                  <!-- <th>Featured</th> -->

							                  <th>Action</th>

							                </tr>

							            </thead>



							            <tbody>

							                <?php if(!empty($allpost)){ foreach ($allpost as $key => $value): 

							                ?>

							                <tr id="<?php echo "post_".$value['id']; ?>">

							                  <td><?php echo $k++; ?></td>

							                  <!-- <td><?php //echo $value['id']; ?></td>

							                  <td><?php //echo date('Y-m-d',strtotime($value['publish_date'])); ?></td> -->

							                  <td>

							                  	<?php if($value['image']!=''){ ?>

						                            <img src="<?php echo base_url($value['image']); ?>" alt="image" style="width:100px;">

					                            <?php } ?>

							                  </td>

							                  <td><?php echo $value['post_title']; ?></td>
							                  <td><?php echo $value['post_category']; ?></td>
							                  <!-- <td><input type="checkbox" name="isFeatured" class="isFeatured" value="1" data-id="<?php //echo $value['id']; ?>" <?php //echo ($value['isFeatured']==1)?'checked':""; ?> /></td>  -->

							                  <td>
							                  	<?php if($this->admin_type=='superadmin' || (in_array('5.7', $this->authority))){ ?>
							                    	<a href="<?php echo base_url(A."/edit-bclass/".$value['id']); ?>" class="text-inverse pr-10" data-value="">
							                    		<button class="btn btn-info btn-icon-anim btn-square">
							                    			<i class="fa fa-pencil fa-lg"></i>
							                    		</button>
							                    	</a>
							                    <?php } ?>

							                    <?php if($this->admin_type=='superadmin' || (in_array('5.8', $this->authority))){ ?>
							                    	<a href="javascript:void(0)" class="text-inverse post_delete" data-table="post" data-value="<?php echo "postid_".$value['id']; ?>" data-image='' data-id="<?php echo $value['id']; ?>">
							                    		<button class="btn btn-danger btn-icon-anim btn-square">
							                    			<i class="fa fa-trash fa-lg"></i>
							                    		</button>
							                    	</a>
							                    <?php } ?>

							                  </td>

							                </tr>

							                <?php endforeach; } ?>

							            </tbody>

									</table>

								</div>

							</div>

						</div>

						<div class="panel-footer clearfix">

                            <div class="row">

                                <div class="col-md-12">

                                    <div class="text-center"><?php echo (isset($links))?$links:""; ?></div>

                                </div>

                            </div>

                        </div>

					</div>

				</div>	

			</div>

		</div>

		<!-- /Row -->

	</div>

<script type="text/javascript">

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

	var urlLink = "<?php echo A; ?>";



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

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

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

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

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

	    if (ok) {

	        $.ajax({

	            url: site_url+urlLink+'/ajaxDelete',

	            type:'POST',

	            data:'id='+id+'&pimage='+pimage+'&table='+table,

	            success: function(data){

	                location.reload();

	            },

	        });

	    }

	});

	$('.isFeatured').change(function(){
	    var td = this.checked ? '1' : '0';
	    var pid = $(this).attr('data-id');
	    $.ajax({
	        url: site_url+urlLink+"/setFeaturedPost",
	        type: "POST",
	        data: "id="+pid+"&isFeatured="+td,
	        success: function(data){  
	        	alert('Status Update');
	        	// location.reload();
	        }
	    });
	});

</script>

<script type="text/javascript">
    var path = "<?php echo base_url(A); ?>";
    $("#admin_length").on("change",function(){
        var length = $(this).val();
        $.ajax({
            url: path+"/AdminSearchLength",
            type:"POST",
            data:"length="+length,
            success: function(result){
                if(result==1){
                    window.location.reload();
                }
            }
        });
    });
</script>