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

  <div class="content-wrapper">

    <div class="container-fluid">

     <div class="row pt-2 pb-2">

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

		    <h4 class="page-title">Manage Blogs</h4>

	   </div>

     </div>

     <div class="row">

			<div class="col-lg-4">

			   <?php if($this->session->flashdata("msg")){echo $this->session->flashdata("msg"); }?>

               <div class="card">

                    	  <div class="card-header">Add/Edit Blogs</div>

                    <div class="card-body">

                           <?php if($this->uri->segment(3)){
							   $edit=$this->db->get_where("blogs",array("blog_id"=>$this->uri->segment(3)))->row();?>

                            <form  action="<?php echo base_url();?>admin/add_blog/<?php echo $this->uri->segment(3);?>" method="post" enctype="multipart/form-data">

                                  
                                  

                                  <div class="form-group ">

                                    <label for="email">Blog Title</label>

                                    <input type="text" required class="form-control" value="<?php echo $edit->blog_title;?>" name="blog_title">

                                  </div>
                                  <div class="form-group ">

                                    <label for="email">Blog Link</label>

                                    <input type="url" required class="form-control" value="<?php echo $edit->blog_link;?>" name="blog_link">

                                  </div>
                                  <div class="form-group ">

                                    <label for="email">Blog User</label>

                                    <input type="text" required class="form-control" value="<?php echo $edit->blog_user;?>" name="blog_user">

                                  </div>
                                  
                                  <div class="form-group ">

                                    <label for="email">Blog Image</label>

                                  	<input type="file" name="img" class="form-control"/>
                                  	<input type="hidden" name="oldimg" class="form-control" value="<?php echo $edit->blog_img;?>"/>
                                    
                                    </div><img  width="100px" src="<?php echo base_url();?>assets/images/category/<?php echo $edit->blog_img;?>" class="img img-responsive"><br/>

                                  	<button type="submit" class="btn btn-success" name="submit">Update Blog</button>

                                </form>

                              <?php }else{?>

                                <form  action="<?php echo base_url();?>admin/add_blog" method="post" enctype="multipart/form-data">

                                  
                                  

                                  <div class="form-group ">

                                    <label for="email">Blog Title</label>

                                    <input type="text" required class="form-control" name="blog_title">

                                  </div>
                                  <div class="form-group ">

                                    <label for="email">Blog Link</label>

                                    <input type="url" required class="form-control" name="blog_link">

                                  </div>
                                  <div class="form-group ">

                                    <label for="email">Blog User</label>

                                    <input type="text" required class="form-control" name="blog_user">

                                  </div>
                                  
                                  <div class="form-group ">

                                    <label for="email">Blog Image</label>

                                  	<input type="file" name="img" class="form-control"/></div><br/>

                                  	<button type="submit" class="btn btn-success" name="submit">Add Blog</button>

                                </form>

                                <?php }?>

                    </div>

                    

               </div>                  

            </div>

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

               <div class="card">

                    <div class="card-header">Listed Blog</div>

                    <div class="card-body">

<table class="table table-condensed table-bordered" id="default-datatable">

<thead><tr><th>Image</th><th>Title</th><th>User</th><th>Action</th></tr></thead>

<tbody>

    <?php $i=1;foreach($blogs as $cat){?>

    <tr>

    <td width="100px"><img  width="100%" src="<?php echo base_url();?>assets/images/category/<?php echo $cat->blog_img;?>" class="img img-responsive"></td>

    <td><?php echo $cat->blog_title;?><td>
    <td><?php echo $cat->blog_user;?></td>

<td>

    <a href="<?php echo base_url();?>admin/blogs/<?php echo $cat->blog_id;?>" class="btn btn-sm btn-warning"><i class="fa fa-edit"></i></a>

        <a href="<?php echo $cat->blog_id;?>" class="btn btn-sm btn-danger catdelete"><i class="fa fa-trash-o"></i></a></td>
</tr>
    <?php $i++;}?>

    <!--<tr><td><button type="submit" class="btn btn-success btn-md">Sort</button></td><td></td><td></td><td></td></tr>-->

</tbody>

</table>

                    </div>

                    

               </div>                  

            </div>

            

        </div><!--End Row-->

	  

	  <!--End Row-->



    </div>

    <!-- End container-fluid-->

    

    </div><!--End content-wrapper-->

   <!--Start Back To Top Button-->

    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>

    <!--End Back To Top Button-->

	

	<!--Start footer-->

	<footer class="footer">

      <div class="container">

        <div class="text-center">

          Copyright © 2022

        </div>

      </div>

    </footer>

	<!--End footer-->

   

  </div><!--End wrapper-->





  <!-- Bootstrap core JavaScript-->

	

	<!-- simplebar js -->

     <script src="<?php echo base_url();?>adminassets/plugins/bootstrap-datatable/js/jquery.dataTables.min.js"></script>

  <script src="<?php echo base_url();?>adminassets/plugins/bootstrap-datatable/js/dataTables.bootstrap4.min.js"></script>



    <script>

	$(document).ready(function(){
		
		$(".catdelete").click(function(e){e.preventDefault();

		if (!confirm("Sure you want to delete?")){

				  return false;

				}

			var id=$(this).attr("href");$(this).closest("tr").remove();

			$.ajax({

							 type: "POST",

							 url: '<?php echo base_url();?>admin/blog_delete',

							 data: {id:id},

							 success: function(response){

								 //alert(response);

							 }

							 });

		});	
	});

</script>

	

  <script src="<?php echo base_url();?>adminassets/js/sidebar-menu.js"></script>

  <!-- Custom scripts -->

  <script src="<?php echo base_url();?>adminassets/js/app-script.js"></script>

  

  <!-- Vector map JavaScript -->

  <!-- Index js -->

  <script src="<?php echo base_url();?>adminassets/js/index.js"></script>

  

 

</body>

</html>

