<?php

    include('../../config/config.php');
    
    $class = $_POST['abba_get_class'];
    $term = $_POST['abba_get_term'];
    $result_type = $_POST['abba_get_result_type'];
    $studentId = $_POST['student_id'];
    $camp = $_POST['campus_id'];
    $institution_id = $_POST['institution_id'];
    $usertype = $_POST['usertype'];
    
    $sql_session = ("SELECT * FROM `classordepartmentstudentallocation` WHERE ClassOrDepartmentID = '$class' AND StudentID = '$studentId'");
	$result_session = mysqli_query($link, $sql_session);
	$row_session = mysqli_fetch_assoc($result_session);
	$row_cnt_session = mysqli_num_rows($result_session);
	
    $session = $row_session['Session'];
    
    // Plain text to encrypt
    $plain_text = 'class=' . $class . '&term=' . $term . '&session=' . $session . '&camp=' . $camp . '&studentid='.$studentId.'&usertype='.$usertype.'&result_type='.$result_type.'';

    // Secret key (32 bytes for AES-256, adjust as per the encryption algorithm)
    $secret_key = "16-character-secret"; // Replace with your secure secret key

    // Encryption algorithm and mode (AES-256 CBC)
    $encryption_algo = "AES-256-CBC";

    // Initialization vector (IV) - random bytes for each encryption
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($encryption_algo));

    // Perform encryption
    $encrypted_data = openssl_encrypt($plain_text, $encryption_algo, $secret_key, OPENSSL_RAW_DATA, $iv);

    // Combine IV and cipher text for storage/transfer
    $encrypted_message = base64_encode($iv . $encrypted_data);

    // Create the URL with the encrypted data and encryption algorithm
    $encoded_message = urlencode($encrypted_message);
    echo $encrypted_url = $defaultUrl."app/academics/check-result/?const=" . $encoded_message;
?>