For MARC 21, instead of deleting the whole subfield when a character does not
[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 $note = $input->param('note');
15 my $copyrightdate =$input->param('copyrightdate');
16 my $publishercode = $input->param('publishercode');
17 my $volumedesc = $input->param('volumedesc');
18 my $publicationyear = $input->param('publicationyear');
19 my $place = $input->param('place');
20 my $isbn = $input->param('isbn');
21 my $status = $input->param('status');
22 my $suggestedbyme = $input->param('suggestedbyme');
23 my $op = $input->param('op');
24 $op = 'else' unless $op;
25
26 my ($template, $borrowernumber, $cookie);
27
28 my $dbh = C4::Context->dbh;
29
30 if (C4::Context->preference("AnonSuggestions")) {
31         ($template, $borrowernumber, $cookie)
32                 = get_template_and_user({template_name => "opac-suggestions.tmpl",
33                                                                 query => $input,
34                                                                 type => "opac",
35                                                                 authnotrequired => 1,
36                                                         });
37 if (!$borrowernumber) {
38         $borrowernumber = C4::Context->preference("AnonSuggestions");
39 }
40 } else {
41         ($template, $borrowernumber, $cookie)
42                 = get_template_and_user({template_name => "opac-suggestions.tmpl",
43                                                                 query => $input,
44                                                                 type => "opac",
45                                                                 authnotrequired => 1,
46                          });
47 }
48
49 if ($op eq "add_confirm") {
50         &NewSuggestion($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,'');
51         # empty fields, to avoid filter in "SearchSuggestion"
52         $title='';
53         $author='';
54         $publishercode='';
55         $copyrightdate ='';
56         $volumedesc = '';
57         $publicationyear = '';
58         $place = '';
59         $isbn = '';
60         $op='else';
61 }
62
63 if ($op eq "delete_confirm") {
64         my @delete_field = $input->param("delete_field");
65         foreach my $delete_field (@delete_field) {
66                 &DelSuggestion($borrowernumber,$delete_field);
67         }
68         $op='else';
69 }
70
71 my $suggestions_loop= &SearchSuggestion($borrowernumber,$author,$title,$publishercode,$status,$suggestedbyme);
72 $template->param(suggestions_loop => $suggestions_loop,
73                                 title => $title,
74                                 author => $author,
75                                 publishercode => $publishercode,
76                                 status => $status,
77                                 suggestedbyme => $suggestedbyme,
78                                 "op_$op" => 1,
79 );
80 output_html_with_http_headers $input, $cookie, $template->output;