<?php
/******************************************************************************/
// Knjižnica, kjer so zbrane funkcije za editor
// Author: Dave @ zabec.net
// Date: 2008
/******************************************************************************/

/* class skrbi za generiranje editorja */
class editor
{
	var $sections;
	function editor($sections, $language)
	{
		global $tpl;
		global $clean;
		global $mod_settings;
		global $db;
		global $modul_selected;
		global $lang;
		global $vsebina_polja;
		$this->jezik = $lang;
		$this->db = $db;
		$this->settings = $mod_settings;
		$this->tpl = $tpl;
		$this->sections = $sections;
		$this->id = $clean['id'];
		$this->lang = $language;

		if($this->settings['zakljucek'] != "off")
		{
			$this->sections[] = $lang['add_zakljucek'];
		}

		//zadnje spremembe
		spremembeBox($this->id);

		//naslov
		generate_naslov($modul_selected);
		$r = $this->get_field_value();

		if(!$r[$vsebina_polja[0]])
		{
			$r[$vsebina_polja[0]] = $lang['add_ninaslova'];
		}
		$tpl->assign("detail_naslov", $r[$vsebina_polja[0]]);

		//lang zavihek (definiran v lib_mod_general.php)
		generate_lang_zavihek($this->lang);

	}


	function generate_stopnja($ime, $razdelek = true)
	{
		if(in_array($ime,$this->sections) OR $ime == $lang['add_zakljucek'])
		{
			$this->tpl->newBlock("stopnja");
			$this->tpl->assign("title",$ime);
			if($razdelek)
			{
				$this->generate_razdelek();
			}
			$this->navigation(array_search($ime, $this->sections));
		}
		else
		{
			echo "error je";
		}
	}

	function generate_razdelek($naslov = "", $unique = "")
	{
		if($naslov)
		{
			$this->tpl->newBlock("presledek");
			$this->tpl->assign("naslov",$naslov);
		}
		$this->tpl->newBlock("razdelek");
		if($unique)
		{
			$this->tpl->assign("unique","id = '".$unique."'");
		}
		$this->tpl->assign("editid",$this->id);
		$this->tpl->assign("lang",$this->lang);
	}
	function generate_poljeSlika($obvezno = false)
	{
		$r = $this->get_field_value();
		if($r['slika'])
		{
			$this->tpl->newBlock("slika_polje");
			$this->tpl->assign("slika","../../".$this->settings['slika_path'].$r['slika']);
			$this->tpl->assign("slika_name",$r['slika']);
			$this->tpl->assign("slika_izbris","remove_slika()");
		}
		else
		{
			$this->generate_addUpload("slika");
			if($obvezno)
			{
				$this->generateRequired();
			}
		}
		//$this->generate_field("slika", "Napis", "text", "", "", "", true);
	}

	function generate_galerija($obvezno = false, $opis = false)
	{
		$result = $this->db->query("SELECT * FROM ".$this->settings['galerija_tabela']." WHERE item_id = '$this->id' ORDER BY vrstni_red");
		$i = 0;
		while($r = $result->fetch())
		{
			if($i > 0)
			{
				$this->generate_razdelek();
			}
			$i++;
			$this->tpl->newBlock("slika_polje");
			$this->tpl->assign("slika","../../".$this->settings['slika_path'].$r['slika']);
			$this->tpl->assign("slika_name",$r['slika']);
			$this->tpl->assign("slika_izbris","remove_slika_galerija('$r[id]')");
			if($opis)
			{
				$this->generate_field("opis_".$r['id'], "Opis","imgtext",false,$r['opis'],true);
			}
			if($this->settings['galerija_vrstni_red'])
			{
				$this->tpl->newBlock("slika_polje_vrstni_red");
				$this->tpl->assign("id",$r['id']);
			}
		}
		$this->generate_addUpload("galerija");
		if($i == 0 AND $obvezno)
		{
			$this->generateRequired();
		}
	}

	function generate_datoteka($obvezno = false)
	{
		$result = $this->db->query("SELECT * FROM ".$this->settings['datoteke_tabela']." WHERE item_id = '$this->id'");
		$i = 0;
		while($r = $result->fetch())
		{
			if($i > 0)
			{
				$this->generate_razdelek();
			}
			$i++;
			$this->tpl->newBlock("datoteka_polje");
			$this->tpl->assign("datoteka_name",$r['datoteka']);
			$this->tpl->assign("id",$r['id']);

			$koncnica = strtolower(strrchr($r['datoteka'],"."));

			switch($koncnica)
			{
				case ".pdf":
					$ikona = "i_pdf.png";
				break;
				case ".txt":
					$ikona = "i_pdf.png";
				break;
				default:
					$ikona = "i_no.png";
				break;
			}
			$this->tpl->assign("ikona",$ikona);

		}
		$this->generate_addUpload("datoteke");
		if($i == 0 AND $obvezno)
		{
			$this->generateRequired();
		}
	}

	function generate_addField($target){
		$this->tpl->newBlock("field_dodaj");
		$this->tpl->assign("num_fields","0");
		$this->tpl->assign("field_name","Odgovor");
		$this->tpl->assign("target",$target);
	}

	function generate_addUpload($tip)
	{
		global $lang;
		$this->tpl->newBlock("slika_dodaj");
		switch($tip)
		{
			case "galerija":
			case "slika":
				$this->tpl->assign("napis",$lang['add_dodajsliko']);
				$dovoljeno = $this->settings['editor_allowed_image'];
			break;
			case "datoteke":
				$this->tpl->assign("napis",$lang['add_dodajdatoteko']);
				$dovoljeno = $this->settings['editor_allowed_file'];
			break;
		}

		/* generiramo utrezen seznam za dovoljene tipe datotek */
		$allowed = "";
		foreach($dovoljeno AS $value)
		{
			$allowed .= "*".$value.";";
		}

		$this->tpl->assign("tip",$tip);
		$this->tpl->assign("session",session_id());
		$this->tpl->assign("file_types",$allowed);
		$this->tpl->assign("max_size",$this->settings['editor_max_file_size']);
	}

	function generateRequired()
	{
		$this->tpl->newBlock("obvazno_polje");
	}

	function generate_zakljucek()
	{
		unset($_SESSION['editor_stopnja']);
		$this->generate_stopnja("Zaključek");
		$this->tpl->newBlock("zakljucek");

		/* odstranimo session stopnje */
		$num = count($this->settings['editor_stopnja']);
		for($i = 1; $i<=$num; $i++)
		{
			if($_SESSION['editor_ok_'.$this->id.'_'.$i] != "ok")
			{
				$napaka = true;
				$napaka_stage[] = $i;
			}

		}
		$napaka_stopnja = "";
		if($napaka_stage)
		{
			foreach($napaka_stage AS $value)
			{
				$napaka_stopnja .= $this->sections[$value-1].", ";
			}
		}
		if($napaka)
		{
			$this->tpl->assign("opozorilo",$lang['add_nisoizpolnjena'] . ": ".strtoupper($napaka_stopnja));
			$this->tpl->assign("opomba",$lang['add_shranite_neizpolnjeno']);
		}
		else
		{
			$this->tpl->assign("opomba",$lang['add_shranite_izpolnjeno']);
		}
		//if(isset($_SESSION['new_item_'.$this->id]) AND $napaka)

		if(!$napaka)
		{
			$this->generate_gumb_objavi();
		}

		//$this->generate_gumb_v_osnutke();
	}


	function get_field_value()
	{
		if($this->id)
		{
			$result = $this->db->query("SELECT * FROM ".$this->settings['tabela']." WHERE id = '$this->id'");
			return $result->fetch();
		}
		else
		{
			return null;
		}
	}
	function get_field_lang_value($lang)
	{
		if($this->id)
		{
			$result = $this->db->query("SELECT * FROM ".$this->settings['tabela']."_".$lang." WHERE item_id = '$this->id'");
			return $result->fetch();
		}
		else
		{
			return null;
		}
	}

	function generate_custom()
	{
		$this->tpl->newBlock("custom_editor");
	}

	function required($fields)
	{
		$this->obveznapolja = $fields;
	}
	/*function checkrequired()
	{
		foreach($this->obveznapolja AS $required)
		{
			$fields .= $required.", ";
		}


		if($this->settings['active_lang'])
		{
			foreach($this->settings['active_lang'] AS $jezik)
			{
				$join_jezik .= " LEFT JOIN ".$this->settings['tabela']."_".$jezik." AS ".$jezik." ON p.id = ".$jezik.".item_id";
			}
		}
		$result = $this->db->query("SELECT * FROM ".$this->settings['tabela']." AS p".$join_jezik." WHERE id = '$this->id'");
		$r = $result->fetch();
		foreach($this->obveznapolja AS $value)
		{
			if($r[$value] == "")
			{
				$error = "true";
			}
		}
		if($error)
		{
			return false;
		}
		else
		{
			return true;
		}
	}*/
	function generate_field($ime, $ime_prikaz, $tip, $lang = "", $fieldvalue = "", $slika = "")
	{
		if($slika)
		{
			$this->tpl->gotoBlock("slika_polje");
		}
		else
		{
			$this->tpl->newBlock("polje");
		}
		/* če je required */
		if(in_array($ime, $this->obveznapolja))
		{
			$class = " required";
			$mark = " *";
		}
		/*if($required == "required")
		{
			$class = " required";
			$mark = " *";
		}*
		/* če je jezikovno pogojen */
		if($lang)
		{
			$this->tpl->assign("langclass","editor_lang_znakec");
			$this->tpl->assign("jezik",strtoupper($this->lang));
			$lang = $this->lang."_";

			/* vrnemo vrednosti če obstajajo */
			if($this->get_field_lang_value($this->lang))
			{
				$r = $this->get_field_lang_value($this->lang);
				$value = $r[$ime];
			}
		}
		else
		{
			$this->tpl->assign("langclass","editor_lang_znakec_off");
			$lang = "";

			/* vrnemo vrednosti če obstajajo */
			if($this->get_field_value())
			{
				$r = $this->get_field_value();
				$value = $r[$ime];
			}
		}
		//RichTextEditor je false (zaenkrat)
		if(!$this->rich)
		{
			$this->rich = false;
		}
		/* izpišemo tip */
		switch($tip)
		{
			case "text":
				if($slika)
				{
					$clase = "slika_input_text";
				}
				else
				{
					$clase = "editor_input_text";
				}
				if($fieldvalue)
				{
					$value = $fieldvalue;
				}
				$polje = "<input type='text' class='".$clase.$class."' name='".$lang.$ime."' value='$value'/>";
				break;
			case "datum":
			$datum = formatDateFromDB($value, "date");
			//preprečimo prazen datum
			if($datum == "00.00.0000")
			{
				$datum = "";
			}
			$polje = "<input type='text' class='datumPicker ".$clase.$class."' id='".$lang.$ime."' name='".$lang.$ime."' value='$datum'/>";
			break;

			case "imgtext":
				$clase = "slika_input_text";
				$polje = "<input type='text' class='".$clase.$class."' name='".$lang.$ime."' value='$fieldvalue'/>";
			break;
			case "password":
				$clase = "editor_input_text";

				$polje = "<input type='password' class='".$clase.$class."' name='".$lang.$ime."'/>";
				break;
			case "textarea":
				$polje = "<textarea class='editor_input_textarea".$class."' id='".$ime."' name='".$lang.$ime."'/>$value</textarea>";
				break;
			case "richtextarea":
				$polje = "<textarea class='editor_input_textarea richtextarea".$class."' id='".$lang.$ime."' name='".$lang.$ime."'/>$value</textarea>";
				$this->rich = true;
				break;
			case "radiobutton":
				$polje = "";
				foreach($fieldvalue AS $fvalue)
				{
					if($value == $fvalue)
					{
						$checked = " checked=true";
					}
					else
					{
						$checked = "";
					}
					$polje .= "<input type='radio' class='".$class."' name='".$lang.$ime."'".$checked." value='$fvalue'>$fvalue<br/>";
				}
				break;
			case "checkbox":
				if($value == $fieldvalue)
				{
					$checked = " checked=true";
				}
				else
				{
					$checked = "";
				}
				$polje = "<input type='checkbox' class='".$class."' name='".$lang.$ime."'".$checked." value='$fieldvalue'>";
				break;
			case "izberi":
				$polje = "<select class='editor_input_select".$class."' name='".$lang.$ime."'>";
				$polje .= "<option value=''>" . $this->jezik['add_izberivrednost'] . "</option>";
				foreach($fieldvalue AS $vrednost => $prikaz)
				{
					if($value == $vrednost)
					{
						$selected = "selected='selected'";
					}
					else
					{
						$selected = "";
					}
					$polje .= "<option value='$vrednost'$selected>$prikaz</option>";
				}
				$polje .= "</select>";
				break;

			case "kategorija":
				$polje = "<select class='editor_input_select".$class."' name='$ime'>";
				$polje .= "<option value=''>" . $this->jezik['add_izberikategorijo'] . "</option>";
				//če gre za enonivojsko kategorijo
				if($this->settings['no_multi_kategorija'])
				{
					$sqlParent = "";
				}
				else
				{
					$sqlParent = " WHERE parent='0'";
				}

				$result = $this->db->query("SELECT id, ime FROM ".$this->settings['kat_tabela'].$sqlParent." ORDER BY ime DESC;");
				while($r = $result->fetch())
				{
					if($value == $r['id'])
					{
						$selected = "selected='selected'";
					}
					else
					{
						$selected = "";
					}
					$polje .= "<option value='$r[id]'$selected>$r[ime]</option>";

					//če ni nastavljene multinivojske spremenljivke
					if(!$this->settings['no_multi_kategorija'])
					{
						//Še podkategorije
						$result2 = $this->db->query("SELECT id, ime FROM ".$this->settings['kat_tabela']." WHERE parent=" . $r['id'] . " ORDER BY ime DESC;");
						while($r2 = $result2->fetch())
						{
							if($value == $r2['id'])
							{
								$selected = "selected='selected'";
							}
							else
							{
								$selected = "";
							}
							$polje .= "<option value='$r2[id]'$selected>&nbsp;&nbsp;&nbsp;&nbsp;> $r2[ime]</option>";
						}
					}
				}
				$polje .= "</select>";
				break;

		}
		$this->tpl->assign("naziv",$ime_prikaz.$mark);
		$this->tpl->assign("name",$ime);
		$this->tpl->assign("polje",$polje);
		$this->isRichEditor();
		$this->isSelectDatum();
	}
	function navigation($key)
	{
		/* tabs */
		$num = count($this->sections)-1;
		foreach($this->sections AS $tabkey => $tab)
		{
			$stopnja = $tabkey+1;
			$this->tpl->newBlock("navigation_tabs");
			/* tab je izbran */
			if($tabkey == $key)
			{
				$izbran = $stopnja +1;
				$this->tpl->assign("tab_class","editor_tab_on");
				$this->tpl->assign("tab_link","$tab");
				$this->tpl->gotoBlock("razdelek");
				$this->tpl->assign("trenutna_stopnja","$stopnja");

			}
			/* tab je že obdelan */
			elseif($tabkey < $key OR $tabkey == $key+1)
			{
				$this->tpl->assign("tab_class","editor_tab_off");
				$this->tpl->assign("tab_link","<a href='#' onclick=\"editor_check('$stopnja')\">$tab</a>");

				if($_SESSION['editor_ok_'.$this->id.'_'.$stopnja]  == "ok")
				{
					$this->tpl->newBlock("navigation_tabs_tick");
				}
			}
			/*  še ni obdelan*/
			elseif($tabkey > $key)
			{
				$this->tpl->assign("tab_class","editor_tab_off");
				$this->tpl->assign("tab_link","$tab");

				if($_SESSION['editor_ok_'.$this->id.'_'.$stopnja]  == "ok")
				{
					$this->tpl->newBlock("navigation_tabs_tick");
				}
			}
		}

		$numsections = count($this->sections)-1;
		/* left navigation */
		if($key > 0)
		{
			$levo = $key-1;
			$this->tpl->newBlock("navigation_left");
			$this->tpl->assign("navigacija",$this->sections[$levo]);
			$this->tpl->assign("stopnja",$key);
		}
		/* rigth navigation */
		if($key < $numsections)
		{
			$desno = $key+1;
			$this->tpl->newBlock("navigation_right");
			$this->tpl->assign("navigacija",$this->sections[$desno]);
			$this->tpl->assign("stopnja",$izbran);
		}

		if($this->settings['zakljucek'] == "off" AND $key == $numsections)
		{
			$this->generate_gumb_objavi();
		}
		$this->generate_gumb_zapri();
		$this->generate_gumb_v_osnutke();
		//prvi zavihek
		/*if($key == 0)
		{
			$this->generate_gumb_zapri();
		}*/
	}


	function isRichEditor()
	{
		$this->tpl->gotoBlock("razdelek");
		if($this->rich)
		{
			$this->tpl->assign("richeditor","true");
		}
		else
		{
			$this->tpl->assign("richeditor","false");
		}
	}

	function isSelectDatum()
	{
		$this->tpl->gotoBlock("razdelek");
		if($this->settings['active_datumselect'])
		{
			$this->tpl->assign("selectdatum","true");
		}
		else
		{
			$this->tpl->assign("selectdatum","false");
		}
	}

	function generate_gumb_objavi()
	{
		$numsections = count($this->sections)-1;
		$this->tpl->newBlock("gumb_objavi");
		$this->tpl->assign("stopnja",$numsections);
	}
	function generate_gumb_zapri()
	{
		$this->tpl->newBlock("gumb_zapri");
	}
	function generate_gumb_v_osnutke()
	{

		if($this->settings["osnutek"])
		{
			$this->tpl->newBlock("gumb_vosnutke");
		}
	}
}

function checkRequired($required, $id)
{
	if($_SESSION['editor_stopnja'])
	{
		if($required == "ok")
		{
			$_SESSION['editor_ok_'.$id.'_'.$_SESSION['editor_stopnja']] = "ok";
		}
		else
		{
			$_SESSION['editor_ok_'.$id.'_'.$_SESSION['editor_stopnja']] = false;
		}
	}
}

function saveEdit($sqlclean, $objava, $id, $langs)
{
		global $mod_settings;
		global $db;
		global $lang;

		$field = "";
		$values = "";
		$update = "";
		$lfield = "";
		$lvalues = "";
		$lupdate = "";

		if($objava)
		{
			/* odstranimo session stopnje */
			$num = count($mod_settings['editor_stopnja']);
			for($i = 1; $i<=$num; $i++)
			{
				unset($_SESSION['editor_ok_'.$id.'_'.$i]);
			}

			if($_SESSION['new_item_'.$id])
			{
				novaSprememba($id, $lang['add_novaobjava']);
				unset($_SESSION['new_item_'.$id]);
				if($mod_settings['order_date'])
				{
					$fchange = ", zadnja_sprememba, zadnji_vnos";
					$schange = ",NOW(),NOW()";
					$uchange = ", zadnja_sprememba = NOW(), zadnji_vnos = NOW()";
				}
			}
			else
			{
				novaSprememba($id, $lang['add_popravljenaobjava']);
				if($mod_settings['order_date'])
				{
					$fchange = ", zadnja_sprememba";
					$schange = ",NOW()";
					$uchange = ", zadnja_sprememba = NOW()";
				}
			}
		}

		$result = $db->query("SELECT * FROM ".$mod_settings['tabela']." WHERE id = '$id'");
		$r = $result->fetch();
		if($r['osnutek'] == "0")
		{
			$objava = 1;
		}

		if($sqlclean)
		{
			foreach($sqlclean AS $key => $value)
			{
				//preverjanje če gre za jezik
				$exist = strpos($key, $langs);
				$vejca = ", ";
				if($exist === false)
				{
					$update .= $key." = '".$value."'".$vejca;
					$field .= $key.$vejca;
					$values .= "'".$value."'".$vejca;

					/* specifika zaradi kategorije in vrstnega reda */
					if($key == "kategorija" AND $mod_settings['vrstni_red'])
					{
						/* gre za spremembo kategorije */
						//if($r['kategorija'] != $value AND isset($_SESSION[$id.'_vrstni_red']))
						if($r['kategorija'] != $value)
						{
							$vrstni_reset = true;
							vrstni_red($id, "odstrani");
							unset($_SESSION[$id.'_vrstni_red']);
						}
					}
				}
				else
				{
					$key = str_replace($langs,"",$key);
					$language = true;
					$lupdate .= $key." = '".$value."'".$vejca;
					$lfield .= $key.$vejca;
					$lvalues .= "'".$value."'".$vejca;
				}
			}
		}

		// je objava ali osnutek
		if($objava)
		{
			/* generiramo vrstni red - če je ta v igri */
			if($mod_settings['vrstni_red'])
			{
				/* obstaja star vrstni red */
				if(!$vrstni_reset)
				{
					if(isset($_SESSION[$id.'_vrstni_red']))
					{
						vrstni_red($id, "resolve_temp");
					}
					else
					{
						vrstni_red($id, "dodaj");
					}
				}
			}
			$osnutek = 0;
		}
		else
		{
			// shranimo začasen vrstni red v session, će že ni nastavljen
			if(!isset($_SESSION[$id.'_vrstni_red']) AND $mod_settings['vrstni_red'])
			{
				vrstni_red($id, "save_temp");
			}
			$osnutek = 1;
		}

		if($mod_settings['osnutek'])
		{
			$update .= "osnutek = '$osnutek'";
			$field .= "osnutek";
			$values .= "'1'";
		}
		else
		{
			$update = substr($update, 0, -2);
			$field = substr($field, 0, -2);
			$values = substr($values, 0, -2);
		}

		/* preverimo če id obstaja */
		$result = $db->query("SELECT id FROM ".$mod_settings['tabela']." WHERE id = '$id'");

		/* id obstaja -> update */
		if($result->exist())
		{
			if($update)
			{
				$db->query("UPDATE ".$mod_settings['tabela']." SET ".$update.$uchange." WHERE id = '$id' ");
				$usedid = $id;
			}
		}
		/* id ne obstaja -> insert */
		else
		{
			$result = $db->query("INSERT INTO ".$mod_settings['tabela']." (".$field.$fchange.") VALUES (".$values.$schange.")");
			$usedid = $result->insertID();
			$_SESSION['new_item_'.$usedid] = true;
		}

		/* jeziki */
		if($language)
		{
			$lupdate .= "item_id = '$usedid'";
			$lfield .= "item_id";
			$lvalues .= "'$usedid'";
			$langs = str_replace("_","",$langs);
			$lang_tabela = $mod_settings['tabela']."_".$langs;
			/* preverimo če id obstaja */
			$result = $db->query("SELECT item_id FROM ".$lang_tabela." WHERE item_id = '$id'");

			/* id obstaja -> update */
			if($result->exist())
			{
				$db->query("UPDATE ".$lang_tabela." SET ".$lupdate." WHERE item_id = '$id' ");
			}
			/* id ne obstaja -> insert */
			else
			{
				$result = $db->query("INSERT INTO ".$lang_tabela." (".$lfield.") VALUES (".$lvalues.")");
			}

		}
		if(!$usedid)
		{
			$usedid = $id;
		}
		if($vrstni_reset AND $objava AND $mod_settings['vrstni_red'])
		{
			vrstni_red($usedid, "dodaj");
		}
		return $usedid;
}

function addSlika($datoteka, $id, $tip)
{
	global $mod_settings;
	global $db;
	global $lang;
	global $moreimages;
	global $path;
	global $log;

	$file = new fileHandling();
	$paths = "../../".$mod_settings['slika_path'];

	$upload = $file->upload($datoteka, $paths, $mod_settings['editor_allowed_image']);
	if($upload)
	{
		$image = new imageHandling();

		//kreiramo zahtevane slike
		if($moreimages)
		{
			foreach($moreimages AS $value)
			{
				//kakšen tip slike se generira
				$custom_path = $paths."/".$value[0]."/";
				if(file_exists($custom_path))
				{
					switch($value[1])
					{
						case "original":
							$file->kopiraj($paths.$upload, $custom_path.$upload);
						break;
						case "custom":
							include($path."/custom_images.php");
						break;
					}
				}
				else
				{
					return false;
				}
			}
		}
		//$image->crop($path.$upload,$path.$upload, 0, 0, 59, 59);
		//$image->resize($path.$upload,$path.$upload,59,"omejena");
		$image->createThumb($paths.$upload,$paths.$upload,59);

		switch($tip)
		{
			case "slika":
				$sql = "UPDATE ".$mod_settings['tabela']." SET slika = '$upload' WHERE id = '$id'";
				break;
			case "galerija":
				$sql = "INSERT INTO ".$mod_settings['galerija_tabela']." (item_id, slika) VALUES ('$id', '$upload')";
				break;
			default:
				return false;
			break;
		}

		$result = $db->query($sql);
		if($result)
		{
			if($mod_settings['galerija_vrstni_red'] AND $tip == "galerija")
			{
				vrstni_red($result->insertID(), "dodaj", "galerija");
			}
			novaSprememba($id, $lang['add_dodanaslika']);
			return true;
		}
	}
	else
	{
		return false;
	}
}

function addDatoteka($datoteka, $id)
{
	global $mod_settings;
	global $db;
	global $lang;

	$file = new fileHandling();
	$path = "../../".$mod_settings['datoteka_path'];

	$upload = $file->upload($datoteka, $path, $mod_settings['editor_allowed_file']);
	if($upload)
	{
		$result = $db->query("INSERT INTO ".$mod_settings['datoteke_tabela']." (item_id, datoteka) VALUES ('$id', '$upload')");
		if($result)
		{
			novaSprememba($id, $lang['add_dodanadatoteka']);
			return true;
		}
	}
	return false;
}

/* funkcija shrani opis pri galerijah */
function saveOpis($id)
{
	global $db;
	global $mod_settings;

	$result = $db->query("SELECT id, opis FROM ".$mod_settings['galerija_tabela']." WHERE item_id = '$id'");
	while($r = $result->fetch())
	{
		$clean['opis'] = inputXSScheck($_POST['opis_'.$r['id']]);
		if($clean['opis'] != "" AND $clean['opis'] != $r['opis'])
		{
			$db->query("UPDATE ".$mod_settings['galerija_tabela']." SET opis = '$clean[opis]' WHERE id = '$r[id]'");
		}
	}
}

?>