home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / visilotu.zip / FILES.PRG < prev    next >
Text File  |  1995-08-31  |  19KB  |  597 lines

  1. !.HEADER
  2. !.SPEC APPDEST 0 D:\DESKTOP\VIS2LONO\LNQ.APL
  3. !.HEADER
  4. ! Program Name     - FILES.PRG
  5. ! Program Function - Program Task for the Sample Lotus Notes Query application
  6. !                    This program provides a modal dialog allowing the user to 
  7. !                    select a Lotus Notes form for querying.  The dialog provided
  8. !                    is identical to the standard dialog used in Visualizer for the
  9. !                    selection of tables, files, etc.  The user selects from a list
  10. !                    of Lotus Notes servers to locate a Notes database.  Once a database
  11. !                    is selected then a list of the Forms within the database is displayed.
  12. !                    The User then selects the desired Form and control is returned to
  13. !                    calling task.
  14. !  
  15. ! Called by        - LNQMAIN.PRG
  16. ! Calls            - LOTUSNOTES ASL Object for interface to Lotus Notes
  17. !                    The Object is initialised in LNQMAIN and passed to this
  18. !                    Module
  19. ! Dynamic-Link-Library with functions to access Lotus Notes
  20. ! The LOTUSNOTES object uses VIS2LONO.DLL (accessed via the LIBRARY DLL statement in ASL)
  21. ! to provide all of the function necessary to get data from Lotus Notes databases.
  22. ! The following actions are called from this program:
  23. !   Request a list of servers from Notes     "GetServerList" 
  24. !   Request a list of files on a server      "GetFileList"   
  25. !   Request a list of forms in a database    "GetFormList"
  26. !.spec winsize MAX MAX
  27. !.spec textcol 0 17
  28. !.spec appdest 0 d:\desktop\vis2lono\lnq.apl
  29. !.HEADER
  30. !
  31. ! DEFINITION
  32. ! This block contains general definitions.
  33. !
  34. DECLARE POINTER LotusObjectPtr                    ! Pointer to Lotus Notes Object
  35. !
  36. ! ON SELECT
  37. ! This block is triggered whenever the user selects a control
  38. ! or menu entry.
  39. !
  40. ON SELECT
  41. DO
  42.   CASE A.System.Object
  43.     !
  44.     WHEN "T.W_files.STD_PUSH"
  45.     DO
  46.       CASE A.System.Boxnumber
  47.         WHEN 1                                    ! button marked 'OK'
  48.         DO
  49.           IF FIND(ItemList,SelName)=0             ! is the form in our list
  50.           DO                                      ! of valid forms?
  51.             ERROR 2,"The Form name supplied does not exist, "||
  52.              "please supply another."
  53.             RETURN
  54.           END
  55.  
  56.           ! Interpret OK on a primary window as required
  57.           LET A..Server    = CurrentServer        ! set scalars for the application
  58.           LET A..Directory = CurrentDirectory     ! level task so that
  59.           LET A..Database  = CurrentFile          ! the appropriate functions
  60.           LET A..Form      = SelName              ! can be executed there
  61.  
  62.           MODIFY T..W_Files,                      ! hide this window
  63.            VISIBLE = No,                          ! by setting to INVISIBLE
  64.            MODAL = No                             ! and turn off MODAL nature
  65.  
  66.           SIGNAL PROGRAM A.System.Master          ! signal the caller that we are done
  67.         END
  68.         !
  69.         WHEN 2                                    ! button marked 'Cancel'
  70.         DO
  71.           MODIFY T..W_Files,                      ! hide this window
  72.            VISIBLE = No,                          ! by setting to INVISIBLE
  73.            MODAL = No                             ! and turn off MODAL nature
  74.  
  75.           SIGNAL PROGRAM A.System.Master          ! signal the caller that we are done
  76.  
  77.         END
  78.         !
  79.         WHEN 3                                    ! button marked 'Help'
  80.         DO
  81.           ! help button
  82.           NOTHING
  83.         END
  84.         !
  85.       END
  86.     END
  87.     !
  88.     WHEN "T.W_files.LIST1"                        ! user selects from the lefthand
  89.     DO                                            ! listbox (names of forms)
  90.       ! list box set for single select mode
  91.  
  92.       DEFINE FormSel[0]
  93.       CALL T.W_Files.LIST1'QUERYCHECK(FormSel[0])
  94.  
  95.       IF FormSel[0]'ENTRIES
  96.         DO
  97.         LET SelName=ItemList[A.System.BoxNumber]  ! store selected form name
  98.         LET T.W_Files'CURSORBOX = T.W_Files.Std_Push[1]     ! Make OK Button the default
  99.         END
  100.       ELSE
  101.         LET SelName = ""
  102.  
  103.     END
  104.     !
  105.     WHEN "T.W_files.LIST2"                        ! user selects from righthand
  106.     DO                                            ! Listbox (Locations)
  107.       ! list box set for single select mode
  108.       CALL Fill_Locations(                        ! call function to use
  109.        LocationList[A.System.BoxNumber],          ! selected location and type
  110.        LocationType[A.System.BoxNumber])          ! to get next level of files/directories
  111.  
  112.       CALL T.W_Files.LIST2'UNCHECK(               ! de-select item in List
  113.        A.System.BoxNumber)
  114.       LET T.W_Files.LIST2'TOPROW=1                ! and set list to top row
  115.  
  116.     END
  117.   END
  118. END
  119. !
  120. ! ON DATA
  121. ! This block responds to controls which can accept data entry.
  122. ! It is executed whenever the cursor leaves the control after
  123. ! data has been changed. This is normally used to provide input
  124. ! validation.
  125. !
  126. ON DATA
  127. DO
  128.   CASE A.System.Object
  129.     WHEN "T.W_files.SLE1"
  130.     DO
  131.       ! React to change to data variable  SelName
  132.       !
  133.       !
  134.     END
  135.     WHEN "T.W_files.SLE2"
  136.     DO
  137.       ! React to change to data variable  SelLocation
  138.       !
  139.       !
  140.       CALL User_Location()                        ! determine what location the user entered
  141.     END
  142.   END
  143. END
  144. ON START(pExistingName,pLotus)
  145. DO
  146.   DECLARE LOCAL NULL CHARACTER[*] pExistingName   ! Handle of main window passed as parameter
  147.   DECLARE LOCAL POINTER pLOTUS                    ! Pointer to LotusNotes object from lnqmain
  148.  
  149.   LET LotusObjectPtr = pLOTUS                     ! Make Address available to whole program
  150.  
  151.   !
  152.   ! Assign boolean variables
  153.   LET yes = 1
  154.   LET no  = 0
  155.  
  156.   !
  157.   ! Assign all variables referred by the windows
  158.   !
  159.   LET SelName = ""
  160.   LET SelLocation = ""
  161.  
  162.   !
  163.   ! Call procedure to define data for list control(s)
  164.   !
  165.   CALL List_Define
  166.  
  167.   !
  168.   OPEN WINDOW W_Files, , "I.Windows.Files",
  169.    MODAL=Yes,
  170.    OWNERWINDOW=A..W_lnqmain
  171.  
  172.   ! assign the default push button
  173.   LET T.W_files.STD_PUSH[0]'DEFAULT = 1
  174.   ! assign the help button
  175.   LET T.W_files.STD_PUSH[0]'HELPBUTTON = 3
  176.   !
  177. END
  178. !
  179. ! Construct the arrays needed to support list controls
  180. !
  181. PROCEDURE List_Define
  182. DO
  183.   !
  184.   ! Define data to handle list 'T.W_files.LIST1'
  185.   !
  186.   DEFINE NColumns[0]                              ! coldata vector
  187.   DEFINE NLayout[0]                               ! expression vector
  188.   !
  189.   ! fill the expression vector
  190.   !
  191.   INSERT NLayout[0]="WIDTH=120 SEPARATOR=YES JUST=LEFT READONLY=YES"
  192.   !
  193.   ! Initialise the referred vectors. These are the vectors
  194.   ! which will contain the data to be displayed
  195.   !
  196.   DEFINE ItemList[0]
  197.   !
  198.   ! fill the reference vector to point to these vectors
  199.   !
  200.   INSERT NColumns[0] = "ItemList"
  201.   !
  202.   ! Define data to handle list 'T.W_files.LIST2'
  203.   !
  204.   DEFINE LColumns[0]                              ! coldata vector
  205.   DEFINE LLayout[0]                               ! expression vector
  206.   !
  207.   ! fill the expression vector
  208.   !
  209.   INSERT LLayout[0]="WIDTH=100 SEPARATOR=YES JUST=LEFT READONLY=YES"
  210.   INSERT LLayout[0]="WIDTH=150 SEPARATOR=YES JUST=LEFT READONLY=YES"
  211.   !
  212.   ! Initialise the referred vectors. These are the vectors
  213.   ! which will contain the data to be displayed
  214.   !
  215.   DEFINE LocationList[0]
  216.   DEFINE LocationDetails[0]
  217.   !
  218.   ! fill the reference vector to point to these vectors
  219.   !
  220.   INSERT LColumns[0] = "LocationList"
  221.   INSERT LColumns[0] = "LocationDetails"
  222.  
  223. CALL Get_Server_List()
  224. END
  225. !
  226. ! ON ESCAPE
  227. ! This block is executed when the user hits the 'Escape'
  228. ! key. This will normally be interpreted to mean the same
  229. ! as a selection on a 'Cancel' button(ie shut the window without
  230. ! committing any changes) and is applicable to
  231. ! secondary windows only.
  232. !
  233. ON ESCAPE
  234. DO
  235.   IF A.System.Object ="T..W_files"
  236.   DO
  237.     LET A.System.BoxNumber= 2                     ! cancel button
  238.     LET A.System.Object="T.W_files.Std_Push"
  239.     QUEUE PROGRAM A.System.Thistask,SELECT
  240.   END
  241. END
  242. !
  243. ! ON QUIT
  244. ! This block is executed when the user uses Close in the
  245. ! system menu.
  246. ! For a secondary window this would imply, 'shut the window'.
  247. ! For a primary window the impication is, 'close the
  248. ! Application'.
  249. !
  250. ON QUIT
  251. DO
  252.   CASE A.System.Object
  253.  
  254.     WHEN "T..W_files"                             ! primary window
  255.       MODIFY T..W_Files,
  256.        VISIBLE = No,
  257.        MODAL = No
  258.  
  259.     OTHERWISE
  260.       SHUT ?A.System.Object
  261.  
  262.   END
  263. END
  264. !
  265. ! ON ENTER
  266. ! This block is executed when the user hits the enter key
  267. ! This is normally coded to be equivalent to selecting
  268. ! the default push button (often the OK button).
  269. !
  270. ON ENTER
  271. DO
  272.   IF A.System.Object ="T..W_files" 
  273.   DO
  274.     LET A.System.BoxNumber= T.W_files.Std_Push'DEFAULT[0]
  275.     LET A.System.Object="T.W_files.Std_Push"
  276.     QUEUE PROGRAM A.System.Thistask,SELECT
  277.   END
  278. END
  279. !
  280. ! ON QUEUE
  281. ! The default block to which control is passed when another
  282. ! program RUNs or QUEUEs this task
  283. !
  284. ON QUEUE
  285. DO
  286.   MODIFY T..W_Files,                              ! control has been passed back
  287.    VISIBLE = Yes,                                 ! so surface the window
  288.    MODAL = Yes                                    ! and make it modal
  289. END
  290. !
  291. ! ERROR event
  292. ! This block is executed when there is a run-time error.
  293. ! You can trap errors here or allow the error message provided
  294. ! to identify the error and stop the program.
  295. !
  296.  
  297. ON ERROR
  298. DO
  299.   !
  300.   ! Message to identify failing module and line
  301.   !
  302.   LET ans=DIALOG("EFD7004",0,
  303.    A.System.ErrorModule ,
  304.    A.System.ErrorLine )
  305.  
  306.   DO i=1 : A.System.ErrorNumber[0]'ENTRIES
  307.  
  308.     IF ans = "CANCEL"
  309.       TERMINATE
  310.  
  311.       ! Display system message corresponding to error
  312.     LET ans = DIALOG ("EFD" ||
  313.      A.System.Errornumber[i], 0,
  314.      A.System.ErrorInfo[i])
  315.   END
  316.   STOP
  317.  
  318. END
  319. !
  320. ! ON STOP
  321. ! This block is executed when the program is terminated.
  322. ! You should use the block to carry out any housekeeping
  323. ! required before closing
  324. !
  325. ON STOP
  326. DO
  327.  
  328.   STOP
  329. END
  330. !
  331. ! User specified procedures may have up to 10 passed parameters.
  332. ! Procedures may be called as functions (using the RETURN
  333. ! facility to return a value) or may be called as normal
  334. ! procedures.
  335. !
  336. PROCEDURE Fill_Locations(pLocation,pType)
  337. DO
  338.   DECLARE LOCAL NUMERIC CurrLen =0
  339.  
  340.   CASE pType                                      ! what type of item was selected?
  341.     WHEN "SERVER"                                 ! a server
  342.     DO
  343.       LET SelLocation=pLocation                   ! First possible part of name
  344.  
  345.       LET CurrentServer=pLocation
  346.  
  347.       LET CurrentDirectory=""                     ! reset directory variable
  348.  
  349.       CALL Fill_List()                            ! fill list for this server
  350.  
  351.     END
  352.     WHEN "DIRECTORY"                              ! a directory was selecte
  353.     DO
  354.       IF CurrentDirectory=""                      ! if the first directory
  355.       DO
  356.         LET SelLocation=CurrentServer ||"\"|| pLocation
  357.         LET CurrentDirectory=pLocation
  358.       END
  359.       ELSE
  360.       DO
  361.         LET SelLocation=TRIM(SelLocation) ||
  362.          "\" || pLocation
  363.  
  364.         LET CurrentDirectory=TRIM(CurrentDirectory)||
  365.          "\"|| pLocation
  366.       END
  367.  
  368.       CALL Fill_List()
  369.  
  370.     END
  371.     WHEN "FILE"
  372.     DO
  373.       IF CurrentDirectory\=""
  374.         LET CurrentFile=TRIM(CurrentDirectory) ||
  375.          "\" ||
  376.          pLocation
  377.       ELSE
  378.         LET CurrentFile = pLocation
  379.  
  380.       LET SelLocation=TRIM(SelLocation) ||
  381.        "\" || pLocation
  382.  
  383.       LET CurrentDirectory=TRIM(CurrentDirectory)||
  384.        "\"|| pLocation
  385.       ! GetFormList
  386.  
  387.       DEFINE IList[0]
  388.       DEFINE ItemList[0]
  389.  
  390.  
  391.       ! 'push' button marked 'GetFormList'
  392.  
  393.       LET (?LotusObjectPtr)'SERVERNAME = CurrentServer
  394.       LET (?LotusObjectPtr)'DIRECTORY = CurrentDirectory
  395.       LET (?LotusObjectPtr)'DATABASE = CurrentFile
  396.  
  397.       FORGIVE
  398.           CALL (?LotusObjectPtr)'GetFormList( POINTER(IList[0]) ) ! pointer to ASL vector of forms
  399.       If (?LotusObjectPtr)'CODE > 0
  400.          DO
  401.          MESSAGE "FTB0003",0,(?LotusObjectPtr)'REASON
  402.          RETURN
  403.          END
  404.  
  405.       DO ii=1:IList[0]'ENTRIES
  406.         IF Ilist[ii]\=""
  407.           INSERT ItemList[0]=Ilist[ii]
  408.       END
  409.  
  410.       DEFINE LocationList[0]                      ! Listbox vector of locations
  411.       DEFINE LocationType[0]                      ! type of location
  412.  
  413.  
  414.       INSERT LocationList[0]="[..]PREVIOUS"       ! and the previous one
  415.  
  416.        INSERT LocationType[0]="PREVIOUS"
  417.     END
  418.     WHEN "PREVIOUS"
  419.     DO
  420.       LET SelName = ""                            ! clear form name
  421.       LET Levels=WORDS(CurrentDirectory,,"\")
  422.  
  423.       IF Levels
  424.       DO
  425.         LET CurrentDirectory=WORDS(CurrentDirectory,1,"\",
  426.          Levels-1)
  427.       END
  428.       ELSE
  429.       DO
  430.         LET CurrentDirectory = ""
  431.  
  432.         CALL Get_Server_List()
  433.         RETURN
  434.       END
  435.  
  436.       IF CurrentServer=""
  437.         LET SelLocation=CurrentDirectory
  438.       ELSE
  439.         LET SelLocation=CurrentServer||
  440.          IF(CurrentDirectory\="","\","")||CurrentDirectory
  441.  
  442.       CALL Fill_List
  443.  
  444.     END
  445.  
  446.   END
  447.  
  448. END
  449. !
  450. ! User specified procedures may have up to 10 passed parameters.
  451. ! Procedures may be called as functions (using the RETURN
  452. ! facility to return a value) or may be called as normal
  453. ! procedures.
  454. !
  455. PROCEDURE Fill_List
  456. DO
  457.   DECLARE LOCAL CHARACTER[*] ReturnMsg
  458.   DECLARE LOCAL CHARACTER[*] ServerName
  459.  
  460.   DEFINE DList[0]                                 ! used for list of Drives
  461.   DEFINE FDetails[0]                              ! used for list of file details
  462.   DEFINE FList[0]                                 ! used for list of files
  463.   DEFINE ItemList[0]                              ! used for list of forms in file
  464.  
  465.   LET (?LotusObjectPtr)'ServerName = CurrentServer      ! call the API to get  
  466.   LET (?LotusObjectPtr)'Directory = CurrentDirectory    ! a list of drives/files/details 
  467.    FORGIVE                                        ! for the specified server       
  468.      CALL (?LotusObjectPtr)'GetFileList( POINTER(DList[0]),   ! and directory providing        
  469.                            POINTER(FList[0]),     ! ptr to vector of Directories and
  470.                            POINTER(FDetails[0]))  ! ptr to vector of Files and     
  471.       If (?LotusObjectPtr)'CODE > 0               ! ptr to vector of File Details  
  472.          DO                                                                         
  473.          MESSAGE "FTB0003",0,(?LotusObjectPtr)'REASON                                                                             
  474.          RETURN                                                                     
  475.          END                                                                        
  476.                                                                                     
  477.   DEFINE LocationList[0]                          ! Listbox vector of locations
  478.   DEFINE LocationType[0]                          ! type of location
  479.  
  480.   INSERT LocationList[0]="[..]PREVIOUS"           ! and the previous one
  481.  
  482.   INSERT LocationType[0]="PREVIOUS"
  483.  
  484.   DO ff=1:DList[0]'ENTRIES
  485.     IF DList[ff]\=".." &
  486.      DList[ff]\=" "
  487.     DO
  488.       INSERT LocationList[0]=DList[ff]
  489.       INSERT LocationType[0]="DIRECTORY"
  490.     END
  491.   END
  492.  
  493.   DO ff=1:FList[0]'ENTRIES
  494.     IF Flist[ff]\=""
  495.     DO
  496.       INSERT LocationList[0]=FList[ff]
  497.       INSERT LocationType[0]="FILE"
  498.     END
  499.   END
  500.  
  501. END
  502. !
  503. ! User specified procedures may have up to 20 passed parameters.
  504. ! Procedures may be called as functions (using the RETURN
  505. ! facility to return a value) or may be called as normal
  506. ! procedures.
  507. !
  508. PROCEDURE User_Location
  509. DO
  510.   LET CurrentServer = WORDS(SelLocation,1,"\")    ! get server name from entry
  511.  
  512.   LET CurrentDirectory =                          ! get the directory path
  513.    WORDS(
  514.    SelLocation,                                   ! from the the entry
  515.    2,                                             ! use 2 to skip the server name
  516.    "\",                                           ! separate by "slash"
  517.    WORDS(SelLocation,,"\")-2)                     ! get all except last part
  518.  
  519.   LET LastPartOfPath =                            ! now get the last part here
  520.    WORDS(
  521.    SelLocation,                                   ! from the entry
  522.    WORDS(SelLocation,,"\"),"\")                   ! just get the last part
  523.  
  524.   CALL Fill_List()                                ! get list of drives/files for 'CurrentDirectory' above
  525.  
  526.   LET FindAt = FIND(LocationList,                 ! look for the last part
  527.    LastPartOfPath)                                ! we derived above as well
  528.  
  529.   IF LocationType[FindAt] = "FILE"                ! if this last part is a file (notes database)
  530.   DO
  531.     CALL Fill_Locations(LastPartOfPath,"FILE")    ! then get list of forms for it
  532.  
  533.     LET SelLocation =                             ! directory is now the
  534.      WORDS(SelLocation,                           ! entire path entered
  535.      1,                                           ! excluding the server name
  536.      "\",
  537.      WORDS(SelLocation,,"\")-1)
  538.  
  539.   END
  540.   ELSE                                            ! otherwise use the entire
  541.   DO                                              ! path specified to get new list
  542.     LET CurrentDirectory =                        ! directory is now the
  543.      WORDS(SelLocation,                           ! entire path entered
  544.      2,                                           ! excluding the server name
  545.      "\",
  546.      WORDS(SelLocation,,"\")-1)
  547.  
  548.     CALL Fill_List()                              ! refresh location list
  549.  
  550.   END
  551. END
  552. !
  553. ! User specified procedures may have up to 20 passed parameters.
  554. ! Procedures may be called as functions (using the RETURN
  555. ! facility to return a value) or may be called as normal
  556. ! procedures.
  557. !
  558. PROCEDURE Get_Server_List
  559. DO
  560.   DEFINE LocationList[0]                          ! Listbox vector of locations
  561.   DEFINE LocationType[0]                          ! type of location
  562.  
  563.   LET SelLocation = ""
  564.   LET SelName     = ""
  565.  
  566.   DEFINE ServerList[0]
  567.    FORGIVE
  568.      CALL (?LotusObjectPtr)'GetServerList(POINTER(ServerList[0]))  ! Get List of Lotus Notes Server
  569.                                                   ! into ServerList
  570.    If (?LotusObjectPtr)'CODE > 0
  571.       DO
  572.       MESSAGE "FTB0003",0,(?LotusObjectPtr)'REASON
  573.       RETURN
  574.       END
  575.  
  576.  
  577.  
  578.   DO ss=1:ServerList[0]'ENTRIES                   ! "GetServerList" returns a blank
  579.     IF \NOVALUE(ServerList[ss])                   ! in the list of servers if
  580.       INSERT LocationList[0] =ServerList[ss]      ! any remote servers exist
  581.   END
  582.  
  583.   DEFINE LocationType[LocationList[0]'ENTRIES]=   ! mark "Local" and all others as servers
  584.    "SERVER"
  585. END
  586.