oSystem=&$oSystem;
		$this->msTPLPath=CURRDIR."apps/neueveranstaltung/tpl/";
		$this->mlUserPK=$this->oSystem->oUser->oUserData->UserPK;
		$this->gotoUebersicht=false;
	}
	function gsRender($asParams)
	{
		$oTPL=$this->oSystem->goGetTPLParser($this->msTPLPath."main.tpl");
		if(is_array($asParams))
			$sAction=strtolower(array_shift($asParams));
		switch($sAction)
		{
			default:
				$sContent=$this->gsGetEditor($asParams);
				break;
			case "hinzufuegen":
				$sContent=$this->gsSave();
				break;
			case "entfernen":
				$sContent=$this->gsEntfernen();
				break;
			case "speichern":
				$sContent=$this->gbStoreTODB();
		}
		$oTPL->gbSetValue("save",$this->canSave());
		$oTPL->gbSetValue("back",$this->oSystem->oUI->gsGetAnchor("javascript:",$this->oSystem->oSiteNavi->gsGetURL("StartSeite"),"<< Zur Startseite"));
		$oTPL->gbSetContent($sContent);
		$oTPL->gbSetValue("infokey",$this->oSystem->oUI->gsGetInfo(0));
		return $oTPL->gsParse();
	}
	function gbStoreToDB()
	{
		
		$sFormKey=$this->oSystem->oClientData->gvGetVariable("__formKey",false);
		if(1)
		{
			unset($_SESSION["form.editva"]);
			$_SESSION["neueveranstaltung"]["title"]["BeginnAnmeldung"]	    ="15.09.2005";
			$_SESSION["neueveranstaltung"]["title"]["EndeAnmeldung"]		="20.09.2005";
			$_SESSION["neueveranstaltung"]["title"]["BeginnDatum"]		    ="01.10.2005";
			$_SESSION["neueveranstaltung"]["title"]["EndeDatum"]			="02.10.2005";
			$asS=$_SESSION["neueveranstaltung"]["title"];
			$asInsert["BeginnAnmeldung"]	=$this->getTermin($asS["BeginnAnmeldung"]);
			$asInsert["EndeAnmeldung"]		=$this->getTermin($asS["EndeAnmeldung"]);
			$asInsert["BeginnDatum"]		=$this->getTermin($asS["BeginnDatum"]);
			$asInsert["EndeDatum"]			=$this->getTermin($asS["EndeDatum"]);
			$asInsert["VeranstaltungsName"] =$this->oSystem->oDB->gsEscapeString($asS["VeranstaltungsName"]);
			$asInsert["VeranstaltungsKey"] =$this->oSystem->oDB->gsEscapeString($asS["VeranstaltungsKey"]);
			
			$asInsert["CreateDate"]			="now()";
			$asInsert["Creator"]			=$this->mlUserPK;
			$bError=false;
			if(sizeof($_SESSION["neueveranstaltung"]["programmpunkte"])>0)
			{
				if($oRes=$this->oSystem->oDB->goInsertArray("tdVeranstaltungen",$asInsert))
				{
					$asData=$_SESSION["neueveranstaltung"]["programmpunkte"];
					$lVeranstaltungsPK=$oRes->glGetInsertID();
					foreach($asData as $asPGM)
					{
						unset($asInsert);
						$asInsert["Name"]				=$this->oSystem->oDB->gsEscapeString($asPGM["ProgrammPunktName"]);
						$asInsert["BeginnDatum"]		=$this->getTermin($asPGM["BeginnDatum"]);
						$asInsert["BeginnUhrzeit"]		=$this->oSystem->oDB->gsEscapeString($asPGM["BeginnUhrzeit"]);
						$asInsert["EndeDatum"]			=$asPGM["EndeDatum"]==""?"NULL":$this->getTermin($asPGM["EndeDatum"]);
						$asInsert["EndeUhrzeit"]		=$asPGM["EndeUhrzeit"]==""?"NULL":$this->oSystem->oDB->gsEscapeString($asPGM["EndeUhrzeit"]);
						$asInsert["PreisRabattiert"]	=$asPGM["PreisRabattiert"]==""?"NULL":$this->oSystem->oDB->gsEscapeString(CMoney::Betrag2Double($asPGM["PreisRabattiert"]));
						$asInsert["PreisNormal"]		=$asPGM["PreisNormal"]==""?"NULL":$this->oSystem->oDB->gsEscapeString(CMoney::Betrag2Double($asPGM["PreisNormal"]));
						$asInsert["Kontingent"]			=$asPGM["Kontingent"]==""?"NULL":$this->oSystem->oDB->gsEscapeString($asParams["Kontingent"]);
						$asInsert["GratisForACV"]	   =$this->oSystem->oDB->gsEscapeString($asPGM["GratisForACV"]==-1?"-1":"0");
						$asInsert["CreateDate"]			="now()";
						$asInsert["Creator"]			=$this->mlUserPK;
						$asInsert["VeranstaltungsPK"]	=$lVeranstaltungsPK;
						if($oRes=$this->oSystem->oDB->goInsertArray("tdProgrammPunkte",$asInsert))
						{
						}
						else
						{
							$bError=true;
						}
					}
					unset($_SESSION["neueveranstaltung"]);
					$this->gotoUebersicht=$this->oSystem->oSiteNavi->gsGetURL("StartSeite");
					if($bError===true)
					{
						$this->oSystem->oDB->goQuery("DELETE FROM tdProgrammPunkte 	WHERE VeranstaltungsPK=".$lVeranstaltungsPK);
						$this->oSystem->oDB->goQuery("DELETE FROM tdVeranstaltungen WHERE VeranstaltungsPK=".$lVeranstaltungsPK);
						return "nicht gespecihernt";
					}
					return "Die Veranstaltung wurde gespeichert";
				}
			}
		}
		$this->gotoUebersicht=$this->oSystem->oSiteNavi->gsGetURL("StartSeite");
		return "Die Veranstaltung wurde gespeichert";
	}
	function getTermin($asSet)
	{
		$asDatum=explode(".",$asSet);
		if(sizeof($asDatum)<3)
			$asDatum[2]=date("Y");
		$asDatum=array_reverse($asDatum);
		return $this->oSystem->oDB->gsEscapeString(join("-",$asDatum));	
	}
	function gsEntfernen()
	{
		$lPK=$this->oSystem->oClientData->gvGetVariable("PK");
		if($lPK!==false)
		{
			if(isset($_SESSION["neueveranstaltung"]["programmpunkte"][$lPK]))
				unset($_SESSION["neueveranstaltung"]["programmpunkte"][$lPK]);
		}
		return $this->gsGetEditor($asParams);
	}
	function gsSave()
	{
		$sFormKey=$this->oSystem->oClientData->gvGetVariable("__formKey",false);
		if($sFormKey==$_SESSION["form.editva"])
		{
			unset($_SESSION["form.editva"]);
			if($asData=$this->oSystem->oClientData->gvGetVariable("__data",false))
			{
				$_SESSION["neueveranstaltung"]["title"]=$asData;
			}
			if($asData=$this->oSystem->oClientData->gvGetVariable("__programmPunkt",false))
			{
				if(trim($asData["ProgrammPunktName"])!="")
				{
					$_SESSION["neueveranstaltung"]["programmpunkte"][]=$asData;
				}
			}
		}
		return $this->gsGetEditor($asParams);
	}
	function canSave()
	{
		if($this->gotoUebersicht!==false)
		{
			return $this->oSystem->oUI->gsGetAnchor("javascript:",$this->gotoUebersicht,"Zur Startseite  >>");
		}
		if(sizeof($_SESSION["neueveranstaltung"]["programmpunkte"])>0)
			return $this->oSystem->oUI->gsGetAnchor("javascript:saveData()","#","Speichern >>");
		return " ";
	}
	function gasGetEmpty($lEditorPK=false )
	{
		$as["VeranstaltungsKey"]	=$_SESSION["neueveranstaltung"]["title"]["VeranstaltungsKey"];
		$as["VeranstaltungsName"]	=$_SESSION["neueveranstaltung"]["title"]["VeranstaltungsName"];
		$as["BeginnAnmeldung"]		=$_SESSION["neueveranstaltung"]["title"]["BeginnAnmeldung"];
		$as["EndeAnmeldung"]		=$_SESSION["neueveranstaltung"]["title"]["EndeAnmeldung"];
		$as["BeginnDatum"]			=$_SESSION["neueveranstaltung"]["title"]["BeginnDatum"];
		$as["EndeDatum"]			=$_SESSION["neueveranstaltung"]["title"]["EndeDatum"];
		$as["PGMBeginnUhrzeit"]		=$_SESSION["neueveranstaltung"]["title"];
		$as["PGMBeginnDatum"]		=$_SESSION["neueveranstaltung"]["title"];
		$as["PGMEndeUhrzeit"]		=$_SESSION["neueveranstaltung"]["title"];
		$as["PGMEndeDatum"]			=$_SESSION["neueveranstaltung"]["title"];
		$as["ProgrammPunktName"]	=$_SESSION["neueveranstaltung"]["title"];
		$as["PreisRabattiert"]		=$_SESSION["neueveranstaltung"]["title"];
		$as["PreisNormal"]			=$_SESSION["neueveranstaltung"]["title"];
		$oR=$this->oSystem->oDB->goQuery("SELECT TypePK as Value,Name AS Anzeige,'' as Preselected FROM tdProgrammPunktTypen ORDER BY Name");
		$asData=$oR->gaaGetAllRecords();
		$as["programmtyp"]=$this->oSystem->oUI->gsGetSelectBox($asData,"__programmPunkt[TypePK]",array("class"=>"transpSelect","style"=>"width:150"));
		$as["PGMBeginnUhrzeit"]		="";
		$as["PGMBeginnDatum"]		="";
		$as["PGMEndeUhrzeit"]		="";
		$as["PGMEndeDatum"]			="";
		$as["ProgrammPunktName"]	="";
		$as["PreisRabattiert"]		="";
		$as["PreisNormal"]			="";
		$as["Kontingent"]			="";
		return $as;
	}
	function gasGetPGMPKTE()
	{
		
		$asData=$_SESSION["neueveranstaltung"]["programmpunkte"];
		$asReturn=array();
		if(is_array($asData))
		{
			foreach($asData as $lKey=>$asPGM)
			{
				if(isset($asPGM["TypePK"]))
					$asPGM["TypeName"]=$this->oSystem->oDB->gsGetFieldValue("tdProgrammPunktTypen","Name","TypePK=".$asPGM["TypePK"]);
				$lTime=CDateTime::glGetTimeStampDT($asPGM["BeginnDatum"],$asPGM["BeginnUhrzeit"]);
				while(isset($asReturn[$lTime]))
				{
					$lTime++;
				}
				$asPGM["KEY"]=$lKey;
				$asReturn[$lTime]=$asPGM;
			}
			ksort($asReturn);
		}
		return $asReturn;
	}
	function gsGetEditor($asParams,$bGetFromSession=false)
	{
		$oTPL=$this->oSystem->goGetTPLParser($this->msTPLPath."edit.tpl");
		$oTPL->gbSetValue("save",$this->oSystem->oSiteNavi->gsGetURL("NeueVeranstaltung",array("Hinzufuegen")));
		$oTPL->gbSetValue("DROPURL",$this->oSystem->oSiteNavi->gsGetURL("NeueVeranstaltung",array("Entfernen")));
		if($bGetFromSession===false)
		{
			$asData=$this->gasGetEmpty();
		}
		$_SESSION["form.editva"]=md5(mt_rand());
		$oTPL->gbSetValue("__formKey",$_SESSION["form.editva"]);
		$oTPL->gbSetBlock("programmpunkte",$this->gasGetPGMPKTE());
		$oTPL->gbSetValArray($asData);
		$oTPL->gbSetValue("STORE",$this->oSystem->oSiteNavi->gsGetURL("NeueVeranstaltung",array("Speichern")));
		return $oTPL->gsParse();
	}
	function gasGetVeranstaltungen()
	{
		return false;
	}
	function msContent()
	{
		
	}
	
}