structdoc.php: Generate HTML document from a structured document stored in a Socrata table

structdoc.php is a PHP program to display a structured document stored in a Socrata table

Parameters:
  A SODA API URL: https://data.smcgov.org/resource/skc5-dd9k.json
  The UID of the stored structured document.
    Typically: "filename.pdf:timestamp"
  The OID of the section you want to render
    Rendering OID 0 will render the entire document
    Rendering other OIDs, 1.2.3..., will render that section
      Default: render all sections
  Render flags: TBD

Data Flow:
Make API query of document:0 to validate document
Make API query of document:$OID to retrieve matching rows

Parse Row() {
// Order of parsing is important: table headers/titles before table rows
Case:
  // Meta data
  DocName:
  Meta:
    Title:
    Owner:
    Creator:
    CreateTime:
    ModTime:
    DataSrc:
    DaraCmd:

  // Content data (text)
  Header:
  Paragr:

  //Ref data, tables of numbers/lists and URLs
  RefData:
    RefTitle:
  RefList:
    RefTitle:
    ListRow:
  RefTable:
    RefTitle:
    Schema:
    ColTitle:
    TableRow:

// Support functions
// metadata generates  code, null arg prints all elements
metadata(elements)
// markup rewrites with opening a closing tags, text
markup(markup_element)
// href rewrites with text
href(URL,Text)
// writes a list of data items as a table row:
//   data1data2,
tblrow(type,e1,e2,e3,...) // type=th or tr

errorhandler

main {
  Initialize
  Input OID
  Check document:0
    Store title
  StoreCVSasArray(Query OID)
  Generate top
    Doctype 1st line
    Generate 
    Stop at first non "0." OID
  Generate body
    Html generator
  Generate tail
}


=============================================
Enhancements
discover all documents in structured document dataset
search for Ref elements
search for Title/Header/Ref elements for simple TOC
generate without Ref elements with note of missing element
Turn the program into an API
  structdoc.php?doc=file.pdf&oid=&options=opts
export tables as stand alone CSV tables