home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / xbase / library / fox / workgrp / attach.prg < prev    next >
Text File  |  1993-08-27  |  8KB  |  303 lines

  1. * Attach.prg
  2. *
  3. * The attach program brings up a dialog of developers
  4. * working on a similar project. It allows them to
  5. * simultaneously update and receive files used in projects
  6. * by the users working on them. This example shows the use
  7. * the "IPC" type message. By flagging a message with this
  8. * type, MS MAIL will ignore it. The popup of developer names
  9. * is only meant to simulate the person sending the message. In
  10. * real application, you could gather this information
  11. * programmatically without having to use a popup.
  12.  
  13. #DEFINE nonmailtype 'IPC.MSFOXPRO.UPDATER'
  14. #DEFINE mb_purge     'Do you want to permanently delete these files from mail server?'
  15.  
  16. PRIVATE devpick,btn,oldtalk,retval
  17.  
  18. IF SET("TALK") = "ON"
  19.     SET TALK OFF
  20.     m.oldtalk= "ON"
  21. ELSE
  22.     m.oldtalk= "OFF"
  23. ENDIF
  24. devpick=1
  25. btn=3
  26. retval=.T.
  27.  
  28. * arrays for lists in dialog
  29. DIMENSION fromnames[1]
  30. DIMENSION tonames[1]
  31.  
  32. * array used for names popup
  33. SELECT name FROM coders;
  34.     INTO ARRAY devnames
  35.  
  36. * gets files associated with developer
  37. DO devnamesval
  38.  
  39. * run screen
  40. DO attach.spr
  41. IF m.btn=3     &&exit button
  42.     SET TALK &oldtalk
  43.     RETURN
  44. ENDIF
  45.  
  46. * logon to MS Mail if not already done so
  47. islogon=.F.
  48. DO CASE
  49.     CASE TYPE('mailsession')#'N'
  50.         PUBLIC mailsession
  51.         mailsession = 0
  52.         mailsession=mapilib('LOGON')
  53.     CASE m.mailsession=0
  54.         mailsession=mapilib('LOGON')
  55.     OTHERWISE
  56.         islogon=.T.
  57. ENDCASE
  58.  
  59. IF m.mailsession=0  &&failed to logon
  60.     SET TALK &oldtalk
  61.     RETURN
  62. ENDIF
  63.  
  64. * handle button selected
  65. DO CASE
  66.     CASE m.btn=1  && send files
  67.         IF EMPTY(tonames)
  68.             SET TALK &oldtalk
  69.             RETURN
  70.         ENDIF
  71.         DO sendfiles
  72.     CASE m.btn=2  && poll for received files
  73.         DO getfiles
  74. ENDCASE
  75.  
  76. * Now log off and cleanup stuff
  77. IF !islogon
  78.     =mapilib('LOGOFF',m.mailsession)
  79.     mailsession = 0
  80. ENDIF
  81.  
  82.  
  83. IF USED('mapiMesg')
  84.     USE IN mapimesg
  85. ENDIF
  86. IF USED('mapiFile')
  87.     USE IN mapifile
  88. ENDIF
  89. IF USED('mapiRecip')
  90.     USE IN mapirecip
  91. ENDIF
  92. IF USED('mapiOrig')
  93.     USE IN mapiorig
  94. ENDIF
  95. USE IN FILES
  96. USE IN coders
  97. SET TALK &oldtalk
  98.  
  99.  
  100. *!*********************************************************************
  101. *!
  102. *!      FUNCTION: devnamesval
  103. *!
  104. *!*********************************************************************
  105. * This routine is called from the popup VALID statement and
  106. * changes the contents of the lists with files associated with
  107. * selected developer.
  108. PROCEDURE devnamesval
  109.     PRIVATE getname
  110.     getname=LOOKUP(coders.address,ALLTRIM(devnames[devpick]),coders.name)
  111.     SELECT filename FROM FILES;
  112.         WHERE address=getname;
  113.         INTO ARRAY fromnames
  114.     frompick=1
  115.     DIMENSION tonames[1]
  116.     tonames[1]=''
  117.     topick=1
  118.     SHOW GETS
  119.     RETURN
  120.  
  121.  
  122.     *!*********************************************************************
  123.     *!
  124.     *!      FUNCTION: movebtnval
  125.     *!
  126.     *!*********************************************************************
  127.     * VALID routine to handle move button.
  128. PROCEDURE movebtnval
  129.     IF frompick=0 OR EMPTY(fromnames[frompick])
  130.         RETURN
  131.     ENDIF
  132.     IF EMPTY(tonames[1])
  133.         tonames[1]=fromnames[frompick]
  134.     ELSE
  135.         DIMENSION tonames[ALEN(tonames)+1]
  136.         tonames[ALEN(tonames)]=fromnames[frompick]
  137.     ENDIF
  138.     IF ALEN(fromnames)=1
  139.         fromnames[1]=''
  140.     ELSE
  141.         =ADEL(fromnames,frompick)
  142.         DIMENSION fromnames[ALEN(fromnames)-1]
  143.     ENDIF
  144.     frompick=1
  145.     SHOW GETS
  146.     RETURN
  147.  
  148.  
  149.     *!*********************************************************************
  150.     *!
  151.     *!      FUNCTION: sendfiles
  152.     *!
  153.     *!*********************************************************************
  154.     * This procedure handles the send files button on the dialog.
  155.     * The names in the database are first validated thru MPResolve.
  156.     * Then they are loaded into a mapiRecip cursor called filelist.
  157.     * Finally, a single mail message is sent out to the developers
  158.     * in the filelist cursor. This message is tagged as "IPC" so that
  159.     * only apps such as FoxPro which are specifically looking for these
  160.     * types of messages will pick them up. The message does not contain
  161.     * text. Only the files selected are included.
  162. PROCEDURE sendfiles
  163.  
  164.     =mapilib('newcursor','mapiMesg')
  165.     =mapilib('newcursor','mapiFile')
  166.     =mapilib('newcursor','mapiRecip','filelist')
  167.  
  168.     * Now check database for names and validate
  169.     * in MPResolve(checkid routine). Avoid sending
  170.     * yourself devnames[devpick] files.
  171.     SELECT coders
  172.     SCAN FOR name#ALLTRIM(devnames[devpick])
  173.         WAIT WINDOW 'Verifying valid MS MAIL address ... '+;
  174.             ALLT(coders.name) NOWAIT
  175.         IF checkid()
  176.             SELECT mapirecip
  177.             SCATTER MEMVAR MEMO
  178.             INSERT INTO filelist FROM MEMVAR
  179.         ELSE
  180.             LOOP
  181.         ENDIF
  182.         SELECT coders
  183.     ENDSCAN
  184.     WAIT CLEAR
  185.  
  186.     * Create contents of message. Notice how we have to add a
  187.     * space in the Notetext field of mapiMesg for each file. This
  188.     * is important, else the call will fail.
  189.     INSERT INTO mapimesg VALUES(0,'Project Files',SPACE(ALEN(tonames)),nonmailtype,;
  190.         mapilib('getdate'),'',0,RECCOUNT('filelist'),ALEN(tonames))
  191.  
  192.     * Now create the mapiFile cursor which will contain a record
  193.     * for each file being sent
  194.     FOR i=1 TO ALEN(tonames)
  195.         INSERT INTO mapifile VALUES(0,0,i-1,tonames[i],tonames[i],"")
  196.     ENDFOR
  197.  
  198.     * Call the MPSendMail function without bringing up dialog.
  199.     retval=mapilib("sendmail",mailsession,"mapiMesg","filelist","mapiFile",0)
  200.     * Note: you can use the following line instead to test
  201.     * the receiving files function if you are working off-line.
  202.     *=MAPILIB("savenote",mailsession,"mapiMesg","filelist","mapiFile")
  203.  
  204.     IF m.retval
  205.         =mapilib('MPINFO',ALLTRIM(devnames[devpick])+"'s file(s) were sent successfully." )
  206.     ENDIF
  207.     USE IN filelist
  208.     RETURN
  209.  
  210.  
  211.     *!*********************************************************************
  212.     *!
  213.     *!      FUNCTION: getfiles
  214.     *!
  215.     *!*********************************************************************
  216.     * The getfiles routine polls for messages of type "IPC" and
  217.     * subject topic equal to 'Project Files' which are messages
  218.     * created in the sendfiles routine above. Note: this routine
  219.     * only shows files that were found (they are deleted once you
  220.     * exit the routine). If you actually want to update existing files
  221.     * you need to modify this routine a little. At the end, the user is
  222.     * offered the choice to purge the files from the Mail server.
  223. PROCEDURE getfiles
  224.     PRIVATE oldmessid,messageid,oldsafe
  225.     oldmessid=''
  226.     messageid=''
  227.     oldsafe=SET('safe')
  228.     SET SAFETY OFF
  229.     *Create cursor to store files
  230.     =mapilib('newcursor','mapiFile','newfiles')
  231.     *Create cursor to store messages
  232.     CREATE CURSOR newmesgs (messageid C(100))
  233.     WAIT WINDOW 'Searching for new files...' NOWAIT
  234.     * Need to poll all messages using MPFindNext and MPReadMail
  235.     * to locate messages which meet criteria.
  236.     DO WHILE .T.
  237.         messageid = mapilib('getnextnote',m.mailsession,oldmessid,nonmailtype)
  238.         INSERT INTO newmesgs VALUES(m.messageid)
  239.         IF EMPTY(m.messageid)
  240.             EXIT
  241.         ENDIF
  242.         IF mapimesg.filecount>0
  243.             SELECT mapifile
  244.             SCAN
  245.                 SCATTER MEMVAR MEMO
  246.                 INSERT INTO newfiles FROM MEMVAR
  247.             ENDSCAN
  248.         ENDIF
  249.         oldmessid = m.messageid
  250.     ENDDO
  251.     WAIT CLEAR
  252.     SELECT newfiles
  253.     IF RECCOUNT('newfiles')#0
  254.         BROWSE FIELDS filename FONT 'ms sans serif',10;
  255.             TITLE 'The following new files were found:'
  256.         * Always delete temporary files. These will be recreated
  257.         * again if user does not purge ones stored in mail server.
  258.         SCAN
  259.             DELETE FILE (pathname)
  260.         ENDSCAN
  261.         IF mapilib('mpalert',mb_purge)
  262.             SELECT newmesgs
  263.             SCAN
  264.                 =mapilib('deletenote',m.mailsession,ALLT(messageid))
  265.             ENDSCAN
  266.         ENDIF
  267.     ELSE
  268.         =mapilib('MPINFO','No files found')
  269.     ENDIF
  270.     USE IN newfiles
  271.     USE IN newmesgs
  272.     SET SAFETY &oldsafe
  273.     RETURN
  274.  
  275.  
  276.     *!*********************************************************************
  277.     *!
  278.     *!      FUNCTION: checkid
  279.     *!
  280.     *!*********************************************************************
  281.     * This routine validates the Mail name/alias in the MPResolve
  282.     * function. If it is correctly validated, TRUE is returned. If
  283.     * not, a dialog is presented to select a name. An alert follows
  284.     * asking whether they want to use this new name or try again.
  285. FUNCTION checkid
  286.     validid=.T.
  287.     DO WHILE .T.
  288.         IF !mapilib('resolve',mailsession,ALLT(coders.address))
  289.             validid=.F.
  290.             EXIT
  291.         ENDIF
  292.         IF ALLT(coders.name) $ mapirecip.name
  293.             EXIT
  294.         ELSE
  295.             IF mapilib('mpalert','The name selected ('+ALLT(mapirecip.name)+;
  296.                     ') does not match the one in the database ('+ALLT(coders.name)+;
  297.                     '). Use this name (Yes) or try again (No)?')
  298.                 EXIT
  299.             ENDIF
  300.         ENDIF
  301.     ENDDO
  302.     RETURN validid
  303.