<?php
  require_once("../../session_check.php");
  require_once("../../../classes/main_classes.php");

  //OBJECTS
  $retrieveObj=new RETRIEVE();

  $get_bc=$retrieveObj->retriever("blog_categories","*","fetchAll");
?>

<h4 class="page-title">
	<span class="fas fa-blog"></span>
	Blog
</h4>
<p><a href="#" class="bold" onclick="blog_view()">Blog</a> <span class="fas fa-angle-right"></span> Blog Categories</p>
<div class="row">
	<div class="col-md-12 mb-3">
		<p class="font-weight-bold mb-2 text-right">
			<span>
				<a href="#!" class="text-primary font-weight-normal mx-2" onclick="add_blog_category_view()"><span class="fas fa-plus"></span> Add blog category</a>
			</span>  
 		</p>
 		<div id="delete_blog_category_response"></div>
		<table class="table table-head-bg-primary mt-4" id="blog_categories_table">
			<thead>
				<tr>
                  <th scope="col">Blog category name</th>
                  <th></th>
                </tr>
			</thead>
			<tbody>
				<?php
                    
          if($get_bc!="1020"){
            $element_id="element_id";
              foreach ($get_bc as $blog_category) {
                $element_id=$element_id."Ot";
        ?>  
            <tr id="<?php echo $element_id ?>">         
              <td>
                <?php 
                  echo $blog_category->b_category_name;
                ?>
              </td>
              
              <td id="<?php echo $element_id.'Dbtn' ?>">
                  <div class="">
                    <button title="Edit" class="btn btn-success hand_cursor" onclick="edit_blog_category_view(<?php echo $blog_category->b_category_id ?>)"><span class="fas fa-edit"></span> Edit </button>
                    <form id="<?php echo 'R'.$element_id.'form' ?>" class="mb-0 hand_cursor" style="display: inline;">
                        <input type="hidden" name="delete_blog_category_note" value="<?php echo $blog_category->b_category_id; ?>">
                        <button id="<?php echo $element_id.'Rbtn' ?>" onclick="delete_blog_category('<?php echo 'R'.$element_id.'form' ?>','<?php echo $element_id; ?>','delete_blog_category_response')" type="submit" title="Delete" class="btn btn-danger hand_cursor"><span class="fas fa-times"></span> Delete</button>
                    </form>
                    
                  </div>       
              </td>
            </tr>
          <?php
              }
            }
          ?>
			</tbody>
		</table>
	</div>
</div>
<script type="text/javascript">
  $(document).ready(function () {
    var table = $('#blog_categories_table').DataTable({
      columnDefs: [
        {bSortable: false, targets: [4]} 
      ]
    });
  })
</script>