
<?php
include "header.php";
//include_once('controllers/database.php');

//include('models/retrieve-data.php');
date_default_timezone_set('Africa/Lagos');


if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $user_ip = $SERVER['HTTP_CLIENT_IP'] ?? ($_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR']);
    // Process comprehensive form logic
    $programme = isset($_POST['programme']) ? mysqli_real_escape_string($conn, $_POST['programme']) : '';
    $firstname = isset($_POST['firstname']) ? mysqli_real_escape_string($conn, $_POST['firstname']) : '';
    $middlename = isset($_POST['middlename']) ? mysqli_real_escape_string($conn, $_POST['middlename']) : '';
    $surname = isset($_POST['surname']) ? mysqli_real_escape_string($conn, $_POST['surname']) : '';
    $dob = isset($_POST['dob']) ? mysqli_real_escape_string($conn, $_POST['dob']) : '';
    $age = 0;
    $sex = isset($_POST['sex']) ? mysqli_real_escape_string($conn, $_POST['sex']) : '';
    $religion = isset($_POST['religion']) ? mysqli_real_escape_string($conn, $_POST['religion']) : '';
    $maritalstatus = isset($_POST['maritalstatus']) ? mysqli_real_escape_string($conn, $_POST['maritalstatus']) : '';
    $phone = isset($_POST['phone']) ? mysqli_real_escape_string($conn, $_POST['phone']) : '';
    $email = isset($_POST['email']) ? mysqli_real_escape_string($conn, $_POST['email']) : '';
    $address = isset($_POST['address']) ? mysqli_real_escape_string($conn, $_POST['address']) : '';
    $nationality = isset($_POST['nationality']) ? mysqli_real_escape_string($conn, $_POST['nationality']) : '';
    $state = isset($_POST['state']) ? mysqli_real_escape_string($conn, $_POST['state']) : '';
    $lga = isset($_POST['lga']) ? mysqli_real_escape_string($conn, $_POST['lga']) : '';
    $parentname = isset($_POST['parentname']) ? mysqli_real_escape_string($conn, $_POST['parentname']) : '';
    $parentoccupation = isset($_POST['parentoccupation']) ? mysqli_real_escape_string($conn, $_POST['parentoccupation']) : '';
    $parentphone = isset($_POST['parentphone']) ? mysqli_real_escape_string($conn, $_POST['parentphone']) : '';
    $parentemail = isset($_POST['parentemail']) ? mysqli_real_escape_string($conn, $_POST['parentemail']) : '';
    $remarkaboutstudent = isset($_POST['remarkaboutstudent']) ? mysqli_real_escape_string($conn, $_POST['remarkaboutstudent']) : '';
    $generalcomment = isset($_POST['generalcomment']) ? mysqli_real_escape_string($conn, $_POST['generalcomment']) : '';
    $challenges = isset($_POST['challenges']) ? mysqli_real_escape_string($conn, $_POST['challenges']) : '';
    $allergies = isset($_POST['allergies']) ? mysqli_real_escape_string($conn, $_POST['allergies']) : '';
    $bloodgroup = isset($_POST['bloodgroup']) ? mysqli_real_escape_string($conn, $_POST['bloodgroup']) : '';
    $genotype = isset($_POST['genotype']) ? mysqli_real_escape_string($conn, $_POST['genotype']) : '';
    $passportphoto = isset($_POST['passportphoto']) ? mysqli_real_escape_string($conn, $_POST['passportphoto']) : '';
    $olevelresult = isset($_POST['olevelresult']) ? mysqli_real_escape_string($conn, $_POST['olevelresult']) : '';
    $birthcertificate = isset($_POST['birthcertificate']) ? mysqli_real_escape_string($conn, $_POST['birthcertificate']) : '';
    $otherdocument = isset($_POST['otherdocument']) ? mysqli_real_escape_string($conn, $_POST['otherdocument']) : '';
    $username = isset($_POST['username']) ? mysqli_real_escape_string($conn, $_POST['username']) : '';
    $password = isset($_POST['password']) ? mysqli_real_escape_string($conn, $_POST['password']) : '';


    $year = date('Y');
    $studentYear = substr($dob, 0, 4);
    $age = ($year - $studentYear);

 $applications = [
        [
            'key' => 'admission_no',
            'value' => 'SCA',
            'param' => 's'
        ],
        [
            'key' => 'programme',
            'value' => $programme,
            'param' => 's'
        ],
        [
            'key' => 'firstname',
            'value' => $firstname,
            'param' => 's'
        ],
        [
            'key' => 'middlename',
            'value' => $middlename,
            'param' => 's'
        ],
        [
            'key' => 'surname',
            'value' => $surname,
            'param' => 's'
        ],
        [
            'key' => 'dob',
            'value' => $dob,
            'param' => 's'
        ],
        [
            'key' => 'age',
            'value' => $age,
            'param' => 'i'
        ],
        [
            'key' => 'sex',
            'value' => $sex,
            'param' => 's'
        ],
        [
            'key' => 'religion',
            'value' => $religion,
            'param' => 's'
        ],
        [
            'key' => 'maritalstatus',
            'value' => $maritalstatus,
            'param' => 's'
        ],
        [
            'key' => 'phone',
            'value' => $phone,
            'param' => 's'
        ],
        [
            'key' => 'email',
            'value' => $email,
            'param' => 's'
        ],
        [
            'key' => 'address',
            'value' => $address,
            'param' => 's'
        ],
        [
            'key' => 'nationality',
            'value' => $nationality,
            'param' => 's'
        ],
        [
            'key' => 'state',
            'value' => $state,
            'param' => 's'
        ],
        [
            'key' => 'lga',
            'value' => $lga,
            'param' => 's'
        ],
        [
            'key' => 'parentname',
            'value' => $parentname,
            'param' => 's'
        ],
        [
            'key' => 'parentoccupation',
            'value' => $parentoccupation,
            'param' => 's'
        ],
        [
            'key' => 'parentphone',
            'value' => $parentphone,
            'param' => 's'
        ],
        [
            'key' => 'parentemail',
            'value' => $parentemail,
            'param' => 's'
        ],
        [
            'key' => 'remarkaboutstudent',
            'value' => $remarkaboutstudent,
            'param' => 's'
        ],
        [
            'key' => 'generalcomment',
            'value' => $generalcomment,
            'param' => 's'
        ],
        [
            'key' => 'challenges',
            'value' => $challenges,
            'param' => 's'
        ],
        [
            'key' => 'allergies',
            'value' => $allergies,
            'param' => 's'
        ] ,
        [
            'key' => 'bloodgroup',
            'value' => $bloodgroup,
            'param' => 's'
        ],
        [
            'key' => 'genotype',
            'value' => $genotype,
            'param' => 's'
        ],
        [
            'key' => 'passportphoto',
            'value' => $passportphoto,
            'param' => 's'
        ],
        [
            'key' => 'olevelresult',
            'value' => $olevelresult,
            'param' => 's'
        ],
        [
            'key' => 'birthcertificate',
            'value' => $birthcertificate,
            'param' => 's'
        ] ,
        [
            'key' => 'otherdocument',
            'value' => $otherdocument,
            'param' => 's'
        ],
        [
            'key' => 'username',
            'value' => $username,
            'param' => 's'
        ],
        [
            'key' => 'password',
            'value' => $password,
            'param' => 's'
        ],
        [
            'key' => 'user_ip',
            'value' => $user_ip,
            'param' => 's'
        ]
    ];



insertRecord($conn, 'applications', $applications);
//header("Location: index.html");


$prefix = '#SCA'; // Customize the prefix as needed


// Retrieve existing rows
$query = "SELECT id FROM applications";
$result = mysqli_query($conn, $query);

if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        $admission_no = $prefix . $row['id'];

        // Update the row with the generated booking ID
        $updateQuery = "UPDATE applications SET admission_no = '$admission_no' WHERE id = " . $row['id'];
        mysqli_query($conn, $updateQuery);




    }

    // Free result set
    mysqli_free_result($result);
} else {
    echo "Error retrieving data: " . mysqli_error($conn);
}








}


$fullname = $surname . ' ' .$firstname . ' '. $middlename;



?>
<!doctype html>
<html class="no-js" lang="zxx">

<head>

</head>

<body>


  <main>


      <!-- breadcrumb-area -->
      <section class="breadcrumb__area include-bg pt-150 pb-150 breadcrumb__overlay" data-background="assets/img/alevels/13.jpg">
         <div class="container">
            <div class="row">
               <div class="col-xxl-12">
                  <div class="breadcrumb__content p-relative z-index-1">
                     <h3 class="breadcrumb__title mb-20">Your Registraton Was Successful</h3>
                     <div class="breadcrumb__list">
                        <span><a href="index.html">Home</a></span>
                        <span class="dvdr"><i class="fa-regular fa-angle-right"></i></span>
                        <span class="sub-page-black">Successful Registration</span>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </section>
      <!-- breadcrumb-area-end -->

      <!-- login-area-strat -->
      <section class="login-area pt-100 pb-100">
         <div class="container">
               <div class="row">
                  <div class="col-lg-8 offset-lg-2">
                     <div class="basic-login">
                           <h3 class="text-center mb-60">Congratulations,    <?= $fullname; ?> <br> <span style="color:green">Your form has been submitted successfully!</span></h3>
                           <p>Your Application form for <span ><?= $programme; ?> </span> has been submitted Successfully!</p>
                           <h5>If you are paying the tuition in full, Please pay into the Account Below </h5>
                           <div class="col-xl-5 col-lg-5 d-none d-lg-block">

                     </div>
                           <h6 class="account">Bank:  Union Bank Plc    <br>
                           Name:   St. Catherine’s Schools Ltd <br>
                           Account No.:   0074647940</h6>

                           <p>Then Send Evidence of Payment to Us Via Whatsapp via <a href="https://wa.me/+23490909099796">+234 (909) 090 9979</a> </p>
                           <h6>If you are not paying the tuition in full, Kindly <a href="undertakenform.html" target="_blank">click Here</a> to fill an Undertaken Form.</h6>
                           <p>Congrats Once Again!</p>

                           <button class="tp-btn w-100">Fill Undertaken Form</button>
                              <div class="or-divide"><span>or</span></div>
                           <a href="index.html" class="tp-border-btn w-100">Return Home</a>

                     </div>
                  </div>
               </div>
         </div>
      </section>
      <!-- login-area-strat-end -->


   </main>

  <!-- footer-area -->
          <?php  include "footer.php" ?>
      <!-- footer-area-end -->





   <!-- JS here -->
   <script src="assets/js/vendor/jquery.js"></script>
   <script src="assets/js/vendor/waypoints.js"></script>
   <script src="assets/js/bootstrap-bundle.js"></script>
   <script src="assets/js/meanmenu.js"></script>
   <script src="assets/js/slick.js"></script>
   <script src="assets/js/magnific-popup.js"></script>
   <script src="assets/js/parallax.js"></script>
   <script src="assets/js/backtotop.js"></script>
   <script src="assets/js/nice-select.js"></script>
   <script src="assets/js/counterup.js"></script>
   <script src="assets/js/wow.js"></script>
   <script src="assets/js/isotope-pkgd.js"></script>
   <script src="assets/js/imagesloaded-pkgd.js"></script>
   <script src="assets/js/ajax-form.js"></script>
   <script src="assets/js/main.js"></script>
</body>

</html>
