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

(-)a/C4/Letters.pm (-5 / +158 lines)
Lines 22-27 use warnings; Link Here
22
22
23
use MIME::Lite;
23
use MIME::Lite;
24
use Mail::Sendmail;
24
use Mail::Sendmail;
25
use Date::Calc qw( Add_Delta_Days );
26
use Encode;
27
use Carp;
28
use Template;
29
use Module::Load::Conditional qw(can_load);
25
30
26
use C4::Koha qw(GetAuthorisedValueByCode);
31
use C4::Koha qw(GetAuthorisedValueByCode);
27
use C4::Members;
32
use C4::Members;
Lines 33-43 use C4::Debug; Link Here
33
use Koha::DateUtils;
38
use Koha::DateUtils;
34
use Koha::SMS::Providers;
39
use Koha::SMS::Providers;
35
40
36
use Date::Calc qw( Add_Delta_Days );
37
use Encode;
38
use Carp;
39
use Koha::Email;
41
use Koha::Email;
40
use Koha::DateUtils qw( format_sqldatetime );
42
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
43
42
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
44
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
43
45
Lines 704-711 sub GetPreparedLetter { Link Here
704
        }
706
        }
705
    }
707
    }
706
708
709
    $letter->{content} = _process_tt(
710
        {
711
            content => $letter->{content},
712
            tables  => $tables,
713
        }
714
    );
715
707
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
716
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
708
#   $letter->{content} =~ s/<<[^>]*>>//go;
709
717
710
    return $letter;
718
    return $letter;
711
}
719
}
Lines 1363-1368 sub _set_message_status { Link Here
1363
    return $result;
1371
    return $result;
1364
}
1372
}
1365
1373
1374
sub _process_tt {
1375
    my ( $params ) = @_;
1376
1377
    my $content = $params->{content};
1378
    my $tables = $params->{tables};
1379
1380
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
1381
    my $template           = Template->new(
1382
        {
1383
            EVAL_PERL    => 1,
1384
            ABSOLUTE     => 1,
1385
            PLUGIN_BASE  => 'Koha::Template::Plugin',
1386
            COMPILE_EXT  => $use_template_cache ? '.ttc' : '',
1387
            COMPILE_DIR  => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
1388
            FILTERS      => {},
1389
            ENCODING     => 'UTF-8',
1390
        }
1391
    ) or die Template->error();
1392
1393
    my $tt_params = _get_tt_params( $tables );
1394
1395
    my $output;
1396
    $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error();
1397
1398
    return $output;
1399
}
1400
1401
sub _get_tt_params {
1402
    my ($tables) = @_;
1403
1404
    my $params;
1405
1406
    my $config = {
1407
        biblio => {
1408
            module   => 'Koha::Biblios',
1409
            singular => 'biblio',
1410
            plural   => 'biblios',
1411
            pk       => 'biblionumber',
1412
        },
1413
        borrowers => {
1414
            module   => 'Koha::Patrons',
1415
            singular => 'borrower',
1416
            plural   => 'borrowers',
1417
            pk       => 'borrowernumber',
1418
        },
1419
        branches => {
1420
            module   => 'Koha::Libraries',
1421
            singular => 'branch',
1422
            plural   => 'branches',
1423
            pk       => 'branchcode',
1424
        },
1425
        items => {
1426
            module   => 'Koha::Items',
1427
            singular => 'item',
1428
            plural   => 'items',
1429
            pk       => 'itemnumber',
1430
        },
1431
        opac_news => {
1432
            module   => 'Koha::News',
1433
            singular => 'news',
1434
            plural   => 'news',
1435
            pk       => 'idnew',
1436
        },
1437
        reserves => {
1438
            module   => 'Koha::Holds',
1439
            singular => 'hold',
1440
            plural   => 'holds',
1441
            fk       => [ 'borrowernumber', 'biblionumber' ],
1442
        },
1443
        serial => {
1444
            module   => 'Koha::Serials',
1445
            singular => 'serial',
1446
            plural   => 'serials',
1447
            pk       => 'serialid',
1448
        },
1449
        subscription => {
1450
            module   => 'Koha::Subscriptions',
1451
            singular => 'subscription',
1452
            plural   => 'subscriptions',
1453
            pk       => 'subscriptionid',
1454
        },
1455
        suggestions => {
1456
            module   => 'Koha::Suggestions',
1457
            singular => 'suggestion',
1458
            plural   => 'suggestions',
1459
            pk       => 'suggestionid',
1460
        },
1461
        issues => {
1462
            module   => 'Koha::Checkouts',
1463
            singular => 'checkout',
1464
            plural   => 'checkouts',
1465
            fk       => 'itemnumber',
1466
        },
1467
        borrower_modifications => {
1468
            module   => 'Koha::Patron::Modifications',
1469
            singular => 'patron_modification',
1470
            plural   => 'patron_modifications',
1471
            fk       => 'verification_token',
1472
        },
1473
    };
1474
1475
    foreach my $table ( keys %$tables ) {
1476
        next unless $config->{$table};
1477
1478
        my $ref = ref( $tables->{$table} ) || q{};
1479
        my $module = $config->{$table}->{module};
1480
1481
        if ( can_load( modules => { $module => undef } ) ) {
1482
            my $pk = $config->{$table}->{pk};
1483
            my $fk = $config->{$table}->{fk};
1484
1485
            if ( $ref eq q{} || $ref eq 'HASH' ) {
1486
                my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table};
1487
                my $object;
1488
                if ( $fk ) { # Using a foreign key for lookup
1489
                    $object = $module->search( { $fk => $id } )->next();
1490
                } else { # using the table's primary key for lookup
1491
                    $object = $module->find($id);
1492
                }
1493
                $params->{ $config->{$table}->{singular} } = $object;
1494
            }
1495
            else {    # $ref eq 'ARRAY'
1496
                my $object;
1497
                if ( @{ $tables->{$table} } == 1 ) {    # Param is a single key
1498
                    $object = $module->search( { $pk => $tables->{$table} } )->next();
1499
                }
1500
                else {                                  # Params are mutliple foreign keys
1501
                    my @values = @{ $tables->{$table} };
1502
                    my @keys   = @{ $config->{$table}->{fk} };
1503
                    my %params = map { $_ => shift(@values) } @keys;
1504
                    $object = $module->search( \%params )->next();
1505
                }
1506
                $params->{ $config->{$table}->{singular} } = $object;
1507
            }
1508
        }
1509
        else {
1510
            croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR";
1511
        }
1512
    }
1513
1514
    $params->{today} = dt_from_string();
1515
1516
    return $params;
1517
}
1518
1366
1519
1367
1;
1520
1;
1368
__END__
1521
__END__
(-)a/Koha/Checkout.pm (+52 lines)
Line 0 Link Here
1
package Koha::Checkout;
2
3
# Copyright ByWater Solutions 2015
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 Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Checkout - Koha Checkout object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'Issue';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
1;
(-)a/Koha/Checkouts.pm (+62 lines)
Line 0 Link Here
1
package Koha::Checkouts;
2
3
# Copyright ByWater Solutions 2015
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 Carp;
23
24
use Koha::Database;
25
26
use Koha::Checkout;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Checkouts - Koha Checkout object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub _type {
45
    return 'Issue';
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Checkout';
54
}
55
56
=head1 AUTHOR
57
58
Kyle M Hall <kyle@bywatersolutions.com>
59
60
=cut
61
62
1;
(-)a/Koha/News.pm (+62 lines)
Line 0 Link Here
1
package Koha::News;
2
3
# Copyright ByWater Solutions 2015
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 Carp;
23
24
use Koha::Database;
25
26
use Koha::NewsItem;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::News - Koha News object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub _type {
45
    return 'OpacNews';
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::NewsItem';
54
}
55
56
=head1 AUTHOR
57
58
Kyle M Hall <kyle@bywatersolutions.com>
59
60
=cut
61
62
1;
(-)a/Koha/NewsItem.pm (+54 lines)
Line 0 Link Here
1
package Koha::NewsItem;
2
3
# Copyright ByWater Solutions 2015
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 Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::NewsItem - Koha News Item object class
31
32
Koha::NewsItem represents a single piece of news from the opac_news table
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub _type {
45
    return 'OpacNews';
46
}
47
48
=head1 AUTHOR
49
50
Kyle M Hall <kyle@bywatersolutions.com>
51
52
=cut
53
54
1;
(-)a/Koha/Patron/Modification.pm (+52 lines)
Line 0 Link Here
1
package Koha::Patron::Modification;
2
3
# Copyright ByWater Solutions 2014
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 Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Item - Koha Item object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'BorrowerModification';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
1;
(-)a/Koha/Patron/Modifications.pm (-2 / +22 lines)
Lines 27-36 use Modern::Perl; Link Here
27
use C4::Context;
27
use C4::Context;
28
use C4::Debug;
28
use C4::Debug;
29
29
30
use base qw(Koha::Objects);
31
30
sub new {
32
sub new {
31
    my ( $class, %args ) = @_;
33
    my ( $self, %args ) = @_;
34
35
    $self = $self->SUPER::new(@_);
36
37
    foreach my $key ( keys %args ) {
38
        $self->{$key} = $args{$key};
39
    }
32
40
33
    return bless( \%args, $class );
41
    return $self;
34
}
42
}
35
43
36
=head2 AddModifications
44
=head2 AddModifications
Lines 304-307 sub GetModifications { Link Here
304
    return $data;
312
    return $data;
305
}
313
}
306
314
315
sub _type {
316
    return 'BorrowerModification';
317
}
318
319
=head3 object_class
320
321
=cut
322
323
sub object_class {
324
    return 'Koha::Patron::Modification';
325
}
326
307
1;
327
1;
(-)a/Koha/Suggestion.pm (+52 lines)
Line 0 Link Here
1
package Koha::Suggestion;
2
3
# Copyright ByWater Solutions 2015
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 Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Suggestion - Koha Suggestion object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'Suggestion';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
1;
(-)a/Koha/Suggestions.pm (+62 lines)
Line 0 Link Here
1
package Koha::Suggestions;
2
3
# Copyright ByWater Solutions 2015
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 Carp;
23
24
use Koha::Database;
25
26
use Koha::Suggestion;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Suggestions - Koha Suggestion object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub _type {
45
    return 'Suggestion';
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Suggestion';
54
}
55
56
=head1 AUTHOR
57
58
Kyle M Hall <kyle@bywatersolutions.com>
59
60
=cut
61
62
1;
(-)a/tools/letter.pl (-1 / +1 lines)
Lines 259-264 sub add_validate { Link Here
259
    my @content       = $input->multi_param('content');
259
    my @content       = $input->multi_param('content');
260
    for my $mtt ( @mtt ) {
260
    for my $mtt ( @mtt ) {
261
        my $is_html = $input->param("is_html_$mtt");
261
        my $is_html = $input->param("is_html_$mtt");
262
        my $is_tt = $input->param("is_tt_$mtt") ? 1 : 0;
262
        my $title   = shift @title;
263
        my $title   = shift @title;
263
        my $content = shift @content;
264
        my $content = shift @content;
264
        my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt);
265
        my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt);
265
- 

Return to bug 14757