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>.
26 # use warnings; FIXME - Bug 2505
31 use C4
::Dates
qw(format_date_in_iso);
34 use C4
::Languages
qw(getTranslatedLanguages);
35 use Date
::Calc qw
/Date_to_Days Today/;
36 use C4
::Branch qw
/GetBranches/;
40 my $id = $cgi->param('id');
41 my $title = $cgi->param('title');
42 my $new = $cgi->param('new');
43 my $expirationdate = format_date_in_iso
($cgi->param('expirationdate'));
44 my $timestamp = format_date_in_iso
($cgi->param('timestamp'));
45 my $number = $cgi->param('number');
46 my $lang = $cgi->param('lang');
47 my $branchcode = $cgi->param('branch');
48 # Foreign Key constraints work with NULL, not ''
49 # NULL = All branches.
50 $branchcode = undef if (defined($branchcode) && $branchcode eq '');
52 my $new_detail = get_opac_new
($id);
54 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
56 template_name
=> "tools/koha-news.tt",
60 flagsrequired
=> { tools
=> 'edit_news' },
67 my $tlangs = getTranslatedLanguages
() ;
68 foreach my $language ( @
$tlangs ) {
71 language
=> $language->{'rfc4646_subtag'},
72 selected
=> ( $new_detail->{lang
} eq $language->{'rfc4646_subtag'} ?
1 : 0 ),
76 my $branches = GetBranches
;
78 $template->param( lang_list
=> \
@lang_list,
79 branch_list
=> $branches,
80 branchcode
=> $branchcode );
82 my $op = $cgi->param('op') // '';
84 if ( $op eq 'add_form' ) {
85 $template->param( add_form
=> 1 );
87 if($new_detail->{lang
} eq "slip"){ $template->param( slip
=> 1); }
90 id
=> $new_detail->{'idnew'}
92 $template->{VARS
}->{'new_detail'} = $new_detail;
95 $template->param( op
=> 'add' );
98 elsif ( $op eq 'add' ) {
104 expirationdate
=> $expirationdate,
105 timestamp
=> $timestamp,
107 branchcode
=> $branchcode,
110 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
112 elsif ( $op eq 'edit' ) {
119 expirationdate
=> $expirationdate,
120 timestamp
=> $timestamp,
122 branchcode
=> $branchcode,
125 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
127 elsif ( $op eq 'del' ) {
128 my @ids = $cgi->param('ids');
129 del_opac_new
( join ",", @ids );
130 print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
135 my ( $opac_news_count, $opac_news ) = &get_opac_news
( undef, $lang, $branchcode );
137 foreach my $new ( @
$opac_news ) {
138 next unless $new->{'expirationdate'};
139 #$new->{'expirationdate'}=format_date_in_iso($new->{'expirationdate'});
140 my @date = split (/-/,$new->{'expirationdate'});
141 if ($date[0]*$date[1]*$date[2]>0 && Date_to_Days
( @date ) < Date_to_Days
(&Today
) ){
142 $new->{'expired'} = 1;
147 opac_news
=> $opac_news,
148 opac_news_count
=> $opac_news_count,
151 $template->param( lang
=> $lang );
152 output_html_with_http_headers
$cgi, $cookie, $template->output;