
! script name: datatable.d/exporthtml
! var_topic: export a table of data in html format

!A
!A NAME:
!A
!A 	Export Table (HTML)	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Export a table of data, in html format.
!A
!B INSTRUCTIONS:
!B
!B 	The root directory is the current user directory.
!B
!# see also - htdocs/help.d/datatables.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: export html table")

DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Filename$[256],File2$[256]
DIM Filepath$[256]
DIM Destination$[256]
DIM Data$[4096]
DIM Title$[256]
DIM Sdevice$[256],Sdevice2$[256]
DIM Htmlroot$[256]
DIM SynergyHtml$[256]
DIM ExportFile$[256]
DIM Table$[256]
DIM Drive_letter$[32]

DEG

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
DEG

ActivateUndo
Lf$= CHR$(10)

Backround_color= 6
Table_color= 11
Caption_color= 1
Cell_spacing= -1
Cell_padding= -1

Sdevice$= System$("MASS STORAGE IS")
N1=POS(Sdevice$,":")
IF N1>1 AND N1<LEN(Sdevice$) THEN
	Drive_letter$=Sdevice$[1,N1-1]
	Sdevice$=Sdevice$[N1+1]
END IF

! Stat= NamedVarStr("http root dir",WsSystemVars,"/usr/weber/http/Web/",Sdevice$)
! Stat= NamedVarStr("synergy html dir",WsSystemVars,"Html.Syn/",Sdevice2$)
! Htmlroot$= Sdevice$
! SynergyHtml$= Sdevice2$

! F_type= DoesFileExist(Sdevice$)
! SELECT F_type
! CASE 0
! 	Data$= "Defined root directory DOES NOT EXIST."&Lf$
! 	Data$= Data$&"CREATE directory  "&Sdevice$
! 	Stat= MessageStringBox(Data$,"EXPORT ERROR MESSAGE")
! 	GOTO Leave
! CASE 1
! 	Data$= "Defined root directory IS A FILE.."&Lf$
! 	Data$= Data$&"CREATE directory  "&Sdevice$&Lf$
! 	Data$= Data$&"or change the VARIABLE:  http root dir."&Lf$
! 	Data$= Data$&"Also\, create directory "&Sdevice$&Sdevice2$
! 	Stat= MessageStringBox(Data$,"EXPORT ERROR MESSAGE")
! 	GOTO Leave
! END SELECT


! Sdevice$= Sdevice$&Sdevice2$
! F_type= DoesFileExist(Sdevice$)
! SELECT F_type
! CASE 0
! 	Data$= "HTML document directory DOES NOT EXIST."&Lf$
! 	Data$= Data$&"CREATE directory  "&Sdevice$&Lf$
! 	Data$= Data$&"or change the VARIABLE:  synergy html dir."&Lf$
! 	Stat= MessageStringBox(Data$,"EXPORT ERROR MESSAGE")
! 	GOTO Leave
! CASE 1
! 	Data$= "HTML document directory IS A FILE."&Lf$
! 	Data$= Data$&"CREATE directory  "&Sdevice$&Lf$
! 	Data$= Data$&"or change the VARIABLE:  synergy html dir."&Lf$
! 	Stat= MessageStringBox(Data$,"EXPORT ERROR MESSAGE")
! 	GOTO Leave
! END SELECT

Filename$=""

Ask_file:!
Stat=SetInputFormat("a99","")
Stat=GetValue("EXPORT FILE NAME",File2$)
IF ExitScript(Destination$) THEN Leave
IF (NOT POS(File2$,".html")) AND (NOT POS(File2$,".HTML")) THEN
        File2$= File2$&".html"
END IF
ExportFile$= File2$
Filename$= FileNameString(Sdevice$,File2$)

F_type= DoesFileExist(Filename$)
SELECT F_type
CASE 1
        Stat=SetInputFormat("a1",",Y,N,")
        Stat=GetValue("FILE EXISTS: OVERWRITE  Yes or No",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$= "N" THEN
                GOTO Ask_file
        END IF
CASE 2
        Stat=SetInputFormat("a1",",P,")
        Stat=GetValue("COPY NAME IS A DIRECTORY: Proceed ",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        GOTO Ask_file
END SELECT


Pick_table:stat= SetInputFormat("n4","")
Table1=PickEntity("PICK TABLE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Table1) THEN Pick_table
Stat= EntityNameCheck(Table1,Table$)

Stat=SetInputFormat("a99","")
Stat=GetValue("TABLE TITLE  None ",Title$)
IF ExitScript(Destination$) THEN Leave
Title$= TRIM$(Title$)
SELECT Title$
CASE "None","NONE","N","n"
	Title$=""
END SELECT

RecordFunctionOn
Stat= RecordDescr("EXPORT HTML TABLE: "&Filename$)
V1= StringConstant(Filename$)
! V2= StringConstant(SynergyHtml$)
! V3= StringConstant(ExportFile$)
V4= StringConstant(FileNameString(V1))
Stat= RemoveFile(V4)
V5= StringConstant(Title$)
V6= FreeParameter("Backround color",Backround_color)
V7= FreeParameter("Table color",Table_color)
V8= FreeParameter("Caption color",Caption_color)
V9= FreeParameter("Cell spacing",Cell_spacing)
V10= FreeParameter("Cell padding",Cell_padding)
Stat= ExportHtmlTable(Table$,V4,V5,V6,V7,V8,V9,V10)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("export html")
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

! stat= StartProcess("/usr/weber/bin/browser.ksh http://HOST/"&Sdevice2$&File2$&" &")
A$ = UniformPathName(Filename$)
Stat = MessageFileBox(A$,"HTML_VIEW","")

Leave:!
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
