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