<?php
/********************************************************************
** Skripta, ki skrbi za vključevanje levega menuja v CMS zabec.net **
** Author: Dave @ zabec.net		  											 **
** Date: 2008 																	    **
********************************************************************/

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

	/* Izpišemo module izbranega topmenuja iz databaze */
	$result = $db->query("SELECT p.id, modul, modul_link, topmenu, id_topmenu FROM core_modules AS p LEFT JOIN core_topmenu AS d ON p.id_topmenu = d.id WHERE id_topmenu = '$clean[topmenu]' AND p.enabled='1'");
	while($r = $result->fetch())
	{
		/* preverimo pravice za ogled posameznega modula */
		if(checkView($r['id']))
		{
			/* naslov topmenuja v levem menuju */
			$tpl->assign("topmenu", $r['topmenu']);

			/* zgeneriramo pot do modula */
			$path = "mod/".$r['modul_link']."/";
			/* modul obstaja */
			if(file_exists($path))
			{
				/* generiramo osnovni prikaz modulov */
				$tpl->newBlock("nav_meni");
				$tpl->assign("modul_link", $r['modul_link']);

				if($clean['page'] == $r['modul_link'])
				{
					$tpl->assign("nav_meni", "nav_meni_on");
				}
				else
				{
					$tpl->assign("nav_meni", "nav_meni_off");
				}

				/* ime modula */
				$tpl->newBlock("nav_meni_on");
				$tpl->assign("modul", $r['modul']);

				if($clean['page'] == $r['modul_link'])
				{
					$tpl->assign("class", "block");
					$tpl->assign("classoff", "none");
				}
				else
				{
					$tpl->assign("class", "none");
					$tpl->assign("classoff", "block");
				}


					/* vključimo menu izbranega modula */
					$result1 = $db->query("SELECT text, link FROM core_modules_menu WHERE modul_id = '$r[id]' ORDER BY id ASC");
					while($r1 = $result1->fetch())
					{
						/* izpišemo podatke v izbranega modula */
						$tpl->newBlock("nav_meni_on_sub");
						$tpl->assign("tm_on", $r['id_topmenu']);
						$tpl->assign("povezava_on", $r['modul_link']);
						$tpl->assign("link", $r1['link']);
						$tpl->assign("text", $r1['text']);
						if(($r1['link'] == $clean['act'])AND($r['modul_link'] == $clean['page'])){
							$tpl->assign("izbrani_class","levi_selected");
						}

						/* preverimo če je akcija v modulu izbrana */
						if($clean['page'] == $r['modul_link'] AND $clean['act'] == $r1['link'] )
						{
							$tpl->newBlock("nav_meni_on_sub_selected");
							$_SESSION['modul'] = $r['modul_link'];
							$_SESSION['modul_id'] = $r['id'];
							$_SESSION['act'] = $clean['act'];
						}
					}
					//osnutki
					$oresult = $db->query("SELECT COUNT(id) AS stevilo_osnutkov FROM modul_".$r['modul_link']." WHERE osnutek = 1");
					$or = $oresult->fetch();
					$tpl->gotoBlock("nav_meni_on");
					$tpl->assign("tm_on", $r['id_topmenu']);
					$tpl->assign("povezava_on", $r['modul_link']);
					$tpl->assign("stevilo_osnutkov", $or['stevilo_osnutkov']);
					
					

					//> za osnutek
					if($clean['page'] == $r['modul_link'] AND $clean['act'] == "osnutek" )
					{
						//Obvezno treba definirat pred tem. Drugače ne dela
						$tpl->assign("izbrani_class","levi_selected");
						
						$tpl->newBlock("nav_meni_on_osnutek_selected");
						$_SESSION['modul'] = $r['modul_link'];
						$_SESSION['modul_id'] = $r['id'];
						$_SESSION['act'] = $clean['act'];
						
					}

					/* prenesemo path spremenljivko */
					if($clean['page'] == $r['modul_link'] AND $clean['act'])
					{
						$modul_selected = $path;
					}
				//}
				/* modul ni izbran */
				//else
				//{
					/* izpišemo podatke o neizbranem modulu */
			/*		$tpl->newBlock("nav_meni_off");
					$tpl->assign("modul", $r['modul']);
					$tpl->assign("tm", $clean['topmenu']);
					$tpl->assign("povezava", $r['modul_link']);
				}*/
			}
			/* modul ne obstaja */
			else
			{
				/* izpišemo error v left menu template */
				$tpl->newBlock("left_nav_error");
				$tpl->assign("modul", "Modul ".strtolower($r['modul']). " ne obstaja!");
			}
		}
	}