<?php

	function ceTerminalCopyCfg($termType=false, $configContent=false, $termId=false){
		$writeTmp=false;
		$xCopy=false;
			if(strlen($configContent) > 11 ){
				$targetPath=false;
				if(strtolower($termType) == 'six'){
					$filePath="include\cardPayment\sixTmp.cfg";
					$targetPath="c:\sitpos\bankomat\six\TimApi.cfg";
				}
				else if(strtolower($termType) == 'hobex')
				{
					// bei Hobex wird die exe auch in das unterverzeichnis gelegt, damit verschiedene cfg Dateien genommen werden
					$filePath="include\cardPayment\hobexTmp.cfg";
					// Check ob es das Directory gibt, sonst anlegen
					$checkCmd="start /B dir C:\sitpos\bankomat\hobex\\".$termId;
					$checkZft=shell_exec($checkCmd);
					if(preg_match('/'.$termId.'/i', $checkZft)){
						$targetPath="c:\sitpos\bankomat\hobex\\".$termId."\\hobex_zahlen.exe.config";
					}
					else
					{
						$mkDirCmd="start /B mkdir C:\sitpos\bankomat\hobex\\".$termId;
						$mkDir=shell_exec($mkDirCmd);
						$targetPath="c:\sitpos\bankomat\hobex\\".$termId."\\hobex_zahlen.exe.config";
						writeLog(basename( __FILE__)." ". __LINE__ , "Directory angelegt ".$checkCmd."  term id -> ".$termId." -> : ".$mkDir." ---> ".$targetPath."\n");
					}
					// exe kopieren
					shell_exec("start /B copy c:\sitpos\bankomat\hobex\\hobex_zahlen.exe c:\sitpos\bankomat\hobex\\".$termId."\\");
					shell_exec("start /B copy c:\sitpos\bankomat\hobex\\Hobex.ECR.Terminal.dll c:\sitpos\bankomat\hobex\\".$termId."\\");
					shell_exec("start /B copy c:\sitpos\bankomat\hobex\\log4net.dll c:\sitpos\bankomat\hobex\\".$termId."\\");
					shell_exec("start /B copy c:\sitpos\bankomat\hobex\\nunit.framework.dll c:\sitpos\bankomat\hobex\\".$termId."\\");
				}
				else if(strtolower($termType) == 'zvt'){
					$filePath="include\cardPayment\zvtTmp.cfg";
					$checkCmd="start /B dir C:\sitpos\bankomat\zvt\\".$termId;
					$checkZft=shell_exec($checkCmd);
					if(preg_match('/'.$termId.'/i', $checkZft)){
						$targetPath="c:\sitpos\bankomat\zvt\\".$termId."\\easybpi.cfg";
					}
					else{
						$mkDirCmd="start /B mkdir C:\sitpos\bankomat\zvt\\".$termId;
						$mkDir=shell_exec($mkDirCmd);
						$targetPath="c:\sitpos\bankomat\zvt\\".$termId."\\easybpi.cfg";
						writeLog(basename( __FILE__)." ". __LINE__ , "check dir  worr NED do ".$checkCmd."  term id -> ".$termId." -> : ".$mkDir." ---> ".$targetPath."\n");
					}
					
					
				}
								
				$writeTmp=file_put_contents($filePath, $configContent);
				writeLog(basename( __FILE__)." ". __LINE__ , "tmp file write -> : ".$writeTmp."\n");
				if($writeTmp !== false){
					#$shellCmd="start /B copy ".$filePath." ".$targetPath;
					$shellCmd="start /B copy ".$filePath." ".$targetPath;
					$xCopy=shell_exec($shellCmd);
					
					writeLog(basename( __FILE__)." ". __LINE__ , "copy file  -> : ".$xCopy."\n");
				}
			}
			else{
				$writeTmp="config leer od ungültig (min 11 Zeichen lang)";
			}
		
		//return $writeTmp." / ".$termType." / ".$xCopy;
		
	}
	
//echo "jetzt editieren Key: " . $this->rec;
//echo "\n\n\n Type: " . $newvals['terminal_type'];

ceTerminalCopyCfg($newvals['terminal_type'], $newvals['terminal_config'], $newvals['terminal_id']);
?>