@Echo off

Print "-------------------------------------------------------------------------"
Print " Script...................: VolumeRevokeGrant_ForUsersToVolumeList.cmd"
Print " #New.....................: 05.06.2024 / J.Fes"
Print " #LUp.....................: 05.06.2024 / J.Fes"
Print " #Description.............: 05.06.2024 / J.Fes"
Print "-------------------------------------------------------------------------"

 set CmdCurRoot_DP=%~dp0
 set CmdCurRoot_DP=%CmdCurRoot_DP:~0,-1%
 if not defined BinPublic_DP set BinPublic_DP=%CmdCurRoot_DP%\..\..\..\..\03-BinPublic
 set JobMgrDefaults_DP=%CmdCurRoot_DP%\..\_JobMgrDefaults
 set path=%CmdCurRoot_DP%;%JobMgrDefaults_DP%;%BinPublic_DP%;%path%


 call :DateTimeNowGet

 Echo #todo: Setup Get Prompt
 set TCPrompt_Custom_DPNE=%CmdCurRoot_DP%\..\_CustomDefaults\TcPrompt\TcPrompt_Custom.cmd
 set TcSiteId=#TcSiteId#
 rem -- TC Prompt for Custom
 set TCPrompt_Custom_Opt=TcOnly
 Call "%TCPrompt_Custom_DPNE%"

 set TC_TMP_DIR=%CmdCurRoot_DP%\VolumeRevokeGrant_ForUsersToVolumeList_log\%DateTimeNowFileExt%

 if not exist "%TC_TMP_DIR%" md "%TC_TMP_DIR%"
 set temp=%TC_TMP_DIR%
 set tmp=%TC_TMP_DIR%
 set TC_LOG=%TC_TMP_DIR%
 set TC_KEEP_SYSTEM_LOG=TRUE



 Echo Logs are located at dir: %TC_TMP_DIR%
 start "" explorer "%TC_TMP_DIR%"
 pause

 Echo #toDo: set up tc user
 set JobMgr_TcUseUPG=-u=#infodba# -p=#custompwuser# -g=dba

 Echo #toDo: set up user List
 Echo Do Grand for UserList Volumes
 set UserList=refileusr01
 set UserList=%UserList%;refileusr02
 set UserList=%UserList%;refileusr03
 set UserList=%UserList%;refileusr04
 set UserList=%UserList%;refileusr05
 set UserList=%UserList%;refileusr06
 set UserList=%UserList%;refileusr07
 set UserList=%UserList%;refileusr08
 set UserList=%UserList%;refileusr09
 set UserList=%UserList%;refileusr10
 call :GrandUserToVolumes "%UserList%"


 set UserList=refileusr11
 set UserList=%UserList%;refileusr12
 set UserList=%UserList%;refileusr13
 set UserList=%UserList%;refileusr14
 set UserList=%UserList%;refileusr15
 set UserList=%UserList%;refileusr16
 set UserList=%UserList%;refileusr17
 set UserList=%UserList%;refileusr18
 set UserList=%UserList%;refileusr19
 set UserList=%UserList%;refileusr20
 set UserList=%UserList%;refileusr21
 call :GrandUserToVolumes "%UserList%"


 Echo Done
pause
goto :ende

:GrandUserToVolumes
 set TcUser_c=%1
 Echo Edit User: %TcUser_c% --------------
 set UserList=%~1
 for /d %%i in (%UserList%) do call :TcUserGrandForVols %%i
 goto :eof

:TcUserGrandForVols
 rem Edits the group and role assignment of a user
 rem Note: If the required group or role does not exist, it will be created automatically
 rem If the role has not yet been added to the group, it is automatically added to the group

 Echo #toDo: setup Volume List
 set TcUser_c=%~1
 set VolList=archiv01
 set VolList=%VolList%;archiv02
 set VolList=%VolList%;archiv03
 set VolList=%VolList%;archiv04
 set VolList=%VolList%;archiv05
 set VolList=%VolList%;archiv06
 set VolList=%VolList%;archiv07
 set VolList=%VolList%;archiv08
 set VolList=%VolList%;archiv09
 set VolList=%VolList%;archiv10

 rem -- #doc: do Grand User: %TcUser_c% to vol %%j ----------------------------
 for /d %%j in (%VolList%) do call :TcUserGrandForVol "%TcUser_c%" "%%j"

 set VolList=archiv11
 set VolList=%VolList%;archiv12
 set VolList=%VolList%;archiv13
 set VolList=%VolList%;archiv14
 set VolList=%VolList%;archiv15
 set VolList=%VolList%;archiv16
 set VolList=%VolList%;archiv17
 set VolList=%VolList%;archiv18
 set VolList=%VolList%;archiv19
 set VolList=%VolList%;archiv20

 rem -- #doc: do Grand User: %TcUser_c% to vol %%j ----------------------------
 for /d %%j in (%VolList%) do call :TcUserGrandForVol "%TcUser_c%" "%%j"

 goto :eof

:TcUserGrandForVol
 set TcUser_c=%~1
 set TcVol_c=%~2
 Echo ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----
 Echo Do VolGrand for TCuser:"%TcUser_c%" to:Vol:"%TcVol_c%"
 set toRun=make_user.exe
 set toRun=%toRun% -user=%TcUser_c%
 set toRun=%toRun% -defaultvolume=%TcVol_c%
 set toRun=%toRun% -update
 set toRun=%toRun% -V
 set toRun=%toRun% %JobMgr_TcUseUPG%

 Echo %toRun%
 call %toRun%
 Echo Result make_user.exe:%errorlevel%
 timeout /T:1
 goto :eof


rem --------------------------------------------------------------------
:DateTimeNowGet
 rem call :DateTimeNowGet
 rem Set File_LPNE=%DatRoot_LP%\MyName-%DateTimeNowFileExt%.txt


 if     "%time:~0,1%"==" " set time-h=0%time:~1,1%
 if not "%time:~0,1%"==" " set time-h=%time:~0,2%

 if     "%time:~3,1%"==" " set time-m=0%time:~4,1%
 if not "%time:~3,1%"==" " set time-m=%time:~3,2%

 set Date-Y=%Date:~6,4%
 set Date-M=%Date:~3,2%
 set Date-D=%Date:~0,2%
 set DateTimeNowFileExt=%Date-Y%-%Date-M%-%Date-D%-%time-h%-%time-m%
 goto :eof


:ende
 Pause

