From bab31936d136a9e1d0462baa63b61649cc4c9a90 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 17 Dec 2021 02:06:51 +0000 Subject: [PATCH] Bug 15326: Using AdditionalContents for custom pages on OPAC This page utilises the Additional Contents feature to add custom pages to the staff client and the OPAC in the user's desired language. To test: 1. Apply patch and restart services 2. In the staff client, go to Tools, then go to the new 'Pages' page 3. Add a new page to display on both the staff client and OPAC. 4. Notice the 'View' button in the Actions column. This button should only show when viewing Pages, it should not show when viewing HTML customisations or News. Test that the main View button links you to the page in the staff client. Test that clicking the arrow shows a button to view the page in the OPAC, and clicking it opens the OPAC in a new tab. 5. When viewing your new page in the staff client, confirm a Pages navigation shows in the left navigation. 6. When viewing your new page in the OPAC, confirm a Pages navigation shows in the left navigation. Confirm pages are also linked in the masthead links (i.e. with Advanced search and Libraries etc). 7. Confirm that any pages made for the staff client only do not show in the OPAC, and that any pages made for the OPAC only do not show in the staff client. 8. Pages that can be viewed on the staff client will also show under the Pages link on the Tools main page. Sponsored-by: Catalyst IT --- Koha/AdditionalContents.pm | 3 +- Koha/Template/Plugin/AdditionalContents.pm | 4 ++ .../intranet-tmpl/prog/en/includes/pages-nav.inc | 10 +++ .../intranet-tmpl/prog/en/includes/tools-menu.inc | 1 + .../prog/en/modules/tools/additional-contents.tt | 53 +++++++++++--- .../intranet-tmpl/prog/en/modules/tools/page.tt | 64 +++++++++++++++++ .../prog/en/modules/tools/tools-home.tt | 10 +++ koha-tmpl/intranet-tmpl/prog/js/tools-menu.js | 2 + .../opac-tmpl/bootstrap/en/includes/masthead.inc | 12 ++++ .../opac-tmpl/bootstrap/en/modules/opac-page.tt | 83 ++++++++++++++++++++++ opac/opac-page.pl | 67 +++++++++++++++++ tools/page.pl | 64 +++++++++++++++++ tools/tools-home.pl | 16 ++++- 13 files changed, 376 insertions(+), 13 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/pages-nav.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/page.tt create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-page.tt create mode 100755 opac/opac-page.pl create mode 100755 tools/page.pl diff --git a/Koha/AdditionalContents.pm b/Koha/AdditionalContents.pm index 711b187ad3..2bae923954 100644 --- a/Koha/AdditionalContents.pm +++ b/Koha/AdditionalContents.pm @@ -38,7 +38,7 @@ Koha::AdditionalContents - Koha Additional content object set class =head3 search_for_display my $contents = Koha::AdditionalContents->search_for_display({ - category => 'news', # news or html_customizations + category => 'news', # news, html_customizations, or pages location => 'slip', lang => 'es-ES', library_id => $branchcode @@ -75,6 +75,7 @@ sub search_for_display { $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' }; $search_params->{-or} = [ expirationdate => { '>=' => \'CAST(NOW() AS DATE)' }, expirationdate => undef ]; + $search_params->{category} = $params->{category}; if ( $params->{lang} ) { # FIXME I am failing to translate the following query diff --git a/Koha/Template/Plugin/AdditionalContents.pm b/Koha/Template/Plugin/AdditionalContents.pm index c37abece4e..8f2821d456 100644 --- a/Koha/Template/Plugin/AdditionalContents.pm +++ b/Koha/Template/Plugin/AdditionalContents.pm @@ -46,6 +46,10 @@ sub get { } ); + if ( $category and $category eq 'pages' ) { + return $content->unblessed; + } + if ( $content->count ) { return { content => $content, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/pages-nav.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/pages-nav.inc new file mode 100644 index 0000000000..b3105c19eb --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/pages-nav.inc @@ -0,0 +1,10 @@ +[% IF ( pages.count ) %] + [% IF show_heading %]

Pages

[% END %] + +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc index 0b5f33110f..67c8939ead 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc @@ -109,6 +109,7 @@ [% IF ( CAN_user_tools_edit_additional_contents ) %]
  • News
  • HTML customizations
  • +
  • Pages
  • [% END %] [% IF ( CAN_user_tools_schedule_tasks ) %]
  • Task scheduler
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt index c1a5a01a1c..0bd0be5af4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt @@ -39,6 +39,8 @@
  • [% IF category == 'news' %] News + [% ELSIF category == 'pages' %] + Pages [% ELSE %] HTML customizations [% END %] @@ -50,7 +52,7 @@ [% ELSE %] Add additional content [% END %] - ([% IF category == 'news' %]News[% ELSE %]HTML customizations[% END %]) + ([% IF category == 'news' %]News[% ELSIF category == 'pages' %]Pages[% ELSE %]HTML customizations[% END %])
  • [% ELSE %] @@ -58,6 +60,8 @@ [% IF category == 'news' %] News + [% ELSIF category == 'pages' %] + Pages [% ELSE %] HTML customizations [% END %] @@ -160,7 +164,7 @@ [% IF additional_content %]

    Modify an additional content

    [% ELSE %] -

    New additional content ([% IF category == 'news' %]News[% ELSE %]HTML customizations[% END %])

    +

    New additional content ([% IF category == 'news' %]News[% ELSIF category == 'pages' %]Pages[% ELSE %]HTML customizations[% END %])

    [% END %]
    @@ -169,6 +173,8 @@
    [% IF category == 'news' %]
    Cancel + [% ELSIF category == 'pages' %] + Cancel [% ELSE %] Cancel [% END %] @@ -289,11 +295,13 @@ -

    Additional contents ([% IF category == 'news' %]News[% ELSE %]HTML customizations[% END %])

    +

    Additional contents ([% IF category == 'news' %]News[% ELSIF category == 'pages' %]Pages[% ELSE %]HTML customizations[% END %])

    [% IF category == 'news' %] - See HTML customizations + See HTML customizations or Pages + [% ELSIF category == 'pages' %] + See HTML customizations or News [% ELSE %] - See News + See News or Pages [% END %] [% IF additional_contents.count %] @@ -320,7 +328,7 @@ - [% IF c.category == 'news' %] + [% IF c.category == 'news' || c.category == 'pages' %] [% IF c.location == 'staff_and_opac' %]All [% ELSIF c.location == 'staff_only' %]Librarian interface [% ELSIF c.location == 'opac_only' %]OPAC @@ -379,6 +387,27 @@
    Delete
    + [% IF c.category == 'pages' %] +
    + [% IF c.location == 'opac_only' %] + View + [% ELSE %] + View + [% END %] + [% IF c.location == 'staff_and_opac' %] + + [% END %] +
    + [% END %] [% END %] @@ -399,7 +428,7 @@ [% END %] [% BLOCK locations_options %] - [% IF category == 'news' %] + [% IF category == 'news' || category == 'pages' %] [% IF location == "staff_and_opac" %] [% ELSE %] @@ -418,10 +447,12 @@ [% END %] - [% IF location == "slip" %] - - [% ELSE %] - + [% UNLESS category == 'pages' %] + [% IF location == "slip" %] + + [% ELSE %] + + [% END %] [% END %] [% ELSE %] [% FOREACH l IN [ 'OpacNavRight', 'opacheader', 'OpacCustomSearch', 'OpacMainUserBlock', 'opaccredits', 'OpacLoginInstructions', 'OpacNav', 'OpacNavBottom', 'OpacSuggestionInstructions', 'ArticleRequestsDisclaimerText' ] %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/page.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/page.tt new file mode 100644 index 0000000000..172da7f5d6 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/page.tt @@ -0,0 +1,64 @@ +[% USE raw %] +[% USE Asset %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +[% IF page %][% page.title | html %][% ELSE %]Page error[% END %] › Tools › Koha +[% INCLUDE 'doc-head-close.inc' %] + + + + [% INCLUDE 'header.inc' %] + [% INCLUDE 'cat-search.inc' %] + + + +
    +
    +
    +
    + + [% IF page %] + +

    [% page.title | html %]

    + +
    + [% page.content | $raw %] +
    + + [% ELSE %] + +
    + This page does not exist. +
    + + [% END %] + +
    +
    + +
    + +
    +
    + +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/tools-menu.js") | $raw %] +[% END %] + +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt index 5d0d7f84cb..af630ae493 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt @@ -5,6 +5,12 @@ [% INCLUDE 'doc-head-open.inc' %] Tools › Koha [% INCLUDE 'doc-head-close.inc' %] + [% INCLUDE 'header.inc' %] @@ -120,6 +126,10 @@
    HTML customizations
    Write HTML customizations
    + +
    Pages
    +
    Write custom pages
    + [% INCLUDE 'pages-nav.inc' %] [% END %] [% IF ( CAN_user_tools_schedule_tasks ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/tools-menu.js b/koha-tmpl/intranet-tmpl/prog/js/tools-menu.js index 14325b6f9d..d5d0382e26 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/tools-menu.js +++ b/koha-tmpl/intranet-tmpl/prog/js/tools-menu.js @@ -18,5 +18,7 @@ $('#navmenulist a[href$="/cgi-bin/koha/tools/stockrotation.pl"]').addClass("current"); } else if (path.indexOf("plugins") >= 0 ) { $('#navmenulist a[href$="/cgi-bin/koha/plugins/plugins-home.pl?method=tool"]').addClass("current"); + } else if (path.indexOf("page.pl") >= 0 ) { + $('#navmenulist a[href$="/cgi-bin/koha/tools/additional-contents.pl?category=pages"]').addClass("current"); } }); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc index c2cf93a090..885361c7c2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc @@ -8,6 +8,7 @@ [% SET OpacHeader = AdditionalContents.get( location => "opacheader", lang => lang, library => logged_in_user.branchcode, blocktitle => 0 ) %] [% SET OpacCustomSearch = AdditionalContents.get( location => "OpacCustomSearch", lang => lang, library => logged_in_user.branchcode, blocktitle => 0 ) %] [% SET OpacLoginInstructions = AdditionalContents.get( location => "OpacLoginInstructions", lang => lang, library => branchcode ) %] +[% SET pages = AdditionalContents.get( category => "pages", location => [ "opac_only", "staff_and_opac" ], lang => lang, library => branchcode ) %]
    @@ -352,6 +353,17 @@ [% END %] + [% IF pages %] +
    + [% FOREACH page IN pages %] + + [% END %] +
    + [% END %] [% Koha.Preference('OpacMoreSearches') | $raw %]
    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-page.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-page.tt new file mode 100644 index 0000000000..9a8a976550 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-page.tt @@ -0,0 +1,83 @@ +[% USE raw %] +[% USE Koha %] +[% USE AdditionalContents %] +[% PROCESS 'i18n.inc' %] +[% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode, blocktitle => 0 ) %] +[% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode, blocktitle => 0 ) %] +[% INCLUDE 'doc-head-open.inc' %] +[% IF page %][% page.title | html %][% ELSE %]Page error[% END %] › [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog +[% INCLUDE 'doc-head-close.inc' %] +[% BLOCK cssinclude %][% END %] + +[% INCLUDE 'bodytag.inc' bodyid='opac-page-' _ page.idnew %] +[% INCLUDE 'masthead.inc' %] + +
    + + +
    +
    + [% IF ( OpacNav || OpacNavBottom || pages.count ) %] +
    + +
    +
    + [% ELSE %] +
    + [% END %] +
    + + [% IF page %] + +

    [% page.title | html %]

    + +
    + [% page.content | $raw %] +
    + + [% ELSE %] + +
    + This page does not exist. +
    + + [% END %] + +
    + +
    +
    +
    + +[% INCLUDE 'opac-bottom.inc' %] +[% BLOCK jsinclude %][% END %] diff --git a/opac/opac-page.pl b/opac/opac-page.pl new file mode 100755 index 0000000000..eab3584441 --- /dev/null +++ b/opac/opac-page.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use CGI qw ( -utf8 ); +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_html_with_http_headers ); +use Koha::AdditionalContents; + +my $query = CGI->new(); + +my $branchcode = $query->param('branchcode'); + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-page.tt", + query => $query, + type => "opac", + authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), + } +); + +my $homebranch; +if (C4::Context->userenv) { + $homebranch = C4::Context->userenv->{'branch'}; +} +my $pages = Koha::AdditionalContents->search_for_display( + { + category => 'pages', + location => [ 'opac_only', 'staff_and_opac' ], + lang => $template->lang, + library_id => $homebranch + } +); + +my $page_id = $query->param('page_id'); + +my $page; +if ( $page_id ) { + foreach ( @{$pages->unblessed} ) { + if ( $_->{idnew} eq $page_id ) { + $page = $_; + } + } +} + +$template->param( + pages => $pages, + page => $page, +); + +output_html_with_http_headers $query, $cookie, $template->output; diff --git a/tools/page.pl b/tools/page.pl new file mode 100755 index 0000000000..18102b288b --- /dev/null +++ b/tools/page.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use CGI qw ( -utf8 ); +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_html_with_http_headers ); +use Koha::AdditionalContents; + +my $query = CGI->new; +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "tools/page.tt", + query => $query, + type => "intranet", + flagsrequired => { tools => '*' }, + } +); + +my $homebranch; +if (C4::Context->userenv) { + $homebranch = C4::Context->userenv->{'branch'}; +} +my $pages = Koha::AdditionalContents->search_for_display( + { + category => 'pages', + location => [ 'staff_only', 'staff_and_opac' ], + lang => $template->lang, + library_id => $homebranch + } +); + +my $page_id = $query->param('page_id'); + +my $page; +if ( $page_id ) { + foreach ( @{$pages->unblessed} ) { + if ( $_->{idnew} eq $page_id ) { + $page = $_; + } + } +} + +$template->param( + pages => $pages, + page => $page, +); + +output_html_with_http_headers $query, $cookie, $template->output; diff --git a/tools/tools-home.pl b/tools/tools-home.pl index 842ae68874..17734d2708 100755 --- a/tools/tools-home.pl +++ b/tools/tools-home.pl @@ -36,9 +36,23 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $pendingcomments = Koha::Reviews->search_limited({ approved => 0 })->count; my $pendingtags = get_count_by_tag_status(0); +my $homebranch; +if (C4::Context->userenv) { + $homebranch = C4::Context->userenv->{'branch'}; +} +my $pages = Koha::AdditionalContents->search_for_display( + { + category => 'pages', + location => [ 'staff_only', 'staff_and_opac' ], + lang => $template->lang, + library_id => $homebranch + } +); + $template->param( pendingcomments => $pendingcomments, - pendingtags => $pendingtags + pendingtags => $pendingtags, + pages => $pages, ); if ( C4::Context->config('enable_plugins') ) { -- 2.11.0