Bug? Intermittent situation with CGI program
Sadhunathan Nadesan
sadhu at castandcrew.com
Mon Jul 15 16:59:00 EDT 2002
Promised 3rd mail follow up.
3. back end cgi
...................cut here....................
#!/usr/local/bin/mc
#*************************************************************************
#
# -=< Web Stuff >=-
#
# Program name: test_approve.mt
# Version number: 1.0
# Author: SN
# Date: 04/09/02
# Description: Process Foobar Invoice Approval form messages
#
#*************************************************************************
on startup
global formdata, keywords, the_message
put "youraddress at yourcompany.com " into recipient_string
if ($REQUEST_METHOD = "POST") then
read from stdin for $CONTENT_LENGTH
# Collect the information from the form
put it into url "file:/tmp/it2.txt"
else
put "echo 'get' " into command_string
put "| /usr/psl/bin/mimemail -s " after command_string
put "'Unhandled get in script' recipient_string" after command_string
set shellCommand to "/bin/sh"
put shell(command_string)
end if
# Our user's Outlook sends extra null data, prevent acting on it
if (length(it) < 10) then
put "echo 'got blank' " into command_string
put "| /usr/psl/bin/mimemail -s " after command_string
put "'Our user Blank' recipient_string" after command_string
set shellCommand to "/bin/sh"
put shell(command_string)
show_bad_get
# if actual data is received, then act
else
put urlDecode (it) into formdata
put formdata into url "file:/tmp/formdata2.txt"
put "/usr/psl/bin/newcopy /tmp/formdata2.txt" into command_string
set shellCommand to "/bin/sh"
put shell(command_string)
split formdata by "&" and "="
put keys(formdata) into keywords
sort keywords
put formdata["email_address"] after recipient_string
# format the response as html
put empty into the_message
write_web_response
boiler
put the_message into url "file:/tmp/commdata2.txt"
put "/usr/psl/bin/newcopy /tmp/commdata2.txt" into command_string
set shellCommand to "/bin/sh"
put shell(command_string)
# Email the form contents to the user
put "/usr/psl/bin/mimemail \" & cr into command_string
put "-a /tmp/boiler2.txt -t text/plain \" & cr after command_string
put "-a /tmp/commdata2.txt -t text/html \" & cr after command_string
put "-H -x \" & cr after command_string
put "-r yourname at yourcompany.com \" & cr after command_string
put "-f yourname at yourcompany.com \" & cr after command_string
put "-s 'SUBJECT' \" & cr after command_string
put recipient_string & cr after command_string
replace "SUBJECT" with formdata["subject"] in command_string
set shellCommand to "/bin/sh"
put shell(command_string)
put command_string into url "file:/tmp/command2.txt"
# Playback form contents to the user
# Our user says, turn this off please
# sorry, no can do
show_response
end if
end startup
on write_web_response
global formdata, keywords, the_message
put "<html>" & cr into the_message
put "<body bgcolor='white' text='black'>" & cr after the_message
put "<center>" & cr after the_message
put "<h2>" & cr after the_message
put "INVOICE APPROVAL CONFIRMATION" & cr after the_message
put "<br>" & cr after the_message
put "Sent by Chloe Productions" & cr after the_message
put "<br>" & cr after the_message
put "</h2>" & cr after the_message
put "<br>" & cr after the_message
put "</center>" & cr after the_message
put "<br>" & cr after the_message
put "<br>" & cr after the_message
put "<h5>" & cr after the_message
put "<table BGCOLOR='#EFEDC5' BORDER=1 CELLPADDING=4 ALIGN=CENTER>" & cr after the_message
put "<th align=center>" & cr after the_message
put "Approved?" & cr after the_message
put "</th>" & cr after the_message
put "<th align=center>" & cr after the_message
put "Inv #" & cr after the_message
put "</th>" & cr after the_message
put "<th align=center>" & cr after the_message
put "Inv Amount" & cr after the_message
put "</th>" & cr after the_message
put "<th align=center>" & cr after the_message
put "Paymaster" & cr after the_message
put "</th>" & cr after the_message
put "<th align=center>" & cr after the_message
put "Who Sends" & cr after the_message
put "</th>" & cr after the_message
put "</h5>" & cr after the_message
repeat for each line this_item in keywords
if (formdata[this_item] = "Yes" or formdata[this_item] = "No") then
put "<tr>" & cr after the_message
# Need this false tag so program knows which invoices are approved.
if (formdata[this_item] = "Yes") then
put "<approved_inv invoice=" after the_message
put this_item after the_message
put "></approved_inv>" after the_message
end if
put "<td>" & cr after the_message
put "<b>" & cr after the_message
put formdata[this_item] & cr after the_message
put "</b>" & cr after the_message
put "</td>" & cr after the_message
# Strip out spaces.
replace " " with "" in this_item
put "<td>" & cr after the_message
put "<b>" & cr after the_message
put this_item & cr after the_message
put "</b>" & cr after the_message
put "</td>" & cr after the_message
put "inv_total_" into label_string
put this_item after label_string
put "<td>" & cr after the_message
put formdata[label_string] & cr after the_message
put "</td>" & cr after the_message
put "entered_by_" into label_string
put this_item after label_string
put "<td>" & cr after the_message
put formdata[label_string] & cr after the_message
put "</td>" & cr after the_message
put "who_sends_" into label_string
put this_item after label_string
put "<td>" & cr after the_message
put formdata[label_string] & cr & cr after the_message
put "</td>" & cr after the_message
#put "<td align=center>" & cr after the_message
#put formdata["invoice_memo"] & cr after the_message
#put "</td>" & cr after the_message
put "</tr>" & cr after the_message
end if
end repeat
put "</table>" & cr after the_message
put "<br><hr><br>" & cr after the_message
put "<h5>" & cr after the_message
put "Comments:" & cr after the_message
put "</h5>" & cr after the_message
put "<p>" & cr after the_message
put formdata["Notes"] & cr after the_message
put "</html>" & cr after the_message
put "</body>" & cr after the_message
end write_web_response
on boiler
put "'This is an HTML-formatted message which your mail'" & cr into boiled
put "' client cannot properly display.'" & cr after boiled
put cr && cr after boiled
put boiled into url "file:/tmp/boiler2.txt"
end boiler
on show_response
put "Content-Type: text/html" & cr & cr
put "<html>" & cr
put "<body bgcolor='pink' text='blue'>" & cr
put "<br>" & cr
put "<br>" & cr
put "<br>" & cr
put "<center>" & cr
put "<img src='http://sdwebdev.bogus.com/intro_logo.jpg'>"
put "<hr><h2>" & cr
put "<br>" & cr
put "Thank you for using the Cast & Crew Invoice Approval program." & cr
put "<br>" & cr
put "<br>" & cr
put "<hr></h2>" & cr
put "</html>" & cr
put "</body>" & cr
end show_response
on show_bad_get
put "Content-Type: text/html" & cr & cr
put "<html>" & cr
put "<body bgcolor='blue' text='pink'>" & cr
put "<br>" & cr
put "<br>" & cr
put "<br>" & cr
put "<center>" & cr
put "<img src='http://sdwebdev.bogus.com/intro_logo.jpg'>"
put "<hr><h2>" & cr
put "<br>" & cr
put "There was an extra get command from your Outlook email client" & cr
put "Please contact your consultant to have it re-configured. " & cr
put "<br>" & cr
put "<br>" & cr
put "<hr></h2>" & cr
put "</html>" & cr
put "</body>" & cr
end show_bad_get
...................cut here....................
More information about the metacard
mailing list