<?php
session_start();
include 'header.php';
include 'connect.php';
date_default_timezone_set('Africa/Nairobi');
    $month = date('m');
    $msg = "";
    $message = '';
    
if(isset($_POST["mobile_no"]))
{
    $name  = $_POST["first_name"]." ".$_POST["last_name"];
    $grade = $_POST["grade"];
    $course  = $_POST["course"];	
    $tel = $_POST["mobile_no"];
    
    $sql = "SELECT * FROM lettersothers where telephone = '$tel' ";
    $result = mysqli_query($conn, $sql);
    $count = mysqli_num_rows($result);
    // $row = mysqli_fetch_array($result);
    // $simu = $row['telephone'];
    if ($count > 0){
        $message = "<div class='alert alert-danger'>Your application has already been submitted successfully.</div>";
    }
    else{
    $query = "INSERT INTO lettersothers (name, telephone, grade, course) VALUES ('$name', '$tel', '$grade', '$course') ";
    if(mysqli_query($conn, $query))
    {
        $message = "<div class='alert alert-success'>
            Your application has been submitted successfully. We will contact you via your provided mobile number: <b>$tel</b>.<br>
            You will be contacted soon.
            </div>";
    }
 
    else {
        // echo "ERROR: Could not able to execute $query. "   . mysqli_error($conn);
        $message ='<div class="alert alert-danger">There is an error in Registration... </div>';
 }
        
    }
}
?>
<html>
 <head>
   	<title>Registration for Admission | Virtual Learning</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
  <link rel = "icon" href = "rvibs_logo.png" type = "image/x-icon">
  
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>


  <style>
    .box{width:80%;margin:0 auto;}
    .active_tab1{background-color:#fff;color:#333;font-weight: 600;}
    .inactive_tab1{background-color: #f5f5f5;color: #333;cursor: not-allowed;}
    .has-error{border-color:#cc0000;background-color:#ffff99;}
    .user{color:#0d4f81; background:#0d4f81; text-align: center; font-weight: bold; font-size:18px;}
    .user3 {color:white;}
    body{background-color:#eef5e4;}
    .bs-example{margin: 5px;}
    .accordion .fa{margin-right: 0.5rem;}
    .center_div{margin: 0 auto; width:20%}
    .mt{margin-top: 4px;}
  </style>
  
 </head>
 <body>

<div class="container">
<div class="container-fluid">
<div class="row">
<div class="col-md-6 mx-auto" style="background-color:;">

    <h4><center><b><u>Admissions Application</u></b></center></h4>

   <?php echo $message; ?>
   <form method="post" id="register_form" enctype="multipart/form-data">
      <div class="panel panel-default">
       <div class="panel-heading">Fill to complete application</div>
       <div class="panel-body">
        <div class="row">
        <div class="col-sm-12 col-md-6">    
        <label>First Name</label><span style="color:red">*</span>
        <input type="text" name="first_name" id="first_name" class="form-control" placeholder="First Name"/>
        </div>
        
        <div class="col-sm-12 col-md-6">
        <label>Last Name</label><span style="color:red">*</span>
         <input type="text" name="last_name" id="last_name" class="form-control" placeholder="Last Name"/> 
         </div>
         </div>
        <br>

    
    <div class="row">
        <div class="col-sm-12 col-md-6">
            <label>Telephone</label><span style="color:red">*</span>
            <input type="text" name="mobile_no" id="mobile_no" class="form-control" placeholder="07xxxxxxxxx"/>
        </div>
        <div class="col-sm-12 col-md-6">
            <label>Grade</label><span style="color:red">*</span>
            <select type="text" name="grade" id="grade" class="form-control">
                <option selected disabled></option>
                <option value ="A">A</option>
                <option value ="A-">A-</option>
                <option value ="B+">B+</option>
                <option value ="B">B</option>
                <option value ="B-">B-</option>
                <option value ="C+">C+</option>
                <option value ="C">C</option>
                <option value ="C-">C-</option>
                <option value ="D+">D+</option>
                <option value ="D">D</option>
                <option value ="D-">D-</option>
                <option value ="E">E</option>
                <option value ="KCPE">KCPE</option>
                <option value ="OTHER">OTHER</option>
                <option DISABLED></option>
            </select>    
        </div>
    </div>
    <br>
    
    <div class="row">
        <div class="col-sm-12 col-md-12">
            <label>Course</label><span style="color:red">*</span>
            <select id="course" name="course"  class="form-control" onchange="showUser(this.value);">
             <option disabled selected>SELECT A COURSE</option>
             <option disabled></option>
             <?php
            include 'config.php';
            $sql1 = "SELECT distinct course FROM courses order by course asc ";      
            if($result1 = mysqli_query($connect, $sql1)){
            if(mysqli_num_rows($result1) > 0){
            echo  '<optgroup label="COURSES">'.'</optgroup>';
            echo  '<option disabled>'.'</optgroup>';
            while($row1 = mysqli_fetch_array($result1, MYSQLI_ASSOC)){
                echo  '<option value="'.$row1["course"].'">'.$row1["course"].'</option>';
        }}}
        
            ?>
              <option disabled></option>
            </select>    
        </div>
    </div>
    <br>

        <div align="center">
            <button type="button" name="btn_contact_details" id="btn_contact_details" class="btn btn-primary btn-m">SUBMIT</button>
        </div>
      </div>
     </div>
    
     <div class="col-sm-12 col-md-12 text-center">
        <p>Follow us on:</p>
        <a href="https://wa.me/254715111101" target="_blank"> <button type="button" class="btn btn-primary btn-floating mx-1">
        <i class="fa fa-whatsapp"></i>
        </button></a>
        
       <a href="https://www.facebook.com/rvibs/" target="_blank"> <button type="button" class="btn btn-primary btn-floating mx-1">
        <i class="fa fa-facebook-f"></i>
        </button></a>

        <a href="https://www.youtube.com/channel/UCEFbrwEKfkkrFeKW8zZZudg" target="_blank"><button type="button" class="btn btn-primary btn-floating mx-1">
        <i class="fa fa-youtube"></i>
        </button></a>

        <a href="https://twitter.com/riftrvibs" target="_blank"><button type="button" class="btn btn-primary btn-floating mx-1">
        <i class="fa fa-twitter"></i>
        </button></a>

        <a href="https://www.instagram.com/rvibs_/" target="_blank"><button type="button" class="btn btn-primary btn-floating mx-1">
        <i class="fa fa-instagram"></i>
        </button></a>
        
         &nbsp;&nbsp;&nbsp;

        <a href="https://rvibs.ac.ke/" target="_blank"> <button type="button" class="btn btn-success btn-floating mx-1">
        Main Website
        </button></a>

    </div>
   

   </form>
 </div>
 
 <!--<div class="col-md-6 d-sm-none d-md-block" style="background-color:;">-->
 <!--        <br><br>-->
 <!--       <img src="img1.png" width="100%" height="">-->
 <!--   </div>-->

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

 
<script>
$(document).ready(function(){
 
 $('#btn_contact_details').click(function(){
    var error_first_name = '';
    var error_last_name = '';
    var error_mobile_no = '';
    var mobile_validation = /^\d{10}$/;
    var error_grade = '';
    var error_course = '';
  
  if($.trim($('#first_name').val()).length == 0)
  {
   error_first_name = 'First Name is required';
   $('#error_first_name').text(error_first_name);
   $('#first_name').addClass('has-error');
  }
  else
  {
   error_first_name = '';
   $('#error_first_name').text(error_first_name);
   $('#first_name').removeClass('has-error');
  }
  
  
  if($.trim($('#last_name').val()).length == 0)
  {
   error_last_name = 'Last Name is required';
   $('#error_last_name').text(error_last_name);
   $('#last_name').addClass('has-error');
  }
  else
  {
   error_last_name = '';
   $('#error_last_name').text(error_last_name); 
   $('#last_name').removeClass('has-error');
  }
  
  if(error_first_name != '' || error_last_name != ''){ return false; }
  


    if($.trim($('#mobile_no').val()).length == 0)
  {
   error_mobile_no = 'Mobile Number is required';
   $('#error_mobile_no').text(error_mobile_no);
   $('#mobile_no').addClass('has-error');
  }
  else
  {
   if (!mobile_validation.test($('#mobile_no').val()))
   {
    error_mobile_no = 'Invalid Mobile Number';
    $('#error_mobile_no').text(error_mobile_no);
    $('#mobile_no').addClass('has-error');
   }
   else
   {
    error_mobile_no = '';
    $('#error_mobile_no').text(error_mobile_no);
    $('#mobile_no').removeClass('has-error');
   }
  }
  
    if($.trim($('#grade').val()).length == 0)
  {
   error_grade = 'Fill grade';
   $('#error_grade').text(error_grade);
   $('#grade').addClass('has-error');
  }
  else
  {
   error_grade = '';
   $('#error_grade').text(error_grade);
   $('#grade').removeClass('has-error');
  }

 
  if(error_grade != '' || error_mobile_no!= ''){ return false; }
  
 if($.trim($('#course').val()).length == 0)
  {
   error_course = 'course is required';
   $('#error_course').text(error_course);
   $('#course').addClass('has-error');
  }
  else
  {
   error_course = '';
   $('#error_course').text(error_course);
   $('#course').removeClass('has-error');
  }
  
 if(error_course != '' ) { return false; }
 

  else { $("#register_form").submit();}
  
 });
 
});

</script>
    