# $Id: contact.html,v 1.7 2005/09/20 16:15:30 feargal Exp $ if {[info exists NeoWebUserConf(version)] && ![info exists _Common_] && [file exists /www/lib/$NeoWebUserConf(version)-Common.tcl]} {source /www/lib/$NeoWebUserConf(version)-Common.tcl} ########################## # Start of configuration # ########################## # TODO allow all this to be set in a config file # The subject of the email which will be send. set _Contact_(subject) "From the $webenv(SERVER_NAME) bookings page" # The default recipient of the email # if there is a -Common.tcl file in the lib directory and # _Common_(contact_email) is set in it, that value will be used, otherwise the # hard-coded value below will be used. if {[info exists _Common_(contact_email)]} { set _Contact_(recipient) $_Common_(contact_email) } { # hardcoded value: set _Contact_(recipient) "no.such.address@domain.invalid" } # TODO use the TableEditor style declarations for this. # All fields which are to be displayed in the email # format is {field_name field_label ... ...} set _Contact_(fields) {name "Name" email "E-Mail" date "Date" time "Times" tel "Telephone" address "Address" company "Company" jobtitle "Jobtitle" postcode "Postcode" country "Country" fax "Fax" comments "Comments"} # Any required fields, again format is {field_name field_label ... ...} set _Contact_(required) {name "Name" email "E-Mail"} # The default address to send emails from set _Contact_(default_sender) automaton@fbi.ie # The page which contains the form (relative to here) set _Contact_(form_page) booking_form.html # The thank-you page (relative to here) set _Contact_(thanks_page) booking_thanks.html # Specify the field that contains the sender's email address if you want the # Reply-To header set. If use_sender_address is set below, this MUST be defined set _Contact_(sender_address) email # If a header file is to be included, set it here, otherwise leave blank # (header file may already be included in the form and thank you pages). #set _Contact_(header) "" # If a footer file is to be included, set it here, otherwise leave blank #set _Contact_(footer) "" # To allow the user to override the default recipient, specify the form field: #set _Contact_(recipient_override) recipient # # Specify the list of addresses which may be selected from: #set _Contact_(recipient_pool) {info@domain.example sales@domain.example} # If the sender address is to be set to the visitor's email address, set this # to 1 # NOTE this is bad practice for now in consideration of SPF and other such # technologies # TODO check the sender's domain for SPF type setups, and if found, override #set _Contact_(use_sender_address) 0 # If mimefiles are to be uploaded, specify a list of their field names here, # otherwise leave this commented out. #set _Contact_(mimefiles) "file" # # The base url to link to the uploaded file, is inserted into the email. #set _Contact_(downloads_url) "$_Common_(site_url)/manage/downloads" # # A block of code to be eval'd after processing each upload - for example, to # move a file from public uploads to elsewhere. #set _Contact_(After_Upload_Block) { #vant_mv_uploads $filename #} ######################## # End of configuration # ######################## if {[info exists _Contact_(header)] && [string length $_Contact_(header)]} { include_virtual $_Contact_(header) } if {[info exists _Contact_(mimefiles)] && [llength $_Contact_(mimefiles)]} { load_mime_response response mimefiles } if {![info exists response] || [llength [array names response]]==0} {load_response response} array set safe [array get response] safetext safe if {![info exists safe(id)] || ![regexp {^[0-9]+$} $safe(id)]} { set safe(id) 0 } op Send { attribute response webenv _Common_ _Contact_ op_err op_nxt mimefiles safe foreach {i j} $_Contact_(required) { if {![info exists response($i)] || [string length $response($i)]==0} { lappend op_err "Missing required field: $j" } } #checking date validity if {[info exists response(day)] && [info exists response(year)] && [info exists response(month)]} { set date "$response(day) $response(month) $response(year)" set res [catch {clock scan $date} out] if {$res == 1} { lappend op_err "Wrong date: $date" } { set response(date) $date } } #checking time validity if {[info exists response(from)] && [info exists response(to)]} { regsub {:00} $response(from) {} from regsub {:00} $response(to) {} to if {$from > $to} { lappend op_err "Wrong time" } if {$from == $to} { lappend op_err "Wrong time" } if {[lempty $op_err]} { set response(time) "$response(from) - $response(to)" } } if {[info exists _Contact_(sender_address)]} { if {[info exists response($_Contact_(sender_address))] && [string length $response($_Contact_(sender_address))] && ![verifyemail $response($_Contact_(sender_address))]} { lappend op_err "Invalid email address: $response($_Contact_(sender_address))" } { set reply_to "$response($_Contact_(sender_address))" } } if {[llength $op_err]==0} { set from $_Contact_(default_sender) # See if we are using a supplied email address # there is no need to call verifyemail as that will be done above. if {[info exists _Contact_(use_sender_address)] && $_Contact_(use_sender_address)==1} { if {[info exists response($_Contact_(sender_address))] && [string length $response($_Contact_(sender_address))]} { set from $response($_Contact_(sender_address)) } } set recipient $_Common_(contact_email) set _Contact_(subject) "$_Contact_(subject)\nReply-To: $reply_to" set m [open_outbound_mail $_Contact_(subject) $recipient $from] foreach {i j} $_Contact_(fields) { if {[info exists response($i)] && [string length $response($i)]} { puts $m "$j: $response($i)" puts $m "" } } set m_res [catch {close $m} m_err] if {$m_res} { lappend op_err [subst { Email not sent, perhaps your email address is incorrect? If not, please report this error to $webenv(SERVER_ADMIN). $m_err $m_res }] } { set op_nxt Thanks } } } set op_res ""; set op_err ""; set op_nxt Form invoke_op response foreach {i j} $_Contact_(fields) { if {![info exists response($i)]} {set response($i) ""} } switch $op_nxt { Form { include_virtual $_Contact_(form_page) } Thanks { include_virtual $_Contact_(thanks_page) } } if {[info exists _Contact_(footer)] && [string length $_Contact_(footer)]} { include_virtual $_Contact_(footer) }