Bug 14329: Useless copy/pasta from Template::Plugin::HtmlToText
[koha.git] / opac / opac-suggestions.pl
blobd55ef3dfac016eb825965cd14bac93516ab4fe9e
1 #!/usr/bin/perl
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>.
18 use strict;
19 use warnings;
21 use CGI;
22 use C4::Auth; # get_template_and_user
23 use C4::Members;
24 use C4::Branch;
25 use C4::Koha;
26 use C4::Output;
27 use C4::Suggestions;
28 use C4::Koha;
29 use C4::Dates;
30 use C4::Scrubber;
32 use Koha::DateUtils qw( dt_from_string );
34 my $input = new CGI;
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.
42 if ($negcaptcha ) {
43 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl");
44 exit;
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");
50 exit;
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",
64 query => $input,
65 type => "opac",
66 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
69 if ( !$$suggestion{suggestedby} ) {
70 $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron");
73 else {
74 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
76 template_name => "opac-suggestions.tt",
77 query => $input,
78 type => "opac",
79 authnotrequired => 0,
83 if ($allsuggestions){
84 delete $$suggestion{suggestedby};
86 else {
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} };
98 last;
101 else {
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>;
112 $suggestions_loop =
113 &SearchSuggestion( $suggestion );
114 push @messages, { type => 'info', code => 'success_on_inserted' };
116 $op = 'else';
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 );
124 $op = 'else';
125 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
126 exit;
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'} );
134 else {
135 delete $$support{'imageurl'}
139 foreach my $suggestion(@$suggestions_loop) {
140 if($suggestion->{'suggestedby'} == $borrowernumber) {
141 $suggestion->{'showcheckbox'} = $borrowernumber;
142 } else {
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....
157 my $userbranch = '';
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 );
168 $template->param(
169 %$suggestion,
170 itemtypeloop=> $supportlist,
171 suggestions_loop => $suggestions_loop,
172 patron_reason_loop => $patron_reason_loop,
173 showall => $allsuggestions,
174 "op_$op" => 1,
175 $op => 1,
176 messages => \@messages,
177 suggestionsview => 1,
180 output_html_with_http_headers $input, $cookie, $template->output;