<?php 
    include("../db.php");
    
    //insert
   if(isset($_POST['title'])){
     
         $db->insertAry("announcements", $_POST);
            
        
        header("Location: announcement");
   }
          
    
    //end
if($_GET['action']=="delete" && isset($_GET['id']) && trim($_GET['id'])!='' ){
    
    
 	$res=$db->delete("announcements","where id='".$_GET['id']."' ");
     header("Location: announcement");
}
    
    
   
?>

<!DOCTYPE html>
<html>
<head>
      <title>Admin Dashboard</title>
    <?php include("meta.php"); ?>

</head>
<body> 
 
<?php include("header.php"); ?>

<?php include("sidebar.php"); 

    $data = $db->getRows("select * from announcements  ");

?>

<div class="main">
    
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="content-div">
                    <h2>ANNOUNCEMENT</h2>
                    <div>
                    <button  style="background: blue;color: white;font-size: 25px;" data-toggle="modal" data-target="#exampleModal">+Add New</button>
                    </div>
                    <table class="table table-hover">
  <thead class="bg-black text-white font-weight-bold ml-3" style="font-size: 15px;">
    <tr>
        <th scope="col">S.No</th>
            <th scope="col">Title</th>

      <th scope="col">Description</th>
      <th scope="col">Added on</th>
      <th scope="col">Action</th>
    </tr>
  </thead>
  <tbody>
      <?php 
      $i=0;
      foreach($data as $res){$i++
          
          ?>
           <tr >
      <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $i ; ?></th>
      <th  style="font-weight: 600; color: green;padding: 0.75rem;" ><?php echo $res['title'];?></th>
      <th style="padding: 0.75rem;" ><?php echo $res['description'];?></th>
       <th style="padding: 0.75rem;" ><?php echo $res['entrytime'];?></th>
     <td><a href="announcement?action=delete&id=<?php echo $res['id']; ?>" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i></a></td>
    </tr>
    <?php  }?>
   
  
  </tbody>
</table>



<!-- Modal add -->
<div class="modal fade " id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Add Announcement</h5>
        
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="" method="post" >
    <div class="form-group">
    <label for="exampleInputEmail1">Title</label>
    <input type="text" class="form-control" name="title" required  placeholder="Enter title">
    
  </div>
  <div class="form-group mt-3">
    <label for="exampleInputPassword1">Description</label>
    <input type="text" class="form-control" name="description" required placeholder="description">
  </div>

  <button type="submit"  class="btn btn-success mt-4">Save</button>
</form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
       
      </div>
    </div>
  </div>
</div>
              
             
                </div>

            </div>   
        </div>
    </div>
    
</div>
     
</body>
</html> 
