@@ -, +, @@ borrower type --- C4/Auth.pm | 10 ++++++-- Koha/Patron/Category.pm | 25 +++++++++++++++++++ .../en/modules/admin/preferences/opac.pref | 7 +++++- .../en/includes/opac-detail-sidebar.inc | 2 +- .../bootstrap/en/includes/usermenu.inc | 2 +- opac/opac-suggestions.pl | 12 ++++----- 6 files changed, 47 insertions(+), 11 deletions(-) --- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -499,6 +499,12 @@ sub get_template_and_user { # these template parameters are set the same regardless of $in->{'type'} + # Decide if the patron can make suggestions in the OPAC + my $can_make_suggestions; + if ( C4::Context->userenv && C4::Context->userenv->{'number'} ) { + $can_make_suggestions = Koha::Patrons->find(C4::Context->userenv->{'number'})->category->can_make_suggestions; + } + my $minPasswordLength = C4::Context->preference('minPasswordLength'); $minPasswordLength = 3 if not $minPasswordLength or $minPasswordLength < 3; $template->param( @@ -537,7 +543,7 @@ sub get_template_and_user { intranetstylesheet => C4::Context->preference("intranetstylesheet"), IntranetUserCSS => C4::Context->preference("IntranetUserCSS"), IntranetUserJS => C4::Context->preference("IntranetUserJS"), - suggestion => C4::Context->preference("suggestion"), + suggestion => $can_make_suggestions, virtualshelves => C4::Context->preference("virtualshelves"), StaffSerialIssueDisplayCount => C4::Context->preference("StaffSerialIssueDisplayCount"), EasyAnalyticalRecords => C4::Context->preference('EasyAnalyticalRecords'), @@ -627,7 +633,7 @@ sub get_template_and_user { OpenLibrarySearch => C4::Context->preference("OpenLibrarySearch"), ShowReviewer => C4::Context->preference("ShowReviewer"), ShowReviewerPhoto => C4::Context->preference("ShowReviewerPhoto"), - suggestion => "" . C4::Context->preference("suggestion"), + suggestion => $can_make_suggestions, virtualshelves => "" . C4::Context->preference("virtualshelves"), OPACSerialIssueDisplayCount => C4::Context->preference("OPACSerialIssueDisplayCount"), SyndeticsClientCode => C4::Context->preference("SyndeticsClientCode"), --- a/Koha/Patron/Category.pm +++ a/Koha/Patron/Category.pm @@ -205,6 +205,31 @@ sub override_hidden_items { split( /\|/, C4::Context->preference('OpacHiddenItemsExceptions') ); } +=head3 can_make_suggestions + + + if ( $patron->category->can_make_suggestions ) { + ... + } + +Returns if the OPAC logged-in user is allowed to make OPAC purchase suggestions. + +=cut + +sub can_make_suggestions { + my ( $self ) = @_; + + if ( C4::Context->preference('suggestion') ) { + my @patron_categories = split ',', C4::Context->preference('suggestionPatronCategoryExceptions'); + if ( @patron_categories ) { + my $categorycode = $self->categorycode; + return if grep {$_ eq $categorycode } @patron_categories; + } + return 1; + } + return; +} + =head2 Internal methods =head3 _library_limits --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -427,7 +427,12 @@ OPAC: choices: 1: Allow 0: "Don't allow" - - patrons to make purchase suggestions on the OPAC. + - 'Patron categories allowed to make purchase suggestions on the OPAC:' + - + - 'Patron categories not affected by suggestion:' + - pref: suggestionPatronCategoryExceptions + choices: patron-categories + class: multiple - - pref: OPACComments choices: --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc +++ a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-detail-sidebar.inc @@ -38,7 +38,7 @@ [% END %] [% END %] - [% IF Koha.Preference('suggestion') %] + [% IF ( suggestion ) %]
  • Suggest for purchase
  • [% END %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc +++ a/koha-tmpl/opac-tmpl/bootstrap/en/includes/usermenu.inc @@ -83,7 +83,7 @@ your holds history [% END %] - [% IF Koha.Preference( 'suggestion' ) == 1 %] + [% IF ( suggestion ) %] [% IF ( suggestionsview ) %]
  • [% ELSE %] --- a/opac/opac-suggestions.pl +++ a/opac/opac-suggestions.pl @@ -69,12 +69,6 @@ if ($negcaptcha ) { exit; } -#If suggestions are turned off we redirect to 404 error. This will also redirect guest suggestions -if ( ! C4::Context->preference('suggestion') ) { - print $input->redirect("/cgi-bin/koha/errors/404.pl"); - exit; -} - my ( $template, $borrowernumber, $cookie, @messages ); my $deleted = $input->param('deleted'); my $submitted = $input->param('submitted'); @@ -99,6 +93,12 @@ else { ); } +# If suggestions are turned off, or this patron belongs to a category not allowed to make suggestions (suggestionPatronCategoryExceptions syspref) we redirect to 404 error. This will also redirect guest suggestions +if ( !Koha::Patrons->find( $borrowernumber )->category->can_make_suggestions ) { + print $input->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + my $suggested_by; if ( $op eq 'else' ) { if ( C4::Context->preference("OPACViewOthersSuggestions") ) { --