<?php 

use Mijn\realmapi;
use Mijn\mijnovis;
	
require_once dirname(__FILE__) . '/../../config/inc.config.php';

$aURL = parse_url($_SERVER['REQUEST_URI']);
$aURI = array_filter(array_pad(explode('/', $aURL['path']), 10, ''));

$sToken			= !empty($_SESSION['ssoRouteLoginToken'])	? $_SESSION['ssoRouteLoginToken']	: false;
$iUserId		= !empty($_SESSION['ssoRouteLoginUserId'])	? $_SESSION['ssoRouteLoginUserId']	: false;

$oVerifyUser = new realmapi();
$oVerifyUser->setToken($sToken);
$oVerify = $oVerifyUser->verifyUser();	

if(empty($oVerify) || $oVerify->result == false || $aURI[1] != 'afbeelding' || empty($aURI[2])) {
	if(empty($oVerifyUser->_sToken)) {
		header('Location: /');
		exit;					
	}		
}

if(file_exists($_SERVER['DOCUMENT_ROOT'].'/../image_upload/'.$iUserId.'/thumb_'.$aURI[2].'.jpg')){
	header("Content-type: image/jpeg");
	echo readfile($_SERVER['DOCUMENT_ROOT'].'/../image_upload/'.$iUserId.'/thumb_'.$aURI[2].'.jpg');	
	exit;
} else {
	header("Content-type: image/jpeg");
	echo readfile($_SERVER['DOCUMENT_ROOT'].'/assets/img/placeholder.jpg');
	exit;
}
?>