; Installer for WebChat V1.0
; 
;   1.0 - It works but needs support for mailto.
;
; © W.P.Wilson - north@lantic16.demon.co.uk


(set type (askchoice (prompt 'What do you want to do?')
                     (help @askchoice-help)
                     (choices 'Install'
                              'Update')))

(procedure INS
 (message '\nInstalling:\n\n'
          'The Installing process needs two sections of HTML, a initial part & '
          'an end part.\n'
          'It also needs a local path for the finished HTML to go ready for uploading.\n'
          'Please read help for futher information before proceeding!\n\n'
          'This script "Web.rexx" and ALL associated files are provided '
          'with NO warranties as to the compatibility , reliability etc. '
          'Also if this program should do ANY type of damage to the user, the '
          'computer hardware or software or anything else I AND no-one else may '
          'be directly or indirectly connected with the fault -\n\n'
          '* You use this script at your own risk! *')

 (set base (pathonly @icon))

 (set @default-dest (askdir (prompt 'Select the where you want Weblist & its file putting.\n'
                                    '* A drawer wil NOT be created *')
                            (help 'Just select where you want Weblist.\n'
                                  'A Weblist: assign will be made there from '
                                  'the user-startup on boot.')
                            (default 'Work:')
 )                  )

 (set html (askdir (prompt 'Select the where you want chat.html creating.')
                            (help 'chat.html - the filename of the created HTML page. '
                                  'Its path should be somewhere in your local backup '
                                  'of your site.')
                            (default 'Work:Mysitebackupdir/')
 )                  )

 (set deftop (cat base '/HTML/default-top'))

 (set topsor (askfile (prompt 'Select the inital part of the chat.html.\n'
                               '* Use the default-top one in the html '
                               'drawer in you haven\'t made one *')
                       (help 'The initial part is the bit containing the <HTML> & <BODY> '
                             'tags & anything else you want to add such as a logo & help texts.')
                       (default deftop)
 )            )

 (set defbot (cat base '/HTML/default-end'))

 (set botsor (askfile (prompt 'Select the end part of the chat.html.\n'
                               '* Use the default-end one in the html '
                               'drawer in you haven\'t made one *')
                       (help 'The end part is the bit containing the </HTML> & </BODY> '
                             'tags & anything else you want to add such as a logo & help texts.')
                       (default defbot)
 )            )

 (ID)
; (MAILTO)

 (set exe (tackon base 'Install'))
 (set fil (tackon @default-dest 'HTML'))
 (set buf (cat base '/HTML/buffer'))
 (set htm (tackon @default-dest 'htmlpath'))
 (set cha (cat base '/HTML/chat.html'))

 (copyfiles (source exe)
            (dest @default-dest)
            (infos)
            (all)
 )
 
 (copyfiles (source topsor)
            (dest fil)
 )

 (copyfiles (source botsor)
            (dest fil)
 )

 (copyfiles (source buf)
            (dest fil)
 )

 (textfile (dest htm)
           (append html)
 )

 (copyfiles (source cha)
            (dest html)
 )

 (startup 'WebChat' (prompt 'WebChat needs a WebChat assign to be made.')
                    (help 'This will edit your user-startup.')
                    (command (cat 'ASSIGN WebChat: ' @default-dest))
 )
)

(procedure ID

 (message '\nWhen decoding a <FORM> output mail the script checks for '
          'a predefined formid given by\n(chat is the default ID):\n\n'
          '<INPUT type="HIDDEN" name="formid" value="chat">\n\n\n'
          'This is used to check the script is not decoding an '
          'incorrect mail.')

 (set NID (askstring (prompt 'Type in the chosen ID:\n'
                             'Leave as chat if using default top/bottom files.')
                     (help 'If you are starting with default files then use chat '
                           'as the ID. Else choose the one your own web code defines.')
                     (default 'chat')
 )        )

 (textfile (dest 'ENVARC:Webchat.pref')
           (append  NID)
 )
)

(procedure UPD

 (message '\nUpdate:\n\n'
          'This will allow you to change your '
          'initial & end parts of the html.\n'
          'It will also allow you to change your '
          '<FORM> ID.')

 (set ass 'WebChat:')
 (set fil (cat ass 'HTML'))
 (set deftop (cat fil '/default-top'))
 (set defbot (cat fil '/default-bot'))

 (set topsor (askfile (prompt 'Select the inital part of the chat.html.\n'
                               '* Use the default-top one in the html '
                               'drawer in you haven\'t made one *')
                       (help 'The initial part is the bit containing the <HTML> & <BODY> '
                             'tags & anything else you want to add such as a logo & help texts.')
                       (default deftop)
 )            )

 (set botsor (askfile (prompt 'Select the end part of the chat.html.\n'
                               '* Use the default-end one in the html '
                               'drawer in you haven\'t made one *'
                               ' - but remember to put in your email '
                               'address in the mailto:')
                       (help 'The end part is the bit containing the </HTML> & </BODY> '
                             'tags & anything else you want to add such as a logo & help texts.')
                       (default defbot)
 )            )

 (ID)

 (copyfiles (source topsor)
            (dest fil)
 )

 (copyfiles (source botsor)
            (dest fil)
 )

 (copyfiles (source buf)
            (dest fil)
 )

)

;(procedure MAILTO
;)

;(procedure UNI
;(message 'Uninstall')
;)

(if (= type 0) (INS))
(if (= type 1) (UPD))
;(if (= type 2) (UNI))

(exit)