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
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 # use warnings; FIXME - Bug 2505
30 use C4::Dates qw(format_date_in_iso);
33 use C4::Languages qw(getTranslatedLanguages);
34 use Date::Calc qw/Date_to_Days Today/;
38 my $id = $cgi->param('id');
39 my $title = $cgi->param('title');
40 my $new = $cgi->param('new');
41 my $expirationdate = format_date_in_iso($cgi->param('expirationdate'));
42 my $timestamp = format_date_in_iso($cgi->param('timestamp'));
43 my $number = $cgi->param('number');
44 my $lang = $cgi->param('lang');
46 my $new_detail = get_opac_new($id);
48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
50 template_name => "tools/koha-news.tmpl",
54 flagsrequired => { tools => 'edit_news' },
61 my $tlangs = getTranslatedLanguages() ;
62 foreach my $language ( @$tlangs ) {
65 language => $language->{'rfc4646_subtag'},
66 selected => ( $new_detail->{lang} eq $language->{'rfc4646_subtag'} ? 1 : 0 ),
70 $template->param( lang_list => \@lang_list );
72 my $op = $cgi->param('op');
74 if ( $op eq 'add_form' ) {
75 $template->param( add_form => 1 );
77 if($new_detail->{lang} eq "slip"){ $template->param( slip => 1); }
80 id => $new_detail->{'idnew'}
82 $template->{VARS}->{'new_detail'} = $new_detail;
85 $template->param( op => 'add' );
88 elsif ( $op eq 'add' ) {
89 add_opac_new( $title, $new, $lang, $expirationdate, $timestamp, $number );
90 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
92 elsif ( $op eq 'edit' ) {
93 upd_opac_new( $id, $title, $new, $lang, $expirationdate, $timestamp ,$number );
94 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
96 elsif ( $op eq 'del' ) {
97 my @ids = $cgi->param('ids');
98 del_opac_new( join ",", @ids );
99 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
104 my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, $lang );
106 foreach my $new ( @$opac_news ) {
107 next unless $new->{'expirationdate'};
108 #$new->{'expirationdate'}=format_date_in_iso($new->{'expirationdate'});
109 my @date = split (/-/,$new->{'expirationdate'});
110 if ($date[0]*$date[1]*$date[2]>0 && Date_to_Days( @date ) < Date_to_Days(&Today) ){
111 $new->{'expired'} = 1;
116 opac_news => $opac_news,
117 opac_news_count => $opac_news_count,
120 output_html_with_http_headers $cgi, $cookie, $template->output;