<?php
/******************************************************************************/
// Posebna stran modula, kjer se nastavlja editor (request in response)
// Date: 2008
/******************************************************************************/

/* NE SPREMINJAJ **************************************************************/
if($editor_stage == "generate")
{
/******************************************************************************/
/* Uporaba:
	- vsak zavihek ima svojo stopnjo, najprej kličemo ukaz:
--> $editor->generate_stopnja("stopnja");
	  * stopnja mora biti definirana v $mod_settings['editor_stopnja']

	- potem poljubno definiramo vnosna polja
--> $editor->generate_field("ime_polja", "ime_prikaz", "vrsta_polja", "lang");
	  * vrsta polja je lahko (text, textarea, izberi)
	  * required (ni obvezen), drugače prazno
	  * lang (ni obvezen), true ali false
/******************************************************************************/
	$editor->required(array("ime"));
	switch($clean['stopnja'])
	{
		case "1":
			$_SESSION['editor_stopnja'] = 1;
			$editor->generate_stopnja("Skupina");
			$editor->generate_field("ime", "Ime skupine", "text");
		break;
		case "2":
			$_SESSION['editor_stopnja'] = 2;
			$custom = true;
			$editor->generate_stopnja("Pravice");
			//generiramo custom prikaz (template je še vedno editor.tpl)
			$editor->generate_custom();
			$tpl->newBlock("dostop_modul_pravice");
			//nastavitve (ni najbolj elegantno sam jebat ga)
			$tpl->newBlock("dostop_modul_pravice_moduli");
			$tpl->assign("modul","nastavitve");
			$tpl->assign("ids","1");
			$res = $db->query("SELECT pravica FROM core_groups WHERE modul_id = '1' AND group_id = '$clean[id]'");
			$rs = $res->fetch();
			$selected = " selected='selected'";
			switch($rs['pravica'])
			{
				case 1:
					$tpl->assign("vrednost_1",$selected);
				break;
				case 2:
					$tpl->assign("vrednost_2",$selected);
				break;
				case 3:
					$tpl->assign("vrednost_3",$selected);
				break;
				default:
					$tpl->assign("ni_vrednost",$selected);
				break;
			}

			$result = $db->query("SELECT id AS ids, modul_link FROM core_modules WHERE enabled = 1 OR id = 1");
			while($r = $result->fetch())
			{
				$tpl->newBlock("dostop_modul_pravice_moduli");
				$tpl->assign("modul",$r['modul_link']);
				$tpl->assign("ids",$r['ids']);
				$res = $db->query("SELECT pravica FROM core_groups WHERE modul_id = '$r[ids]' AND group_id = '$clean[id]'");
				$rs = $res->fetch();
				$selected = " selected='selected'";
				switch($rs['pravica'])
				{
					case 1:
						$tpl->assign("vrednost_1",$selected);
					break;
					case 2:
						$tpl->assign("vrednost_2",$selected);
					break;
					case 3:
						$tpl->assign("vrednost_3",$selected);
					break;
					default:
						$tpl->assign("ni_vrednost",$selected);
					break;
				}
			}

		break;
	}

/* NE SPREMINJAJ **************************************************************/
}
elseif($editor_stage == "response")
{
/******************************************************************************/

	switch($_SESSION['editor_stopnja'])
	{
		case 1:
			$sqlclean['ime'] = inputXSScheck($_POST['ime']);
		break;
		case 2:
			foreach($_POST AS $key => $value)
			{
				if(strstr($key, "_moduls"))
				{
					$clean['moduls'] = intval($key);
					$clean['pravica'] = intval($value);
					$result = $db->query("SELECT group_id FROM core_groups WHERE modul_id = '$clean[moduls]' AND group_id = '$clean[id]'");
					if($clean['pravica'] > 0)
					{
						if($result->exist())
						{
							//update
							$db->query("UPDATE core_groups SET pravica = '$clean[pravica]' WHERE modul_id = '$clean[moduls]' AND group_id = '$clean[id]'");
						}
						else
						{
							//insert
							$db->query("INSERT INTO core_groups (group_id, modul_id, pravica) VALUES ('$clean[id]', $clean[moduls], '$clean[pravica]')");
						}
					}
				}
			}
		break;
	}

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