/*
 * ExportHTML.mmx
 *
 *
 * ©1997 Andreas Mair
 *
 *
 * Version:      1.00
 * Date:         19.07.1997
 *
 * Function:     A simple ARexx-Script for use with MusicManIII.
 *               This script will read all records of the currently open file
 *               in MusicManIII and write it to an HTML-file.
 *
 *               The output consists of three HTML-files:
 *
 *                - index.htm      open this file in your WWW-browser
 *                                 (must support tables and frames!)
 *
 *                - contents.htm   this file is displayed in the left frame
 *                                 it shows alphapetic links to let you jump
 *                                 quickly to those records
 *
 *                - data.htm       this file is displayed in the right frame
 *                                 this file contains the records' data in the format:
 *
 *                                   Artist
 *                                   Title
 *                                   Songs Length (for every song)
 *                                   separator
 *
 *               NOTE: * this script will always overwrite the files "contents.htm"
 *                       and "data.htm", so you have to rename the files if you want
 *                       to keep them.
 *                     * the file "index.htm" is never created! Don't loose it ;-)
 *
 * Requirements: MusicManIII V3.06 (or above)
 *               ARexx running
 *
 * Usage:        - first start MusicManIII and load the file you want to export
 *               - go to a CLI (or Shell) and start this script ("rx ExportHTML.mmx")
 *
 */

ADDRESS 'MUSICMAN'

OPTIONS RESULTS

QUERY RECORDSCOUNT
MaxRecords=RESULT

RECORD GET NUMBER 1

CALL OPEN( "cont", "contents.htm", 'WRITE' )
CALL OPEN( "data", "data.htm", 'WRITE' )

CALL WRITELN( "data", "<HTML>" )
CALL WRITELN( "cont", "<HTML>" )

LastChar=' '

DO i=1 TO MaxRecords
	SAY "Working on record #"i" of "MaxRecords

	QUERY ARTIST TITLE SONGSCOUNT SUBRECORDSCOUNT STEM record.

	IF LEFT( record.artist, 1 )~=LastChar THEN
		DO
		LastChar=LEFT( record.artist, 1 )
		CALL WRITELN( "cont", '<A HREF="data.htm#'LastChar'" TARGET="data">'LastChar'</A><BR>' )
		CALL WRITELN( "data", '<A NAME="'LastChar'">' )
		END

	CALL WRITELN( "data", "<HR><H1>"record.artist"<BR>"record.title"</H1><BR>" )

	CALL WRITELN( "data", "<TABLE NOBORDER CELLPADDING=5>" )

	DO j=1 TO record.songscount
		QUERY SONG LENGTH BPM SPECIAL STEM song.
		CALL WRITELN( "data", "<TR><TD>"j"</TD><TD>"song.song"</TD><TD>"song.length"</TD></TR>" )
		SONG NEXT
	END

	CALL WRITELN( "data", "</TABLE><P>" )

	RECORD NEXT

	CALL WRITELN( "data", "")
END

CALL WRITELN( "cont", "</HTML>" )
CALL WRITELN( "data", "</HTML>" )

CALL CLOSE( "cont" )
CALL CLOSE( "data" )

