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 C4
::Auth
; # get_template_and_user
32 use Koha
::DateUtils
qw( dt_from_string );
35 my $allsuggestions = $input->param('showall');
36 my $op = $input->param('op');
37 my $suggestion = $input->Vars;
38 delete $suggestion->{negcap
};
39 my $negcaptcha = $input->param('negcap');
41 # If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return.
43 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl");
47 #If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions
48 if ( ! C4
::Context
->preference('suggestion') ) {
49 print $input->redirect("/cgi-bin/koha/errors/404.pl");
53 delete $$suggestion{$_} foreach qw
<op suggestedbyme
>;
54 $op = 'else' unless $op;
56 my ( $template, $borrowernumber, $cookie, @messages );
57 my $deleted = $input->param('deleted');
58 my $submitted = $input->param('submitted');
60 if ( C4
::Context
->preference("AnonSuggestions") ) {
61 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
63 template_name
=> "opac-suggestions.tt",
66 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
69 if ( !$$suggestion{suggestedby
} ) {
70 $$suggestion{suggestedby
} = C4
::Context
->preference("AnonymousPatron");
74 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
76 template_name
=> "opac-suggestions.tt",
84 delete $$suggestion{suggestedby
};
87 $$suggestion{suggestedby
} ||= $borrowernumber unless ($allsuggestions);
89 # warn "bornum:",$borrowernumber;
91 my $suggestions_loop =
92 &SearchSuggestion
( $suggestion);
93 if ( $op eq "add_confirm" ) {
94 if (@
$suggestions_loop>=1){
95 #some suggestion are answering the request Donot Add
96 for my $suggestion ( @
$suggestions_loop ) {
97 push @messages, { type
=> 'error', code
=> 'already_exists', id
=> $suggestion->{suggestionid
} };
102 my $scrubber = C4
::Scrubber
->new();
103 foreach my $suggest (keys %$suggestion){
104 $suggestion->{$suggest} = $scrubber->scrub($suggestion->{$suggest});
106 $suggestion->{suggesteddate
} = dt_from_string
;
107 $suggestion->{branchcode
} = $input->param('branchcode') || C4
::Context
->userenv->{"branch"};
109 &NewSuggestion
($suggestion);
110 # empty fields, to avoid filter in "SearchSuggestion"
111 $$suggestion{$_}='' foreach qw
<title author publishercode copyrightdate place collectiontitle isbn STATUS
>;
113 &SearchSuggestion
( $suggestion );
114 push @messages, { type
=> 'info', code
=> 'success_on_inserted' };
119 if ( $op eq "delete_confirm" ) {
120 my @delete_field = $input->param("delete_field");
121 foreach my $delete_field (@delete_field) {
122 &DelSuggestion
( $borrowernumber, $delete_field );
125 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
128 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo
($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @
$suggestions_loop;
129 my $supportlist=GetSupportList
();
130 foreach my $support(@
$supportlist){
131 if ($$support{'imageurl'}){
132 $$support{'imageurl'}= getitemtypeimagelocation
( 'opac', $$support{'imageurl'} );
135 delete $$support{'imageurl'}
139 foreach my $suggestion(@
$suggestions_loop) {
140 if($suggestion->{'suggestedby'} == $borrowernumber) {
141 $suggestion->{'showcheckbox'} = $borrowernumber;
143 $suggestion->{'showcheckbox'} = 0;
145 if($suggestion->{'patronreason'}){
146 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib
("OPAC_SUG",$suggestion->{'patronreason'},1);
150 my $patron_reason_loop = GetAuthorisedValues
("OPAC_SUG");
152 # Is the person allowed to choose their branch
153 if ( C4
::Context
->preference("AllowPurchaseSuggestionBranchChoice") ) {
154 my ( $borr ) = GetMemberDetails
( $borrowernumber );
156 # pass the pickup branch along....
158 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
159 $userbranch = C4
::Context
->userenv->{'branch'};
161 my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
163 # make branch selection options...
164 my $branchloop = GetBranchesLoop
($branchcode);
165 $template->param( branchloop
=> $branchloop );
170 itemtypeloop
=> $supportlist,
171 suggestions_loop
=> $suggestions_loop,
172 patron_reason_loop
=> $patron_reason_loop,
173 showall
=> $allsuggestions,
176 messages
=> \
@messages,
177 suggestionsview
=> 1,
180 output_html_with_http_headers
$input, $cookie, $template->output;