@echo off

REM #Doc: Controls AutoCheckin for TC via tcpb_auto_checkin.exe
REM      Date       User   Description
REM #New:31.07.2018 J.Fes  created
REM #LUp:

  set CmdCurRoot_DP=%~dp0
  set CmdCurRoot_DP=%CmdCurRoot_DP:~0,-1%
  set path=%CmdCurRoot_DP%;%CmdCurRoot_DP%\..\_CustomDefaults\TcPrompt;%CmdCurRoot_DP%\..\_JobMgrDefaults;%path%

  call ColorSet IsIdel


  rem --#toDo: setup default "#TcSiteId#"
  set TcSiteId=tc11prod
  if "%~1" neq "" set TcSiteId=%~1
  rem #ToDo: define dir containing plm easy tool
  set tcpbBin_DP=%CmdCurRoot_DP%\tc10_bin64
  set tcpbBin_DP=R:\tc11prodlocal\win64\bin

  Echo ---------------------------------------------------------------------------
  Echo before get tc prompt for %TcSiteId%
  Call "%CmdCurRoot_DP%\..\_CustomDefaults\TcPrompt\TcPrompt_Custom.cmd" "%TcSiteId%"
  call "%TC_DATA%\tc_profilevars.bat"
  if "%JobMgr_TCPromptGet_ResCode%" equ "0"  goto :Start

  call ColorSet ERR
  Echo.
  Echo ---------------------------------------------------------------------------
  Echo ERROR in "%0"
  Echo Please Check Script settings
  Echo script ends without doing any thing
  pause
  Exit /B

:Start
  rem insert in path variable tcpbBin_DP
  set path=%tcpbBin_DP%;%tc_root%\bin;%path%

  REM #todo: add Groups
  call :tcpb_auto_checkinDo dba
  rem call :tcpb_auto_checkinDo group2

  call ColorSet END
  pause
  goto :eof


:tcpb_auto_checkinDo
  rem P1 = name der Gruppe
  set TC_CheckInGroup=%~1

  call ColorSet IsExecuting

  rem get env variable DateTimeStamp
  call DateTimeGet.cmd
  set Log_DP=%CmdCurRoot_DP%\Log\TC_AutoCheckIn_#Group_%TC_CheckInGroup%\%DateTimeStamp%
  if not exist "%Log_DP%" md "%Log_DP%"

  set temp=%Log_DP%
  set tmp=%Log_DP%

  set TC_SQL_DEBUG=
  set TC_TMP_DIR=%temp%
  set TC_KEEP_SYSTEM_LOG=TRUE
  set TC_Journalling=OFF
  set TC_Journaling=OFF
  set TC_TRACEBACK=OFF

  Set tcpb_auto_checkin_LOG_DPNE=%Log_DP%\tcpb_auto_checkin_#Group_%TC_CheckInGroup%_Log.txt

  set titleTxt=[%TcSiteId%] tcpb_auto_checkin.exe:[%TC_CheckInGroup%] Log:%tcpb_auto_checkin_LOG_DPNE%
  Echo.
  Echo --------------------------------------------------------------------------------
  Echo %titleTxt%
  title %titleTxt%
  set toRun=%tcpbBin_DP%\tcpb_auto_checkin.exe -u=infodba -p=infodba -g=dba -all -group=%TC_CheckInGroup% -log="%tcpb_auto_checkin_LOG_DPNE%"
REM   set toRun=%tcpbBin_DP%\tcpb_auto_checkin.exe -help
REM   Echo %toRun%
REM   pause
  call %toRun%
  set PrgExitCode=%errorlevel%

  if "%PrgExitCode%" equ "0" call ColorSet OK
  if "%PrgExitCode%" neq "0" call ColorSet ERR

  goto :eof
