/* Mode=Run */
/* ***********************************************************************

    HTML_results.rexx v1.1 (01-7-99) for THE FOOTBALL REXX SUITE
    -----------------------------------------------------------
     by Kevin Lambert (amiga4000@bizonline.co.uk)

    -This script will generate an HTML file of the fixtures and results.

    -To use HTML_results.rexx you can run it by using the 'Run Script' button
     on the Football main panel. Select HTML_results.rexx from the file
     requester and away you go. A file (????res.html) will be written to RAM:
     but this location can be changed. View the file with any browser that
     supports tables.


    -Look through the script if you want to change some Options :-)


     Version    Date     History
    --------------------------------------------------------------------------
      1.0       270599   First release.
      1.1       010799   Name Changed from HTMLresults.rexx to HTML_results.rexx
                         Changes to work with football v2.4

                250899   Update by Mark. Added error msg to file check.
                110999   Converted to use locale. Some error messages, before
                         reading the locale, will still be in English.

************************************************************************** */
PARSE ARG league_file

htmlpath    = "HTML/"               /* path for your HTML files */
lname       = league_file           /* name for the HTML file taken from league file name */
version     = 1
input_file  = '.sf'
input2_file = '.df'
autosched   = '*AUTOSCHD='
separator   = '*'

if pos("/",league_file) > 0 then
   parse var league_file . "/" lname

lname = strip(lname)
league_file = "Data/"league_file

if open(datafile,"Data/Football.locale",'r') then do
   line = readln(datafile)
   locdir = strip(line)
   close(datafile)
end
else do
   say
   say "ERROR :    (HTML_Results)"
   say
   say "Cannot read 'Data/Football.locale' for the locale settings."
   exit
end

locdir = locdir"User/HTML_Results.data"

if open(datafile,"ENV:FootballRXPath",'r') then do
   line = readln(datafile)
   rxdir = strip(line)
   close(datafile)
end
else
   rxdir = "SYS:Rexxc/"

if exists(locdir) > 0 then do
  address command rxdir'rx 'locdir
  VarCount = getclip('VarCount')
  do i = 1 to VarCount
    interpret getclip('var.'i)
  end
end
else do
   say
   say "ERROR :    (HTML_Results)"
   say
   say "Cannot find '"locdir"' to read locale settings."
   exit
end

if exists(league_file || input_file) = 0  then do
   say
   say htr_error
   say
   say htr_t1"'"league_file || input_file"'."
   exit
end

if exists(league_file || input2_file) = 0  then do
   say
   say htr_error
   say
   say htr_t1"'"league_file || input2_file"'."
   exit
end

if open(stats,htmlpath||lname||"res.html","w") = 0 then do
   say
   say htr_error
   say
   say htr_t2"'"htmlpath||lname||"res.html'"htr_t4
   exit
end

autos = 0
if open(datafile,league_file || input2_file,'r') then do
   do while ~eof(datafile)
      line = readln(datafile)
      if pos(autosched,line) > 0 then do
         autofile = delstr(line,1,10)
         autos = 1
      end
   end
   close(datafile)
end
else do
   say
   say htr_error
   say
   say htr_t2"'"league_file||input2_file"'"htr_t3
   exit
end

if autos = 0 then do
   say
   say htr_error
   say
   say htr_t5
   say htr_t6
   say htr_t7
   say
   exit
end

if open(datafile,league_file || input_file,'r') then do

/* ------------------------------- HTML options -------------------------------------------- */



cs   =  2                             /* Cellspacing             */
cp   =  2                             /* Cellpadding             */
br   =  1                             /* Border size             */
pb   =  #779977                       /* Page Background colour  */
bg   =  #ccddcc                       /* Table background colour */
tw   =  500                           /* Table width             */
sc   =  #ffffff                       /* Score Background colour */




call writeln(stats,"<HTML>")
call writeln(stats,"")
call writeln(stats,"<!-- Created with HTMLresults.rexx (v1.1) Script for Football -->")
call writeln(stats,"<!--          A football tracking program for the Amiga       -->")
call writeln(stats,"")
call writeln(stats,"<HEAD>")
call writeln(stats,"<TITLE>")
call writeln(stats,lname" results and fixtures")
call writeln(stats,"</TITLE>")
call writeln(stats,"")
call writeln(stats,"<META NAME=""author""      CONTENT=""Kevin Lambert (amiga4000@bizonline.co.uk)"">")
call writeln(stats,"<META NAME=""generator""   CONTENT=""HTML_Results.rexx"">")
call writeln(stats,"")
call writeln(stats,"</HEAD>")
call writeln(stats,"")
call writeln(stats,"<BODY BGCOLOR="""pb""">")
call writeln(stats,"<DIV ALIGN=""center"">")
call writeln(stats,"<TABLE CELLSPACING="""cs""" CELLPADDING="""cp""" BORDER="""br"""BGCOLOR=""#5555ee""WIDTH="""tw""">")
   do while ~eof(datafile)
      line = readln(datafile)
      if pos(separator,line) = 0 then do
         t1 = right(strip(substr(line,1,30)),30,' ')
         teams.i = t1||substr(line,31)                         /* main stuff */
         if words(teams.i)=0 THEN LEAVE
          teams.i=insert("</TD></TR>",teams.i,69)
          teams.i=insert("</TD><TD BGCOLOR="""BG""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",teams.i,39)
          teams.i=insert("</TD><TD BGCOLOR="""SC""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",teams.i,36)
          teams.i=insert("</TD><TD BGCOLOR="""SC""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",teams.i,31)
          teams.i=insert("<TR><TD BGCOLOR="""BG""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",teams.i,0)
          teams.i=space(teams.i,1)
          call writeln(stats,teams.i)
      end

      else do
         if words(line) > 1 then do
            if pos("*Week",line) > 0 then do
               chas = subword(line,2)
                do mm=1 to length(chas)
                  if substr(chas,mm,1) = "0" then
                     chas = overlay(" ",chas,mm,1)
                  else
                     leave
               end
               chas = htr_t8" "strip(chas)
            end
            else
               chas = subword(line,2)
            teams.i = chas
            teams.i=insert("</TH></TR>",teams.i,80)                                   /*weeks*/
            teams.i=insert("<TR><TH BGCOLOR=""#ee5555"" ALIGN=""CENTER"" VALIGN=""MIDDLE"" COLSPAN=""4""WIDTH="""tw""">",teams.i,0)
            teams.i=space(teams.i,1)
            call writeln(stats,teams.i)
            uline = ''
            do i=1 to length(chas)
               uline = insert('-',uline,i,1)
            end
         end
      end
   end
   call writeln(stats,"</TABLE><BR>")
   call writeln(stats,"<small>Created using HTML_Results.rexx script for Football 1999</small>")
   call writeln(stats,"</DIV></BODY>")
   call writeln(stats,"</HTML>")
   close(datafile)
   say
   say center(htr_t9,78)
   say"-------------------------------------------------------------------------------------------"
   say
   say"           "htr_t10
   htr_ul = ""
   do ji=1 to length(htr_t10)
      htr_ul = htr_ul"-"
   end
   say"           "htr_ul
   say
   say" HTML_Results "htr_t11":"
   say
   say"  " htmlpath||lname||"res.html"
   say
   say" "htr_t12
   say" "htr_t13
   say" "htr_t14
   say" "htr_t15
   say
   say" "htr_t16":"
   say
   say"      http://www.blue-shantung.demon.co.uk"
   say
   say
   say"-------------------------------------------------------------------------------------------"
end
else do
   say
   say htr_error
   say
   say htr_t2"'"league_file||input_file"'"htr_t3
end

exit