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

  if(!isset($_POST["b_id"])){
    die("<p class='alert alert-warning'>Invalid request</p>");
  }

  $b_id=addslashes($_POST["b_id"]);

  //OBJECTS
  $retrieveObj=new RETRIEVE();
  $rowcountObj=new ROWCOUNT();

  $get_blog=$retrieveObj->retriever("blog 
      JOIN blog_categories ON blog_categories.b_category_id=blog.b_category_id
      JOIN users ON users.user_id=blog.user_id
      JOIN user_roles ON user_roles.user_id=users.user_id
      JOIN user_role ON user_roles.role_id=user_role.role_id
      WHERE blog.b_status='active' and blog.b_id='$b_id'","*","fetch");

?>

<div class="row">
  <div class="col-md-12 col-sm-12 col-xs-12">
    <p class="text-left mt-1">
      <a href="#blogs_container" class="btn btn-dark btn-sm" onclick="back_to_blogs()">
        <span class="fa fa-arrow-left"></span>
        Back
      </a>
    </p>
    <!-- single-blog start -->
    <article class="blog-post-wrapper">
      <div class="post-thumbnail">
        <a href="<?php echo 'img/blogs/'.$get_blog->b_image.'?timestamp'.time() ?>" class="fancybox" rel="ligthbox">
          <img src="img/blogs/<?php echo $get_blog->b_image ?>" alt="" />
        </a>
      </div>
      <div class="post-information">
        <h2><?php echo $get_blog->b_title; ?></h2>
        <div class="entry-meta">
          <span class="author-meta">
            <i class="fa fa-user"></i>
            <b>
              <?php echo $get_blog->username ?>
              (<?php  
                if($get_blog->user_role=='admin' or $get_blog->user_role=='su_admin'){
                  echo "Admin";
                }
              ?>)
            </b>
          </span>
          <span>
            <i class="fa fa-clock-o"></i>
            <?php
              echo date("M j, Y", strtotime($get_blog->b_date_posted)) ;
              echo " / ";
              echo date("H:i A", strtotime($get_blog->b_date_posted)) ;
            ?>
          </span>
          <span class="tag-meta">
							<i class="fa fa-folder-o"></i>
							<a href="#"><?php echo $get_blog->b_category_name ?></a>,
							
						</span>
          <span><i class="fa fa-comments-o"></i> <a href="#"><?php echo $rowcountObj->rowcounter("blog_comments","*","b_id",$get_blog->b_id); ?> comment/s</a></span>
        </div>
        <div class="entry-content">
          <?php echo $get_blog->b_body; ?>
        </div>
      </div>
    </article>
    <div class="clear"></div>
    <div class="single-post-comments" >
      <div class="comments-area" id="single-post-comments">
        
      </div>
      <div class="comment-respond">
        <h3 class="comment-reply-title">Leave a comment </h3>
        <span class="email-notes">Your email address will not be published. Required fields are marked *</span>
        <form id="add_comment_form">
          <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
              <p>Name *</p>
              <input type="text" name="full_name" />
            </div>
            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
              <p>Email *</p>
              <input type="email" name="email" />
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 comment-form-comment">
              <p>Message</p>
              <textarea name="message" id="message-box" cols="30" rows="10"></textarea>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12 pt-2" id="add_comment_response"></div>
            <div class="col-lg-12 col-md-12 col-sm-12 py-2">
              <input type="hidden" name="add_comment_note" value="<?php echo $get_blog->b_id; ?>">
              <button type="submit" class="btn pb-2 px-3 rounded-pill btn-outline-info" onclick="add_blog_comment(<?php echo $get_blog->b_id; ?>)">Post Comment</button>
            </div>
          </div>
        </form>
      </div>
    </div>
    <!-- single-blog end -->
  </div>
</div>

<script type="text/javascript">
  $(document).ready(function(){
    load_blog_comments(<?php echo $get_blog->b_id ?>)
  })
</script>