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. Confirm the URLs in the Page URL column work as expected.
5. 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.
6. Confirm that pages do not show on the OPAC main page where news items
show. Confirm news items show on the OPAC main page as expected.

Sponsored-by: Chartered Accountants Australia and New Zealand

Signed-off-by: Thibault Kero <thibault.keromnes@univ-paris8.fr>

Signed-off-by: Lisette Scheer <lisettePalouse+Koha@gmail.com>

Signed-off-by: Lisette Scheer <lisettePalouse+Koha@gmail.com>

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Aleisha Amohia 2021-12-17 02:06:51 +00:00 committed by Tomas Cohen Arazi
parent 5c1db538e6
commit 8de80449dd
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
9 changed files with 289 additions and 19 deletions

View file

@ -110,6 +110,7 @@
[% IF ( CAN_user_tools_edit_additional_contents ) %]
<li><a href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a></li>
<li><a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a></li>
<li><a href="/cgi-bin/koha/tools/additional-contents.pl?category=pages">Pages</a></li>
[% END %]
[% IF ( CAN_user_tools_schedule_tasks ) %]
<li><a href="/cgi-bin/koha/tools/scheduler.pl">Task scheduler</a></li>

View file

@ -24,6 +24,12 @@
.syspref-link::before {
content: " | ";
}
.customisation-link::before {
content: " | ";
}
.customisation-link:first-child::before {
content: none;
}
</style>
</head>
@ -44,6 +50,8 @@
<li>
[% IF category == 'news' %]
<a href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a>
[% ELSIF category == 'pages' %]
<a href="/cgi-bin/koha/tools/additional-contents.pl?category=pages">Pages</a>
[% ELSE %]
<a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a>
[% END %]
@ -55,7 +63,7 @@
[% ELSE %]
<span>Add additional content</span>
[% END %]
([% IF category == 'news' %]<span>News</span>[% ELSE %]<span>HTML customizations</span>[% END %])
([% IF category == 'news' %]<span>News</span>[% ELSIF category == 'pages' %]<span>Pages</span>[% ELSE %]<span>HTML customizations</span>[% END %])
</a>
</li>
[% ELSE %]
@ -63,6 +71,8 @@
<a href="#" aria-current="page">
[% IF category == 'news' %]
News
[% ELSIF category == 'pages' %]
Pages
[% ELSE %]
HTML customizations
[% END %]
@ -165,7 +175,7 @@
[% IF additional_content %]
<h1>Modify an additional content</h1>
[% ELSE %]
<h1>New additional content ([% IF category == 'news' %]News[% ELSE %]HTML customizations[% END %])</h1>
<h1>New additional content ([% IF category == 'news' %]News[% ELSIF category == 'pages' %]Pages[% ELSE %]HTML customizations[% END %])</h1>
[% END %]
<div id="toolbar" class="btn-toolbar">
@ -180,6 +190,8 @@
</div>
[% IF category == 'news' %]
<a class="btn btn-default cancel" href="/cgi-bin/koha/tools/additional-contents.pl"><i class="fa fa-remove"></i> Cancel</a>
[% ELSIF category == 'pages' %]
<a class="btn btn-default cancel" href="/cgi-bin/koha/tools/additional-contents.pl?category=pages"><i class="fa fa-remove"></i> Cancel</a>
[% ELSE %]
<a class="btn btn-default cancel" href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations"><i class="fa fa-remove"></i> Cancel</a>
[% END %]
@ -308,16 +320,17 @@
</div>
</div>
<h2>Additional contents ([% IF category == 'news' %]News[% ELSE %]HTML customizations[% END %])</h2>
[% IF category == 'news' %]
See <a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a>
[% ELSE %]
See <a href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a>
[% END %]
[% IF ( CAN_user_parameters_manage_sysprefs ) %]
<a class="syspref-link" href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=OPACUserJS'>OPACUserJS</a>
<a class="syspref-link" href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=OPACUserCSS'>OPACUserCSS</a>
[% END %]
<h2>Additional contents ([% IF category == 'news' %]News[% ELSIF category == 'pages' %]Pages[% ELSE %]HTML customizations[% END %])</h2>
<span id="additional_contents_links">
See
<a class="customisation-link" href="/cgi-bin/koha/tools/additional-contents.pl?category=news">News</a>
<a class="customisation-link" href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a>
<a class="customisation-link" href="/cgi-bin/koha/tools/additional-contents.pl?category=pages">Pages</a>
[% IF ( CAN_user_parameters_manage_sysprefs ) %]
<a class="syspref-link" href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=OPACUserJS'>OPACUserJS</a>
<a class="syspref-link" href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=OPACUserCSS'>OPACUserCSS</a>
[% END %]
</span>
[% IF additional_contents.count %]
<form id="del_form" method="post" action="/cgi-bin/koha/tools/additional-contents.pl">
@ -332,7 +345,12 @@
<th>Expiration date</th>
<th class="anti-the">Title</th>
<th>Author</th>
<th class="anti-the">News</th>
[% IF category == 'pages' %]
<th>Page URL</th>
<th class="anti-the">Page</th>
[% ELSE %]
<th class="anti-the">News</th>
[% END %]
<th class="NoSort noExport">Actions</th>
</tr>
</thead>
@ -343,7 +361,7 @@
<input type="checkbox" name="ids" value="[% c.idnew | html %]" />
</td>
<td>
[% IF c.category == 'news' %]
[% IF c.category == 'news' || c.category == 'pages' %]
[% IF c.location == 'staff_and_opac' %]<span>All</span>
[% ELSIF c.location == 'staff_only' %]<span>Librarian interface</span>
[% ELSIF c.location == 'opac_only' %]<span>OPAC</span>
@ -365,6 +383,18 @@
<td data-order="[% c.expirationdate | html %]">[% c.expirationdate | $KohaDates %] [% IF ( c.is_expired ) %](<span class="expired">expired</span>)[% END %]</td>
<td>[% c.title | html %]</td>
<td>[% IF ( c.author) %][% INCLUDE 'patron-title.inc' patron=c.author %][% END %]</td>
[% IF category == 'pages' %]
<td class="actions">
[% IF c.location == 'opac_only' %]
<strong>OPAC</strong>: <a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.idnew | uri %]" title="View on OPAC">[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.idnew | uri %]</a>
[% ELSIF c.location == 'staff_only' %]
<strong>Librarian interface</strong>: <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.idnew | uri %]" title="View on librarian interface">[% Koha.Preference('staffClientBaseURL') | url %]/cgi-bin/koha/tools/page.pl?page_id=[% c.idnew | uri %]</a>
[% ELSIF c.location == 'staff_and_opac' %]
<strong>OPAC</strong>: <a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.idnew | uri %]" title="View on OPAC">[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.idnew | uri %]</a><br>
<strong>Librarian interface</strong>: <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.idnew | uri %]" title="View on librarian interface">[% Koha.Preference('staffClientBaseURL') | url %]/cgi-bin/koha/tools/page.pl?page_id=[% c.idnew | uri %]</a>
[% END %]
</td>
[% END %]
<td>
<div class="btn-group">
<a class="preview_news btn btn-default btn-xs" data-number="[% loop.count | html %]"><i class="fa fa-eye" aria-hidden="true"></i> Preview content</a>
@ -422,7 +452,7 @@
[% END %]
[% BLOCK locations_options %]
[% IF category == 'news' %]
[% IF category == 'news' || category == 'pages' %]
[% IF location == "staff_and_opac" %]
<option value="staff_and_opac" selected="selected">Librarian and OPAC interfaces</option>
[% ELSE %]
@ -441,10 +471,12 @@
<option value="opac_only">OPAC</option>
[% END %]
[% IF location == "slip" %]
<option value="slip" selected="selected">Slip</option>
[% ELSE %]
<option value="slip">Slip</option>
[% UNLESS category == 'pages' %]
[% IF location == "slip" %]
<option value="slip" selected="selected">Slip</option>
[% ELSE %]
<option value="slip">Slip</option>
[% END %]
[% END %]
[% ELSE %]
[% FOREACH l IN [ 'OpacNavRight', 'opacheader', 'OpacCustomSearch', 'OpacMainUserBlock', 'opaccredits', 'OpacLoginInstructions', 'OpacNav', 'OpacNavBottom', 'OpacSuggestionInstructions', 'ArticleRequestsDisclaimerText', 'OpacMoreSearches', 'OpacMySummaryNote' ] %]

View file

@ -0,0 +1,62 @@
[% USE raw %]
[% USE Asset %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% IF page %][% page.title | html %][% ELSE %]Page error[% END %] &rsaquo; Tools &rsaquo; Koha</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body id="tools_page_[% page.idnew | html %]" class="tools">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
<ol>
<li>
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
</li>
<li>
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
</li>
<li>
<a href="#" aria-current="page">[% IF page %][% page.title | html %][% ELSE %]Page error[% END %]</a>
</li>
</ol>
</nav>
<div class="main container-fluid">
<div class="row">
<div class="col-sm-10 col-sm-push-2">
<main>
[% IF page %]
<h1>[% page.title | html %]</h1>
<div class="page">
[% page.content | $raw %]
</div>
[% ELSE %]
<div class="dialog alert">
This page does not exist.
</div>
[% END %]
</main>
</div> <!-- /.col-sm-10.col-sm-push-2 -->
<div class="col-sm-2 col-sm-pull-10">
<aside>
[% INCLUDE 'tools-menu.inc' %]
</aside>
</div> <!-- /.col-sm-2.col-sm-pull-10 -->
</div> <!-- /.row -->
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/tools-menu.js") | $raw %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]

View file

@ -121,6 +121,9 @@
<dt><a href="/cgi-bin/koha/tools/additional-contents.pl?category=html_customizations">HTML customizations</a></dt>
<dd>Write HTML customizations</dd>
<dt><a href="/cgi-bin/koha/tools/additional-contents.pl?category=pages">Pages</a></dt>
<dd>Write custom pages</dd>
[% END %]
[% IF ( CAN_user_tools_schedule_tasks ) %]

View file

@ -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");
}
});

View file

@ -100,6 +100,7 @@
<div id="news" class="newscontainer">
[% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'opac' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
[% FOREACH koha_new IN koha_news %]
[% IF koha_new.category == 'news' %]
<div class="newsitem">
<h4 class="newsheader">
[% IF ( news_item ) %]
@ -120,6 +121,7 @@
</div>
</div>
[% END %]
[% END %]
[% UNLESS news_item %]
<div id="rssnews-container">

View file

@ -0,0 +1,73 @@
[% 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' %]
<title>[% IF page %][% page.title | html %][% ELSE %]Page error[% END %] &rsaquo; [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title>
[% INCLUDE 'doc-head-close.inc' %]
[% BLOCK cssinclude %][% END %]
</head>
[% INCLUDE 'bodytag.inc' bodyid='opac-page-' _ page.idnew %]
[% INCLUDE 'masthead.inc' %]
<div class="main">
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumbs">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="/cgi-bin/koha/opac-main.pl">Home</a>
</li>
[% IF page %]
<li class="breadcrumb-item active">
<a href="#" aria-current="page">[% page.title | html %]</a>
</li>
[% ELSE %]
<li class="breadcrumb-item active">
<a href="#" aria-current="page">Page error</a>
</li>
[% END %]
</ol>
</nav> <!-- /#breadcrumbs -->
<div class="container-fluid">
<div class="row">
[% IF ( OpacNav || OpacNavBottom ) %]
<div class="col-12 col-lg-2 order-3 order-lg-1">
<div id="navigation">
[% IF ( OpacNav || OpacNavBottom ) %]
<hr>
[% INCLUDE 'navigation.inc' %]
[% END %]
</div>
</div>
<div class="col-12 col-lg-10 order-md-1 maincontent">
[% ELSE %]
<div class="col order-md-1 maincontent">
[% END %]
<div id="page_[% page.idnew | html %]" class="maincontent">
[% IF page %]
<h1>[% page.title | html %]</h1>
<div class="page_content">
[% page.content | $raw %]
</div>
[% ELSE %]
<div class="alert alert-error">
This page does not exist.
</div>
[% END %]
</div> <!-- / .col 6/8 -->
</div> <!-- /.container-fluid -->
</div> <!-- /.row -->
</div> <!-- /.main -->
[% INCLUDE 'opac-bottom.inc' %]
[% BLOCK jsinclude %][% END %]

48
opac/opac-page.pl Executable file
View file

@ -0,0 +1,48 @@
#!/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 <http://www.gnu.org/licenses>.
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, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => "opac-page.tt",
query => $query,
type => "opac",
authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
}
);
my $page_id = $query->param('page_id');
my $page;
if (defined $page_id){
$page = Koha::AdditionalContents->search({ idnew => $page_id, location => ['opac_only', 'staff_and_opac'] });
if ( $page->count > 0){
$template->param( page => $page->next );
} else {
$template->param( page_error => 1 );
}
}
output_html_with_http_headers $query, $cookie, $template->output;

47
tools/page.pl Executable file
View file

@ -0,0 +1,47 @@
#!/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 <http://www.gnu.org/licenses>.
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 $page_id = $query->param('page_id');
my $page;
if (defined $page_id){
$page = Koha::AdditionalContents->search({ idnew => $page_id, location => ['staff_only', 'staff_and_opac'] });
if ( $page->count > 0){
$template->param( page => $page->next );
} else {
$template->param( page_error => 1 );
}
}
output_html_with_http_headers $query, $cookie, $template->output;