          SUBROUTINE (SPEC,TITLE,DOC.ID,HDR,FTR,RPT.DFLT,NOTBASIC)
** Version# 42.0002[1] - 04/14/2016 - 03:08pm - TSMITH - eclipse
*** V42.0001 Change - Custom Coding . - 04/01/2016 - TSMITH - eclipse

*** Subroutine - PRINTER.ON
*---------------------------Program Description---------------------------*
*** This routine initiates the process of printing a document (or creating
*** an ODBC data source).
***
*** Some of the functionality it performs includes:
*** 1) Reserve the next document id (DOC.ID).
*** 2) Writing our document details (attributes) out to the document's
***    report record.
*** 3) Begin communications with the Printer.
*** 4) Create an ODBC file.
*---------------------------Paremeter Definition--------------------------*
***  SPEC       -                                                  [IN]
***  TITLE      - The title of the report.  This will show up in   (IN)
***             - in the report queue.
***  DOC.ID     - Document Id.  This is the key for the REPORTS    [OUT]
***             - file and the &HOLD& file.
***  HDR        - Document Heading                                 (IN)
***  FTR        - Document Footer                                  (IN)
***  RPT.DFLT   - REPORTS Record Defaults                          [IN]
***  NOTBASIC   -                                                  (IN)
*-------------------------------------------------------------------------*
*** Common: ACTIVE.FORMS$
*-------------------------------------------------------------------------*

          * for hot swap reporting
          IF RPT.DFLT<52> = "" THEN
             GET.NEW.ID 'NEXT.DOC',DOC.ID,,,RPTFILE
          END ELSE
             DOC.ID = RPT.DFLT<52>
          END

          REPORT.ID  = DOC.ID
          FORM       = ''
          PTR.ID     = ''
          WIDTH      = ''
          LGTH       = ''
          USE.ACTIVE = ACTIVE.FORMS$<1>
          FORM.NAME  = ''

          IF SPEC="UPSNDA" THEN
          RPT.DFLT<60> = "UPSNDA"
          RPT.DFLT<30> = 2
          END


          * Open the FORMS file.
          UT.OPEN.FILE "FORMS",FORMFILE,FORM.ERR,YES

          READV BYPASS.EFORMS FROM FORMFILE,SPEC,9 ELSE
             BYPASS.EFORMS = NO
          END

          IF NOT(SPEC) THEN SPEC = ''
          SPEC1 = FIELD(SPEC,',',1)
          BEGIN CASE
          CASE SPEC[1,4]  = 'HOLD'
             RPT.DFLT<27> = 'HOLD'
             WIDTH        = FIELD(SPEC,':',2)
          CASE SPEC[1,4]  = 'VIEW'
             RPT.DFLT<27> = 'VIEW'
             WIDTH        = FIELD(SPEC,':',2)
          CASE NUM(SPEC)
             WIDTH    = FIELD(SPEC,'.',1)+0
             IF WIDTH = 0 THEN WIDTH=132
             FORM     = 'PLAIN'
          CASE SPEC[1,1] = '@' AND (SPEC1[2,9] MATCHES "0N" OR SPEC1[2,5] = "SLAVE")
             PTR.ID = SPEC1[2,9]
             WIDTH  = FIELD(SPEC,',',2)
             IF NOT(NUM(WIDTH)) THEN WIDTH = ''
          CASE SPEC[1,1] = '*'
             FORM = SPEC[2,999]
             IF FORM.ERR THEN
                WIDTH = 80
             END ELSE
                READV WIDTH FROM FORMFILE,FORM,4 ELSE WIDTH = 80
             END
          CASE OTHERWISE
             * If Eclipse Forms, then we may need to cross-reference the
             * old document name to the new document name.  Leave FORM.NAME
             * null so that it sets RPT<60> correctly.
             IF (USE.ECLIPSE.FORMS$) THEN
                IF NOT(BYPASS.EFORMS) THEN
                   CTRL.ID = 'PRINTER.SETUP.VALID.FORMS'
                   READ VALID.FORMS FROM CTRLFILE,CTRL.ID THEN
                      LOCATE SPEC IN VALID.FORMS<3> SETTING FPOS THEN
                         SPEC = VALID.FORMS<2,FPOS>
                      END
                   END
                END
                FORM.NAME = SPEC
             END ELSE
                FORM.NAME = SPEC
             END
             PRINTER.FORM.GET SPEC,FORM,WIDTH
          END CASE



          * Check to see if Eclipse Forms should be bypassed based on the
          * form being printed. For example, label will bypass Eclipse
          * Forms.
          IF NOT(FORM.ERR) THEN
             * If this type of form should bypass Eclipse Forms, we will
             * set the global variable to NO here. This will be restored
             * in PRINTER.OFF from the SV.ECLIPSE.FORMS$ global variable
             * which is set in COMMON.INIT when USE.ECLIPSE.FORMS$ is set.
             IF BYPASS.EFORMS THEN
                USE.ECLIPSE.FORMS$ = NO
             END
          END ELSE
             BYPASS.EFORMS = NO
          END

          * The form name is being stored here as well as RPT.DFLT<17>
          * because there is a section of code later that set the form
          * to plain regarless of what the form is now.  This attribute
          * stores the intended form name.

          * If printing a form, we need RPT<60> to have the real form name
          * instead of the mapped form name in TITLE.POSTING control rec
          * because if a form is mapped to "PLAIN", Solar will fail to
          * print the document.

          IF FORM.NAME THEN
             READ FORM.XREF FROM CTRLFILE,'TITLE.POSTING' ELSE FORM.XREF=""
             FORM.NAME = OCONV(FORM.NAME,'MCU')
             LOCATE SPEC IN FORM.XREF<1> SETTING NOTHING THEN
                RPT.DFLT<60> = FORM.NAME
             END ELSE
                RPT.DFLT<60> = FORM
             END
          END ELSE
             RPT.DFLT<60> = FORM
          END

          IF TITLE[1,4]="NEXT" THEN
          RPT.DFLT<60> = "UPSNDA"
          RPT.DFLT<30> = 2
          END






          IF RPT.DFLT<27> # '' THEN
             PTR.ID = RPT.DFLT<27>
          END

          IF WIDTH + 0 = 0 THEN WIDTH = 132

          PRINTER.ID  = ''
          FAX.DATA    = RPT.DFLT<29>
          O.BODY      = RPT.DFLT<57>
          EMAIL.DATA  = RPT.DFLT<58>
          FTP.DATA    = RPT.DFLT<65>

          * There are certain times for faxing when will not want to
          * use Eclipse Forms - use old style faxing instead. An
          * example of this would be the Fax Memo.
          IF (FAX.DATA<1,18> = "NO.ECLIPSE.FORMS") THEN
             USE.ECLIPSE.FORMS$ = NO
             BYPASS.EFORMS      = YES
          END

          IF JAVA.PROC$ THEN
             JAVA.PASSER$<JP.MODE$>   = 'JAVA.PRINTER.ON'
             JAVA.PASSER$<JP.DOC.ID$> = 'DOC#':DOC.ID
             JAVA.PASSER$<JP.FORM$>   = 'FORM#':FORM
             RPT.DFLT<27>             = 'HOLD'
          END ELSE
             IF FAX.DATA = '' AND PTR.ID = '' THEN
                IF USE.ACTIVE THEN
                   LOCATE FORM IN ACTIVE.FORMS$<2> SETTING POS THEN
                      PTR.ID = ACTIVE.FORMS$<3,POS>
                   END ELSE
                      PTR.ID = SELECT.PTR(FORM)
                      ACTIVE.FORMS$<2,POS> = FORM
                      ACTIVE.FORMS$<3,POS> = PTR.ID
                   END
                END ELSE
                   PTR.ID = SELECT.PTR(FORM)
                END
             END
          END

          IF (((TITLE = '' AND FAX.DATA) OR (TITLE = '' AND PTR.ID # '' AND PTR.ID # 'VIEW')) AND NOT(USE.ECLIPSE.FORMS$)) THEN
             ORIEN = RPT.DFLT<18>
             DPLX  = RPT.DFLT<28>
             PRINTER.ON.INIT DOC.ID,PTR.ID,WIDTH,LGTH,OPEN.ERR,FAX.DATA,ORIEN,DPLX
          END ELSE
             IF FAX.DATA THEN
                PTR.ID = ''
                FAX.PTR.SELECT FAX.DATA<1,1>,FAX.DATA<1,9>,PTR.ID
             END

             COMMAND  = 'SETPTR 0,':WIDTH:',999,,,3,NOHEAD,NOEJECT,'
             COMMAND := 'NOFMT,BRIEF,BANNER ':DOC.ID
             EXECUTE COMMAND CAPTURING GARBAGE

             IF NOT(NOTBASIC) THEN
                PRINTER ON
                PRINTER.ON$ = YES
             END
             FORM = 'PLAIN'
          END

          IF TITLE[1,4]="NEXT" THEN
          FORM = "UPSNDA"
          HDR = ""
          RPT.DFLT<30> = 2
          END

          READU RPT FROM RPTFILE,DOC.ID ELSE
             RPT = RPT.DFLT
          END

          * Check vars beign added to the RPT array and lower any that
          * might have been passed in with more than 1 AM.
          IF DCOUNT(HDR,AM) > 1        THEN HDR        = LOWER(HDR)
          IF DCOUNT(FTR,AM) > 1        THEN FTR        = LOWER(FTR)
          IF DCOUNT(FAX.DATA,AM) > 1   THEN FAX.DATA   = LOWER(FAX.DATA)
          IF DCOUNT(EMAIL.DATA,AM) > 1 THEN EMAIL.DATA = LOWER(EMAIL.DATA)
          IF DCOUNT(O.BODY,AM) > 1     THEN O.BODY     = LOWER(O.BODY)

          * If user defined heading option is set to strip heading, clear
          * out the heading
          IF RPT.DFLT<63> THEN HDR = ''





          RPT<1>      = TITLE
          RPT<2>      = WIDTH
          IF RPT<3>   = '' THEN RPT<3> = LGTH
          IF RPT<4>   = '' THEN RPT<4> = USER.ID
          RPT<5>      = DATE()
          RPT<6>      = INT(TIME())
          RPT<7>      = @TTY[9,9]
          RPT<8>      = HDR
          RPT<9>      = FTR
          RPT<10>     = NOTBASIC
          RPT<17>     = FORM
          RPT<27>     = PTR.ID
          RPT<29>     = FAX.DATA
          IF RPT<36>  = '' THEN RPT<36> = RPT<4>
          PROC.ID     = PID$
          RPT<53>     = PROC.ID
          RPT<57>     = O.BODY
          RPT<58>     = EMAIL.DATA
          RPT<65>     = FTP.DATA

          * Inidicate that Eclipse Forms should be bypassed.
          IF BYPASS.EFORMS THEN
             RPT<67> = "BYPASS.ECLIPSE.FORMS"
          END

          * Update the PHANTOM.LOG with the document @ID and
          * the schedule process ID to tie the output to the process
          ATTRB = 9
          VALUE = RPT.DFLT<62,1>
          UPDATE.PHANTOM.LOG.FIELD PROC.ID,ATTRB,VALUE

          WRITE RPT ON RPTFILE,DOC.ID
          GOSUB CREATE.ODBC.FILE

          RETURN
*-------------------------------------------------------------------------*
CREATE.ODBC.FILE: *** This will create the odbc file if the current report
          *** requires one.

          ODBC.FLAG = RPT<40,1>
          IF NOT(ODBC.FLAG) THEN RETURN

          ODBC.NAME = 'ODBC.':DOC.ID
          CREATE.CT = 0
          COMMAND   = "CREATE-FILE ":ODBC.NAME:" 1 500,4,30"

          LOOP
             EXECUTE COMMAND CAPTURING NOTHING

             ERR.MSG = ''
             UT.OPEN.FILE ODBC.NAME,ODBCFILE,ERR.MSG,YES
             IF NOT(ERR.MSG) THEN EXIT

             WHILE CREATE.CT < 3

             CREATE.CT += 1
          REPEAT

          RETURN
!TSMITH~04/14/16~15:08
