'********************************************************************
'*                                                                   
'* File:           OpenAllImageAttachments.vbs                                
'* Created:        April 2004                                       
'* Version:        1.0                                              
'*                                                                   
'* Main Function:  Add a new EnterpriseOne FILE/URL MO Attachment.   
'*                                                                   
'* Syntax:
'* cscript.exe OpenAttachment.vbs <username> <password> <environment> <GT DSTR Name> <Key>
'*                                                                   
'* Copyright (C) 2005 Everest Software International. All Right Reserved.       
'*                                                                   
'********************************************************************

ON ERROR RESUME NEXT

DIM MOR
dim objShell

DIM Usr
DIM Pwd
DIM Env
DIM Dsn
DIM Key
DIM Fil
DIM Typ
DIM Cnt
DIM i

If Wscript.Arguments.Count <> 5 Then
   Wscript.Echo "Wrong number of parameters." & vbCRLF & _
                "" & vbCRLF & _
                "Usage:" & vbCRLF & _
                "=========================" & vbCRLF & _
                "cscript.exe OpenAllImageAttachments.vbs <username> <password> <environment> <GT DSTR Name> <Key>" & vbCRLF & _
                ""
Else
   Usr = Wscript.arguments.Item(0)
   Pwd = Wscript.arguments.Item(1)
   Env = Wscript.arguments.Item(2)
   Dsn = Wscript.arguments.Item(3)
   Key = Wscript.arguments.Item(4)

   Set MOR = CreateObject("OneAttachmentManager.MOReader")

   Select Case MOR.LoginIntoEnterpriseOne(Usr, Pwd, Env)
      Case 0
         Wscript.Echo "Logged In"

         Cnt = MOR.QueryByKey(Dsn, Key)
         if Cnt = 0 then
            Wscript.Echo "No Attachments Found"
         Else
            Wscript.Echo "Found " & Cnt & " Attachments"

            For i = 1 to Cnt
               Call MOR.GetNextAttacment(Typ, Fil)

               Select Case Typ
                  Case 1
                     Wscript.Echo "Found: " & Fil & ", Opening..."
                     set objShell = CreateObject("Shell.Application")
                     objShell.ShellExecute Fil, "", "", "open", 1
                     set objShell = nothing
                  Case 0
                     Wscript.Echo "Found: TEXT - wrong type, skipping."
                  Case 5
                     Wscript.Echo "Found: FILE/URL - wrong type, skipping."
               End Select
           Next
         End If

         MOW.Logout
      Case 100
         Wscript.Echo "Licensing Failed"
      Case 1
         Wscript.Echo "Login Failed"
      Case 2
         Wscript.Echo "Login Crashed"
   End Select
End If

Set MOW = Nothing

