From b49184f9a649eab0eca04eaf519685fa52b7ee6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Sun, 23 Apr 2017 00:22:51 +0200 Subject: [PATCH] Bug 18483 - Customised help: Enhance staff client with news based, easily editable help system Koha's staff client has a file based help system with an edit function for customising. However, the edited files have to be saved and restored with each release. Otherwise they are overwritten. As an enhancement or alternative, the existing news system can be used to implement a complementing help system. Similar to the news, the text can be created for all branches or for individual branches. Help is context sensitive (based on the existing help system), and it can be created / edited directly from the help page (based on a user permission). The display can be managed with a system preference (Bug 18472: Add system preference CustomOnlineHelpStaff to hide / select custom online help system). This patch is work in progress. It is not yet ready for testing or sign-off. Amended to resolve minor conflicts with Bug 18472 Amended to expand sysprefs from Bug 18472 Amended to add permissions Amended for visibility of edit buttons Amended for updatedb fixes Amended for managing permissions Amended to use news manging page as popup, needs Bug 13835 to test (not to apply) Amended to make it apply again on 18472 Still work in progress, not yet ready to test. --- edithelp.pl | 13 +---- help.pl | 50 ++++++++++++++++++-- ...dd_system_preference_CustomOnlineHelpStaff.perl | 2 +- .../bug_18483_news-driven-help-system.perl | 17 +++++++ installer/data/mysql/sysprefs.sql | 2 +- .../intranet-tmpl/prog/en/includes/header.inc | 2 +- .../intranet-tmpl/prog/en/includes/help-bottom.inc | 15 ++++-- .../intranet-tmpl/prog/en/includes/help-top.inc | 55 +++++++++++++++------- .../intranet-tmpl/prog/en/includes/permissions.inc | 1 + .../prog/en/modules/admin/preferences/admin.pref | 1 + .../intranet-tmpl/prog/en/modules/help/mainpage.tt | 5 +- .../prog/en/modules/help/nohelptext.tt | 2 + .../prog/en/modules/tools/koha-news.tt | 55 ++++++++++++++++++++-- .../prog/en/modules/tools/tools-home.tt | 14 ++++-- tools/koha-news.pl | 28 +++++++++-- 15 files changed, 209 insertions(+), 53 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18483_news-driven-help-system.perl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/help/nohelptext.tt diff --git a/edithelp.pl b/edithelp.pl index dca61b1..e2ec5f4 100755 --- a/edithelp.pl +++ b/edithelp.pl @@ -18,6 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; +use C4::Koha; use C4::Output; use C4::Templates; use C4::Auth; @@ -45,17 +46,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => { - catalogue => 1, - circulate => 1, - parameters => 1, - borrowers => 1, - permissions => 1, - reserveforothers => 1, - reserveforself => 1, - editcatalogue => 1, - updatecharges => 1, - }, + flagsrequired => { tools => 'edit_help' }, debug => 1, } ); diff --git a/help.pl b/help.pl index ad86a2d..cc18864 100755 --- a/help.pl +++ b/help.pl @@ -21,7 +21,8 @@ use strict; use warnings; use C4::Templates; use C4::Output; -# use C4::Auth; +use C4::NewsChannels; # GetNewsToDisplay +use C4::Auth; use C4::Context; use CGI qw ( -utf8 ); @@ -47,24 +48,65 @@ C4::Context->interface('intranet'); our $refer = $query->param('url'); $refer = $query->referer() if !$refer || $refer eq 'undefined'; my $from = _help_template_file_of_url($refer); +my $helpkey = substr( $from, 0, rindex( $from, q{.} ) ); my $htdocs = C4::Context->config('intrahtdocs'); -# +my $helpsys = C4::Context->preference('HelpSystem'); + +#Template for 'classic' Koha help text (filebased) if needed, otherwise no text + # checking that the help file exist, otherwise, display nohelp.tt page -# my ( $theme, $lang ) = C4::Templates::themelanguage( $htdocs, $from, "intranet", $query ); + unless ( -e "$htdocs/$theme/$lang/modules/$from" ) { $from = "help/nohelp.tt"; ( $theme, $lang ) = C4::Templates::themelanguage( $htdocs, $from, "intranet", $query ); } -my $template = C4::Templates::gettemplate($from, 'intranet', $query); +# Classic Koha help text not used +if ( $helpsys eq 'newsbased' ) { + #Template without classic Koha help text + $from = "help/nohelptext.tt"; + ( $theme, $lang ) = C4::Templates::themelanguage( $htdocs, $from, "intranet", $query ); +} + +#my $template = C4::Templates::gettemplate($from, 'intranet', $query); + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => $from, + query => $query, + type => "intranet", + authnotrequired => 0, + } +); + + + + $template->param( referer => $refer, + helpkey => $helpkey, intranetstylesheet => C4::Context->preference("intranetstylesheet"), intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + helpsystem => $helpsys, ); +if ( index($helpsys,'newsbased') != -1 || index ($helpsys,'filebased') != -1 ) { + + my $homebranch; + if (C4::Context->userenv) { + $homebranch = C4::Context->userenv->{'branch'}; + } + my $help_from_news = &GetNewsToDisplay('staffhelp', $homebranch); + my $help_from_news_count = scalar @$help_from_news; + $template->param( + help_from_news => $help_from_news, + help_from_news_count => $help_from_news_count, + homebranch => $homebranch + ); +} + my $help_version = C4::Context->preference("Version"); if ( $help_version =~ m|^(\d+)\.(\d{2}).*$| ) { my $version = $1; diff --git a/installer/data/mysql/atomicupdate/bug_18472-Add_system_preference_CustomOnlineHelpStaff.perl b/installer/data/mysql/atomicupdate/bug_18472-Add_system_preference_CustomOnlineHelpStaff.perl index ce31d2d..a523c76 100644 --- a/installer/data/mysql/atomicupdate/bug_18472-Add_system_preference_CustomOnlineHelpStaff.perl +++ b/installer/data/mysql/atomicupdate/bug_18472-Add_system_preference_CustomOnlineHelpStaff.perl @@ -1,7 +1,7 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { # you can use $dbh here like: - $dbh->do("INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('HelpSystem', 'filebased', 'filebased', 'Select online help system.', 'multiple')" ); + $dbh->do("INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('HelpSystem', 'filebased', 'filebased|newsbased', 'Select online help system.', 'multiple')" ); $dbh->do("INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('EnableEditingFilebasedHelp', '1', '', 'Enable editing of file based Koha help.', 'yesno')" ); # or perform some test and warn diff --git a/installer/data/mysql/atomicupdate/bug_18483_news-driven-help-system.perl b/installer/data/mysql/atomicupdate/bug_18483_news-driven-help-system.perl new file mode 100644 index 0000000..c00c8dc --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_18483_news-driven-help-system.perl @@ -0,0 +1,17 @@ +$DBversion = 'XXXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + # you can use $dbh here like: + $dbh->do( "UPDATE systempreferences SET VALUE = 'filebased', OPTIONS = 'filebased|newsbased' where variable = 'HelpSystem'" ); + + $dbh->do( "ALTER TABLE opac_news ADD COLUMN helpkey varchar(250) AFTER lang "); + $dbh->do( "INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (13, 'edit_help', 'Edit custom help');" ); + + # or perform some test and warn + # if( !column_exists( 'biblio', 'biblionumber' ) ) { + # warn "There is something wrong"; + # } + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18483 - Customised help: Enhance staff client with news based, easily editable help system)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 9c32d85..244b225 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -115,7 +115,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'), ('CumulativeRestrictionPeriods',0,NULL,'Cumulate the restriction periods instead of keeping the highest','YesNo'), ('CurrencyFormat','US','US|FR|CH','Determines the display format of currencies. eg: \'36000\' is displayed as \'360 000,00\' in \'FR\' or \'360,000.00\' in \'US\'.','Choice'), -('HelpSystem', 'filebased', 'filebased', 'Select online help system.', 'multiple'), +('HelpSystem', 'filebased', 'filebased|newsbased', 'Select online help system.', 'multiple'), ('EnableEditingFilebasedHelp', '1', '', 'Enable editing of file based Koha help.', 'yesno'), ('dateformat','us','metric|us|iso|dmydot','Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd, dmydot dd.mm.yyyy)','Choice'), ('DebugLevel','2','0|1|2','Define the level of debugging information sent to the browser when errors are encountered (set to 0 in production). 0=none, 1=some, 2=most','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc index 82c2a4a..3ecc2df 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -98,7 +98,7 @@ - [% IF Koha.Preference('HelpSystem') == 'filebased' %] + [% IF Koha.Preference('HelpSystem').match('filebased|newsbased') %]
  • Help
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/help-bottom.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/help-bottom.inc index 0ed2086..8d8f706 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/help-bottom.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/help-bottom.inc @@ -1,10 +1,15 @@ +[% USE Koha %] +
    -
    - [% IF (Koha.Preference('HelpSystem') == 'filebased') && (Koha.Preference('EnableEditingFilebasedHelp') ) %] - +
    + -
    - [% END %] + [% IF ( Koha.Preference('HelpSystem').match('filebased') && Koha.Preference('EnableEditingFilebasedHelp') && CAN_user_tools_edit_help ) %] + + + [% END %] +
    + diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc index ff6aeb8..d6fcf51 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/help-top.inc @@ -1,21 +1,44 @@ [% USE Koha %] +[% USE Branches %] [% INCLUDE 'doc-head-open.inc' %] Online help - - - - -[% INCLUDE intranetstylesheet.inc %] -[% IF ( bidi ) %] - -[% END %] - - - - - - - - +[% USE Koha %] +[% INCLUDE 'doc-head-close.inc' %] + + +[% IF Koha.Preference('HelpSystem').match('newsbased') %] +
    +

    Help for [% Branches.GetName( homebranch ) %]

    + [% FOREACH helpitem IN help_from_news %] + [% IF (helpitem.helpkey == helpkey) || (helpitem.helpkey == 'all') %] +
    +

    [% helpitem.title %]

    +
    [% helpitem.content %]
    +
    [% helpitem.newdate %]
    + +
    + [% END %] + [% END %] + [% IF CAN_user_tools_edit_help %] +
    +

    + New custom help for this page + Key is: [% helpkey %]

    +

    + New custom help for all pages + Key is: all

    +
    + [% END %] +
    +[% END %] + +
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index 7c6275a..7d6beac 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -57,6 +57,7 @@ [%- CASE 'batch_upload_patron_images' -%]Upload patron images in a batch or one at a time [%- CASE 'delete_anonymize_patrons' -%]Delete old borrowers and anonymize circulation history (deletes borrower reading history) [%- CASE 'edit_calendar' -%]Define days when the library is closed + [%- CASE 'edit_help' -%]Edit custom help [%- CASE 'edit_news' -%]Write news for the OPAC and staff interfaces [%- CASE 'edit_notice_status_triggers' -%]Set notice/status triggers for overdue items [%- CASE 'edit_notices' -%]Define notices diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index c0c4526..5493b5a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -420,6 +420,7 @@ Administration: default: filebased multiple: filebased: "File based (staff client)" + newsbased: "News based" - - "Enable editing of file based Koha help: " - pref: EnableEditingFilebasedHelp diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/mainpage.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/mainpage.tt index 86ab4b7..0096079 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/mainpage.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/mainpage.tt @@ -2,7 +2,6 @@ [% INCLUDE 'help-top.inc' %]

    Welcome to Koha

    -

    If this is your first time logging into Koha, you should now go to Koha Administration and set up all system preferences, patron categories, item types and libraries. You should also review the other settings found in Administration.

    Once you have set up patron categories, you should create a new user in the Patrons module with superlibrarian permissions. Once that user is created, you should log in as that user rather than the root user which is set up as part of installation.

    @@ -18,7 +17,8 @@
  • Chat with Koha users and developers
  • -[% IF ( Koha.Preference('HelpSystem') == 'filebased' ) %] + [% IF Koha.Preference('HelpSystem').match('filebased') && (Koha.Preference('EnableEditingFilebasedHelp') && CAN_user_tools_edit_help ) %] +

    Can I edit the online help?

    You can edit the online help through the Koha Staff Client by clicking the "Edit Help" button. This feature has been designed so that library workflow and policies can be documented within Koha.

    @@ -26,6 +26,7 @@

    IMPORTANT: Your online help will be overwritten by the new Help when there is an upgrade. If you want to keep a copy of your online help, you should instruct your System Administrator to upgrade the Online Help directory in the Koha file tree.

    The online help directory is:

    [% themelang %]/modules/help

    +

    Note: Files in help directory must be writeable to make this feature work. Additionally, system preference 'EnableEditingFilebasedHelp' must be set to 'Yes'.

    [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/nohelptext.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/nohelptext.tt new file mode 100644 index 0000000..ea6af02 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/nohelptext.tt @@ -0,0 +1,2 @@ +[% INCLUDE 'help-top.inc' %] +[% INCLUDE 'help-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt index dd1ae84..d5b3548 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt @@ -1,3 +1,4 @@ +[% USE Koha %] [% USE KohaDates %] [% USE Branches %] [% INCLUDE 'doc-head-open.inc' %] @@ -72,11 +73,14 @@ tinyMCE.init({ -[% INCLUDE 'header.inc' %] -[% INCLUDE 'cat-search.inc' %] - Slip [% CASE "" %] All + [% CASE "staffhelp" %] + Staff help [% opac_new.helpkey %] [% CASE %] OPAC ([% opac_new.lang %]) [% END %] 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 4c8cca9..32c070a 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 @@ -1,3 +1,4 @@ +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Tools [% INCLUDE 'doc-head-close.inc' %] @@ -89,9 +90,16 @@
    Browse the system logs
    [% END %] - [% IF ( CAN_user_tools_edit_news ) %] -
    News
    -
    Write news for the OPAC and staff interfaces
    + [% IF CAN_user_tools_edit_news && CAN_user_tools_edit_help && Koha.Preference('HelpSystem').match('newsbased') %] +
    Manage news and news based help
    +
    Write news for the OPAC and staff interfaces and manage news based online help for staff interface
    + [% ELSIF CAN_user_tools_edit_help && Koha.Preference('HelpSystem').match('newsbased') %] +
    Manage news based help
    +
    Manage news based online help for staff interface
    + [% ELSE %] +
    Manage news
    +
    Write news for the OPAC and staff interfaces
    + [% END %] [% IF ( CAN_user_tools_schedule_tasks ) %] diff --git a/tools/koha-news.pl b/tools/koha-news.pl index 61c3ec6..40c20c0 100755 --- a/tools/koha-news.pl +++ b/tools/koha-news.pl @@ -45,6 +45,7 @@ if ( $cgi->param('expirationdate') ) { } my $timestamp = output_pref({ dt => dt_from_string( scalar $cgi->param('timestamp') ), dateformat => 'iso', dateonly => 1 }); my $number = $cgi->param('number'); +my $helpkey = $cgi->param('helpkey'); my $lang = $cgi->param('lang'); my $branchcode = $cgi->param('branch'); my $error_message = $cgi->param('error_message'); @@ -55,17 +56,29 @@ $branchcode = undef if (defined($branchcode) && $branchcode eq ''); my $new_detail = get_opac_new($id); +# flagsrequired checks for all flags listed, we need an 'or' +# to work with edit_news or edit_help. my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { template_name => "tools/koha-news.tt", query => $cgi, type => "intranet", - authnotrequired => 0, - flagsrequired => { tools => 'edit_news' }, + authnotrequired => 1, debug => 1, } ); +#news based help system can call this script as a popup window +$template->param( popup_window => 1 ) if( $cgi->param('popup_window')== 1 ); + +#Check now the flags, user must have news or help edit permissions +if ( not (defined $template->{VARS}->{'CAN_user_tools_edit_news'} || + defined $template->{VARS}->{'CAN_user_tools_edit_help'} ) ) { +warn "EXIT FROM koha-news.pl "; + print $cgi->redirect("/cgi-bin/koha/errors/403.pl"); +} else { +#TODO: Indent as followup to bug 18483 + # Pass error message if there is one. $template->param( error_message => $error_message ) if $error_message; @@ -99,7 +112,11 @@ if ( $op eq 'add_form' ) { $template->{VARS}->{'new_detail'} = $new_detail; } else { - $template->param( op => 'add' ); + $template->param( + op => 'add', + helpkey => $helpkey + ); + } } elsif ( $op eq 'add' ) { @@ -112,6 +129,7 @@ elsif ( $op eq 'add' ) { expirationdate => $expirationdate, timestamp => $timestamp, number => $number, + helpkey => $helpkey, branchcode => $branchcode, borrowernumber => $borrowernumber, } @@ -131,6 +149,7 @@ elsif ( $op eq 'edit' ) { lang => $lang, expirationdate => $expirationdate, timestamp => $timestamp, + helpkey => $helpkey, number => $number, branchcode => $branchcode, } @@ -145,7 +164,7 @@ elsif ( $op eq 'del' ) { else { - my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, $lang, $branchcode ); + my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, 'staffhelp', $branchcode ); foreach my $new ( @$opac_news ) { next unless $new->{'expirationdate'}; @@ -161,4 +180,5 @@ else { ); } $template->param( lang => $lang ); +} output_html_with_http_headers $cgi, $cookie, $template->output; -- 2.1.4