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
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.
22 use Encode qw( encode );
23 use C4::Auth; # get_template_and_user
33 use Koha::DateUtils qw( dt_from_string );
36 my $allsuggestions = $input->param('showall');
37 my $op = $input->param('op');
38 my $suggestion = $input->Vars;
39 delete $suggestion->{negcap};
40 my $negcaptcha = $input->param('negcap');
42 # If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return.
44 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl");
48 delete $$suggestion{$_} foreach qw<op suggestedbyme>;
49 $op = 'else' unless $op;
51 my ( $template, $borrowernumber, $cookie );
52 my $deleted = $input->param('deleted');
53 my $submitted = $input->param('submitted');
55 if ( C4::Context->preference("AnonSuggestions") ) {
56 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
58 template_name => "opac-suggestions.tt",
61 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
64 if ( !$$suggestion{suggestedby} ) {
65 $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron");
69 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
71 template_name => "opac-suggestions.tt",
79 delete $$suggestion{suggestedby};
82 $$suggestion{suggestedby} ||= $borrowernumber unless ($allsuggestions);
84 # warn "bornum:",$borrowernumber;
86 my $suggestions_loop =
87 &SearchSuggestion( $suggestion);
88 if ( $op eq "add_confirm" ) {
89 if (@$suggestions_loop>=1){
90 #some suggestion are answering the request Donot Add
93 my $scrubber = C4::Scrubber->new();
94 foreach my $suggest (keys %$suggestion){
95 # Don't know why the encode is needed for Perl v5.10 here
96 $suggestion->{$suggest} = Encode::encode("utf8", $scrubber->scrub($suggestion->{$suggest}) );
98 $suggestion->{suggesteddate} = dt_from_string;
99 $suggestion->{branchcode} = $input->param('branchcode') || C4::Context->userenv->{"branch"};
101 &NewSuggestion($suggestion);
102 # empty fields, to avoid filter in "SearchSuggestion"
103 $$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>;
105 &SearchSuggestion( $suggestion );
108 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
112 if ( $op eq "delete_confirm" ) {
113 my @delete_field = $input->param("delete_field");
114 foreach my $delete_field (@delete_field) {
115 &DelSuggestion( $borrowernumber, $delete_field );
118 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&deleted=1");
121 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;
122 my $supportlist=GetSupportList();
123 foreach my $support(@$supportlist){
124 if ($$support{'imageurl'}){
125 $$support{'imageurl'}= getitemtypeimagelocation( 'opac', $$support{'imageurl'} );
128 delete $$support{'imageurl'}
132 foreach my $suggestion(@$suggestions_loop) {
133 if($suggestion->{'suggestedby'} == $borrowernumber) {
134 $suggestion->{'showcheckbox'} = $borrowernumber;
136 $suggestion->{'showcheckbox'} = 0;
138 if($suggestion->{'patronreason'}){
139 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib("OPAC_SUG",$suggestion->{'patronreason'},1);
143 my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
145 # Is the person allowed to choose their branch
146 if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
147 my ( $borr ) = GetMemberDetails( $borrowernumber );
149 # pass the pickup branch along....
151 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
152 $userbranch = C4::Context->userenv->{'branch'};
154 my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
156 # make branch selection options...
157 my $branchloop = GetBranchesLoop($branchcode);
158 $template->param( branchloop => $branchloop );
163 itemtypeloop=> $supportlist,
164 suggestions_loop => $suggestions_loop,
165 patron_reason_loop => $patron_reason_loop,
166 showall => $allsuggestions,
168 suggestionsview => 1,
171 output_html_with_http_headers $input, $cookie, $template->output;