Function RTI_BRW_FILTER(invokingName, UDetails, Param1)
*#!Precompile
/*
*  This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without
*  written permission from Revelation Technologies, Inc.
!
*
*  VERSION    : 1.0
*
*
*  AUTHOR     : Bryan Shumsky
*
*  CREATED    : September 23, 2009
*
*
!
*
*  REVISION HISTORY           (Most CURRENT first) :
*
*   DATE         IMPLEMENTOR  FUNCTION
*   --------     -----------  --------
*  09 Aug 2019   bzs          Added note on INIT and TERM calls - extra flag passed on first (INIT) and last (TERM) calls in a group
*  05 Feb 2019   bzs          Added support for SYSDICT call
*  10 Nov 2016   bzs          Added support for "reports" call
*  04 Oct 2012	  bzs	     Added support for "definitions" call
*  24 Feb 2012   bzs          Added support for "term" call
*  17 Jan 2012   bzs          Added support for "init" call
*  03 May 2010   bzs          Added logic to respect environment security settings
*
*
*/
*
$Insert ENVIRON_CONSTANTS
*
If Assigned(invokingname) Else invokingname = ""
If Assigned(udetails) Else udetails = ""
If Assigned(Param1) Else Param1 = ""
*
* By default, no filters are applied EXCEPT for system-wide filters
/* BZS 031124
SecFlds = @ENVIRON_SET<ENV_EXCLUDE_FIELDS$>
Sectbl =  @ENVIRON_SET<ENV_EXCLUDE_FROM_REPORTS$>
*/
SecFlds = @ENVIRON_SET_OI<ENV_EXCLUDE_FIELDS$>
SecTbl = @ENVIRON_SET_OI<ENV_EXCLUDE_FROM_REPORTS$>

rslt = ""
Begin Case
     Case uDetails = "REPORTS"
          * return list of report groups to provide to the report designer
          * Param1 is the full list of report groups available (@FM delimited)
          * Return modified list, or full list, or report groups
          * Note: to return NO report groups, explicitly return the string <<NONE>>
           rslt = param1
          
	Case uDetails = "INIT"
		* perform any required initialization
          * note: "DESIGNER" may be passed as invoking name if called from BRWDesigner, otherwise invokingname is a unique identifier
          * if multiple reports from a report group are being generated at the same time, param1 will be "1" for the initial INIT call
		RSLT = ""          

	Case uDetails = "TERM"
		* perform any required wrapup
          * note: "DESIGNER" may be passed as invoking name if called from BRWDesigner, otherwise invokingname is a unique identifier
          * if multiple reports from a report group are being generated at the same time, param1 will be "1" for the final TERM call
		RSLT = ""

	Case uDetails = "MSG_RENDERED"
		* perform any required operation when display to screen is generated
          * note: "DESIGNER" may be passed as invoking name if called from BRWDesigner, otherwise invokingname is a unique identifier         
		RSLT = ""

     Case uDetails = "STPROC"
		* return list of stored procedures to use as a data source
		RSLT = ""
		*RSLT = "@RTI_BRW_SAMPLEDATASOURCE"

	Case uDetails = "TABLES"
		* return list of all tables (except "!" and "DICT." tables)
		bExclude = 1
		Call Rlist("SELECT SYSTABLES BY @ID", '5')
		DONE = 0
		Loop
			Readnext id Else DONE = 1
		Until DONE Do
			If bExclude=0 Or (id[1,1] <> "!" And id[1,5] <> "DICT.") then
				Locate id In SecTbl<1> Using @VM Setting dummy else
					rslt<1,-1> = id
				End
			end
		Repeat		

	Case uDetails = "FIELDS" Or uDetails = "MVFIELDS"
		* return list of fields for specified table
          * Param1 is the name of the table
		trslt = Xlate("DICT.":Param1, "%FIELDS%", "", "X")
		num.flds = dcount(trslt<3>, @VM)
		rslt = ""
		For each.fld = 1 To num.flds
			this.fld = trslt<3,each.fld>
			ismv = trslt<9,each.fld>
			If (uDetails = "FIELDS") Or (uDetails = "MVFIELDS" And isMV) Then
				chkfld = Param1:@svm:this.fld
				Locate chkfld In secflds<1> Using @vm Setting chkpos Else
					rslt<1,-1> = this.fld
				End
			End
		Next each.fld
          
	Case uDetails = "SYSDICT"
          * Return list of SYSDICT items to make available to reports
          * return explicit "<<NONE>>" to return nothing, otherwise default %FIELDS% record will be used
          *
          * rslt = "<<NONE>>"
          *
          Open "SYSDICT" To sysdict.fl Then
               done = 0
               CALL Rlist("SELECT SYSDICT BY @ID", 5)
               //Select sysdict.fl
               Loop
                    Readnext id Else done = 1
               Until done do
                    Read dInfo From sysdict.fl, id Then
                       If dInfo[1,1] = "F" Or dInfo[1,1] = "S" Then
                         rslt<1,-1> = ID
                       end
                    End
               Repeat
          end
          *
          
     Case uDetails = "DEFINITIONS"
		Begin Case
			Case INVOKINGNAME _eqc "LABEL"
				* Return overriding list of label definitions
				* Read from a record in the system, or hard-code
				* format of the lines:
				/*
				// ID        label id
				// DESC      description
				// ACROSS    labels across a page
				// METRIC    metric/english units
				// WID       label width (all measurements in twips)
				// HEI       label height
				// XSPC      horz space between labels
				// YSPC      vert space between labels
				// MLEFT     page margin left
				// MRIGHT    page margin right
				// MTOP      page margin top
				// MLEFTLBL  label margin left
				// MTOPLBL   label margin top
				// CONT      continuous/sheet
				// PORTRAIT  portrait orientation				
				*
				* for example:
				*
				rslt = "OML 101,24 mm x 102 mm,1,1,5783,1503,0,0,709,709,71,340,113,1,1"
				rslt<-1> = "OML 102,37 mm x 102 mm,1,1,5783,2240,0,0,709,709,71,340,113,1,1"
				rslt<-1> = "OML 103,49 mm x 102 mm,1,1,5783,2920,0,0,709,709,71,340,113,1,1"
				rslt<-1> = "OML 105,49 mm x 127 mm,1,1,7201,2920,0,0,709,709,71,340,113,1,1"
				rslt<-1> = "OML 202,37 mm x 102 mm,2,1,5874,2240,91,0,675,675,71,340,113,1,1"
				rslt<-1> = "OML 203,49 mm x 102 mm,2,1,5874,2920,91,0,675,675,71,340,113,1,1"
				*/
			Case INVOKINGNAME _eqc "PAPER"
				* Return overriding list of paper definitions
                    
               Case INVOKINGNAME _Eqc "THEMES"
                    * Return overriding list of themes
                    *                    
                    /*
                    * format of the lines:
                    * themeName<space>{ReportHeader_theme}{PageHeader_theme}{GroupHeader_theme}{Detail_theme}{PageFooter_theme}
                    * where each section_theme contains:
                    * fontName;fontSize;fontStyle;foreColor;backColor;lineInfo;alternateColor
                    * fontStyle: null or style bits
                    * lineInfo: null or "a" (lineAbove), "b" (lineBelow), or "c" (lineAbove and lineBelow) followed by lineColor
                    * alternateColor: null or "striping" color
                    *
                    * for example:
                    *
                    rslt = "Access 2007 {Segoe UI;20;;#000000;;;}{Segoe UI;9;;#204D89;#C2DCFF;;}{Segoe UI;9;Bold;#000000;;;}{Segoe UI;9;;#000000;;;#F0F0F0}{Segoe UI;8;;#000000;;;}"
                    rslt<-1> = "Access 2003 {Tahoma;24;;#000000;;;}{Tahoma;8;;#000000;;;}{Tahoma;8;Bold;#000000;;;}{Tahoma;8;;#000000;;;}{Tahoma;8;;#000000;;;}"
                    rslt<-1> = "Apex {Lucida Sans;20;;#69676D;;;}{Book Antiqua;10;;#CEB966;#69676D;;}{Book Antiqua;10;Bold;#69676D;;a#69676D;}{Book Antiqua;10;;#000000;;;}{Book Antiqua;9;;#A0A0A0;;;}"
                    rslt<-1> = "Aspect {Verdana;18;;#323232;#E3DED1;;}{Verdana;8;;#E3DED1;#323232;;}{Verdana;8;Bold;#604878;;;}{Verdana;8;;#000000;;;}{Verdana;7;;#323232;;;}"
                    rslt<-1> = "Civic {Georgia;20;;#D6614A;;;}{Georgia;8;;#E4EEF3;#8CAEAD;;}{Georgia;8;Bold;#090000;;b#000000;}{Georgia;8;;#000000;;b#73A8D4;}{Georgia;7;;#000000;;;}"
                    rslt<-1> = "Concourse {Eras Medium ITC;20;;#282828;#2DA2BF;;}{Eras Medium ITC;9;;#EEEEEE;#282828;;}{Eras Medium ITC;9;Bold;#576793;;;}{Eras Medium ITC;9;;#282828;;;#EEEEEE}{Eras Medium ITC;8;;#2DA2BF;;;}"
                    rslt<-1> = "ComponentOne {Eras Medium ITC;20;;;#DD0000;;}{Eras Medium ITC;10;;#EEEEEE;#282828;;}{Eras Medium ITC;10;Bold;#576793;;;}{Eras Medium ITC;10;;#282828;;;#EEEEEE}{Eras Medium ITC;9;;#404040;;;}"
                    rslt<-1> = "Equity {Franklin Gothic Book;20;;;#D34817;;}{Perpetua;11;;#E9E5DC;#855D5D;;}{Perpetua;11;Bold;#9B2D1F;;;}{Perpetua;11;;#696464;;b#E9E5DC;}{Perpetua;10;;#BFBFBF;;;}"
                    rslt<-1> = "Flow {Calibri;20;;#04617B;#D1EAF0;;}{Constantia;9;;#04617B;;;}{Constantia;9;Bold;#04617B;;;}{Constantia;9;;#000000;;;}{Constantia;8;;#04617B;;;}"
                    rslt<-1> = "Foundry {Rockwell;20;;;#676A55;;}{Rockwell;9;;#EAEBDE;#676A55;;}{Rockwell;9;Bold;#EAEBDE;#676A55;;}{Rockwell;9;;#000000;;b#72A376;}{Rockwell;8;;#72A376;;;}"
                    rslt<-1> = "Median {Tw Cen Mt;20;;#FBEEC9;#775F55;;}{Tw Cen Mt;10;;#FBEEC9;#94B6D2;;}{Tw Cen Mt;10;Bold;#775F55;;;}{Tw Cen Mt;10;;#000000;;;}{Tw Cen Mt;8;;#775F55;;;}"
                    rslt<-1> = "Metro {Constantia;20;;;#000000;;}{Constantia;9;;;#000000;;}{Constantia;9;Bold;#4E5B6F;;;}{Constantia;9;;#000000;;;}{Constantia;9;;#000000;;;}"
                    rslt<-1> = "Module {Corbel;20;;;#383265;;}{Corbel;10;;;#383265;;}{Corbel;10;Bold;#000000;;;}{Corbel;10;;#000000;;;#EFEFEF}{Corbel;9;;#000000;;;}"
                    rslt<-1> = "None {Calibri;20;;#000000;;;}{Calibri;11;;#000000;;;}{Calibri;11;Bold;#000000;;;}{Calibri;11;;#000000;;;}{Calibri;11;;#000000;;;}"
                    rslt<-1> = "Northwind {Trebuchet;20;;#7F001B;;;}{Arial;9;;#F9F9F7;#C7C5BC;;}{Arial;9;Bold;#CF5216;;;}{Arial;9;;#000000;;;}{Arial;8;;#C7C5BC;;;}"
                    rslt<-1> = "Office {Cambria;20;Bold;#00224D;;;}{Calibri;9;Bold;#00224D;#79A7E3;;}{Calibri;9;Bold;#5C83B4;;;}{Calibri;9;;#000000;;;}{Calibri;8;;#000000;;;}"
                    rslt<-1> = "Opulent {Trebuchet;20;;#660066;#E9F7DD;;}{Trebuchet;9;;;#B13F9A;;}{Trebuchet;9;Bold;#B13F9A;;;}{Trebuchet;9;;#000000;;;#E9F7DD}{Trebuchet;8;;#000000;;;}"
                    rslt<-1> = "Oriel {Century Schoolbook;20;;#575F6D;;;}{Century Schoolbook;9;;#000000;;a#FF7D26;}{Century Schoolbook;9;Bold;#FF7D26;;a#000000;}{Century Schoolbook;9;;#000000;;;#FFF3EB}{Century Schoolbook;8;;#FF7D26;;;}"
                    rslt<-1> = "Origin {Bookman Old Style;20;;#DDE9EC;#46465D;;}{Gill Sans MT;10;;#DDE9EC;#46465D;;}{Gill Sans MT;10;Bold;#727CA3;;;}{Gill Sans MT;10;;#46465D;;;#DDE9EC}{Gill Sans MT;9;;#000000;;;}"
                    rslt<-1> = "Paper {Constantia;20;;#000000;#EFF2F5;;}{Constantia;9;;#EFF2F5;#4A606E;;}{Constantia;9;Bold;#4A606E;;b#000000;}{Constantia;9;;#000000;;b#95AEB1;}{Constantia;8;;#95AEB1;;;}"
                    rslt<-1> = "Solstice {Gill Sans MT;20;;#4F271C;#E7DEC9;;}{Gill Sans MT;10;;#4F271C;#E7DEC9;;}{Gill Sans MT;10;Bold;#3891A7;;;}{Gill Sans MT;10;;#4F271C;;;#E7DEC9}{Gill Sans MT;9;;#9F8D69;;;}"
                    rslt<-1> = "Technic {Franklin Gothic Book;20;;;#3B3B3B;;}{Arial;9;;#D4D2D0;#000000;;}{Arial;9;Bold;#979EA8;;b#979EA8;}{Arial;9;;#3B3B3B;;b#979EA8;}{Arial;8;;#000000;;;}"
                    rslt<-1> = "Trek {Franklin Gothic Book;20;;#4E3B30;;;}{Franklin Gothic Book;10;Bold;#4E3B30;;;}{Franklin Gothic Book;10;Bold;#A5644E;;;}{Franklin Gothic Book;10;;#4E3B30;;;#FBEEC9}{Franklin Gothic Book;9;;#000000;;;}"
                    rslt<-1> = "Urban {Trebuchet;20;;#42415A;;;}{Georgia;9;;#DEDEDE;#42415A;;}{Georgia;9;Bold;#42415A;;b#000000;}{Georgia;9;;#000000;;;#DEDEDE}{Georgia;8;;#438086;;;}"
                    rslt<-1> = "Verve {Century Gothic;20;;;#666666;;}{Century Gothic;8;;;#666666;;}{Century Gothic;8;Bold;#666666;;;}{Century Gothic;8;;#000000;;;#D2D2D2}{Century Gothic;7;;#000000;;;}"
                    rslt<-1> = "Windows Vista {Segoe UI;20;;;#000000;;}{Segoe UI;9;;#FFFFFF;#000000;;}{Segoe UI;9;Bold;#616A76;;;}{Segoe UI;9;;#373C43;;;#EBEBEB}{Segoe UI;8;;#000000;;;}"
                    rslt<-1> = "Bold {Times New Roman;20;Bold;#800000;;;}{Arial;10;Bold;#000000;;;}{Arial;10;Bold;#000000;;a#000000;}{Times New Roman;9;;#000000;;;}{Times New Roman;8;;#000000;;;}"
                    rslt<-1> = "Casual {Tahoma;24;Bold;#008080;;;}{Arial;10;;#000000;;;}{Arial;10;Bold;#000000;;b#008080;}{Times New Roman;9;;#000000;;;}{Times New Roman;8;;#000000;;;}"
                    rslt<-1> = "Compact {Haettenschweiler;26;Bold;#000000;;;}{Haettenschweiler;14;;#000000;;;}{Haettenschweiler;12;;#000000;;;}{Arial;9;;#000000;;;}{Arial;8;;#000000;;;}"
                    rslt<-1> = "Corporate {Times New Roman;20;Bold-Italic;#000080;;;}{Times New Roman;9;Bold-Italic;#000080;;;}{Times New Roman;9;Bold-Italic;#000080;;b#808080;}{Arial;9;;#000000;;;}{Arial;8;;#000000;;;}"
                    rslt<-1> = "Formal {Times New Roman;20;;#000000;;;}{Times New Roman;9;Bold;#000000;;;}{Times New Roman;9;Bold;#000000;;;}{Arial;9;;#000000;;;}{Arial;8;;#000000;;;}"
                    rslt<-1> = "Soft Gray {Arial;24;Bold;;#C0C0C0;;}{Arial;9;;#000000;;a#C0C0C0;}{Arial;9;Bold;#000000;;;}{Times New Roman;9;;#000000;;;}{Times New Roman;8;;#000000;;;}"
                    rslt<-1> = "Verdana {Verdana;18;Bold;;#4580B5;;}{Verdana;9;Bold;#4580B5;;a#000000;}{Verdana;9;;#4580B5;;;}{Verdana;9;;#000000;;;}{Verdana;8;;#000000;;;}"
                    rslt<-1> = "Web Report {Verdana;18;Bold;#50308C;#F5F5DC;;}{Verdana;9;Bold;#50308C;;a#000000;}{Verdana;9;;#4580B5;;;}{Verdana;9;;#000000;;;}{Verdana;8;;#000000;;;}"
                    */
          End CASE		
End Case
*
Return rslt
