#! /bin/sh

string=? ; PLTHOME=/usr/local/lib/plt/100 exec /usr/local/lib/plt/100/bin/mzscheme -q -r "$0"

(current-library-collection-paths (cons "/home/ptg/extras" (current-library-collection-paths)))

(print-struct #t)

(error-display-handler
  (lambda (exn) (output-xexpr `(html (head (title "Error")) (body ,(format "~a" exn))))))

;; output-xexpr : Xexpression -> Void
(define (output-xexpr x)
  (printf "Content-type: text/html~n~n")
  (write-xml/content (xexpr->xml x))
  (newline))

(define maintainer "cork@cs.rice.edu")
(define to '("dxnguyen@cs.rice.edu"))

(require-library "cgi.ss" "net")
(require-library "smtp.ss" "net")
(require-library "head.ss" "net")
(require-library "xml.ss" "xml")

(define bindings (get-bindings))

(define name (extract-binding/single 'name bindings))
(define address-email (extract-binding/single 'address-email bindings))
(define home-phone (extract-binding/single 'home-phone bindings))
(define work-phone (extract-binding/single 'work-phone bindings))
(define exper (extract-binding/single 'exper bindings))

(define mail-server "128.42.1.30")

;(when (ormap (lambda (s) (zero? (string-length s)))
              ;(list concepts-comments concepts-clear concepts-unclear comfy-write comfy-write-comments other-comments))
  ;(output-xexpr `(html (head (title "Oops!"))
                       ;(body ((bgcolor "white"))
                             ;(p "Please fill out all required fields before submitting the form."))))
  ;(exit))

(smtp-send-message mail-server
                   maintainer
                   to
                   (standard-message-header maintainer to null null "Applying for TeachJava 2001 Workhop")
                   (list "Hi, Dung."
                         "Here's a TeachJava application from the web:"
                         ""
                         (format "Name: ~a" name)
                         (format "Email Address: ~a" address-email)
                         (format "Home Phone: ~a" home-phone)
                         (format "Work Phone: ~a" work-phone)
                         (format "Experience: ~a" exper)))

(output-xexpr `(html (head (title "Request processed"))
                     (body ((bgcolor "white"))
                           (p "Your request has been forwarded to Zung Nguyen at Rice (" ,@to ")."))))
