oSystem=&$oSystem; } function gsSave($asData) { switch(strtolower($this->moForm->DataHandler)) { case "record": return $this->gsSaveRecord($asData); break; case "list": break; } } function gsSaveRecord($asData) { $oDB=$this->oSystem->oDB; if($this->moForm->DBAccessKey!="__db__") { $oDB=new CDatabase($this->moForm->DBAccessKey); } $sClassName="CDBFormHelper".$this->moForm->FormKey; if(!class_exists($sClassName)) { $sFile=PATHQS."form/class.ext.".strtolower($this->moForm->FormKey).".php"; if(file_exists($sFile)) { require($sFile); } else { return "".utf8_encode("Formular fehlerhaft!".$sFile."").""; } } if(class_exists($sClassName)) { $oDBHelper=new $sClassName($this->oSystem,$oDB,$this->moForm); } else { return "".utf8_encode("Daten konnten nicht gespeichert werden $sClassName!").""; } $oFormDB=new CFormDB($this->oSystem); $asCheckResult=$oFormDB->gbCheckFields($this->moForm,$this->moElements,$asData["data"],$asData["method"]); if($asCheckResult["Error"]===false) { $sAddXML=""; $bSaved=false; if($asData["method"]=="update") { if($oDBHelper!==false) { if(method_exists($oDBHelper,"gbUpdate")) { if($asData=$oDBHelper->gbUpdate($asData,$asCheckResult)) { if(is_array($asData)) { $sAddXML="".$asData["ShowPK"]."".utf8_encode($asData["ShowValue"]).""; } $bSaved=true; } } } } else { if($oDBHelper!==false) { if(method_exists($oDBHelper,"gbInsert")) { if($asData=$oDBHelper->gbInsert($asData,$asCheckResult)) { if(is_array($asData)) { $sAddXML="".$asData["ShowPK"]."".utf8_encode($asData["ShowValue"]).""; } $bSaved=true; } } } } if($bSaved===true) { $lPrimaryKey=$asData["PrimaryKey"]; return "".utf8_encode("Die Daten wurden gespeichert!")."".$sAddXML."".$lPrimaryKey."".$asCheckResult["messages"].""; } return "".utf8_encode("Daten konnten nicht gespeichert werden!\n").""; } else { return "".$asCheckResult["ErrorXML"].""; } } function gbLoadForm($sFormKey,$sMethod) { if($oResult=$this->oSystem->oDB->goQuery("SELECT *,IF(AfterInsertQuery='','__false__',AfterInsertQuery) as AfterInsertQuery, IF(AfterUpdateQuery='','__false__',AfterUpdateQuery) as AfterUpdateQuery, IF(UserPKField='','__false__',UserPKField) as UserPKField FROM tdForms WHERE FormKey='".$sFormKey."'")) { if($oResult->glGetNumberOfRecords()>0) { $this->moForm=$oResult->goGetRecord(); $this->oFormHTML=new CFormHTML($this->oSystem,$this->moForm); switch(strtolower($this->moForm->DataHandler)) { case "record": if($this->mbLoadFormData($sMethod)) { return true; } return false; break; case "list": break; } } } else return "__false__"; } function msGetQuery($lPKValue) { foreach($this->moElements as $oElement) { $sTableName=$oElement->SourceTable; if($oElement->ForeignKey!="__false__") { $sTMPTableName="comboJOIN".$sTableName; $asJoinTables[$sTableName." as ".$sTMPTableName]=$this->moForm->SourceTable.".".$oElement->FieldName."=".$sTMPTableName.".".$oElement->ForeignKey; $asFields[]=$sTMPTableName.".".$oElement->ForeignShow." as ".$sTMPTableName.$oElement->ForeignShow; $asFields[]=$sTMPTableName.".".$oElement->ForeignKey." as ".$oElement->FieldName; } else { $asFields[]=$oElement->SourceTable.".".$oElement->FieldName." as ".$oElement->FieldName; } } $sQuery="SELECT \n"; $sQuery.=join(",\n",$asFields); $sQuery.="\nFROM ".$this->moForm->SourceTable."\n"; if(sizeof($asJoinTables)>0) { foreach($asJoinTables as $sTable=>$sCondition) { $sQuery.=" LEFT JOIN ".$sTable." ON ".$sCondition."\n"; } } $sQuery.=" WHERE ".$this->moForm->SourceTable.".".$this->moForm->SourcePKField."=".$lPKValue; return $sQuery; } function gbSetData($asData) { // setzt zusätzliche daten für Anzeige template $this->masAdditionalTPLData=$asData; } function goGetFormTPL($lPK=false,$asViewData=array()) { switch(strtolower($this->moForm->DataHandler)) { case "record": return $this->moGetRecordForm($lPK,$asViewData); break; case "list": return $this->moGetListForm($lPK,$asViewData); break; } } function masGetInfo() { $sQuery="SELECT * FROM tdFormInfo WHERE FormPK=".$this->moForm->FormPK." ORDER BY RF ASC"; if($oResult=$this->oSystem->oDB->goQuery($sQuery)) { if($oResult->glGetNumberOfRecords()>0) return $oResult->gaaGetAllRecords(); return false; } return false; } function moGetRecordForm($lPK,$asViewData) { $sJSFile=PATHQS."tpl/form/js.form.record.tpl"; $oTPL=$this->oSystem->goGetTPLParser($sJSFile); $oTPL->gbSetValue("interfaceURL",$this->oSystem->oControl->oURL->gsGetInterfaceURL("form","save")); $oTPL->gbSetValue("CalendarURL",$this->oSystem->oControl->oURL->gsGetURL("Calendar",array("Simple"),"Dialoge")); $oTPL->gbSetValue("FormKey",$this->moForm->FormKey); $asData=$this->gasGetElements($lPK,$asViewData); if($lPK===false) $oTPL->gbSetValue("CurrentPK","false"); else $oTPL->gbSetValue("CurrentPK",$lPK); $this->oSystem->gbAddAdditionalJS($this->oFormHTML->sAdditionalScript); $oTPL->gbSetBlock("JSElements",$asData["JS"]); $sHTMLFile=PATHQS."tpl/form/form.".strtolower($this->moForm->FormKey).".tpl"; $oTPLHTML=$this->oSystem->goGetTPLParser($sHTMLFile); $sInfo=" "; if($asHelp=$this->masGetInfo()) { $sInfoFile=PATHQS."tpl/form/additional.info.tpl"; $oInfoTPL=$this->oSystem->goGetTPLParser($sInfoFile); $oInfoTPL->gbSetBlock("info",$asHelp); $sInfo=$oInfoTPL->gsParse(); } $oTPLHTML->gbSetValue("formAdditionalInfo",$sInfo); $oTPLHTML->gbSetBlock("HTMLElements",$asData["HTML"]); $oTPLHTML->gbSetValue("FormID","form".$this->moForm->DomFormID); $oTPLHTML->gbSetValue("tabsubmit",$this->oFormHTML->mlTabIndex++); $this->oFormHTML->mlTabIndex++; $oTPLHTML->gbSetValue("tabreset",$this->oFormHTML->mlTabIndex++); $oTPL->gbSetValue("FormID","form".$this->moForm->DomFormID); $oTPL->gbSetValue("content",$oTPLHTML->gsParse()); $oTPLReturn=$this->oSystem->goGetTPLParser($oTPL->gsParse(),false); return $oTPLReturn; } function mbLoadFormdata($sMethod) { if($sMethod!="update") { $sQuery="SELECT *, IFNULL(Type,'text') as Type, IFNULL(MouseOver,'__false__') as MouseOver, IFNULL(MouseOut,'__false__') as MouseOut, IFNULL(Activate,'__false__') as Activate, IFNULL(PreselValue,'__false__') as PreselValue , IFNULL(SourceTable,'__false__') as SourceTable, IFNULL(ForeignKey,'__false__') as ForeignKey, IFNULL(TabIndex,'__false__') as TabIndex, IFNULL(JSCheckHandler,'__false__') as JSCheckHandler, IFNULL(CheckHandler,'__false__') as CheckHandler, IFNULL(MultiSelectOptions,'__false__') as MultiSelectOptions, IFNULL(MultiSelectView,'__false__') as MultiSelectView FROM tdFormElements WHERE FormPK=".$this->moForm->FormPK." ORDER BY lpad(TabIndex,3,'0') ASC"; } else { $sQuery="SELECT *, IFNULL(Type,'text') as Type, IFNULL(MouseOver,'__false__') as MouseOver, IFNULL(MouseOut,'__false__') as MouseOut, IFNULL(Activate,'__false__') as Activate, IFNULL(PreselValue,'__false__') as PreselValue , IFNULL(SourceTable,'__false__') as SourceTable, IFNULL(ForeignKey,'__false__') as ForeignKey, IFNULL(TabIndex,'__false__') as TabIndex, IFNULL(JSCheckHandler,'__false__') as JSCheckHandler, IFNULL(CheckHandler,'__false__') as CheckHandler, IFNULL(MultiSelectOptions,'__false__') as MultiSelectOptions, IFNULL(MultiSelectView,'__false__') as MultiSelectView FROM tdFormElements WHERE DontUpdate!=-1 AND FormPK=".$this->moForm->FormPK." ORDER BY lpad(TabIndex,3,'0') ASC"; } if($oResult=$this->oSystem->oDB->goQuery($sQuery)) { if($oResult->glGetNumberOfRecords()>0) { $this->moElements=$oResult->gaoGetAllRecords(); return true; } } return false; } function gasGetElements($lPK,$asViewData) { $asPresel=false; if($lPK!==false) { $oDB=$this->oSystem->oDB; if($this->moForm->DBAccessKey!="__db__") { $oDB=new CDatabase($this->moForm->DBAccessKey); } else { } if($oData=$oDB->goQuery($this->msGetQuery($lPK))) { if($oData->glGetNumberOfRecords()>0) { $asPData=$oData->gasGetRecord(); foreach($asPData as $sKey=>$sValue) { if(is_int($sKey)===true) unset($asPData[$sKey]); } } } else { echo "
";
				echo $oDB->msQuery;
				echo mysql_error();
				return false;
			}
			
			
			}
		if(sizeof($asPData)>0)
			$asPresel=$asPData;
		$asReturn=false;
		
		if(is_array($this->moElements)&&sizeof($this->moElements)>0)
			{
			$asReturn=array();
			$asJS=array();
			foreach($this->moElements as $oElement)
				{
				$sID=$this->moForm->DomFormID.$oElement->FieldName;
				$asJSPush["DOMFormID"]=$sID;
				$asJSPush["checkHandler"]=$oElement->JSCheckHandler;
				array_push($asJS,$asJSPush);
				$asHTMLPush["Anzeige"]=$oElement->Anzeige;
				$asHTMLPush["PflichtFeld"]=$this->gbIsPflicht($oElement->CheckHandler)===true?"*":"";
				$asHTMLPush["Eingabe"]=$this->oFormHTML->gsGetHTML($oElement,$sID,$asPresel,$asViewData);
				array_push($asReturn,$asHTMLPush);
				}
			}
		return array("HTML"=>$asReturn,"JS"=>$asJS);
		}
	function gbIsPflicht($sCheck)
		{
		$as=explode(":",$sCheck);
		if(is_array($as))
			{
			$sMethod=strtolower(array_shift($as));
			switch($sMethod)
				{

				case "gbUniqueValue":
					if($as[0]=="nonempty")
						return true;
					break;
				case "gbnonempty":
					return true;
				case "gbphonenumber":
					if($as[0]=="nonempty")
						return true;
					break;
				case "gbdatum":
					if($as[0]=="nonempty")
						return true;
					break;
				case "gbuhrzeit":
					if($as[0]=="nonempty")
						return true;
					break;
				case "gbcheckpassword":
					return true;
				case "gbCFserial":
					return true;
				case "gbnumber":
					if($as[0]=="nonempty")
						return true;
					break;
				case "gbnumberstring":
					if($as[0]=="nonempty")
						return true;
					break;
				case "gbcheckusername":	
					return true;
				case "gbismail":
					
					if($as[0]=="nonempty")
						return true;
					break;
				case "gbuniquefieldmd":
					return true;
				}
			}
		
		return false;
		}
		
	}
	
	
class CFormDB
	{
	function CFormDB(&$oSystem)
		{
		$this->oSystem=&$oSystem;
		}
	function gbCheckFields($oForm,$asElements,$asData,$sMethod)
		{
		$this->msMethod=$sMethod;
		$bError=false;
		$this->oDB=$this->oSystem->oDB;
		if($oForm->DBAccessKey!="__db__")
			{
			$this->oDB=new CDatabase($oForm->DBAccessKey);
			
			}
		$sErrorXML="";
		foreach($asElements as $oElement)
			{
			$sValue=$asData[$oElement->FieldName];
				
				if($oElement->CheckHandler!="__false__")
					{
					$asCheckHandler=explode(":",$oElement->CheckHandler);
					if(method_exists($this,$asCheckHandler[0]))
						{
						$asReturnData=call_user_method($asCheckHandler[0],$this,$sValue,$asCheckHandler[1],$asCheckHandler[2],$asCheckHandler[3],$oElement);
						if($asReturnData["doSave"]===true)
							{
							if($asReturnData["Value"]!==false)
								{
								$asSaveData[$oElement->FieldName]=$asReturnData["Value"];
								}
							else
								$sWarnings.="".utf8_encode($oElement->Anzeige." wird nicht verändert!")."";
							}
						else
							{
							
							$sJSDOMID=$oForm->DomFormID.$oElement->FieldName;
							if($oElement->Type=="combo")
								$sJSDOMID.="Show";
							$sErrorXML.="".$sJSDOMID."";
							$bError=true;
							}
						}
					else
						{
						$sWarnings.="".$asCheckHandler[0]." existiert nicht";
						}
					}
				else
					{
					$asSaveData[$oElement->FieldName]=CDatabase::gsString2SQL2($sValue);
					}
				
				
			}
		return array("ErrorXML"=>$sErrorXML,"Error"=>$bError,"SaveData"=>$asSaveData,"messages"=>$sWarnings);
		}
	/* checkroutines for dbvalues */
	function masReturnData($ok,$sValue)
		{
		/*
			0: check ok/ not ok;
				// wenn nicht ok, ist 1 egal!
			1: wert für UPDATE INSERT;
		*/
		$sValue=($sValue);
		return array("doSave"=>$ok,"Value"=>$sValue);
		}
	function gbUniqueValue($sValue,$sEmpty,$sTable,$sField,$oElement)
		{
		
		$sValue=urldecode($sValue);
		$sValue=trim($sValue);
		
		if($sMustBe=="empty" && trim($sValue)=="")
			return $this->masReturnData(true,"''");
		if($sValue=="")
			return array(false,"");
		if($this->msMethod!="update" &&  $this->oDB->glGetNumberOfRecords($sTable,$oElement->FieldName."='".$sValue."'")>0)
			
			return array(false,"");
		
		if($this->msMethod=="update" && $this->oDB->glGetNumberOfRecords($oElement->SourceTable,$oElement->FieldName."='".$sValue."'")==1)
			return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		}
	function gbUniqueFieldMD($sValue,$sEmpty,$sTable,$sField)
		{
		$sValue=urldecode($sValue);
		$sValue=trim($sValue);
		if($sMustBe=="empty" && trim($sValue)=="")
			return $this->masReturnData(true,"''");
		if($sValue=="")
			return array(false,"");

		if($this->oDB->glGetNumberOfRecords($sTable,$sField."='".$sValue."' AND IFNULL(DeleteDate,-1)=-1")>0)
			return array(false,"");
		return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		}
	function gbCheckUserName($sValue)
		{
		$sValue=urldecode($sValue);
		$sValue=trim($sValue);
		if($sValue=="")
			return array(false,"");
		if(strlen($sValue)<6)
			return array(false,"");
		if($this->oDB->glGetNumberOfRecords("tdUser","UserName='".$sValue."'")>0)
			return array(false,"");
		return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		}
	function gbEmpty($sValue)
		{
		$sValue=urldecode($sValue);
		return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		}
	function gbCheckPassword($sValue)
		{
		// password nicht ändern
		if(trim($sValue)==""&&$this->msMethod=="update")	
			return $this->masReturnData(true,false);
		if(strlen($sValue)<6)
			return $this->masReturnData(false,"xx");
		return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		}	
	function gbIsMail($sValue,$sMustBe)
		{
		if($sMustBe=="empty" && trim($sValue)=="")
			return $this->masReturnData(true,"''");
		if(trim($sValue)=="")
			return $this->masReturnData(false,"");
		$atPos=strpos($sValue,chr(64));
		if($atPos===false)
			return $this->masReturnData(false,"");
		$dotPos=strpos($sValue,".",$atPos);
		if($dotPos+1!=$atPos)
			return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		return $this->masReturnData(false,"NULL");
		}
	function gbNonEmpty($sValue)
		{			
		 if(trim($sValue)!="")

		 	return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		return $this->masReturnData(false,"NULL");
		}
	function gbUhrzeit($sValue,$sMustBe)
		{
		if($sMustBe=="empty" && trim($sValue)=="")
			{
			return $this->masReturnData(true,"''");
			}
		$asUhr=explode(":",$sValue);
		if(sizeof($asUhr)<2)
			return $this->masReturnData(false,"''");
		if($asUhr[0]<0 || $asUhr[0]>23)	
			return $this->masReturnData(false,"''");
		if($asUhr[1]<0 || $asUhr[1]>59)	
			return $this->masReturnData(false,"''");
		return $this->masReturnData(true,CDatabase::gsString2SQL2(join(":",$asUhr)));
		}
	function gbDatum($sValue,$sMustby)
		{
		if($sMustBe=="empty" && trim($sValue)=="")
			{
			return $this->masReturnData(true,"''");
			}
		$asDatum=explode(".",$sValue);
		if(sizeof($asDatum)!=3)
			return $this->masReturnData(false,"''");
		$asDat["DAY"]=$asDatum[0];
		$asDat["MONTH"]=$asDatum[1];
		$asDat["YEAR"]=$asDatum[2];
		$oDT=new CDateTime();
		if($lTimeStamp=$oDT->glGetTSFromArray($asDat))
			{
			return $this->masReturnData(true,CDatabase::gsString2SQL2(date("Y-m-d",$lTimeStamp)));
			}
		return $this->masReturnData(false,"''");
		}
	function gbPhoneNumber($sValue,$sMustBe)
		{
		// wenns leer sein darf und die rufnummer leer ist, TRUE, kann gespeichert werden
		if($sMustBe=="empty" && trim($sValue)=="")
			{
			return $this->masReturnData(true,"''");
			}
		$asAllowedNumber[]="+";
		$asAllowedNumber[]="-";
		$asAllowedNumber[]="/";
		$asAllowedNumber[]="1";
		$asAllowedNumber[]="2";
		$asAllowedNumber[]="3";
		$asAllowedNumber[]="4";
		$asAllowedNumber[]="5";
		$asAllowedNumber[]="6";
		$asAllowedNumber[]="7";
		$asAllowedNumber[]="8";
		$asAllowedNumber[]="9";
		$asAllowedNumber[]="0";
		if(trim($sValue)=="")
			return false;
		$bReturn=true;
		$lCount=strlen($sValue);
		for($i;$i<$lCount;$i++)
			{
			$sChar=substr($sValue,$i,1);
			if(in_array($sChar,$asAllowedNumber))
				{
				}
			else
				$bReturn=false;
			}
		
		if( $bReturn===true)
			return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		return $this->masReturnData(false,"NULL");
		}
	function gbNullIfEmpty($sValue)
		{
		if(trim($sValue)=="")
			return $this->masReturnData(true,"NULL");
		return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		}
	function gbMoney($sValue,$sMustBe,$sRet)
		{
		if($sRet==$sValue)
			return $this->masReturnData(true,$sRet);
		// wenns leer sein darf und die rufnummer leer ist, TRUE, kann gespeichert werden
		if($sMustBe=="empty" && trim($sValue)=="")
			{
			return $this->masReturnData(true,$sRet);
			}
		$asAllowedNumber[]="1";
		$asAllowedNumber[]=".";
		$asAllowedNumber[]="2";
		$asAllowedNumber[]="3";
		$asAllowedNumber[]="4";
		$asAllowedNumber[]="5";
		$asAllowedNumber[]="6";
		$asAllowedNumber[]="7";
		$asAllowedNumber[]="8";
		$asAllowedNumber[]="9";
		$asAllowedNumber[]="0";
		if(trim($sValue)=="")
			return false;
		$sValue=str_replace(",",".",$sValue);
		$bReturn=true;
		$lCount=strlen($sValue);
		for($i;$i<$lCount;$i++)
			{
			$sChar=substr($sValue,$i,1);
			if(in_array($sChar,$asAllowedNumber))
				{
				}
			else
				$bReturn=false;
			}
		if($bReturn===true)
			{
			return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
			}
		return $this->masReturnData(false,"NULL");
		}
	function gbCFserial($sValue,$sMustBe,$sRet,$sDummy,$oElement)
		{
		$sValue=str_pad($sValue,8,"0",STR_PAD_LEFT);
		
		if($sRet!="unique")
			if($sRet==$sValue)
				return $this->masReturnData(true,$sRet);
		// wenns leer sein darf und die rufnummer leer ist, TRUE, kann gespeichert werden
		
		if($sMustBe=="empty" && trim($sValue)=="")
			{
			return $this->masReturnData(true,$sRet);
			}
		if($sRet=="unique")
			{
			if($this->oDB->glGetNumberOfRecords($oElement->SourceTable,$oElement->FieldName."='".$sValue."'")>0)
				return $this->masReturnData(false,"");
			}
		$asAllowedNumber[]="1";
		$asAllowedNumber[]="2";
		$asAllowedNumber[]="3";
		$asAllowedNumber[]="4";
		$asAllowedNumber[]="5";
		$asAllowedNumber[]="6";
		$asAllowedNumber[]="7";
		$asAllowedNumber[]="8";
		$asAllowedNumber[]="9";
		$asAllowedNumber[]="0";
		if(trim($sValue)=="")
			return false;
		$bReturn=true;
		$lCount=strlen($sValue);
		for($i;$i<$lCount;$i++)
			{
			$sChar=substr($sValue,$i,1);
			if(in_array($sChar,$asAllowedNumber))
				{
				}
			else
				$bReturn=false;
			}
		if( $bReturn===true)
			return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		return $this->masReturnData(false,"NULL");
		}
	function gbNumber($sValue,$sMustBe,$sRet,$sDummy,$oElement)
		{
		if($sRet!="unique")
			if($sRet==$sValue)
				return $this->masReturnData(true,$sRet);
		// wenns leer sein darf und die rufnummer leer ist, TRUE, kann gespeichert werden
		
		if($sMustBe=="empty" && trim($sValue)=="")
			{
			return $this->masReturnData(true,$sRet);
			}
		if($sRet=="unique")
			{
			if($this->oDB->glGetNumberOfRecords($oElement->SourceTable,$oElement->FieldName."='".$sValue."'")>0)
				return $this->masReturnData(false,"");
			}
		$asAllowedNumber[]="1";
		$asAllowedNumber[]="2";
		$asAllowedNumber[]="3";
		$asAllowedNumber[]="4";
		$asAllowedNumber[]="5";
		$asAllowedNumber[]="6";
		$asAllowedNumber[]="7";
		$asAllowedNumber[]="8";
		$asAllowedNumber[]="9";
		$asAllowedNumber[]="0";
		if(trim($sValue)=="")
			return false;
		$bReturn=true;
		$lCount=strlen($sValue);
		for($i;$i<$lCount;$i++)
			{
			$sChar=substr($sValue,$i,1);
			if(in_array($sChar,$asAllowedNumber))
				{
				}
			else
				$bReturn=false;
			}
		if( $bReturn===true)
			return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		return $this->masReturnData(false,"NULL");
		}
	function gbNumberString($sValue,$sMustBe,$sRet)
		{
		if($sRet==$sValue)
			return $this->masReturnData(true,$sRet);
		// wenns leer sein darf und die rufnummer leer ist, TRUE, kann gespeichert werden
		if($sMustBe=="empty" && trim($sValue)=="")
			{
			return $this->masReturnData(true,$sRet);
			}
		$asAllowedNumber[]="1";
		$asAllowedNumber[]="2";
		$asAllowedNumber[]="3";
		$asAllowedNumber[]="4";
		$asAllowedNumber[]="5";
		$asAllowedNumber[]="6";
		$asAllowedNumber[]="7";
		$asAllowedNumber[]="8";
		$asAllowedNumber[]="9";
		$asAllowedNumber[]="0";
		if(trim($sValue)=="")
			return false;
		$bReturn=true;
		$lCount=strlen($sValue);
		for($i;$i<$lCount;$i++)
			{
			$sChar=substr($sValue,$i,1);
			if(in_array($sChar,$asAllowedNumber))
				{
				}
			else
				$bReturn=false;
			}
		if( $bReturn===true)
			return $this->masReturnData(true,CDatabase::gsString2SQL2($sValue));
		return $this->masReturnData(false,"NULL");
		}
	}
class CFormHTML
	{
	function CFormHTML(&$oSystem,&$oForm)
		{
		$this->moForm=&$oForm;
		$this->oSystem=&$oSystem;
		$this->mlTabIndex=false;
		}
	function gsGetHTML($oElement,$sDOMID,$asPreselData=array(),$asViewData)
		{
		$this->mlTabIndex=$this->mlTabIndex===false?$oElement->TabIndex:$this->mlTabIndex;
		$asAttributes["id"]=$sDOMID;
		$asAttributes["zIndex"]="0";
		
		$asAttributes["type"]=$oElement->Type=="__false__"?"text":$oElement->Type;
		
		if($oElement->TabIndex!="__false__")
			{
			$asAttributes["tabindex"]=$this->mlTabIndex;
			}
		if($oElement->CSSClass!="")
			{
			$asAttributes["class"]=$oElement->CSSClass;
			}
		$oElement->CSSStyle.=";z-index:1";
		if($oElement->CSSStyle!="")
			{
			$asAttributes["style"]=$oElement->CSSStyle;
			}
		if($oElement->MouseOver!="__false__")
			{
			$asAttributes["onmouseover"]=$oElement->MouseOver;
			}
		if($oElement->Change!="__false__")
			{
			$asAttributes["onchange"]=$oElement->Change;
			}
		if($oElement->KeyUp!="__false__")
			{
			$asAttributes["onkeyup"]=$oElement->KeyUp;
			}
		if($oElement->Activate!="__false__")
			{
			$asAttributes["onactivate"]=$oElement->Activate;
			}
		if($oElement->MouseOver!="__false__")
			{
			$asAttributes["onmouseover"]=$oElement->MouseOver;
			}
		if(isset($asPreselData[$oElement->FieldName]))
			$oElement->PreselValue=$asPreselData[$oElement->FieldName];
		$asAttributes["name"]=$oElement->FieldName;
		$oElement->PreselValue=$this->msHtmlEntities($oElement->PreselValue);
		if(strtolower($oElement->Type)=="text"||strtolower($oElement->Type)=="cfserial")
			{
			if($oElement->PreselValue!="__false__")
				{
				if(strtolower($oElement->TagName)=="input")
					$asAttributes["value"]=$oElement->PreselValue;
				else
					$innerHTML=$oElement->PreselValue;
				}
			else
				{
				}
			}
		else
			{
			$asAttributes["value"]="__SET__";
			}
		if($oElement->Type=="cfserial")
			$asAttributes["maxlength"]=8;
		$sHTML="<".$oElement->TagName;
		$sHTML.=$this->gsBuildAttributes($asAttributes).">";
		switch(strtolower($oElement->TagName))
			{
			case "input":
				switch(strtolower($oElement->Type))
					{
					case "cfserial":
					case "text":
						 if($oElement->AdditionalHTML!="")
							$sHTML.=$oElement->AdditionalHTML;
						$this->mlTabIndex++;
						return $sHTML;
						break;
					
					case "checkBox":
					case "radio":
						if($oElement->MultiSelectOptions!="__false__")
							{
							$asData=explode("||",$oElement->MultiSelectOptions);
							$sReturn="";
							$asDataX=array();
							foreach($asData as $sKey=>$sSelectOptions)
								{
								$asPair=explode(":",$sSelectOptions);
								$sAnzeige=$asPair[0];
								$sValue=$asPair[1];
								$asPush="array('".str_replace("'","\\'",$sValue)."','".str_replace("'","\\'",$sAnzeige).")";
								array_push($asDataX,$asPush);
								$asAttributes["tabindex"]++;
								$asAttributes["value"]=$sValue;
								$asAttributes["checked"]=false;
								if(strtolower($oElement->Type)=="radio")
									$asAttributes["name"]=$oElement->FieldName;
								else
									$asAttributes["name"]=$oElement->FieldName.$sKey;
								$asAttributes["id"]=$sDOMID;
								if(strtolower($oElement->Type)!="radio")
								$asAttributes["id"]=$sDOMID.$sKey;
								$asAttributes["tabindex"]=$this->mlTabIndex;
								$this->mlTabIndex++;
								if($oElement->PreselValue==$sValue)
									{
									$asAttributes["checked"]=true;
									}
								
								$sReturn.="<".$oElement->TagName.$this->gsBuildAttributes($asAttributes).">".$oElement->AdditionalHTML."\n";								
								}
							}						
						return $sReturn;
						break;
					case "helper":
						$sComboName="oHelper".$sDOMID;
						if($asPreselData["AddressPK"]=="")
							{
							$oDB=$this->oSystem->oDB;
							if($this->moForm->DBAccessKey!="__db__")
								{
								
								$oDB=new CDatabase($this->moForm->DBAccessKey);
								$oX=$this->oSystem->goGetTPLParser($oElement->MultiSelectOptions,false);
								$oX->gbSetValArray($asViewData);
								$sQuery=$oX->gsParse();
								if($oRes=$oDB->goQuery($sQuery))
									{
									$oRec=$oRes->goGetRecord();
									$sShowVal=$oRec->ShowVal;
									$sPresValue=$oRec->ValueVal;
									}
								}
							}	
						else
							{
							$sPresValue=$asPreselData[$oElement->FieldName];
							$sShowVal=$asPreselData["comboJOIN".$oElement->SourceTable.$oElement->ForeignShow];
							}
						$sReturn="";
						unset($asAttributes["name"]);
						$sHelperURL=$this->oSystem->oControl->oURL->gsGetURL($oElement->MultiSelectView,false,"Dialoge",array("Key"=>$sPresValue,"rnd"=>md5(mt_rand())));
						$onclick="javascript:openHelper('".$sHelperURL."',400,500,document.getElementById('".$asAttributes["id"]."Show'),document.getElementById('".$asAttributes["id"]."'));";
						$sReturn.="gsBuildAttributes($asAttributes)." style=vertical-align:middle;cursor:hand>";;
						return $sReturn;
						break;
					case "uhrzeit":
						$sPresel=$asPreselData[$oElement->FieldName];
						if(empty($asPreselData[$oElement->FieldName]))
							$sPresel=date("H:i");
						else
							{
							$asHM=explode(":",$asPreselData[$oElement->FieldName]);
							array_pop($asHM);
							$sPresel=join(":",$asHM);
							}
						$sReturn="gsBuildAttributes($asAttributes)." style=vertical-align:middle>";;
						return $sReturn;
						break;
					case "datum":
						$sPresel=$asPreselData[$oElement->FieldName];
						if(empty($asPreselData[$oElement->FieldName]))
							$sPresel=date("d.m.Y");
						else
							{
							$sPresel=CDateTime::gsSqlToDate($sPresel);
							}
						unset($asAttributes["onmousewheel"]);
						$sReturn="gsBuildAttributes($asAttributes)." style=vertical-align:middle>";;
						return $sReturn;
						break;
					case "combo":
						$sComboName="oComboBox".$sDOMID;
						unset($asAttributes["value"]);
			 			// $asAttributes["onfocusout"]="javascript:alert(window.event.keyCode);".$sComboName.".hide(true)";
						$asAttributes["onfocusin"]="javascript:".$sComboName.".show()";
						$asData=array();
						$asDataX=array();
						$lPreselKey=0;
						$lCount=0;
						if($oElement->MultiSelectOptions!="__false__")
							{
							$asData=explode("||",$oElement->MultiSelectOptions);
							$lCount=sizeof($asData)-1;
							}
						if($oElement->MultiSelectView!="__false__");
							{
							if($oData=$this->oSystem->oDB->goGetResultView($oElement->MultiSelectView,$asViewData,$this->moForm->DBAccessKey))
								{
								$asDataDB=$oData->gaaGetAllRecords(true);
								if(is_array($asDataDB))
									{
									foreach($asDataDB as $sKey=>$asRecord)
										{
										$asDataX[$sKey+$lCount]=$asRecord["selectShow"].":".$asRecord["selectValue"];
										if($asRecord["IsPresel"]=="true")
											$lPreselKey=$sKey+$lCount;
										}
								 	}
								 }
							else
								{	
								}
							}
						$asData=array_merge($asData,$asDataX);

						if($asPreselData[$oElement->FieldName]=="")
							{
							$asFirstValue=explode(":",$asData[$lPreselKey]);
							$sPresShow=$asFirstValue[0];
							$sPresValue=$asFirstValue[1];
							}
						else
							{
							$sPresShow=$asPreselData["comboJOIN".$oElement->SourceTable.$oElement->ForeignShow];
							$sPresValue=$asPreselData[$oElement->FieldName];
							}
						
						$sReturn="";
						unset($asAttributes["name"]);
						unset($asAttributes["id"]);
						$sShow=$asPreselData[$oElement->ForeignShow]==""?$asData[0][0]:$asPreselData[$oElement->ForeignShow];
						//$asAttributes["onkeyup"]="alert(window.event.keyCode)";
						$sReturn.="gsBuildAttributes($asAttributes).">";;
							$asDataX=array();
							foreach($asData as $sKey=>$sSelectOptions)
								{
								$asPair=explode(":",$sSelectOptions);
								$sAnzeige=$asPair[0];
								$sValue=$asPair[1];
								$asPush="new Array('".str_replace("'","\\'",$sValue)."','".str_replace("'","\\'",$sAnzeige)."')";
								array_push($asDataX,$asPush);
								$asAttributes["tabindex"]++;
								$asAttributes["value"]=$sValue;
								$asAttributes["checked"]=false;
								if(strtolower($oElement->Type)=="radio")
									$asAttributes["name"]=$oElement->FieldName;
								else
									$asAttributes["name"]=$oElement->FieldName.$sKey;
								$asAttributes["id"]=$sDOMID;
								if(strtolower($oElement->Type)!="radio")
								$asAttributes["id"]=$sDOMID.$sKey;
								$asAttributes["tabindex"]=$this->mlTabIndex;
								$this->mlTabIndex++;
								if($oElement->PreselValue==$sValue)
									{
									$asAttributes["checked"]=true;
									}
								// $sReturn.="<".$oElement->TagName.$this->gsBuildAttributes($asAttributes).">".$oElement->AdditionalHTML."\n";								
								}
							// 
							
							$this->sAdditionalScript.="";
					//htmlentities($this->sAdditionalScript);
						//	$this->sAdditionalScript.=$sComboName.".showAndHide()";
						unset($asData);
							return $sReturn;
							break;
							}
						unset($asData);
						break;
					
				break;
			case "textarea";
				$sInnerHTML=htmlentities($asPreselData[$oElement->FieldName]);
				$sHTML.=$sInnerHTML."TagName.">";
				$this->mlTabIndex++;
				return $sHTML;
				break;
			}
		
		}
	function msHtmlEntities($sString)
		{
		// prevents from JS errors parsing strings
		$sString=str_replace("'","\'",$sString);
		$sString=htmlentities($sString);
		return $sString;
		}
	function gsBuildAttributes($asAttributes)
		{
		$asReturn=array();
		foreach($asAttributes as $sName=>$sValue)
			{
			if($sValue===true)
				{
				$sPush=$sName;
				}
			elseif($sValue===false)	
				{
				}
			else
				$sPush=$sName."=\"".$sValue."\"";
			array_push($asReturn,$sPush);
			}
		if(sizeof($asReturn)>0)
			return " ".join(" ",$asReturn)." ";
		return "";
		}
	}