;MergeUpload.WAS  v1.0

;*****************************************************************************
;*                                                                           *
;* MergeUpload.WAS                                                           *
;* Copyright (C) 1998 Symantec                                               *
;* All rights reserved.                                                      *
;*                                                                           *
;* Written by:  Symantec ASPECT Assist                                       *
;* 12/1/97                                                                   *
;*                                                                           *                                                                             
;* The script will combine two files, call the host computer, log on and     *
;* upload the new file to host system.  The script will also send an email   *
;* message to 3 addresses to verify the file transfer.  A log file with      * 
;* success or failure will then be sent to the default Windows printer.      *
;* The script will then exit Procomm Plus.                                   *
;*                                                                           *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************

;****************************************************************************
;* MACROS                                                                   *
;****************************************************************************
#define fSOURCE "C:\test\source.txt"           ;The source file.
#define fCARDFILE "C:\test\card.txt"           ;The card file to add to top of source.
#define fNEWFILE "C:\test\newfile.txt"         ;The new created file.
#define fLOGFILE "C:\test\logfile.txt"         ;The error/log file.

#define szComment "Place Comment Here:"        ;Comment for log file.
#define szNUMBER "9,99999999999"               ;The phone number to dial.
#define szLOGIN "login"                        ;The login id.
#define szPASSWORD "password"                  ;The password id.

#define szSubject "Subject Line"               ;The subject line for email message.
#define szMAIL1 "email@email.com"             ;The email ids.
#define szMAIL2 "email@email.com" 
#define szMAIL3 "email@email.com" 


;****************************************************************************
;* Main                                                                     *
;****************************************************************************
proc Main

   startprocess()
endproc


;****************************************************************************
;* StartProcess                                                             *
;****************************************************************************
proc StartProcess

   string szMsg

   pwmode TERMINAL
   yield
   if fopen 0 fLOGFILE READAPPEND TEXT           ; Open log file for read only.
      logit("***************************************************")
      strfmt szMsg ("Date: %s") $date          ;Info for log file.
      logit(szMsg)
      strfmt szMsg ("Time: %s") $time
      logit(szMsg)
      logit("")
      logit(szComment)
      logit("")
   else
      errormsg "Couldn't open the log file `"%s`"." fLOGFILE  ;Error if not able to
                                                              ; create log file.
      exit
   endif
   
   Combine()
   DialHost()
   UploadFile()
   PrintFile()
   fclose 0
   mspause 500
   yield

;**************************************************************************
;* if you do not wish to send emails as part of the process, comment out the 
;* following block of lines, as well as the EmailFile procedure.

   EmailFile(szMAIL1)
   yield
   EmailFile(szMAIL2)
   yield
   EmailFile(szMAIL3)
   yield
   sendkey ALT 'A'                       ;menu to check/send message.
   mspause 500
   sendkey ALT 'S'                       ;send all scheduled messages.
   
;* end of email block   
;***************************************************************************
   
   statmsg "Done processing Script."
endproc


;****************************************************************************
;* Combine                                                                  *
;****************************************************************************
proc Combine

   string szLine, szMsg

   if fopen 1 fCARDFILE READ TEXT
      if fopen 2 fSOURCE READ TEXT
         if fopen 3 fNEWFILE WRITE TEXT
            while not feof 1                   ;Add first file to new file.
               fgets 1 szLine
               fputs 3 szLine
            endwhile
            fclose 1
            while not feof 2                   ;Add second file to new file.
               fgets 2 szLine
               fputs 3 szLine
            endwhile
            fclose 2
            fclose 3
            strfmt szMsg ("File `"%s`" combined with file `"%s.`"") fCARDFILE fSOURCE
            logit(szMsg)
         else
            strfmt szMsg ("Error opening created file `"%s.`"") fNEWFILE
            logit(szMsg)
            errormsg "Error opening created file `"%s.`"" fNEWFILE
            exit
         endif
      else
         strfmt szMsg ("Error opening source file `"%s.`"") fSOURCE
         logit(szMsg)
         statmsg "Error opening source file `"%s.`"" fSOURCE
         exit
      endif
   else
      strfmt szMsg ("Error opening source file `"%s.`"") fCARDFILE
      logit(szMsg)
      errormsg "Error opening source file `"%s.`"" fCARDFILE
      exit   
   endif
endproc


;****************************************************************************
;* DialHost                                                                *
;****************************************************************************
proc DialHost

   clear
   set dial retries 20
   dialnumber DATA szNUMBER                    ;Dial the host system.
   while $dialing
      yield
   endwhile
   if $carrier                                 ; if connected
      Logit("Connected to host system.")
      waitfor "Enter logon id" 15
      transmit szLOGIN                         ; send login id
      mspause 500
      transmit "^M"
      waitfor "Enter password" 15
      transmit szPASSWORD                      ; send password
      mspause 500
      yield
      transmit "^M"
      if waitfor "ZMODEM" 15
         Logit("Successful logon to host system.")
      else
         Logit("Error: Unable to logon to host system.")
      endif
   else
      Logit("Error: Problems connecting to host system.")
   endif
endproc


;****************************************************************************
;* UploadFile                                                               *
;****************************************************************************
proc UploadFile

   integer iTemp

   set ZMODEM sender crashrecover 2            ;Always crash recover.
   set ZMODEM receiver crashrecover 2
   
   iTemp = 1
   sendfile ZMODEM fNEWFILE
   while iTemp == 1                            ;While file transfer is going on. 
      iTemp = $XFERSTATUS                      ;Store value in $XFERSTATUS in iTemp
      yield                                    ;Yield processor time.
   endwhile
   if iTemp == 2
      if $carrier                               ;Test the value of iTemp for success
         Logit("File successfully uploaded to host.")
      else 
         Logit("Error: File may not have uploaded successfully!")
      endif
   else                                        ;or failure of file transfer.
      Logit("Error: File upload failed!")
   endif
endproc


;****************************************************************************
;* PrintFile                                                                *
;****************************************************************************
proc PrintFile

   string szLine

   if printer open                             ;Open the default printer.
      fclose 0
      yield
      mspause 500
      fopen 0 fLOGFILE READ TEXT
      while not feof 0
         fgets 0 szLine
         printstr szLine
         printstr "`r`n"                       ;Print an end of line.
      endwhile
      printer close                            ;Close the print device.
   else
      logit("Error: Couldn't open the default printer!")
   endif
endproc


;****************************************************************************
;* EmailFile                                                                *
;****************************************************************************
proc EmailFile
param string szAddress

   pwmode MAIL
   pause 2
   yield
   if filetoclip TEXT fNEWFILE                    ;Take file to send and put in 
                                                  ; the windows clipboard.
      if dialnumber MAIL szAddress
         sendkeystr szSUBJECT
         mspause 250
         sendvkey 0x09                         ;send a tab key.
         mspause 250
         sendvkey 0x09
         mspause 500
         sendkey CTRL 'V'                      ;paste clip info to message.
         pause 1
         sendkey ALT 'M'                       ;menu to send message.
         mspause 500
         sendkey ALT 'M'                       ;send the message.
         mspause 500
         yield
      else
      errormsg "Error: Problems sending mail message to: %s" szAddress
   endif
   else
      errormsg "Error: Problems reading from Hard Drive - Mail"
   endif   
endproc


;*******************************************************************************
;* LogIT                                                                       * 
;*******************************************************************************
proc LogIT
param string szMsg

   fputs 0 szMsg                               ;output to logfile.
endproc
