chiark / gitweb /
96124131d93a83a3e464d4c9c702650882cad3b2
[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 my $usedq = $dbh->prepare(<<END);
41     SELECT *
42      FROM        config
43        LEFT JOIN addresses USING (emailaddr)
44        LEFT JOIN texts     USING (textid)
45      ORDER BY emailaddr
46 END
47 $usedq->execute();
48
49 if (!$tx) { die "no such text $textid"; }
50
51 </%perl>
52 <& htmlhead, subpage => "Edit \"$tx->{'desc'}\"" &>
53 <form action="save" method="post">
54 <&| txtable, tx => $tx, inputs => 1 &>
55 <tr><td colspan=2><textarea name="text" cols="79" rows="15"><%
56   $tx->{'text'} |h %></textarea></td></tr>
57 </&>
58 </table><table>
59 % while (my $row = $usedq->fetchrow_hashref()) {
60 <tr><td>Use for <% $row->{'emailaddr'} |h %></td>
61 <td><input type="checkbox" value="1" name=u_<% hquote($row->{'emailaddr'}) %>
62 %     if (!$create && $row->{'textid'} eq $textid) {
63  checked></td><td>(currently using this message)
64 %     } elsif (defined $row->{'textid'}) {
65  ></td><td>(currently using another message "<% $row->{'desc'} |h %>")
66 %     } else {
67  >
68 %     }
69 </td></tr>
70 % }
71 </table><p>
72 <input type="hidden" name="textid" value="<% $tx->{'textid'} %>">
73 <input type="submit" name="save" value="Save">
74 <input type="submit" name="cancel" value="Cancel edit">