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 #If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions
49 if ( ! C4
::Context
->preference('suggestion') ) {
50 print $input->redirect("/cgi-bin/koha/errors/404.pl");
54 delete $$suggestion{$_} foreach qw
<op suggestedbyme
>;
55 $op = 'else' unless $op;
57 my ( $template, $borrowernumber, $cookie );
58 my $deleted = $input->param('deleted');
59 my $submitted = $input->param('submitted');
61 if ( C4
::Context
->preference("AnonSuggestions") ) {
62 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
64 template_name
=> "opac-suggestions.tt",
67 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
70 if ( !$$suggestion{suggestedby
} ) {
71 $$suggestion{suggestedby
} = C4
::Context
->preference("AnonymousPatron");
75 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
77 template_name
=> "opac-suggestions.tt",
85 delete $$suggestion{suggestedby
};
88 $$suggestion{suggestedby
} ||= $borrowernumber unless ($allsuggestions);
90 # warn "bornum:",$borrowernumber;
92 my $suggestions_loop =
93 &SearchSuggestion
( $suggestion);
94 if ( $op eq "add_confirm" ) {
95 if (@
$suggestions_loop>=1){
96 #some suggestion are answering the request Donot Add
99 my $scrubber = C4
::Scrubber
->new();
100 foreach my $suggest (keys %$suggestion){
101 # Don't know why the encode is needed for Perl v5.10 here
102 $suggestion->{$suggest} = Encode
::encode
("utf8", $scrubber->scrub($suggestion->{$suggest}) );
104 $suggestion->{suggesteddate
} = dt_from_string
;
105 $suggestion->{branchcode
} = $input->param('branchcode') || C4
::Context
->userenv->{"branch"};
107 &NewSuggestion
($suggestion);
108 # empty fields, to avoid filter in "SearchSuggestion"
109 $$suggestion{$_}='' foreach qw
<title author publishercode copyrightdate place collectiontitle isbn STATUS
>;
111 &SearchSuggestion
( $suggestion );
114 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
118 if ( $op eq "delete_confirm" ) {
119 my @delete_field = $input->param("delete_field");
120 foreach my $delete_field (@delete_field) {
121 &DelSuggestion
( $borrowernumber, $delete_field );
124 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&deleted=1");
127 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo
($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @
$suggestions_loop;
128 my $supportlist=GetSupportList
();
129 foreach my $support(@
$supportlist){
130 if ($$support{'imageurl'}){
131 $$support{'imageurl'}= getitemtypeimagelocation
( 'opac', $$support{'imageurl'} );
134 delete $$support{'imageurl'}
138 foreach my $suggestion(@
$suggestions_loop) {
139 if($suggestion->{'suggestedby'} == $borrowernumber) {
140 $suggestion->{'showcheckbox'} = $borrowernumber;
142 $suggestion->{'showcheckbox'} = 0;
144 if($suggestion->{'patronreason'}){
145 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib
("OPAC_SUG",$suggestion->{'patronreason'},1);
149 my $patron_reason_loop = GetAuthorisedValues
("OPAC_SUG");
151 # Is the person allowed to choose their branch
152 if ( C4
::Context
->preference("AllowPurchaseSuggestionBranchChoice") ) {
153 my ( $borr ) = GetMemberDetails
( $borrowernumber );
155 # pass the pickup branch along....
157 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
158 $userbranch = C4
::Context
->userenv->{'branch'};
160 my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
162 # make branch selection options...
163 my $branchloop = GetBranchesLoop
($branchcode);
164 $template->param( branchloop
=> $branchloop );
169 itemtypeloop
=> $supportlist,
170 suggestions_loop
=> $suggestions_loop,
171 patron_reason_loop
=> $patron_reason_loop,
172 showall
=> $allsuggestions,
174 suggestionsview
=> 1,
177 output_html_with_http_headers
$input, $cookie, $template->output;