Koha/opac/opac-user.pl
tipaul df6c6bcada 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 ;-) )
2005-08-04 08:54:54 +00:00

156 lines
4.3 KiB
Perl
Executable file

#!/usr/bin/perl
use strict;
require Exporter;
use CGI;
use C4::Auth;
use C4::Koha;
use C4::Circulation::Circ2;
use C4::Reserves2;
use C4::Search;
use C4::Interface::CGI::Output;
use HTML::Template;
use C4::Date;
use C4::Letters;
my $query = new CGI;
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => "opac-user.tmpl",
query => $query,
type => "opac",
authnotrequired => 0,
flagsrequired => {borrow => 1},
debug => 1,
});
# get borrower information ....
my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
$borr->{'dateenrolled'} = format_date($borr->{'dateenrolled'});
$borr->{'expiry'} = format_date($borr->{'expiry'});
$borr->{'dateofbirth'} = format_date($borr->{'dateofbirth'});
$borr->{'ethnicity'} = fixEthnicity($borr->{'ethnicity'});
if ($borr->{'amountoutstanding'} > 5) {
$borr->{'amountoverfive'} = 1;
}
if (5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
$borr->{'amountoverzero'} = 1;
}
if ($borr->{'amountoutstanding'} < 0) {
$borr->{'amountlessthanzero'} = 1;
$borr->{'amountoutstanding'} = -1*($borr->{'amountoutstanding'});
}
$borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
my @bordat;
$bordat[0] = $borr;
$template->param(BORROWER_INFO => \@bordat);
$template->param(borrowernumber => $borrowernumber);
#get issued items ....
my $issues = getissues($borr);
my $count = 0;
my $overdues_count = 0;
my @overdues;
my @issuedat;
foreach my $key (keys %$issues) {
my $issue = $issues->{$key};
$issue->{'date_due'} = format_date($issue->{'date_due'});
# check for reserves
my ($restype, $res) = CheckReserves($issue->{'itemnumber'});
if ($restype) {
$issue->{'reserved'} = 1;
}
my ($numaccts,$accts,$total) = getboracctrecord(undef,$borr);
my $charges = 0;
foreach my $ac (@$accts) {
if ($ac->{'itemnumber'} == $issue->{'itemnumber'}) {
$charges += $ac->{'amountoutstanding'} if $ac->{'accounttype'} eq 'F';
$charges += $ac->{'amountoutstanding'} if $ac->{'accounttype'} eq 'L';
}
}
$issue->{'charges'} = $charges;
# get publictype for icon
my $publictype = $issue->{'publictype'};
$issue->{$publictype} = 1;
# check if item is renewable
my %env;
my $status = renewstatus(\%env,$borrowernumber, $issue->{'itemnumber'});
$issue->{'status'} = $status;
if ($issue->{'overdue'}) {
push @overdues, $issue;
$overdues_count++;
$issue->{'overdue'} = 1;
} else {
$issue->{'issued'} = 1;
}
push @issuedat, $issue;
$count++;
}
$template->param(ISSUES => \@issuedat);
$template->param(issues_count => $count);
$template->param(OVERDUES => \@overdues);
$template->param(overdues_count => $overdues_count);
my $branches = getbranches();
# now the reserved items....
my ($rcount, $reserves) = FindReserves(undef, $borrowernumber);
foreach my $res (@$reserves) {
$res->{'reservedate'} = format_date($res->{'reservedate'});
my $publictype = $res->{'publictype'};
$res->{$publictype} = 1;
$res->{'waiting'} = 1 if $res->{'found'} eq 'W';
$res->{'branch'} = $branches->{$res->{'branchcode'}}->{'branchname'};
}
$template->param(RESERVES => $reserves);
$template->param(reserves_count => $rcount);
my @waiting;
my $wcount = 0;
foreach my $res (@$reserves) {
if ($res->{'itemnumber'}) {
my $item = getiteminformation('',$res->{'itemnumber'},'');
$res->{'holdingbranch'} = $branches->{$item->{'holdingbranch'}}->{'branchname'};
$res->{'branch'} = $branches->{$res->{'branchcode'}}->{'branchname'};
if($res->{'holdingbranch'} eq $res->{'branch'}){
$res->{'atdestination'} = 1;
}
push @waiting, $res;
$wcount++;
}
}
$template->param(WAITING => \@waiting);
# current alert subscriptions
warn " B : $borrowernumber";
my $alerts = getalert($borrowernumber);
foreach (@$alerts) {
$_->{$_->{type}}=1;
$_->{relatedto} = findrelatedto($_->{type},$_->{externalid});
}
$template->param(waiting_count => $wcount,
LibraryName => C4::Context->preference("LibraryName"),
suggestion => C4::Context->preference("suggestion"),
virtualshelves => C4::Context->preference("virtualshelves"),
textmessaging => $borr->{textmessaging},
alertloop => $alerts,
);
output_html_with_http_headers $query, $cookie, $template->output;