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

(-)a/C4/Letters.pm (-5 / +5 lines)
Lines 762-768 sub _parseletter_sth { Link Here
762
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
762
    ($table eq 'subscription') ? "SELECT * FROM $table WHERE subscriptionid = ?" :
763
    ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
763
    ($table eq 'serial') ? "SELECT * FROM $table WHERE serialid = ?" :
764
    ($table eq 'problem_reports') ? "SELECT * FROM $table WHERE reportid = ?" :
764
    ($table eq 'problem_reports') ? "SELECT * FROM $table WHERE reportid = ?" :
765
    ($table eq 'additional_contents' || $table eq 'opac_news') ? "SELECT * FROM additional_contents WHERE idnew = ?" :
765
    ($table eq 'additional_contents' || $table eq 'opac_news') ? "SELECT * FROM additional_contents_localizations WHERE id = ?" :
766
    ($table eq 'recalls') ? "SELECT * FROM $table WHERE recall_id = ?" :
766
    ($table eq 'recalls') ? "SELECT * FROM $table WHERE recall_id = ?" :
767
    undef ;
767
    undef ;
768
    unless ($query) {
768
    unless ($query) {
Lines 1733-1748 sub _get_tt_params { Link Here
1733
            pk       => 'itemnumber',
1733
            pk       => 'itemnumber',
1734
        },
1734
        },
1735
        additional_contents => {
1735
        additional_contents => {
1736
            module   => 'Koha::AdditionalContents',
1736
            module   => 'Koha::AdditionalContentsLocalizations',
1737
            singular => 'additional_content',
1737
            singular => 'additional_content',
1738
            plural   => 'additional_contents',
1738
            plural   => 'additional_contents',
1739
            pk       => 'idnew',
1739
            pk       => 'id',
1740
        },
1740
        },
1741
        opac_news => {
1741
        opac_news => {
1742
            module   => 'Koha::AdditionalContents',
1742
            module   => 'Koha::AdditionalContentsLocalizations',
1743
            singular => 'news',
1743
            singular => 'news',
1744
            plural   => 'news',
1744
            plural   => 'news',
1745
            pk       => 'idnew',
1745
            pk       => 'id',
1746
        },
1746
        },
1747
        aqorders => {
1747
        aqorders => {
1748
            module   => 'Koha::Acquisition::Orders',
1748
            module   => 'Koha::Acquisition::Orders',
(-)a/C4/Members.pm (-20 / +4 lines)
Lines 516-555 sub IssueSlip { Link Here
516
                issues      => $all,
516
                issues      => $all,
517
            };
517
            };
518
        }
518
        }
519
        my $news = Koha::AdditionalContents->search_for_display(
519
        my @news_ids = Koha::AdditionalContents->search_for_display(
520
            {
520
            {
521
                category   => 'news',
521
                category   => 'news',
522
                location   => 'slip',
522
                location   => 'slip',
523
                lang       => $patron->lang,
523
                lang       => $patron->lang,
524
                library_id => $branch,
524
                library_id => $branch,
525
            }
525
            }
526
        );
526
        )->get_column('id');
527
        my @news;
528
        while ( my $n = $news->next ) {
529
            my $all = $n->unblessed_all_relateds;
530
531
            # FIXME We keep newdate and timestamp for backward compatibility (from GetNewsToDisplay)
532
            # But we should remove them and adjust the existing templates in a db rev
533
            # FIXME This must be formatted in the notice template
534
            my $published_on_dt = output_pref({ dt => dt_from_string( $all->{published_on} ), dateonly => 1 });
535
            $all->{newdate} = $published_on_dt;
536
            $all->{timestamp} = $published_on_dt;
537
538
            push @news, {
539
                additional_contents => $all,
540
            };
541
        }
542
        $letter_code = 'ISSUESLIP';
527
        $letter_code = 'ISSUESLIP';
543
        %repeat      = (
528
        %repeat      = (
544
            checkedout => \@checkouts,
529
            checkedout => \@checkouts,
545
            overdue    => \@overdues,
530
            overdue    => \@overdues,
546
            news       => \@news,
547
        );
531
        );
548
        %loops = (
532
        %loops = (
549
            issues => [ map { $_->{issues}{itemnumber} } @checkouts ],
533
            issues => [ map { $_->{issues}{itemnumber} } @checkouts ],
550
            overdues   => [ map { $_->{issues}{itemnumber} } @overdues ],
534
            overdues   => [ map { $_->{issues}{itemnumber} } @overdues ],
551
            opac_news => [ map { $_->{additional_contents}{idnew} } @news ],
535
            opac_news => \@news_ids,
552
            additional_contents => [ map { $_->{additional_contents}{idnew} } @news ],
536
            additional_contents => \@news_ids,
553
        );
537
        );
554
    }
538
    }
555
539
(-)a/Koha/AdditionalContent.pm (-4 / +60 lines)
Lines 19-29 package Koha::AdditionalContent; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
23
use Koha::Database;
22
use Koha::Database;
24
use Koha::DateUtils qw( dt_from_string );
23
use Koha::DateUtils qw( dt_from_string );
25
use Koha::Libraries;
24
use Koha::Libraries;
26
use Koha::Patrons;
25
use Koha::Patrons;
26
use Koha::AdditionalContentsLocalizations;
27
27
28
use base qw(Koha::Object);
28
use base qw(Koha::Object);
29
29
Lines 61-67 Returns 1 if the additional content is expired or 0; Link Here
61
=cut
61
=cut
62
62
63
sub is_expired {
63
sub is_expired {
64
    my ( $self ) = @_;
64
    my ($self) = @_;
65
65
66
    return 0 unless $self->expirationdate;
66
    return 0 unless $self->expirationdate;
67
    return 1 if dt_from_string( $self->expirationdate ) < dt_from_string->truncate( to => 'day' );
67
    return 1 if dt_from_string( $self->expirationdate ) < dt_from_string->truncate( to => 'day' );
Lines 77-89 Returns Koha::Library object or undef Link Here
77
=cut
77
=cut
78
78
79
sub library {
79
sub library {
80
    my ( $self ) = @_;
80
    my ($self) = @_;
81
81
82
    my $library_rs = $self->_result->branchcode;
82
    my $library_rs = $self->_result->branchcode;
83
    return unless $library_rs;
83
    return unless $library_rs;
84
    return Koha::Library->_new_from_dbic( $library_rs );
84
    return Koha::Library->_new_from_dbic($library_rs);
85
}
86
87
=head3 translated_contents
88
89
my $translated_contents = $additional_content->translated_contents;
90
$additional_content->translated_contents(\@contents)
91
92
=cut
93
94
sub translated_contents {
95
    my ( $self, $localizations ) = @_;
96
    if ($localizations) {
97
        my $schema = $self->_result->result_source->schema;
98
        $schema->txn_do(
99
            sub {
100
                $self->translated_contents->delete;
101
102
                for my $localization (@$localizations) {
103
                    $self->_result->add_to_additional_contents_localizations($localization);
104
                }
105
            }
106
        );
107
    }
108
109
    my $rs = $self->_result->additional_contents_localizations;
110
    return Koha::AdditionalContentsLocalizations->_new_from_dbic($rs);
85
}
111
}
86
112
113
=head3 default_localization
114
115
my $default_content = $additional_content->default_localization;
116
117
Return the default content.
118
119
=cut
120
121
sub default_localization {
122
    my ($self) = @_;
123
    my $rs = $self->_result->additional_contents_localizations->find( { lang => 'default' } );
124
    return Koha::AdditionalContentsLocalization->_new_from_dbic($rs);
125
}
126
127
=head3 translated_content
128
129
my $translated_content = $additional_content->translated_content($lang);
130
131
Return the translated content for a given language. The default is returned if none exist.
132
133
=cut
134
135
sub translated_content {
136
    my ( $self, $lang ) = @_;
137
    my $content = $self->translated_contents->search(
138
        { lang => [ 'default', ( $lang ? $lang : () ) ] },
139
        { ( $lang ? ( order_by => \[ "field(lang, '" . $lang . "', 'default')" ] ) : () ) }
140
    )->next;
141
    return $content;
142
}
87
143
88
=head3 _type
144
=head3 _type
89
145
(-)a/Koha/AdditionalContents.pm (-28 / +33 lines)
Lines 19-27 package Koha::AdditionalContents; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Array::Utils qw( array_minus );
23
22
use Koha::Database;
24
use Koha::Database;
23
use Koha::Exceptions;
25
use Koha::Exceptions;
24
use Koha::AdditionalContent;
26
use Koha::AdditionalContent;
27
use Koha::AdditionalContentsLocalizations;
25
28
26
use base qw(Koha::Objects);
29
use base qw(Koha::Objects);
27
30
Lines 72-115 sub search_for_display { Link Here
72
    my ( $self, $params ) = @_;
75
    my ( $self, $params ) = @_;
73
76
74
    my $search_params;
77
    my $search_params;
75
    $search_params->{location} = $params->{location};
78
    $search_params->{location}     = $params->{location};
76
    $search_params->{branchcode} = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
79
    $search_params->{branchcode}   = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
77
    $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' };
80
    $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' };
78
    $search_params->{-or} = [ expirationdate => { '>=' => \'CAST(NOW() AS DATE)' },
81
    $search_params->{-or}          = [
79
                              expirationdate => undef ];
82
        expirationdate => { '>=' => \'CAST(NOW() AS DATE)' },
83
        expirationdate => undef
84
    ];
80
    $search_params->{category} = $params->{category} if $params->{category};
85
    $search_params->{category} = $params->{category} if $params->{category};
81
86
87
    my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } );
88
82
    if ( $params->{lang} ) {
89
    if ( $params->{lang} ) {
83
        # FIXME I am failing to translate the following query
90
        my $translated_contents = Koha::AdditionalContentsLocalizations->search(
84
        # SELECT   a1.category,   a1.code,   COALESCE(a2.title, a1.title)
85
        # FROM additional_contents a1
86
        # LEFT JOIN additional_contents a2 on a1.code=a2.code AND a2.lang="es-ES"
87
        # WHERE a1.lang = 'default';
88
89
        # So we are retrieving the code with a translated content, then the other ones
90
        my $translated_contents =
91
          $self->SUPER::search( { %$search_params, lang => $params->{lang} } );
92
        my $default_contents = $self->SUPER::search(
93
            {
91
            {
94
                %$search_params,
92
                additional_content_id => [$contents->get_column('id')],
95
                lang => 'default',
93
                lang => $params->{lang},
96
                code =>
97
                  { '-not_in' => [ $translated_contents->get_column('code') ] }
98
            }
94
            }
99
        );
95
        );
100
96
        my @all_content_id = $contents->get_column('id');
101
        return $self->SUPER::search(
97
        my @translated_content_id = $translated_contents->get_column('additional_content_id');
98
        my $default_contents    = Koha::AdditionalContentsLocalizations->search(
99
            {
100
                additional_content_id => [array_minus(@all_content_id, @translated_content_id)],
101
                lang                  => 'default',
102
            }
103
        );
104
        return Koha::AdditionalContentsLocalizations->search(
102
            {
105
            {
103
                idnew => [
106
                id => [
104
                    $translated_contents->get_column('idnew'),
107
                    $translated_contents->get_column('id'),
105
                    $default_contents->get_column('idnew')
108
                    $default_contents->get_column('id'),
106
                ]
109
                ]
107
            },
110
            },
108
            { order_by => 'number' }
109
        );
111
        );
110
    }
112
    }
111
113
    return $contents->search( { lang => 'default' }, { order_by => 'number' } )->translated_contents;
112
    return $self->SUPER::search({%$search_params, lang => 'default'}, { order_by => 'number'});
113
}
114
}
114
115
115
=head3 find_best_match
116
=head3 find_best_match
Lines 129-141 sub find_best_match { Link Here
129
    my $library_id = $params->{library_id};
130
    my $library_id = $params->{library_id};
130
    my $lang = $params->{lang};
131
    my $lang = $params->{lang};
131
132
132
    my $rs = $self->SUPER::search({
133
    my $contents = $self->SUPER::search({
133
        category => $params->{category},
134
        category => $params->{category},
134
        location => $params->{location},
135
        location => $params->{location},
135
        lang => [ $lang, 'default' ],
136
        branchcode => [ $library_id, undef ],
136
        branchcode => [ $library_id, undef ],
137
    });
137
    });
138
138
139
    my $rs = Koha::AdditionalContentsLocalizations->search({
140
            additional_content_id => [ $contents->get_column('id') ],
141
            lang => [ $lang, 'default' ],
142
        });
143
139
    # Pick the best
144
    # Pick the best
140
    my ( $alt1, $alt2, $alt3 );
145
    my ( $alt1, $alt2, $alt3 );
141
    while( my $rec = $rs->next ) {
146
    while( my $rec = $rs->next ) {
(-)a/Koha/AdditionalContentsLocalization.pm (+217 lines)
Line 0 Link Here
1
package Koha::AdditionalContentsLocalization;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
use Koha::AdditionalContents;
22
23
use base qw(Koha::Object);
24
25
=head1 NAME
26
27
Koha::AdditionalContentsLocalization - Koha Additional content localization object class
28
29
=head1 API
30
31
=head2 Class Methods
32
33
=cut
34
35
=head3 additional_content
36
37
    $c->additional_content;
38
39
Return the Koha::AdditionalContent for this translated content.
40
41
=cut
42
43
sub additional_content {
44
    my ( $self ) = @_;
45
    my $rs = $self->_result->additional_content;
46
    return Koha::AdditionalContent->_new_from_dbic($rs);
47
}
48
49
=head3 author
50
51
    $c->author;
52
53
Return the author of the content
54
55
=cut
56
57
sub author {
58
    my ( $self, @params ) = @_;
59
    return $self->additional_content->author(@params);
60
}
61
62
=head3 is_expired
63
64
    $c->is_expired;
65
66
Return $content->is_expired
67
68
=cut
69
70
sub is_expired {
71
    my ( $self, @params ) = @_;
72
    return $self->additional_content->is_expired(@params);
73
}
74
75
=head3 library
76
77
    $c->library;
78
79
Return the library of the content
80
81
=cut
82
83
sub library {
84
    my ( $self, @params ) = @_;
85
    return $self->additional_content->library(@params);
86
}
87
88
=head3 category
89
90
    $c->category;
91
92
Return the category of the content
93
94
=cut
95
96
sub category {
97
    my ( $self, @params ) = @_;
98
    return $self->additional_content->category;
99
}
100
101
=head3 code
102
103
    $c->code;
104
105
Return the code of the content
106
107
=cut
108
109
sub code {
110
    my ( $self, @params ) = @_;
111
    return $self->additional_content->code(@params);
112
}
113
114
=head3 location
115
116
    $c->location;
117
118
Return the location of the content
119
120
=cut
121
122
sub location {
123
    my ( $self, @params ) = @_;
124
    return $self->additional_content->location(@params);
125
}
126
127
=head3 branchcode
128
129
    $c->branchcode;
130
131
Return the branchcode of the content
132
133
=cut
134
135
sub branchcode {
136
    my ( $self, @params ) = @_;
137
    return $self->additional_content->branchcode(@params);
138
}
139
140
=head3 published_on
141
142
    $c->published_on;
143
144
Return the publication date of the content
145
146
=cut
147
148
sub published_on {
149
    my ( $self, @params ) = @_;
150
    return $self->additional_content->published_on(@params);
151
}
152
153
=head3 updated_on
154
155
    $c->updated_on;
156
157
Return the date of the last update of the content
158
159
=cut
160
161
sub updated_on {
162
    my ( $self, @params ) = @_;
163
    return $self->additional_content->updated_on(@params);
164
}
165
166
=head3 expirationdate
167
168
    $c->expirationdate;
169
170
Return the expiration date of the content
171
172
=cut
173
174
sub expirationdate {
175
    my ( $self, @params ) = @_;
176
    return $self->additional_content->expirationdate(@params);
177
}
178
179
=head3 number
180
181
    $c->number;
182
183
Return the number (order of display) of the content
184
185
=cut
186
187
sub number {
188
    my ( $self, @params ) = @_;
189
    return $self->additional_content->number(@params);
190
}
191
192
=head3 borrowernumber
193
194
    $c->borrowernumber;
195
196
Return the borrowernumber of the content
197
198
=cut
199
200
sub borrowernumber {
201
    my ( $self, @params ) = @_;
202
    return $self->additional_content->borrowernumber(@params);
203
}
204
205
=head2 Class Methods
206
207
=cut
208
209
=head3 _type
210
211
=cut
212
213
sub _type {
214
    return 'AdditionalContentsLocalization';
215
}
216
217
1;
(-)a/Koha/AdditionalContentsLocalizations.pm (+52 lines)
Line 0 Link Here
1
package Koha::AdditionalContentsLocalizations;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
use Koha::Exceptions;
22
use Koha::AdditionalContentsLocalization;
23
24
use base qw(Koha::Objects);
25
26
=head1 NAME
27
28
Koha::AdditionalContentLocalizations - Koha Additional content localization object set class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 _type
37
38
=cut
39
40
sub _type {
41
    return 'AdditionalContentsLocalization';
42
}
43
44
=head3 object_class
45
46
=cut
47
48
sub object_class {
49
    return 'Koha::AdditionalContentsLocalization';
50
}
51
52
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt (-3 / +3 lines)
Lines 29-40 Link Here
29
                        <h3><span class="news_title">News</span></h3>
29
                        <h3><span class="news_title">News</span></h3>
30
                        [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'staff' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
30
                        [% SET show_author = Koha.Preference('NewsAuthorDisplay') == 'staff' || Koha.Preference('NewsAuthorDisplay') == 'both' %]
31
                        [% FOREACH koha_new IN koha_news %]
31
                        [% FOREACH koha_new IN koha_news %]
32
                            <div class="newsitem" id="news[% koha_new.idnew | html %]"><h4>[% koha_new.title | html %]</h4>
32
                            <div class="newsitem" id="news[% koha_new.additional_content_id | html %]"><h4>[% koha_new.title | html %]</h4>
33
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
33
                                <div class="newsbody">[% koha_new.content | $raw %]</div>
34
                                <p class="newsfooter"> Posted on [% koha_new.published_on | $KohaDates %][% IF( show_author && koha_new.author ) %] by <span class="newsauthor">[% INCLUDE 'patron-title.inc' patron=koha_new.author %]<br />[% END %]
34
                                <p class="newsfooter"> Posted on [% koha_new.published_on | $KohaDates %][% IF( show_author && koha_new.author ) %] by <span class="newsauthor">[% INCLUDE 'patron-title.inc' patron=koha_new.author %]<br />[% END %]
35
                                    [% IF ( CAN_user_tools_edit_additional_contents ) %]
35
                                    [% IF ( CAN_user_tools_edit_additional_contents ) %]
36
                                        <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% koha_new.idnew | uri %]">Edit</a>
36
                                        <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% koha_new.additional_content_id | uri %]">Edit</a>
37
                                         | <a class="news_delete" href="/cgi-bin/koha/tools/additional-contents.pl?op=delete_confirmed&amp;ids=[% koha_new.idnew | html %]">Delete</a>
37
                                         | <a class="news_delete" href="/cgi-bin/koha/tools/additional-contents.pl?op=delete_confirmed&amp;ids=[% koha_new.additional_content_id | html %]">Delete</a>
38
                                         | <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form">New</a>
38
                                         | <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form">New</a>
39
                                    [% END %]
39
                                    [% END %]
40
                                </p>
40
                                </p>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/additional-contents.tt (-17 / +20 lines)
Lines 59-65 Link Here
59
                [% END %]
59
                [% END %]
60
            [% END %]
60
            [% END %]
61
                [% WRAPPER breadcrumb_item bc_active= 1 %]
61
                [% WRAPPER breadcrumb_item bc_active= 1 %]
62
                    [% IF additional_content.idnew %]
62
                    [% IF additional_content.id %]
63
                        <span>Modify additional content</span>
63
                        <span>Modify additional content</span>
64
                    [% ELSE %]
64
                    [% ELSE %]
65
                        <span>Add additional content</span>
65
                        <span>Add additional content</span>
Lines 205-211 Link Here
205
        <input type="hidden" name="op" value="add_validate" />
205
        <input type="hidden" name="op" value="add_validate" />
206
        <input type="hidden" name="category" value="[% category | html %]" />
206
        <input type="hidden" name="category" value="[% category | html %]" />
207
        <input type="hidden" name="code" value="[% additional_content.code | html %]" />
207
        <input type="hidden" name="code" value="[% additional_content.code | html %]" />
208
        <input type="hidden" name="idnew" value="[% additional_content.idnew | html %]" />
208
        <input type="hidden" name="id" value="[% additional_content.id | html %]" />
209
        <input type="hidden" id="redirect" name="redirect" value="" />
209
        <input type="hidden" id="redirect" name="redirect" value="" />
210
        <input type="hidden" id="editmode" name="editmode" value="[% editmode | html %]" />
210
        <input type="hidden" id="editmode" name="editmode" value="[% editmode | html %]" />
211
        <fieldset class="rows">
211
        <fieldset class="rows">
Lines 280-295 Link Here
280
280
281
                [% WRAPPER tab_panels %]
281
                [% WRAPPER tab_panels %]
282
                    [% FOR language IN languages %]
282
                    [% FOR language IN languages %]
283
                        [% SET translated_content = translated_contents.item(language.lang) %]
283
                        [% WRAPPER tab_panel tabname="lang_${language.lang}" %]
284
                        [% WRAPPER tab_panel tabname="lang_${language.lang}" %]
284
                            <fieldset>
285
                            <fieldset>
285
                                <ol>
286
                                <ol>
286
                                    <li>
287
                                    <li>
287
                                        <label for="title_[% language.lang | html %]">Title: </label>
288
                                        <label for="title_[% language.lang | html %]">Title: </label>
288
                                        <input id="title_[% language.lang| html %]" size="100" maxlength="250" type="text" name="title_[% language.lang | html %]" value="[% translated_contents.item(language.lang).title | html %]">
289
                                        <input id="title_[% language.lang| html %]" size="100" maxlength="250" type="text" name="title_[% language.lang | html %]" value="[% translated_content.title | html %]">
289
                                    </li>
290
                                    </li>
290
                                    <li>
291
                                    <li>
291
                                        <label for="content_[% language.lang | html %]">Content: </label>
292
                                        <label for="content_[% language.lang | html %]">Content: </label>
292
                                        <textarea name="content_[% language.lang | html %]" id="content_[% language.lang | html %]" data-lang="[% language.lang | html%]" cols="75" rows="10">[% translated_contents.item(language.lang).content | html %]</textarea>
293
                                        <textarea name="content_[% language.lang | html %]" id="content_[% language.lang | html %]" data-lang="[% language.lang | html%]" cols="75" rows="10">[% translated_content.content | html %]</textarea>
294
                                        <input type="hidden" name="id_[% language.lang | html %]" value="[% translated_content.id | html %]" />
293
                                        <input type="hidden" name="lang" value="[% language.lang | html %]" />
295
                                        <input type="hidden" name="lang" value="[% language.lang | html %]" />
294
                                    </li>
296
                                    </li>
295
                                </ol>
297
                                </ol>
Lines 364-372 Link Here
364
                    </thead>
366
                    </thead>
365
                    <tbody>
367
                    <tbody>
366
                        [% FOREACH c IN additional_contents%]
368
                        [% FOREACH c IN additional_contents%]
369
                            [% SET default_localization = c.default_localization %]
367
                            [% IF ( c.is_expired ) %]<tr class="expired">[% ELSE %]<tr>[% END %]
370
                            [% IF ( c.is_expired ) %]<tr class="expired">[% ELSE %]<tr>[% END %]
368
                            <td>
371
                            <td>
369
                                <input type="checkbox" name="ids" value="[% c.idnew | html %]" />
372
                                <input type="checkbox" name="ids" value="[% c.id | html %]" />
370
                            </td>
373
                            </td>
371
                            <td>
374
                            <td>
372
                                [% IF c.category == 'news' || c.category == 'pages' %]
375
                                [% IF c.category == 'news' || c.category == 'pages' %]
Lines 389-410 Link Here
389
                            <td>[% c.number | html %]</td>
392
                            <td>[% c.number | html %]</td>
390
                            <td data-order="[% c.published_on | html %]">[% c.published_on | $KohaDates %]</td>
393
                            <td data-order="[% c.published_on | html %]">[% c.published_on | $KohaDates %]</td>
391
                            <td data-order="[% c.expirationdate | html %]">[% c.expirationdate | $KohaDates %] [% IF ( c.is_expired ) %](<span class="expired">expired</span>)[% END %]</td>
394
                            <td data-order="[% c.expirationdate | html %]">[% c.expirationdate | $KohaDates %] [% IF ( c.is_expired ) %](<span class="expired">expired</span>)[% END %]</td>
392
                            <td>[% c.title | html %]</td>
395
                            <td>[% default_localization.title | html %]</td>
393
                            <td>[% IF ( c.author) %][% INCLUDE 'patron-title.inc' patron=c.author %][% END %]</td>
396
                            <td>[% IF ( c.author) %][% INCLUDE 'patron-title.inc' patron=c.author %][% END %]</td>
394
                            [% IF category == 'pages' %]
397
                            [% IF category == 'pages' %]
395
                                <td class="actions">
398
                                <td class="actions">
396
                                    [% IF c.location == 'opac_only' OR c.location == 'staff_and_opac' %]
399
                                    [% IF c.location == 'opac_only' OR c.location == 'staff_and_opac' %]
397
                                        <strong>OPAC</strong>:
400
                                        <strong>OPAC</strong>:
398
                                        <a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.idnew | url %]" title="View on OPAC">Default</a>
401
                                        <a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.id | uri %]&lang=default" title="View on OPAC">Default</a>
399
                                        OR
402
                                        OR
400
                                        <a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?code=[% c.code | url %]" title="View on OPAC">Current language</a>
403
                                        <a target="_blank" href="[% Koha.Preference('OPACBaseURL') | url %]/cgi-bin/koha/opac-page.pl?page_id=[% c.id | uri %]&lang=[% lang | uri %]" title="View on OPAC">Current language</a>
401
                                    [% END %]
404
                                    [% END %]
402
                                    [% IF c.location == 'staff_only' OR c.location == 'staff_and_opac' %]
405
                                    [% IF c.location == 'staff_only' OR c.location == 'staff_and_opac' %]
403
                                        [% IF c.location == 'staff_and_opac' %]<br/>[% END %]
406
                                        [% IF c.location == 'staff_and_opac' %]<br/>[% END %]
404
                                        <strong>Staff interface</strong>:
407
                                        <strong>Staff interface</strong>:
405
                                        <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.idnew | url %]" title="View on staff interface">Default</a>
408
                                        <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.id | uri %]&lang=default" title="View on staff interface">Default</a>
406
                                        OR
409
                                        OR
407
                                        <a href="/cgi-bin/koha/tools/page.pl?code=[% c.code | url %]" title="View on staff interface">Current language</a>
410
                                        <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.id | uri %]&lang=[% lang | uri %]" title="View on staff interface">Current language</a>
408
                                    [% END %]
411
                                    [% END %]
409
                                </td>
412
                                </td>
410
                            [% END %]
413
                            [% END %]
Lines 416-425 Link Here
416
                                    <div class="modal-dialog" role="document">
419
                                    <div class="modal-dialog" role="document">
417
                                        <div class="modal-content modal-lg">
420
                                        <div class="modal-content modal-lg">
418
                                            <div class="modal-header">
421
                                            <div class="modal-header">
419
                                                <h5 class="modal-title">Preview of: "[% c.title | html %]"</h5>
422
                                                <h5 class="modal-title">Preview of: "[% default_localization.title | html %]"</h5>
420
                                            </div>
423
                                            </div>
421
                                        <div class="modal-body">
424
                                        <div class="modal-body">
422
                                            [% c.content | $raw %]
425
                                            [% default_localization.content | $raw %]
423
                                        </div>
426
                                        </div>
424
                                        <div class="modal-footer">
427
                                        <div class="modal-footer">
425
                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
428
                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
Lines 429-449 Link Here
429
                            </td>
432
                            </td>
430
                            <td class="actions">
433
                            <td class="actions">
431
                                <div class="btn-group dropup">
434
                                <div class="btn-group dropup">
432
                                    <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.idnew | uri %]&editmode=[% editmode | uri %]" class="btn btn-default btn-xs"> <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a><button class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
435
                                    <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=[% editmode | uri %]" class="btn btn-default btn-xs"> <i class="fa-solid fa-pencil"></i> Edit</a><button class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
433
                                        <span class="caret"></span>
436
                                        <span class="caret"></span>
434
                                    </button>
437
                                    </button>
435
                                    <ul class="dropdown-menu pull-right">
438
                                    <ul class="dropdown-menu pull-right">
436
                                        <li>
439
                                        <li>
437
                                            [% IF ( wysiwyg ) %]
440
                                            [% IF ( wysiwyg ) %]
438
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.idnew | uri %]&editmode=text"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit with text editor</a>
441
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=text"><i class="fa-solid fa-pencil"></i> Edit with text editor</a>
439
                                            [% ELSE %]
442
                                            [% ELSE %]
440
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.idnew | uri %]&editmode=wysiwyg"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit with WYSIWYG editor</a>
443
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=wysiwyg"><i class="fa-solid fa-pencil"></i> Edit with WYSIWYG editor</a>
441
                                            [% END %]
444
                                            [% END %]
442
                                        </li>
445
                                        </li>
443
                                    </ul>
446
                                    </ul>
444
                                </div>
447
                                </div>
445
                                <div class="btn-group">
448
                                <div class="btn-group">
446
                                    <a href="#" class="delete_news btn btn-default btn-xs" data-idnew="[% c.idnew | html %]"><i class="fa fa-trash-can"></i> Delete</a>
449
                                    <a href="#" class="delete_news btn btn-default btn-xs" data-idnew="[% c.id | html %]"><i class="fa fa-trash-can"></i> Delete</a>
447
                                </div>
450
                                </div>
448
                            </td>
451
                            </td>
449
                        </tr>
452
                        </tr>
Lines 580-586 Link Here
580
                $("#del_form").on("click", ".delete_news", function(e){
583
                $("#del_form").on("click", ".delete_news", function(e){
581
                    e.preventDefault();
584
                    e.preventDefault();
582
                    if( confirmDelete( _("Are you sure you want to delete this content? This cannot be undone.") ) ){
585
                    if( confirmDelete( _("Are you sure you want to delete this content? This cannot be undone.") ) ){
583
                        $("#del_ids").val( $(this).data("idnew") );
586
                        $("#del_ids").val( $(this).data("id") );
584
                        $("#delete_single").submit();
587
                        $("#delete_single").submit();
585
                    }
588
                    }
586
                });
589
                });
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/page.tt (-1 / +1 lines)
Lines 6-12 Link Here
6
[% INCLUDE 'doc-head-close.inc' %]
6
[% INCLUDE 'doc-head-close.inc' %]
7
</head>
7
</head>
8
8
9
<body id="tools_page_[% page.idnew | html %]" class="tools">
9
<body id="tools_page_[% page.additional_content_id | html %]" class="tools">
10
[% WRAPPER 'header.inc' %]
10
[% WRAPPER 'header.inc' %]
11
    [% INCLUDE 'cat-search.inc' %]
11
    [% INCLUDE 'cat-search.inc' %]
12
[% END %]
12
[% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt (-1 / +1 lines)
Lines 102-108 Link Here
102
                            [% IF ( news_item ) %]
102
                            [% IF ( news_item ) %]
103
                                [% koha_new.title | html %]
103
                                [% koha_new.title | html %]
104
                            [% ELSE %]
104
                            [% ELSE %]
105
                                <a name="newsitem[% koha_new.idnew | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.idnew | uri %]">[% koha_new.title | html %]</a>
105
                                <a name="newsitem[% koha_new.id | html %]" href="/cgi-bin/koha/opac-main.pl?news_id=[% koha_new.id | uri %]">[% koha_new.title | html %]</a>
106
                            [% END %]
106
                            [% END %]
107
                        </h4>
107
                        </h4>
108
                        <div class="newsbody">[% koha_new.content | $raw %]</div>
108
                        <div class="newsbody">[% koha_new.content | $raw %]</div>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-news-rss.tt (-1 / +1 lines)
Lines 10-16 Link Here
10
      <item>
10
      <item>
11
        <title>[% newsitem.title | html %]</title>
11
        <title>[% newsitem.title | html %]</title>
12
        <description>[% newsitem.content | $raw %]</description>
12
        <description>[% newsitem.content | $raw %]</description>
13
        <guid>[% OPACBaseURL | html %]/cgi-bin/koha/opac-main.pl#newsitem[% newsitem.idnew | html %]</guid>
13
        <guid>[% OPACBaseURL | html %]/cgi-bin/koha/opac-main.pl#newsitem[% newsitem.additional_content_id | html %]</guid>
14
      </item>
14
      </item>
15
      [% END %]
15
      [% END %]
16
   </channel>
16
   </channel>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-page.tt (-2 / +2 lines)
Lines 9-15 Link Here
9
[% INCLUDE 'doc-head-close.inc' %]
9
[% INCLUDE 'doc-head-close.inc' %]
10
[% BLOCK cssinclude %][% END %]
10
[% BLOCK cssinclude %][% END %]
11
</head>
11
</head>
12
[% INCLUDE 'bodytag.inc' bodyid='opac-page-' _ page.idnew %]
12
[% INCLUDE 'bodytag.inc' bodyid='opac-page-' _ page.additional_content_id %]
13
[% INCLUDE 'masthead.inc' %]
13
[% INCLUDE 'masthead.inc' %]
14
14
15
<div class="main">
15
<div class="main">
Lines 44-50 Link Here
44
            [% END %]
44
            [% END %]
45
45
46
            [% IF page %]
46
            [% IF page %]
47
                <div class="maincontent">
47
                <div id="page_[% page.additional_content_id | html %]" class="maincontent">
48
                    <h1>[% page.title | html %]</h1>
48
                    <h1>[% page.title | html %]</h1>
49
49
50
                        <div class="page_content">
50
                        <div class="page_content">
(-)a/opac/opac-main.pl (-1 lines)
Lines 27-33 use C4::Members; Link Here
27
use C4::Overdues qw( checkoverdues );
27
use C4::Overdues qw( checkoverdues );
28
use Koha::Checkouts;
28
use Koha::Checkouts;
29
use Koha::Holds;
29
use Koha::Holds;
30
use Koha::AdditionalContents;
31
use Koha::Patron::Messages;
30
use Koha::Patron::Messages;
32
31
33
my $input = CGI->new;
32
my $input = CGI->new;
(-)a/opac/opac-page.pl (-9 / +11 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use C4::Auth qw( get_template_and_user );
21
use C4::Auth qw( get_template_and_user );
22
use C4::Output qw( output_html_with_http_headers );
22
use C4::Output qw( output_html_with_http_headers );
23
use C4::Languages qw( getlanguage );
23
use Koha::AdditionalContents;
24
use Koha::AdditionalContents;
24
25
25
my $query = CGI->new();
26
my $query = CGI->new();
Lines 34-54 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
34
);
35
);
35
36
36
my $page_id = $query->param('page_id');
37
my $page_id = $query->param('page_id');
37
my $code = $query->param('code');
38
my $lang = $query->param('language');
38
my $page;
39
39
40
my $homebranch = $ENV{OPAC_BRANCH_DEFAULT};
40
my $homebranch = $ENV{OPAC_BRANCH_DEFAULT};
41
if (C4::Context->userenv) {
41
if (C4::Context->userenv) {
42
    $homebranch = C4::Context->userenv->{'branch'};
42
    $homebranch = C4::Context->userenv->{'branch'};
43
}
43
}
44
44
45
if( $page_id ) {
45
my $page = Koha::AdditionalContents->find($page_id);
46
    $page = Koha::AdditionalContents->search({ idnew => $page_id, location => ['opac_only', 'staff_and_opac'], branchcode => [ $homebranch, undef ] });
46
47
} elsif( $code ) {
47
if ( !$page || $page->category ne 'pages' || $page->branchcode && $page->branchcode != $homebranch || $page->location ne 'opac_only' && $page->location ne 'staff_and_opac' ) {
48
    my $lang = $query->param('language') || $query->cookie('KohaOpacLanguage') || $template->lang;
48
    print $query->redirect('/cgi-bin/koha/errors/404.pl');
49
    # In the next query we make sure that the 'default' records come after the regular languages
49
    exit;
50
    $page = Koha::AdditionalContents->search({ code => $code, lang => ['default', $lang], location => ['opac_only', 'staff_and_opac'], branchcode => [ $homebranch, undef ] }, { order_by => { -desc => \[ 'CASE WHEN lang="default" THEN "" ELSE lang END' ]}} );
51
}
50
}
52
$template->param( $page && $page->count ? ( page => $page->next ) : ( page_error => 1 ) );
51
52
my $content = $page->translated_content( $lang || C4::Languages::getlanguage($query) );
53
54
$template->param( page => $content );
53
55
54
output_html_with_http_headers $query, $cookie, $template->output;
56
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/tools/additional-contents.pl (-111 / +94 lines)
Lines 24-29 Link Here
24
24
25
use Modern::Perl;
25
use Modern::Perl;
26
use CGI qw ( -utf8 );
26
use CGI qw ( -utf8 );
27
use Try::Tiny;
28
use Array::Utils qw( array_minus );
27
use C4::Auth qw(get_template_and_user);
29
use C4::Auth qw(get_template_and_user);
28
use C4::Koha;
30
use C4::Koha;
29
use C4::Context;
31
use C4::Context;
Lines 65-82 if ( $op eq 'add_form' ) { Link Here
65
67
66
    my $additional_content = Koha::AdditionalContents->find($id);
68
    my $additional_content = Koha::AdditionalContents->find($id);
67
    my $translated_contents;
69
    my $translated_contents;
68
    if ( $additional_content ) {
70
    if ($additional_content) {
69
        $translated_contents = {
71
        $translated_contents = { map { $_->lang => $_ } $additional_content->translated_contents->as_list };
70
            map { $_->lang => $_ } Koha::AdditionalContents->search(
72
        $category            = $additional_content->category;
71
                {
72
                    category   => $additional_content->category,
73
                    code       => $additional_content->code,
74
                    location   => $additional_content->location,
75
                    branchcode => $additional_content->branchcode,
76
                }
77
            )->as_list
78
        };
79
        $category = $additional_content->category;
80
    }
73
    }
81
    $template->param(
74
    $template->param(
82
        additional_content => $additional_content,
75
        additional_content => $additional_content,
Lines 88-94 elsif ( $op eq 'add_validate' ) { Link Here
88
    my $location   = $cgi->param('location');
81
    my $location   = $cgi->param('location');
89
    my $code       = $cgi->param('code');
82
    my $code       = $cgi->param('code');
90
    my $branchcode = $cgi->param('branchcode') || undef;
83
    my $branchcode = $cgi->param('branchcode') || undef;
91
    my $idnew      = $cgi->param('idnew');
92
84
93
    my @lang       = $cgi->multi_param('lang');
85
    my @lang       = $cgi->multi_param('lang');
94
86
Lines 96-196 elsif ( $op eq 'add_validate' ) { Link Here
96
    my $published_on = $cgi->param('published_on');
88
    my $published_on = $cgi->param('published_on');
97
    my $number = $cgi->param('number');
89
    my $number = $cgi->param('number');
98
90
99
    my $original_default = $idnew ? Koha::AdditionalContents->find($idnew) : undef;
91
    try {
100
92
        Koha::Database->new->schema->txn_do(
101
    my $success = 1;
93
            sub {
102
    for my $lang ( sort {$a ne 'default'} @lang ) { # Process 'default' first
94
                my $additional_content;
103
        my $title   = $cgi->param( 'title_' . $lang );
95
                my $params = {
104
        my $content = $cgi->param( 'content_' . $lang );
105
        # Force a default record
106
        $content ||= '<!-- no_content -->' if $lang eq 'default';
107
108
        my $additional_content = Koha::AdditionalContents->find(
109
            {
110
                category   => $category,
111
                code       => $code,
112
                branchcode => $original_default ? $original_default->branchcode : $branchcode,
113
                lang       => $lang,
114
            }
115
        );
116
        # Delete if title or content is empty
117
        if( $lang ne 'default' && !$title && !$content ) {
118
            if ( $additional_content ) {
119
                eval { $additional_content->delete };
120
                unless ($@) {
121
                    logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $additional_content->code, $additional_content->title, $additional_content->lang, $additional_content->content));
122
                }
123
            }
124
            next;
125
        } elsif ( $additional_content ) {
126
            my $updated;
127
            eval {
128
                $additional_content->set(
129
                    {
130
                        category       => $category,
131
                        code           => $code,
132
                        location       => $location,
96
                        location       => $location,
133
                        branchcode     => $branchcode,
97
                        branchcode     => $branchcode,
134
                        title          => $title,
135
                        content        => $content,
136
                        lang           => $lang,
137
                        expirationdate => $expirationdate,
98
                        expirationdate => $expirationdate,
138
                        published_on   => $published_on,
99
                        published_on   => $published_on,
139
                        number         => $number,
100
                        number         => $number,
140
                        borrowernumber => $borrowernumber,
101
                        borrowernumber => $borrowernumber,
141
                    }
102
                    };
142
                );
143
                $updated = $additional_content->_result->get_dirty_columns;
144
                $additional_content->store;
145
                $id = $additional_content->idnew;
146
            };
147
            if ($@) {
148
                $success = 0;
149
                push @messages, { type => 'error', code => 'error_on_update' };
150
                last;
151
            }
152
103
153
            logaction('NEWS', 'MODIFY' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content))
104
                if ( $id ) {
154
                if C4::Context->preference("NewsLog") && $updated;
105
                    $additional_content = Koha::AdditionalContents->find($id);
155
        }
106
                    $additional_content->set($params)->store;
156
        else {
107
                } else {
157
            my $additional_content = Koha::AdditionalContent->new(
108
                    $additional_content = Koha::AdditionalContent->new(
158
                {
109
                        {
159
                    category       => $category,
110
                            category   => $category,
160
                    code           => $code || 'tmp_code',
111
                            code       => $code,
161
                    location       => $location,
112
                            branchcode => $branchcode,
162
                    branchcode     => $branchcode,
113
                            %$params,
163
                    title          => $title,
114
                        }
164
                    content        => $content,
115
                    )->store;
165
                    lang           => $lang,
166
                    expirationdate => $expirationdate,
167
                    published_on   => $published_on,
168
                    number         => $number,
169
                    borrowernumber => $borrowernumber,
170
                }
116
                }
171
            )->store;
172
            eval {
173
                $additional_content->store;
174
                unless ($code) {
117
                unless ($code) {
175
                    $additional_content->discard_changes;
118
                    $additional_content->discard_changes;
176
                    $code = $category eq 'news'
119
                    $code =
177
                      ? 'News_' . $additional_content->idnew
120
                      $category eq 'news'
178
                      : $location . '_' . $additional_content->idnew;
121
                      ? 'News_' . $additional_content->id
122
                      : $location . '_' . $additional_content->id;
179
                    $additional_content->code($code)->store;
123
                    $additional_content->code($code)->store;
180
                    $id = $additional_content->idnew;
124
                    $id = $additional_content->id;
181
                }
125
                }
182
            };
126
                my @translated_contents;
183
            if ($@) {
127
                my $existing_contents = $additional_content->translated_contents;
184
                $success = 0;
128
                my @seen_ids;
185
                push @messages, { type => 'error', code => 'error_on_insert' };
129
                for my $lang (@lang) {
186
                last;
130
                    my $id      = $cgi->param( 'id_' . $lang );
187
            }
131
                    my $title   = $cgi->param( 'title_' . $lang );
132
                    my $content = $cgi->param( 'content_' . $lang );
133
                    $content ||= '<!-- no_content -->' if $lang eq 'default';
188
134
189
            logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content))
135
                    next unless $title || $content;
190
                if C4::Context->preference("NewsLog");
191
        }
192
136
193
    }
137
                    push @seen_ids, $id;
138
                    push @translated_contents,
139
                      {
140
                        title   => $title,
141
                        content => $content,
142
                        lang    => $lang,
143
                      };
144
145
                    if ( C4::Context->preference("NewsLog") ) {
146
                        my $existing_content = $existing_contents->find($id);
147
                        if ( $existing_content ) {
148
                            if ( $existing_content->title ne $title || $existing_content->content ne $content ) {
149
                                logaction('NEWS', 'MODIFY' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content));
150
                            }
151
                        } else {
152
                            logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content))
153
                        }
154
                    }
155
                }
156
157
                if ( C4::Context->preference("NewsLog") ) {
158
                    my @existing_ids = $existing_contents->get_column('id');
159
                    my @deleted_ids = array_minus( @existing_ids, @seen_ids );
160
                    for my $id ( @deleted_ids ) {
161
                        my $c = $existing_contents->find($id);
162
                        logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s", $code, $c->lang, $c->content));
163
                    }
164
                }
165
166
                $additional_content->translated_contents( \@translated_contents );
167
            }
168
        );
169
    } catch {
170
        warn $_;
171
        if ( $id ) {
172
            push @messages, { type => 'error', code => 'error_on_update' };
173
        } else {
174
            push @messages, { type => 'error', code => 'error_on_insert' };
175
        }
176
    };
194
177
195
    if( $redirect eq "just_save" ){
178
    if( $redirect eq "just_save" ){
196
        print $cgi->redirect("/cgi-bin/koha/tools/additional-contents.pl?op=add_form&id=$id&category=$category&editmode=$editmode&redirect=done");
179
        print $cgi->redirect("/cgi-bin/koha/tools/additional-contents.pl?op=add_form&id=$id&category=$category&editmode=$editmode&redirect=done");
Lines 202-239 elsif ( $op eq 'add_validate' ) { Link Here
202
elsif ( $op eq 'delete_confirmed' ) {
185
elsif ( $op eq 'delete_confirmed' ) {
203
    output_and_exit_if_error($cgi, $cookie, $template, { check => 'csrf_token' });
186
    output_and_exit_if_error($cgi, $cookie, $template, { check => 'csrf_token' });
204
    my @ids = $cgi->multi_param('ids');
187
    my @ids = $cgi->multi_param('ids');
205
    my $deleted = eval {
206
188
207
        my $schema = Koha::Database->new->schema;
189
    try {
208
        $schema->txn_do(
190
        Koha::Database->new->schema->txn_do(
209
            sub {
191
            sub {
210
                my $contents =
192
                my $contents =
211
                  Koha::AdditionalContents->search( { idnew => \@ids } );
193
                  Koha::AdditionalContents->search( { id => \@ids } );
212
194
213
                while ( my $c = $contents->next ) {
195
                if ( C4::Context->preference("NewsLog") ) {
214
                    Koha::AdditionalContents->search( { code => $c->code } )->delete;
196
                    while ( my $c = $contents->next ) {
215
                    if ( C4::Context->preference("NewsLog") ) {
197
                        my $translated_contents = $c->translated_contents;
216
                        logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $c->title, $c->lang, $c->content));
198
                        while ( my $translated_content = $translated_contents->next ) {
199
                            logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $translated_content->lang, $translated_content->content));
200
                        }
217
                    }
201
                    }
218
                }
202
                }
203
                $contents->delete;
219
            }
204
            }
220
        );
205
        );
221
    };
222
223
    if ( $@ or not $deleted ) {
224
        push @messages, { type => 'error', code => 'error_on_delete' };
225
    }
226
    else {
227
        push @messages, { type => 'message', code => 'success_on_delete' };
206
        push @messages, { type => 'message', code => 'success_on_delete' };
228
    }
207
    } catch {
208
        warn $_;
209
        push @messages, { type => 'error', code => 'error_on_delete' };
210
    };
229
211
230
    $op = 'list';
212
    $op = 'list';
231
}
213
}
232
214
233
if ( $op eq 'list' ) {
215
if ( $op eq 'list' ) {
234
    my $additional_contents = Koha::AdditionalContents->search(
216
    my $additional_contents = Koha::AdditionalContents->search(
235
        { category => $category, lang => 'default' },
217
        { category => $category, 'additional_contents_localizations.lang' => 'default' },
236
        { order_by => { -desc => 'published_on' } }
218
        { order_by => { -desc => 'published_on' }, join => 'additional_contents_localizations' }
237
    );
219
    );
238
    $template->param( additional_contents => $additional_contents );
220
    $template->param( additional_contents => $additional_contents );
239
}
221
}
Lines 269-274 $template->param( Link Here
269
    wysiwyg   => $wysiwyg,
251
    wysiwyg   => $wysiwyg,
270
    editmode  => $editmode,
252
    editmode  => $editmode,
271
    languages => \@languages,
253
    languages => \@languages,
254
    messages  => \@messages,
272
);
255
);
273
256
274
output_html_with_http_headers $cgi, $cookie, $template->output;
257
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/tools/page.pl (-12 / +13 lines)
Lines 32-49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
32
    }
32
    }
33
);
33
);
34
34
35
my $branch = C4::Context->userenv->{'branch'};
36
my $page_id = $query->param('page_id');
35
my $page_id = $query->param('page_id');
37
my $code = $query->param('code');
36
my $lang = $query->param('language');
38
my $page;
37
39
38
my $branch = C4::Context->userenv->{'branch'};
40
if( $page_id ) {
39
41
    $page = Koha::AdditionalContents->search({ idnew => $page_id, location => ['staff_only', 'staff_and_opac'], branchcode => [ $branch, undef ] });
40
my $page = Koha::AdditionalContents->find($page_id);
42
} elsif( $code ) {
41
43
    my $lang = $query->param('language') || $query->cookie('KohaOpacLanguage');
42
if ( !$page || $page->category ne 'pages' || $page->branchcode && $page->branchcode != $branch || $page->location ne 'staff_only' && $page->location ne 'staff_and_opac' ) {
44
    # In the next query we make sure that the 'default' records come after the regular languages
43
    print $query->redirect('/cgi-bin/koha/errors/404.pl');
45
    $page = Koha::AdditionalContents->search({ code => $code, lang => ['default', $lang], location => ['staff_only', 'staff_and_opac'], branchcode => [ $branch, undef ] }, { order_by => { -desc => \[ 'CASE WHEN lang="default" THEN "" ELSE lang END' ]}} );
44
    exit;
46
}
45
}
47
$template->param( $page && $page->count ? ( page => $page->next ) : ( page_error => 1 ) );
46
47
my $content = $page->translated_content( $lang || C4::Languages::getlanguage($query) );
48
49
$template->param( page => $content );
48
50
49
output_html_with_http_headers $query, $cookie, $template->output;
51
output_html_with_http_headers $query, $cookie, $template->output;
50
- 

Return to bug 31383