synch'ing 2.2 and head
[koha.git] / opac / opac-alert-subscribe.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Date;
7 use C4::Output;
8 use C4::Interface::CGI::Output;
9 use C4::Context;
10 use C4::Koha;
11 use C4::Letters;
12 use C4::Bull;
13 # use C4::Search;
14 use HTML::Template;
15
16 my $query = new CGI;
17 my $op = $query->param('op');
18 my $dbh = C4::Context->dbh;
19
20 my $sth;
21 my ($template, $loggedinuser, $cookie);
22 my $externalid = $query->param('externalid');
23 my $alerttype = $query->param('alerttype');
24 my $biblionumber = $query->param('biblionumber');
25
26 ($template, $loggedinuser, $cookie)
27         = get_template_and_user({template_name => "opac-alert-subscribe.tmpl",
28                                 query => $query,
29                                 type => "opac",
30                                 authnotrequired => 1,
31                                 debug => 1,
32                                 });
33
34 if ($op eq 'alert_confirmed') {
35         addalert($loggedinuser,$alerttype,$externalid);
36         if ($alerttype eq 'issue') {
37                 print $query->redirect("opac-serial-issues.pl?biblionumber=$biblionumber");
38                 exit;
39         }
40 } elsif ($op eq 'cancel_confirmed') {
41         my $alerts =getalert($loggedinuser,$alerttype,$externalid);
42         foreach (@$alerts) { # we are supposed to have only 1 result, but just in case...
43                 delalert($_->{alertid});
44         }
45         if ($alerttype eq 'issue') {
46                 print $query->redirect("opac-serial-issues.pl?biblionumber=$biblionumber");
47                 exit;
48         }
49
50 } else {
51         if ($alerttype eq 'issue') { # alert for subscription issues
52                 my $subscription = &getsubscription($externalid);
53                 $template->param("typeissue$op" => 1,
54                                                 bibliotitle => $subscription->{bibliotitle},
55                                                 notes => $subscription->{notes},
56                                                 externalid => $externalid,
57                                                 biblionumber => $biblionumber,
58                                                 );
59         } else {
60         }
61         
62 }
63 output_html_with_http_headers $query, $cookie, $template->output;