Bug 11032: Check a valid MARC::Record passed to Biblio
[koha.git] / opac / opac-suggestions.pl
blob72383eb1c53ae26cfa86841ce2961466ccb1214d
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 use strict;
19 use warnings;
21 use CGI;
22 use C4::Auth; # get_template_and_user
23 use C4::Members;
24 use C4::Branch;
25 use C4::Koha;
26 use C4::Output;
27 use C4::Suggestions;
28 use C4::Koha;
29 use C4::Dates;
30 use C4::Scrubber;
32 my $input = new CGI;
33 my $allsuggestions = $input->param('showall');
34 my $op = $input->param('op');
35 my $suggestion = $input->Vars;
36 delete $$suggestion{$_} foreach qw<op suggestedbyme>;
37 $op = 'else' unless $op;
39 my ( $template, $borrowernumber, $cookie );
40 my $deleted = $input->param('deleted');
41 my $submitted = $input->param('submitted');
43 if ( C4::Context->preference("AnonSuggestions") ) {
44 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
46 template_name => "opac-suggestions.tmpl",
47 query => $input,
48 type => "opac",
49 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
52 if ( !$$suggestion{suggestedby} ) {
53 $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron");
56 else {
57 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
59 template_name => "opac-suggestions.tmpl",
60 query => $input,
61 type => "opac",
62 authnotrequired => 0,
66 if ($allsuggestions){
67 delete $$suggestion{suggestedby};
69 else {
70 $$suggestion{suggestedby} ||= $borrowernumber unless ($allsuggestions);
72 # warn "bornum:",$borrowernumber;
74 my $suggestions_loop =
75 &SearchSuggestion( $suggestion);
76 if ( $op eq "add_confirm" ) {
77 if (@$suggestions_loop>=1){
78 #some suggestion are answering the request Donot Add
80 else {
81 my $scrubber = C4::Scrubber->new();
82 foreach my $suggest (keys %$suggestion){
83 $suggestion->{$suggest} = $scrubber->scrub($suggestion->{$suggest});
85 $$suggestion{'suggesteddate'}=C4::Dates->today;
86 $$suggestion{'branchcode'}= $input->param('branch') || C4::Context->userenv->{"branch"};
88 &NewSuggestion($suggestion);
89 # empty fields, to avoid filter in "SearchSuggestion"
90 $$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>;
91 $suggestions_loop =
92 &SearchSuggestion( $suggestion );
94 $op = 'else';
95 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
96 exit;
99 if ( $op eq "delete_confirm" ) {
100 my @delete_field = $input->param("delete_field");
101 foreach my $delete_field (@delete_field) {
102 &DelSuggestion( $borrowernumber, $delete_field );
104 $op = 'else';
105 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&deleted=1");
106 exit;
108 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;
109 my $supportlist=GetSupportList();
110 foreach my $support(@$supportlist){
111 if ($$support{'imageurl'}){
112 $$support{'imageurl'}= getitemtypeimagelocation( 'opac', $$support{'imageurl'} );
114 else {
115 delete $$support{'imageurl'}
119 foreach my $suggestion(@$suggestions_loop) {
120 if($suggestion->{'suggestedby'} == $borrowernumber) {
121 $suggestion->{'showcheckbox'} = $borrowernumber;
122 } else {
123 $suggestion->{'showcheckbox'} = 0;
125 if($suggestion->{'patronreason'}){
126 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib("OPAC_SUG",$suggestion->{'patronreason'},1);
130 my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
132 # Is the person allowed to choose their branch
133 if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
134 my ( $borr ) = GetMemberDetails( $borrowernumber );
136 # pass the pickup branch along....
137 my $userbranch = '';
138 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
139 $userbranch = C4::Context->userenv->{'branch'};
141 my $branch = $input->param('branch') || $borr->{'branchcode'} || $userbranch || '' ;
143 # make branch selection options...
144 my $branchloop = GetBranchesLoop($branch);
145 $template->param( branchloop => $branchloop );
148 $template->param(
149 %$suggestion,
150 itemtypeloop=> $supportlist,
151 suggestions_loop => $suggestions_loop,
152 patron_reason_loop => $patron_reason_loop,
153 showall => $allsuggestions,
154 "op_$op" => 1,
155 suggestionsview => 1,
158 output_html_with_http_headers $input, $cookie, $template->output;