@@ -, +, @@
---
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
--- a/Koha/SignStream.pm
+++ a/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';
}
--- a/Koha/SignsToStream.pm
+++ a/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';
}
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc
+++ a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc
@@ -121,6 +121,9 @@
[% IF ( CAN_user_tools_edit_quotes ) %]
+
+
+
+
+[% 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 %]
+
+
+[% ELSIF op == 'sign_form' %]
+ [% IF ( sign.sign_id ) %]
+
Edit sign
+ [% ELSE %]
+
Add sign
+ [% END %]
+
+
+[% ELSIF op == 'edit_streams' %]
+
Edit streams attached to [% sign.name %]
+
Streams already attached to this sign
+ [% IF ( sts.count ) %]
+
+
+
+ Name |
+ Parameters |
+ |
+
+
+
+ [% FOREACH s IN sts %]
+
+ [% s.sign_stream.name %] |
+ [% IF s.params %][% s.params %][% ELSE %]None[% END %] |
+
+ [% IF s.params %]
+
+ [% ELSE %]
+
+ [% END %]
+ |
+ Detach |
+
+ [% END %]
+
+
+ [% ELSE %]
+ There are no streams attached to this sign.
+ [% END %]
+
+
Attach a new stream to this sign
+
+
+[% ELSIF op == 'get_params' %]
+
Parameters for [% stream.name %]
+ Based on report: [% sql.report_name %] |
Edit this report
+
+
+
+
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 %]
+
+
+
+ Name |
+ Web-app |
+ Theme (swatch) |
+ Transition |
+ Idle after |
+ Page delay |
+ Reload after |
+ |
+
+
+
+ [% FOREACH s IN signs %]
+
+ [% s.name %] |
+ [% IF ( s.webapp ) %]Yes[% ELSE %]No[% END %] |
+ [% s.swatch %] |
+ [% s.transition %] |
+ [% s.idleafter %] |
+ [% s.pagedelay %] |
+ [% s.reloadafter %] |
+
+
+ |
+
+ [% END %]
+
+
+ [% 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 %]
+
+ [% END %]
+
+
Streams
+ [% IF streams %]
+
+
+
+ Name |
+ Report |
+ Actions |
+
+
+
+ [% FOREACH s IN streams %]
+
+ [% s.name %] |
+ [% s.saved_sql.report_name %] |
+
+ Edit
+ Delete
+ |
+
+ [% END %]
+
+
+ [% ELSE %]
+
+ [% 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 ) %]
+
+
+
+ biblionumber |
+ title |
+
+
+
+ [% FOREACH r IN records %]
+ [% r.biblionumber %] | [% r.title %] |
+ [% END %]
+
+
+ [% ELSE %]
+ No records found.
+ [% END %]
+[% END %]
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt
+++ a/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
--- a/koha-tmpl/intranet-tmpl/prog/js/tools-menu.js
+++ a/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");
}
});
--- a/tools/signs.pl
+++ a/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
--