[
 (define title "On the Map")

 ; Inputs x,y are always strings or null, but we want integers
 (define (get-integer str)
   (round (string->number (or (brl-nonblank? str)
                              "0"))))

 ; Validate inputs x, y, descr
 (define-input (get-integer x)
               (get-integer y)
               (brl-nonblank? descr))

 ; Get a JDBC statement object that will be closed automatically
 ; when this page is finished with it.
 (define st (brl-sql-statement brl-context (db1 brl-context)))

 ; If given a new description, try to update.
 (define updates
   (if descr
     (sql-execute-update st
        ]update brlewis_map set descr = [(ss descr)]
where x=[x] and y=[y]
[)
     0))

 ; If there was nothing to update, we need to insert
 (define inserts
   (if (and descr (zero? updates))
     (sql-execute-update st
        ]insert into brlewis_map(x, y, descr)
values([x], [y], [(ss descr)])
[)
     0))

 (define descr-to-show
   (brl-html-escape
     (or descr
         (let ((results (sql-statement-results st
  ]select descr from brlewis_map where x=[x] and y=[y]
[)))
           (if (pair? results)
               (caar results)
               "")))))
]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
<title>[title]</title>
<link rel=stylesheet type="text/css" href="/brl.css">
</head>

<body>

<h1>[title]</h1>

[(if (positive? (+ updates inserts))
     "<p><strong>Description updated.</strong></p>"
     "")]

<p>You are at location ([x], [y]) on the map.
[(brl-when (and (<= -99 x 99)
                (<= -99 y 99))]  You may go
<a rel="nofollow" href="map.brl?x=[x]&y=[(+ y 1)]">north</a>,
<a rel="nofollow" href="map.brl?x=[x]&y=[(- y 1)]">south</a>,
<a rel="nofollow" href="map.brl?x=[(+ x 1)]&y=[y]">east</a>, or
<a rel="nofollow" href="map.brl?x=[(- x 1)]&y=[y]">west</a>.</p>
[)]

<form action="map.brl" method="POST">
<input type="hidden" name="x" value="[x]">
<input type="hidden" name="y" value="[y]">

<table class="example"><tr><td>
<p>Here is what you see:</p>
<textarea name="descr" cols=50 rows=5>[descr-to-show]</textarea>
<input type="submit" value="Update">
</td></tr></table>
</form>

<a href="[(brl-source-link brl-context)]">Show Source</a>

</body>
</html>