<?php

session_start();

//config datoteka
require("sys/config.php");

//datoteka, kjer se vključujejo potrebne knjižnjice
require("sys/init.php");

//Cleanup
$clean['show'] = inputXSScheck($_GET['show']);
$clean['podshow'] = inputXSScheck($_GET['podshow']);
$clean['id'] = inputXSScheck($_GET['id']);
$clean['lang']= inputXSScheck($_GET['jezik']);




if(!$clean['lang'])
	$clean['lang']="slo";

if($clean['show']=="post"){
	include('post/'.strtolower(basename($clean['podshow'])).'.php');
}

if($clean['show']){
	$tpl=new TemplatePower("templates/default.tpl");
	$tpl->prepare();
	
	$tpl->assignInclude("header","templates/controlers/header.tpl");
	$tpl->prepare();
	
	$tpl->assignInclude("menu","templates/controlers/menu_".$clean['show'].".tpl");
	$tpl->prepare();
	
	$tpl->assignGlobal($clean['podshow']."_active","active");
}


if($clean['show'] == "" || $clean['show'] =="o_oddaji"){
	include('content/default.php');
}elseif(($clean['show'] == "index") OR ($clean['show'] == "..") OR ($clean['show'] == ".") OR ($clean['show'] == "/")){
		include('content/error.php');
}else{
	if(file_exists("content/" . strtolower(basename($clean['show'])) . ".php")){		
		include("content/" . strtolower(basename($clean['show'])) . ".php");
	}else{
		include('content/error.php');
	}
}

// MNENJA
$sql="
SELECT mnenje,ime FROM modul_mnenja WHERE 1 ORDER BY RAND() LIMIT 1;
";
$result=$db->query($sql);
$r=$result->fetch();
$tpl->assignGlobal('mnenje',$r['mnenje']);
$tpl->assignGlobal('ime_mnenje',$r['ime']);


$tpl->assignInclude("right","templates/controlers/right.tpl");

// SPOROČILA
$sql="
SELECT sporocilo FROM modul_sporocila WHERE osnutek<>1 ORDER BY vrstni_red LIMIT 1;
";
$result=$db->query($sql);
$r=$result->fetch();
$tpl->assignGlobal('sporocilo',$r['sporocilo']);


# INCLUDE language glede na template..
# samo pogledas v /templates/template.tpl | /content/language/template.php > prefix
/*
foreach(array_merge(array('base' => $tpl->tpl_base), $tpl->tpl_include) as $name => $t){
	$pinfo = pathinfo($t[0]);
	if(!file_exists('content/language/'.$pinfo['filename'].'.php')){
		$printtpl .= "<br><b>".$pinfo['filename']."</b>";
		continue;
	}
	$printtpl .= "<br>".$pinfo['filename'];
	include("content/language/".$pinfo['filename'].".php");
	foreach($lang as $x => $value)	$tpl->assignGlobal($lang_prefix.$x, $value);
	unset($lang);
}
*/


$tpl->assignGlobal("site_title",$settings['site_title'][$clean['lang']]);
$tpl->assignGlobal("server_name",$_SERVER['SERVER_NAME']);

$tpl->prepare();
$tpl->printToScreen();
?>