Fix errors on Korean translation files
[koha.git] / opac / opac-suggestions.pl
blob2d89d9367c7acc2389103ae44a4340b73b1b03a1
1 #!/usr/bin/perl
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
8 # version.
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.
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 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",
58 query => $input,
59 type => "opac",
60 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
63 if ( !$$suggestion{suggestedby} ) {
64 $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron");
67 else {
68 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
70 template_name => "opac-suggestions.tt",
71 query => $input,
72 type => "opac",
73 authnotrequired => 0,
77 if ($allsuggestions){
78 delete $$suggestion{suggestedby};
80 else {
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
91 else {
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>;
102 $suggestions_loop =
103 &SearchSuggestion( $suggestion );
105 $op = 'else';
106 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
107 exit;
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 );
115 $op = 'else';
116 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&deleted=1");
117 exit;
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'} );
125 else {
126 delete $$support{'imageurl'}
130 foreach my $suggestion(@$suggestions_loop) {
131 if($suggestion->{'suggestedby'} == $borrowernumber) {
132 $suggestion->{'showcheckbox'} = $borrowernumber;
133 } else {
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....
148 my $userbranch = '';
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 );
159 $template->param(
160 %$suggestion,
161 itemtypeloop=> $supportlist,
162 suggestions_loop => $suggestions_loop,
163 patron_reason_loop => $patron_reason_loop,
164 showall => $allsuggestions,
165 "op_$op" => 1,
166 suggestionsview => 1,
169 output_html_with_http_headers $input, $cookie, $template->output;