4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
27 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
29 # set the version for version checking
34 C4::Letters - Give functions for Letters management
42 "Letters" is the tool used in Koha to manage informations sent to the patrons and/or the library. This include some cron jobs like
43 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)
45 Letters are managed through "alerts" sent by Koha on some events. All "alert" related functions are in this module too.
50 @EXPORT = qw(&GetLetterList &addalert &getalert &delalert &findrelatedto);
54 parameter : $module : the name of the module
55 This sub returns an array of hashes with all letters from a given module
56 Each hash entry contains :
57 - module : the module name
58 - code : the code of the letter, char(20)
59 - name : the complete name of the letter, char(200)
60 - title : the title that will be used as "subject" in mails, char(200)
61 - 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
67 my $dbh = C4::Context->dbh;
68 my $sth = $dbh->prepare("select * from letter where module=?");
69 $sth->execute($module);
71 while (my $line = $sth->fetchrow_hashref) {
80 - $borrowernumber : the number of the borrower subscribing to the alert
81 - $type : the type of alert.
82 - externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
84 create an alert and return the alertid (primary key)
89 my ($borrowernumber,$type,$externalid) = @_;
90 my $dbh=C4::Context->dbh;
91 my $sth = $dbh->prepare("insert into alert (borrowernumber, type, externalid) values (?,?,?)");
92 $sth->execute($borrowernumber,$type,$externalid);
93 # get the alert number newly created and return it
94 my $alertid = $dbh->{'mysql_insertid'};
100 - alertid : the alert id
106 # warn "ALERTID : $alertid";
107 my $dbh = C4::Context->dbh;
108 my $sth = $dbh->prepare("delete from alert where alertid=?");
109 $sth->execute($alertid);
115 - $borrowernumber : the number of the borrower subscribing to the alert
116 - $type : the type of alert.
117 - externalid : the primary key of the object to put alert on. For issues, the alert is made on subscriptionid.
118 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.
123 my ($borrowernumber,$type,$externalid) = @_;
124 my $dbh=C4::Context->dbh;
125 my $query = "select * from alert where";
127 if ($borrowernumber) {
128 $query .= " borrowernumber=? and";
129 push @bind,$borrowernumber;
132 $query .= " type=? and";
136 $query .= " externalid=? and";
137 push @bind,$externalid;
141 my $sth = $dbh->prepare($query);
142 $sth->execute(@bind);
144 while (my $line = $sth->fetchrow_hashref) {
147 return \@result if $#result >=0; # return only if there is one result.
152 - $type : the type of alert
153 - $externalid : the id of the "object" to query
155 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.
156 When type=issue, the id is related to a subscriptionid and this sub returns the name of the biblio.
157 When type=virtual, the id is related to a virtual shelf and this sub returns the name of the sub
160 my ($type,$externalid) = @_;
161 my $dbh=C4::Context->dbh;
163 if ($type eq "issue") {
164 $sth=$dbh->prepare("select title as result from subscription left join biblio on subscription.biblionumber=biblio.biblionumber where subscriptionid=?");
166 $sth->execute($externalid);
167 my ($result) = $sth->fetchrow;
171 END { } # module clean-up code here (global destructor)