Bug 5342: Serial claiming improvements: add a counter
[koha.git] / opac / opac-suggestions.pl
blob2801233a15029bbfab34a32d968e3d0be98f6678
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 my $input = new CGI;
33 my $allsuggestions = $input->param('showall');
34 my $op = $input->param('op');
35 my $suggestion = $input->Vars;
36 my $negcaptcha = $input->param('negcap');
38 # If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return.
39 if ($negcaptcha ) {
40 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl");
41 exit;
44 delete $$suggestion{$_} foreach qw<op suggestedbyme>;
45 $op = 'else' unless $op;
47 my ( $template, $borrowernumber, $cookie );
48 my $deleted = $input->param('deleted');
49 my $submitted = $input->param('submitted');
51 if ( C4::Context->preference("AnonSuggestions") ) {
52 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
54 template_name => "opac-suggestions.tt",
55 query => $input,
56 type => "opac",
57 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
60 if ( !$$suggestion{suggestedby} ) {
61 $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron");
64 else {
65 ( $template, $borrowernumber, $cookie ) = get_template_and_user(
67 template_name => "opac-suggestions.tt",
68 query => $input,
69 type => "opac",
70 authnotrequired => 0,
74 if ($allsuggestions){
75 delete $$suggestion{suggestedby};
77 else {
78 $$suggestion{suggestedby} ||= $borrowernumber unless ($allsuggestions);
80 # warn "bornum:",$borrowernumber;
82 my $suggestions_loop =
83 &SearchSuggestion( $suggestion);
84 if ( $op eq "add_confirm" ) {
85 if (@$suggestions_loop>=1){
86 #some suggestion are answering the request Donot Add
88 else {
89 my $scrubber = C4::Scrubber->new();
90 foreach my $suggest (keys %$suggestion){
91 $suggestion->{$suggest} = $scrubber->scrub($suggestion->{$suggest});
93 $$suggestion{'suggesteddate'}=C4::Dates->today;
94 $$suggestion{'branchcode'}= $input->param('branch') || C4::Context->userenv->{"branch"};
96 &NewSuggestion($suggestion);
97 # empty fields, to avoid filter in "SearchSuggestion"
98 $$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>;
99 $suggestions_loop =
100 &SearchSuggestion( $suggestion );
102 $op = 'else';
103 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
104 exit;
107 if ( $op eq "delete_confirm" ) {
108 my @delete_field = $input->param("delete_field");
109 foreach my $delete_field (@delete_field) {
110 &DelSuggestion( $borrowernumber, $delete_field );
112 $op = 'else';
113 print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&deleted=1");
114 exit;
116 map{ $_->{'branchcodesuggestedby'}=GetBranchInfo($_->{'branchcodesuggestedby'})->[0]->{'branchname'}} @$suggestions_loop;
117 my $supportlist=GetSupportList();
118 foreach my $support(@$supportlist){
119 if ($$support{'imageurl'}){
120 $$support{'imageurl'}= getitemtypeimagelocation( 'opac', $$support{'imageurl'} );
122 else {
123 delete $$support{'imageurl'}
127 foreach my $suggestion(@$suggestions_loop) {
128 if($suggestion->{'suggestedby'} == $borrowernumber) {
129 $suggestion->{'showcheckbox'} = $borrowernumber;
130 } else {
131 $suggestion->{'showcheckbox'} = 0;
133 if($suggestion->{'patronreason'}){
134 $suggestion->{'patronreason'} = GetKohaAuthorisedValueLib("OPAC_SUG",$suggestion->{'patronreason'},1);
138 my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG");
140 # Is the person allowed to choose their branch
141 if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
142 my ( $borr ) = GetMemberDetails( $borrowernumber );
144 # pass the pickup branch along....
145 my $userbranch = '';
146 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
147 $userbranch = C4::Context->userenv->{'branch'};
149 my $branch = $input->param('branch') || $borr->{'branchcode'} || $userbranch || '' ;
151 # make branch selection options...
152 my $branchloop = GetBranchesLoop($branch);
153 $template->param( branchloop => $branchloop );
156 $template->param(
157 %$suggestion,
158 itemtypeloop=> $supportlist,
159 suggestions_loop => $suggestions_loop,
160 patron_reason_loop => $patron_reason_loop,
161 showall => $allsuggestions,
162 "op_$op" => 1,
163 suggestionsview => 1,
166 output_html_with_http_headers $input, $cookie, $template->output;