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 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 delete $$suggestion{$_} foreach qw
<op suggestedbyme
>;
48 $op = 'else' unless $op;
50 my ( $template, $borrowernumber, $cookie );
51 my $deleted = $input->param('deleted');
52 my $submitted = $input->param('submitted');
54 if ( C4
::Context
->preference("AnonSuggestions") ) {
55 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
57 template_name
=> "opac-suggestions.tt",
60 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
63 if ( !$$suggestion{suggestedby
} ) {
64 $$suggestion{suggestedby
} = C4
::Context
->preference("AnonymousPatron");
68 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
70 template_name
=> "opac-suggestions.tt",
78 delete $$suggestion{suggestedby
};
81 $$suggestion{suggestedby
} ||= $borrowernumber unless ($allsuggestions);
83 # warn "bornum:",$borrowernumber;
85 my $suggestions_loop =
86 &SearchSuggestion
( $suggestion);
87 if ( $op eq "add_confirm" ) {
88 if (@
$suggestions_loop>=1){
89 #some suggestion are answering the request Donot Add
92 my $scrubber = C4
::Scrubber
->new();
93 foreach my $suggest (keys %$suggestion){
94 $suggestion->{$suggest} = $scrubber->scrub($suggestion->{$suggest});
96 $suggestion->{suggesteddate
} = dt_from_string
;
97 $suggestion->{branchcode
} = $input->param('branchcode') || C4
::Context
->userenv->{"branch"};
99 &NewSuggestion
($suggestion);
100 # empty fields, to avoid filter in "SearchSuggestion"
101 $$suggestion{$_}='' foreach qw
<title author publishercode copyrightdate place collectiontitle isbn STATUS
>;
103 &SearchSuggestion
( $suggestion );
106 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
110 if ( $op eq "delete_confirm" ) {
111 my @delete_field = $input->param("delete_field");
112 foreach my $delete_field (@delete_field) {
113 &DelSuggestion
( $borrowernumber, $delete_field );
116 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&deleted=1");
119 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo
($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @
$suggestions_loop;
120 my $supportlist=GetSupportList
();
121 foreach my $support(@
$supportlist){
122 if ($$support{'imageurl'}){
123 $$support{'imageurl'}= getitemtypeimagelocation
( 'opac', $$support{'imageurl'} );
126 delete $$support{'imageurl'}
130 foreach my $suggestion(@
$suggestions_loop) {
131 if($suggestion->{'suggestedby'} == $borrowernumber) {
132 $suggestion->{'showcheckbox'} = $borrowernumber;
134 $suggestion->{'showcheckbox'} = 0;
136 if($suggestion->{'patronreason'}){
137 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib
("OPAC_SUG",$suggestion->{'patronreason'},1);
141 my $patron_reason_loop = GetAuthorisedValues
("OPAC_SUG");
143 # Is the person allowed to choose their branch
144 if ( C4
::Context
->preference("AllowPurchaseSuggestionBranchChoice") ) {
145 my ( $borr ) = GetMemberDetails
( $borrowernumber );
147 # pass the pickup branch along....
149 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
150 $userbranch = C4
::Context
->userenv->{'branch'};
152 my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
154 # make branch selection options...
155 my $branchloop = GetBranchesLoop
($branchcode);
156 $template->param( branchloop
=> $branchloop );
161 itemtypeloop
=> $supportlist,
162 suggestions_loop
=> $suggestions_loop,
163 patron_reason_loop
=> $patron_reason_loop,
164 showall
=> $allsuggestions,
166 suggestionsview
=> 1,
169 output_html_with_http_headers
$input, $cookie, $template->output;