chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 30 Aug 2012 00:40:36 +0000 (01:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 30 Aug 2012 00:40:36 +0000 (01:40 +0100)
AwayMsg.pm
mason/main
schema

index 483345524ee2dedb1eae5678b601e78e97494b70..d6f63a5b3e42bb96769845f7a57602b4d3d541d4 100644 (file)
@@ -12,7 +12,8 @@ BEGIN {
     our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
-    @EXPORT      = qw(db_connect db_commit expires2timet
+    @EXPORT      = qw(db_connect db_commit
+                      expires2timet expirestime2show
                       $dbh);
     %EXPORT_TAGS = ( );
     @EXPORT_OK   = qw();
@@ -49,7 +50,7 @@ sub nooutput ($) {
 
 sub expires2timet ($) {
     my ($str) = @_;
-    if ($str eq '') {
+    if ($str eq '' or $str =~ m/never/i) {
        return undef;
     }
     open F, "-|", qw(date -d),'$str',qw(+%s) or die $!;
@@ -59,11 +60,20 @@ sub expires2timet ($) {
     return $dtime+0;
 }
 
+sub expirestime2show ($) {
+    my ($tt) = @_;
+    if (!defined $tt) {
+       return 'never';
+    } else {
+       return strftime("%Y-%m-%d %H:%M");
+    }
+}
+
 sub db_commit () {
     nooutput("SELECT * FROM addresses LEFT JOIN config".
             " USING (emailaddr) WHERE forwardfile IS NULL");
     nooutput("SELECT * FROM addresses LEFT JOIN texts".
-            " USING (textid) WHERE name IS NULL");
+            " USING (textid) WHERE desc IS NULL");
     $dbh->do("COMMIT");
 }
 
index 5997c3af035faf164ad6dc953b3a72ce68143101..e8c29e6fd7c864ec49941a2fc02e56d33ad10162 100755 (executable)
@@ -1,25 +1,24 @@
 <%init>
 use AwayMsg;
 db_connect();
+my ($sth,$row,$sthi,$rowi);
 </%init>
 <html lang="en"><head>
 <title>Email "out of office" setup</title>
 </head><body>
 <h1>Email "out of office" setup</h1>
-<h2>Email addresses and their configuration</h2>
-
 
+<h2>Email addresses and their configuration</h2>
 <%perl>
-my %row;
-my $sth = $dbh->prepare(<<END);
+$sth = $dbh->prepare(<<END);
     SELECT *
      FROM        addresses
        LEFT JOIN config    USING (emailaddr)
        LEFT JOIN texts     USING (textid)
      ORDER BY emailaddr
 END
+$sth->execute();
 </%perl>
-
 <table rules="all">
 <tr>
 <td>Address</td>
@@ -27,7 +26,6 @@ END
 <td>Which message?</td>
 <td>Expiry date</td>
 </tr><tr>
-% $sth->execute();
 % while (my $row= $sth->fetchrow_hashref()) {
 <tr>
 <td><% $row->{'emailaddr'} |h %></td>
@@ -38,12 +36,8 @@ END
 %         } else {
 <td>active</td>
 %         }
-<td><% $row->{'name'} |h %></td>
-%         if (defined $expires) {
-<td><% $row->{'expires'} |h %></td>
-%         } else {
-<td>never</td>
-%         }
+<td><% $row->{'desc'} |h %></td>
+<td><% expirestime2show($expires) |h %></td>
 %     } else {
 <td>inactive</td>
 <td></td>
@@ -52,3 +46,29 @@ END
 </tr>
 % }
 </table>
+
+<h2>Outbound messages</h2>
+<%perl>
+$sth = $dbh->prepare("SELECT * FROM texts ORDER BY desc");
+$sthi = $dbh->prepare(<<END);
+    SELECT * FROM addresses
+     WHERE textid = ?
+     ORDER BY emailaddr
+END
+$sth->execute();
+</%perl>
+% while (my $row= $sth->fetchrow_hashref()) {
+<h3>Message "<% $row->{'desc'} |h %>"</h3>
+<table>
+<tr><td>Short name:</td><td><% $row->{'desc'} |h %></td></tr>
+<tr><td>Expires:</td><td><%
+  expirestime2show(expires2timet($row->{'expires'}))
+                                              |h %></td></tr>
+<tr><td>Subject:</td>
+  <td><code><% $row->{'subject'} |h %></code></td></tr>
+</table>
+<p>
+<pre>
+<% $row->{'text'} |h %>
+</pre>
+% }
diff --git a/schema b/schema
index aaeb0d92ba72d3052db2288334dfe3b3c4bd2ae0..afcda2980a4158e998ee58013620a6e33a525e53 100644 (file)
--- a/schema
+++ b/schema
@@ -1,7 +1,7 @@
 
 CREATE TABLE texts (
        textid          INTEGER PRIMARY KEY NOT NULL,
-       name            TEXT NOT NULL,
+       desc            TEXT NOT NULL,
        subject         TEXT NOT NULL,
        text            TEXT NOT NULL,
        expires         TEXT NOT NULL