<?php

include 'db_connect.php';

$id = $_POST[ 'id' ];
$status = $_POST[ 'status' ];
$key = $_POST[ 'key' ];

$security_key = decrypData( $key );

if ( $security_key == 'Jobayer121415' && strlen( $id )>0 ) {

    $con = dbConnect();

    $sql = "UPDATE singup_table SET online = '$status' WHERE id = '$id'";
    $result = mysqli_query ( $con, $sql );
    
    $sql1 = "UPDATE post_table SET online = '$status' WHERE userid = '$id'";
    $result1 = mysqli_query ( $con, $sql1 );

    if ( $result && $result1) {
        echo 'Successfully';
    } else {
        echo'Qury Error';
    }

} else {
    echo json_encode( [ 'error' => 'Invalid key or password' ] );
}

function decrypData ( $text ) {

    $encoded = $text;
    $decoded = base64_decode( $encoded );
    $decrypted = openssl_decrypt( $decoded, 'AES-128-ECB', '0175526800812345', OPENSSL_RAW_DATA );
    return $decrypted;

}

?>