;HOTLIST.WAS    v1.00  Creates a hot list for URL's.


;*************************************************************************
;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* 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.                         *                                                                          *
;*****************************************************************************




;*************************************************************************
;*   MACRO DEFINITIONS                                                   *
;*************************************************************************

#define _MENU_HOT_LIST        10
#define _MENU_ADD_CURRENT     11
#define _MENU_IMPORT_HOT_LIST 12
#define _MENU_EXPORT_CONN_DIR 13



;*************************************************************************
;*   GLOBAL VARIABLES                                                    *
;*************************************************************************

string szListFile = $PWLOCALPATH       ;holds local pw path
string szMailFile = $PWLOCALPATH       ;holds local pw path
integer hDlg
integer hMenu                          ;holds menu item


;*************************************************************************
;*                                                                       *
;* MAIN                                                                  *
;* The main procedure calls InitializeGlobal and DisplayDialog.  It also *
;* waits for the Menu Bar Hotlist command to be executed, when it is     *
;* executed it calls MenuHandler.                                        *
;*                                                                       *
;* Globals: NONE                                                         *
;* Calls: INITIALIZEGLOBAL, MENUHANDLER, DISPLAYDIALOG                   *
;*                                                                       *
;*************************************************************************

proc Main
   InitializeGlobal()
   when $ASPMENU call MenuHandler
   DisplayDialog()
endproc



;*************************************************************************
;*                                                                       *
;* INITIALIZEGLOBAL()                                                    *
;* The procedure INITIALIZEGLOBAL sets the global variables to their     *
;* proper settings and also draws the HotList menu bar selection.        *
;*                                                                       *
;* Globals:  SZLISTFILE, SZMAILFILE, HMENU                               *
;* Calls:    NONE                                                        *
;* Called by:  MAIN                                                      *
;*                                                                       *
;*************************************************************************

proc InitializeGlobal

   addfilename szListFile "web"        ;adding Web to filename
   addfilename szListFile "url.lst"    ;adding url.lst to filename
   addfilename szMailFile "web"        ;adding web to mail filename
   addfilename szMailFile "url.txt"    ;adding url.txt to mail filename

   ;********************Draws HotList menubar options*********************
   
   menupopup $PWMENUBAR "Hot&List" hMenu
      menuitem hMenu _MENU_HOT_LIST "&Hot List Window"
      menuitem hMenu _MENU_ADD_CURRENT "&Add Current"
      menuitem hMenu _MENU_IMPORT_HOT_LIST "&Import Hot List..."
      menuitem hMenu _MENU_EXPORT_CONN_DIR "&Export Connection Directory..."
   menushow $PWMENUBAR                 ;shows menu bar
   menucheck _MENU_HOT_LIST ON
   ;**********************************************************************

endproc



;*************************************************************************
;*                                                                       *
;* MENUHANDLER()                                                         *
;* The procedure MENUHANDLER handles each menu selection.                *
;*                                                                       *
;* Globals:  HDLG                                                        *
;* Calls:    GETCURRENTURL, IMPORTHOTLIST, EXPORTCONNDIR                 *
;* Called by:  MAIN                                                      *
;*                                                                       *
;*************************************************************************

proc MenuHandler
   
   switch $ASPMENU
      case _MENU_HOT_LIST                 ;case = 10
         if winvisible hDlg               ;if window visable 
            winhide hDlg                  ;hide the dialog
            menucheck _MENU_HOT_LIST OFF  ;turn the menu item off         
         else
            winshow hDlg                  ;show the dialog
            menucheck _MENU_HOT_LIST ON   ;turn the menu item on
         endif
      endcase
      case _MENU_ADD_CURRENT              ;case = 11
         GetCurrentURL()                  ;calls the procedure
         dlgupdate 0 1                    ;update dialog box
         dlglist 0 1 SELECT 0             ;update dlg list
      endcase
      case _MENU_IMPORT_HOT_LIST          ;case = 12
         menuselect ASPMENU _MENU_HOT_LIST;select menu item
         ImportHotList()                  ;calls the procedure 
         dlgupdate 0 1                    ;update dialog box
         dlglist 0 1 SELECT 0             ;update dlg list
         winactivate $PWMAINWIN           ;activate PW3.0
         menuselect ASPMENU _MENU_HOT_LIST;select menu item
      endcase
      case _MENU_EXPORT_CONN_DIR          ;case = 13
         menuselect ASPMENU _MENU_HOT_LIST;select menu item
         ExportConnDir()                  ;calls the procedure
         dlgupdate 0 1                    ;update dialog box
         dlglist 0 1 SELECT 0             ;update dlg list
         winactivate $PWMAINWIN           ;activate PW3.0
         menuselect ASPMENU _MENU_HOT_LIST;select menu item
      endcase
   endswitch

endproc



;*************************************************************************
;*                                                                       *
;* DISPLAYDIALOG()                                                       *
;* The procedure DISPLAYDIALOG displays dialog box and repositions it in *
;* the bottom right corner of the screen.  It also has a switch state-   *
;* ment to handle selections from the dialogbox.                         *
;*                                                                       *
;* Globals:  NONE                                                        *
;* Calls:    GETCURRENTURL, OPENWEBPAGE, CREATEMAILFILE, MAILLIST        *
;*           REMOVEITEM
;* Called by:  MAIN                                                      *
;*                                                                       *
;*************************************************************************

proc DisplayDialog
   string szItem = $NULLSTR            ;URL item
   
   integer iEvent                      ;dialog event
   integer iItem = 0                   ;number of items in list
   integer iDlgState = 0               ;dialog state
   integer iDlgXPosn, iDlgYPosn        ;X&Y position of dialog
   integer iDlgWidth, iDlgHeight       ;width and height of dialog
   
   dialogbox 0 74 36 149 118 63 "PROCOMM PLUS Web Browser Hot List"
      flistbox 1 7 13 89 102 szListFile "500" single szItem hscroll sort
      pushbutton 2 102 12 40 14 "&Add Current"
      pushbutton 3 102 28 40 14 "&Remove"
      pushbutton 4 102 45 40 14 "&Open URL" default
      pushbutton 5 102 62 40 14 "Mail &URL..."
      pushbutton 6 102 79 40 14 "&Mail List..."
      pushbutton 7 102 96 40 14 "&Cancel"
      text 8 8 3 33 8 "&Web Sites" left
   enddialog

   dlgwin 0 hDlg                       ;gets window id of dlg box
   dlgupdate 0 1                       ;updates dialog box
   dlglist 0 1 SELECT 0                ;selects item from dlg box
   dlgshow 0                           ;shows dialog box
      
   ;******repositions dlg box in bottom right corner**********************
   wincoord hDlg iDlgXPosn iDlgYPosn iDlgWidth iDlgHeight
   iDlgXPosn = $XPIXELS - iDlgWidth - 10
   iDlgYPosn = $YPIXELS - iDlgHeight - 40
   winmove hDlg iDlgXPosn iDlgYPosn
   ;**********************************************************************
   while 1
      dlgevent 0 iEvent                ;gets dlg event
      switch iEvent     
         case 0
         case 1                        ;case 0 & 1 do nothing
         endcase
         case 2                        ;case 2
            GetCurrentURL()            ;calls the procedure
            dlgupdate 0 1              ;update dlg box
            if not nullstr szItem      ;check to see if NULLSTR
               dlglist 0 1 SELECT szItem;if not select item from list
            endif
         endcase
         case 3                        ;case 3
            if not nullstr szItem      ;check to see if NULLSTR
               dlglist 0 1 ITEMFIND szItem iItem;if not find item in list
               RemoveItem(szItem)      ;remove the item
               dlgupdate 0 1           ;update dlg box
               if iItem > 0            ;if the item # greater than 0
                  dlglist 0 1 SELECT (iItem - 1);select previous item
               else
                  dlglist 0 1 SELECT 0 ;otherwise select item 0
               endif
            endif
         endcase
         case 4                        ;case 4
            profilerd "PW3.INI" "Hot List" "HideWhenURLSelected" iDlgState
            if iDlgState               ;if dlg state is 1
               menuselect ASPMENU 10   ;select menu item 10
            endif
            OpenWebPage(szItem)        ;call the procedure
         endcase
         case 5                        ;case 5
            if not nullstr szItem      ;check to see if NULLSTR
               CreateMailFile(szItem, 1);if not call procedure
               MailList()               ;call procedure
            endif
         endcase
         case 6                        ;case 6
            CreateMailFile($NULLSTR, 2);call the procedure
            MailList()                 ;call the procedure
         endcase
         case 7                        ;case 7
            exitwhile                  ;exitwhile loop
         endcase
      endswitch
   endwhile
   
   dlgdestroy 0 CANCEL                 ;destroy the dlg box

endproc



;*************************************************************************
;*                                                                       *
;* GETCURRENTURL()                                                       *
;* The procedure GETCURRENTURL gets current URL and adds it to HOTLIST.  *
;*                                                                       *
;* Globals:  NONE                                                        *
;* Calls:    NONE                                                        *
;* Called by:  MENUHANDLER, DISPLAYDIALOG                                *
;*                                                                       *
;*************************************************************************

proc GetCurrentURL
   string szURL, szItemName, szItem
   integer iLength, iMaxAnnotationLength
   
   if $PWMODE == 2            ;if in Web browser mode
      winactivate $PWMAINWIN  ;set focus to PW main window
      strtoclip $NULLSTR      ;clear clipboard
      sendkey ALT 'A'         ;select URL in Address field
      sendkey CTRL 'C'        ;copy URL to clipboard
      cliptostr szURL         ;copy URL in clipboard to string
   
      szItemName = $PWTITLEBAR;Gets item name from PWTITLEBAR
      strreplace szItemName "PROCOMM PLUS for Windows Browser : " $NULLSTR
      strreplace szItemName "PROCOMM PLUS Browser : " $NULLSTR
   
      strlen szItemName iLength        ;gets length of URL name
      iMaxAnnotationLength = 254 - iLength;gets max length
      sdlginput "Page Name" szURL szItemName iMaxAnnotationLength DEFAULT
      if SUCCESS
         strfmt szItem "%s`t%s" szItemName szURL  ;formats URL name
         if fopen 2 szListFile APPEND TEXT        ;open URL file
            fputs 2 szItem                        ;put in new item
            fclose 2                              ;close file
         endif
         dlgupdate 0 1                            ;update dlg box
      endif
   endif
endproc



;*************************************************************************
;*                                                                       *
;* MAILLIST()                                                            *
;* The procedure MAILLIST sends the keystrokes to send mail to           *
;* receipients.                                                          *
;*                                                                       *
;* Globals:  NONE                                                        *
;* Calls:    NONE                                                        *
;* Called by:  DISPLAYDIALOG                                             *
;*                                                                       *
;*************************************************************************

proc MailList
   string szRecipients                 ;holds recipients for mail message
   string szPW3CommandLine = $PWTASKPATH;puts pw path to the variable
   
   integer iMailTaskID
   integer hMailWin
   integer iModeSwitchSuccess = 0
   
   menuselect ASPMENU _MENU_HOT_LIST   ;hide hot list dialog
 
   sdlginput "Recipients" "Enter addresses of recipients:" szRecipients 150
   if SUCCESS
      strfmt szPW3CommandLine "%s\PW3.EXE MAIL" szPW3CommandLine

      run szPW3CommandLine iMailTaskID ;run program with the id
      taskwin iMailTaskID hMailWin     ;gets the task id of window

      sendkey ALT 'A'                  ;send ALT 'A' to window
      mspause 250                      ;pause briefly
      sendkey 'N'                      ;send N to window
      mspause 250                      ;pause briefly
      strtoclip szRecipients           ;send str of recipients to clipbd
      sendkey CTRL 'V'                 ;send CTRL 'V' to window(paste)
      mspause 250                      ;pause briefly
      sendkey 0x09                     ;send Tab to window
      sendkey 0x09                     ;send tab to window
      strtoclip "Web pages to check out!";Send this string to clipbd
      sendkey CTRL 'V'                 ;send CTRL 'V' to window(paste)
      mspause 250                      ;pause briefly
      sendkey ALT 'F'                  ;activate File menu
      mspause 500                      ;pause little more than briefly
      sendkey 'I'                      ;select Import Text
      mspause 250                      ;pause briefly
      sendkey 0x0D                     ;send <Enter> 
      mspause 250                      ;pause briefly
      strtoclip szMailFile             ;copy mailfile to clipbd
      sendkey CTRL 'V'                 ;send CTRL 'V' to window(paste)
      sendkey 0x0D                     ;send a return to window
      mspause 250                      ;pause briefly
      sendkey ALT 'M'                  ;activate Message menu
      mspause 250                      ;pause briefly
      sendkey 'M'                      ;select Send Message
      mspause 500                      ;pause a little more than briefly
      while $ACTIVEWIN != hMailWin     ;while active win not mail window
         sendkey ALT 'N'               ;send ALT 'N' to window
      endwhile
      winactivate hMailWin             ;active mail window
      sendkey ALT 'A'                  ;activate Message menu
      mspause 250                      ;pause briefly
      sendkey 'M'                      ;select Deliver Mail
      mspause 250                      ;pause briefly
      while $FOCUSWIN != hMailWin      ;while FOCUSWIN is not mail window
         yield                         ;pause the script
      endwhile
      taskexit iMailTaskID             ;exit mail task
   endif   
   menuselect ASPMENU _MENU_HOT_LIST   ;select menu item
endproc



;*************************************************************************
;*                                                                       *
;* REMOVEITEM(szItem)                                                    *
;* The procedure REMOVEITEM removes a URL from the list.                 *
;*                                                                       *
;* Globals:  SZLISTFILE                                                  *
;* Calls:    NONE                                                        *
;* Called by:  DISPLAYDIALOG                                             *
;*                                                                       *
;*************************************************************************

proc RemoveItem
param string szItem                    ;item to be removed
   
   string szTempFile                   ;temporary file
   string szLine                       ;line in the file
   
   if findfirst szListFile             ;check item
      szTempFile = szListFile          ;temp file is list file
      strreplace szTempFile $FEXT "TMP";replace text in temp file
   endif
   
   if fopen 0 szListFile READ TEXT     ;open the list file
      if fopen 1 szTempFile CREATE TEXT;open the temp file
         while not feof 0              ;check for EOF of list file
            fgets 0 szLine             ;if not get a line in list file
            if not stricmp szLine szItem;compare line with list item
               if not nullstr szLine   ;if not nullstr
                  fputs 1 szLine       ;put line in tempfile
               endif               
            endif
         endwhile
         fclose 1                      ;close temp file
      endif
      fclose 0                         ;close list file
   endif
   delfile szListFile                  ;delete list file
   rename szTempFile szListFile        ;put tempfile as list file
   dlgupdate 0 1                       ;update dlg box
endproc



;*************************************************************************
;*                                                                       *
;* OPENWEBPAGE(szitem)                                                   *
;* The procedure OPENWEBPAGE opens the URL selected.                     *
;*                                                                       *
;* Globals:  NONE                                                        *
;* Calls:    NONE                                                        *
;* Called by:  DISPLAYDIALOG                                             *
;*                                                                       *
;*************************************************************************

proc OpenWebPage
param string szItem
   
   string szURL                        ;holds URL selected
   
   strextract szURL szItem "`t" 1      ;extract from szItem
   
   www OPEN szURL                      ;open URL

endproc



;*************************************************************************
;*                                                                       *
;* CREATEMAILFILE(szItem iFileType)                                      *
;* The procedure CREATEMAILFILE puts the WEBPOLL menu on the PW Menu bar.*
;*                                                                       *
;* Globals:  SZMAILFILE, SZLISTFILE                                      *
;* Calls:    NONE                                                        *
;* Called by:  DISPLAYDIALOG                                             *
;*                                                                       *
;*************************************************************************

proc CreateMailFile
param string szItem                    ;holds URL
param integer iFileType                ;holds file type

   string szLine                       ;holds the line of info

   switch iFileType
      case 1                           ;single URL
         if fopen 1 szMailFile CREATE TEXT;open mail file
            fputs 1 szItem             ;put URL in file
            fclose 1                   ;close mail file
         endif
      endcase
      case 2                           ;list
         if fopen 0 szListFile READ TEXT;open list file
            if fopen 1 szMailFile CREATE TEXT;open mail file
               while not feof 0        ;check for EOF of list file
                  fgets 0 szLine       ;get line in list file
                  if not nullstr szLine;make sure not a NULLSTR
                     fputs 1 szLine    ;put line in mail file
                  endif
               endwhile
               fclose 1                ;close mail file
            endif
            fclose 0                   ;close list file
         endif
      endcase
   endswitch

endproc



;*************************************************************************
;*                                                                       *
;* IMPORTHOTLIST()                                                       *
;* The procedure IMPORTHOTLIST imports a list of URL's.                  *
;*                                                                       *
;* Globals:  SZLISTFILE                                                  *
;* Calls:    NONE                                                        *
;* Called by:  MENUHANDLER                                               *
;*                                                                       *
;*************************************************************************

proc ImportHotList
   string szInputFile = $NULLSTR       ;set imput file to nulls
   string szLine                       ;variable for line of info
   
   sdlgfopen "Import File" "*.txt" SINGLE szInputFile;get file to open
   if SUCCESS                          ;if successful
      if fopen 0 szInputFile READ TEXT ;open input file
         if fopen 1 szListFile CREATE TEXT ;open listfile
            while not feof 0           ;do while not eof
               fgets 0 szLine          ;get line from import file
               if strfind szLine "http://";find http:// in line
                  strfind szLine "`t"     ;find character
                  if FAILURE           ;if fails
                     strreplace szLine "http://" "`thttp://"
                  endif
                  fputs 1 szLine       ;put into list file
               endif
            endwhile
            fclose 1                   ;close list file
         endif
         fclose 0                      ;close import file
      endif
   endif

endproc



;*************************************************************************
;*                                                                       *
;* EXPORTCONNDIR()                                                       *
;* The procedure EXPORTCONNDIR export connection directory entries to    *
;* hotlist.                                                              *
;*                                                                       *
;* Globals:  SZLISTFILE                                                  *
;* Calls:    NONE                                                        *
;* Called by:  MENUHANDLER                                               *
;*                                                                       *
;*************************************************************************

proc ExportConnDir
   string szConnDir, szEntryName      ;connection directory and entry name
   string szURL, szItem               ;URL and Item
   
   integer iNumEntries, iEntry        ;total number entries and current
   
   sdlgfopen "Connection Directory to Export" "*.dir" SINGLE szConnDir
   if SUCCESS
      if fopen 0 szListFile CREATE TEXT
         dialsave
         dialload szConnDir
         dialcount WWW iNumEntries
         for iEntry = 0 UPTO (iNumEntries - 1)
            dialname WWW iEntry szEntryName
            set dialentry access WWW szEntryName
            fetch dialentry ipaddress szURL
            strfmt szItem "%s`t%s" szEntryName szURL
            fputs 0 szItem
         endfor
         fclose 0
      endif
   endif
   
endproc
