<?php
// exit("Watch out for the next PROMO EVENT");
session_start();
require('app/app.php');

// ensure_user_is_authenticated();

if (is_post()) {
$fname = sanitize($_POST['firstName']);
$minitial = sanitize(isset($_POST['middleInitial']) ? $_POST['middleInitial'] : '');
$lname = sanitize($_POST['lastName']);
$address = sanitize($_POST['address']);
$age = sanitize($_POST['age']);
$registeredEmail = sanitize($_POST['registeredMail']);
$contactNumber = sanitize($_POST['contactNumber']);

// $dname = sanitize($_POST['dealerName']);
$unitName = sanitize($_POST['unitName']);
$dateOfPurch = sanitize($_POST['dateOfPurch']);
$receiptNumber = sanitize($_POST['receiptNumber']);
$receiptAmount = sanitize($_POST['receiptAmount']);
$proofPurchase = $_FILES['file-input'];



    // require_once 'sn.php';
    require_once 'pof.php';

    // $promoCode = 'PK-' . getCode(20);


    // checking for serial number that already used!
    if(Data::select_record_registered($receiptNumber)) {
      // echo '<p>The Serial Number has been registered already!</p>';
      $_SESSION['err_message']= "<p>The Serial Number has already registered!</p>";
      // header('location: error-message.php, true, 301');

      // $script = file_get_contents('js/snUsed.js');
      echo "<script>window.location.href='error.php' </script>";
    }
    elseif(!in_array($file_extension, $allowed)){
      // exit('<p>Upload valid images. Only PNG , JPG and JPEG are allowed.</p>');
      $_SESSION['err_message']= "<p>Upload valid images. Only PNG , JPG and JPEG are allowed.</p>";
      echo "<script>window.location.href='error.php' </script>";
      }elseif
  // checking for the file size of image
      ($proofPurchase["size"] > 10000000) {
      // exit('<p>Image size for Proof of Purchase exceeds 10MB!</p>');
      $_SESSION['err_message']= "<p>Image size for Proof of Purchase exceeds 10MB!</p>";
      echo "<script>window.location.href='error.php' </script>";
      } else {
  Data::add_record($fname,
    $minitial,
    $lname,
    $address,
    $age,
    $registeredEmail,
    $contactNumber,
    $unitName,
    $dateOfPurch,
    $receiptNumber,
    $receiptAmount,
    $target
    );



  $_SESSION['success_message'] = "<h2>Welcome to the GameXtreme Holiday XP E-Raffle Promo, $fname  $lname! 🎉!</h2>
        <p>Thank you for registering and submitting your raffle entry. Your official promo code will be sent directly to your registered email address.
        </p>
        <p><span>Note:</span> All customers who register and purchase during the promo period are eligible to participate in this raffle promotion.
        </p>
        <p>
        📅 Promo Duration:
        November 20, 2025 – January 15, 2026
        </p>
        <p>
        📅 🕒 Deadline for Submission of Entries:
        January 15, 2026 | 11:59 PM

        </p>

        <p>Per DTI FTEB Permit No. ______, Series of 2025.</p>";

        // header("location: completed-registration.php, true, 301");
        echo "<script>window.location.href='registered.php' </script>";
  // redirect('./');
}
  //   }
}

$item = Data::get_record_item();

view('admin/create', $item);
