<?php 
include('header.php');

if($_SESSION['userid'] != "ADMIN"){
  ?>
  <script>
      window.location.href='index.php';
  </script>
  <?php
  die;

}
if (isset($_POST['txn_form']) && $_POST['txn_form'] == "ahkwebsolutions"  ){
  
  $newstitle = mysqli_real_escape_string($conn, $_POST['newstitle']);
  $link = mysqli_real_escape_string($conn, $_POST['link']);

  $res = mysqli_query($conn,"INSERT INTO `newsline`(`newstitle`, `link`) VALUES ('$newstitle','$link')");
  if($res){
      ?>
      <script>
          $(function(){
              Swal.fire(
                  'Success',
                  'Notification Send Successfully',
                  'success'
              )

          });
           
  window.setTimeout(function() {
  window.location.href = "index.php";
  }, 1500);
      </script>
      <?php
  }else{
      ?>
      <script>
          $(function(){
              Swal.fire(
                  'Opps',
                  'Internal Server Problem Please Try Again Lates!',
                  'error'
              )

          });
      </script>
      <?php

  }
  
}
?>
<!-- Begin Page Content -->
<div class="container-fluid">

<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-gray-800">ADD NOTOFICATIONS</h1>
    <a href="#" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i
            class="fas fa-download fa-sm text-white-50"></i> Generate Report</a>
</div>

<!-- Content Row -->
<div class="row">

  
    <!-- Pie Chart -->
    <div class="col-xl-13 col-lg-5">
      
            <!-- Card Body -->
          
            
            <div class="card card-default">
              <div class="card-header">
               
                <h6 class="card-title m-0 font-weight-bold text-danger"><i class="fas fa-bullhorn"></i> ADD NOTIFICATIONS MESSAGE  <?php echo $_SESSION['name'] ?></h6>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
                <div class="callout callout-danger">
                  <h5>SEND NOTIFICATIONS</h5>
                </div>
                <form action="" name="newsline" method="POST">
          <div class="input-group mb-3">
            <input type="text" class="form-control" style="text-transform:uppercase" id="newstitle" name="newstitle" placeholder="news title"value="" required="">
            <input type="hidden" name="txn_form" value="ahkwebsolutions">
            <div class="input-group-append">
              <div class="input-group-text">
                <span class="fas fa-user"></span>
              </div>
            </div>
          </div>
          
          <div class="input-group mb-3">
          <input type="text" class="form-control" id="link"  name="link" placeholder="link or message"value="" required="">
            <div class="input-group-append">
              <div class="input-group-text">
                <span class="fas fa-envelope"></span>
              </div>
            </div>
          </div>
        
          
            <div class="input-group mb-3">
              <button type="submit" class="btn btn-primary btn-block">SEND NOTIFICATION</button>
              <div class="input-group-append">
            </div>
            <!-- /.col -->
          </div>
        </form>
        
                </div>
                </div>
                <br> </br>
                </div>
              <!-- /.card-body -->
            



         <div class="col-md-12">
        <div class="card">
          <div class="card-header p-2">
            <ul class="nav nav-pills">
              <li class="nav-item"><a class="nav-link active" href="#wallet-history" data-toggle="tab">ALL NOTIFICATION</a></li>
            </ul>
          </div><!-- /.card-header -->
          <div class="card-body">
            <div class="tab-content">
              <div class="active tab-pane" id="wallet-history">
                
	                <table id="tb-wallet" class="table table-bordered table-hover">
	                  <thead>
	                  <tr>
	                    <th class="text-center" style="width: 40px;">ID</th>
	                    <th class="text-center" >Nwes Ttile</th>
	                    
	                    <th class="text-center" >link </th>
	                    <th class="text-center">Date</th>
	                    <th class="text-center" style="width:100px;">action</th>
	                  </tr>
	                  </thead>
	                  <tbody>
	                      <?php
	                      
if (isset($_POST['delete']) && $_POST['delete'] == "ahkwebsolutions") {
    $id = base64_decode($_POST['id']);
    $del = mysqli_query($conn, "DELETE FROM `newsline` WHERE id='$id'");
    if ($del) {
    ?>
        <script>
            $(function() {
                Swal.fire(
                    'Success',
                    'Data Deleted Success!',
                    'success'
                )
            });
            window.setTimeout(function() {
  window.location.href = "notifi.php";
  }, 1500);
        </script>
    <?php
    } else {
    ?>
        <script>
            $(function() {
                Swal.fire(
                    'Opps',
                    'Data Not Deleted !',
                    'error'
                )
            });
        </script>
<?php
    }
}
?>
                      <?php 
                      
                      $dres = mysqli_query($conn,"SELECT * FROM `newsline` ");
                      if(mysqli_num_rows($dres)>0){
                        while($data = mysqli_fetch_assoc($dres)){
                            ?>
                            <tr>
                          
                          <td><?php echo $data['id'] ?></td>
                          <td class="text-bold"><?php echo $data['newstitle'] ?></td>
                          <td><?php echo $data['link'] ?></td>
                        
                          <td><?php echo $data['date'] ?></td>
                            <td> <form action="" method="post" class="d-inline">
                                                        <input type="hidden" name="id" value="<?php echo base64_encode($data['id'])  ?>">
                                                        <input type="hidden" name="delete" value="ahkwebsolutions"> <input type="hidden" name="_method" value="DELETE"> <button type="button" class="btn btn-danger btn-sm ml-2" onclick="deleteRecord(this)"><i class="fa fa-trash"></i></button>
                                                    </form></td>
                         
                        
                        </tr>
                            <?php
                        }
                      }
                      ?>
                        
	                  
	                  </tfoot>
	                </table>

              </div>
              <!-- /.tab-pane -->

            </div>
            <!-- /.tab-content -->
          </div><!-- /.card-body -->
        </div>
        <!-- /.card -->
      </div>
      <!-- /.col -->
    </div>
     </div>
      </div>
    <!-- /.row -->
    
	</div><!-- /.container-fluid -->






<!-- /.container-fluid -->

</div>
<!-- End of Main Content -->
<?php include "footer.php";?>