chiark / gitweb /
run-mason.cgi: seems to work
[nj-awaymsg.git] / mason / edit
index 7869cc814c4cc6526c0aec599e2efd881d48223a..96124131d93a83a3e464d4c9c702650882cad3b2 100755 (executable)
@@ -1,6 +1,7 @@
 <%init>
 use AwayMsg;
 db_connect();
+www_begin($r,$m);
 </%init>
 
 <%args>
@@ -14,7 +15,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;
        }
@@ -22,21 +23,52 @@ if (defined $create) {
     die unless defined $textid;
 }
 
-my $sth = $dbh->prepare("SELECT * FROM texts WHERE textid=?");
-$sth->execute($textid);
-my $tx = $sth->fetchrow_hashref();#
+my $tx;
+
+if ($ARGS{'create'}) {
+    my $date = `date --iso-8601=minutes`; chomp $date or die;
+    $tx = { desc => "Message created $date",
+           subject => "Away from my email",
+           textid => "new",
+           text => "" };
+} else {
+    my $sth = $dbh->prepare("SELECT * FROM texts WHERE textid=?");
+    $sth->execute($textid);
+    $tx = $sth->fetchrow_hashref();#
+}
+
+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"; }
 
 </%perl>
-<html lang="en"><head>
-<title>Editing - <% $tx->{'desc'} |h %> - Email "out of office" setup</title>
-</head><body>
-<h1>Edit "<% $tx->{'desc'} |h %>"</h1>
+<& htmlhead, subpage => "Edit \"$tx->{'desc'}\"" &>
 <form action="save" method="post">
 <&| txtable, tx => $tx, inputs => 1 &>
-<tr><td>TXTABLE CONTENT</td></tr>
+<tr><td colspan=2><textarea name="text" cols="79" rows="15"><%
+  $tx->{'text'} |h %></textarea></td></tr>
 </&>
-
-<input type="submit" name="t<% $tx->{'textid'} %>"
-   value="Edit or configure this message">
+</table><table>
+% while (my $row = $usedq->fetchrow_hashref()) {
+<tr><td>Use for <% $row->{'emailaddr'} |h %></td>
+<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>
+% }
+</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">