3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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, @messages );
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
97 for my $suggestion ( @
$suggestions_loop ) {
98 push @messages, { type
=> 'error', code
=> 'already_exists', id
=> $suggestion->{suggestionid
} };
103 my $scrubber = C4
::Scrubber
->new();
104 foreach my $suggest (keys %$suggestion){
105 # Don't know why the encode is needed for Perl v5.10 here
106 $suggestion->{$suggest} = Encode
::encode
("utf8", $scrubber->scrub($suggestion->{$suggest}) );
108 $suggestion->{suggesteddate
} = dt_from_string
;
109 $suggestion->{branchcode
} = $input->param('branchcode') || C4
::Context
->userenv->{"branch"};
111 &NewSuggestion
($suggestion);
112 # empty fields, to avoid filter in "SearchSuggestion"
113 $$suggestion{$_}='' foreach qw
<title author publishercode copyrightdate place collectiontitle isbn STATUS
>;
115 &SearchSuggestion
( $suggestion );
116 push @messages, { type
=> 'info', code
=> 'success_on_inserted' };
121 if ( $op eq "delete_confirm" ) {
122 my @delete_field = $input->param("delete_field");
123 foreach my $delete_field (@delete_field) {
124 &DelSuggestion
( $borrowernumber, $delete_field );
127 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
130 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo
($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @
$suggestions_loop;
131 my $supportlist=GetSupportList
();
132 foreach my $support(@
$supportlist){
133 if ($$support{'imageurl'}){
134 $$support{'imageurl'}= getitemtypeimagelocation
( 'opac', $$support{'imageurl'} );
137 delete $$support{'imageurl'}
141 foreach my $suggestion(@
$suggestions_loop) {
142 if($suggestion->{'suggestedby'} == $borrowernumber) {
143 $suggestion->{'showcheckbox'} = $borrowernumber;
145 $suggestion->{'showcheckbox'} = 0;
147 if($suggestion->{'patronreason'}){
148 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib
("OPAC_SUG",$suggestion->{'patronreason'},1);
152 my $patron_reason_loop = GetAuthorisedValues
("OPAC_SUG");
154 # Is the person allowed to choose their branch
155 if ( C4
::Context
->preference("AllowPurchaseSuggestionBranchChoice") ) {
156 my ( $borr ) = GetMemberDetails
( $borrowernumber );
158 # pass the pickup branch along....
160 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
161 $userbranch = C4
::Context
->userenv->{'branch'};
163 my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
165 # make branch selection options...
166 my $branchloop = GetBranchesLoop
($branchcode);
167 $template->param( branchloop
=> $branchloop );
172 itemtypeloop
=> $supportlist,
173 suggestions_loop
=> $suggestions_loop,
174 patron_reason_loop
=> $patron_reason_loop,
175 showall
=> $allsuggestions,
178 messages
=> \
@messages,
179 suggestionsview
=> 1,
182 output_html_with_http_headers
$input, $cookie, $template->output;