koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/misc mailinglist.pl mailinglist.tmpl [dev_week]


From: Kyle Hall
Subject: [Koha-cvs] koha/misc mailinglist.pl mailinglist.tmpl [dev_week]
Date: Thu, 26 Apr 2007 15:24:37 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Kyle Hall <kylemhall>   07/04/26 15:24:37

Added files:
        misc           : mailinglist.pl mailinglist.tmpl 

Log message:
        Script to mail users new items weekly using the ClubsAndServices 
Archetype 'New Items E-mail List'

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/misc/mailinglist.pl?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/mailinglist.tmpl?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1

Patches:
Index: mailinglist.pl
===================================================================
RCS file: mailinglist.pl
diff -N mailinglist.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ mailinglist.pl      26 Apr 2007 15:24:37 -0000      1.1.2.1
@@ -0,0 +1,139 @@
+#!/usr/bin/perl -w
+#-----------------------------------
+# Author:  Kyle Hall (address@hidden)
+# Description: This script generates e-mails
+# sent to subscribers of e-mail lists from
+# the New Items E-mail List archetype
+# in the ClubsAndServices module
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+# DOCUMENTATION
+# This script utilizes the 'New Items E-mail List' archetype
+# from the ClubsAndServices.pm module.
+# If you do not have this archtype, create an archetype of that name
+# with club/service data 1 as Itemtype, and clab/service data 2 as Callnumber.
+# No other data is needed.
+
+# The script grabs all new items with the given itemtype and callnumber.
+# When creating lists to use this script, use % as a wildcard.
+# If all your science fiction books are of itemtype FIC and have a callnumber
+# beginning with 'FIC SF', then you would create a service based on this
+# Archetype and input 'FIC' as the Itemtype, and 'FIC SF%' as the Callnumber.
+
+# The e-mails are based on the included HTML::Template file mailinglist.tmpl
+# If you would like to modify the style of the e-mail, just alter that file.
+
+my $debug = 0;
+my $fromEmail = 'address@hidden';
+my $opacUrl = 'http://catalog.ccfls.org';
+use strict;
+
+use C4::Context;
+use C4::Date;
+
+use Mail::Sendmail;
+use Getopt::Long;
+use Date::Calc qw(Add_Delta_Days);
+use HTML::Template;
+use Data::Dumper;
+
+
+my $dbh = C4::Context->dbh;
+
+## Step 0: Get the date from last week
+  #Gets localtime on the computer executed on.
+  my ($d, $m, $y) = (localtime)[3,4,5];
+  #Adjust the offset to either a neg or pos number of days.
+  my $offset = -7;
+  #Formats the date and sets the offset to subtract 60 days form the #current 
date. This works with the first line above.
+  my ($y2, $m2, $d2) = Add_Delta_Days($y+1900, $m+1, $d, $offset);
+  #Checks to see if the month is greater than 10.
+  if ($m2<10) {$m2 = "0" . $m2;};
+  #Put in format of mysql date YYYY-MM-DD
+  my $afterDate = $y2 . '-' . $m2 . '-' . $d2;
+  if ( $debug ) { print "Date 7 Days Ago: $afterDate\n"; }
+## Grab the "New Items E-mail List" Archetype
+my $sth = $dbh->prepare("SELECT * FROM clubsAndServicesArchetypes WHERE title 
= 'New Items E-mail List'");
+$sth->execute;
+my $archetype = $sth->fetchrow_hashref();
+
+## Grab all the mailing lists
+$sth = $dbh->prepare("SELECT * FROM clubsAndServices WHERE 
clubsAndServices.casaId = ?");
+$sth->execute( $archetype->{'casaId'} );
+
+## For each mailing list, generate the list of new items, then get the 
subscribers, then mail the list to the subscribers
+while( my $mailingList = $sth->fetchrow_hashref() ) {
+  ## Get the new Items
+  if ( $debug ) { print "###\nWorking On Mailing List: " . 
$mailingList->{'title'} . "\n"; }
+  my $itemtype = $mailingList->{'casData1'};
+  my $callnumber = $mailingList->{'casData2'};
+  ## If either are empty, ignore them with a wildcard
+  if ( ! $itemtype ) { $itemtype = '%'; }
+  if ( ! $callnumber ) { $callnumber = '%'; }
+  
+  my $sth2 = $dbh->prepare("SELECT
+                            biblio.author, 
+                            biblio.title, 
+                            biblio.biblionumber,
+                            biblioitems.isbn, 
+                            items.itemcallnumber
+                            FROM 
+                            items, biblioitems, biblio
+                            WHERE
+                            biblio.biblionumber = biblioitems.biblionumber AND
+                            biblio.biblionumber = items.biblionumber AND
+                            biblioitems.itemtype LIKE ? AND
+                            items.itemcallnumber LIKE ? AND
+                            dateaccessioned > ?");
+  $sth2->execute( $itemtype, $callnumber, $afterDate );
+  my @newItems;
+  while ( my $row = $sth2->fetchrow_hashref ) {
+    $row->{'opacUrl'} = $opacUrl;
+    push( @newItems , $row );
+  }
+print Dumper ( @newItems );
+  $sth2->finish;
+  my $newItems = address@hidden;          
+  my $template = HTML::Template->new( filename => 'mailinglist.tmpl' );
+  $template->param( 
+                    listTitle => $mailingList->{'title'},
+                    newItemsLoop => $newItems,
+                  );
+  my $email = $template->output;
+  
+  ## Get all the members subscribed to this list
+  $sth2 = $dbh->prepare("SELECT * FROM clubsAndServicesEnrollments, borrowers 
+                         WHERE
+                         borrowers.borrowernumber = 
clubsAndServicesEnrollments.borrowernumber AND
+                         clubsAndServicesEnrollments.dateCanceled IS NULL AND
+                         clubsAndServicesEnrollments.casId = ?");
+  $sth2->execute( $mailingList->{'casId'} );
+  while ( my $borrower = $sth2->fetchrow_hashref() ) {
+    if ( $debug ) { print "Borrower Email: " . $borrower->{'emailaddress'} . 
"\n"; }
+    my %mail = (
+      from => $fromEmail,
+      to => $borrower->{'emailaddress'},
+      subject => 'New Items @ Your Library: ' . $mailingList->{'title'},
+      'content-type' => 'text/html; charset="iso-8859-1"',
+      body => $email
+    );
+    
+    sendmail( %mail ) || print "Error: $Mail::Sendmail::error\n";
+  }
+  
+  
+}
\ No newline at end of file

Index: mailinglist.tmpl
===================================================================
RCS file: mailinglist.tmpl
diff -N mailinglist.tmpl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ mailinglist.tmpl    26 Apr 2007 15:24:37 -0000      1.1.2.1
@@ -0,0 +1,35 @@
+<html>
+  <head></head>
+  <body>
+    <table>
+      <h2>New Items @ Your Library!</h2>
+      <h3><!-- TMPL_VAR NAME="listTitle" --></h3>
+<!-- TMPL_LOOP NAME="newItemsLoop" -->
+
+<a href="<!-- TMPL_VAR NAME="opacUrl" -->/cgi-bin/koha/opac-detail.pl?bib=<!-- 
TMPL_VAR NAME="biblionumber" ESCAPE="URL" -->">
+<h2 style="color:#000000;font:bold 15px Verdana, Geneva, Arial, Helvetica, 
sans-serif;border-bottom:3px solid #ffcc33">
+  <!-- TMPL_VAR NAME="title" -->
+</h2>
+</a>
+<table border="0" cellpadding="2" cellspacing="0" width="92%" align="center">
+  <tr>
+    <td valign="top">
+      <a href="<!-- TMPL_VAR NAME="opacUrl" 
-->/cgi-bin/koha/opac-detail.pl?bib=<!-- TMPL_VAR NAME="biblionumber" 
ESCAPE="URL" -->"><img src="<!-- TMPL_IF NAME="isbn" 
-->http://images.amazon.com/images/P/<!-- TMPL_VAR name="isbn" 
-->.01.TZZZZZZZ.jpg<!-- TMPL_ELSE 
-->http://g-images.amazon.com/images/G/01/x-site/icons/no-img-sm.gif<!-- 
/TMPL_IF -->" alt="" class="thumbnail" /></a>
+    </td>
+    <td valign="top">
+      <p style="color:#000000">
+        <ul>
+          <li>Author: <!-- TMPL_VAR NAME="author" --></li>
+          <li>ISBN: <!-- TMPL_VAR NAME="isbn" --></li>
+          <li>Call Number: <!-- TMPL_VAR NAME="itemcallnumber" --></li>
+        </ul>
+        <br>
+      </p>
+    </td>
+  </tr>
+</table>
+<!-- /TMPL_LOOP -->
+
+
+  </body>
+</html>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]