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 1730-1745 sub _get_tt_params { Link Here
1730
            pk       => 'itemnumber',
1730
            pk       => 'itemnumber',
1731
        },
1731
        },
1732
        additional_contents => {
1732
        additional_contents => {
1733
            module   => 'Koha::AdditionalContents',
1733
            module   => 'Koha::AdditionalContentsLocalizations',
1734
            singular => 'additional_content',
1734
            singular => 'additional_content',
1735
            plural   => 'additional_contents',
1735
            plural   => 'additional_contents',
1736
            pk       => 'idnew',
1736
            pk       => 'id',
1737
        },
1737
        },
1738
        opac_news => {
1738
        opac_news => {
1739
            module   => 'Koha::AdditionalContents',
1739
            module   => 'Koha::AdditionalContentsLocalizations',
1740
            singular => 'news',
1740
            singular => 'news',
1741
            plural   => 'news',
1741
            plural   => 'news',
1742
            pk       => 'idnew',
1742
            pk       => 'id',
1743
        },
1743
        },
1744
        aqorders => {
1744
        aqorders => {
1745
            module   => 'Koha::Acquisition::Orders',
1745
            module   => 'Koha::Acquisition::Orders',
(-)a/C4/Members.pm (-20 / +4 lines)
Lines 578-617 sub IssueSlip { Link Here
578
                issues      => $all,
578
                issues      => $all,
579
            };
579
            };
580
        }
580
        }
581
        my $news = Koha::AdditionalContents->search_for_display(
581
        my @news_ids = Koha::AdditionalContents->search_for_display(
582
            {
582
            {
583
                category   => 'news',
583
                category   => 'news',
584
                location   => 'slip',
584
                location   => 'slip',
585
                lang       => $patron->lang,
585
                lang       => $patron->lang,
586
                library_id => $branch,
586
                library_id => $branch,
587
            }
587
            }
588
        );
588
        )->get_column('id');
589
        my @news;
590
        while ( my $n = $news->next ) {
591
            my $all = $n->unblessed_all_relateds;
592
593
            # FIXME We keep newdate and timestamp for backward compatibility (from GetNewsToDisplay)
594
            # But we should remove them and adjust the existing templates in a db rev
595
            # FIXME This must be formatted in the notice template
596
            my $published_on_dt = output_pref({ dt => dt_from_string( $all->{published_on} ), dateonly => 1 });
597
            $all->{newdate} = $published_on_dt;
598
            $all->{timestamp} = $published_on_dt;
599
600
            push @news, {
601
                additional_contents => $all,
602
            };
603
        }
604
        $letter_code = 'ISSUESLIP';
589
        $letter_code = 'ISSUESLIP';
605
        %repeat      = (
590
        %repeat      = (
606
            checkedout => \@checkouts,
591
            checkedout => \@checkouts,
607
            overdue    => \@overdues,
592
            overdue    => \@overdues,
608
            news       => \@news,
609
        );
593
        );
610
        %loops = (
594
        %loops = (
611
            issues => [ map { $_->{issues}{itemnumber} } @checkouts ],
595
            issues => [ map { $_->{issues}{itemnumber} } @checkouts ],
612
            overdues   => [ map { $_->{issues}{itemnumber} } @overdues ],
596
            overdues   => [ map { $_->{issues}{itemnumber} } @overdues ],
613
            opac_news => [ map { $_->{additional_contents}{idnew} } @news ],
597
            opac_news => \@news_ids,
614
            additional_contents => [ map { $_->{additional_contents}{idnew} } @news ],
598
            additional_contents => \@news_ids,
615
        );
599
        );
616
    }
600
    }
617
601
(-)a/Koha/AdditionalContent.pm (-1 / +61 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 84-89 sub library { Link Here
84
    return Koha::Library->_new_from_dbic( $library_rs );
84
    return Koha::Library->_new_from_dbic( $library_rs );
85
}
85
}
86
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);
111
}
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
        {
139
            lang => [ 'default', ( $lang ? $lang : () ) ]
140
        },
141
        {
142
            ( $lang ? ( order_by => \[ "field(lang, '" . $lang . "', 'default')" ] ) : () )
143
        }
144
    )->next;
145
    return $content;
146
}
87
147
88
=head3 _type
148
=head3 _type
89
149
(-)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 70-113 sub search_for_display { Link Here
70
    my ( $self, $params ) = @_;
73
    my ( $self, $params ) = @_;
71
74
72
    my $search_params;
75
    my $search_params;
73
    $search_params->{location} = $params->{location};
76
    $search_params->{location}     = $params->{location};
74
    $search_params->{branchcode} = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
77
    $search_params->{branchcode}   = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
75
    $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' };
78
    $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' };
76
    $search_params->{-or} = [ expirationdate => { '>=' => \'CAST(NOW() AS DATE)' },
79
    $search_params->{-or}          = [
77
                              expirationdate => undef ];
80
        expirationdate => { '>=' => \'CAST(NOW() AS DATE)' },
81
        expirationdate => undef
82
    ];
78
    $search_params->{category} = $params->{category} if $params->{category};
83
    $search_params->{category} = $params->{category} if $params->{category};
79
84
85
    my $contents = $self->SUPER::search( $search_params, { order_by => 'number' } );
86
80
    if ( $params->{lang} ) {
87
    if ( $params->{lang} ) {
81
        # FIXME I am failing to translate the following query
88
        my $translated_contents = Koha::AdditionalContentsLocalizations->search(
82
        # SELECT   a1.category,   a1.code,   COALESCE(a2.title, a1.title)
83
        # FROM additional_contents a1
84
        # LEFT JOIN additional_contents a2 on a1.code=a2.code AND a2.lang="es-ES"
85
        # WHERE a1.lang = 'default';
86
87
        # So we are retrieving the code with a translated content, then the other ones
88
        my $translated_contents =
89
          $self->SUPER::search( { %$search_params, lang => $params->{lang} } );
90
        my $default_contents = $self->SUPER::search(
91
            {
89
            {
92
                %$search_params,
90
                additional_content_id => [$contents->get_column('id')],
93
                lang => 'default',
91
                lang => $params->{lang},
94
                code =>
95
                  { '-not_in' => [ $translated_contents->get_column('code') ] }
96
            }
92
            }
97
        );
93
        );
98
94
        my @all_content_id = $contents->get_column('id');
99
        return $self->SUPER::search(
95
        my @translated_content_id = $translated_contents->get_column('additional_content_id');
96
        my $default_contents    = Koha::AdditionalContentsLocalizations->search(
97
            {
98
                additional_content_id => [array_minus(@all_content_id, @translated_content_id)],
99
                lang                  => 'default',
100
            }
101
        );
102
        return Koha::AdditionalContentsLocalizations->search(
100
            {
103
            {
101
                idnew => [
104
                id => [
102
                    $translated_contents->get_column('idnew'),
105
                    $translated_contents->get_column('id'),
103
                    $default_contents->get_column('idnew')
106
                    $default_contents->get_column('id'),
104
                ]
107
                ]
105
            },
108
            },
106
            { order_by => 'number' }
107
        );
109
        );
108
    }
110
    }
109
111
    return $contents->search( { lang => 'default' }, { order_by => 'number' } )->translated_contents;
110
    return $self->SUPER::search({%$search_params, lang => 'default'}, { order_by => 'number'});
111
}
112
}
112
113
113
=head3 find_best_match
114
=head3 find_best_match
Lines 127-139 sub find_best_match { Link Here
127
    my $library_id = $params->{library_id};
128
    my $library_id = $params->{library_id};
128
    my $lang = $params->{lang};
129
    my $lang = $params->{lang};
129
130
130
    my $rs = $self->SUPER::search({
131
    my $contents = $self->SUPER::search({
131
        category => $params->{category},
132
        category => $params->{category},
132
        location => $params->{location},
133
        location => $params->{location},
133
        lang => [ $lang, 'default' ],
134
        branchcode => [ $library_id, undef ],
134
        branchcode => [ $library_id, undef ],
135
    });
135
    });
136
136
137
    my $rs = Koha::AdditionalContentsLocalizations->search({
138
            additional_content_id => [ $contents->get_column('id') ],
139
            lang => [ $lang, 'default' ],
140
        });
141
137
    # Pick the best
142
    # Pick the best
138
    my ( $alt1, $alt2, $alt3 );
143
    my ( $alt1, $alt2, $alt3 );
139
    while( my $rec = $rs->next ) {
144
    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=del&amp;ids=[% koha_new.idnew | html %]">Delete</a>
37
                                         | <a class="news_delete" href="/cgi-bin/koha/tools/additional-contents.pl?op=del&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 204-210 Link Here
204
        <input type="hidden" name="op" value="add_validate" />
204
        <input type="hidden" name="op" value="add_validate" />
205
        <input type="hidden" name="category" value="[% category | html %]" />
205
        <input type="hidden" name="category" value="[% category | html %]" />
206
        <input type="hidden" name="code" value="[% additional_content.code | html %]" />
206
        <input type="hidden" name="code" value="[% additional_content.code | html %]" />
207
        <input type="hidden" name="idnew" value="[% additional_content.idnew | html %]" />
207
        <input type="hidden" name="id" value="[% additional_content.id | html %]" />
208
        <input type="hidden" id="redirect" name="redirect" value="" />
208
        <input type="hidden" id="redirect" name="redirect" value="" />
209
        <input type="hidden" id="editmode" name="editmode" value="[% editmode | html %]" />
209
        <input type="hidden" id="editmode" name="editmode" value="[% editmode | html %]" />
210
        <fieldset class="rows">
210
        <fieldset class="rows">
Lines 279-294 Link Here
279
279
280
                [% WRAPPER tab_panels %]
280
                [% WRAPPER tab_panels %]
281
                    [% FOR language IN languages %]
281
                    [% FOR language IN languages %]
282
                        [% SET translated_content = translated_contents.item(language.lang) %]
282
                        [% WRAPPER tab_panel tabname="lang_${language.lang}" %]
283
                        [% WRAPPER tab_panel tabname="lang_${language.lang}" %]
283
                            <fieldset>
284
                            <fieldset>
284
                                <ol>
285
                                <ol>
285
                                    <li>
286
                                    <li>
286
                                        <label for="title_[% language.lang | html %]">Title: </label>
287
                                        <label for="title_[% language.lang | html %]">Title: </label>
287
                                        <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 %]">
288
                                        <input id="title_[% language.lang| html %]" size="100" maxlength="250" type="text" name="title_[% language.lang | html %]" value="[% translated_content.title | html %]">
288
                                    </li>
289
                                    </li>
289
                                    <li>
290
                                    <li>
290
                                        <label for="content_[% language.lang | html %]">Content: </label>
291
                                        <label for="content_[% language.lang | html %]">Content: </label>
291
                                        <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>
292
                                        <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>
293
                                        <input type="hidden" name="id_[% language.lang | html %]" value="[% translated_content.id | html %]" />
292
                                        <input type="hidden" name="lang" value="[% language.lang | html %]" />
294
                                        <input type="hidden" name="lang" value="[% language.lang | html %]" />
293
                                    </li>
295
                                    </li>
294
                                </ol>
296
                                </ol>
Lines 363-371 Link Here
363
                    </thead>
365
                    </thead>
364
                    <tbody>
366
                    <tbody>
365
                        [% FOREACH c IN additional_contents%]
367
                        [% FOREACH c IN additional_contents%]
368
                            [% SET default_localization = c.default_localization %]
366
                            [% IF ( c.is_expired ) %]<tr class="expired">[% ELSE %]<tr>[% END %]
369
                            [% IF ( c.is_expired ) %]<tr class="expired">[% ELSE %]<tr>[% END %]
367
                            <td>
370
                            <td>
368
                                <input type="checkbox" name="ids" value="[% c.idnew | html %]" />
371
                                <input type="checkbox" name="ids" value="[% c.id | html %]" />
369
                            </td>
372
                            </td>
370
                            <td>
373
                            <td>
371
                                [% IF c.category == 'news' || c.category == 'pages' %]
374
                                [% IF c.category == 'news' || c.category == 'pages' %]
Lines 388-409 Link Here
388
                            <td>[% c.number | html %]</td>
391
                            <td>[% c.number | html %]</td>
389
                            <td data-order="[% c.published_on | html %]">[% c.published_on | $KohaDates %]</td>
392
                            <td data-order="[% c.published_on | html %]">[% c.published_on | $KohaDates %]</td>
390
                            <td data-order="[% c.expirationdate | html %]">[% c.expirationdate | $KohaDates %] [% IF ( c.is_expired ) %](<span class="expired">expired</span>)[% END %]</td>
393
                            <td data-order="[% c.expirationdate | html %]">[% c.expirationdate | $KohaDates %] [% IF ( c.is_expired ) %](<span class="expired">expired</span>)[% END %]</td>
391
                            <td>[% c.title | html %]</td>
394
                            <td>[% default_localization.title | html %]</td>
392
                            <td>[% IF ( c.author) %][% INCLUDE 'patron-title.inc' patron=c.author %][% END %]</td>
395
                            <td>[% IF ( c.author) %][% INCLUDE 'patron-title.inc' patron=c.author %][% END %]</td>
393
                            [% IF category == 'pages' %]
396
                            [% IF category == 'pages' %]
394
                                <td class="actions">
397
                                <td class="actions">
395
                                    [% IF c.location == 'opac_only' OR c.location == 'staff_and_opac' %]
398
                                    [% IF c.location == 'opac_only' OR c.location == 'staff_and_opac' %]
396
                                        <strong>OPAC</strong>:
399
                                        <strong>OPAC</strong>:
397
                                        <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>
400
                                        <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>
398
                                        OR
401
                                        OR
399
                                        <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>
402
                                        <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>
400
                                    [% END %]
403
                                    [% END %]
401
                                    [% IF c.location == 'staff_only' OR c.location == 'staff_and_opac' %]
404
                                    [% IF c.location == 'staff_only' OR c.location == 'staff_and_opac' %]
402
                                        [% IF c.location == 'staff_and_opac' %]<br/>[% END %]
405
                                        [% IF c.location == 'staff_and_opac' %]<br/>[% END %]
403
                                        <strong>Staff interface</strong>:
406
                                        <strong>Staff interface</strong>:
404
                                        <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.idnew | url %]" title="View on staff interface">Default</a>
407
                                        <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.id | uri %]&lang=default" title="View on staff interface">Default</a>
405
                                        OR
408
                                        OR
406
                                        <a href="/cgi-bin/koha/tools/page.pl?code=[% c.code | url %]" title="View on staff interface">Current language</a>
409
                                        <a href="/cgi-bin/koha/tools/page.pl?page_id=[% c.id | uri %]&lang=[% lang | uri %]" title="View on staff interface">Current language</a>
407
                                    [% END %]
410
                                    [% END %]
408
                                </td>
411
                                </td>
409
                            [% END %]
412
                            [% END %]
Lines 415-424 Link Here
415
                                    <div class="modal-dialog" role="document">
418
                                    <div class="modal-dialog" role="document">
416
                                        <div class="modal-content modal-lg">
419
                                        <div class="modal-content modal-lg">
417
                                            <div class="modal-header">
420
                                            <div class="modal-header">
418
                                                <h5 class="modal-title">Preview of: "[% c.title | html %]"</h5>
421
                                                <h5 class="modal-title">Preview of: "[% default_localization.title | html %]"</h5>
419
                                            </div>
422
                                            </div>
420
                                        <div class="modal-body">
423
                                        <div class="modal-body">
421
                                            [% c.content | $raw %]
424
                                            [% default_localization.content | $raw %]
422
                                        </div>
425
                                        </div>
423
                                        <div class="modal-footer">
426
                                        <div class="modal-footer">
424
                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
427
                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
Lines 428-448 Link Here
428
                            </td>
431
                            </td>
429
                            <td class="actions">
432
                            <td class="actions">
430
                                <div class="btn-group dropup">
433
                                <div class="btn-group dropup">
431
                                    <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 fa-pencil-alt"></i> Edit</a><button class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
434
                                    <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 fa-pencil-alt"></i> Edit</a><button class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
432
                                        <span class="caret"></span>
435
                                        <span class="caret"></span>
433
                                    </button>
436
                                    </button>
434
                                    <ul class="dropdown-menu pull-right">
437
                                    <ul class="dropdown-menu pull-right">
435
                                        <li>
438
                                        <li>
436
                                            [% IF ( wysiwyg ) %]
439
                                            [% IF ( wysiwyg ) %]
437
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.idnew | uri %]&editmode=text"><i class="fa fa-pencil-alt"></i> Edit with text editor</a>
440
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=text"><i class="fa fa-pencil-alt"></i> Edit with text editor</a>
438
                                            [% ELSE %]
441
                                            [% ELSE %]
439
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.idnew | uri %]&editmode=wysiwyg"><i class="fa fa-pencil-alt"></i> Edit with WYSIWYG editor</a>
442
                                                <a href="/cgi-bin/koha/tools/additional-contents.pl?op=add_form&amp;id=[% c.id | uri %]&editmode=wysiwyg"><i class="fa fa-pencil-alt"></i> Edit with WYSIWYG editor</a>
440
                                            [% END %]
443
                                            [% END %]
441
                                        </li>
444
                                        </li>
442
                                    </ul>
445
                                    </ul>
443
                                </div>
446
                                </div>
444
                                <div class="btn-group">
447
                                <div class="btn-group">
445
                                    <a href="#" class="delete_news btn btn-default btn-xs" data-idnew="[% c.idnew | html %]"><i class="fa fa-trash-can"></i> Delete</a>
448
                                    <a href="#" class="delete_news btn btn-default btn-xs" data-idnew="[% c.id | html %]"><i class="fa fa-trash-can"></i> Delete</a>
446
                                </div>
449
                                </div>
447
                            </td>
450
                            </td>
448
                        </tr>
451
                        </tr>
Lines 578-584 Link Here
578
                $("#del_form").on("click", ".delete_news", function(e){
581
                $("#del_form").on("click", ".delete_news", function(e){
579
                    e.preventDefault();
582
                    e.preventDefault();
580
                    if( confirmDelete( _("Are you sure you want to delete this content? This cannot be undone.") ) ){
583
                    if( confirmDelete( _("Are you sure you want to delete this content? This cannot be undone.") ) ){
581
                        $("#del_ids").val( $(this).data("idnew") );
584
                        $("#del_ids").val( $(this).data("id") );
582
                        $("#delete_single").submit();
585
                        $("#delete_single").submit();
583
                    }
586
                    }
584
                });
587
                });
(-)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
            [% ELSE %]
44
            [% ELSE %]
45
                <div class="col order-md-1 maincontent">
45
                <div class="col order-md-1 maincontent">
46
            [% END %]
46
            [% END %]
47
                <div id="page_[% page.idnew | html %]" class="maincontent">
47
                <div id="page_[% page.additional_content_id | html %]" class="maincontent">
48
48
49
            [% IF page %]
49
            [% IF page %]
50
50
(-)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 (-113 / +96 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 87-93 elsif ( $op eq 'add_validate' ) { Link Here
87
    my $location   = $cgi->param('location');
80
    my $location   = $cgi->param('location');
88
    my $code       = $cgi->param('code');
81
    my $code       = $cgi->param('code');
89
    my $branchcode = $cgi->param('branchcode') || undef;
82
    my $branchcode = $cgi->param('branchcode') || undef;
90
    my $idnew      = $cgi->param('idnew');
91
83
92
    my @lang       = $cgi->multi_param('lang');
84
    my @lang       = $cgi->multi_param('lang');
93
85
Lines 95-195 elsif ( $op eq 'add_validate' ) { Link Here
95
    my $published_on = $cgi->param('published_on');
87
    my $published_on = $cgi->param('published_on');
96
    my $number = $cgi->param('number');
88
    my $number = $cgi->param('number');
97
89
98
    my $original_default = $idnew ? Koha::AdditionalContents->find($idnew) : undef;
90
    try {
99
91
        Koha::Database->new->schema->txn_do(
100
    my $success = 1;
92
            sub {
101
    for my $lang ( sort {$a ne 'default'} @lang ) { # Process 'default' first
93
                my $additional_content;
102
        my $title   = $cgi->param( 'title_' . $lang );
94
                my $params = {
103
        my $content = $cgi->param( 'content_' . $lang );
104
        # Force a default record
105
        $content ||= '<!-- no_content -->' if $lang eq 'default';
106
107
        my $additional_content = Koha::AdditionalContents->find(
108
            {
109
                category   => $category,
110
                code       => $code,
111
                branchcode => $original_default ? $original_default->branchcode : $branchcode,
112
                lang       => $lang,
113
            }
114
        );
115
        # Delete if title or content is empty
116
        if( $lang ne 'default' && !$title && !$content ) {
117
            if ( $additional_content ) {
118
                eval { $additional_content->delete };
119
                unless ($@) {
120
                    logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $additional_content->code, $additional_content->title, $additional_content->lang, $additional_content->content));
121
                }
122
            }
123
            next;
124
        } elsif ( $additional_content ) {
125
            my $updated;
126
            eval {
127
                $additional_content->set(
128
                    {
129
                        category       => $category,
130
                        code           => $code,
131
                        location       => $location,
95
                        location       => $location,
132
                        branchcode     => $branchcode,
96
                        branchcode     => $branchcode,
133
                        title          => $title,
134
                        content        => $content,
135
                        lang           => $lang,
136
                        expirationdate => $expirationdate,
97
                        expirationdate => $expirationdate,
137
                        published_on   => $published_on,
98
                        published_on   => $published_on,
138
                        number         => $number,
99
                        number         => $number,
139
                        borrowernumber => $borrowernumber,
100
                        borrowernumber => $borrowernumber,
140
                    }
101
                    };
141
                );
102
142
                $updated = $additional_content->_result->get_dirty_columns;
103
                if ( $id ) {
143
                $additional_content->store;
104
                    $additional_content = Koha::AdditionalContents->find($id);
144
                $id = $additional_content->idnew;
105
                    $additional_content->set($params)->store;
145
            };
106
                } else {
146
            if ($@) {
107
                    $additional_content = Koha::AdditionalContent->new(
147
                $success = 0;
108
                        {
148
                push @messages, { type => 'error', code => 'error_on_update' };
109
                            category   => $category,
149
                last;
110
                            code       => $code,
150
            }
111
                            branchcode => $branchcode,
151
112
                            %$params,
152
            logaction('NEWS', 'MODIFY' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content))
113
                        }
153
                if C4::Context->preference("NewsLog") && $updated;
114
                    )->store;
154
        }
155
        else {
156
            my $additional_content = Koha::AdditionalContent->new(
157
                {
158
                    category       => $category,
159
                    code           => $code || 'tmp_code',
160
                    location       => $location,
161
                    branchcode     => $branchcode,
162
                    title          => $title,
163
                    content        => $content,
164
                    lang           => $lang,
165
                    expirationdate => $expirationdate,
166
                    published_on   => $published_on,
167
                    number         => $number,
168
                    borrowernumber => $borrowernumber,
169
                }
115
                }
170
            )->store;
171
            eval {
172
                $additional_content->store;
173
                unless ($code) {
116
                unless ($code) {
174
                    $additional_content->discard_changes;
117
                    $additional_content->discard_changes;
175
                    $code = $category eq 'news'
118
                    $code =
176
                      ? 'News_' . $additional_content->idnew
119
                      $category eq 'news'
177
                      : $location . '_' . $additional_content->idnew;
120
                      ? 'News_' . $additional_content->id
121
                      : $location . '_' . $additional_content->id;
178
                    $additional_content->code($code)->store;
122
                    $additional_content->code($code)->store;
179
                    $id = $additional_content->idnew;
123
                    $id = $additional_content->id;
180
                }
124
                }
181
            };
125
                my @translated_contents;
182
            if ($@) {
126
                my $existing_contents = $additional_content->translated_contents;
183
                $success = 0;
127
                my @seen_ids;
184
                push @messages, { type => 'error', code => 'error_on_insert' };
128
                for my $lang (@lang) {
185
                last;
129
                    my $id      = $cgi->param( 'id_' . $lang );
186
            }
130
                    my $title   = $cgi->param( 'title_' . $lang );
131
                    my $content = $cgi->param( 'content_' . $lang );
132
                    $content ||= '<!-- no_content -->' if $lang eq 'default';
133
134
                    next unless $title || $content;
135
136
                    push @seen_ids, $id;
137
                    push @translated_contents,
138
                      {
139
                        title   => $title,
140
                        content => $content,
141
                        lang    => $lang,
142
                      };
187
143
188
            logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content))
144
                    if ( C4::Context->preference("NewsLog") ) {
189
                if C4::Context->preference("NewsLog");
145
                        my $existing_content = $existing_contents->find($id);
190
        }
146
                        if ( $existing_content ) {
147
                            if ( $existing_content->title ne $title || $existing_content->content ne $content ) {
148
                                logaction('NEWS', 'MODIFY' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content));
149
                            }
150
                        } else {
151
                            logaction('NEWS', 'ADD' , undef, sprintf("%s|%s|%s|%s", $code, $title, $lang, $content))
152
                        }
153
                    }
154
                }
191
155
192
    }
156
                if ( C4::Context->preference("NewsLog") ) {
157
                    my @existing_ids = $existing_contents->get_column('id');
158
                    my @deleted_ids = array_minus( @existing_ids, @seen_ids );
159
                    for my $id ( @deleted_ids ) {
160
                        my $c = $existing_contents->find($id);
161
                        logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s", $code, $c->lang, $c->content));
162
                    }
163
                }
164
165
                $additional_content->translated_contents( \@translated_contents );
166
            }
167
        );
168
    } catch {
169
        warn $_;
170
        if ( $id ) {
171
            push @messages, { type => 'error', code => 'error_on_update' };
172
        } else {
173
            push @messages, { type => 'error', code => 'error_on_insert' };
174
        }
175
    };
193
176
194
    if( $redirect eq "just_save" ){
177
    if( $redirect eq "just_save" ){
195
        print $cgi->redirect("/cgi-bin/koha/tools/additional-contents.pl?op=add_form&id=$id&category=$category&editmode=$editmode&redirect=done");
178
        print $cgi->redirect("/cgi-bin/koha/tools/additional-contents.pl?op=add_form&id=$id&category=$category&editmode=$editmode&redirect=done");
Lines 200-237 elsif ( $op eq 'add_validate' ) { Link Here
200
}
183
}
201
elsif ( $op eq 'delete_confirmed' ) {
184
elsif ( $op eq 'delete_confirmed' ) {
202
    my @ids = $cgi->multi_param('ids');
185
    my @ids = $cgi->multi_param('ids');
203
    my $deleted = eval {
204
186
205
        my $schema = Koha::Database->new->schema;
187
    try {
206
        $schema->txn_do(
188
        Koha::Database->new->schema->txn_do(
207
            sub {
189
            sub {
208
                my $contents =
190
                my $contents =
209
                  Koha::AdditionalContents->search( { idnew => \@ids } );
191
                  Koha::AdditionalContents->search( { id => \@ids } );
210
192
211
                while ( my $c = $contents->next ) {
193
                if ( C4::Context->preference("NewsLog") ) {
212
                    Koha::AdditionalContents->search( { code => $c->code } )->delete;
194
                    while ( my $c = $contents->next ) {
213
                    if ( C4::Context->preference("NewsLog") ) {
195
                        my $translated_contents = $c->translated_contents;
214
                        logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $c->title, $c->lang, $c->content));
196
                        while ( my $translated_content = $translated_contents->next ) {
197
                            logaction('NEWS', 'DELETE' , undef, sprintf("%s|%s|%s|%s", $c->code, $translated_content->lang, $translated_content->content));
198
                        }
215
                    }
199
                    }
216
                }
200
                }
201
                $contents->delete;
217
            }
202
            }
218
        );
203
        );
219
    };
220
221
    if ( $@ or not $deleted ) {
222
        push @messages, { type => 'error', code => 'error_on_delete' };
223
    }
224
    else {
225
        push @messages, { type => 'message', code => 'success_on_delete' };
204
        push @messages, { type => 'message', code => 'success_on_delete' };
226
    }
205
    } catch {
206
        warn $_;
207
        push @messages, { type => 'error', code => 'error_on_delete' };
208
    };
227
209
228
    $op = 'list';
210
    $op = 'list';
229
}
211
}
230
212
231
if ( $op eq 'list' ) {
213
if ( $op eq 'list' ) {
232
    my $additional_contents = Koha::AdditionalContents->search(
214
    my $additional_contents = Koha::AdditionalContents->search(
233
        { category => $category, lang => 'default' },
215
        { category => $category, 'additional_contents_localizations.lang' => 'default' },
234
        { order_by => { -desc => 'published_on' } }
216
        { order_by => { -desc => 'published_on' }, join => 'additional_contents_localizations' }
235
    );
217
    );
236
    $template->param( additional_contents => $additional_contents );
218
    $template->param( additional_contents => $additional_contents );
237
}
219
}
Lines 267-272 $template->param( Link Here
267
    wysiwyg   => $wysiwyg,
249
    wysiwyg   => $wysiwyg,
268
    editmode  => $editmode,
250
    editmode  => $editmode,
269
    languages => \@languages,
251
    languages => \@languages,
252
    messages  => \@messages,
270
);
253
);
271
254
272
output_html_with_http_headers $cgi, $cookie, $template->output;
255
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