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>.
32 use C4::Languages qw(getTranslatedLanguages);
33 use Date::Calc qw/Date_to_Days Today/;
39 my $id = $cgi->param('id');
40 my $title = $cgi->param('title');
41 my $content = $cgi->param('content');
43 if ( $cgi->param('expirationdate') ) {
44 $expirationdate = output_pref({ dt => dt_from_string( scalar $cgi->param('expirationdate') ), dateformat => 'iso', dateonly => 1 });
46 my $published_on= output_pref({ dt => dt_from_string( scalar $cgi->param('published_on') ), dateformat => 'iso', dateonly => 1 });
47 my $number = $cgi->param('number');
48 my $lang = $cgi->param('lang');
49 my $branchcode = $cgi->param('branch');
50 my $error_message = $cgi->param('error_message');
52 if( $cgi->param('editmode') ){
53 $wysiwyg = $cgi->param('editmode') eq "wysiwyg" ? 1 : 0;
55 $wysiwyg = C4::Context->preference("NewsToolEditor") eq "tinymce" ? 1 : 0;
58 # Foreign Key constraints work with NULL, not ''
59 # NULL = All branches.
60 $branchcode = undef if (defined($branchcode) && $branchcode eq '');
62 my $new_detail = Koha::News->find( $id );
64 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
66 template_name => "tools/koha-news.tt",
69 flagsrequired => { tools => 'edit_news' },
73 # Pass error message if there is one.
74 $template->param( error_message => $error_message ) if $error_message;
78 my $tlangs = getTranslatedLanguages() ;
80 foreach my $language ( @$tlangs ) {
81 foreach my $sublanguage ( @{$language->{'sublanguages_loop'}} ) {
84 language => $sublanguage->{'rfc4646_subtag'},
85 selected => ( $new_detail && $new_detail->lang eq $sublanguage->{'rfc4646_subtag'} ? 1 : 0 ),
90 $template->param( lang_list => \@lang_list,
91 branchcode => $branchcode );
93 my $op = $cgi->param('op') // '';
95 if ( $op eq 'add_form' ) {
96 $template->param( add_form => 1 );
98 if($new_detail->lang eq "slip"){ $template->param( slip => 1); }
101 id => $new_detail->idnew
103 $template->{VARS}->{'new_detail'} = $new_detail;
106 $template->param( op => 'add' );
109 elsif ( $op eq 'add' ) {
116 expirationdate => $expirationdate,
117 published_on=> $published_on,
119 branchcode => $branchcode,
120 borrowernumber => $borrowernumber,
123 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
126 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl?error_message=title_missing");
129 elsif ( $op eq 'edit' ) {
136 expirationdate => $expirationdate,
137 published_on=> $published_on,
139 branchcode => $branchcode,
142 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
144 elsif ( $op eq 'del' ) {
145 my @ids = $cgi->multi_param('ids');
146 del_opac_new( join ",", @ids );
147 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
152 my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, undef, undef );
154 foreach my $new ( @$opac_news ) {
155 next unless $new->{'expirationdate'};
156 my @date = split (/-/,$new->{'expirationdate'});
157 if ($date[0]*$date[1]*$date[2]>0 && Date_to_Days( @date ) < Date_to_Days(&Today) ){
158 $new->{'expired'} = 1;
163 opac_news => $opac_news,
164 opac_news_count => $opac_news_count,
171 output_html_with_http_headers $cgi, $cookie, $template->output;