@@ -, +, @@ suggestion (staff side) --- C4/Suggestions.pm | 2 +- .../prog/en/modules/suggestion/suggestion.tt | 32 +++++++- suggestion/suggestion.pl | 96 +++++++++++++--------- 3 files changed, 90 insertions(+), 40 deletions(-) --- a/C4/Suggestions.pm +++ a/C4/Suggestions.pm @@ -688,7 +688,7 @@ sub MarcRecordFromNewSuggestion { } else { $record->append_fields( - MARC::Field->new($it_tag, ' ', ' ', $it_subfield => $suggestion->{author}) + MARC::Field->new($it_tag, ' ', ' ', $it_subfield => $suggestion->{itemtype}) ); } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -239,6 +239,16 @@ [% END %] [% IF ( op_save ) %] + [% FOR m IN messages %] +
+ [% SWITCH m.code %] + [% CASE 'biblio_exists' %] + A similar document already exists: [% m.title %]. Click on "Confirm your suggestion" to ignore this message. + [% CASE %] + [% m.code %] + [% END %] +
+ [% END %]
@@ -410,7 +420,25 @@ -
[% IF ( suggestionid ) %] Cancel[% ELSE %] Cancel[% END %] +
+ + [% IF ( suggestionid ) %] + [% IF ( need_confirm ) %] + + + [% ELSE %] + + [% END %] + Cancel + [% ELSE %] + [% IF ( need_confirm ) %] + + + [% ELSE %] + + [% END %] + Cancel + [% END %]
[% END %] @@ -428,6 +456,8 @@ [% SWITCH m.code %] [% CASE 'already_exists' %] The suggestion has not been added. A suggestion with this title already exists (suggestion #[% m.id | html %]) + [% CASE 'biblio_exists' %] + A similar document already exists: [% m.title %]. Click on "Confirm your suggestion" to ignore this message. [% CASE %] [% m.code | html %] [% END %] --- a/suggestion/suggestion.pl +++ a/suggestion/suggestion.pl @@ -91,6 +91,8 @@ my $returnsuggested = $input->param('returnsuggested'); my $managedby = $input->param('managedby'); my $displayby = $input->param('displayby') || ''; my $tabcode = $input->param('tabcode'); +my $save_confirmed = $input->param('save_confirmed') || 0; + my $reasonsloop = GetAuthorisedValues("SUGGEST"); # filter informations which are not suggestion related. @@ -122,57 +124,75 @@ my $branchfilter = $input->param('branchcode') || C4::Context->userenv->{'branch ######################################### ## Operations ## + if ( $op =~ /save/i ) { - $suggestion_only->{suggesteddate} = dt_from_string( $suggestion_only->{suggesteddate} ) - if $suggestion_only->{suggesteddate}; + my @messages; + my $biblio = MarcRecordFromNewSuggestion({ + title => $suggestion_only->{title}, + author => $suggestion_only->{author}, + itemtype => $suggestion_only->{itemtype}, + }); + + if ( ( my ($duplicatebiblionumber, $duplicatetitle) = FindDuplicate($biblio) ) && !$save_confirmed ) { + push @messages, { type => 'error', code => 'biblio_exists', id => $duplicatebiblionumber, title => $duplicatetitle }; + $template->param( + messages => \@messages, + need_confirm => 1 + ); + delete $suggestion_ref->{suggesteddate}; + Init($suggestion_ref); + } + else { + $suggestion_only->{suggesteddate} = dt_from_string( $suggestion_only->{suggesteddate} ) + if $suggestion_only->{suggesteddate}; - 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}; + 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}; } - $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; - } + my $otherreason = $input->param('other_reason'); + if ($suggestion_only->{reason} eq 'other' && $otherreason) { + $suggestion_only->{reason} = $otherreason; + } - if ( $suggestion_only->{'suggestionid'} > 0 ) { - &ModSuggestion($suggestion_only); - } 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} }; + if ( $suggestion_only->{'suggestionid'} > 0 ) { + &ModSuggestion($suggestion_only); + } 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); } - $template->param( messages => \@messages ); - } - else { - ## Adding some informations related to suggestion - &NewSuggestion($suggestion_only); + # empty fields, to avoid filter in "SearchSuggestion" } - # empty fields, to avoid filter in "SearchSuggestion" - } - map{delete $$suggestion_ref{$_}} keys %$suggestion_ref; - $op = 'else'; + map{delete $$suggestion_ref{$_}} keys %$suggestion_ref; + $op = 'else'; - if( $redirect eq 'purchase_suggestions' ) { - print $input->redirect("/cgi-bin/koha/members/purchase-suggestions.pl?borrowernumber=$borrowernumber"); + if( $redirect eq 'purchase_suggestions' ) { + print $input->redirect("/cgi-bin/koha/members/purchase-suggestions.pl?borrowernumber=$borrowernumber"); + } } - } elsif ($op=~/add/) { - #Adds suggestion + #Adds suggestion Init($suggestion_ref); $op ='save'; -} +} elsif ($op=~/edit/) { #Edit suggestion $suggestion_ref=&GetSuggestion($$suggestion_ref{'suggestionid'}); --