- if (@$suggestions_loop>=1){
- #some suggestion are answering the request Donot Add
- }
- else {
- $$suggestion{'suggesteddate'}=C4::Dates->today;
- $$suggestion{'branchcode'}= $input->param('branch') || C4::Context->userenv->{"branch"};
- &NewSuggestion($suggestion);
- # empty fields, to avoid filter in "SearchSuggestion"
- $$suggestion{$_}='' foreach qw<title author publishercode copyrightdate place collectiontitle isbn STATUS>;
- $suggestions_loop =
- &SearchSuggestion( $suggestion );
- }
- $op = 'else';
- print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else&submitted=1");
- exit;
+ if ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers
+ {
+ push @messages, { type => 'error', code => 'too_many' };
+ }
+ elsif ( @$suggestions_loop >= 1 ) {
+
+ #some suggestion are answering the request Donot Add
+ for my $suggestion (@$suggestions_loop) {
+ push @messages,
+ {
+ type => 'error',
+ code => 'already_exists',
+ id => $suggestion->{suggestionid}
+ };
+ last;
+ }
+ }
+ else {
+ my $scrubber = C4::Scrubber->new();
+ foreach my $suggest ( keys %$suggestion ) {
+
+ # Don't know why the encode is needed for Perl v5.10 here
+ $suggestion->{$suggest} = Encode::encode( "utf8",
+ $scrubber->scrub( $suggestion->{$suggest} ) );
+ }
+ $suggestion->{suggesteddate} = dt_from_string;
+ $suggestion->{branchcode} = $input->param('branchcode') || C4::Context->userenv->{"branch"};
+
+ &NewSuggestion($suggestion);
+ $patrons_pending_suggestions_count++;
+
+ # delete empty fields, to avoid filter in "SearchSuggestion"
+ foreach my $field ( qw( title author publishercode copyrightdate place collectiontitle isbn STATUS ) ) {
+ delete $suggestion->{$field}; #clear search filters (except borrower related) to show all suggestions after placing a new one
+ }
+ $suggestions_loop = &SearchSuggestion($suggestion);
+
+ push @messages, { type => 'info', code => 'success_on_inserted' };
+
+ }
+ $op = 'else';