chiark / gitweb /
e887bdb739a78f84caf2bf5cf60f28400c46795f
[nj-awaymsg.git] / mason / edit
1 <%init>
2 use AwayMsg;
3 db_connect();
4 </%init>
5
6 <%args>
7 $create => undef
8 </%args>
9
10 <%perl>
11
12 my $textid;
13
14 if (defined $create) {
15 } else {
16     foreach my $k (keys %ARGS) {
17         if ($k =~ m/^t(\d{0,7})$/) {
18             $textid= $1;
19             last;
20         }
21     }
22     die unless defined $textid;
23 }
24
25 my $tx;
26
27 if ($ARGS{'create'}) {
28     my $date = `date --iso-8601=minutes`; chomp $date or die;
29     $tx = { desc => "Message created $date",
30             subject => "Away from my email",
31             textid => "new",
32             text => "" };
33 } else {
34     my $sth = $dbh->prepare("SELECT * FROM texts WHERE textid=?");
35     $sth->execute($textid);
36     $tx = $sth->fetchrow_hashref();#
37 }
38
39 if (!$tx) { die "no such text $textid"; }
40
41 </%perl>
42 <& htmlhead, subpage => "Edit \"$tx->{'desc'}\"" &>
43 <form action="save" method="post">
44 <&| txtable, tx => $tx, inputs => 1 &>
45 <tr><td colspan=2><textarea cols=79 rows=15><%
46   $tx->{'text'} |h %></textarea></td></tr>
47 </&>
48 <input type="hidden" name="textid" value="<% $tx->{'textid'} %>">
49 <input type="submit" name="save" value="Save">
50 <input type="submit" name="cancel" value="Cancel edit">