;*******************************************************************************
;* Configurador de Usuarios                                              *******
;*******************************************************************************
;Autor           : Vise Informatica (VISERP)
;Desenvolvido    : 01/01/2002 por Anivel Augusto Rodrigues
;Ultima Alteracao: 25/11/2004 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes novas tabelas
;Ultima Alteracao: 14/06/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Array
;Ultima Alteracao: 15/08/2007 por Anivel Augusto Rodrigues
;Motivo Alteracao: Ajustes Run

;*******************************************************************************
;* Monta Janela
;*******************************************************************************
Proc JANELAJ()
     Atua_Menu()

     Moveto [Descricao]

     REG=NRecords(Diretorio+"\\"+TABELA)
     REG=REG+3

     If REG > NREG
        Then REG=NREG
     EndIf

     TAMDESC=FieldType()
     TAMDESC=SubStr(TAMDESC,2,2)

     JANELA=GetWindow()

     Dynarray WinArray[]
     WinArray["Width"]=Numval(TAMDESC)+16
     WinArray["Height"]=REG
     WinArray["Style"]=31
     WinArray["Hasframe"]=True
     WinArray["CanClose"]=False
     WinArray["CanMove"]=False
     WinArray["CanMaximize"]=False
     WinArray["CanResize"]=False
     WinArray["HasShadow"]=true
     WinArray["Echo"]=True
     WinArray["Canvas"]=True
     WinArray["OriginCol"]=COLUNA
     WinArray["OriginRow"]=LINHA
     WinArray["Title"]=TITULO

     Window SetAttributes JANELA From WinArray
     Right
EndProc

;*******************************************************************************
;* Rotina de Escolha de Acesso
;*******************************************************************************
Proc ESCOLHE()
Moveto Diretorio+"\\"+TABELA
EditKey
CONTROLE=0
While True

     ImageRights ReadOnly

     MSGPROMPT=" Esc=Retornar  Enter=Selecionar  X=Marca/Desmarca  F5=Marcar_Todos  "
     If TABELA="M_prin"
        Then MSGPROMPT=MSGPROMPT+"F4=Copiar"
     EndIf

     Prompt MSGPROMPT

     Wait Table
        UNTIL "ESC","ENTER","X","x","RIGHT","LEFT","CTRLHOME","CTRLEND","F4","F5"

     Switch
       Case RetVal = "RIGHT" or RetVal = "LEFT" or
            RetVal = "CTRLHOME" or RetVal = "CTRLEND":
            Loop
       Case RetVal = "ESC":
            ImageRights
            clib=0
            Scan
              If [Liberado]="X" And ([Comando]<> "SAIR" Or
                                     [Comando]<> "Informa"  Or
                                     [Comando]<> "Retornar")
                 Then clib=1
              Endif
              If ([Comando]="SAIR" Or
                  [Comando]="Informa"  Or
                  [Comando]="Retornar") And clib=1
                  Then [Liberado]="X"
              Endif
            EndScan
            Do_It!
            ImageRights ReadOnly
            QuitLoop
       Case Retval = "ENTER":
            If SubStr([Comando],1,2)="M_" And
               [liberado]="X"
               Then TABELA=[Comando]
                         If [Tipo de Comando]="T"
                       Then If Not IsTable(TABELA)
                               Then XCopia_Arquivo("\\Sistemas\\Cadastro\\"+TABELA+".*")
                            EndIf
                    EndIf
                    TITULO=[Descricao]
                    CONTROLE=1
                    Do_It!
                    QuitLoop
            Endif
       Case RetVal = "F4" And TABELA="M_prin":
            ConfGeral("Deseja copiar todas as op‡”es do Sistema novamente ?")
            If OK="S"
               Then CONTROLE=2
                    Do_It!
                    ClearImage

                    XCopia_Arquivo("\\Sistemas\\Cadastro\\M_*.*")

                    QuitLoop
            EndIf
       Case RetVal = "X" or RetVal = "x":
            ImageRights
            If [Liberado]=""
               Then [Liberado]="X"
               Else [Liberado]=""
            Endif
       Case RetVal = "F5":
            ImageRights
            Scan
               [Liberado]="X"
            EndScan
            Home
       OtherWise:
          Loop
     EndSwitch
EndWhile
EndProc

Proc Atua_Menu()
Private alam, vlam, OPMENUREG
Limpa_Array_Menu()

View "\\Sistemas\\Cadastro\\"+TABELA
Edit Diretorio+"\\"+TABELA
vlam=1
Home
While True
  If Not IsBlank([Comando]) And [Liberado]="X"
     Then OPMENU[vlam]=[Comando]
  EndIf
  Del
  If IsBlank([Descricao]) Then QuitLoop EndIf
  vlam=vlam+1
EndWhile

Moveto "\\Sistemas\\Cadastro\\"+TABELA
Scan
  CopyToArray OPMENUREG

  Moveto Diretorio+"\\"+TABELA
  If Not IsBlank([Descricao])
     Then End Down
  EndIf
  CopyFromArray OPMENUREG

  For alam From 1 To 150
      If OPMENU[alam]=[Comando] And
         Not IsBlank([Comando])
         Then [Liberado]="X"
              QuitLoop
      EndIf
  EndFor
  Moveto "\\Sistemas\\Cadastro\\"+TABELA
EndScan
Do_It!
ClearImage

Moveto Diretorio+"\\"+TABELA
Home
EndProc

Proc Limpa_Array_Menu()
Private lam
For lam From 1 To 150
    OPMENU[lam]=""
EndFor
EndProc

;*******************************************************************************
;* Rotina Principal                                                            *
;*******************************************************************************

Array OPMENU[150]

TABELA ="M_prin"
TABELA1="M_prin"
TABELA2=""
TABELA3=""
NREG=21
J1=0
While True
      If J1=0
         Then TITULO="Menu Principal"
              COLUNA=01
              LINHA =02
              JANELAJ()
              J1=1
      Endif
      ESCOLHE()
      If CONTROLE=0
         Then ClearImage

              CoEdit "M_Prin"
              Scan
                If UPPER([Comando])="M_UTIL"
                    Then [Liberado]="X"
                Endif
              EndScan
              Do_It!
              ClearImage

              CoEdit "M_Util"
              Scan
                If UPPER([Comando])="SENHA"    Or
                   UPPER([Comando])="SET_IMP"  Or
                   UPPER([Comando])="SET_VID"  Or
                   UPPER([Comando])="CONTRDIA" Or
                   UPPER([Comando])="USERCON"
                    Then [Liberado]="X"
                Endif
              EndScan
              Do_It!
              ClearImage

              QuitLoop
      Endif
      If CONTROLE=2
         Then J1=0
              Loop
      EndIf
      TABELA2=TABELA
      J2=0
      While True
            If J2=0
               Then COLUNA=03
                    LINHA =05
                    NREG=15
                    JANELAJ()
                    J2=1
            Endif
            ESCOLHE()
            If CONTROLE=0
               Then ClearImage
                    TABELA=TABELA1
                    QuitLoop
            Endif
            COLUNA=21
            LINHA =02
            NREG=21
            JANELAJ()
            ESCOLHE()
            ClearImage
            TABELA=TABELA2
      EndWhile
EndWhile
ClearAll
Release Vars TABELA,TABELA1,TABELA2,TABELA3,LINHA,COLUNA,
             NREG,J1,J2,J3,CONTROLE,TITULO,TAMDESC,JANELA,REG,clib
Release Procs ESCOLHE,JANELAJ
