From aae6bd0d82a1887769690c1685734142f569a873 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 26 Apr 2019 01:09:18 +0000 Subject: [PATCH] Bug 8628: Digital signs - staff interface This patch adds the interface for creating and managing digital signs and streams. --- Koha/SignStream.pm | 14 + Koha/SignsToStream.pm | 14 + .../intranet-tmpl/prog/en/includes/tools-menu.inc | 3 + .../prog/en/modules/admin/preferences/opac.pref | 2 +- .../intranet-tmpl/prog/en/modules/tools/signs.tt | 490 +++++++++++++++++++++ .../prog/en/modules/tools/tools-home.tt | 5 + koha-tmpl/intranet-tmpl/prog/js/tools-menu.js | 2 + tools/signs.pl | 327 ++++++++++++++ 8 files changed, 856 insertions(+), 1 deletion(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/signs.tt create mode 100755 tools/signs.pl diff --git a/Koha/SignStream.pm b/Koha/SignStream.pm index daabddc767..185e21422a 100644 --- a/Koha/SignStream.pm +++ b/Koha/SignStream.pm @@ -33,6 +33,20 @@ Koha::SignStream - Koha SignStream object class =cut +=head3 saved_sql + +my $saved_sql = $stream->saved_sql; + +Return the report attached to a stream + +=cut + +sub saved_sql { + my ( $self ) = @_; + my $sql_rs = $self->_result->saved_sql; + return Koha::Report->_new_from_dbic( $sql_rs ); +} + sub _type { return 'SignStream'; } diff --git a/Koha/SignsToStream.pm b/Koha/SignsToStream.pm index b76f160ea6..cc73371eb9 100644 --- a/Koha/SignsToStream.pm +++ b/Koha/SignsToStream.pm @@ -33,6 +33,20 @@ Koha::SignsToStream - SignsToStream object class =cut +=head3 sign_stream + +my $sign_stream = $sts->sign_stream + +Return the stream + +=cut + +sub sign_stream { + my ( $self ) = @_; + my $stream_rs = $self->_result->sign_stream; + return Koha::SignStream->_new_from_dbic( $stream_rs ); +} + sub _type { return 'SignsToStream'; } 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 3fce8ea0e0..f091bb964c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc @@ -121,6 +121,9 @@ [% IF ( CAN_user_tools_edit_quotes ) %]
  • Quote editor
  • [% END %] + [% IF ( CAN_user_tools_edit_digital_signs ) %] +
  • Digital signs + [% END %] [% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
  • Tool plugins
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 1a6ab2ddf2..b21c6b1cdf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -67,7 +67,6 @@ OPAC: no: "Don't show" - "a warning that the OPAC is under maintenance, instead of the OPAC itself. Note: this shows the same warning as when the database needs to be upgraded, but unconditionally." - - - - "Show the following HTML when OpacMaintenance is enabled:" - pref: OpacMaintenanceNotice type: textarea @@ -857,6 +856,7 @@ OPAC: - when creating a new sign. By default the themes a-e are provided, but you can override these by creating your own themes and entering them into the OPACDigitalSignsCSS system preference. If you do add your own custom themes there you will want to adjust the letters in this system preference to match the themes you created. Advanced Search Options: + - - Show search options - pref: OpacAdvSearchOptions multiple: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/signs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/signs.tt new file mode 100644 index 0000000000..80b74d9caa --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/signs.tt @@ -0,0 +1,490 @@ +[% USE Koha %] +[% USE Asset %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Tools › Digital signs +[% INCLUDE 'doc-head-close.inc' %] +[% Asset.css("css/datatables.css") %] + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + +[% BLOCK dslink %]Digital signs ›[% END %] + + +
    +
    +
    +
    + +[% UNLESS Koha.Preference( 'OPACDigitalSigns' ) %] +
    + Digital signs are not enabled. Please enable OPACDigitalSigns for OPAC digital signs to work. +
    +[% END %] + +[% IF ( else ) %] + +[% END %] + +[% IF op == 'stream_form' %] + [% UNLESS ( reports ) %] +
    +

    No reports found

    + No reports with group code "SIGN" were found. Please create a new report with group code "SIGN" and try again. +
    + [% END %] + + [% IF ( stream.sign_stream_id ) %] +

    Edit stream

    + [% ELSE %] +

    Add stream

    + [% END %] +
    + + [% IF ( stream.sign_stream_id ) %] + + [% END %] +
    +
      +
    1. + + + Required +
    2. +
    3. + + Required +
    4. +
    5. +
    +
    +
    +
    + +[% ELSIF op == 'sign_form' %] + [% IF ( sign.sign_id ) %] +

    Edit sign

    + [% ELSE %] +

    Add sign

    + [% END %] +
    + + [% IF ( sign.sign_id ) %] + + [% END %] +
    + General settings +
      +
    1. +
    +
    +
    + Appearance +
      +
    1. + +
    2. +
    3. + +
    4. +
    5. + +
    6. +
    +
    +
    + Automatic page turning +
      +
    1. + seconds. (Set to 0 to disable automatic page turning.) +
    2. +
    3. + seconds. +
    4. +
    5. + seconds. +
    6. +
    +
    +
    +
    + +[% ELSIF op == 'edit_streams' %] +

    Edit streams attached to [% sign.name %]

    +

    Streams already attached to this sign

    + [% IF ( sts.count ) %] + + + + + + + + + + [% FOREACH s IN sts %] + + + + + + + [% END %] + +
    NameParameters 
    [% s.sign_stream.name %][% IF s.params %][% s.params %][% ELSE %]None[% END %] + [% IF s.params %] + + [% ELSE %] + + [% END %] + Detach
    + [% ELSE %] + There are no streams attached to this sign. + [% END %] + +

    Attach a new stream to this sign

    +
    + + +
    +
      +
    1. + +
    2. +
    +
    +
    +
    + +[% ELSIF op == 'get_params' %] +

    Parameters for [% stream.name %]

    + Based on report: [% sql.report_name %] | Edit this report + +
    + + + + +
    + [% IF ( sts.params ) %] + Edit parameters + [% ELSE %] + Add parameters + [% END %] +
      +
    1. + +
    2. +
    +
    +
    +
    + +

    Raw SQL

    +
    [% sql.savedsql | html %]
    + +

    SQL with current parameters replaced

    +
    [% newsql | html %]
    + + [% IF ( has_params ) %] + Sorry, your SQL still contains placeholders. You need to add more parameters. + [% ELSE %] +

    Records

    + [% INCLUDE display_records %] + [% END %] + +[% ELSIF op == 'del_stream' %] +
    +

    Confirm deletion of stream '[% stream.name %]'?

    +
    + + + +
    + +
    + +
    +
    + +[% ELSIF op == 'del_stream_ok' %] +
    +

    Stream deleted

    +
    + +
    +
    + +[% ELSIF op == 'del_sign' %] +
    +

    Confirm deletion of sign '[% sign.name %]'?

    +
    + + + +
    + +
    + +
    +
    + +[% ELSIF op == 'del_sign_ok' %] +
    +

    Sign deleted

    +
    + +
    +
    + +[% ELSIF op == 'view_sign' %] +

    [% sign.name %]

    +

    Streams

    + + [% IF ( streams ) %] + [% FOREACH stream IN streams %] +

    [% stream.sign_stream.name %]

    + + [% END %] + [% ELSE %] + No streams attached. + [% END %] + +[% ELSIF op == 'view_stream' %] +

    [% stream.name %]

    + Based on report: [% stream.saved_sql_id.report_name %] | Edit this report + +

    SQL

    +
    [% stream.saved_sql_id.savedsql | html %]
    + +

    Records

    + [% IF ( has_params ) %] + Unable to display records. Check that this stream has been attached to a sign and any parameters have been filled appropriately. + [% ELSE %] + [% INCLUDE display_records %] + [% END %] + +[% ELSE %] +

    Digital signs

    + + [% IF ( error_on_insert_stream ) %] +
    Failed to create a new stream.
    + [% ELSIF ( success_on_insert_stream ) %] +
    New stream added.
    + [% END %] + +

    Signs

    + [% IF signs %] + + + + + + + + + + + + + + + [% FOREACH s IN signs %] + + + + + + + + + + + [% END %] + +
    NameWeb-appTheme (swatch)TransitionIdle afterPage delayReload after 
    [% s.name %][% IF ( s.webapp ) %]Yes[% ELSE %]No[% END %][% s.swatch %][% s.transition %][% s.idleafter %][% s.pagedelay %][% s.reloadafter %] + +
    + [% UNLESS ( OPACBaseURL ) %]Please note: Links to view signs in the OPAC will only be displayed if you fill in the OPACBaseURL system preference.[% END %] + [% ELSE %] +
    No signs defined. Create a new sign.
    + [% END %] + +

    Streams

    + [% IF streams %] + + + + + + + + + + [% FOREACH s IN streams %] + + + + + + [% END %] + +
    NameReportActions
    [% s.name %][% s.saved_sql.report_name %] + Edit + Delete +
    + [% ELSE %] +
    No streams defined. Create a new stream.
    + [% END %] + +[% END %] + +
    +
    + +
    +[% INCLUDE 'tools-menu.inc' %] +
    + +
    + +[% MACRO jsinclude BLOCK %] +[% INCLUDE 'datatables.inc' %] +[% Asset.js("js/tools-menu.js") | $raw %] + +[% END %] + +[% INCLUDE 'intranet-bottom.inc' %] + +[% BLOCK display_records %] + [% IF ( records.0 ) %] + + + + + + + + + [% FOREACH r IN records %] + + [% END %] + +
    biblionumbertitle
    [% r.biblionumber %][% r.title %]
    + [% ELSE %] + No records found. + [% END %] +[% 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 732563ce0a..0bfd9c7f3b 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 @@ -114,6 +114,11 @@
    Quote editor for Quote-of-the-day feature in OPAC
    [% END %] + [% IF ( CAN_user_tools_edit_digital_signs ) %] +
    Digital signs
    +
    Create and edit digital signs for the OPAC
    + [% END %] + [% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
    Tool plugins
    Use tool plugins
    diff --git a/koha-tmpl/intranet-tmpl/prog/js/tools-menu.js b/koha-tmpl/intranet-tmpl/prog/js/tools-menu.js index 14325b6f9d..c25e6439f0 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("signs") >= 0 ) { + $('#navmenulist a[href$="/cgi-bin/koha/tools/signs.pl"]').addClass("current"); } }); diff --git a/tools/signs.pl b/tools/signs.pl new file mode 100755 index 0000000000..01c70bc4de --- /dev/null +++ b/tools/signs.pl @@ -0,0 +1,327 @@ +#!/usr/bin/perl + +# Copyright 2012 Magnus Enger Libriotech +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +=head1 NAME + +signs.pl - Script for managing digital signs for the OPAC. + +=head1 SYNOPSIS + +signs.pl + +=head1 DESCRIPTION + +Allows authorized users to create and manage digital signs for the OPAC. + +=cut + +use Koha::Sign; +use Koha::Signs; +use Koha::SignStream; +use Koha::SignStreams; +use Koha::SignsToStreams; +use Koha::Reports; +use CGI; +use C4::Auth; +use C4::Context; +use C4::Log; +use C4::Output; +use C4::Reports::Guided; +use Modern::Perl; + +my $cgi = new CGI; +my $dbh = C4::Context->dbh; +my $script_name = 'signs.pl'; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ + template_name => "tools/signs.tt", + query => $cgi, + type => "intranet", + authnotrequired => 0, + flagsrequired => { tools => 'edit_digital_signs' }, + debug => 0, +}); + +my $op = $cgi->param('op') || ''; +my $sign_id = $cgi->param('sign_id') || ''; +my $sign_stream_id = $cgi->param('sign_stream_id') || ''; +my $sign_to_stream_id = $cgi->param('sign_to_stream_id') || ''; +my $parameters = $cgi->param('parameters') || ''; + +# Streams + +if ( $op eq 'add_stream' ) { + + $template->param( + op => 'stream_form', + reports => get_saved_reports({ group => 'SIGN' }), + ); + +} elsif ( $op eq 'edit_stream' && $sign_stream_id ne '') { + + my $stream = Koha::SignStreams->find( $sign_stream_id ); + + $template->param( + op => 'stream_form', + stream => $stream, + reports => get_saved_reports({ group => 'SIGN' }), + script_name => $script_name + ); + +} elsif ( $op eq 'save_stream' ) { + + my $name = $cgi->param('name'); + my $report = $cgi->param('report'); + if ( $sign_stream_id ne '' ) { + Koha::SignStreams->find( $sign_stream_id )->set({ name => $name, saved_sql_id => $report })->store; # modify + } else { + Koha::SignStream->new({ name => $name, saved_sql_id => $report })->store; # add new + } + print $cgi->redirect($script_name); + +} elsif ( $op eq 'view_stream' && $sign_stream_id ne '' ) { + + my $stream = Koha::SignStreams->find( $sign_stream_id ); + my $report = Koha::Reports->find($stream->saved_sql_id); + my $sql = $report->savedsql; + my ( $records, $error ) = execute_query( $sql, 0, 999999 ); + if ( $records && not $error ) { + $records = $records->fetchall_arrayref({}); + $template->param( records => $records ); + } else { + $template->param( has_params => 1 ); + } + + $template->param( + op => 'view_stream', + stream => $stream, + script_name => $script_name + ); + +} elsif ( $op eq 'del_stream' ) { + + my $stream = Koha::SignStreams->find( $sign_stream_id ); + + $template->param( + op => 'del_stream', + stream => $stream, + script_name => $script_name, + ); + +} elsif ( $op eq 'del_stream_ok' ) { + + Koha::SignStreams->find( $sign_stream_id )->delete; + + $template->param( + op => 'del_stream_ok', + script_name => $script_name, + ); + +# Signs + +} elsif ( $op eq 'add_sign' ) { + + $template->param( op => 'sign_form' ); + +} elsif ( $op eq 'edit_sign' && $sign_id ne '' ) { + + my $sign = Koha::Signs->find( $sign_id ); + + $template->param( + op => 'sign_form', + sign => $sign, + script_name => $script_name, + ); + +} elsif ( $op eq 'save_sign' ) { + + if ($cgi->param('sign_id')) { + Koha::Signs->find( scalar $cgi->param('sign_id') )->set({ + name => scalar $cgi->param('name'), + webapp => scalar $cgi->param('webapp'), + swatch => scalar $cgi->param('swatch'), + transition => scalar $cgi->param('transition'), + idleafter => scalar $cgi->param('idleafter'), + pagedelay => scalar $cgi->param('pagedelay'), + reloadafter => scalar $cgi->param('reloadafter') + })->store; # modify + } else { + Koha::Sign->new({ + name => scalar $cgi->param('name'), + webapp => scalar $cgi->param('webapp'), + swatch => scalar $cgi->param('swatch'), + transition => scalar $cgi->param('transition'), + idleafter => scalar $cgi->param('idleafter'), + pagedelay => scalar $cgi->param('pagedelay'), + reloadafter => scalar $cgi->param('reloadafter') + })->store; # add new + } + print $cgi->redirect($script_name); + +} elsif ( $op eq 'view_sign' && $sign_id ne '' ) { + + # Getting sign streams attached to sign with records + my $schema = Koha::Database->new()->schema(); + my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' }); + my @changedstreams; + + foreach my $s ( @signstostreams ) { + my $stream = Koha::SignStreams->find( $s->sign_stream_id ); + my $sql = Koha::Reports->find($stream->saved_sql_id); + my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $s->sign_to_stream_id }); + # Generate SQL with added params + my $newsql = $sql->savedsql; + foreach my $param ( split /&/, $params->params ) { + my ( $key, $value ) = split /=|<|>/, $param; # The < and > in the split are just to prevent software errors, the sign in the query must be changed in the report itself + $newsql =~ s/$key/$value/g; + } + # Run query with new sql + my ( $records, $error ) = execute_query( $newsql, 0, 999999 ); + if ( $records && not $error ) { + $s->{'records'} = $records->fetchall_arrayref({}); + push @changedstreams, $s; + } + } + + $template->param( + op => 'view_sign', + sign => Koha::Signs->find( $sign_id ), + streams => \@changedstreams, + script_name => $script_name, + ); + +} elsif ( $op eq 'del_sign' && $sign_id ne '' ) { + + my $sign = Koha::Signs->find( $sign_id ); + + $template->param( + op => 'del_sign', + sign => $sign, + script_name => $script_name, + ); + +} elsif ( $op eq 'del_sign_ok' ) { + + Koha::Signs->find( $sign_id )->delete; + + $template->param( + op => 'del_sign_ok', + script_name => $script_name, + ); + +# Signs and streams + +} elsif ( $op eq 'edit_streams' && $sign_id ne '') { + + my $sign = Koha::Signs->find( $sign_id ); + my $streams = Koha::SignStreams->search({}); + my $signstostreams = Koha::SignsToStreams->search({ 'sign_id' => $sign_id }); + + $template->param( + op => 'edit_streams', + sign => $sign, + sign_id => $sign_id, + streams => $streams, + sts => $signstostreams, + script_name => $script_name + ); + +} elsif ( $op eq 'attach_stream_to_sign' && $sign_stream_id ne '' && $sign_id ne '' ) { + + my $sign_to_stream = Koha::SignsToStream->new({ sign_stream_id => $sign_stream_id, sign_id => $sign_id })->store; + + # Check if the SQL associated with the stream needs parameters + my $stream = Koha::SignStreams->find( $sign_stream_id ); + my $sql = Koha::Reports->find($stream->saved_sql_id); + if ( $sql->savedsql =~ m/WHERE/ ) { + print $cgi->redirect( $script_name . '?op=get_params&sign_to_stream_id=' . $sign_to_stream->sign_to_stream_id . '&sign_stream_id=' . $sign_stream_id . '&sign_id=' . $sign_id ); + } else { + print $cgi->redirect( $script_name . '?op=edit_streams&sign_id=' . $sign_id ); + } + +} elsif ( $op eq 'get_params' && $sign_to_stream_id ne '' && $sign_stream_id ne '' && $sign_id ne '' ) { + + my $stream = Koha::SignStreams->find( $sign_stream_id ); + my $sql = Koha::Reports->find($stream->saved_sql_id); + my $sts = Koha::SignsToStreams->find({ sign_to_stream_id => $sign_to_stream_id }); + # Generate SQL with added params + my $newsql = $sql->savedsql; + foreach my $param ( split /&/, $sts->params ) { + $param =~ tr/ //ds; # replace any whitespace with nothing, strip the spaces out so the query works + my ( $key, $value ) = split /=|<|>/, $param; # The < and > in the split are just to prevent software errors, the sign in the query must be changed in the report itself + $newsql =~ s/$key/$value/g; + } + # Run query with new sql + my ( $records, $error ) = execute_query( $newsql, 0, 999999 ); + if ( $records && not $error) { + $template->param( records => $records->fetchall_arrayref({}) ); + } else { + $template->param( has_params => 1 ); + } + + my $sign = Koha::Signs->find( $sign_id ); + + $template->param( + op => 'get_params', + stream => $stream, + sign_id => $sign_id, + sign_stream_id => $sign_stream_id, + sign_to_stream_id => $sign_to_stream_id, + sts => $sts, + sql => $sql, + newsql => $newsql, + script_name => $script_name, + sign => $sign + ); + +} elsif ( $op eq 'save_params' && $sign_to_stream_id ne '' && $sign_id ne '' ) { + + Koha::SignsToStreams->find( $sign_to_stream_id )->set({ params => $parameters })->store; + print $cgi->redirect( $script_name . '?op=get_params&sign_to_stream_id=' . $sign_to_stream_id . '&sign_stream_id=' . $sign_stream_id . '&sign_id=' . $sign_id ); + +} elsif ( $op eq 'detach_stream_from_sign' && $sign_to_stream_id ne '' ) { + + Koha::SignsToStreams->find( $sign_to_stream_id )->delete; + print $cgi->redirect($script_name . '?op=edit_streams&sign_id=' . $sign_id); + +} else { + + my @streams = Koha::SignStreams->search(); + my @signs = Koha::Signs->search(); + + $template->param( + streams => \@streams, + signs => \@signs, + reports => get_saved_reports({ group => 'SIGN' }), + OPACBaseURL => C4::Context->preference( 'OPACBaseURL' ) || '', + else => 1 + ); + +} + +output_html_with_http_headers $cgi, $cookie, $template->output; + +exit 0; + +=head1 AUTHORS + +Written by Magnus Enger of Libriotech. +Aleisha Amohia + +=cut -- 2.11.0