View | Details | Raw Unified | Return to bug 8628
Collapse All | Expand All

(-)a/Koha/Schema/Result/SavedSql.pm (-2 / +19 lines)
Lines 162-170 __PACKAGE__->add_columns( Link Here
162
162
163
__PACKAGE__->set_primary_key("id");
163
__PACKAGE__->set_primary_key("id");
164
164
165
=head1 RELATIONS
165
166
166
# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-10-24 09:58:16
167
=head2 sign_streams
167
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:eGWRRzpe1+EBialePAIhMQ
168
169
Type: has_many
170
171
Related object: L<Koha::Schema::Result::SignStream>
172
173
=cut
174
175
__PACKAGE__->has_many(
176
  "sign_streams",
177
  "Koha::Schema::Result::SignStream",
178
  { "foreign.saved_sql_id" => "self.id" },
179
  { cascade_copy => 0, cascade_delete => 0 },
180
);
181
182
183
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
184
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:f9cgj30zP/aIRPhEmZNT6g
168
185
169
186
170
# You can replace this text with custom content, and it will be preserved on regeneration
187
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/Sign.pm (+132 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::Sign;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::Sign
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<signs>
19
20
=cut
21
22
__PACKAGE__->table("signs");
23
24
=head1 ACCESSORS
25
26
=head2 sign_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 name
33
34
  data_type: 'varchar'
35
  is_nullable: 1
36
  size: 64
37
38
=head2 webapp
39
40
  data_type: 'integer'
41
  default_value: 0
42
  is_nullable: 0
43
44
=head2 transition
45
46
  data_type: 'char'
47
  default_value: 'none'
48
  is_nullable: 0
49
  size: 16
50
51
=head2 swatch
52
53
  data_type: 'char'
54
  default_value: (empty string)
55
  is_nullable: 0
56
  size: 1
57
58
=head2 idleafter
59
60
  data_type: 'integer'
61
  default_value: 0
62
  is_nullable: 0
63
64
=head2 pagedelay
65
66
  data_type: 'integer'
67
  default_value: 0
68
  is_nullable: 0
69
70
=head2 reloadafter
71
72
  data_type: 'integer'
73
  default_value: 0
74
  is_nullable: 0
75
76
=cut
77
78
__PACKAGE__->add_columns(
79
  "sign_id",
80
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
81
  "name",
82
  { data_type => "varchar", is_nullable => 1, size => 64 },
83
  "webapp",
84
  { data_type => "integer", default_value => 0, is_nullable => 0 },
85
  "transition",
86
  { data_type => "char", default_value => "none", is_nullable => 0, size => 16 },
87
  "swatch",
88
  { data_type => "char", default_value => "", is_nullable => 0, size => 1 },
89
  "idleafter",
90
  { data_type => "integer", default_value => 0, is_nullable => 0 },
91
  "pagedelay",
92
  { data_type => "integer", default_value => 0, is_nullable => 0 },
93
  "reloadafter",
94
  { data_type => "integer", default_value => 0, is_nullable => 0 },
95
);
96
97
=head1 PRIMARY KEY
98
99
=over 4
100
101
=item * L</sign_id>
102
103
=back
104
105
=cut
106
107
__PACKAGE__->set_primary_key("sign_id");
108
109
=head1 RELATIONS
110
111
=head2 signs_to_streams
112
113
Type: has_many
114
115
Related object: L<Koha::Schema::Result::SignsToStream>
116
117
=cut
118
119
__PACKAGE__->has_many(
120
  "signs_to_streams",
121
  "Koha::Schema::Result::SignsToStream",
122
  { "foreign.sign_id" => "self.sign_id" },
123
  { cascade_copy => 0, cascade_delete => 0 },
124
);
125
126
127
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
128
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OWtbToVshm6D/q7jMbhAEA
129
130
131
# You can replace this text with custom code or comments, and it will be preserved on regeneration
132
1;
(-)a/Koha/Schema/Result/SignStream.pm (+105 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::SignStream;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::SignStream
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<sign_streams>
19
20
=cut
21
22
__PACKAGE__->table("sign_streams");
23
24
=head1 ACCESSORS
25
26
=head2 sign_stream_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 saved_sql_id
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 0
37
38
=head2 name
39
40
  data_type: 'varchar'
41
  is_nullable: 1
42
  size: 64
43
44
=cut
45
46
__PACKAGE__->add_columns(
47
  "sign_stream_id",
48
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
49
  "saved_sql_id",
50
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
51
  "name",
52
  { data_type => "varchar", is_nullable => 1, size => 64 },
53
);
54
55
=head1 PRIMARY KEY
56
57
=over 4
58
59
=item * L</sign_stream_id>
60
61
=back
62
63
=cut
64
65
__PACKAGE__->set_primary_key("sign_stream_id");
66
67
=head1 RELATIONS
68
69
=head2 saved_sql
70
71
Type: belongs_to
72
73
Related object: L<Koha::Schema::Result::SavedSql>
74
75
=cut
76
77
__PACKAGE__->belongs_to(
78
  "saved_sql",
79
  "Koha::Schema::Result::SavedSql",
80
  { id => "saved_sql_id" },
81
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
82
);
83
84
=head2 signs_to_streams
85
86
Type: has_many
87
88
Related object: L<Koha::Schema::Result::SignsToStream>
89
90
=cut
91
92
__PACKAGE__->has_many(
93
  "signs_to_streams",
94
  "Koha::Schema::Result::SignsToStream",
95
  { "foreign.sign_stream_id" => "self.sign_stream_id" },
96
  { cascade_copy => 0, cascade_delete => 0 },
97
);
98
99
100
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
101
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+QnTPOZSc8xl1o2qI0YB8A
102
103
104
# You can replace this text with custom code or comments, and it will be preserved on regeneration
105
1;
(-)a/Koha/Schema/Result/SignsToStream.pm (+114 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::SignsToStream;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::SignsToStream
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<signs_to_streams>
19
20
=cut
21
22
__PACKAGE__->table("signs_to_streams");
23
24
=head1 ACCESSORS
25
26
=head2 sign_to_stream_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 sign_stream_id
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 0
37
38
=head2 sign_id
39
40
  data_type: 'integer'
41
  is_foreign_key: 1
42
  is_nullable: 0
43
44
=head2 params
45
46
  data_type: 'varchar'
47
  default_value: (empty string)
48
  is_nullable: 0
49
  size: 255
50
51
=cut
52
53
__PACKAGE__->add_columns(
54
  "sign_to_stream_id",
55
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
56
  "sign_stream_id",
57
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
58
  "sign_id",
59
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
60
  "params",
61
  { data_type => "varchar", default_value => "", is_nullable => 0, size => 255 },
62
);
63
64
=head1 PRIMARY KEY
65
66
=over 4
67
68
=item * L</sign_to_stream_id>
69
70
=back
71
72
=cut
73
74
__PACKAGE__->set_primary_key("sign_to_stream_id");
75
76
=head1 RELATIONS
77
78
=head2 sign
79
80
Type: belongs_to
81
82
Related object: L<Koha::Schema::Result::Sign>
83
84
=cut
85
86
__PACKAGE__->belongs_to(
87
  "sign",
88
  "Koha::Schema::Result::Sign",
89
  { sign_id => "sign_id" },
90
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
91
);
92
93
=head2 sign_stream
94
95
Type: belongs_to
96
97
Related object: L<Koha::Schema::Result::SignStream>
98
99
=cut
100
101
__PACKAGE__->belongs_to(
102
  "sign_stream",
103
  "Koha::Schema::Result::SignStream",
104
  { sign_stream_id => "sign_stream_id" },
105
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
106
);
107
108
109
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-12-21 22:48:12
110
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fAi1KA4VmwQM96sQoI5DMQ
111
112
113
# You can replace this text with custom code or comments, and it will be preserved on regeneration
114
1;
(-)a/Koha/Sign.pm (+40 lines)
Line 0 Link Here
1
package Koha::Sign;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw( Koha::Object );
25
26
=head1 NAME
27
28
Koha::Sign - Koha Sign object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
sub _type {
37
    return 'Sign';
38
}
39
40
1;
(-)a/Koha/SignStream.pm (+40 lines)
Line 0 Link Here
1
package Koha::SignStream;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw( Koha::Object );
25
26
=head1 NAME
27
28
Koha::SignStream - Koha SignStream object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
sub _type {
37
    return 'SignStream';
38
}
39
40
1;
(-)a/Koha/SignStreams.pm (+59 lines)
Line 0 Link Here
1
package Koha::SignStreams;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::SignStream;
24
25
use base qw( Koha::Objects );
26
27
=head1 NAME
28
29
Koha::SignStreams - Koha SignStream object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'SignStream';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::SignStream';
51
}
52
53
=head1 AUTHOR
54
55
Aleisha Amohia <aleisha@catalyst.net.nz>
56
57
=cut
58
59
1;
(-)a/Koha/Signs.pm (-307 / +36 lines)
Lines 1-330 Link Here
1
package Koha::Signs;
1
package Koha::Signs;
2
2
3
use C4::Context;
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
use C4::Biblio;
4
#
5
use C4::Koha;
5
# This file is part of Koha.
6
use C4::Items;
6
#
7
use Modern::Perl;
7
# Koha is free software; you can redistribute it and/or modify it under the
8
8
# terms of the GNU General Public License as published by the Free Software
9
use base qw( Exporter );
9
# Foundation; either version 3 of the License, or (at your option) any later
10
10
# version.
11
# set the version for version checking
11
#
12
our @EXPORT = qw(
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
    AddSignStream
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
    ModSignStream
15
#
16
    GetSignStream
16
# You should have received a copy of the GNU General Public License along
17
    GetSignStreams
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
    DelSignStream
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
    GetSignStreamRecords
21
22
    AddSign
23
    ModSign
24
    GetSign
25
    GetSigns
26
    DelSign
27
28
    AttachSignStreamToSign
29
    DetachSignStreamFromSign
30
    GetSignStreamsAttachedToSign
31
    GetSignStreamsAttachedToSignWithRecords
32
33
    ModSignStreamParams
34
    GetSignStreamParams
35
);
36
37
my $dbh = C4::Context->dbh;
38
39
# Streams
40
41
# Returns id of new sign_stream
42
sub AddSignStream {
43
44
    my ( $name, $report ) = @_;
45
46
    my $sth=$dbh->prepare("INSERT INTO sign_streams SET name = ?, saved_sql_id = ?");
47
    $sth->execute( $name, $report );
48
    return $dbh->last_insert_id( undef, undef, 'sign_streams', 'sign_stream_id' );
49
50
}
51
52
sub ModSignStream {
53
54
    my ( $name, $report, $sign_stream_id ) = @_;
55
56
    my $sth = $dbh->prepare("UPDATE sign_streams SET name = ?, saved_sql_id = ? WHERE sign_stream_id = ?");
57
    return $sth->execute( $name, $report, $sign_stream_id );
58
59
}
60
61
sub GetSignStream {
62
63
    my ( $sign_id ) = @_;
64
65
    return unless $sign_id;
66
67
    my $query = "SELECT s.*, sq.report_name, sq.savedsql
68
                 FROM sign_streams AS s, saved_sql AS sq
69
                 WHERE s.saved_sql_id = sq.id
70
                   AND s.sign_stream_id = ?";
71
    my $sth = $dbh->prepare($query);
72
    $sth->execute($sign_id);
73
    return $sth->fetchrow_hashref();
74
75
}
76
77
sub GetSignStreams {
78
79
    my $query = "SELECT s.*, sq.report_name, sq.savedsql
80
                 FROM sign_streams AS s, saved_sql AS sq
81
                 WHERE s.saved_sql_id = sq.id
82
                 ORDER BY s.name";
83
    my $sth = $dbh->prepare($query);
84
    $sth->execute();
85
    return $sth->fetchall_arrayref({});
86
87
}
88
89
sub DelSignStream {
90
91
    my ( $sign_stream_id ) = @_;
92
93
    return unless $sign_stream_id;
94
95
    my $sth = $dbh->prepare('DELETE FROM sign_streams WHERE sign_stream_id = ?');
96
    return $sth->execute($sign_stream_id);
97
98
}
99
100
sub GetSignStreamRecords {
101
    my ( $stream, $sign_to_stream_id) = @_;
102
    my $sql = $stream->{'savedsql'};
103
104
    if ( defined $sign_to_stream_id ) {
105
        my $params = GetSignStreamParams( $sign_to_stream_id );
106
        $sql = ReplaceParamsInSQL( $sql, $params );
107
        return undef if ( $sql =~ m/<</ );
108
    }
109
110
    return {result => RunSQL( $sql ), sql => $sql };
111
}
112
113
# Signs
114
115
# Returns id of new sign
116
sub AddSign {
117
118
    my ( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter ) = @_;
119
120
    my $sth=$dbh->prepare("INSERT INTO signs SET name = ?, webapp = ?, swatch = ?, transition = ?, idleafter = ?, pagedelay = ?, reloadafter = ?");
121
    $sth->execute( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter );
122
    return $dbh->last_insert_id( undef, undef, 'signs', 'sign_id' );
123
124
}
125
126
sub ModSign {
127
128
    my ( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter, $sign_id ) = @_;
129
130
    my $sth = $dbh->prepare("UPDATE signs SET name = ?, webapp = ?, swatch = ?, transition = ?, idleafter = ?, pagedelay = ?, reloadafter = ? WHERE sign_id = ?");
131
    return $sth->execute( $name, $webapp, $swatch, $transition, $idleafter, $pagedelay, $reloadafter, $sign_id );
132
133
}
134
135
sub GetSign {
136
137
    my ( $sign_id ) = @_;
138
139
    return unless $sign_id;
140
141
    my $query = "SELECT *
142
                 FROM signs
143
                 WHERE sign_id = ?";
144
    my $sth = $dbh->prepare($query);
145
    $sth->execute($sign_id);
146
    return $sth->fetchrow_hashref();
147
19
148
}
20
use Modern::Perl;
149
150
sub GetSigns {
151
152
    my $query = "SELECT *
153
                 FROM signs
154
                 ORDER BY name";
155
    my $sth = $dbh->prepare($query);
156
    $sth->execute();
157
    return $sth->fetchall_arrayref({});
158
159
}
160
161
sub DelSign {
162
163
    my ( $sign_id ) = @_;
164
165
    return unless $sign_id;
166
167
    my $sth = $dbh->prepare('DELETE FROM signs WHERE sign_id = ?');
168
    return $sth->execute($sign_id);
169
170
}
171
172
# Streams attached to signs
173
174
# Returns the ID of the connection between sign and stream
175
sub AttachSignStreamToSign {
176
177
    my ( $sign_stream_id, $sign_id ) = @_;
178
179
    return unless $sign_stream_id || $sign_id;
180
181
    my $sth = $dbh->prepare( 'INSERT INTO signs_to_streams SET sign_stream_id = ?, sign_id = ?' );
182
    $sth->execute( $sign_stream_id, $sign_id );
183
    return $dbh->last_insert_id( undef, undef, 'signs_to_streams', 'sign_to_stream_id' );
184
185
}
186
187
sub ModSignStreamParams {
188
189
    my ( $sign_to_stream_id, $params ) = @_;
190
    return unless $sign_to_stream_id;
191
    my $sth = $dbh->prepare( 'UPDATE signs_to_streams SET params = ? WHERE sign_to_stream_id = ?' );
192
    return $sth->execute( $params, $sign_to_stream_id );
193
194
}
195
196
# Returns the string of params for a given stream-attached-to-sign
197
sub GetSignStreamParams {
198
199
    my ( $sign_to_stream_id ) = @_;
200
201
    return unless $sign_to_stream_id;
202
203
    my $query = 'SELECT params FROM signs_to_streams WHERE sign_to_stream_id = ?';
204
    my $sth = $dbh->prepare( $query );
205
    $sth->execute( $sign_to_stream_id );
206
    return $sth->fetchrow_array();
207
208
}
209
210
sub ReplaceParamsInSQL {
211
212
    my ( $sql, $params ) = @_;
213
214
    return unless $sql || $params;
215
    return $sql unless $sql =~ m/<</;
216
217
    foreach my $param ( split /&/, $params ) {
218
        my ( $key, $value ) = split /=/, $param;
219
        # FIXME Handle spaces
220
        $sql =~ s/<<$key>>/$value/g;
221
    }
222
    return $sql;
223
224
}
225
226
sub GetSignStreamsAttachedToSign {
227
228
    my ( $sign_id ) = @_;
229
230
    return unless $sign_id;
231
232
    my $query = 'SELECT s.*, sts.sign_to_stream_id, sts.params, sq.report_name, sq.savedsql
233
                 FROM sign_streams AS s, signs_to_streams AS sts, saved_sql AS sq
234
                 WHERE s.sign_stream_id = sts.sign_stream_id
235
                   AND s.saved_sql_id = sq.id
236
                   AND sts.sign_id = ?
237
                 ORDER BY s.name';
238
    my $sth = $dbh->prepare( $query );
239
    $sth->execute( $sign_id );
240
    return $sth->fetchall_arrayref({});
241
242
}
243
244
sub GetSignStreamsAttachedToSignWithRecords {
245
246
    my ( $sign_id, $include_marc ) = @_;
247
248
    return unless $sign_id;
249
250
    my $streams = GetSignStreamsAttachedToSign( $sign_id );
251
    my @changedstreams;
252
    my %record_cache = ();
253
254
    # Add records to the streams
255
    foreach my $stream ( @{$streams} ) {
256
257
        my $records = RunSQL( ReplaceParamsInSQL( $stream->{'savedsql'}, $stream->{'params'} ) );
258
259
        if ( $include_marc ) {
260
261
            my @processed_records;
262
            foreach my $rec ( @{$records} ) {
263
                unless(defined $record_cache{$rec->{'biblionumber'}}) {
264
                    my $marc = GetMarcBiblio( $rec->{'biblionumber'} );
265
                    if ( ! $marc ) {
266
                        next;
267
                    }
268
269
                    my $isbn = GetNormalizedISBN( undef, $marc, C4::Context->preference("marcflavor") ) || '';
270
                    $rec->{'isbn'} = $isbn;
271
21
272
                    my $dat = GetBiblioData($rec->{'biblionumber'});
22
use Koha::Database;
273
                    my @items = GetItemsInfo($rec->{'biblionumber'});
23
use Koha::Sign;
274
                    foreach my $item ( @items ) {
275
                        my $shelflocations = GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
276
                        if ( defined $item->{'location'} ) {
277
                            $item->{'location_description'} = $shelflocations->{ $item->{'location'} };
278
                        }
279
                    }
280
                    $rec->{'items'} = \@items;
281
                    foreach ( keys %{$dat} ) {
282
                        $rec->{"$_"} = defined $dat->{$_} ? $dat->{$_} : '';
283
                    }
284
24
285
                    $rec->{'marc'} = $marc;
25
use base qw( Koha::Objects );
286
26
287
                    $record_cache{$rec->{'biblionumber'}} = $rec;
27
=head1 NAME
288
                }
289
                push @processed_records, $record_cache{$rec->{'biblionumber'}};
290
            }
291
            $stream->{'records'} = \@processed_records;
292
28
293
        } else {
29
Koha::Signs - Koha Sign object set class
294
30
295
          $stream->{'records'} = $records;
31
=head1 API
296
32
297
        }
33
=head2 Class Methods
298
34
299
        push @changedstreams, $stream;
35
=cut
300
36
301
    }
37
=head3 type
302
38
303
    return \@changedstreams;
39
=cut
304
40
41
sub _type {
42
    return 'Sign';
305
}
43
}
306
44
307
sub DetachSignStreamFromSign {
45
=head3 object_class
308
309
    my ( $sign_to_stream_id ) = @_;
310
311
    return unless $sign_to_stream_id;
312
46
313
    my $sth = $dbh->prepare( 'DELETE FROM signs_to_streams WHERE sign_to_stream_id = ?' );
47
=cut
314
    return $sth->execute( $sign_to_stream_id );
315
48
49
sub object_class {
50
    return 'Koha::Sign';
316
}
51
}
317
52
318
sub RunSQL {
53
=head1 AUTHOR
319
54
320
    my ( $query ) = @_;
55
Aleisha Amohia <aleisha@catalyst.net.nz>
321
56
322
    return unless $query;
57
=cut
323
324
    my $sth = $dbh->prepare($query);
325
    $sth->execute();
326
    return $sth->fetchall_arrayref({});
327
328
}
329
58
330
1;
59
1;
(-)a/Koha/SignsToStream.pm (+40 lines)
Line 0 Link Here
1
package Koha::SignsToStream;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use base qw( Koha::Object );
25
26
=head1 NAME
27
28
Koha::SignsToStream - SignsToStream object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
sub _type {
37
    return 'SignsToStream';
38
}
39
40
1;
(-)a/Koha/SignsToStreams.pm (+59 lines)
Line 0 Link Here
1
package Koha::SignsToStreams;
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
use Koha::SignsToStream;
24
25
use base qw( Koha::Objects );
26
27
=head1 NAME
28
29
Koha::SignsToStreams - Koha SignsToStream object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'SignsToStream';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::SignsToStream';
51
}
52
53
=head1 AUTHOR
54
55
Aleisha Amohia <aleisha@catalyst.net.nz>
56
57
=cut
58
59
1;
(-)a/installer/data/mysql/atomicupdate/bug_8628-digital-signs.sql (-1 / +1 lines)
Lines 1-4 Link Here
1
DROP TABLE IF EXISTS signs_to_streams;
2
DROP TABLE IF EXISTS sign_streams;
1
DROP TABLE IF EXISTS sign_streams;
3
CREATE TABLE sign_streams (
2
CREATE TABLE sign_streams (
4
  sign_stream_id int(11) NOT NULL auto_increment,    -- primary key, used to identify streams
3
  sign_stream_id int(11) NOT NULL auto_increment,    -- primary key, used to identify streams
Lines 19-24 CREATE TABLE signs ( Link Here
19
  reloadafter int(11) NOT NULL default 0,      -- seconds to wait before reloading all the pages
18
  reloadafter int(11) NOT NULL default 0,      -- seconds to wait before reloading all the pages
20
  PRIMARY KEY (sign_id)
19
  PRIMARY KEY (sign_id)
21
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
21
DROP TABLE IF EXISTS signs_to_streams;
22
CREATE TABLE signs_to_streams (
22
CREATE TABLE signs_to_streams (
23
  sign_to_stream_id int(11) NOT NULL auto_increment, -- primary key, used to identify connections between signs and streams (the same stream can be attached to a sign more than once, with different parameters)
23
  sign_to_stream_id int(11) NOT NULL auto_increment, -- primary key, used to identify connections between signs and streams (the same stream can be attached to a sign more than once, with different parameters)
24
  sign_stream_id int(11) NOT NULL,                   -- foreign key from the decks sign_streams table
24
  sign_stream_id int(11) NOT NULL,                   -- foreign key from the decks sign_streams table
(-)a/installer/data/mysql/kohastructure.sql (+45 lines)
Lines 3921-3926 CREATE TABLE `article_requests` ( Link Here
3921
  CONSTRAINT `article_requests_ibfk_4` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
3921
  CONSTRAINT `article_requests_ibfk_4` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
3922
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3922
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3923
3923
3924
--
3925
-- Table structure for table 'sign_streams'
3926
--
3927
3928
DROP TABLE IF EXISTS sign_streams;
3929
CREATE TABLE sign_streams (
3930
  `sign_stream_id` int(11) NOT NULL auto_increment, -- primary key, used to identify streams
3931
  `saved_sql_id` int(11) NOT NULL, -- foreign key from the saved_sql table
3932
  `name` varchar(64), -- name/title of the sign
3933
  PRIMARY KEY (`sign_stream_id`),
3934
  CONSTRAINT `sign_streams_ibfk_1` FOREIGN KEY (`saved_sql_id`) REFERENCES `saved_sql` (`id`) ON DELETE CASCADE
3935
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3936
3937
--
3938
-- Table structure for table 'signs'
3939
--
3940
3941
DROP TABLE IF EXISTS signs;
3942
CREATE TABLE signs (
3943
  `sign_id` int(11) NOT NULL auto_increment, -- primary key, used to identify signs
3944
  `name` varchar(64), -- name/title of the deck
3945
  `webapp` int(1) NOT NULL DEFAULT 0, -- display as web app or normal page
3946
  `transition` char(16) NOT NULL DEFAULT 'none', -- transition to use between pages, must be one of the transitions defined by jQuery Mobile (see their docs)
3947
  `swatch` char(1) NOT NULL DEFAULT '', -- swatches determine the colors of page elements
3948
  `idleafter` int(11) NOT NULL default 0, -- seconds to wait before automatic page turning clicks in
3949
  `pagedelay` int(11) NOT NULL default 0, -- seconds to wait before turning to a new page/record
3950
  `reloadafter` int(11) NOT NULL default 0, -- seconds to wait before reloading all the pages
3951
  PRIMARY KEY (`sign_id`)
3952
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3953
3954
--
3955
-- Table structure for table 'signs_to_streams'
3956
--
3957
3958
DROP TABLE IF EXISTS signs_to_streams;
3959
CREATE TABLE signs_to_streams (
3960
  `sign_to_stream_id` int(11) NOT NULL auto_increment, -- primary key, used to identify connections between signs and streams (the same stream can be attached to a sign more than once, with different parameters)
3961
  `sign_stream_id` int(11) NOT NULL, -- foreign key from the decks sign_streams table
3962
  `sign_id` int(11) NOT NULL, -- foreign key from the signs table
3963
  `params` varchar(255) NOT NULL DEFAULT '', -- list of parameters for the SQL associated with the sign_stream
3964
  PRIMARY KEY (`sign_to_stream_id`),
3965
  CONSTRAINT `signs_to_streams_ibfk_1` FOREIGN KEY (`sign_stream_id`) REFERENCES `sign_streams` (`sign_stream_id`) ON DELETE CASCADE,
3966
  CONSTRAINT `signs_to_streams_ibfk_2` FOREIGN KEY (`sign_id`) REFERENCES `signs` (`sign_id`) ON DELETE CASCADE
3967
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3968
3924
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3969
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3925
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3970
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3926
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
3971
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc (+3 lines)
Lines 119-124 Link Here
119
    [% IF ( CAN_user_tools_edit_quotes ) %]
119
    [% IF ( CAN_user_tools_edit_quotes ) %]
120
       <li><a href="/cgi-bin/koha/tools/quotes.pl">Quote editor</a></li>
120
       <li><a href="/cgi-bin/koha/tools/quotes.pl">Quote editor</a></li>
121
    [% END %]
121
    [% END %]
122
    [% IF ( CAN_user_tools_edit_digital_signs ) %]
123
        <li><a href="/cgi-bin/koha/tools/signs.pl">Digital signs</a></li>
124
    [% END %]
122
    [% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
125
    [% IF ( UseKohaPlugins && CAN_user_plugins_tool ) %]
123
        <li><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=tool">Tool plugins</a></li>
126
        <li><a href="/cgi-bin/koha/plugins/plugins-home.pl?method=tool">Tool plugins</a></li>
124
    [% END %]
127
    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/signs.tt (-73 / +76 lines)
Lines 6-40 Link Here
6
[% INCLUDE 'datatables.inc' %]
6
[% INCLUDE 'datatables.inc' %]
7
<script type="text/javascript">
7
<script type="text/javascript">
8
//<![CDATA[
8
//<![CDATA[
9
9
    // prepare DOM for YUI Toolbar
10
	// prepare DOM for YUI Toolbar
10
    $(document).ready(function() {
11
	 $(document).ready(function() {
12
        $("#table_signs").dataTable($.extend(true, {}, dataTablesDefaults, {
11
        $("#table_signs").dataTable($.extend(true, {}, dataTablesDefaults, {
13
            "aoColumns": [
12
            "aoColumnDefs": [
14
                null,
13
                { "aTargets": [ -1 ], "bSearchable": false, "bSortable": false },
15
                {"bSearchable": false},
16
                {"bSearchable": false},
17
                {"bSearchable": false},
18
                {"bSearchable": false},
19
                {"bSearchable": false},
20
                {"bSearchable": false},
21
                {"bSearchable": false, "bSortable": false},
22
                {"bSearchable": false, "bSortable": false},
23
                {"bSearchable": false, "bSortable": false},
24
                {"bSearchable": false, "bSortable": false}
25
            ],
14
            ],
26
            "sPaginationType": "four_button"
15
            "sPaginationType": "four_button"
27
        } ));
16
        }));
28
        $("#table_streams").dataTable($.extend(true, {}, dataTablesDefaults, {
17
        $("#table_streams").dataTable($.extend(true, {}, dataTablesDefaults, {
29
            "aoColumns": [
18
            "aoColumnDefs": [
30
                null,
19
                { "aTargets" : [ -1 ], "bSearchable": false, "bSortable": false },
31
                {"bSearchable": false},
32
                {"bSearchable": false, "bSortable": false},
33
                {"bSearchable": false, "bSortable": false},
34
            ],
20
            ],
35
            "sPaginationType": "four_button"
21
            "sPaginationType": "four_button"
36
        } ));
22
        }));
37
	 });
23
24
        $(".detach").on("click", function(){
25
            return confirmDelete(_("Are you sure you want to detach this stream from this sign?"));
26
        });
27
    });
38
//]]>
28
//]]>
39
</script>
29
</script>
40
</head>
30
</head>
Lines 80-105 Link Here
80
</div>
70
</div>
81
71
82
<div id="doc3" class="yui-t2">
72
<div id="doc3" class="yui-t2">
83
73
<div id="bd">
84
   <div id="bd">
74
<div id="yui-main">
85
	<div id="yui-main">
75
<div class="yui-b">
86
	<div class="yui-b">
87
76
88
[% UNLESS Koha.Preference( 'OPACDigitalSigns' ) %]
77
[% UNLESS Koha.Preference( 'OPACDigitalSigns' ) %]
89
<div class="dialog alert">
78
<div class="dialog alert">
90
    <p>
79
    <p>Digital signs are not enabled. Please enable <a href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=OPACDigitalSigns">OPACDigitalSigns</a> for OPAC digital signs to work.</p>
91
    Digital signs are not enabled. Please enable
92
    <a href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=OPACDigitalSigns">OPACDigitalSigns</a>
93
    for OPAC digital signs to work.
94
    </p>
95
</div>
80
</div>
96
[% END %]
81
[% END %]
97
82
98
[% IF ( else ) %]
83
[% IF ( else ) %]
99
  <div id="toolbar">
84
  <div id="toolbar">
100
    <ul class="toolbar">
85
    <ul class="toolbar">
101
      <li><a id="newsign" href="?op=add_sign" class="btn btn-small"><i class="icon-plus"></i>New sign</a></li>
86
      <li><a id="newsign" href="?op=add_sign" class="btn btn-small"><i class="fa fa-plus"></i> New sign</a></li>
102
      <li><a id="newstream" href="?op=add_stream" class="btn btn-small"><i class="icon-plus"></i>New stream</a></li>
87
      <li><a id="newstream" href="?op=add_stream" class="btn btn-small"><i class="fa fa-plus"></i> New stream</a></li>
103
    </ul>
88
    </ul>
104
  </div>
89
  </div>
105
[% END %]
90
[% END %]
Lines 127-134 Link Here
127
  <fieldset class="rows">
112
  <fieldset class="rows">
128
    <ol>
113
    <ol>
129
    <li><label for="name">Name</label><input type="text" name="name" value="[% stream.name %]" /></li>
114
    <li><label for="name">Name</label><input type="text" name="name" value="[% stream.name %]" /></li>
130
    <li><label for="report">Report</label>
115
    <li><label for="report" class="required">Report</label>
131
      <select name="report" id="report">
116
      <select name="report" id="report" class="required" required="required">
132
        [% UNLESS ( stream.sign_stream_id ) %]
117
        [% UNLESS ( stream.sign_stream_id ) %]
133
        <option value="">Choose report</option>
118
        <option value="">Choose report</option>
134
        [% END %]
119
        [% END %]
Lines 140-145 Link Here
140
          [% END %]
125
          [% END %]
141
        [% END %]
126
        [% END %]
142
      </select>
127
      </select>
128
      <span class="required">Required</span>
143
    </li>
129
    </li>
144
    </ol>
130
    </ol>
145
  </fieldset>
131
  </fieldset>
Lines 223-246 Link Here
223
209
224
  <h1>Edit streams attached to [% sign.name %]</h1>
210
  <h1>Edit streams attached to [% sign.name %]</h1>
225
  <h2>Streams already attached to this sign</h2>
211
  <h2>Streams already attached to this sign</h2>
226
  [% IF ( attached.size ) %]
212
  [% IF ( sts ) %]
227
    <table>
213
    <table>
228
    <thead>
214
    <thead>
229
    <tr><th>Name</th><th>Parameters</th><th>Edit parameters</th><th>Detach</th></tr>
215
        <tr>
216
            <th>Name</th>
217
            <th colspan="2">Parameters</th>
218
            <th>&nbsp;</th>
219
        </tr>
230
    </thead>
220
    </thead>
231
    <tbody>
221
    <tbody>
232
    [% FOREACH s IN attached %]
222
    [% FOREACH s IN sts %]
233
      <tr>
223
      <tr>
234
      <td>[% s.name %]</td>
224
        <td>[% s.sign_stream.name %]</td>
235
      <td>[% s.params %]</td>
225
        <td>[% IF ( s.params ) %][% s.params %][% ELSE %]None[% END %]</td>
236
      <td>[% IF s.savedsql.match('<<') %]<a href="?op=get_params&sign_to_stream_id=[% s.sign_to_stream_id %]&sign_stream_id=[% s.sign_stream_id %]&sign_id=[% sign.sign_id %]">Edit parameters</a>[% ELSE %]No parameters[% END %]</td>
226
        <td class="actions">[% IF ( s.params ) %]<a href="?op=get_params&sign_to_stream_id=[% s.sign_to_stream_id %]&sign_stream_id=[% s.sign_stream_id %]&sign_id=[% s.sign_id %]" class="btn btn-mini" title="Edit parameters"><i class="fa fa-pencil"></i></a>[% ELSE %]<a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% s.sign_stream.saved_sql_id %]&phase=Edit SQL" class="btn btn-mini" title="Edit SQL"><i class="fa fa-pencil"></i></a>[% END %]</td>
237
      <td><a href="?op=detach_stream_from_sign&sign_id=[% sign.sign_id %]&sign_to_stream_id=[% s.sign_to_stream_id %]">Detach</a></td>
227
        <td class="actions"><a href="?op=detach_stream_from_sign&sign_id=[% sign.sign_id %]&sign_to_stream_id=[% s.sign_to_stream_id %]" class="btn btn-mini detach"><i class="fa fa-times"></i> Detach</a></td>
238
      </tr>
228
      </tr>
239
    [% END %]
229
    [% END %]
240
    </tbody>
230
    </tbody>
241
    </table>
231
    </table>
242
  [% ELSE %]
232
  [% ELSE %]
243
    <p>There are no streams attached to this sign, yet.</p>
233
    <p>There are no streams attached to this sign.</p>
244
  [% END %]
234
  [% END %]
245
235
246
  <h2>Attach a new stream to this sign</h2>
236
  <h2>Attach a new stream to this sign</h2>
Lines 264-270 Link Here
264
[% ELSIF op == 'get_params' %]
254
[% ELSIF op == 'get_params' %]
265
255
266
  <h1>Parameters for [% stream.name %]</h1>
256
  <h1>Parameters for [% stream.name %]</h1>
267
  <p>Based on report: [% stream.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
257
  <p>Based on report: [% sql.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
268
258
269
  <form action="[% script_name %]" name="get_params_form" id="get_params_form" method="post">
259
  <form action="[% script_name %]" name="get_params_form" id="get_params_form" method="post">
270
  <input type="hidden" name="op" value="save_params" />
260
  <input type="hidden" name="op" value="save_params" />
Lines 272-285 Link Here
272
  <input type="hidden" name="sign_stream_id" value="[% sign_stream_id %]" />
262
  <input type="hidden" name="sign_stream_id" value="[% sign_stream_id %]" />
273
  <input type="hidden" name="sign_id" value="[% sign_id %]" />
263
  <input type="hidden" name="sign_id" value="[% sign_id %]" />
274
  <fieldset class="rows">
264
  <fieldset class="rows">
275
    [% IF ( params ) %]
265
    [% IF ( params.params ) %]
276
      <legend id="save_params_lgd">Edit parameters</legend>
266
      <legend id="save_params_lgd">Edit parameters</legend>
277
    [% ELSE %]
267
    [% ELSE %]
278
      <legend id="save_params_lgd">Add parameters</legend>
268
      <legend id="save_params_lgd">Add parameters</legend>
279
    [% END %]
269
    [% END %]
280
    <ol>
270
    <ol>
281
    <li><label for="stream">Parameters</label>
271
    <li><label for="stream">Parameters</label>
282
      <input type="text" size="60" name="parameters" id="parameters" value="[% params %]" />
272
      <input type="text" size="60" name="parameters" id="parameters" value="[% params.params %]" />
283
    </li>
273
    </li>
284
    </ol>
274
    </ol>
285
  </fieldset>
275
  </fieldset>
Lines 287-293 Link Here
287
  </form>
277
  </form>
288
278
289
  <h2>Raw SQL</h2>
279
  <h2>Raw SQL</h2>
290
  <pre id="sql_output">[% stream.savedsql | html %]</pre>
280
  <pre id="sql_output">[% sql.savedsql | html %]</pre>
291
281
292
  <h2>SQL with current parameters replaced</h2>
282
  <h2>SQL with current parameters replaced</h2>
293
  <pre id="sql_output">[% newsql | html %]</pre>
283
  <pre id="sql_output">[% newsql | html %]</pre>
Lines 305-314 Link Here
305
    <form action="[% script_name %]" id ="confirm_stream_delete_form" method="post">
295
    <form action="[% script_name %]" id ="confirm_stream_delete_form" method="post">
306
    <input type="hidden" name="op" value="del_stream_ok" />
296
    <input type="hidden" name="op" value="del_stream_ok" />
307
    <input type="hidden" name="sign_stream_id" value="[% stream.sign_stream_id %]" />
297
    <input type="hidden" name="sign_stream_id" value="[% stream.sign_stream_id %]" />
308
    <input type="submit" class="approve" value="Yes, Delete this stream" /></form>
298
    <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete this stream</button>
299
    </form>
309
300
310
    <form action="[% script_name %]" id="cancel_stream_delete_form" method="get">
301
    <form action="[% script_name %]" id="cancel_stream_delete_form" method="get">
311
    <input type="submit" value="No, do not delete" class="deny" />
302
    <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i>  No, do not delete</button>
312
    </form>
303
    </form>
313
    </div>
304
    </div>
314
305
Lines 328-337 Link Here
328
    <form action="[% script_name %]" id ="confirm_sign_delete_form" method="post">
319
    <form action="[% script_name %]" id ="confirm_sign_delete_form" method="post">
329
    <input type="hidden" name="op" value="del_sign_ok" />
320
    <input type="hidden" name="op" value="del_sign_ok" />
330
    <input type="hidden" name="sign_id" value="[% sign.sign_id %]" />
321
    <input type="hidden" name="sign_id" value="[% sign.sign_id %]" />
331
    <input type="submit" class="approve" value="Yes, Delete this sign" /></form>
322
    <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete this sign</button>
323
    </form>
332
324
333
    <form action="[% script_name %]" id="cancel_sign_delete_form" method="get">
325
    <form action="[% script_name %]" id="cancel_sign_delete_form" method="get">
334
    <input type="submit" value="No, do not delete" class="deny" />
326
    <button type="submit" class="deny"><i class="fa fa-fw fa-remove"></i> No, do not delete</button>
335
    </form>
327
    </form>
336
    </div>
328
    </div>
337
329
Lines 351-357 Link Here
351
343
352
  [% IF ( streams ) %]
344
  [% IF ( streams ) %]
353
    [% FOREACH stream IN streams %]
345
    [% FOREACH stream IN streams %]
354
      <h3>[% stream.name %]</h3>
346
      <h3>[% stream.sign_stream.name %]</h3>
355
      <ul>
347
      <ul>
356
      [% FOREACH record IN stream.records %]
348
      [% FOREACH record IN stream.records %]
357
        <li><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.biblionumber %]">[% record.title %]</a></li>
349
        <li><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% record.biblionumber %]">[% record.title %]</a></li>
Lines 365-376 Link Here
365
[% ELSIF op == 'view_stream' %]
357
[% ELSIF op == 'view_stream' %]
366
358
367
  <h1>[% stream.name %]</h1>
359
  <h1>[% stream.name %]</h1>
368
  <p>Based on report: [% stream.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
360
  <p>Based on report: [% stream.saved_sql_id.report_name %] | <a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% stream.saved_sql_id %]&phase=Edit SQL">Edit this report</a></p>
369
  <h2>SQL</h2>
361
  <h2>SQL</h2>
370
  <pre id="sql_output">[% stream.savedsql | html %]</pre>
362
  <pre id="sql_output">[% stream.saved_sql_id.savedsql | html %]</pre>
371
  <h2>Records</h2>
363
  <h2>Records</h2>
372
  [% IF ( has_params ) %]
364
  [% IF ( has_params ) %]
373
    <p>Sorry, the report this stream is based on has parameters and displaying it only makes sense after it has been attached to a sign and parameters have been added.</p>
365
    <p>Unable to display records. Check that this stream has been attached to a sign and any parameters have been filled appropriately.</p>
374
  [% ELSE %]
366
  [% ELSE %]
375
    [% INCLUDE display_records %]
367
    [% INCLUDE display_records %]
376
  [% END %]
368
  [% END %]
Lines 379-386 Link Here
379
371
380
  <h1>Digital signs</h1>
372
  <h1>Digital signs</h1>
381
373
374
  [% IF ( error_on_insert_stream ) %]
375
    <div class="dialog error">Failed to create a new stream.</div>
376
  [% ELSIF ( success_on_insert_stream ) %]
377
    <div class="dialog message">New stream added.</div>
378
  [% END %]
379
380
  <h2>Signs</h2>
382
  [% IF signs %]
381
  [% IF signs %]
383
    <h2>Signs</h2>
384
    <table id="table_signs">
382
    <table id="table_signs">
385
        <thead>
383
        <thead>
386
            <tr>
384
            <tr>
Lines 391-400 Link Here
391
                <th>Idle after</th>
389
                <th>Idle after</th>
392
                <th>Page delay</th>
390
                <th>Page delay</th>
393
                <th>Reload after</th>
391
                <th>Reload after</th>
394
                <th>Edit</th>
392
                <th>&nbsp;</th>
395
                <th>Edit streams</th>
396
                <th>Delete</th>
397
                <th>View sign</th>
398
            </tr>
393
            </tr>
399
        </thead>
394
        </thead>
400
        <tbody>
395
        <tbody>
Lines 407-449 Link Here
407
                <td>[% s.idleafter %]</td>
402
                <td>[% s.idleafter %]</td>
408
                <td>[% s.pagedelay %]</td>
403
                <td>[% s.pagedelay %]</td>
409
                <td>[% s.reloadafter %]</td>
404
                <td>[% s.reloadafter %]</td>
410
                <td><a href="?op=edit_sign&amp;sign_id=[% s.sign_id %]">Edit</a></td>
405
                <td>
411
                <td><a href="?op=edit_streams&amp;sign_id=[% s.sign_id %]">Edit streams</a></td>
406
                    <div class="dropdown">
412
                <td><a href="?op=del_sign&amp;sign_id=[% s.sign_id %]">Delete</a></td>
407
                        <a class="btn btn-mini dropdown-toggle" id="opensignsactions[% s.sign_id %]" role="button" data-toggle="dropdown" href="#"> Actions <b class="caret"></b></a>
413
                <td>[% IF ( OPACBaseURL ) %]<a href="http://[% OPACBaseURL %]/cgi-bin/koha/opac-signs.pl?sign=[% s.sign_id %]" title="View this sign in the OPAC">View sign</a>[% END %]</td>
408
                        <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="opensignsactions[% s.sign_id %]">
409
                            <li><a href="/cgi-bin/koha/tools/signs.pl?op=edit_sign&amp;sign_id=[% s.sign_id %]"><i class="fa fa-pencil"></i> Edit</a></li>
410
                            <li><a href="/cgi-bin/koha/tools/signs.pl?op=edit_streams&amp;sign_id=[% s.sign_id %]"><i class="fa fa-pencil"></i> Edit streams</a></li>
411
                            <li><a href="/cgi-bin/koha/tools/signs.pl?op=del_sign&amp;sign_id=[% s.sign_id %]"><i class="fa fa-trash"></i> Delete</a></li>
412
                            [% IF ( OPACBaseURL ) %]<li><a href="[% OPACBaseURL %]/cgi-bin/koha/opac-signs.pl?sign=[% s.sign_id %]" title="View this sign in the OPAC"><i class="fa fa-eye"></i> View sign</a></li>[% END %]
413
                        </ul>
414
                    </div>
415
                </td>
414
            </tr>
416
            </tr>
415
        [% END %]
417
        [% END %]
416
        </tbody>
418
        </tbody>
417
    </table>
419
    </table>
418
    [% UNLESS ( OPACBaseURL ) %]<p>Please note: Links to view signs in the OPAC will only be displayed if you fill in the OPACBaseURL system preference.</p>[% END %]
420
    [% UNLESS ( OPACBaseURL ) %]<p>Please note: Links to view signs in the OPAC will only be displayed if you fill in the OPACBaseURL system preference.</p>[% END %]
419
  [% ELSE %]
421
  [% ELSE %]
420
    <p>No signs defined!</p>
422
    <div class="dialog message">No signs defined. <a href="/cgi-bin/koha/tools/signs.pl?op=add_sign">Create a new sign.</a></div>
421
  [% END %]
423
  [% END %]
422
424
425
  <h2>Streams</h2>
423
  [% IF streams %]
426
  [% IF streams %]
424
    <h2>Streams</h2>
425
    <table id="table_streams">
427
    <table id="table_streams">
426
        <thead>
428
        <thead>
427
            <tr>
429
            <tr>
428
                <th>Name</th>
430
                <th>Name</th>
429
                <th>Report</th>
431
                <th>Report</th>
430
                <th>Edit</th>
432
                <th>Actions</th>
431
                <th>Delete</th>
432
            </tr>
433
            </tr>
433
        </thead>
434
        </thead>
434
        <tbody>
435
        <tbody>
435
        [% FOREACH s IN streams %]
436
        [% FOREACH s IN streams %]
436
            <tr>
437
            <tr>
437
                <td><a href="?op=view_stream&amp;sign_stream_id=[% s.sign_stream_id %]">[% s.name %]</a></td>
438
                <td><a href="?op=view_stream&amp;sign_stream_id=[% s.sign_stream_id %]">[% s.name %]</a></td>
438
                <td title="ID: [% s.saved_sql_id %]">[% s.report_name %]</td>
439
                <td>[% FOREACH r IN reports %][% IF r.id == s.saved_sql_id %][% r.report_name %][% END %][% END %]</td>
439
                <td><a href="?op=edit_stream&amp;sign_stream_id=[% s.sign_stream_id %]">Edit</a></td>
440
                <td class="actions">
440
                <td><a href="?op=del_stream&amp;sign_stream_id=[% s.sign_stream_id %]">Delete</a></td>
441
                    <a href="/cgi-bin/koha/tools/signs.pl?op=edit_stream&amp;sign_stream_id=[% s.sign_stream_id %]" class="btn btn-mini"><i class="fa fa-pencil"></i> Edit</a>
442
                    <a href="/cgi-bin/koha/tools/signs.pl?op=del_stream&amp;sign_stream_id=[% s.sign_stream_id %]" class="btn btn-mini"><i class="fa fa-trash"></i> Delete</a>
443
                </td>
441
            </tr>
444
            </tr>
442
        [% END %]
445
        [% END %]
443
        </tbody>
446
        </tbody>
444
    </table>
447
    </table>
445
  [% ELSE %]
448
  [% ELSE %]
446
    <p>No streams defined!</p>
449
    <div class="dialog message">No streams defined. <a href="/cgi-bin/koha/tools/signs.pl?op=add_stream">Create a new stream.</a></div>
447
  [% END %]
450
  [% END %]
448
451
449
[% END %]
452
[% END %]
(-)a/opac/opac-signs.pl (-5 / +67 lines)
Lines 20-26 Link Here
20
use CGI;
20
use CGI;
21
use C4::Auth;
21
use C4::Auth;
22
use C4::Output;
22
use C4::Output;
23
use C4::Biblio;
24
use C4::Reports::Guided;
25
use C4::Context;
26
use C4::Koha;
27
use C4::Items;
28
use Koha::AuthorisedValues;
23
use Koha::Signs;
29
use Koha::Signs;
30
use Koha::SignStreams;
31
use Koha::SignsToStreams;
24
use Modern::Perl;
32
use Modern::Perl;
25
33
26
binmode STDOUT, ':encoding(UTF-8)'; # FIXME Non-ASCII is broken without this
34
binmode STDOUT, ':encoding(UTF-8)'; # FIXME Non-ASCII is broken without this
Lines 38-48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user({ Link Here
38
46
39
if ( C4::Context->preference('OPACDigitalSigns') ) {
47
if ( C4::Context->preference('OPACDigitalSigns') ) {
40
    if ( $sign_id ne '' ) { # Display a sign with streams
48
    if ( $sign_id ne '' ) { # Display a sign with streams
41
        $template->{VARS}->{'sign'}    = GetSign( $sign_id );
49
        $template->{VARS}->{'sign'} = Koha::Signs->find( $sign_id );
42
        $template->{VARS}->{'streams'} = GetSignStreamsAttachedToSignWithRecords( $sign_id, 1 );
50
43
    }
51
        # Getting sign streams attached to sign with records
44
    else { # Display a list of all available signs
52
        my $schema = Koha::Database->new()->schema();
45
       $template->{VARS}->{'signs'}  = GetSigns();
53
        my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' });
54
        my @changedstreams;
55
        my %record_cache = ();
56
        foreach my $s ( @signstostreams ) {
57
            my $stream = Koha::SignStreams->find( $s->sign_stream_id );
58
            my $sql = get_saved_report($stream->saved_sql_id);
59
            my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $s->sign_to_stream_id });
60
61
            # Generate SQL with added params
62
            my $newsql = $sql->{'savedsql'};
63
            foreach my $param ( split /&/, $params->params ) {
64
                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
65
                $newsql =~ s/$key/$value/g;
66
            }
67
68
            # Run query with new sql
69
            my ( $records, $error ) = execute_query( $newsql, 0, 999999 );
70
            if ( ! $error ) {
71
                $records = $records->fetchall_arrayref({});
72
            }
73
            # Include marc
74
            my @processed_records;
75
            foreach my $rec ( @{$records} ) {
76
                unless (defined $record_cache{$rec->{'biblionumber'}}) {
77
                    my $marc = GetMarcBiblio( $rec->{'biblionumber'} );
78
                    if ( ! $marc ) {
79
                        next;
80
                    }
81
82
                    my $isbn = GetNormalizedISBN( undef, $marc, C4::Context->preference("marcflavor") ) || '';
83
                    $rec->{'isbn'} = $isbn;
84
85
                    my $dat = GetBiblioData($rec->{'biblionumber'});
86
                    my @items = GetItemsInfo($rec->{'biblionumber'});
87
                    foreach my $item ( @items ) {
88
                        my $shelflocations = { map { $_->authorised_value => $_->opac_description } Koha::AuthorisedValues->search_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
89
                        if ( defined $item->{'location'} ) {
90
                            $item->{'location_description'} = $shelflocations->{ $item->{'location'} };
91
                        }
92
                    }
93
                    $rec->{'items'} = \@items;
94
                    foreach ( keys %{$dat} ) {
95
                        $rec->{"$_"} = defined $dat->{$_} ? $dat->{$_} : '';
96
                    }
97
                    $rec->{'marc'} = $marc;
98
                    $record_cache{$rec->{'biblionumber'}} = $rec;
99
                }
100
                push @processed_records, $record_cache{$rec->{'biblionumber'}};
101
            }
102
            $s->{'records'} = \@processed_records;
103
            push @changedstreams, $s;
104
        }
105
        $template->{VARS}->{'streams'} = \@changedstreams;
106
    } else { # Display a list of all available signs
107
        $template->{VARS}->{'signs'}  = Koha::Signs->search({});
46
    }
108
    }
47
}
109
}
48
110
(-)a/tools/signs.pl (-41 / +86 lines)
Lines 16-24 Link Here
16
# You should have received a copy of the GNU General Public License along
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
#
20
#
21
#
22
19
23
=head1 NAME
20
=head1 NAME
24
21
Lines 34-40 Allows authorized users to create and manage digital signs for the OPAC. Link Here
34
31
35
=cut
32
=cut
36
33
34
use Koha::Sign;
37
use Koha::Signs;
35
use Koha::Signs;
36
use Koha::SignStream;
37
use Koha::SignStreams;
38
use Koha::SignsToStreams;
39
38
use CGI;
40
use CGI;
39
use C4::Auth;
41
use C4::Auth;
40
use C4::Context;
42
use C4::Context;
Lines 73-79 if ( $op eq 'add_stream' ) { Link Here
73
75
74
} elsif ( $op eq 'edit_stream' && $sign_stream_id ne '') {
76
} elsif ( $op eq 'edit_stream' && $sign_stream_id ne '') {
75
77
76
    my $stream = GetSignStream( $sign_stream_id );
78
    my $stream = Koha::SignStreams->find( $sign_stream_id );
77
79
78
    $template->param(
80
    $template->param(
79
      'op'          => 'stream_form',
81
      'op'          => 'stream_form',
Lines 84-105 if ( $op eq 'add_stream' ) { Link Here
84
86
85
} elsif ( $op eq 'save_stream' ) {
87
} elsif ( $op eq 'save_stream' ) {
86
88
89
    my $name = $cgi->param('name');
90
    my $report = $cgi->param('report');
87
    if ( $sign_stream_id ne '' ) {
91
    if ( $sign_stream_id ne '' ) {
88
        ModSignStream( $cgi->param('name'), $cgi->param('report'), $cgi->param('sign_stream_id') );
92
        Koha::SignStreams->find( $sign_stream_id )->set({ name => $name, saved_sql_id => $report })->store; # modify
89
    } else {
93
    } else {
90
        AddSignStream( $cgi->param('name'), $cgi->param('report'),  );
94
        Koha::SignStream->new({ name => $name, saved_sql_id => $report })->store; # add new
91
    }
95
    }
92
    print $cgi->redirect($script_name);
96
    print $cgi->redirect($script_name);
93
97
94
} elsif ( $op eq 'view_stream' && $sign_stream_id ne '' ) {
98
} elsif ( $op eq 'view_stream' && $sign_stream_id ne '' ) {
95
99
    my $stream = Koha::SignStreams->find( $sign_stream_id );
96
    my $stream = GetSignStream( $sign_stream_id );
100
    my $report = get_saved_report($stream->saved_sql_id);
97
101
    my $sql = $report->{'savedsql'};
98
    if ( $stream->{'savedsql'} =~ m/<</ ) {
102
    my ( $records, $error ) = execute_query( $sql, 0, 999999 );
99
        $template->param( 'has_params' => 1 );
103
    if ( $records && not $error ) {
104
        $records = $records->fetchall_arrayref({});
105
        $template->param( 'records' => $records );
100
    } else {
106
    } else {
101
        my $records = GetSignStreamRecords( $stream );
107
        $template->param( 'has_params' => 1 );
102
        $template->param( 'records' => $records->{result} );
103
    }
108
    }
104
109
105
    $template->param(
110
    $template->param(
Lines 110-116 if ( $op eq 'add_stream' ) { Link Here
110
115
111
} elsif ( $op eq 'del_stream' ) {
116
} elsif ( $op eq 'del_stream' ) {
112
117
113
    my $stream = GetSignStream( $sign_stream_id );
118
    my $stream = Koha::SignStreams->find( $sign_stream_id );
114
119
115
    $template->param(
120
    $template->param(
116
        'op'          => 'del_stream',
121
        'op'          => 'del_stream',
Lines 119-126 if ( $op eq 'add_stream' ) { Link Here
119
    );
124
    );
120
125
121
} elsif ( $op eq 'del_stream_ok' ) {
126
} elsif ( $op eq 'del_stream_ok' ) {
122
127
    Koha::SignStreams->find( $sign_stream_id )->delete;
123
    DelSignStream( $sign_stream_id );
124
128
125
    $template->param(
129
    $template->param(
126
        'op'          => 'del_stream_ok',
130
        'op'          => 'del_stream_ok',
Lines 139-163 if ( $op eq 'add_stream' ) { Link Here
139
143
140
    $template->param(
144
    $template->param(
141
        'op'          => 'sign_form',
145
        'op'          => 'sign_form',
142
        'sign'        => GetSign( $sign_id ),
146
        'sign'        => Koha::Signs->find( $sign_id ),
143
        'script_name' => $script_name,
147
        'script_name' => $script_name,
144
    );
148
    );
145
149
146
} elsif ( $op eq 'save_sign' ) {
150
} elsif ( $op eq 'save_sign' ) {
147
151
148
    if ($cgi->param('sign_id')) {
152
    if ($cgi->param('sign_id')) {
149
        ModSign( $cgi->param('name'), $cgi->param('webapp'), $cgi->param('swatch'), $cgi->param('transition'), $cgi->param('idleafter'), $cgi->param('pagedelay'), $cgi->param('reloadafter'), $cgi->param('sign_id') );
153
        Koha::Signs->find( $cgi->param('sign_id') )->set({ name => $cgi->param('name'), webapp => $cgi->param('webapp'), swatch => $cgi->param('swatch'), transition => $cgi->param('transition'), idleafter => $cgi->param('idleafter'), pagedelay => $cgi->param('pagedelay'), reloadafter => $cgi->param('reloadafter') })->store; # modify
150
    } else {
154
    } else {
151
        AddSign(  $cgi->param('name'), $cgi->param('webapp'), $cgi->param('swatch'), $cgi->param('transition'), $cgi->param('idleafter'), $cgi->param('pagedelay'), $cgi->param('reloadafter') );
155
        Koha::Sign->new({ name => $cgi->param('name'), webapp => $cgi->param('webapp'), swatch => $cgi->param('swatch'), transition => $cgi->param('transition'), idleafter => $cgi->param('idleafter'), pagedelay => $cgi->param('pagedelay'), reloadafter => $cgi->param('reloadafter') })->store; # add new
152
    }
156
    }
153
    print $cgi->redirect($script_name);
157
    print $cgi->redirect($script_name);
154
158
155
} elsif ( $op eq 'view_sign' && $sign_id ne '' ) {
159
} elsif ( $op eq 'view_sign' && $sign_id ne '' ) {
156
160
161
    # Getting sign streams attached to sign with records
162
    my $schema = Koha::Database->new()->schema();
163
    my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' });
164
    my @changedstreams;
165
166
    foreach my $s ( @signstostreams ) {
167
        my $stream = Koha::SignStreams->find( $s->sign_stream_id );
168
        my $sql = get_saved_report($stream->saved_sql_id);
169
        my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $s->sign_to_stream_id });
170
        # Generate SQL with added params
171
        my $newsql = $sql->{'savedsql'};
172
        foreach my $param ( split /&/, $params->params ) {
173
            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
174
            $newsql =~ s/$key/$value/g;
175
        }
176
        # Run query with new sql
177
        my ( $records, $error ) = execute_query( $newsql, 0, 999999 );
178
        if ( $records && not $error ) {
179
            $s->{'records'} = $records->fetchall_arrayref({});
180
            push @changedstreams, $s;
181
        }
182
    }
183
157
    $template->param(
184
    $template->param(
158
        'op'          => 'view_sign',
185
        'op'          => 'view_sign',
159
        'sign'        => GetSign( $sign_id ),
186
        'sign'        => Koha::Signs->find( $sign_id ),
160
        'streams'     => GetSignStreamsAttachedToSignWithRecords( $sign_id, 0 ),
187
        'streams'     => \@changedstreams,
161
        'script_name' => $script_name,
188
        'script_name' => $script_name,
162
    );
189
    );
163
190
Lines 165-177 if ( $op eq 'add_stream' ) { Link Here
165
192
166
    $template->param(
193
    $template->param(
167
        'op'          => 'del_sign',
194
        'op'          => 'del_sign',
168
        'sign'        => GetSign( $sign_id ),
195
        'sign'        => Koha::Signs->find( $sign_id ),
169
        'script_name' => $script_name,
196
        'script_name' => $script_name,
170
    );
197
    );
171
198
172
} elsif ( $op eq 'del_sign_ok' ) {
199
} elsif ( $op eq 'del_sign_ok' ) {
173
200
174
    DelSign( $sign_id );
201
    Koha::Signs->find( $sign_id )->delete;
175
202
176
    $template->param(
203
    $template->param(
177
        'op'          => 'del_sign_ok',
204
        'op'          => 'del_sign_ok',
Lines 182-203 if ( $op eq 'add_stream' ) { Link Here
182
209
183
} elsif ( $op eq 'edit_streams' && $sign_id ne '') {
210
} elsif ( $op eq 'edit_streams' && $sign_id ne '') {
184
211
212
    my $sign = Koha::Signs->find( $sign_id );
213
    my $streams = Koha::SignStreams->search({});
214
215
    my $schema = Koha::Database->new()->schema();
216
    my @signstostreams = $schema->resultset('SignsToStream')->search({ 'me.sign_id' => $sign_id }, { prefetch => 'sign_stream' });
217
185
    $template->param(
218
    $template->param(
186
        'op'          => 'edit_streams',
219
        'op'          => 'edit_streams',
187
        'sign'        => GetSign( $sign_id ),
220
        'sign'        => $sign,
188
        'sign_id'     => $sign_id,
221
        'sign_id'     => $sign_id,
189
        'streams'     => GetSignStreams(),
222
        'streams'     => $streams,
190
        'attached'    => GetSignStreamsAttachedToSign( $sign_id ),
223
        'sts'         => \@signstostreams,
191
        'script_name' => $script_name
224
        'script_name' => $script_name
192
    );
225
    );
193
226
194
} elsif ( $op eq 'attach_stream_to_sign' && $sign_stream_id ne '' && $sign_id ne '' ) {
227
} elsif ( $op eq 'attach_stream_to_sign' && $sign_stream_id ne '' && $sign_id ne '' ) {
195
228
196
    my $sign_to_stream_id = AttachSignStreamToSign( $sign_stream_id, $sign_id );
229
    Koha::SignsToStream->new({ sign_stream_id => $sign_stream_id, sign_id => $sign_id })->store;
197
230
198
    # Check if the SQL associated with the stream needs parameters
231
    # Check if the SQL associated with the stream needs parameters
199
    my $stream = GetSignStream( $sign_stream_id );
232
    my $stream = Koha::SignStreams->find( $sign_stream_id );
200
    if ( $stream->{'savedsql'} =~ m/<</ ) {
233
    my $sql = get_saved_report($stream->saved_sql_id);
234
    if ( $sql->{'savedsql'} =~ m/WHERE/ ) {
201
        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 );
235
        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 );
202
    } else {
236
    } else {
203
        print $cgi->redirect( $script_name . '?op=edit_streams&sign_id=' . $sign_id );
237
        print $cgi->redirect( $script_name . '?op=edit_streams&sign_id=' . $sign_id );
Lines 205-214 if ( $op eq 'add_stream' ) { Link Here
205
239
206
} elsif ( $op eq 'get_params' && $sign_to_stream_id ne '' && $sign_stream_id ne '' && $sign_id ne '' ) {
240
} elsif ( $op eq 'get_params' && $sign_to_stream_id ne '' && $sign_stream_id ne '' && $sign_id ne '' ) {
207
241
208
    my $stream = GetSignStream( $sign_stream_id );
242
    my $stream = Koha::SignStreams->find( $sign_stream_id );
209
    my $records = GetSignStreamRecords($stream, $sign_to_stream_id);
243
    my $sql = get_saved_report($stream->saved_sql_id);
210
    if ( $records ) {
244
    my $params = Koha::SignsToStreams->find({ sign_to_stream_id => $sign_to_stream_id });
211
        $template->param( 'records' => $records->{result} );
245
    # Generate SQL with added params
246
    my $newsql = $sql->{'savedsql'};
247
    foreach my $param ( split /&/, $params->params ) {
248
        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
249
        $newsql =~ s/$key/$value/g;
250
    }
251
    # Run query with new sql
252
    my ( $records, $error ) = execute_query( $newsql, 0, 999999 );
253
    if ( $records && not $error) {
254
        $template->param( 'records' => $records->fetchall_arrayref({}) );
212
    } else {
255
    } else {
213
        $template->param( 'has_params' => 1 );
256
        $template->param( 'has_params' => 1 );
214
    }
257
    }
Lines 219-246 if ( $op eq 'add_stream' ) { Link Here
219
        'sign_id'           => $sign_id,
262
        'sign_id'           => $sign_id,
220
        'sign_stream_id'    => $sign_stream_id,
263
        'sign_stream_id'    => $sign_stream_id,
221
        'sign_to_stream_id' => $sign_to_stream_id,
264
        'sign_to_stream_id' => $sign_to_stream_id,
222
        'params'            => GetSignStreamParams( $sign_to_stream_id ),
265
        'params'            => $params,
223
        'newsql'            => $records->{sql},
266
        'sql'               => $sql,
267
        'newsql'            => $newsql,
224
        'script_name'       => $script_name,
268
        'script_name'       => $script_name,
225
    );
269
    );
226
270
227
} elsif ( $op eq 'save_params' && $sign_to_stream_id ne '' && $sign_id ne '' ) {
271
} elsif ( $op eq 'save_params' && $sign_to_stream_id ne '' && $sign_id ne '' ) {
228
272
229
    ModSignStreamParams( $sign_to_stream_id, $parameters );
273
    Koha::SignsToStreams->find( $sign_to_stream_id )->set({ params => $parameters })->store;
230
    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 );
274
    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 );
231
275
232
} elsif ( $op eq 'detach_stream_from_sign' && $sign_to_stream_id ne '' ) {
276
} elsif ( $op eq 'detach_stream_from_sign' && $sign_to_stream_id ne '' ) {
233
277
234
    DetachSignStreamFromSign( $sign_to_stream_id );
278
    Koha::SignsToStreams->find( $sign_to_stream_id )->delete;
235
    print $cgi->redirect($script_name . '?op=edit_streams&sign_id=' . $sign_id);
279
    print $cgi->redirect($script_name . '?op=edit_streams&sign_id=' . $sign_id);
236
280
237
} else {
281
} else {
238
282
239
    # TODO Check the setting of OPACDigitalSigns, give a warning if it is off
283
    my $streams = Koha::SignStreams->search({});
284
    my $signs   = Koha::Signs->search({});
240
285
241
    $template->param(
286
    $template->param(
242
        'streams'     => GetSignStreams(),
287
        'streams'     => $streams,
243
        'signs'       => GetSigns(),
288
        'signs'       => $signs,
289
        'reports'     => get_saved_reports( { group => 'SIG' } ),
244
        'OPACBaseURL' => C4::Context->preference( 'OPACBaseURL' ) || '',
290
        'OPACBaseURL' => C4::Context->preference( 'OPACBaseURL' ) || '',
245
        'else'        => 1
291
        'else'        => 1
246
    );
292
    );
247
- 

Return to bug 8628