#!/usr/bin/rexx
/* -------------------------------------------------------------------------- */
/* REXX script SAMPLE for evaluation of WEB server's guest                  - */
/* -------------------------------------------------------------------------- */
srv_name =  value('SERVER_NAME',, environment)  /* Get the name of the server */
ret_data =  value('QUERY_STRING',, environment)  /* Get the data returned     */
client_addr =  value('REMOTE_ADDR',, environment)  /* Get the remote address  */

parm = .parmdir~new(ret_data)          /* create parameter directory         */

say "Content-type: text/html"
say
say "<html>"
say '<body bgcolor="#ffffff">'

/* My standard header ------------------------------------------------------- */
say "<table width='70%'><tr>",
    "<td><img src=/orexx.gif align=top>",
    "<td><p align="center"><font size=+2 color=#008000><b>CGI powered by Object REXX</b></font>",
    "<br><font size=+1 color=#808080><b>The Scripting Language</b></font>",
    "</table>"
say "<head> <title> Evaluation of Object REXX WEB page guests</title> </head>",
    "<h1> Evaluation of comment about Object REXX on server '"srv_name"': </h1>",
    "<br> <b>Date:</b> "date()"; <b>Time:</b> "time()

/* Show the environment variables for debugging ----------------------------- */
if parm['debug'] = 'env' then
  do
    'set | rxqueue'
    i = 0;
    do queued()
      i = i + 1;
      parse pull listenv.i;
    end
    listenv.0 = i;
    say "<ul>"
    do i = 1 to listenv.0
      a = listenv.i
      a = a~changestr("<","&lt;")       /* Change special characters to mask  */
      a = a~changestr(">","&gt;")
      parse var a key"="value
      if a <> "" then
        say '<li> <font color="#0000ff">'key'</font> <font size=5>=</font>',
            '<font color="#ff0000">'value'</font></li>'
    end
    say "</ul><p>"
end

/* Get values of returned parameters ---------------------------------------- */
if (parm['text'] <> '+') & (parm['text'] <> '' ) then
  do
    ptext = parm['text']
    ptitle = parm['title']
    pfname = parm['fname']
    psname = parm['sname']
    pemaddr = parm['emaddr']
    puserx = parm['userx']
    purx = parm['urx1']
    purx = purx||parm['urx2']
    purx = purx||parm['urx3']
    purx = purx||parm['urx4']
    purx = purx||parm['urx5']
    purx = purx||parm['urx6']
    purx = purx||parm['urx7']

/* Store the parameters into file ------------------------------------------- */
    headline = '0'
    vbook = .stream~new("/home/nobody/vbook.txt")
    vbook~open
    headline = vbook~linein(1,1)
    parse var headline "ENDCNT=" pcnt rest
    if pcnt = "" then 
     do
       vbook~lineout("ENDCNT= 0")
       vbook~lineout(" ")
       pcnt = 0 
    end
    pcnt = pcnt + 1
    vbook~lineout("CNT= "pcnt" DATE= "date('O')"@"time()" FROM= "client_addr)
    vbook~lineout("TITEL= "ptitle" FNAM= "pfname" SNAM= "psname)
    vbook~lineout("E-MAIL= "pemaddr)
    vbook~lineout("RXUSE= "puserx" "purx)
    ptext = ptext~changestr("+"," ")    /* Change special characters to mask  */
    vbook~lineout("TEXT= "ptext)
    vbook~lineout("END*===============================")
    vbook~lineout("ENDCNT= "pcnt,1)
    vbook~close

    /* Display the message for data has been received ----------------------- */
    say "<br>"
    if (ptitle <> '') & (psname <> '') then
      say '<p>  Hello, 'ptitle' 'psname'!<p>'
    say '<b>The </b>',
        '<img align="center" src="/orxok.gif"><b>Team thanks you for your comment :-)</b>'
    dcount = pcnt~right(7,'0')     /* Display the COUNTER ------------------- */
    dispcnt = ""
    do i = 1 to 7
       dispcnt = dispcnt||'<img align="center" src="/'dcount~substr(i,1)||'.gif">'
    end
    say '<p> Your entry has got number:  ',
        dispcnt,
        '<p align="center"> If you like to see the entries, click on ',
        '<a  href="http://'srv_name'/orxwww/rxdispVB"> DISPLAY, </a>'
end
else
  do
    /* Display the message for NOD data has been received ------------------- */
    say "<p>",
      '<img align="right" src="/orxok.gif"><b><font color="#ff0000"> No comment has been entered :-(</font></b>',
      '<p> Please go',
      '<a align="center" href="http://'srv_name'/rxguest"> BACK, </a>',
      'if you like to enter a comment.'

end
/* Footing of WEB page ------------------------------------------------------ */
say "<p>",
    "<hr>"

say "</body> </html>"

exit

::requires "myhtml.cls"                /* load myHtml class                  */
