+
+ if ( $suggestion_only->{'suggestionid'} > 0 ) {
+
+ $suggestion_only->{lastmodificationdate} = dt_from_string;
+ $suggestion_only->{lastmodificationby} = C4::Context->userenv->{number};
+ $suggestion_only->{branchcode} = undef
+ if exists $suggestion_only->{branchcode}
+ && $suggestion_only->{branchcode} eq "";
+
+ &ModSuggestion($suggestion_only);
+
+ if ( $notify ) {
+ my $patron = Koha::Patrons->find( $suggestion_only->{managedby} );
+ my $email_address = $patron->notice_email_address;
+ if ($patron->notice_email_address) {
+
+ my $letter = C4::Letters::GetPreparedLetter(
+ module => 'suggestions',
+ letter_code => 'NOTIFY_MANAGER',
+ branchcode => $patron->branchcode,
+ lang => $patron->lang,
+ tables => {
+ suggestions => $suggestion_only->{suggestionid},
+ branches => $patron->branchcode,
+ borrowers => $patron->borrowernumber,
+ },
+ );
+ C4::Letters::EnqueueLetter(
+ {
+ letter => $letter,
+ borrowernumber => $patron->borrowernumber,
+ message_transport_type => 'email'
+ }
+ );
+ }
+ }
+ } else {
+ ###FIXME:Search here if suggestion already exists.
+ my $suggestions= Koha::Suggestions->search_limited( $suggestion_only );
+ if ( $suggestions->count ) {
+ #some suggestion are answering the request Donot Add
+ my @messages;
+ while ( my $suggestion = $suggestions->next ) {
+ push @messages, { type => 'error', code => 'already_exists', id => $suggestion->suggestionid };
+ }
+ $template->param( messages => \@messages );
+ }
+ else {
+ ## Adding some informations related to suggestion
+ &NewSuggestion($suggestion_only);
+ }
+ # empty fields, to avoid filter in "SearchSuggestion"
+ }
+ map{delete $$suggestion_ref{$_} unless $_ eq 'branchcode' } keys %$suggestion_ref;
+ $op = 'else';
+
+ if( $redirect eq 'purchase_suggestions' ) {
+ print $input->redirect("/cgi-bin/koha/members/purchase-suggestions.pl?borrowernumber=$borrowernumber");
+ }
+ }