<?php
$trosk = $modx->getService('trosk','Trosk',$modx->getOption('doodles.core_path',null,$modx->getOption('core_path').'components/trosk/').'model/trosk/',$scriptProperties);
if (!($trosk instanceof Trosk)) return '';


$tpl='fem.banners.topBanner';
$criteria=$modx->newQuery('modResource');
$criteria->where(array(
	'published' => 1,
	'parent' => $parent,
));
$criteria->sortBy('RAND()');
$banners=$modx->getCollection('modResource',$criteria);
if(empty($banners)) {
	return '<p>Mjesto za vašu reklamu!</p>';	
}
$ctxs = !empty($ctxs) ? $ctxs : $modx->context->get('key');
if (!is_array($ctxs)) $ctxs = explode(',',$ctxs);
if (!$modx->user->hasSessionContext($ctxs)) {
	foreach ($banners as $banner) {
		$zups=$banner->getTVValue('zupanije');
		if(empty($zups)){
			return $trosk->bannerCount($banner,$tpl);		
		}
	}
}
$profile=$modx->user->getOne('Profile');
$userZups=unserialize($profile->get('photo'));
foreach ($banners as $banner) {
	$zups=$banner->getTVValue('zupanije');
	$zupsArray=explode('||',$zups);
	$match=array_intersect($userZups,$zupsArray);
	if(empty($match) AND !empty($zups)) continue;
	return $trosk->bannerCount($banner,$tpl);
}
return '<p>Mjesto za vašu reklamu!</p>';	
 
