<?php 
include 'header.php';

            if($_GET['key'] && $_GET['token'])
            {
              include "config.php";
              $email = $_GET['key'];
              $token = $_GET['token'];
              $query = mysqli_query($connection,
              "SELECT * FROM `applications` WHERE `token`='".$token."' and `email`='".$email."';"
              );

                if (mysqli_num_rows($query) > 0) {
                   
                  $row= mysqli_fetch_array($query);

                   if($row['email_status'] == 0){
                    mysqli_query($connection,"UPDATE applications set email_status = 1 WHERE email= '$email'");
                    $msg_success = "Congratulations";
                    $msg = "Congratulations for Joining RVIBS Virtual School";
                     header( "refresh:3;url=https://vschool.rvibs.ac.ke/portal/dashboard.php" );
                   }else{
                      header( "refresh:3;url=https://vschool.rvibs.ac.ke/portal/dashboard.php" );
                    $msg_success = "Congratulations";
                    $msg = "Congratulations for Joining RVIBS Virtual School";
                   }
     
                } else {
                    header( "refresh:3;url=https://vschool.rvibs.ac.ke" );
                    $msg_success = "An error Occurred..!";
                    $msg = "This email has not been registered with us";
                }
                        
              }
              else{
                  header( "refresh:3;url=https://vschool.rvibs.ac.ke" );
                $msg_success = "An error Occurred..!";
                $msg = "Error! Something has gone wrong.";
                 }
                        
            ?>
            
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
       <style>
          .p1{ font-size :27px};
      </style>
   </head>
   <body>
          
      <div class="container mt-3">
          <div class="card">
            <div class="card-header text-center p1"><?php echo $msg_success; ?> </div>
            <div class="card-body"><p><?php echo $msg; ?></p></div>
          </div>
      </div>

   </body>
</html>