, undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) );
}
-=head2 addalert ($borrowernumber, $type, $externalid)
+=head2 addalert ($borrowernumber, $subscriptionid)
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.
-
+ - $subscriptionid
+
create an alert and return the alertid (primary key)
=cut
sub addalert {
- my ( $borrowernumber, $type, $externalid ) = @_;
+ my ( $borrowernumber, $subscriptionid) = @_;
my $dbh = C4::Context->dbh;
my $sth =
$dbh->prepare(
- "insert into alert (borrowernumber, type, externalid) values (?,?,?)");
- $sth->execute( $borrowernumber, $type, $externalid );
+ "insert into alert (borrowernumber, externalid) values (?,?)");
+ $sth->execute( $borrowernumber, $subscriptionid );
# get the alert number newly created and return it
my $alertid = $dbh->{'mysql_insertid'};
$sth->execute($alertid);
}
-=head2 getalert ([$borrowernumber], [$type], [$externalid])
+=head2 getalert ([$borrowernumber], [$subscriptionid])
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.
+ - $subscriptionid
+ all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $subscriptionid, returns all alerts for a borrower on a topic.
=cut
sub getalert {
- my ( $borrowernumber, $type, $externalid ) = @_;
+ my ( $borrowernumber, $subscriptionid ) = @_;
my $dbh = C4::Context->dbh;
my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1";
my @bind;
$query .= " AND borrowernumber=?";
push @bind, $borrowernumber;
}
- if ($type) {
- $query .= " AND type=?";
- push @bind, $type;
- }
- if ($externalid) {
+ if ($subscriptionid) {
$query .= " AND externalid=?";
- push @bind, $externalid;
+ push @bind, $subscriptionid;
}
my $sth = $dbh->prepare($query);
$sth->execute(@bind);
my %letter;
# find the list of borrowers to alert
- my $alerts = getalert( '', 'issue', $subscriptionid );
+ my $alerts = getalert( '', $subscriptionid );
foreach (@$alerts) {
my $patron = Koha::Patrons->find( $_->{borrowernumber} );
next unless $patron; # Just in case
<h4>[% bibliotitle %]</h4>
[% IF ( notes ) %]<p>[% notes %]</p>[% END %]
<input type="hidden" name="externalid" value="[% externalid %]">
- <input type="hidden" name="alerttype" value="[% alerttype %]">
<input type="hidden" name="referer" value="[% referer %]">
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
<input type="hidden" name="op" value="alert_confirmed">
<h4>[% bibliotitle %]</h4>
[% IF ( notes ) %]<p>[% notes %]</p>[% END %]
<input type="hidden" name="externalid" value="[% externalid %]">
- <input type="hidden" name="alerttype" value="[% alerttype %]">
<input type="hidden" name="referer" value="[% referer %]">
<input type="hidden" name="biblionumber" value="[% biblionumber | html %]">
<input type="hidden" name="op" value="cancel_confirmed">
[% IF ( subscription.letter ) %]<span class="email_notifications">
[% IF ( loggedinusername ) %]
[% IF ( subscription.hasalert ) %]
- <span>You have subscribed to email notification on new issues. </span><a style="color:#000;" class="btn" title="Cancel email notification" href="/cgi-bin/koha/opac-alert-subscribe.pl?op=cancel&externalid=[% subscription.subscriptionid %]&alerttype=issue&biblionumber=[% subscription.biblionumber %]">Cancel email notification</a>
+ <span>You have subscribed to email notification on new issues. </span><a style="color:#000;" class="btn" title="Cancel email notification" href="/cgi-bin/koha/opac-alert-subscribe.pl?op=cancel&externalid=[% subscription.subscriptionid %]&biblionumber=[% subscription.biblionumber %]">Cancel email notification</a>
[% ELSE %]
- <a style="color:#000;" class="btn" title="Subscribe to email notification on new issues" href="/cgi-bin/koha/opac-alert-subscribe.pl?externalid=[% subscription.subscriptionid %]&alerttype=issue&biblionumber=[% subscription.biblionumber %]">Subscribe to email notification on new issues</a>
+ <a style="color:#000;" class="btn" title="Subscribe to email notification on new issues" href="/cgi-bin/koha/opac-alert-subscribe.pl?externalid=[% subscription.subscriptionid %]&biblionumber=[% subscription.biblionumber %]">Subscribe to email notification on new issues</a>
[% END %]
[% ELSE %]
<span>You must log in if you want to subscribe to email notification on new issues</span>
[% IF ( subscription_LOO.letter ) %]
[% IF ( loggedinusername ) %]
[% IF ( subscription_LOO.hasalert ) %]
- You have subscribed to email notification on new issues <a href="opac-alert-subscribe.pl?op=cancel&externalid=[% subscription_LOO.subscriptionid %]&alerttype=issue&referer=serial&biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Cancel email notification">
+ You have subscribed to email notification on new issues <a href="opac-alert-subscribe.pl?op=cancel&externalid=[% subscription_LOO.subscriptionid %]&referer=serial&biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Cancel email notification">
Cancel email notification
</a>
[% ELSE %]
- <a href="opac-alert-subscribe.pl?externalid=[% subscription_LOO.subscriptionid %]&alerttype=issue&referer=serial&biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Subscribe to email notification on new issues">
+ <a href="opac-alert-subscribe.pl?externalid=[% subscription_LOO.subscriptionid %]&referer=serial&biblionumber=[% subscription_LOO.biblionumber %]" class="btn" title="Subscribe to email notification on new issues">
Subscribe to email notification on new issues
</a>
[% END %]
my $sth;
my ( $template, $loggedinuser, $cookie );
my $externalid = $query->param('externalid');
-my $alerttype = $query->param('alerttype') || '';
my $referer = $query->param('referer') || 'detail';
my $biblionumber = $query->param('biblionumber');
);
if ( $op eq 'alert_confirmed' ) {
- addalert( $loggedinuser, $alerttype, $externalid );
+ addalert( $loggedinuser, $externalid );
if ( $referer eq 'serial' ) {
print $query->redirect(
"opac-serial-issues.pl?biblionumber=$biblionumber");
}
}
elsif ( $op eq 'cancel_confirmed' ) {
- my $alerts = getalert( $loggedinuser, $alerttype, $externalid );
- warn "CANCEL confirmed : $loggedinuser, $alerttype, $externalid".Data::Dumper::Dumper( $alerts );
+ my $alerts = getalert( $loggedinuser, $externalid );
+ warn "CANCEL confirmed : $loggedinuser, $externalid".Data::Dumper::Dumper( $alerts );
foreach (@$alerts)
{ # we are supposed to have only 1 result, but just in case...
delalert( $_->{alertid} );
}
else {
- if ( $alerttype eq 'issue' ) { # alert for subscription issues
- my $subscription = &GetSubscription($externalid);
- $template->param(
- alerttype => $alerttype,
- referer => $referer,
- "typeissue$op" => 1,
- bibliotitle => $subscription->{bibliotitle},
- notes => $subscription->{notes},
- externalid => $externalid,
- biblionumber => $biblionumber,
- );
- }
+ my $subscription = &GetSubscription($externalid);
+ $template->param(
+ referer => $referer,
+ "typeissue$op" => 1,
+ bibliotitle => $subscription->{bibliotitle},
+ notes => $subscription->{notes},
+ externalid => $externalid,
+ biblionumber => $biblionumber,
+ );
}
output_html_with_http_headers $query, $cookie, $template->output;
$cell{latestserials} =
GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
if ( $borrowernumber ) {
- my $sub = getalert($borrowernumber,'issue',$subscription->{subscriptionid});
+ my $sub = getalert($borrowernumber, $subscription->{subscriptionid});
if (@$sub[0]) {
$cell{hasalert} = 1;
}
# now, check is there is an alert subscription for one of the subscriptions
if ($loggedinuser) {
foreach (@$subscriptions) {
- my $sub = getalert($loggedinuser,'issue',$_->{subscriptionid});
+ my $sub = getalert($loggedinuser, $_->{subscriptionid});
if ($sub) {
$_->{hasalert} = 1;
}
# now, check is there is an alert subscription for one of the subscriptions
if ($loggedinuser){
foreach (@$subscriptions) {
- my $subscription = getalert($loggedinuser,'issue',$_->{subscriptionid});
+ my $subscription = getalert($loggedinuser, $_->{subscriptionid});
if (@$subscription[0]) {
$_->{hasalert} = 1;
}
my $subscriptionid=$input->param('subscriptionid');
-my $borrowers = getalert('','issue',$subscriptionid);
+my $borrowers = getalert('', $subscriptionid);
my $subscription = GetSubscription($subscriptionid);
for my $borrowernumber (@$borrowers) {
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use Test::More tests => 77;
+use Test::More tests => 75;
use Test::MockModule;
use Test::Warn;
is( $letter14206_c->{message_transport_type}, 'print', 'Bug 14206 - correct mtt detected for call from overdue_notices.pl' );
# addalert
-my $type = 'my type';
my $externalid = 'my external id';
-my $alert_id = C4::Letters::addalert($borrowernumber, $type, $externalid);
+my $alert_id = C4::Letters::addalert($borrowernumber, $externalid);
isnt( $alert_id, undef, 'addalert does not return undef' );
$alerts = C4::Letters::getalert($borrowernumber);
is( @$alerts, 1, 'addalert adds an alert' );
is( $alerts->[0]->{alertid}, $alert_id, 'addalert returns the alert id correctly' );
-is( $alerts->[0]->{type}, $type, 'addalert stores the type correctly' );
is( $alerts->[0]->{externalid}, $externalid, 'addalert stores the externalid correctly' );
-$alerts = C4::Letters::getalert($borrowernumber, $type);
+$alerts = C4::Letters::getalert($borrowernumber);
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
-$alerts = C4::Letters::getalert($borrowernumber, $type, $externalid);
+$alerts = C4::Letters::getalert($borrowernumber, $externalid);
is( @$alerts, 1, 'getalert returns the correct number of alerts' );
-$alerts = C4::Letters::getalert($borrowernumber, 'another type');
-is( @$alerts, 0, 'getalert returns the correct number of alerts' );
-$alerts = C4::Letters::getalert($borrowernumber, $type, 'another external id');
+$alerts = C4::Letters::getalert($borrowernumber, 'another external id');
is( @$alerts, 0, 'getalert returns the correct number of alerts' );
dateofbirth => $date,
email => 'john.smith@test.de',
);
-my $alert_id = C4::Letters::addalert($borrowernumber, 'issue', $subscriptionid);
+my $alert_id = C4::Letters::addalert($borrowernumber, $subscriptionid);
my $err2;