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
32 use Koha
::DateUtils
qw( dt_from_string );
35 my $op = $input->param('op');
36 my $suggestion = $input->Vars;
37 my $negcaptcha = $input->param('negcap');
38 my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0;
40 # If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return.
42 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl");
45 # don't pass 'negcap' column to DB, else DBI::Class will error
46 # DBIx::Class::Row::store_column(): No such column 'negcap' on Koha::Schema::Result::Suggestion at Koha/C4/Suggestions.pm
47 delete $suggestion->{negcap
};
50 #If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions
51 if ( ! C4
::Context
->preference('suggestion') ) {
52 print $input->redirect("/cgi-bin/koha/errors/404.pl");
56 delete $suggestion->{$_} foreach qw
<op suggested_by_anyone
>;
57 $op = 'else' unless $op;
59 my ( $template, $borrowernumber, $cookie, @messages );
60 my $deleted = $input->param('deleted');
61 my $submitted = $input->param('submitted');
63 if ( C4
::Context
->preference("AnonSuggestions") or ( C4
::Context
->preference("OPACViewOthersSuggestions") and $op eq 'else' ) ) {
64 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
66 template_name
=> "opac-suggestions.tt",
69 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
74 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
76 template_name
=> "opac-suggestions.tt",
84 if ( $op eq 'else' ) {
85 if ( C4
::Context
->preference("OPACViewOthersSuggestions") ) {
86 if ( $borrowernumber ) {
87 # A logged in user is able to see suggestions from others
88 $suggestion->{suggestedby
} = $suggested_by_anyone
93 # Non logged in user is able to see all suggestions
94 $suggestion->{suggestedby
} = undef;
98 if ( $borrowernumber ) {
99 $suggestion->{suggestedby
} = $borrowernumber;
102 $suggestion->{suggestedby
} = -1;
106 if ( $borrowernumber ) {
107 $suggestion->{suggestedby
} = $borrowernumber;
110 $suggestion->{suggestedby
} = C4
::Context
->preference("AnonymousPatron");
114 my $suggestions_loop =
115 &SearchSuggestion
( $suggestion);
116 if ( $op eq "add_confirm" ) {
117 if (@
$suggestions_loop>=1){
118 #some suggestion are answering the request Donot Add
119 for my $suggestion ( @
$suggestions_loop ) {
120 push @messages, { type
=> 'error', code
=> 'already_exists', id
=> $suggestion->{suggestionid
} };
125 my $scrubber = C4
::Scrubber
->new();
126 foreach my $suggest (keys %$suggestion){
127 # Don't know why the encode is needed for Perl v5.10 here
128 $suggestion->{$suggest} = Encode
::encode
("utf8", $scrubber->scrub($suggestion->{$suggest}) );
130 $suggestion->{suggesteddate
} = dt_from_string
;
131 $suggestion->{branchcode
} = $input->param('branchcode') || C4
::Context
->userenv->{"branch"};
133 &NewSuggestion
($suggestion);
134 # empty fields, to avoid filter in "SearchSuggestion"
135 $$suggestion{$_}='' foreach qw
<title author publishercode copyrightdate place collectiontitle isbn STATUS
>;
137 &SearchSuggestion
( $suggestion );
138 push @messages, { type
=> 'info', code
=> 'success_on_inserted' };
143 if ( $op eq "delete_confirm" ) {
144 my @delete_field = $input->multi_param("delete_field");
145 foreach my $delete_field (@delete_field) {
146 &DelSuggestion
( $borrowernumber, $delete_field );
149 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
152 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo
($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @
$suggestions_loop;
154 foreach my $suggestion(@
$suggestions_loop) {
155 if($suggestion->{'suggestedby'} == $borrowernumber) {
156 $suggestion->{'showcheckbox'} = $borrowernumber;
158 $suggestion->{'showcheckbox'} = 0;
160 if($suggestion->{'patronreason'}){
161 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib
("OPAC_SUG",$suggestion->{'patronreason'},1);
165 my $patron_reason_loop = GetAuthorisedValues
("OPAC_SUG");
167 # Is the person allowed to choose their branch
168 if ( C4
::Context
->preference("AllowPurchaseSuggestionBranchChoice") ) {
169 my ( $borr ) = GetMemberDetails
( $borrowernumber );
171 # pass the pickup branch along....
173 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
174 $userbranch = C4
::Context
->userenv->{'branch'};
176 my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
178 # make branch selection options...
179 my $branchloop = GetBranchesLoop
($branchcode);
180 $template->param( branchloop
=> $branchloop );
185 suggestions_loop
=> $suggestions_loop,
186 patron_reason_loop
=> $patron_reason_loop,
189 messages
=> \
@messages,
190 suggestionsview
=> 1,
191 suggested_by_anyone
=> $suggested_by_anyone,
194 output_html_with_http_headers
$input, $cookie, $template->output;