/* htmldict.p
 *
 * HTML dictionary report
 *
 * 01/11/96	tom	created (thanks to Gerry Duprey for the idea)
 * 04/03/96	mjb	changed lots of stuff to automate this.
 * 04/17/96	mjb	put an html link back to the dict.html page at the bottom of every table listing.
 * 08/30/96	bmy	protect against hashes in URL names via encoding
 * 09/24/96	dmk	changed links to use _dump-name.html instead of _file-name.html to match with actual names of link files
 * 02/06/98	tom	adapted to genericize
 * 07/16/03	rgl	corrected links to *.html instead of *.htm
 * 08/01/03	tom	fixed absolute path names & table selection
 *
 * January 11, 1996 */

define variable d_name  as character no-undo.
define variable d_title as character no-undo initial "Data Dictionary".
define variable d_dir   as character no-undo initial "dict".

define variable i as integer no-undo.

output to value( "./" + d_dir + "/dict.html" ).

put unformatted "<html>" skip.
put unformatted "<head>" skip.
put unformatted "<title>" + d_title + "</title><P>" skip.
put unformatted "<head/>" skip.
put unformatted "<body>" skip.
put unformatted "<hr>" skip.
put unformatted "<h1>" + d_title + "</h1>" skip.
put unformatted "<hr>" skip.
put unformatted "<p>" skip.
put unformatted '<table cellpadding="5" cellspacing="0" width="750">' skip.

for each _file no-lock where _file._file-num > 0 and _file._file-num < 10000:

  i = i + 1.
  if i modulo 5 = 1 then put unformatted "<tr>" skip.

  /** replace any # (hashes) with special encoding for URL **/

  d_name = _file._dump-name.
  do while index( d_name, "#" ) > 0:
    substring( d_name, index( d_name, "#" ), 1 ) = "%23".
  end.

  put unformatted '<td><a href=' + d_name + '.html>' + _file._file-name + ' </td>' skip.
  if i modulo 5 = 0 then put unformatted "</tr>" skip.

end.

put unformatted "</table>" skip.
put unformatted "</p>" skip.
put unformatted "<hr>" skip.
put unformatted "<i>Last updated " + string( today, "99/99/9999" ) + " " + string( time, "hh:mm:ss am" ) + "</i>" skip.
put unformatted "</body>" skip.
put unformatted "</html>" skip.

output close.

for each _file no-lock where _file._file-num > 0 and _file._file-num < 10000:

  output to value( "./" + d_dir + "/" + _file._dump-name + ".html" ).

  put unformatted "<html>" skip.
  put unformatted "<head>" skip.
  put unformatted "<title>" + d_title + " -- " + _file._file-name + " </title><P>" skip.
  put unformatted "<head/>" skip.
  put unformatted "<body>" skip.
  put unformatted "<hr>" skip.
  put unformatted "<h2>" + d_title + "</h2>" skip.
  put unformatted "<hr>" skip.
  put unformatted "<h2>" + _file._file-name + "</h2>" skip.
  put unformatted "<p>" + _file._desc + "</p>" skip.
  put unformatted "<hr>" skip.
  put unformatted '<table cellpadding="5" cellspacing="0" width="750">' skip.

  put unformatted "<p>" skip.
  put unformatted "<tr>" skip.
  put unformatted "<th align=left>Field Name</th>" skip.
  put unformatted "<th align=left>Datatype</th>" skip.
  put unformatted "<th align=right>Format</th>" skip.
  put unformatted "<th align=right>Extent</th>" skip.
  put unformatted "<th align=right>Default</th>" skip.
  put unformatted '<th align=left width="50%">Description</th>' skip.
  put unformatted "</tr>" skip.

  for each _field no-lock where _field._file-recid = recid( _file ) by _order:

    put unformatted "<tr>" skip.
    put unformatted "<td>" + _field._field-name + "    </td>" skip.
    put unformatted "<td>" + _field._data-type  + "    </td>" skip.
    put unformatted "<td align=right>" + _field._format     + "    </td>" skip.
    if _field._extent > 0 then put unformatted "<td align=right>" _field._extent "</td>" skip. 
    else
    do:
        put unformatted "<td align=right>1</td>" skip.
    end.
    put unformatted "<td align=right>" + _field._initial + "</td>" skip.
    put unformatted "<td align=left>" + _field._desc + "</td>" skip.
    put unformatted "</tr>" skip.

  end.

  put unformatted "</table>" skip.
  put unformatted "</p>" skip.
  put unformatted "<hr>" skip.
  put unformatted "<p>" skip.

  for each _index no-lock where _index._file-recid = recid( _file ):

    put unformatted "<b>" + _index._index-name + " </b>" skip.
    if _file._prime-index = recid( _index ) then put unformatted "<i>Primary </i>" skip.
    if _index._unique then put unformatted "<i>Unique </i>" skip.

    for each _index-field no-lock where _index-field._index-recid = recid( _index ):
      find _field no-lock where recid( _field ) = _index-field._field-recid.
      put unformatted _field._field-name + " " skip.
    end.

    put unformatted "<br>" skip.

  end.

  put unformatted "</p>" skip.
  put unformatted "<hr>" skip.
  put unformatted "<i>Last updated " + string( today, "99/99/9999" ) + " " + string( time, "hh:mm:ss am" ) + "</i>" skip.
  put unformatted "<p>" skip.
  put unformatted '<td><a href="dict.html"> Return to Listing Of Database Tables </td>' skip.
  put unformatted "</body>" skip.
  put unformatted "</html>" skip.

  output close.

end.

return.

