chiark / gitweb /
.gitignore: add data dir
[nj-awaymsg.git] / mason / edit
index c8ee036601ac0f7e578394100f99bb773dc2c215..4456d87489ed9be2532e1793beb706a796c17d9d 100755 (executable)
@@ -3,6 +3,9 @@ use AwayMsg;
 db_connect();
 www_begin($r,$m);
 </%init>
+<%shared>
+our ($cgi,$ar);
+</%shared>
 
 <%args>
 $create => undef
@@ -15,7 +18,7 @@ my $textid;
 if (defined $create) {
 } else {
     foreach my $k (keys %ARGS) {
-       if ($k =~ m/^t(\d{0,7})$/) {
+       if ($k =~ m/^t_(\d{0,7})$/) {
            $textid= $1;
            last;
        }
@@ -37,7 +40,13 @@ if ($ARGS{'create'}) {
     $tx = $sth->fetchrow_hashref();#
 }
 
-my $usedq = $dbh->prepare("SELECT * FROM addresses ORDER BY emailaddr");
+my $usedq = $dbh->prepare(<<END);
+    SELECT *
+     FROM        config
+       LEFT JOIN addresses USING (emailaddr)
+       LEFT JOIN texts     USING (textid)
+     ORDER BY emailaddr
+END
 $usedq->execute();
 
 if (!$tx) { die "no such text $textid"; }
@@ -45,18 +54,25 @@ if (!$tx) { die "no such text $textid"; }
 </%perl>
 <& htmlhead, subpage => "Edit \"$tx->{'desc'}\"" &>
 <form action="save" method="post">
+<% $ar->secret_hidden_html() %>
 <&| txtable, tx => $tx, inputs => 1 &>
 <tr><td colspan=2><textarea name="text" cols="79" rows="15"><%
   $tx->{'text'} |h %></textarea></td></tr>
 </&>
-</table><br><table>
+</table><table>
 % while (my $row = $usedq->fetchrow_hashref()) {
 <tr><td>Use for <% $row->{'emailaddr'} |h %></td>
-<td><input type="checkbox"
-%     if ($usedq->
-></td></tr>
+<td><input type="checkbox" value="1" name=u_<% hquote($row->{'emailaddr'}) %>
+%     if (!$create && $row->{'textid'} eq $textid) {
+ checked></td><td>(currently using this message)
+%     } elsif (defined $row->{'textid'}) {
+ ></td><td>(currently using another message "<% $row->{'desc'} |h %>")
+%     } else {
+ >
+%     }
+</td></tr>
 % }
-<p>
+</table><p>
 <input type="hidden" name="textid" value="<% $tx->{'textid'} %>">
 <input type="submit" name="save" value="Save">
 <input type="submit" name="cancel" value="Cancel edit">