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

    HTML_Played.rexx for THE FOOTBALL REXX SUITE
    -----------------------------------------------------------
     by Mark Naughton, modelled on HTML_Results by Kevin Lambert.

    -This script will generate an HTML file of results.

    -To use HTML_Played.rexx you can run it by using the 'Run Script' button
     on the Football main panel. Select HTML_Played.rexx from the file
     requester and away you go. A file (????ply.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       121299   First release, modelled on HTML_Results.


************************************************************************** */
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   = '*'
separator2  = '**'
not_played  = '__   __'


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_Played)"
   say
   say "Cannot read 'Data/Football.locale' for the locale settings."
   exit
end

dfordir = locdir"Football.locale_data"
locdir = locdir"User/HTML_Played.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_Played)"
   say
   say "Cannot find '"locdir"' to read locale settings."
   exit
end

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

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

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

if open(stats,htmlpath||lname||"ply.html","w") = 0 then do
   say
   say htp_error
   say
   say fl_canop"'"htmlpath||lname||"res.html'"fl_forwrit
   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 htp_error
   say
   say fl_canop"'"league_file||input2_file"'"fl_foread
   exit
end

if autos = 0 then do
   say
   say htp_error
   say
   say fl_thispro
   say fl_created
   say "Teams6.schd. "fl_proabor
   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 */


date_insert = 0                       /* 0 will write dates for games played, while */
                                      /* 99 will just write matches */

call writeln(stats,"<HTML>")
call writeln(stats,"")
call writeln(stats,"<!-- Created with HTML_Played.rexx (v1.0) 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")
call writeln(stats,"</TITLE>")
call writeln(stats,"")
call writeln(stats,"<META NAME=""author""      CONTENT=""Kevin Lambert & Mark Naughton"">")
call writeln(stats,"<META NAME=""generator""   CONTENT=""HTML_Played.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""">")
/* doub_ln = 0 */
   do while ~eof(datafile)
      line = readln(datafile)
      if pos(separator,line) > 0 then do
         if words(line) > 1 then do
            if date_insert ~= 98 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 = htp_t8" "strip(chas)
               end
               else
                  chas = subword(line,2)
               temp_n = chas
               temp_n=insert("</TH></TR>",temp_n,80)                                   /*weeks*/
               temp_n=insert("<TR><TH BGCOLOR=""#ee5555"" ALIGN=""CENTER"" VALIGN=""MIDDLE"" COLSPAN=""4""WIDTH="""tw""">",temp_n,0)
               temp_n=space(temp_n,1)
               if pos(separator2,line) > 0 then call writeln(stats,temp_n)
               if date_insert = 99 then do
                  date_insert = 98
/*                  doub_ln = 1 */
               end
            end
         end
/*
         else do
            doub_ln = doub_ln + 1
            if dbl = 0 then do
               if doub_ln = 1 then do
                  call writeln(stats,"<TR><TH BGCOLOR=""#ee5555"" ALIGN=""CENTER"" VALIGN=""MIDDLE"" COLSPAN=""4""WIDTH="""tw"""></TR>")
                  dbl = 1
               end
            end
            else
              dbl = 0
            doub_ln = 0
         end
*/
      end
      if pos(separator,line) = 0 & pos(not_played,line) = 0 then do
         t1 = right(strip(substr(line,1,30)),30,' ')
         temp_m = t1||substr(line,31)                         /* main stuff */
         if words(temp_m)=0 THEN LEAVE
         if date_insert = 0 & temp_n ~= "" then do
            call writeln(stats,temp_n)
            temp_n = ""
         end
         temp_m=insert("</TD></TR>",temp_m,69)
         temp_m=insert("</TD><TD BGCOLOR="""BG""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",temp_m,39)
         temp_m=insert("</TD><TD BGCOLOR="""SC""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",temp_m,36)
         temp_m=insert("</TD><TD BGCOLOR="""SC""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",temp_m,31)
         temp_m=insert("<TR><TD BGCOLOR="""BG""" ALIGN=""CENTER"" VALIGN=""MIDDLE"">",temp_m,0)
         temp_m=space(temp_m,1)
         call writeln(stats,temp_m)
      end
   end
   call writeln(stats,"</TABLE><BR>")
   call writeln(stats,"<small>Created using HTML_Played.rexx script for Football 1999</small>")
   call writeln(stats,"</DIV></BODY>")
   call writeln(stats,"</HTML>")
   close(datafile)
   say
   say center(htp_t9,78)
   say"-------------------------------------------------------------------------------------------"
   say
   say"           "htp_t10
   htp_ul = ""
   do ji=1 to length(htp_t10)
      htp_ul = htp_ul"-"
   end
   say"           "htp_ul
   say
   say" HTML_Played "htp_t11":"
   say
   say"  " htmlpath||lname||"ply.html"
   say
   say" "htp_t12
   say" "htp_t13
   say" "htp_t14
   say" "htp_t15
   say
   say" "htp_t16":"
   say
   say"      http://www.blue-shantung.demon.co.uk"
   say
   say
   say"-------------------------------------------------------------------------------------------"
end
else do
   say
   say htp_error
   say
   say fl_canop"'"league_file||input_file"'"fl_foread
end

exit