<?php 

// ------------ [{ Ready? }] -------------

$prefix = DB_TABLE_PREFIX;
$userid = uss::$global['user']['id'];
$notify = array();


// ------------ [{ Count All }] -------------

$SQL = "
	SELECT COUNT(userid) AS _all
	FROM {$prefix}_notifications
	WHERE userid = {$userid} 
		AND hidden = 0
	GROUP BY userid
";

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

$notify['size'] = $all ? $all['_all'] : 0;


// ----------- [{ Get Limit To Display }] --------------


$max_list = dashboard::config( "notification_limit" ) ?? 20;

$view = (int)( $_GET['view'] ?? 1 );
if( $view < 1 ) $view = 1;

$pointer = ( ($view - 1) * $max_list );

$SQL = sQuery::select( "{$prefix}_notifications", "
	userid = {$userid}
	AND hidden = 0
	ORDER BY id DESC
	LIMIT {$pointer}, {$max_list}
" );

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


// ---------- [{ Check If Next or Prev Page Exists }] --------

$query_size = $pointer + $max_list;

$notify['next'] = ( $query_size >= $notify['size'] ) ? null : ( $view + 1 );
$notify['prev'] = ( $view > 1 ) ? ( $view - 1 ) : null;




