<?php require __DIR__ . '/init.php';

$insecure = array();

$insecure[] = ( $_POST['nonce'] !== uss::nonce( $_SESSION['uss_session_id'] ) );
$insecure[] = empty($_POST['nx']);
$insecure[] = empty($_POST['nonce']);
$insecure[] = empty($_POST['action']);

foreach( $insecure as $sure ) {
	if( $sure ) uss::stop( false, "Security Breach Detected" );
};

// ------------- [{ Now Process }] --------------

$_POST['nx'] = array_map( array(uss::$global['mysqli'], 'real_escape_string'), $_POST['nx'] );

$keys = implode( ", ",  $_POST['nx'] );

$prefix = DB_TABLE_PREFIX;


// ------------- [{ Handle Request }] -------------

switch( $_POST['action'] ) {
	
	case 'viewed':
	case 'view':
			
			$SQL = sQuery::update( "{$prefix}_notifications", array( "viewed" => 1 ), "id IN( {$keys} )" );
		
		break;
		
	case 'removed':
	case 'remove':
	
			$SQL = sQuery::update( "{$prefix}_notifications", array( 'hidden' => 1 ), "id IN( {$keys} )" );
	
		break;
		
};


$status = uss::$global['mysqli']->query( $SQL ?? '' );

uss::stop( $status );



