Attribute VB_Name = "FacSysParameter"
Option Explicit
Public FaxUser() As String '(0,i) = Faxnummer (1,i) = UserName
Public objFaxSession As FaxSession
Public FaxServerAnzeigen As Boolean
Public FaxServer As String

Public CurrentFaxUserName As String
Public CurrentFaxUser



Public Enum FU
  faxDW = 0
  NTUser = 1
  PersKZ = 2
  ZPers1 = 3
  ZMAX = 11
End Enum

Public Enum ErrorMailFehlerstelle
    FaxSend = 1
    DruckJob = 2
    AmFaxserverAnmelden_User = 4
    AmFaxserverAnmelden_Status = 8
End Enum

    
Public Enum ObjectClassID
       FaxMsg_Object_Session = 1
       FaxMsg_Object_Folders = 2
       FaxMsg_Object_Folder = 3
       FaxMsg_Object_Messages = 4
       FaxMsg_Object_Message = 5
       FaxMsg_Object_Recipients = 6
       FaxMsg_Object_Recipient = 7
       FaxMsg_Object_Attachments = 8
       FaxMsg_Object_Attachment = 9
       FaxMsg_Object_CoverPages = 10
       FaxMsg_Object_CoverPage = 11
       FaxMsg_Object_Phonebooks = 12
       FaxMsg_Object_Phonebook = 13
       FaxMsg_Object_PhonebookEntries = 14
       FaxMsg_Object_PhonebookEntry = 15
       FaxMsg_Object_PhonebookContainers = 16
       FaxMsg_Object_PhonebookContainer = 17
       FaxMsg_Object_Fields = 18
       FaxMsg_Object_Field = 19
       FaxMsg_Object_Users = 20
       FaxMsg_Object_User = 21
End Enum
  

Public Enum FACSysSecurityAttributes
       FaxMsg_FSA_ROUTER_ENABLE = 5 ' // enable router
       FaxMsg_FSA_DISABLED = 6 ' // account logon disabled
       FaxMsg_FSA_ADMINISTRATOR = 7 ' // administrator access
       FaxMsg_FSA_MANAGER_APPROVAL = 8 ' // manager approval required
       FaxMsg_FSA_DIAL_PREFIX = 9 ' // enable dialing prefix
       FaxMsg_FSA_DIAL_SUFFIX = 10 ' // enable dialing suffix
       FaxMsg_FSA_SERVER_FOLDERS = 11 ' // access to server folders
       FaxMsg_FSA_SCHEDULE_PRIORITY = 22 ' // schedule priority messages
       FaxMsg_FSA_CHANGE_PASSWORD = 26 ' // change logon password
       FaxMsg_FSA_ROUTE_FAXES = 28 ' // route unread faxes to others
       FaxMsg_FSA_SCHEDULE = 31 ' // schedule fax messages
       FaxMsg_FSA_SELECT_COVERPAGE = 32 ' // select cover page
       FaxMsg_FSA_BROADCAST_RESTRICTION = 33 ' // enforce broadcast restriction
       FaxMsg_FSA_OFFPEAK_ONLY = 34 ' // enforce off-peak fax messages
       FaxMsg_FSA_CREATE_PHONEBOOK = 35 ' // create phonebooks
       FaxMsg_FSA_DELETE_PHONEBOOK = 36 ' // delete phonebooks
       FaxMsg_FSA_ADD_RECIPIENT = 37 ' // add recipients
       FaxMsg_FSA_MODIFY_RECIPIENT = 38 ' // modify recipients
       FaxMsg_FSA_CREATE_COVERPAGE = 39 ' // create cover pages
       FaxMsg_FSA_DELETE_COVERPAGE = 40 ' // delete cover pages
       FaxMsg_FSA_MODIFY_COVERPAGE = 41 ' // modify cover page information
End Enum
  

Public Enum ReservedFolderID
       FaxMsg_Folder_Root = 0 '
       FaxMsg_Folder_Outbox = 1 '
       FaxMsg_Folder_SentItems = 2 '
       FaxMsg_Folder_Inbox = 3 '
       FaxMsg_Folder_DeletedItems = 4 '
       FaxMsg_Folder_Unrouted = 5 '
       FaxMsg_Folder_PendingApproval = 6 '
       FaxMsg_Folder_SystemRoot = 10 '
       FaxMsg_Folder_SystemOutbox = 11 '
       FaxMsg_Folder_SystemSentItems = 12 '
       FaxMsg_Folder_SystemInbox = 13 '
       FaxMsg_Folder_ReservedLast = 13
End Enum
  

Public Enum FolderFlagValues
       FaxMsg_FolderFlags_Reserved = 255
       FaxMsg_FolderFlags_Preview = 256
       FaxMsg_FolderFlags_GridLines = 512
End Enum
  

Public Enum FolderType
       FaxMsg_FolderType_None = 0 '
       FaxMsg_FolderType_Message = 1 '
       FaxMsg_FolderType_Phonebook = 2
End Enum
  

Public Enum MessageType
       FaxMsg_MsgType_None = 0 '
       FaxMsg_MsgType_Send = 1 '
       FaxMsg_MsgType_Receive = 2
End Enum
  

Public Enum MessagePriority
       FaxMsg_Priority_Low = 0 '
       FaxMsg_Priority_Normal = 1 '
       FaxMsg_Priority_High = 2 '
       FaxMsg_Priority_Urgent = 3
End Enum
  

Public Enum MessageFlag
       FaxMsg_MsgFlag_Processed = 1 '
       FaxMsg_MsgFlag_Opened = 2 '
       FaxMsg_MsgFlag_Printed = 4 '
       FaxMsg_MsgFlag_Routed = 8 '
       FaxMsg_MsgFlag_User1 = 1024 '
       FaxMsg_MsgFlag_User2 = 2048
End Enum
  

Public Enum RecipientFilterFlag
       FaxMsg_RecipFilter_All = 0 '
       FaxMsg_RecipFilter_Complete = 1 '
       FaxMsg_RecipFilter_Canceled = 2 '
       FaxMsg_RecipFilter_Pending = 4 '
       FaxMsg_RecipFilter_Failed = 8
End Enum
  

Public Enum FileResolution
       FaxMsg_Resolution_Low = 0 '
       FaxMsg_Resolution_High = 1 '
       FaxMsg_Resolution_300DPI = 2 '
       FaxMsg_Resolution_400DPI = 3
End Enum
  

Public Enum FileDeleteMode
       FaxMsg_DeleteMode_Never = 0 '
       FaxMsg_DeleteMode_Done = 1 '
       FaxMsg_DeleteMode_Purge = 2 '
       FaxMsg_DeleteMode_AfterSend = 4096
End Enum
  

Public Enum SortOrder
       FaxMsg_Sort_Ascending = 1 '
       FaxMsg_Sort_Descending = 2
End Enum
  

Public Enum MessageStatus
       FaxMsg_MsgStatus_Pending = 0 '
       FaxMsg_MsgStatus_Complete = 1 '
       FaxMsg_MsgStatus_CompleteWithCancel = 2 '
       FaxMsg_MsgStatus_CompleteWithError = 3 '
       FaxMsg_MsgStatus_OnHold = 4 '
       FaxMsg_MsgStatus_PendingApproval = 5 '
       FaxMsg_MsgStatus_ApprovalDenied = 6 '
       FaxMsg_MsgStatus_PendingRemote = 7
End Enum


Public Enum RecipientStatus
       FaxMsg_Status_Pending = 0 '
       FaxMsg_Status_Complete = 1 '
       FaxMsg_Status_Canceled = 2 '
       FaxMsg_Status_TelephoneError = 3 '
       FaxMsg_Status_LocalError = 4 '
       FaxMsg_Status_RemoteError = 5 '
       FaxMsg_Status_Incompatible = 6 '
       FaxMsg_Status_NoFax = 7 '
       FaxMsg_Status_FileError = 8 '
       FaxMsg_Status_Busy = 9 '
       FaxMsg_Status_AccessDenied = 10 '
       FaxMsg_Status_Unknown = 11 '
       FaxMsg_Status_InvRemoteTX = 12 '
       FaxMsg_Status_InvRemoteMsg = 13 '
       FaxMsg_Status_Disconnect = 14 '
       FaxMsg_Status_NoRemoteBFT = 15 '
       FaxMsg_Status_RetryExceeded = 16 '
       FaxMsg_Status_NoCommonBitRate = 17 '
       FaxMsg_Status_DisconnectAfterPage = 18 '
       FaxMsg_Status_NoResponseAfterPage = 19 '
       FaxMsg_Status_RemoteIncompatible = 20 '
       FaxMsg_Status_NoDialTone = 21 '
       FaxMsg_Status_InvResponse = 22 '
       FaxMsg_Status_LineBusy = 23 '
       FaxMsg_Status_LineDead = 24 '
       FaxMsg_Status_No2ndDialTone = 25 '
       FaxMsg_Status_Timeout = 26 '
       FaxMsg_Status_InvCmdAfterPage = 27 '
       FaxMsg_Status_InvRemoteRX = 28 '
       FaxMsg_Status_MissingBlocks = 29 '
       FaxMsg_Status_ReceiveOverrun = 30 '
       FaxMsg_Status_ReceiveUnderrun = 31 '
       FaxMsg_Status_1stLineTimeout = 32 '
       FaxMsg_Status_ScanLineTooLong = 33 '
       FaxMsg_Status_NoAnswer = 34 '
       FaxMsg_Status_Cancel = 35 '
       FaxMsg_Status_SendTimeExpired = 36 '
       FaxMsg_Status_OnHold = 37 '
       FaxMsg_Status_RouterSubmitted = 38 '
       FaxMsg_Status_RouterPendingRemote = 39 '
       FaxMsg_Status_RouterPendingCancel = 40 '
       FaxMsg_Status_RouterPendingDelete = 41 '
       FaxMsg_Status_InvFileFormat = 42 '
       FaxMsg_Status_RendererNoAccess = 43 '
       FaxMsg_Status_RendererFailure = 44 '
       FaxMsg_Status_ImglibFailure = 45 '
       FaxMsg_Status_ConversionFailure = 46 '
       FaxMsg_Status_PageFailure = 47 '
       FaxMsg_Status_EnvNoAccess = 48 '
       FaxMsg_Status_CoverPageFailure = 49 '
       FaxMsg_Status_PendingApproval = 50 '
       FaxMsg_Status_ApprovalDenied = 51 '
       FaxMsg_Status_BlackListed = 52 '
       FaxMsg_Status_Last = 53
End Enum
  

Public Enum DeviceActivity
       FaxMsg_Activity_Idle = 0 '
       FaxMsg_Activity_Unavailable = 1 '
       FaxMsg_Activity_Resetting = 2 '
       FaxMsg_Activity_Ringing = 3 '
       FaxMsg_Activity_Answering = 4 '
       FaxMsg_Activity_Negotiating = 5 '
       FaxMsg_Activity_Dialing = 7 '
       FaxMsg_Activity_Sending = 8 '
       FaxMsg_Activity_Canceling = 9
End Enum
  

Public Enum ReleaseMessageAction
       FaxMsg_MsgAction_Release = 1 '
       FaxMsg_MsgAction_Approve = 2 '
       FaxMsg_MsgAction_Deny = 3
End Enum
  

Public Enum FileType
       FaxMsg_FileType_Detect = 0 '
       FaxMsg_FileType_ASCII = 1 '
       FaxMsg_FileType_PCX = 2 '
       FaxMsg_FileType_BMP = 3 '
       FaxMsg_FileType_DCX = 4 '
       FaxMsg_FileType_TIF = 5 '
       FaxMsg_FileType_MG3 = 6 '
       FaxMsg_FileType_CPE = 7 '
       FaxMsg_FileType_PCL = 8 '
       FaxMsg_FileType_Postscript = 9 '
       FaxMsg_FileType_RTF = 10 '
       FaxMsg_FileType_RPL = 11 '
       FaxMsg_FileType_GIF = 12 '
       FaxMsg_FileType_HTML = 13 '
       FaxMsg_FileType_MSWord = 14 '
       FaxMsg_FileType_MSExcel = 15 '
       FaxMsg_FileType_MSPowerPoint = 16 '
       FaxMsg_FileType_MSWrite = 17 '
       FaxMsg_FileType_AcrobatPDF = 18 '
       FaxMsg_FileType_Document = 19
End Enum
  

Public Enum JobType
       FaxMsg_JobType_Fax = 0 '
       FaxMsg_JobType_BFT = 1 '
       FaxMsg_JobType_Print = 2 '
       FaxMsg_JobType_Email = 3 '
       FaxMsg_JobType_MSFax = 4 '
       FaxMsg_JobType_MSFaxBFT = 5 '
       FaxMsg_JobType_MSExchange = 6 '
       FaxMsg_JobType_WebAgent = 7
End Enum
  

Public Enum ImageCompression
       FaxMsg_ImgComp_None = 1 '
       FaxMsg_ImgComp_Huffman1D = 2 '
       FaxMsg_ImgComp_Group3 = 3 '
       FaxMsg_ImgComp_Group4 = 4 '
       FaxMsg_ImgComp_LZW = 5 '
       FaxMsg_ImgComp_DCX = 16 '
       FaxMsg_ImgComp_PCX = 17 '
       FaxMsg_ImgComp_RLE4 = 18 '
       FaxMsg_ImgComp_RLE8 = 19 '
       FaxMsg_ImgComp_PackedBits = 32773
End Enum
  

Public Enum ImageCopyOptions
       FaxMsg_ImgOption_2D = 1 '
       FaxMsg_ImgOption_Uncomp = 2 '
       FaxMsg_ImgOption_EOLPad = 4 '
       FaxMsg_ImgOption_InvertBits = 8 '
       FaxMsg_ImgOption_UseResolution = 16 '
       FaxMsg_ImgOption_FillPage = 32 '
       FaxMsg_ImgOption_SplitImage = 64 '
       FaxMsg_ImgOption_ScaleImage = 128 '
       FaxMsg_ImgOption_WordAlign = 256 '
       FaxMsg_ImgOption_DWordAlign = 512 '
       FaxMsg_ImgOption_Stream = 1024 '
       FaxMsg_ImgOption_Compress = 2048 '
       FaxMsg_ImgOption_MultiStrip = 4096 '
       FaxMsg_ImgOption_EnhanceBlack = 8192 '
       FaxMsg_ImgOption_GrayScale = 16384
End Enum
  

Public Enum PhonebookType
       FaxMsg_PhonebookType_Personal = 1 '
       FaxMsg_PhonebookType_System = 2 '
       FaxMsg_PhonebookType_ODBC = 3
End Enum
  

Public Enum PhonebookEntryType
       FaxMsg_PhonebookEntryType_Recipient = 0 '
       FaxMsg_PhonebookEntryType_Group = 1 '
       FaxMsg_PhonebookEntryType_OneOff = 2
End Enum
  

Public Enum PhonebookEntryProperty
       FaxMsg_PB_RECIP_ID = 1 '
       FaxMsg_PB_FLAGS = 2 '
       FaxMsg_PB_FIRST_NAME = 3 '
       FaxMsg_PB_LAST_NAME = 4 '
       FaxMsg_PB_MIDDLE_NAME = 5 '
       FaxMsg_PB_TITLE_NAME = 6 '
       FaxMsg_PB_SUFFIX_NAME = 7 '
       FaxMsg_PB_DISPLAY_NAME = 8 '
       FaxMsg_PB_COMPANY = 9 '
       FaxMsg_PB_JOB_TITLE = 10 '
       FaxMsg_PB_DEPT = 11 '
       FaxMsg_PB_OFFICE = 12 '
       FaxMsg_PB_MANAGER = 13 '
       FaxMsg_PB_ASSISTANT = 14 '
       FaxMsg_PB_ADDRESS_BUSINESS = 15 '
       FaxMsg_PB_CITY_BUSINESS = 16 '
       FaxMsg_PB_STATE_BUSINESS = 17 '
       FaxMsg_PB_ZIP_BUSINESS = 18 '
       FaxMsg_PB_COUNTRY_BUSINESS = 19 '
       FaxMsg_PB_ADDRESS_HOME = 20 '
       FaxMsg_PB_CITY_HOME = 21 '
       FaxMsg_PB_STATE_HOME = 22 '
       FaxMsg_PB_ZIP_HOME = 23 '
       FaxMsg_PB_COUNTRY_HOME = 24 '
       FaxMsg_PB_ADDRESS_OTHER = 25 '
       FaxMsg_PB_CITY_OTHER = 26 '
       FaxMsg_PB_STATE_OTHER = 27 '
       FaxMsg_PB_ZIP_OTHER = 28 '
       FaxMsg_PB_COUNTRY_OTHER = 29 '
       FaxMsg_PB_BUSINESS_FAX = 30 '
       FaxMsg_PB_HOME_FAX = 31 '
       FaxMsg_PB_OTHER_FAX = 32 '
       FaxMsg_PB_BUSINESS_PHONE = 33 '
       FaxMsg_PB_HOME_PHONE = 34 '
       FaxMsg_PB_MOBILE_PHONE = 35 '
       FaxMsg_PB_PAGER_PHONE = 36 '
       FaxMsg_PB_OTHER_PHONE = 37 '
       FaxMsg_PB_EMAIL = 38 '
       FaxMsg_PB_WEBURL = 39 '
       FaxMsg_PB_BILLING_CODE = 40 '
       FaxMsg_PB_CONTAINER_ID = 41 '
       FaxMsg_PB_TYPE = 42 '
       FaxMsg_PB_DESCRIPTION = 43 '
       FaxMsg_PB_NOTE = 44 '
       FaxMsg_PB_DEFAULT_FAX = 45 '
       FaxMsg_PB_USERDEF0 = 46 '
       FaxMsg_PB_USERDEF1 = 47 '
       FaxMsg_PB_USERDEF2 = 48 '
       FaxMsg_PB_USERDEF3 = 49 '
       FaxMsg_PB_NUM_FIELDS = 49
End Enum
  

Public Enum MessageProperty
       FaxMsg_MSG_ID = 1 '
       FaxMsg_MSG_TYPE = 2 '
       FaxMsg_MSG_TO = 3 '
       FaxMsg_MSG_FROM = 4 '
       FaxMsg_MSG_SENT = 5 '
       FaxMsg_MSG_EXPIRE = 6 '
       FaxMsg_MSG_RECEIVED = 7 '
       FaxMsg_MSG_PRIORITY = 8 '
       FaxMsg_MSG_SUBJECT = 9 '
       FaxMsg_MSG_BILLING_CODE = 10 '
       FaxMsg_MSG_STATUS = 11 '
       FaxMsg_MSG_PAGES = 12 '
       FaxMsg_MSG_JOBTYPE = 13 '
       FaxMsg_MSG_CONNECT = 14 '
       FaxMsg_MSG_UNREAD = 15 '
       FaxMsg_MSG_DEVICE = 16 '
       FaxMsg_MSG_ROUTINGINFO = 17 '
       FaxMsg_MSG_USERDEF1 = 18 '
       FaxMsg_MSG_USERDEF2 = 19 '
       FaxMsg_MSG_USERDEF3 = 20 '
       FaxMsg_MSG_USERDEF4 = 21 '
       FaxMsg_MSG_USERDEF5 = 22 '
       FaxMsg_MSG_USERDEF6 = 23 '
       FaxMsg_MSG_USERDEF7 = 24 '
       FaxMsg_MSG_USERDEF8 = 25 '
       FaxMsg_MSG_NUM_FIELDS = 25
End Enum
  

Public Enum FACSysUserType
       FaxMsg_UserType_User = 1 '
       FaxMsg_UserType_Group = 2
End Enum


Public Function CreateMessageStatus(ByVal MessageMessageStatus As Variant) As String
Dim Description
Description = Array("Senden", _
                    "Erledigt", _
                    "Erledigt (Benutzerabbruch)", _
                    "Erledigt (Fehler)", _
                    "Warten", _
                    "Sendeerlaubins?", _
                    "Zustimmung Verweigert", _
                    "Warten auf Gegenstelle")
                    
  CreateMessageStatus = Description(MessageMessageStatus)
End Function

Public Function CreateRecipientStatus(ByVal MessageRecipientsStatus As Variant) As String
Dim Description
Description = Array("Senden", "Erledigt", "Storniert", "Telefon Fehler", "Lokaler Fehler", _
                    "Entferntes Fax Fehler", "Inkompatibel", "Kein Fax", "File Fehler", "Belegt", _
                    "Zugriff Verweigert", "Unbekannt", "InvRemoteTX", "InvRemoteMsg", _
                    "Nicht Verbunden", "NoRemoteBFT", "Wiederholungsanzahl überschritten", _
                    "NoCommonBitRate", "Verbindungsabrruch nach der Seite", _
                    "Keine Rückantwort nach der Seite", "Gegenstelle Inkompatibel", "Kein Wählton", _
                    "InvRespnse", "Leitung belegt", "Leitung tot", "Kein Zweiter Wählton", _
                    "Timeout", "InvCmdAfterPage", "InvRemoteRX", "Missing Blocks", "ReceiveOverrun", _
                    "ReceiveUnderrun", "1stLineTimeout", "ScanLineTooLong", "Keine Antwort", _
                    "Abbruch", "SendTimeExpired", "Warten", "RouterSubmitted", "RouterPendingRemote", _
                    "RouterPendingCancel", "RouterPendingDelete", "InvFileFormat", "RendererNoAccess", _
                    "RendererFailure", "ImglibFailure", "Umwandlungsfehler", "Seiten Fehler", "EnvNoAccess", _
                    "Deckblattfehler", "Sendenerlaubnis?", "Zustimmung Verweigert", "BlackListed", "Last")
                    
  CreateRecipientStatus = Description(MessageRecipientsStatus)
End Function

Public Function AmFaxserverAnmelden(ByVal Firma As String, ByVal Personal As String, Optional FaxCSVDirFilename As String, Optional Kennung As String) As String
Dim obj As Object, PNR As Integer
Dim FaxNr As Integer, Text As String, Faxusername As String
Dim FaxStat As String, AnmeldStat As String
Dim dummy
Dim j As Byte, i As Byte
Dim methode As Object
If FaxCSVDirFilename = "" Then FaxCSVDirFilename = cacheParameterGet("FBM", "FaxUser", , "\\nadlinger\pc\fax.csv", True)
LockEIN
        'von Personal auf FAX User ?
        If Personal = "" Then Personal = "MEP"
        'If Personal = "58" Then Personal = "CAR"
        Set obj = WWS_Server.OpenId("BM.ParPersEdv", Firma & "||" & Umlaut(Personal, "GUIBAUMAT"))
        PNR = obj.PNR
        ObjektSchließen obj
        Set obj = WWS_Server.OpenId("BM.PersBasis", Firma & "||" & PNR)
        FaxNr = obj.fax
        ObjektSchließen obj
        Faxusername = FaxUserErmitteln(FaxNr, FaxCSVDirFilename)
        'If Faxusername = "" Then
        If ErrorMailJN(Faxusername = "", ErrorMailFehlerstelle.AmFaxserverAnmelden_User) Then
          On Error GoTo FehlerMeldung
          Set methode = WWS_Server.Static("GUI.Standard")
          dummy = methode.MailSend(ErrorMailAbsender, ErrorMailEmpfänger, "Baumat Fax Anmeldefehler", "Kein Faxuser für:" + Personal + " gefunden. Kennung: " + Kennung)
          On Error GoTo 0
          ObjektSchließen methode
        End If
        'Anabmeldung wenn neuer Faxuser notwendig ist
        'Vom Faxserver abmelden
        If Not objFaxSession Is Nothing Then
           objFaxSession.Logoff
           Set objFaxSession = Nothing
        End If
        'Am Faxserver anmelden
        AnmeldStat = Anmelden(Faxusername)
        If AnmeldStat <> "" Then AnmeldStat = Anmelden(Faxusername) '2 x Versuchen!!
        AmFaxserverAnmelden = AnmeldStat
    'If AnmeldStat <> "" Then
    If ErrorMailJN(AnmeldStat <> "", ErrorMailFehlerstelle.AmFaxserverAnmelden_Status) Then
      StatusText "FacSysParameter.AmFaxserverAnmelden", AnmeldStat
      'Fehlermeldung per Mail
      On Error GoTo FehlerMeldung
      Set methode = WWS_Server.Static("GUI.Standard")
      dummy = methode.MailSend(ErrorMailAbsender, ErrorMailEmpfänger, "Baumat Fax Anmeldefehler", "Anmeldung für User:" + Faxusername + " Kennung: " + Kennung)
      On Error GoTo 0
      ObjektSchließen methode
    End If
LockAUS
Exit Function
FehlerMeldung:
 MsgBox "Vorgang: " + "Ungültige Anfrage! Kein Ergebnis gefunden" + vbCrLf + vbCrLf + _
        "Aufruf von Mailsend." + vbCrLf + vbCrLf + _
        "Fehler: " + CStr(err.Number) + vbCrLf _
        + err.Description + vbCrLf + vbCrLf _
         , vbExclamation, "Caché Zugriffsfehler"
LockAUS
End Function

Public Function Anmelden(ByVal User As String) As String
'Am Faxserver Anmeldden
 If Not User = "Administrator" And User <> "" Then CurrentFaxUserName = User
 If Not objFaxSession Is Nothing Then
     objFaxSession.Logoff
     Set objFaxSession = Nothing
 End If
 If objFaxSession Is Nothing Then
  Set objFaxSession = CreateObject("facsys.faxsession")
 End If
 On Error Resume Next
 objFaxSession.Logon FaxServer, User, ""
 If Not err.Number = 0 Then
  Dim txtMsg As String
  txtMsg = "Fax Anmeldefehler Fehler User " + User + " #" & str(err.Number) & " Beschreibung: " & err.Description
  ' Display message box with Stop sign icon and OK button.
  'MsgBox txtMsg, vbCritical, "Anmeldung am Faxserver für " & User & " fehlgeschlagen!"
  Debug.Print txtMsg
  Anmelden = txtMsg
  Set objFaxSession = Nothing
 End If
End Function


Sub FaxNummernZuordnung(Optional FaxCSVDirFilename As String)
'Beim Vormladen bzw beim Neulesen der Parameter aufrufen!
Dim Dateidaten, wert() As String
Dim i As Integer, j As Byte
If FaxCSVDirFilename = "" Then FaxCSVDirFilename = cacheParameterGet("FBM", "FaxUser", , "\\nadlinger\pc\fax.csv", True)
i = 0
Open FaxCSVDirFilename For Input As #1   ' Datei zum Einlesen öffnen.
Do While Not EOF(1)   ' Auf Dateiende abfragen.
   Line Input #1, Dateidaten   ' Datenzeilen lesen.
   ReDim Preserve FaxUser(FU.ZMAX + 1, i)
   wert = Split(Dateidaten, ";")
   FaxUser(FU.NTUser, i) = Format(wert(0), "<") 'User
   FaxUser(FU.faxDW, i) = wert(1)  'Nummer
   On Error Resume Next
     For j = FU.PersKZ To FU.ZMAX
        FaxUser(j, i) = wert(j)
     Next j
   On Error GoTo 0
   Debug.Print Dateidaten   ' Daten im Direktfenster ausgeben.
   i = i + 1
Loop
Close #1   ' Datei schließen.
'Gesamtanzahl zuweisen
FaxUser(0, 0) = i - 1
End Sub

Function FaxUserErmitteln(ByVal FaxNummer As String, ByVal FaxCSVDirFilename As String) As String
Dim i As Integer
On Error GoTo LadeNummern
  If FaxUser(0, 0) = "" Then Exit Function
On Error GoTo 0
For i = 1 To FaxUser(0, 0) 'Anzahl
  If FaxUser(FU.faxDW, i) = FaxNummer Then
     FaxUserErmitteln = FaxUser(FU.NTUser, i)
     CurrentFaxUser = i
     Debug.Print "FaxUser= " & FaxNummer & " " & FaxUser(FU.NTUser, i)
     Exit For
  End If
Next
Exit Function
LadeNummern:
FaxNummernZuordnung (FaxCSVDirFilename)
Resume
End Function

Function BaumatUserByFaxUser(ByVal IstFaxUser As String, Optional FaxCSVDirFilename As String) As String
Dim i As Integer
If FaxCSVDirFilename = "" Then FaxCSVDirFilename = cacheParameterGet("FBM", "FaxUser", , "\\nadlinger\pc\fax.csv", True)
On Error GoTo LadeNummern
  If FaxUser(0, 0) = "" Then Exit Function
On Error GoTo 0
For i = 1 To FaxUser(0, 0) 'Anzahl
  If FaxUser(FU.NTUser, i) = IstFaxUser Then
     BaumatUserByFaxUser = FaxUser(FU.PersKZ, i)
     Exit For
  End If
Next
Exit Function
LadeNummern:
FaxNummernZuordnung (FaxCSVDirFilename)
Resume
End Function

Function FaxUserByBaumatUser(ByVal IstBaumatUser As String, Optional FaxCSVDirFilename As String) As String
Dim i As Integer
If FaxCSVDirFilename = "" Then FaxCSVDirFilename = cacheParameterGet("FBM", "FaxUser", , "\\nadlinger\pc\fax.csv", True)
On Error GoTo LadeNummern
  If FaxUser(0, 0) = "" Then Exit Function
On Error GoTo 0
For i = 1 To FaxUser(0, 0) 'Anzahl
  If FaxUser(FU.PersKZ, i) = IstBaumatUser Then
     FaxUserByBaumatUser = FaxUser(FU.NTUser, i)
     Exit For
  End If
Next
Exit Function
LadeNummern:
FaxNummernZuordnung (FaxCSVDirFilename)
Resume
End Function

Sub FaxParameterInitialisieren()
Dim path As String
  path = cacheParameterGet("FBM", "FaxUser", , "\\nadlinger\pc\fax.csv", True)
  FaxServer = cacheParameterGet("EMAIL", "FAX")
  FaxNummernZuordnung path
  FaxUserErmitteln TelFax, path
End Sub

Function AnzahlFaxe(Optional SuchFolder As String, Optional leer As Boolean) As String
    Dim Folders As IFaxFolders
    Dim Folder As IFaxFolder
    Dim RootFolder As IFaxFolder
    Dim msg As IFaxMessage
    Dim CountFolders As Long, CountMsg As Long
    Dim i As Long, j As Long
    Dim Gesamt As Long, Ungelesen As Long
    If IsMissing(SuchFolder) Or SuchFolder = "" Then SuchFolder = "Inbox"
    Set RootFolder = objFaxSession.RootFolder
    Set Folders = RootFolder.Folders
    Dim msgs As IFaxMessages
    CountFolders = Folders.Count
    For i = 1 To CountFolders
        Set Folder = Folders.Item(i)
        If Folder.Name = SuchFolder Then
           Set msgs = Folder.Messages
           CountMsg = msgs.Count
           If CountMsg = 0 Or IsEmpty(CountMsg) Then
             If leer Then AnzahlFaxe = " leer "
             Exit Function 'Abbruch wenn keine Einträge vorhanden
           End If
           For j = 1 To CountMsg
             Set msg = msgs.Item(j)
             Gesamt = Gesamt + 1
             If msg.Unread Then
               Ungelesen = Ungelesen + 1
             End If
           Next
           AnzahlFaxe = CStr(Ungelesen) + " | " + CStr(Gesamt)
           Exit For
        End If
    Next
    If leer And AnzahlFaxe = "" Then AnzahlFaxe = " leer "
End Function

