+ if ( $suggestion_only->{"STATUS"} ) {
+ if ( my $tmpstatus = lc( $suggestion_only->{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) {
+ $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "date" } = dt_from_string;
+ $suggestion_only->{ lc( $suggestion_only->{"STATUS"}) . "by" } = C4::Context->userenv->{number};
+ }
+ $suggestion_only->{manageddate} = dt_from_string;
+ $suggestion_only->{"managedby"} ||= C4::Context->userenv->{number};
+ }
+
+ my $otherreason = $input->param('other_reason');
+ if ($suggestion_only->{reason} eq 'other' && $otherreason) {
+ $suggestion_only->{reason} = $otherreason;
+ }
+
+ if ( $suggestion_only->{'suggestionid'} > 0 ) {
+
+ $suggestion_only->{lastmodificationdate} = dt_from_string;
+ $suggestion_only->{lastmodificationby} = C4::Context->userenv->{number};
+
+ &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_loop =
+ SearchSuggestion( $suggestion_only );
+ if (@$suggestions_loop>=1){
+ #some suggestion are answering the request Donot Add
+ my @messages;
+ for my $suggestion ( @$suggestions_loop ) {
+ 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';