3 # This file is part of Koha.
5 # Script to manage the opac news.
7 # Casta�eda, Carlos Sebastian - seba3c@yahoo.com.ar - Physics Library UNLP Argentina
8 # Modified to include news to KOHA intranet - tgarip@neu.edu.tr NEU library -Cyprus
9 # Copyright 2000-2002 Katipo Communications
10 # Copyright (C) 2013 Mark Tompsett
12 # Koha is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
31 use C4::Languages qw(getTranslatedLanguages);
33 use Koha::AdditionalContents;
37 my $op = $cgi->param('op') || 'list';
38 my $id = $cgi->param('id');
39 my $category = $cgi->param('category') || 'news';
41 if( $cgi->param('editmode') ){
42 $wysiwyg = $cgi->param('editmode') eq "wysiwyg" ? 1 : 0;
44 $wysiwyg = C4::Context->preference("AdditionalContentsEditor") eq "tinymce" ? 1 : 0;
47 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
49 template_name => "tools/additional-contents.tt",
52 flagsrequired => { tools => 'edit_additional_contents' },
57 if ( $op eq 'add_form' ) {
59 my $additional_content = Koha::AdditionalContents->find($id);
60 my $translated_contents;
61 if ( $additional_content ) {
62 $translated_contents = {
63 map { $_->lang => $_ } Koha::AdditionalContents->search(
65 category => $additional_content->category,
66 code => $additional_content->code,
67 location => $additional_content->location,
68 branchcode => $additional_content->branchcode,
74 additional_content => $additional_content,
75 translated_contents => $translated_contents,
78 elsif ( $op eq 'add_validate' ) {
79 my $location = $cgi->param('location');
80 my $code = $cgi->param('code');
81 my $branchcode = $cgi->param('branchcode') || undef;
83 my @title = $cgi->multi_param('title');
84 my @content = $cgi->multi_param('content');
85 my @lang = $cgi->multi_param('lang');
88 if ( $cgi->param('expirationdate') ) {
89 $expirationdate = output_pref(
91 dt => dt_from_string( scalar $cgi->param('expirationdate') ),
97 my $published_on = output_pref(
99 dt => dt_from_string( scalar $cgi->param('published_on') ),
104 my $number = $cgi->param('number');
107 for my $lang ( @lang ) {
108 my $title = shift @title;
109 my $content = shift @content;
110 my $additional_content = Koha::AdditionalContents->find(
112 category => $category,
114 branchcode => $branchcode,
118 # Delete if title or content is empty
119 unless ( $title and $content ) {
120 $additional_content->delete if $additional_content;
122 } elsif ( $additional_content ) {
124 $additional_content->update(
126 category => $category,
128 location => $location,
129 branchcode => $branchcode,
133 expirationdate => $expirationdate,
134 published_on => $published_on,
136 borrowernumber => $borrowernumber,
142 push @messages, { type => 'error', code => 'error_on_update' };
147 my $additional_content = Koha::AdditionalContent->new(
149 category => $category,
151 location => $location,
152 branchcode => $branchcode,
156 expirationdate => $expirationdate,
157 published_on => $published_on,
159 borrowernumber => $borrowernumber,
162 eval { $additional_content->store; };
165 push @messages, { type => 'error', code => 'error_on_insert' };
173 elsif ( $op eq 'delete_confirmed' ) {
174 my @ids = $cgi->multi_param('ids');
176 eval { Koha::AdditionalContents->search( { idnew => @ids } )->delete; };
178 if ( $@ or not $deleted ) {
179 push @messages, { type => 'error', code => 'error_on_delete' };
182 push @messages, { type => 'message', code => 'success_on_delete' };
188 if ( $op eq 'list' ) {
189 my $additional_contents = Koha::AdditionalContents->search(
190 { category => $category, lang => 'default' },
191 { order_by => { -desc => 'published_on' } }
193 $template->param( additional_contents => $additional_contents );
196 my $translated_languages = C4::Languages::getTranslatedLanguages;
198 for my $language (@$translated_languages) {
199 for my $sublanguage ( @{ $language->{sublanguages_loop} } ) {
200 if ( $language->{plural} ) {
203 lang => $sublanguage->{rfc4646_subtag},
204 description => $sublanguage->{native_description} . ' '
205 . $sublanguage->{region_description} . ' ('
206 . $sublanguage->{rfc4646_subtag} . ')',
212 lang => $sublanguage->{rfc4646_subtag},
213 description => $sublanguage->{native_description} . ' ('
214 . $sublanguage->{rfc4646_subtag} . ')',
219 unshift @languages, {lang => 'default'} if @languages;
223 category => $category,
225 languages => \@languages,
229 output_html_with_http_headers $cgi, $cookie, $template->output;