<?php
/* ************************************************************************** *
 *																										*
 * Core - dashboard.php v1.0 by DC, Slodave, 2008, http://www.zabec.net			*
 * -------- -------- -------- -------- -------- -------- -------- --------		*
 * 																									*
 * Datoteka skrbi prikaz elementov na dashboardu (ko ni izbran noben modul)	*
 * ************************************************************************** */

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

//nastavitve za obvestila
$tpl->assign("obvestila_naslov",$settings['obvestila_naslov']);

//pozdravni govor
$tpl->assign("dashboard_uvodni",$settings['dashboard_uvodni']);

//ura
$tpl->assign("trenutni_cas",date("d.m.Y G:i:s"));


/* GENERIRAMO BLIŽNJICE																			*/
/* ************************************************************************** */
	$result = $db->query("SELECT modul,modul_link,id FROM core_modules WHERE id_topmenu='".$clean['topmenu']."' AND enabled='1' ORDER BY id");
	while($r = $result->fetch())
	{
		//preverimo če ima uporabnik dostop do določenega modula
		if(checkView($r['id'])) {

			//generiramo bljižnice
			$tpl->newBlock("bliznice");
			$tpl->assign("modul",$r['modul']);
			$tpl->assign("link","index.php?tm=".$clean['topmenu']."&pg=".$r['modul_link']."&act=view&new=true");
			$tpl->assign("id",$r['modul_link']);

			//generiramo osnutke
			$resulto = $db->query("SELECT id FROM modul_".$r['modul_link']." WHERE osnutek='1'");
			$size = $resulto->size();
			//preverimo če obstaja kakšen osnutek, če obstaja izpišemo povezavo do osnutkov določenega modula
			if($size > 0) {
				$tpl->newBlock("osnutki");
				$tpl->assign("modul",$r['modul']);
				$tpl->assign("link","index.php?tm=".$clean['topmenu']."&pg=".$r['modul_link']."&act=osnutek");
				$tpl->assign("osnutkov",$size);
			}
		}
	}
/* ************************************************************************** */

/* GENERIRAMO NOVICE																				*/
/* ************************************************************************** */
	$result = $db->query("SELECT naziv,cas,opis,link,obvezno,id FROM core_obvestila ORDER BY cas DESC LIMIT 0,3");
	while($r = $result->fetch()) {
		$tpl->newBlock("dashboard_obvestila");
			$tpl->assign("template_dir",$data['template_dir']);
			$tpl->assign("ura",FormatDateFromDB($r['cas'],"dateshorttime"));
			$tpl->assign("link",$r['link']);
			$tpl->assign("naslov",$r['naziv']);
			$tpl->assign("opis",$r['opis']);
			//če je novica obvezna dodamo poseben class
			if($r['obvezno']){
				$tpl->assign("class","obvestilo_obvezno");
			}
	}

/* ************************************************************************** */

/* ZADNJI DOGODKI V CMSju																		*/
/* ************************************************************************** */
	$result = $db->query("SELECT change_time, username, sprememba, t.id AS modul_id, p.modul AS modul_sprememba, first_field, item_id, t.modul, modul_link, s.topmenu, s.id AS topmenuid FROM core_spremembe AS p LEFT JOIN core_uporabniki AS d ON p.change_user = d.id LEFT JOIN core_modules AS t ON p.modul = t.modul_link LEFT JOIN core_topmenu AS s ON t.id_topmenu = s.id ORDER BY change_time DESC");
	$a = 0;
	//prikažemo zadnjih pet dogodkov
	while($r = $result->fetch() AND $a < 5) {
		//preverimo če gre za CMS-nastavitve module (ker so specifični)
		if($r['modul_sprememba'] == "uporabniki" OR $r['modul_sprememba'] == "dostop" OR $r['modul_sprememba'] == "moduli") {
			$r['modul_id'] = "nastavitve";
		}
		//preverimo če ima uporabnik dovoljenje za ogled posameznega modula
		if(checkView($r['modul_id'])) {
			$a++;
			$tpl->newBlock("zadnji_dogodki");
			$tpl->assign("sprememba",$r['sprememba']);
			$tpl->assign("cas",formatDateFromDB($r['change_time']));
			$tpl->assign("uporabnik",$r['username']);

			//specifika nastavitev
			if($r['modul_sprememba'] == "uporabniki" OR $r['modul_sprememba'] == "dostop" OR $r['modul_sprememba'] == "moduli") {
				$tpl->assign("topmenu","Nastavitve");
				$tpl->assign("topmenuid","nastavitve");
				$tpl->assign("modul",ucfirst($r['modul_sprememba']));
				$tpl->assign("modul_link",$r['modul_sprememba']);
			}
			//standardni moduli
			else {
				$tpl->assign("topmenu",$r['topmenu']);
				$tpl->assign("topmenuid",$r['topmenuid']);
				$tpl->assign("modul",$r['modul']);
				$tpl->assign("modul_link",$r['modul_link']);
			}

			//če ni podatka iz prvega polja
			if($r['first_field']) {
				$tpl->assign("modul_polje",$r['first_field']);
			}
			else {
				$tpl->assign("modul_polje","Ni podatka");
			}
		}
	}

/* ************************************************************************** */
?>
