-my $dbh = C4::Context->dbh;
-my ($template, $borrowernumber, $cookie)
- = get_template_and_user({template_name => "opac-suggestions.tmpl",
- type => "opac",
- query => $input,
- authnotrequired => 1,
- flagsrequired => {borrow => 1},
- });
-if ($op eq "add_confirm") {
- &newsuggestion($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn);
- # empty fields, to avoid filter in "searchsuggestion"
- $title='';
- $author='';
- $publishercode='';
- $copyrightdate ='';
- $volumedesc = '';
- $publicationyear = '';
- $place = '';
- $isbn = '';
- $op='else';
+my ( $template, $borrowernumber, $cookie );
+my $deleted = $input->param('deleted');
+my $submitted = $input->param('submitted');
+
+if ( C4::Context->preference("AnonSuggestions") ) {
+ ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+ {
+ template_name => "opac-suggestions.tmpl",
+ query => $input,
+ type => "opac",
+ authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
+ }
+ );
+ if ( !$$suggestion{suggestedby} ) {
+ $$suggestion{suggestedby} = C4::Context->preference("AnonymousPatron");
+ }
+}
+else {
+ ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+ {
+ template_name => "opac-suggestions.tmpl",
+ query => $input,
+ type => "opac",
+ authnotrequired => 0,
+ }
+ );
+}
+if ($allsuggestions){
+ delete $$suggestion{suggestedby};
+}
+else {
+ $$suggestion{suggestedby} ||= $borrowernumber unless ($allsuggestions);
+}
+# warn "bornum:",$borrowernumber;
+
+my $suggestions_loop =
+ &SearchSuggestion( $suggestion);
+if ( $op eq "add_confirm" ) {
+ if (@$suggestions_loop>=1){
+ #some suggestion are answering the request Donot Add
+ }
+ else {
+ my $scrubber = C4::Scrubber->new();
+ foreach my $suggest (keys %$suggestion){
+ $suggestion->{$suggest} = $scrubber->scrub($suggestion->{$suggest});
+ }
+ $$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;