#!mc # This Metatalk script digests a survey form posted from the MetaCard # stack survey.mc, saves the raw data and digested data to files # on the server, and returns a report to the MetaCard stack. on startup if $REQUEST_METHOD is "POST" then # read all the data from HTTP server read from stdin until empty # save a copy of it with info about the poster put $REMOTE_ADDR && $REMOTE_HOST & return & it\ after url "file:rawdata.txt" # read in the last report from file in the current directory put url "file:scores.txt" into scores put line 1 of scores into nscores delete line 1 of scores put line 1 of it into nquestions delete line 1 of it set the numberformat to "0.00" # recompute the averages for each question, and save off comments repeat with i = 1 to nquestions put (line i of scores * nscores + item 1 of line i of it)\ / (nscores + 1) into line i of scores delete item 1 of line i of it if line i of it is not empty then put "q" & i && line i of it & return after url "file:qcomments.txt" end repeat # handle multi-line comment at end of input data get line nquestions + 1 to the number of lines in it of it if it is not empty then put it & return after url "file:comments.txt" # save a copy of the current report put nscores + 1 & cr & scores into url "file:scores.txt" put scores into buffer put buffer into url "file:report.txt" else put url "file:report.txt" into buffer # write out the minimal set of HTTP protocol headers (to stdout) put "Content-Type: text/plain" & cr put "Content-Length:" && the length of buffer & cr & cr # write out the report itself put buffer end startup