<?php
  /**** this section displays users details*****/
  session_start();
  include_once('../../config/config.php');
  $user_id=$_SESSION['user_id'];

  //select statement
  $statement="select * from success_stories a, system_users b where a.posted_by=b.user_id order by a.date desc";

  try{
    $sql=$db->query($statement);
    if($sql){

  ?>

 <table id="order-listing" class="table table-striped table-bordered table-sm">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>Title</th>
                        <th>Date Posted</th>
                        <th>Posted By</th>
                        <th>Action</th>
                      </tr>
                    </thead>
<?php
    echo"<tbody>";
    $i=0;
    while ($row=$sql->fetch()) {
      $date  = strtotime($row['date']);
      $new_d = date('d M,Y',$date);
      $i++;
      echo "
      <tr>
        <td>".$i."</td>
       <td>".$row['title']."</td>
       <td>".$new_d."</td>
       <td>".$row['first_name']." ".$row['last_name']."</td>
       <td>"; ?>
       <div class="btn-toolbar mb-2 mb-md-0">
              <div class="btn-group mr-2">
                <?php
                  if($row['status'] == 0){
                ?>
                <button class="btn btn-sm btn-outline-success show_btn" id="show_btn" name="show_btn" data-id3="<?php echo $row["story_id"]; ?>" ><i class="fa fa-search"></i> Show</button>
                <?php
                  }else{
                ?>
                 <button class="btn btn-sm btn-outline-warning hide_btn" name="hide_btn" data-id3="<?php echo $row["story_id"]; ?>" ><i class="icon icon-trash"></i> Hide</button>
                <?php
                  }
                ?>
                <a href="update-story.php?story_id=<?=$row["story_id"]?>" class="btn btn-sm btn-outline-primary edit_btn"><i class="icon icon-edit"></i> Update</a>

                <button class="btn btn-sm btn-outline-danger btn_delete" name="delete_btn" data-id3="<?php echo $row["story_id"]; ?>" ><i class="icon icon-trash"></i> Delete</button>
              </div>
            </div>

      <?php echo" </td>
      </tr>"
      ;
    }
    echo"</tbody>";

  }
  else{
    echo"<tr><td colspan='6'>There are no system users users</td></tr>";
  }
?>
</table>

  <?php
  }
  catch(PDOException $e){
    $e->getMessage();
  }
?>



 <script>
    (function($) {
      'use strict';
      $(function() {
        $('#order-listing').DataTable({
          "aLengthMenu": [
          [5, 10, 15, -1],
          [5, 10, 15, "All"]
          ],
          "iDisplayLength": 10
        });
      });
    })(jQuery);
  </script>
