<div class="span10">
<div id="usersuggestions" class="maincontent">
[% IF ( op_add ) %]
- [% IF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]
+ [% IF ( Koha.Preference('MaxTotalSuggestions') != '' && patrons_total_suggestions_count >= Koha.Preference('MaxTotalSuggestions') ) %]
+ <h1 class="TooManySuggestions">You cannot place any more suggestions</h1>
+ <h2 class="TooManySuggestionsText">You may have only [% Koha.Preference('MaxTotalSuggestions') | html %] suggestions in last [% Koha.Preference('NumberOfSuggestionDays') | html %] days.</h2>
+ [% ELSIF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]
<h1 class="TooManySuggestions">You cannot place any more suggestions</h1>
<h2 class="TooManySuggestionsText">You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxOpenSuggestions') | html %]). Once the library has processed those suggestions you will be able to place more.</h2>
[% ELSE %]
[% FOR m IN messages %]
<div class="alert alert-[% m.type | html %]">
[% SWITCH m.code %]
+ [% CASE 'total_suggestions' %]
+ The suggestion has not been added. You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxTotalSuggestions') | html %] last [% Koha.Preference('NumberOfSuggestionDays') | html %] days).
[% CASE 'too_many' %]
The suggestion has not been added. You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxOpenSuggestions') | html %]). Once the library has processed those suggestions you will be able to place more.
[% CASE 'already_exists' %]
<input type="hidden" name="op" value="delete_confirm" />
[% IF ( loggedinusername || ( Koha.Preference( 'AnonSuggestions' ) == 1 ) ) %]
<div id="toolbar" class="toolbar clearfix">
- [% IF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]
+ [% IF ( Koha.Preference('MaxTotalSuggestions') != '' && patrons_total_suggestions_count >= Koha.Preference('MaxTotalSuggestions') ) %]
+ <p class="TooManySuggestionsText">You may have only <b>[% Koha.Preference('MaxTotalSuggestions') | html %]</b> suggestions in last <b>[% Koha.Preference('NumberOfSuggestionDays') | html %]</b> days.</p>
+ [% ELSIF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]
<p class="TooManySuggestionsText">You have reached your limit of suggestions you can place at this time ([% Koha.Preference('MaxOpenSuggestions') | html %]).</br>Once the library has processed those suggestions you will be able to place more.</p>
[% ELSE %]
<a class="btn btn-link new" href="/cgi-bin/koha/opac-suggestions.pl?op=add"><i class="fa fa-plus"></i> New purchase suggestion</a>
<p>There are no pending purchase suggestions.</p>
[% END %]
[% IF ( loggedinusername || ( Koha.Preference( 'AnonSuggestions' ) == 1 ) ) %]
- [% IF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]
+ [% IF ( Koha.Preference('MaxTotalSuggestions') != '' && patrons_total_suggestions_count >= Koha.Preference('MaxTotalSuggestions') ) %]
+ <p class="TooManySuggestionsText">You may have only <b>[% Koha.Preference('MaxTotalSuggestions') | html %]</b> suggestions in last <b>[% Koha.Preference('NumberOfSuggestionDays') | html %]</b> days.</p>
+ [% ELSIF ( Koha.Preference('MaxOpenSuggestions') != '' && patrons_pending_suggestions_count >= Koha.Preference('MaxOpenSuggestions') ) %]
<p class="TooManySuggestionsText">You have reached your limit of suggestions you can place at this time.</br>Once the library has processed those suggestions you will be able to place more.</p>
[% ELSE %]
<p><a class="btn btn-link new" href="/cgi-bin/koha/opac-suggestions.pl?op=add"><i class="fa fa-plus"></i> New purchase suggestion</a></p>
}
my $patrons_pending_suggestions_count = 0;
-if ( $borrowernumber && C4::Context->preference("MaxOpenSuggestions") ne '' ) {
- $patrons_pending_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, STATUS => 'ASKED' } ) } ;
+my $patrons_total_suggestions_count = 0;
+if ( $borrowernumber ){
+ if ( C4::Context->preference("MaxTotalSuggestions") ne '' && C4::Context->preference("NumberOfSuggestionDays") ne '' ) {
+ my $suggesteddate_from = dt_from_string()->subtract(days=>C4::Context->preference("NumberOfSuggestionDays"));
+ $patrons_total_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, suggesteddate_from => $suggesteddate_from } ) } ;
+ }
+ if ( C4::Context->preference("MaxOpenSuggestions") ne '' ) {
+ $patrons_pending_suggestions_count = scalar @{ SearchSuggestion( { suggestedby => $borrowernumber, STATUS => 'ASKED' } ) } ;
+ }
}
if ( $op eq "add_confirm" ) {
my $suggestions_loop = &SearchSuggestion($suggestion);
- if ( C4::Context->preference("MaxOpenSuggestions") ne '' && $patrons_pending_suggestions_count >= C4::Context->preference("MaxOpenSuggestions") ) #only check limit for signed in borrowers
+ if ( C4::Context->preference("MaxTotalSuggestions") ne '' && $patrons_total_suggestions_count >= C4::Context->preference("MaxTotalSuggestions") )
+ {
+ push @messages, { type => 'error', code => 'total_suggestions' };
+ }
+ elsif ( 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' };
}
&NewSuggestion($suggestion);
$patrons_pending_suggestions_count++;
+ $patrons_total_suggestions_count++;
# delete empty fields, to avoid filter in "SearchSuggestion"
foreach my $field ( qw( title author publishercode copyrightdate place collectiontitle isbn STATUS ) ) {
suggested_by_anyone => $suggested_by_anyone,
patrons_pending_suggestions_count => $patrons_pending_suggestions_count,
need_confirm => $need_confirm,
+ patrons_total_suggestions_count => $patrons_total_suggestions_count,
);
output_html_with_http_headers $input, $cookie, $template->output, undef, { force_no_caching => 1 };