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 $op = $input->param('op');
36 my $suggestion = $input->Vars;
37 delete $suggestion->{negcap
};
38 my $negcaptcha = $input->param('negcap');
39 my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0;
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 suggested_by_anyone
>;
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") or ( C4
::Context
->preference("OPACViewOthersSuggestions") and $op eq 'else' ) ) {
61 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
63 template_name
=> "opac-suggestions.tt",
66 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
71 ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
73 template_name
=> "opac-suggestions.tt",
81 if ( $op eq 'else' ) {
82 if ( C4
::Context
->preference("OPACViewOthersSuggestions") ) {
83 if ( $borrowernumber ) {
84 # A logged in user is able to see suggestions from others
85 $suggestion->{suggestedby
} = $suggested_by_anyone
90 # Non logged in user is able to see all suggestions
91 $suggestion->{suggestedby
} = undef;
95 if ( $borrowernumber ) {
96 $suggestion->{suggestedby
} = $borrowernumber;
99 $suggestion->{suggestedby
} = -1;
103 if ( $borrowernumber ) {
104 $suggestion->{suggestedby
} = $borrowernumber;
107 $suggestion->{suggestedby
} = C4
::Context
->preference("AnonymousPatron");
111 my $suggestions_loop =
112 &SearchSuggestion
( $suggestion);
113 if ( $op eq "add_confirm" ) {
114 if (@
$suggestions_loop>=1){
115 #some suggestion are answering the request Donot Add
116 for my $suggestion ( @
$suggestions_loop ) {
117 push @messages, { type
=> 'error', code
=> 'already_exists', id
=> $suggestion->{suggestionid
} };
122 my $scrubber = C4
::Scrubber
->new();
123 foreach my $suggest (keys %$suggestion){
124 $suggestion->{$suggest} = $scrubber->scrub($suggestion->{$suggest});
126 $suggestion->{suggesteddate
} = dt_from_string
;
127 $suggestion->{branchcode
} = $input->param('branchcode') || C4
::Context
->userenv->{"branch"};
129 &NewSuggestion
($suggestion);
130 # empty fields, to avoid filter in "SearchSuggestion"
131 $$suggestion{$_}='' foreach qw
<title author publishercode copyrightdate place collectiontitle isbn STATUS
>;
133 &SearchSuggestion
( $suggestion );
134 push @messages, { type
=> 'info', code
=> 'success_on_inserted' };
139 if ( $op eq "delete_confirm" ) {
140 my @delete_field = $input->param("delete_field");
141 foreach my $delete_field (@delete_field) {
142 &DelSuggestion
( $borrowernumber, $delete_field );
145 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
148 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo
($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @
$suggestions_loop;
149 my $supportlist=GetSupportList
();
150 foreach my $support(@
$supportlist){
151 if ($$support{'imageurl'}){
152 $$support{'imageurl'}= getitemtypeimagelocation
( 'opac', $$support{'imageurl'} );
155 delete $$support{'imageurl'}
159 foreach my $suggestion(@
$suggestions_loop) {
160 if($suggestion->{'suggestedby'} == $borrowernumber) {
161 $suggestion->{'showcheckbox'} = $borrowernumber;
163 $suggestion->{'showcheckbox'} = 0;
165 if($suggestion->{'patronreason'}){
166 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib
("OPAC_SUG",$suggestion->{'patronreason'},1);
170 my $patron_reason_loop = GetAuthorisedValues
("OPAC_SUG");
172 # Is the person allowed to choose their branch
173 if ( C4
::Context
->preference("AllowPurchaseSuggestionBranchChoice") ) {
174 my ( $borr ) = GetMemberDetails
( $borrowernumber );
176 # pass the pickup branch along....
178 if (C4
::Context
->userenv && C4
::Context
->userenv->{'branch'}) {
179 $userbranch = C4
::Context
->userenv->{'branch'};
181 my $branchcode = $input->param('branchcode') || $borr->{'branchcode'} || $userbranch || '' ;
183 # make branch selection options...
184 my $branchloop = GetBranchesLoop
($branchcode);
185 $template->param( branchloop
=> $branchloop );
190 itemtypeloop
=> $supportlist,
191 suggestions_loop
=> $suggestions_loop,
192 patron_reason_loop
=> $patron_reason_loop,
195 messages
=> \
@messages,
196 suggestionsview
=> 1,
197 suggested_by_anyone
=> $suggested_by_anyone,
200 output_html_with_http_headers
$input, $cookie, $template->output;