adding suggestions in OPAC
[koha.git] / opac / opac-suggestions.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5 use HTML::Template;
6
7 use C4::Auth;       # get_template_and_user
8 use C4::Interface::CGI::Output;
9 use C4::Suggestions;
10
11 my $input = new CGI;
12 my $title = $input->param('title');
13 my $author = $input->param('author');
14 my $publishercode = $input->param('publishercode');
15 my $status = $input->param('status');
16 my $suggestedbyme = $input->param('suggestedbyme');
17 my $note = $input->param('note');
18 my $op = $input->param('op');
19 $op = 'else' unless $op;
20
21 my $dbh = C4::Context->dbh;
22 my ($template, $borrowernumber, $cookie)
23     = get_template_and_user({template_name => "opac-suggestions.tmpl",
24                              type => "opac",
25                              query => $input,
26                              authnotrequired => 1,
27                              flagsrequired => {borrow => 1},
28                          });
29 if ($op eq "add_confirm") {
30         &newsuggestion($borrowernumber,$title,$author,$publishercode,$note);
31         # empty fields, to avoid filter in "searchsuggestion"
32         $title='';
33         $author='';
34         $publishercode='';
35         $op='else';
36 }
37
38 if ($op eq "delete_confirm") {
39         my @delete_field = $input->param("delete_field");
40         foreach my $delete_field (@delete_field) {
41                 &delsuggestion($borrowernumber,$delete_field);
42         }
43         $op='else';
44 }
45
46 my $suggestions_loop= &searchsuggestion($borrowernumber,$author,$title,$publishercode,$status,$suggestedbyme);
47 $template->param(suggestions_loop => $suggestions_loop,
48                                 title => $title,
49                                 author => $author,
50                                 publishercode => $publishercode,
51                                 status => $status,
52                                 suggestedbyme => $suggestedbyme,
53                                 "op_$op" => 1,
54 );
55 output_html_with_http_headers $input, $cookie, $template->output;