Page 1 of 1

Check if the user is gone away

Posted: Tue Feb 16, 2016 11:22 am
by Marco Turco
Hi,
I have a lot of customers that leave my FWH app active and go away. I need a solution to understand if the user is still working otherwise I want to automatically terminate the app.

I think something like a 15 min timer could runs but I need to reset the timer each time the user move the mouse or press a keyboard key.
Any ideas or alternatives ?

Thanks in advance

Re: Check if the user is gone away

Posted: Tue Feb 16, 2016 12:45 pm
by zekasan

Code: Select all

*************
FUNCTION Main()
*************
 
   nTempo_espera := 10         //Tempo a ser esperado ate chamar a funcao
 
   cNome_funcao := "LOGOFF()"  //nome da funcao a ser chamada quando
                               //chegar no tempo de espera
 
   lTimercontinua := .f.       //se apos executar a funcao , continua monitorando
                               //a inatividade do mouse e teclado.
 
   define window oWnd title "Teste de teclado e mouse"
 
   activate window oWnd ;
            on init tinativo():new( nTempo_espera,cNome_funcao, lTimerContinua )
 
return NIL
 

function logoff()
 
   msgalert("AQUI ENTRA SUA FUNCAO DE LOGOFF !","AVISO")
 
return nil
 
// Classe: tinativo.prg
 
#include "fivewin.ch"
 
CLASS TINATIVO
 
  DATA nTimeInpAntes
  DATA nTimeInpDepois
  DATA cTimeAtu 
  DATA nTempo
  DATA oTimerTime
  DATA cFunc
  DATA lContinuar
 
  METHOD NEW( nTime, cFuncao, lContinua )  CONSTRUCTOR
 
  METHOD ver_tempo()
 
ENDCLASS
 
**********************
METHOD new(ntime,cFuncao,lContinua) CLASS TINATIVO
**********************
 
   ::cfunc:=cfuncao
   ::ntempo:=ntime
   ::lContinuar:=lContinua
   ::oTimerTime := TTimer():New( 1000, { || ::VER_TEMPO() } )
   ::oTimerTime:Activate()
   ::cTimeAtu := time()
   ::nTimeInpAntes := getInputState()    // 0 = erro
 
return self
 
*************************
METHOD VER_TEMPO CLASS TINATIVO
*************************
 
   ::nTimeInpDepois := getInputState()
 
   if ( ::nTimeInpDepois - ::nTimeInpAntes ) > 0
 
      ::nTimeInpAntes := getInputState()
 
      ::cTimeAtu := time()
 
   endif
 
   if ( CONVTIME(time()) - CONVTIME(::cTimeAtu) ) > ::ntempo
 
      ::oTimerTime:DeActivate()
 
      aux := ::cfunc
   
      * aqui executa a funcao
 
      &aux
 
      if ::lContinuar
 
         ::oTimerTime:Activate()
 
         ::cTimeAtu := time()
 
      endif
 
   endif
 
return NIL

Re: Check if the user is gone away

Posted: Tue Feb 16, 2016 1:40 pm
by ukoenig
Wanted to test it, but there are two missing functions :

::nTimeInpAntes := getInputState()

IF ( CONVTIME(time() )

possible to include them :?:

Instead of using CONVTIME, I could use my function

Code: Select all


FUNCTION ELAPSED(dStart, dEnd, cTimeStart, cTimeEnd)
LOCAL nTotalSec, nCtr, nConstant, nTemp, aRetVal[4,2]
 
IF ! ( VALTYPE(dStart) $ 'DC' )
    dStart := DATE()
ELSEIF VALTYPE(dStart) == 'C'
    cTimeStart := dStart
    dStart := DATE()
ENDIF
 
IF ! ( VALTYPE(dEnd) $ 'DC' )
    dEnd := DATE()
ELSEIF VALTYPE(dEnd) == 'C'
    cTimeEnd := dEnd
    dEnd := DATE()
ENDIF
 
IF( VALTYPE(cTimeStart) != 'C', cTimeStart := '00:00:00', )
IF( VALTYPE(cTimeEnd)   != 'C', cTimeEnd   := '00:00:00', )
 
nTotalSec  := (dEnd - dStart) * 86400                              + ;
                VAL(cTimeEnd)   *  3600                              + ;
                VAL(SUBSTR(cTimeEnd,AT(':', cTimeEnd)+1,2)) * 60     + ;
                IF(RAT(':', cTimeEnd) == AT(':', cTimeEnd), 0,         ;
                VAL(SUBSTR(cTimeEnd,RAT(':', cTimeEnd)+1)))          - ;
                VAL(cTimeStart) * 3600                               - ;
                VAL(SUBSTR(cTimeStart,AT(':', cTimeStart)+1,2)) * 60 - ;
                IF(RAT(':', cTimeStart) == AT(':', cTimeStart), 0,     ;
                VAL(SUBSTR(cTimeStart,RAT(':', cTimeStart)+1)))
 
nTemp := nTotalSec
 
FOR nCtr = 1 to 4
    nConstant := IF(nCtr == 1, 86400, IF(nCtr == 2, 3600, IF( nCtr == 3, 60, 1)))
    aRetVal[nCtr,1] := INT(nTemp/nConstant)
    aRetval[nCtr,2] := nTotalSec / nConstant
    nTemp -= aRetVal[nCtr,1] * nConstant
NEXT
 
RETURN aRetVal
 
best regards
Uwe :?:

Re: Check if the user is gone away

Posted: Tue Feb 16, 2016 1:46 pm
by karinha

Re: Check if the user is gone away

Posted: Tue Feb 16, 2016 2:31 pm
by ukoenig
Thank You very much

Tested and works fine !

Maybe my usage gives You a idea to include it inside Your own app ?

I added this solution to my METRO-app section ALARMCLOCK / DateTime -function to define the parameters.
The main-function : a sound is played at a defined date and time. 3 different date/times are possible.
NEW : a defined workingtime < 0 > means the function is disabled.
You can define : closing the app or showing a new LOGIN.


Image

My MAIN-window :
aVal[51] is the time defined inside my alarmclock-function
SHOW_TD(oWnd) opens the alarmclock

ACTIVATE WINDOW oWnd MAXIMIZED ;
ON INIT ( SHOW_TD(oWnd), IIF( aVal[51] > 0, TINATIVO():New( 3, "LOGOFF()", .F. ), NIL ) ) ;
ON CLICK IIF( nRow > ScreenHeight() - 100 .and. nCol > ScreenWidth() - 100, ;
oWnd:End(), ( nBenutzer := USERLOGIN(oWnd), ;
IIF( nBenutzer > 0, ( LOAD_SYS1(nBenutzer), BUILDMETRO(oWnd) ), oWnd:End() ) ) ) ;
ON PAINT ( ABPaint( hDC, ( ScreenWidth() / 2 ) - ( oImgTouch:nWidth / 2 ), ;
( ScreenHeight() / 2 ) - ( oImgTouch:nHeight / 2 ), oImgTouch:hBitmap, 255 ),; // DrawTransparent( hDC, oImgTouch:hBitmap, 250, 500 ),;
ABPaint( hDC, ScreenWidth() - 100, ScreenHeight() - 40,;
oImgEnd:hBitmap, 255 ), ;
oImgEnd:End() )

New LOGIN selected from alarmclock-section after a defined elapsed time :

Image

Code: Select all

FUNCTION LOGOFF()

IF  aVal[52] = 2 // Quit selected
      oWnd:End()
ELSE                // new login selected
   IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
         DBSELECTAREA("SYSTEM")
         LOAD_SYS1(nBenutzer)
         nBenutzer := USERLOGIN(oWnd) // valid = nBenutzer > 0
         IF nBenutzer = 0
              oWnd:End()
         ELSE
              BUILDMETRO(oWnd) 
         ENDIF
    ENDIF
ENDIF
 
RETURN NIL
 
best regards
Uwe :D

Re: Check if the user is gone away

Posted: Wed Feb 17, 2016 11:27 am
by ukoenig
I added a third option to carry on working from
the point, the program has been locked.

Code: Select all

FUNCTION LOGOFF()
LOCAL nOldselect 

IF  aVal[52] = 1
    CLOSE DATABASE
    oWnd:End()
ELSEIF  aVal[52] = 2
    CLOSE DATABASE
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN1(oWnd) 
        IF nBenutzer = 0
            oWnd:End()
        ELSE
            BUILDMETRO(oWnd) 
        ENDIF
    ENDIF
ELSEIF  aVal[52] = 3   // carry on working 
    nOldselect := SELECT()
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN2(oWnd) // small extra login
        DBSELECTAREA( nOldselect )
    ENDIF
ENDIF
 
RETURN NIL
 
best regards
Uwe :D

Re: Check if the user is gone away

Posted: Wed Feb 17, 2016 11:28 am
by ukoenig
I added a third option to carry on working from
the point, the program has been locked.

Image

Code: Select all

FUNCTION LOGOFF()
LOCAL nOldselect 

IF  aVal[52] = 1 // CLOSE
    CLOSE DATABASE
    oWnd:End()
ELSEIF  aVal[52] = 2 // NORMAL LOGIN
    CLOSE DATABASE
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN1(oWnd) 
        IF nBenutzer = 0
            oWnd:End()
        ELSE
            BUILDMETRO(oWnd) 
        ENDIF
    ENDIF
ELSEIF  aVal[52] = 3   // CARRY ON WORKING 
    nOldselect := SELECT()
    IF NET_USE ( c_Pfad3 + "SYSTEM.dbf", "SYSTEM", 3, .T. ) 
        DBSELECTAREA("SYSTEM")
        LOAD_SYS1(nBenutzer)
        nBenutzer := USERLOGIN2(oWnd) // small extra login
        DBSELECTAREA( nOldselect )
    ENDIF
ENDIF
 
RETURN NIL
 
best regards
Uwe :D

Re: Check if the user is gone away

Posted: Wed Feb 17, 2016 4:32 pm
by Marco Turco
Solved, thank you all for the tricks.

Re: Check if the user is gone away

Posted: Wed Feb 17, 2016 7:20 pm
by ukoenig
Marco,
there is a useful solution from Daniel.
Closes the program and starts again for login.

http://forums.fivetechsupport.com/viewt ... ch#p108676

best regards
Uwe :lol: