;3TO4USR.WAS  - upgrades the PW3 HOST User file to PW4 standards. 
;upgrades name files only

;* 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.                         *                                                                          *
;*****************************************************************************



;**** PW4.0 USER RECORD ****
string   LoginName     ;51  
integer  SercurityInt  ;4
string   PasswordStr   ;9
string   TimeLimit     ;5
integer  TimeLeft      ;4
string   UploadPath    ;256
string   DnloadPath    ;256
integer  fDirectory    ;4
integer  fCallback     ;4
integer  fFaxBack      ;4
string   Note          ;51
string   CallBackNum   ;25
integer  CallNumber    ;4
long     LastCalled    ;4
integer  LastMsgRead   ;4
;***************************

;* Needed variables from the HOST40.PRM file 
string  RestrictedTimeStr, NormalTimeStr, SysopTimeStr
integer RestrictedTimeInt, NormalTimeInt, SysopTimeInt


proc main

   ReadHostPrmFile ()
   ClearGlobalVariables ()
   AddVersionTwoFiles ()

endproc


func ReadHostPrmFile : integer
string  JunkStr
integer JunkInt

   fopen 5 "HOST40.PRM" READ TEXT
   if failure 
      errormsg "Could not open the PRM file (HOST40.PRM)."
      halt
   endif
   
   fgets 5 JunkStr                    ;welcome message
   fgets 5 JunkStr                    ;upload path
   fgets 5 JunkStr                    ;download path
   fgetc 5 JunkInt                    ;new user level
   fgetc 5 JunkInt                    ;connection type 
   fgetc 5 JunkInt                    ;system type    
   fgetc 5 JunkInt                    ;goodbye option
   fgetc 5 JunkInt                    ;answer fax calls
   fgetc 5 fFaxBack                   ;if new users can request a faxback
   fgetc 5 JunkInt                    ;time choice
   fgets 5 JunkStr                    ;fax path
   fgets 5 JunkStr                    ;inactive time out
   fgets 5 RestrictedTimeStr          ;time limit of level 0 users
   fgets 5 NormalTimeStr              ;time limit of level 1 users
   fgets 5 SysopTimeStr               ;time limit of level 2 users
   
   fclose 5   
   
   atoi RestrictedTimeStr RestrictedTimeInt
   atoi NormalTimeStr NormalTimeInt
   atoi SysopTimeStr SysopTimeInt
   
   return 0
endfunc


func ClearGlobalVariables : integer

   UploadPath   = ""
   DnloadPath   = ""
   fDirectory   = 0
   fCallBack    = 0
   CallBackNum  = ""
   CallNumber   = 0
   LastCalled   = 0L
   LastMsgRead  = 0

   return 0
endfunc



func AddUserRecord : integer
   fwrite 21 LoginName 51	;write in the user record data for 15 items
   fwrite 21 SercurityInt
   fwrite 21 PasswordStr 9
   fwrite 21 TimeLimit 5                              
   fwrite 21 TimeLeft               
   fwrite 21 UploadPath 256
   fwrite 21 DnloadPath 256
   fwrite 21 fDirectory
   fwrite 21 fCallback
   fwrite 21 fFaxBack
   fwrite 21 Note 51
   fwrite 21 CallBackNum 25
   fwrite 21 CallNumber
   fwrite 21 LastCalled
   fwrite 21 LastMsgRead
  
   return 0
endfunc


func AddVersionTwoFiles : integer
string  TheAspectPath, OldPath
integer Button=0

   
   sdlgmsgbox "Host User File Conversion (PW3 to PW4)" "You will be asked\
 to choose the PW3 Host User file (usually C:\PROWIN3\ASPECT\HOST\HOST30.USR)"\
   INFORMATION OK Button
   if sdlgfopen "Choose PW3 Host User File" "c:\*.*" SINGLE OldPath
      usermsg "You chose to open `"%s`"." OldPath
   endif
   isfile OldPath
   if failure
      errormsg "Could not find the HOST30.USR file for PW3.  Exiting the script."
      halt
   endif
   
   fopen 20 OldPath READ TEXT
   if failure
      errormsg "Could not open the HOST30.USR file for PW3.  Exiting the script."
      halt
   endif
   
   TheAspectPath = $ASPECTPATH
   addfilename TheAspectPath "HOST40.USR"
   isfile TheAspectPath
   if success
      fopen 21 TheAspectPath READWRITE
      if failure 
         strupr TheAspectPath
         errormsg "Error opening the %s file.  Exiting the script." TheAspectPath
         halt
      endif
   else
      fopen 21 TheAspectPath CREATE
      if failure
         strupr TheAspectPath
         errormsg "Error creating the %s file.  Exiting the script." TheAspectPath
         halt
      endif
   endif
   
   AddTwoUserFile ()

   fclose 20
   fclose 21

   return 0
endfunc


func AddTwoUserFile : integer

   fseek 21 0 2
   while 1
      Read211UserRecord ()
      
      if FEOF 20
         exitwhile
      endif
      switch SercurityInt
         case 0
            TimeLimit   = RestrictedTimeStr
            TimeLeft    = RestrictedTimeInt
         endcase
      
         case 1
            TimeLimit   = NormalTimeStr
            TimeLeft    = NormalTimeInt
         endcase
      
         case 2
            TimeLimit   = SysopTimeStr
            TimeLeft    = SysopTimeInt
         endcase
         
         default
            loopwhile
         endcase
      endswitch
            
      AddUserRecord ()
   endwhile
   
   return 0
endfunc


func Read211UserRecord : integer
integer JunkI

   fread 20 LoginName 51
					;get the first byte of the 2 byte integer
   fgetc 20 SercurityInt		;get the second byte of the PW3 2-byte
   fgetc 20 JunkI			;integer (PW4 uses 4-byte integers so we
   					;cannot use the fread command)
   fread 20 PasswordStr 9
   fread 20 TimeLimit 5
   fgetc 20 TimeLeft
   fgetc 20 JunkI
   fread 20 UploadPath 256
   fread 20 DnloadPath 256
   fgetc 20 fDirectory
   fgetc 20 JunkI
   fgetc 20 fCallBack
   fgetc 20 JunkI
   fgetc 20 fFaxBack
   fgetc 20 JunkI
   fread 20 Note 51
   fread 20 CallBackNum 25
   fgetc 20 CallNumber
   fgetc 20 JunkI 
   fread 20 LastCalled
   fgetc 20 LastMsgRead
   fgetc 20 JunkI

   return 0
endfunc