chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 4 Sep 2012 20:45:57 +0000 (21:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 4 Sep 2012 20:45:57 +0000 (21:45 +0100)
mason/edit
mason/save [new file with mode: 0755]

index 5e60d09..60e8b9e 100755 (executable)
@@ -48,5 +48,6 @@ if (!$tx) { die "no such text $textid"; }
 <tr><td colspan=2><textarea cols=79 rows=15><%
   $tx->{'text'} |h %></textarea></td></tr>
 </&>
-
-<input type="submit" name="t<% $tx->{'textid'} %>" value="Save">
+<input type="hidden" name="textid" value="<% $tx->{'textid'} %>">
+<input type="submit" name="save" value="Save">
+<input type="submit" name="cancel" value="Cancel edit">
diff --git a/mason/save b/mason/save
new file mode 100755 (executable)
index 0000000..30cc47a
--- /dev/null
@@ -0,0 +1,34 @@
+<%init>
+use AwayMsg;
+db_connect();
+</%init>
+<%args>
+$textid
+$save => 0
+$cancel => 0
+$textid => undef
+</%args>
+<%perl>
+if ($save) {
+    my $ins;
+    $dbh->do('BEGIN');
+    if ($textid eq 'new') {
+       my $ntextq = $dbh->prepare("SELECT textid FROM texts".
+                                  " ORDER BY textid DESC LIMIT 1");
+       $ntextq->execute();
+       my $ntextrow = $ntextq->fetchrow_hashref();
+       if ($ntextrow) {
+           $textid = $ntextrow->{'textid'} + 1;
+       } else {
+           $textid = 1;
+       }
+    } else {
+       my $dtextq = $dbh->prepare("DELETE FROM texts WHERE textid = ?");
+       my $ndeleted = $dtextq->execute($textid);
+       if (!$ndeleted) {
+</%perl>
+
+
+       $ins = $dbh->prepare("INSERT INTO texts VALUES (
+      $sth = $dbh->
+}