chiark / gitweb /
edit create
[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 <html lang="en"><head>
43 <title>Editing - <% $tx->{'desc'} |h %> - Email away message setup</title>
44 </head><body>
45 <h1>Edit "<% $tx->{'desc'} |h %>"</h1>
46 <form action="save" method="post">
47 <&| txtable, tx => $tx, inputs => 1 &>
48 <tr><td colspan=2><textarea cols=79 rows=15><%
49   $tx->{'text'} |h %></textarea></td></tr>
50 </&>
51
52 <input type="submit" name="t<% $tx->{'textid'} %>" value="Save">