<?php
/********************************
** Osnovna stran CMS zabec.net **
** Author: Dave @ zabec.net	 **
** Date: 2007 						 **
********************************/
session_start();

/* Config datoteka (vsebuje include potrebnih knjižnic) */
require("sys/config.php");

/* Vkluči inicializacijo */
require("sys/init.php");

/* Generiramo začetne template */
/*******************************/
$tpl = new TemplatePower("templates/".$settings['template']."/index.tpl");
$tpl->assignInclude("header", "templates/".$settings['template']."/header.tpl");
$tpl->prepare();
$tpl->assignGlobal("template_dir", "/templates/".$settings['template']);

/* Language */
require('sys/lib_language.php');

/* Preverjanje uporabnika - login */
include('login.php');

/* Nastavitve */
$tpl->assign("site_naslov", $settings['site_naslov']);

/* Licenca */
$tpl->assign("cms_verzija",$licence_data['lastversion']);
$tpl->assign("licenca_tip",$licence_data['versionname']);
$tpl->assign("licenca_update",formatDateFromDB($settings['last_update'],"date"));

// UPORABNKI JE PRIJAVLJEN, IZPIŠEMO VSEBINO
/******************************************************************************/
if ($_SESSION['prijavljen'])
{
	$tpl->newBlock("adds");
	dodajCss("templates/".$settings['template']."/style.css");
	dodajCss("templates/".$settings['template']."/css/editor.css");
	/* Spremenljivke */
	$clean['topmenu'] = intval($_GET['tm']);
	$clean['page'] = inputXSScheck(basename($_GET['pg']));
	$clean['act'] = inputXSScheck(basename($_GET['act']));

	/* Preveri ali je šele login in prikaži prvi tab */
	if(!$clean['topmenu']){
		$result = $db->query("SELECT id FROM core_topmenu ORDER BY id ASC LIMIT 0,1");
		$r = $result->fetch();
		$clean['topmenu'] = $r['id'];
	}
	/* Content template */
	$tpl->assignInclude("content", "templates/".$settings['template']."/content.tpl");
	$tpl->prepare();

	// TOP NAVIGACIJA
	/************************************************************************/
	$result = $db->query("SELECT id, topmenu FROM core_topmenu ORDER BY id ASC");
	while($r = $result->fetch())
	{
		/* Izpišemo podatke v content template */
		$tpl->newBlock("top_nav");
		$tpl->assign("topmenu", $r['topmenu']);
		$tpl->assign("povezava", $r['id']);

		/* preverimo če je topmenu izbran */
		if($clean['topmenu'] == $r['id'] AND $_GET['tm'] != "nastavitve")
		{
			$tpl->assign("class", "nav_gumb_on");
		}
		/* topmenu ni izbran */
		else
		{
			$tpl->assign("class", "nav_gumb_off");
		}
	}
	/* $_GET['act'] je poslan in je pravilen*/
	if(ctype_alpha($_GET['act']))
	{
		/* act je varna (samo črke) */
		$clean['act'] = $_GET['act'];
	}
	/************************************************************************/
	// NASTAVITVE
	/************************************************************************/
	//pravice za ogled nastavitev
	if(checkView(1))
	{
		$tpl->newBlock("top_nav_nastavitve");
	}
	if($_GET['tm'] == "nastavitve")
	{
		if(checkView(1))
		{
			$tpl->assign("nastavitve_status", "on");

			dodajCss("templates/".$settings['template']."/css/pregled.css");
			include("nastavitve.php");
		}
	}
	else
	{
		$tpl->assign("nastavitve_status", "off");
		/************************************************************************/
		// LEVI MENU
		/************************************************************************/
		include('left_menu.php');
		/************************************************************************/
		// MODUL
		/************************************************************************/
		/* Preverimo če je izbran modul (preverjanje dovoljenja za ogled je v left_menu.php) */
		if($modul_selected)
		{
			dodajCss("templates/".$settings['template']."/css/pregled.css");

			/* pot in ime modula */
			if($clean['act'] == "osnutek")
			{
				$path_act = "view";
			}
			else
			{
				$path_act = $clean['act'];
			}
			$path_name = $modul_selected."/".$path_act."/settings.php";

			/* preverimo če zahtevan modul obstaja */
			if(file_exists($path_name))
			{
				/* vključimo podrobno stran modula */
				include($path_name);
				/* vljučimo protrebne javascript knjižnice */
				if($mod_settings['active_rtf'])
				{
					dodajJS($ajax."inc/fckeditor/fckeditor.js");
				}
				if($mod_settings['slika'] OR $mod_settings['galerija'])
				{
					dodajJS($ajax."inc/swfupload.js");
				}
				if($mod_settings['active_datumselect'])
				{
					dodajJS($ajax."inc/datepicker.js");
				}
			}
			/* če ne obstaja izpišemo error */
			else
			{
				$log->log("Zahtevali ste neobstoječ modul!", "fatal", "Neobstoječ modul: ".$path_name);
			}
		}
		else
		{
			dodajCss("templates/".$settings['template']."/css/dashboard.css");
			$tpl->assignInclude("main_content", "templates/".$settings['template']."/dashboard.tpl");
			$tpl->prepare();
			include('dashboard.php');
		}
		/************************************************************************/
	}
	// DESNI MENU
	/************************************************************************/
	include('right_menu.php');
	/************************************************************************/

	// FOOTER
	/************************************************************************/
	$tpl->assignInclude("footer", "templates/".$settings['template']."/footer.tpl");
	$tpl->prepare();
	/************************************************************************/
}
/******************************************************************************/

// UPORABNIK NI PRIJAVLJEN, IZPIŠEMO LOGINBOX
/******************************************************************************/
else
{
	$tpl->assignInclude("content", "templates/".$settings['template']."/login.tpl");
	$tpl->prepare();

	//Nastavimo še številke za pomoč
	$tpl->assign("podpora_tel",$settings['podpora_tel']);
	$tpl->assign("podpora_email",$settings['podpora_email']);

	$tpl->newBlock("adds");
	dodajCss("templates/".$settings['template']."/style.css");
	dodajCss("templates/".$settings['template']."/login.css");
}
/******************************************************************************/

// GENERIRAMO VSEBINO PREKO TEMPLATOV
/******************************************************************************/
$tpl->printToScreen();
/******************************************************************************/

?>