COMPILE FUNCTION SRP_EDITOR_TEMP_PRINTER_SELECT_SYSPROG(PrinterID,RetDefault)

DECLARE FUNCTION PrintSetup, PopUp, Get_Status
DECLARE SUBROUTINE Set_Status

$INSERT POPUP_EQUATES
$INSERT PRINTSETUP_EQUATES

/*
	Routine to Select Printer and Port for use in OIPI Set_Printer("INIT",...) calls. 
	
	2/4/2000 by jch  * * * *
*/


IF NOT(ASSIGNED(PrinterID))	THEN PrinterID = ''
IF NOT(ASSIGNED(RetDefault))	THEN RetDefault = ''

Printers	= ''
Default		= ''
PrintCount	= PrintSetup(PRN_GET$,'',Printers,Default)	;* OI routine returns printer names, driver, port information

DefPrinter	= Default[1,',']
DefPort		= FIELD(Default,',',3)
DefLine		= DefPrinter:' on ':DefPort

IF RetDefault THEN
	SWAP ' on ' WITH @FM IN DefLine
	RETURN DefLine
END

PopLines = ''											;* Pretty up printer names and ports for a popup
SkipPopup = 0

CONVERT @LOWER_CASE TO @UPPER_CASE IN PrinterID

FOR I = 1 TO PrintCount
	Printer = Printers<I>[1,',']
	Port	= FIELD(Printers<I>,',',3)
	IF Printer NE '' THEN
		TestPrinter = Printer
		CONVERT @LOWER_CASE TO @UPPER_CASE IN TestPrinter
		IF TestPrinter = PrinterID THEN SkipPopup = I
	END
	PopLines<1,I> = Printer:' on ':Port
NEXT I

IF SkipPopup THEN
	PrintPath = PopLines<1,SkipPopup>
	SWAP ' on ' WITH @FM IN PrintPath
	RETURN PrintPath
END

LOCATE DefLine IN PopLines USING @VM SETTING DefPos ELSE DefPos = ''

TypeOver = ''
TypeOver<PDISPLAY$>	= PopLines
TypeOver<PFORMAT$>	= '1':@SVM:'60':@SVM:'L':@SVM:'L':@SVM:'':@SVM:'Printer'
TypeOver<PMODE$>	= 'L'
TypeOver<PTYPE$>	= 'E'
TypeOver<PTITLE$>	= 'Select Report Destination...'
IF DefPos NE '' THEN
	TypeOver<PINITSELECT$> = DefPos
END

Set_Status(0)
PrintPath = PopUp(@WINDOW,TypeOver)	;* Pick from popup

IF PrintPath = '' THEN RETURN ''
SWAP ' on ' WITH @FM IN PrintPath						;* Put in format for passing Set_Printer('INIT'...)

RETURN PrintPath
