From df6c6bcada42a98a674df5aa2806122df15ce506 Mon Sep 17 00:00:00 2001 From: tipaul Date: Thu, 4 Aug 2005 08:54:54 +0000 Subject: [PATCH] Letters / alert system, continuing... * adding a package Letters.pm, that manages Letters & alerts. * adding feature : it's now possible to define a "letter" for any subscription created. If a letter is defined, users in OPAC can put an alert on the subscription. When an issue is marked "arrived", all users in the alert will recieve a mail (as defined in the "letter"). This last part (= send the mail) is not yet developped. (Should be done this week) * adding feature : it's now possible to "put to an alert" in OPAC, for any serial subscription. The alert is stored in a new table, called alert. An alert can be put only if the librarian has activated them in subscription (and they activate it just by choosing a "letter" to sent to borrowers on new issues) * adding feature : librarian can see in borrower detail which alerts they have put, and a user can see in opac-detail which alert they have put too. Note that the system should be generic enough to manage any type of alert. I plan to extend it soon to virtual shelves : a borrower will be able to put an alert on a virtual shelf, to be warned when something is changed in the virtual shelf (mail being sent once a day by cron, or manually by the shelf owner. Anyway, a mail won't be sent on every change, users would be spammed by Koha ;-) ) --- C4/Letters.pm | 171 ++++++++++++++++++ admin/letter.pl | 6 +- bull/subscription-add.pl | 15 +- bull/subscription-detail.pl | 10 +- .../default/en/bull/subscription-add.tmpl | 18 +- .../default/en/bull/subscription-detail.tmpl | 17 +- .../default/en/members/moremember.tmpl | 19 ++ .../default/en/parameters/letter.tmpl | 2 +- .../opac-tmpl/css/en/opac-serial-issues.tmpl | 13 ++ koha-tmpl/opac-tmpl/css/en/opac-user.tmpl | 19 ++ members/moremember.pl | 24 ++- opac/opac-serial-issues.pl | 17 +- opac/opac-user.pl | 12 +- 13 files changed, 316 insertions(+), 27 deletions(-) create mode 100644 C4/Letters.pm diff --git a/C4/Letters.pm b/C4/Letters.pm new file mode 100644 index 0000000000..f06002c969 --- /dev/null +++ b/C4/Letters.pm @@ -0,0 +1,171 @@ +package C4::Letters; + + +# Copyright 2000-2002 Katipo Communications +# +# 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 + +use strict; +use C4::Date; +use Date::Manip; +use C4::Suggestions; +require Exporter; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + +# set the version for version checking +$VERSION = 0.01; + +=head1 NAME + +C4::Letters - Give functions for Letters management + +=head1 SYNOPSIS + + use C4::Letters; + +=head1 DESCRIPTION + + "Letters" is the tool used in Koha to manage informations sent to the patrons and/or the library. This include some cron jobs like + late issues, as well as other tasks like sending a mail to users that have subscribed to a "serial issue alert" (= being warned every time a new issue has arrived at the library) + + Letters are managed through "alerts" sent by Koha on some events. All "alert" related functions are in this module too. + +=cut + +@ISA = qw(Exporter); +@EXPORT = qw(&GetLetterList &addalert &getalert &delalert &findrelatedto); + +=head2 GetLetterList + + parameter : $module : the name of the module + This sub returns an array of hashes with all letters from a given module + Each hash entry contains : + - module : the module name + - code : the code of the letter, char(20) + - name : the complete name of the letter, char(200) + - title : the title that will be used as "subject" in mails, char(200) + - content : the content of the letter. Each field to be replaced by a value at runtime is enclosed in << and >>. The fields usually have the same name as in the DB + +=cut + +sub GetLetterList { + my ($module) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select * from letter where module=?"); + $sth->execute($module); + my @result; + while (my $line = $sth->fetchrow_hashref) { + push @result,$line; + } + return @result; +} + +=head2 addalert + + parameters : + - $borrowernumber : the number of the borrower subscribing to the alert + - $type : the type of alert. + - externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid. + + create an alert and return the alertid (primary key) + +=cut + +sub addalert { + my ($borrowernumber,$type,$externalid) = @_; + my $dbh=C4::Context->dbh; + my $sth = $dbh->prepare("insert into alert (borrowernumber, type, externalid) values (?,?,?)"); + $sth->execute($borrowernumber,$type,$externalid); + # get the alert number newly created and return it + my $alertid = $dbh->{'mysql_insertid'}; + return $alertid; +} + +=head2 delalert + parameters : + - alertid : the alert id + deletes the alert +=cut + +sub delalert { + my ($alertid)=@_; +# warn "ALERTID : $alertid"; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("delete from alert where alertid=?"); + $sth->execute($alertid); +} + +=head2 getalert + + parameters : + - $borrowernumber : the number of the borrower subscribing to the alert + - $type : the type of alert. + - externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid. + all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $externalid, returns all alerts for a borrower on a topic. + +=cut + +sub getalert { + my ($borrowernumber,$type,$externalid) = @_; + my $dbh=C4::Context->dbh; + my $query = "select * from alert where"; + my @bind; + if ($borrowernumber) { + $query .= " borrowernumber=? and"; + push @bind,$borrowernumber; + } + if ($type) { + $query .= " type=? and"; + push @bind,$type; + } + if ($externalid) { + $query .= " externalid=? and"; + push @bind,$externalid; + } + $query =~ s/ and$//; +# warn "Q : $query"; + my $sth = $dbh->prepare($query); + $sth->execute(@bind); + my @result; + while (my $line = $sth->fetchrow_hashref) { + push @result,$line; + } + return \@result if $#result >=0; # return only if there is one result. + return; +} +=head2 findrelatedto + parameters : + - $type : the type of alert + - $externalid : the id of the "object" to query + + In the table alert, a "id" is stored in the externalid field. This "id" is related to another table, depending on the type of the alert. + When type=issue, the id is related to a subscriptionid and this sub returns the name of the biblio. + When type=virtual, the id is related to a virtual shelf and this sub returns the name of the sub +=cut +sub findrelatedto { + my ($type,$externalid) = @_; + my $dbh=C4::Context->dbh; + my $sth; + if ($type eq "issue") { + $sth=$dbh->prepare("select title as result from subscription left join biblio on subscription.biblionumber=biblio.biblionumber where subscriptionid=?"); + } + $sth->execute($externalid); + my ($result) = $sth->fetchrow; + return $result; +} + +END { } # module clean-up code here (global destructor) diff --git a/admin/letter.pl b/admin/letter.pl index 7089773b25..1d69bf9d74 100755 --- a/admin/letter.pl +++ b/admin/letter.pl @@ -71,6 +71,7 @@ my $searchfield=$input->param('searchfield'); my $offset=$input->param('offset'); my $script_name="/cgi-bin/koha/admin/letter.pl"; my $code=$input->param('code'); +my $module = $input->param('module'); my $pagesize=20; my $op = $input->param('op'); $searchfield=~ s/\,//g; @@ -100,8 +101,8 @@ if ($op eq 'add_form') { #---- if primkey exists, it's a modify action, so read values to modify... my $letter; if ($code) { - my $sth=$dbh->prepare("select * from letter where code=?"); - $sth->execute($code); + my $sth=$dbh->prepare("select * from letter where module=? and code=?"); + $sth->execute($module,$code); $letter=$sth->fetchrow_hashref; $sth->finish; } @@ -144,6 +145,7 @@ if ($op eq 'add_form') { } $template->param(name => $letter->{name},title => $letter->{title}, content => $letter->{content}, + $letter->{module} => 1, SQLfieldname => \@SQLfieldname,); # END $OP eq ADD_FORM ################## ADD_VALIDATE ################################## diff --git a/bull/subscription-add.pl b/bull/subscription-add.pl index a003171f3a..78ed183cba 100755 --- a/bull/subscription-add.pl +++ b/bull/subscription-add.pl @@ -13,6 +13,7 @@ use C4::Interface::CGI::Output; use C4::Context; use HTML::Template; use C4::Bull; +use C4::Letters; my $query = new CGI; my $op = $query->param('op'); @@ -23,7 +24,7 @@ my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$ $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, $numberingmethod, $status, $biblionumber, - $bibliotitle, $notes); + $bibliotitle, $notes, $letter); my @budgets; my ($template, $loggedinuser, $cookie) @@ -82,6 +83,7 @@ if ($op eq 'mod') { $biblionumber = $subs->{'biblionumber'}; $bibliotitle = $subs->{'bibliotitle'}, $notes = $subs->{'notes'}; + $letter = $subs->{'letter'}; $template->param( $op => 1, user => $auser, @@ -120,6 +122,7 @@ if ($op eq 'mod') { biblionumber => $biblionumber, bibliotitle => $bibliotitle, notes => $notes, + letter => $letter, subscriptionid => $subscriptionid, ); $template->param( @@ -138,6 +141,13 @@ for (my $i=0;$i<=$#budgets;$i++) { $template->param(budgets => \@budgets); #FIXME : END Added by hdl on July, 14 2005 +my @letterlist = GetLetterList('serial'); +for (my $i=0;$i<=$#letterlist;$i++) { + warn "$letterlist[$i]->{'code'} eq ".$letter; + $letterlist[$i]->{'selected'} =1 if $letterlist[$i]->{'code'} eq $letter; +} +$template->param(letters => \@letterlist); + if ($op eq 'addsubscription') { my $auser = $query->param('user'); my $aqbooksellerid = $query->param('aqbooksellerid'); @@ -168,12 +178,13 @@ if ($op eq 'addsubscription') { my $status = 1; my $biblionumber = $query->param('biblionumber'); my $notes = $query->param('notes'); + my $letter = $query->param('letter'); my $subscriptionid = newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, $add1,$every1,$whenmorethan1,$setto1,$lastvalue1, $add2,$every2,$whenmorethan2,$setto2,$lastvalue2, $add3,$every3,$whenmorethan3,$setto3,$lastvalue3, - $numberingmethod, $status, $notes + $numberingmethod, $status, $notes, $letter ); print $query->redirect("/cgi-bin/koha/bull/subscription-detail.pl?subscriptionid=$subscriptionid"); } else { diff --git a/bull/subscription-detail.pl b/bull/subscription-detail.pl index c9bed507e3..b73f6d7f13 100755 --- a/bull/subscription-detail.pl +++ b/bull/subscription-detail.pl @@ -22,7 +22,7 @@ my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$ $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, - $numberingmethod, $status, $biblionumber, $bibliotitle, $notes); + $numberingmethod, $status, $biblionumber, $bibliotitle, $notes,$letter); $subscriptionid = $query->param('subscriptionid'); @@ -60,13 +60,14 @@ if ($op eq 'modsubscription') { $numberingmethod = $query->param('numberingmethod'); $status = 1; $notes = $query->param('notes'); + $letter = $query->param('letter'); &modsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate, $periodicity,$dow,$numberlength,$weeklength,$monthlength, $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, - $numberingmethod, $status, $biblionumber, $notes, $subscriptionid); + $numberingmethod, $status, $biblionumber, $notes, $letter, $subscriptionid); } if ($op eq 'del') { @@ -78,7 +79,6 @@ if ($op eq 'del') { my $subs = &getsubscription($subscriptionid); my ($totalissues,@serialslist) = getserials($subscriptionid); $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue) -# the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...) ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "bull/subscription-detail.tmpl", @@ -89,8 +89,7 @@ $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscript debug => 1, }); -my ($user, $cookie, $sessionID, $flags) - = checkauth($query, 0, {catalogue => 1}, "intranet"); +my ($user, $cookie, $sessionID, $flags) = checkauth($query, 0, {catalogue => 1}, "intranet"); $template->param( user => $subs->{auser}, @@ -129,6 +128,7 @@ $template->param( biblionumber => $subs->{biblionumber}, bibliotitle => $subs->{bibliotitle}, notes => $subs->{notes}, + letter => $subs->{letter}, subscriptionid => $subs->{subscriptionid}, serialslist => \@serialslist, totalissues => $totalissues, diff --git a/koha-tmpl/intranet-tmpl/default/en/bull/subscription-add.tmpl b/koha-tmpl/intranet-tmpl/default/en/bull/subscription-add.tmpl index 2a0be64c18..9194edac5b 100644 --- a/koha-tmpl/intranet-tmpl/default/en/bull/subscription-add.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/bull/subscription-add.tmpl @@ -15,9 +15,21 @@ ">

Librarian

-

" size=4> (" disabled readonly>)...

-

" size=4> (" disabled readonly>)...

-

+

" size=4> (" disabled readonly>)...

+

" size=4> (" disabled readonly>)...

+

+

+ +

warning