Lines 29-34
use C4::Suggestions;
Link Here
|
29 |
use C4::Koha; |
29 |
use C4::Koha; |
30 |
use C4::Dates; |
30 |
use C4::Dates; |
31 |
use C4::Scrubber; |
31 |
use C4::Scrubber; |
|
|
32 |
use C4::Search qw( FindDuplicate ); |
32 |
|
33 |
|
33 |
use Koha::DateUtils qw( dt_from_string ); |
34 |
use Koha::DateUtils qw( dt_from_string ); |
34 |
|
35 |
|
Lines 38-43
my $suggestion = $input->Vars;
Link Here
|
38 |
delete $suggestion->{negcap}; |
39 |
delete $suggestion->{negcap}; |
39 |
my $negcaptcha = $input->param('negcap'); |
40 |
my $negcaptcha = $input->param('negcap'); |
40 |
my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0; |
41 |
my $suggested_by_anyone = $input->param('suggested_by_anyone') || 0; |
|
|
42 |
my $need_confirm = 0; |
41 |
|
43 |
|
42 |
# If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return. |
44 |
# If a spambot accidentally populates the 'negcap' field in the sugesstions form, then silently skip and return. |
43 |
if ($negcaptcha ) { |
45 |
if ($negcaptcha ) { |
Lines 51-57
if ( ! C4::Context->preference('suggestion') ) {
Link Here
|
51 |
exit; |
53 |
exit; |
52 |
} |
54 |
} |
53 |
|
55 |
|
54 |
delete $suggestion->{$_} foreach qw<op suggested_by_anyone>; |
56 |
delete $suggestion->{$_} foreach qw<op suggested_by_anyone confirm>; |
55 |
$op = 'else' unless $op; |
57 |
$op = 'else' unless $op; |
56 |
|
58 |
|
57 |
my ( $template, $borrowernumber, $cookie, @messages ); |
59 |
my ( $template, $borrowernumber, $cookie, @messages ); |
Lines 109-143
if ( $op eq 'else' ) {
Link Here
|
109 |
} |
111 |
} |
110 |
} |
112 |
} |
111 |
|
113 |
|
112 |
my $suggestions_loop = |
114 |
if ( $op eq "add_validate" ) { |
113 |
&SearchSuggestion( $suggestion); |
115 |
$op = 'add_confirm'; |
114 |
if ( $op eq "add_confirm" ) { |
116 |
my $suggestions = &SearchSuggestion($suggestion); |
115 |
if (@$suggestions_loop>=1){ |
117 |
my $biblio = MarcRecordFromSuggestion($suggestion); |
|
|
118 |
if (@$suggestions >=1 ){ |
116 |
#some suggestion are answering the request Donot Add |
119 |
#some suggestion are answering the request Donot Add |
117 |
for my $suggestion ( @$suggestions_loop ) { |
120 |
for my $suggestion ( @$suggestions ) { |
118 |
push @messages, { type => 'error', code => 'already_exists', id => $suggestion->{suggestionid} }; |
121 |
push @messages, { type => 'error', code => 'already_exists', id => $suggestion->{suggestionid} }; |
119 |
last; |
122 |
last; |
120 |
} |
123 |
} |
|
|
124 |
$op = 'else'; |
121 |
} |
125 |
} |
122 |
else { |
126 |
elsif (my ($duplicatebiblionumber, $duplicatetitle) = FindDuplicate($biblio)) { |
123 |
my $scrubber = C4::Scrubber->new(); |
127 |
push @messages, { type => 'error', code => 'biblio_exists', id => $duplicatebiblionumber, title => $duplicatetitle }; |
124 |
foreach my $suggest (keys %$suggestion){ |
128 |
$need_confirm = 1; |
125 |
# Don't know why the encode is needed for Perl v5.10 here |
129 |
$op = 'add'; |
126 |
$suggestion->{$suggest} = Encode::encode("utf8", $scrubber->scrub($suggestion->{$suggest}) ); |
130 |
} |
127 |
} |
131 |
} |
128 |
$suggestion->{suggesteddate} = dt_from_string; |
132 |
|
129 |
$suggestion->{branchcode} = $input->param('branchcode') || C4::Context->userenv->{"branch"}; |
133 |
if ($op eq "add_confirm") { |
130 |
|
134 |
my $scrubber = C4::Scrubber->new(); |
131 |
&NewSuggestion($suggestion); |
135 |
foreach my $suggest (keys %$suggestion) { |
132 |
# empty fields, to avoid filter in "SearchSuggestion" |
136 |
# Don't know why the encode is needed for Perl v5.10 here |
133 |
$$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>; |
137 |
$suggestion->{$suggest} = Encode::encode("utf8", $scrubber->scrub($suggestion->{$suggest}) ); |
134 |
$suggestions_loop = |
138 |
} |
135 |
&SearchSuggestion( $suggestion ); |
139 |
$suggestion->{suggesteddate} = dt_from_string; |
136 |
push @messages, { type => 'info', code => 'success_on_inserted' }; |
140 |
$suggestion->{branchcode} = $input->param('branchcode') || C4::Context->userenv->{"branch"}; |
137 |
} |
141 |
|
|
|
142 |
&NewSuggestion($suggestion); |
143 |
push @messages, { type => 'info', code => 'success_on_inserted' }; |
138 |
$op = 'else'; |
144 |
$op = 'else'; |
139 |
} |
145 |
} |
140 |
|
146 |
|
|
|
147 |
my $suggestions_loop = &SearchSuggestion({suggestedby => $suggestion->{suggestedby}}); |
141 |
if ( $op eq "delete_confirm" ) { |
148 |
if ( $op eq "delete_confirm" ) { |
142 |
my @delete_field = $input->param("delete_field"); |
149 |
my @delete_field = $input->param("delete_field"); |
143 |
foreach my $delete_field (@delete_field) { |
150 |
foreach my $delete_field (@delete_field) { |
Lines 189-195
if ( C4::Context->preference("AllowPurchaseSuggestionBranchChoice") ) {
Link Here
|
189 |
|
196 |
|
190 |
$template->param( |
197 |
$template->param( |
191 |
%$suggestion, |
198 |
%$suggestion, |
192 |
itemtypeloop=> $supportlist, |
199 |
placeitemtypeloop=> $supportlist, |
193 |
suggestions_loop => $suggestions_loop, |
200 |
suggestions_loop => $suggestions_loop, |
194 |
patron_reason_loop => $patron_reason_loop, |
201 |
patron_reason_loop => $patron_reason_loop, |
195 |
"op_$op" => 1, |
202 |
"op_$op" => 1, |
Lines 197-202
$template->param(
Link Here
|
197 |
messages => \@messages, |
204 |
messages => \@messages, |
198 |
suggestionsview => 1, |
205 |
suggestionsview => 1, |
199 |
suggested_by_anyone => $suggested_by_anyone, |
206 |
suggested_by_anyone => $suggested_by_anyone, |
|
|
207 |
need_confirm => $need_confirm, |
200 |
); |
208 |
); |
201 |
|
209 |
|
202 |
output_html_with_http_headers $input, $cookie, $template->output; |
210 |
output_html_with_http_headers $input, $cookie, $template->output; |