          SUBROUTINE (OID,GEN,PASSER)
** Version# 28 - 05/09/2006 - 12:24pm - JEREMYH - main

*** SUBROUTINE - OE.WEB.SHIP
*-------------------------------------------------------------------------*
*** Routine launchs internet various internet sites. More specifically you
*** can launch :
***  MapQuest - will bring up a map to the ship to
***  Track your shipment through FedEx, UPS, Airborne Tracking Status,
***     Roadway Packing System, or the US Postal Service.
*-------------------------------------------------------------------------*
*** OID    -[IN]- Order number
*** GEN    -[IN]- Generation of order
*** PASSER -(IN/OUT)- If passer is set on the way in then this routine is
***                   called from WOE and a browser will not be launched,
***                   but PASSER will be sent back with:
***                   -<2>- URL description
***                   -<3>- URL address
***                   -<4>- Shipping Carrier List
***                   -<5>- Shipping Tracking IDS
***                   If PASSER is not set on the way in then this routine
***                   is called from the header of SOE and will prompt
***                   the user for the type of inquiry they wish to make,
***                   and PASSER will be sent back empty.
*-------------------------------------------------------------------------*
          SHP.ADR    = ''
          SHP.LNGTH  = 0
          SHP.CODES  = ''
          SHP.NUMBS  = ''
          ERR.MSG    = ''
          DATE       = ''
          PASS.BACK  = (PASSER # '')
          UPS.TNO.CT = 0
          WORD       = ''
          VALID.URLS = ''

          READ LEDL FROM LEDLFILE,OID ELSE LEDL = ''
          SHPVIAS = LEDL<23,GEN> ;* Starship ship via's
          TRKNOS  = LEDL<24,GEN> ;* Starship Tracking Number
          CMT.LOG = LEDL<10,GEN> ;* Update log

          *** See if the order has been processed by Starship.
          CMT.CT = DCOUNT(CMT.LOG<1>,VM)
          J = CMT.CT
          LOOP
          WHILE J GE 1
          IF CMT.LOG<1,J,4> = 'StarShip' THEN
             DATE = CMT.LOG<1,J,2>
             EXIT
          END
          J = J-1
          REPEAT
          IF NOT(DATE) THEN DATE = LED(9)<1,GEN>

          *** If called from the header of SOE, prompt the user for the
          *** type of inquiry they wish to make.  If called from WOE,
          *** read the URL from the SHIPPING.URLS control file.
          IF NOT(PASS.BACK) THEN
             SHIPPING.INQUIRY WORD,TMP
             IF F12 THEN RETURN
             SHP.CT = DCOUNT(TMP,AM)
             BEGIN CASE
             CASE WORD = 'MAPQUEST' OR WORD = 'GOOGLEMAPS'
                GOSUB GET.URLLINK
             CASE OTHERWISE
                GOSUB GET.SHP.INFO
                GOSUB SELECT
                *** Eterm can only pass (to the browser) a maximum of 200
                *** characters.  Therefore, the URL we create can only
                *** include up to 3 Tracking #s.  So if the Ship Type is
                *** UPS (which can handle more than 1 Tracking #),
                *** and there ARE more than 3, we need to have the user
                *** select which 3 they want to view...
                IF WORD = 'UPS' AND UPS.TNO.CT > 3 THEN
                   TRACK.NUM.SELECT TMP,SHP.NUMBS
                   IF F12 OR QUIT THEN RETURN
                END
                GOSUB GET.URL
             END CASE

             GOSUB START.BROWSER

          END ELSE
             READ SHIP.URLS FROM CTRLFILE,'SHIPPING.URLS' ELSE RETURN

             URLS.CT = DCOUNT(SHIP.URLS,AM)
             FOR J = 1 TO URLS.CT
                VALID.URLS<-1> = SHIP.URLS<J,1>
             NEXT J

             LOCATE PASSER<1> IN VALID.URLS SETTING POS ELSE POS = ''
             IF POS THEN
                TMP    = SHIP.URLS<POS,3>
                DESC   = SHIP.URLS<POS,2>
                SHP.CT = DCOUNT(TMP,AM)

                BEGIN CASE
                CASE PASSER = 'MAPQUEST' OR PASSER = 'GOOGLEMAPS'
                   GOSUB GET.URLLINK
                CASE OTHERWISE
                   GOSUB GET.SHP.INFO
                   GOSUB GET.URL
                END CASE

                GOSUB PASS.BACK
             END ELSE
                TMP = ''; DESC = ''
                GOSUB GET.SHP.INFO
                GOSUB PASS.BACK
             END
          END

          RETURN
*-------------------------------------------------------------------------*
GET.URLLINK: *** Get the information for a MAPQUEST or GOOGLEMAPS URL

          *** Insert the date, address and zip code.
          TMP.ADDR  = LED(78)<1,GEN,1>   ;* Ship-to address
          TMP.ZIP   = LED(75)<1,GEN,1>   ;* Ship-to ZIP
          TMP.CITY  = LED(78)<1,GEN,4>   ;* Ship-to City
          TMP.STATE = LED(78)<1,GEN,5>   ;* Ship-to State
          READV TMP.COUNTRY FROM ZIPFILE,TMP.ZIP,5 ELSE TMP.COUNTRY = ''

          CONVERT ' ' TO '+' IN TMP.ADDR
          CONVERT ' ' TO '+' IN TMP.CITY
          CONVERT ' ' TO '+' IN TMP.STATE
          CONVERT ' ' TO '+' IN TMP.ZIP
          CONVERT ' ' TO '+' IN TMP.COUNTRY

          UT.REP.STR TMP,'$ADDR$',TMP.ADDR
          UT.REP.STR TMP,'$ZIP$' ,TMP.ZIP
          UT.REP.STR TMP,'$DATE$',OCONV(DATE,'D2/')
          UT.REP.STR TMP,'$CITY$',TMP.CITY
          UT.REP.STR TMP,'$STATE$',TMP.STATE
          UT.REP.STR TMP,'$COUNTRY$',TMP.COUNTRY

          RETURN
*-------------------------------------------------------------------------*
GET.SHP.INFO: *** Get shipping Codes and Tracking numbers for this order

          IF PASSER<2> THEN
             SHP.NUMBS<-1> = TRKNOS<1,1,PASSER<2>>
             RETURN
          END
          *** Create a list of shipping numbers and shipping codes.
          FOR M = 1 TO DCOUNT(SHPVIAS<1,1>,SVM)
             SV.SHP = FIELD(SHPVIAS<1,1,M>,' ',1)

             LOCATE SV.SHP IN SHP.CODES SETTING SC THEN
                SHP.NUMBS<SC,-1> = TRKNOS<1,1,M>
             END ELSE
                SHP.CODES<-1> = OCONV(SV.SHP,"MCU")
                SHP.NUMBS<-1> = TRKNOS<1,1,M>
             END
          NEXT M

          CONVERT ' ' TO '+' IN SHP.NUMBS

          *** Find out how many Tracking #s there are (if any) for UPS...
          FOR SCODE = 1 TO DCOUNT(SHP.CODES,VM) ;**???
             LOCATE 'UPS' IN SHP.CODES SETTING POS THEN
                FOR SN = 1 TO DCOUNT(SHP.NUMBS<POS>,VM)
                   UPS.TNO.CT += 1
                NEXT SN
             END
          NEXT SCODE

          RETURN
*-------------------------------------------------------------------------*
SELECT:   *** Make sure the carrier exists on this order.  If there is
          *** more than one carrier on the order, locate the correct one
          LOCATE WORD IN SHP.CODES SETTING POS THEN
             SHP.NUMBS = SHP.NUMBS<POS>
          END ELSE
             ERR.MSG = 'Shipping Carrier does not exist on this Order'
          END

          RETURN
*-------------------------------------------------------------------------*
GET.URL:  *** Build the URL with the appropriate Tracking #s
          *** We need to reload the Shipping Web Addresses, since we'll now
          *** include any Tracking Numbers in the address...
          FOR J = 1 TO SHP.CT
          IF TMP<J,1> THEN
             IF WORD = 'UPS' THEN
             *** This code is specific to UPS because they can handle
             *** more than one tracking number at a time
                RESP = SHP.NUMBS<J,1>
                *** If it's more than 3, we won't build the URL here

                FOR X = 2 TO 3
                IF SHP.NUMBS<J,X> THEN
                   RESP := '&InquiryNumber':X:'=':SHP.NUMBS<J,X>
                END
                NEXT X

                TEMP.TMP = TMP<J>
                UT.REP.STR TEMP.TMP,'$TRACK.NO$',RESP
                TMP<J> = TEMP.TMP
             END ELSE
                TEMP.TMP = TMP<J>
                UT.REP.STR TEMP.TMP,'$TRACK.NO$',SHP.NUMBS<J,1>
                TMP<J> = TEMP.TMP
             END
          END
          NEXT J

          RETURN
*-------------------------------------------------------------------------*
PASS.BACK: *** Send the URL and description if called from WOE
          PASSER<2> = DESC
          PASSER<3> = TMP
          PASSER<4> = LOWER(SHP.CODES)
          PASSER<5> = LOWER(SHP.NUMBS)

          RETURN
*-------------------------------------------------------------------------*
START.BROWSER: *** Start the web browser with the URL address.
          IF ERR.MSG THEN
             PRINT BELL:;
IN$$1:       INP.PROMPT ,ERR.MSG,,0
          END ELSE
             START.DFLT.BROWSER TMP,ERR.MSG
          END

          RETURN
*-------------------------------------------------------------------------*

!JEREMYH~05/09/06~12:24
