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 "
"; 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."".$oElement->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 ""; } }