COMPILE ROUTINE FIX_REACT_MODE(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE obj_Schedule,Send_Dyn,Send_Info, RList
DECLARE FUNCTION Get_Status, Set_Printer

$INSERT OIPRINT_EQUATES

$INSERT REACT_MODE_EQUATES

EQU TARGET_ACTIVELIST$ to 5

*EQU CRLF$	TO \0D0A\

OPEN 'REACT_MODE' To ReactModeTable ELSE GOTO Bail


SelectSent = 'SELECT REACT_MODE WITH REACT_NO "62" AND WITH START_DTM >= "1/6/2015 11:00:00" BY START_DTM '

RList(SelectSent,TARGET_ACTIVELIST$, "", "", "")

TotRecCnt = @RECCOUNT

DEBUG

Done = 0
RecCnt = 0
PrevKey = ''
LOOP
	READNEXT ReactModeKey ELSE Done = 1
UNTIL Done 
	RecCnt += 1
	
		StartDTM = OCONV(ReactModeKey[-1,'B*'],'DT4^HS')
		
		READ ReactModeRec FROM ReactModeTable,ReactModeKey THEN
			
			StopDTM = ReactModeRec<REACT_MODE_STOP_DTM$>
			StopUser = ReactModeRec<REACT_MODE_STOP_USER$>
			
			
			IF StopDTM NE '' AND StopUser = '' THEN
				StopUser = XLATE('REACT_MODE','60*':StopDTM,REACT_MODE_START_USER$,'X')
			
				ReactModeRec<REACT_MODE_STOP_USER$> = StopUser
				
				*WRITE ReactModeRec ON ReactModeTable,ReactModeKey THEN
					Send_Dyn(ReactModeKey:' ':OCONV(StartDTM,'DT^S'):' ':StopDTM:' ':StopUser)
				*END
			END
		
		END
	
	
REPEAT

GOTO Bail




GOTO Bail

SELECT ReactModeTable

DEBUG

Done = 0
RecCnt = 1
FixCnt = 0

LOOP
	READNEXT REactModeKey ELSE Done = 1
UNTIL Done
	RecCnt += 1
	READ ReactModeRec FROM ReactModeTable,ReactModeKey THEN
		StartNote	= ReactModeRec<REACT_MODE_START_NOTE$>
		StopNote	= ReactModeRec<REACT_MODE_STOP_NOTE$>
		FixedFlag	= 0
		
		IF INDEX(StartNote,CRLF$,1) THEN
			
			SWAP CRLF$ WITH ' ' IN StartNote
			ReactModeRec<REACT_MODE_START_NOTE$> = StartNote
			FixedFlag = 1
		END
		
		IF INDEX(StopNote,CRLF$,1) THEN
			
			SWAP CRLF$ WITH ' ' IN StopNote
			ReactModeRec<REACT_MODE_STOP_NOTE$> = StopNote
			FixedFlag = 1
		END
		
		IF FixedFlag THEN
			WRITE ReactModeRec ON ReactModeTable,ReactModeKey THEN
				FixCnt += 1
			END
		END	
		
	END
	RecCnt += 1
	Send_Info(RecCnt:' ':FixCnt)
REPEAT





GOTO Bail



ReactNo = 26

EndDTM = QUOTE(OCONV(Date() - 3,'D4'):' ':OCONV(Time(),'MTS'))


SelectSent = 'SELECT REACT_MODE WITH REACT_NO = ':QUOTE(ReactNo):' AND WITH START_DTM > ':EndDTM:' BY-DSND START_DTM'

RList(SelectSent,TARGET_ACTIVELIST$, "", "", "")

debug


Done = 0
RecCnt = 0
PrevKey = ''
LOOP
	READNEXT ReactModeKey ELSE Done = 1
UNTIL Done 
	RecCnt += 1
	Send_Info(RecCnt)
	
	READ ReactModeRec FROM ReactModeTable,ReactModeKey THEN
		StartDTM = FIELD(ReactModeKEy,'*',2)
		StopDTM = ReactModeRec<REACT_MODE_STOP_DTM$>
	
		Send_Dyn(ReactModeKey:' ':StopDTM:' ':OCONV(StartDTM,'DT^S'):' ':OCONV(StopDTM,'DT^S'))
	
	/*
		IF PrevKey NE '' THEN
			*StartDTM = FIELD(PrevKey,'*',2)
			
			
			StopDTM = ReactModeRec<REACT_MODE_STOP_DTM$>
			
			Send_Dyn(ReactModeKey:' ':StopDTM:' ':OCONV(StartDTM,'DT^S'):' ':OCONV(StopDTM,'DT^S'))
			
			IF StopDTM NE StartDTM THEN
			
				ReactModeRec<REACT_MODE_STOP_DTM$> = StartDTM
				
				*WRITE ReactModeRec ON  ReactModeTable,ReactModeKey THEN
					*Send_Dyn(ReactModeKey:' ':OCONV(StartDTM,'DT^S'):' ':OCONV(StopDTM,'DT^S'))
				*END
			END
		END
		*/
		PrevKey = ReactModeKey
	END
REPEAT

GOTO Bail





IF Get_Status(errCode) THEN DEBUG


* * * * * * *
Bail:
* * * * * * *


