Fixes bug 4369: Local use does not update datelastseen
[koha.git] / tools / koha-news.pl
1 #!/usr/bin/perl
2
3 # Script to manage the opac news.
4 # written 11/04
5 # Casta�eda, Carlos Sebastian - seba3c@yahoo.com.ar - Physics Library UNLP Argentina
6 # Modified to include news to KOHA intranet - tgarip@neu.edu.tr NEU library -Cyprus
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 use strict;
25 #use warnings; FIXME - Bug 2505
26 use CGI;
27 use C4::Auth;
28 use C4::Koha;
29 use C4::Context;
30 use C4::Dates qw(format_date_in_iso);
31 use C4::Output;
32 use C4::NewsChannels;
33 use C4::Languages qw(getTranslatedLanguages);
34 use Date::Calc qw/Date_to_Days Today/;
35
36 my $cgi = new CGI;
37
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');
45
46 my $new_detail = get_opac_new($id);
47
48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
49     {
50         template_name   => "tools/koha-news.tmpl",
51         query           => $cgi,
52         type            => "intranet",
53         authnotrequired => 0,
54         flagsrequired   => { tools => 'edit_news' },
55         debug           => 1,
56     }
57 );
58
59 # get lang list
60 my @lang_list;
61 my $tlangs = getTranslatedLanguages() ;
62 foreach my $language ( @$tlangs ) {
63     push @lang_list,
64       {
65         language => $language->{'rfc4646_subtag'},
66         selected => ( $new_detail->{lang} eq $language->{'rfc4646_subtag'} ? 1 : 0 ),
67       };
68 }
69
70 $template->param( lang_list => \@lang_list );
71
72 my $op = $cgi->param('op');
73
74 if ( $op eq 'add_form' ) {
75     $template->param( add_form => 1 );
76     if ($id) {
77         $template->param( 
78             op => 'edit',
79             id => $new_detail->{'idnew'}
80         );
81         $template->param($new_detail);
82     }
83     else {
84         $template->param( op => 'add' );
85     }
86 }
87 elsif ( $op eq 'add' ) {
88     add_opac_new( $title, $new, $lang, $expirationdate, $timestamp, $number );
89     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
90 }
91 elsif ( $op eq 'edit' ) {
92     upd_opac_new( $id, $title, $new, $lang, $expirationdate, $timestamp ,$number );
93     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
94 }
95 elsif ( $op eq 'del' ) {
96     my @ids = $cgi->param('ids');
97     del_opac_new( join ",", @ids );
98     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
99 }
100
101 else {
102
103     my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, $lang );
104     
105     foreach my $new ( @$opac_news ) {
106         next unless $new->{'expirationdate'};
107         #$new->{'expirationdate'}=format_date_in_iso($new->{'expirationdate'});
108         my @date = split (/-/,$new->{'expirationdate'});
109         if ($date[0]*$date[1]*$date[2]>0 && Date_to_Days( @date ) < Date_to_Days(&Today) ){
110                         $new->{'expired'} = 1;
111         }
112     }
113     
114     $template->param(
115         $lang           => 1,
116         opac_news       => $opac_news,
117         opac_news_count => $opac_news_count,
118                 );
119 }
120 $template->param(
121                                 DHTMLcalendar_dateformat =>  C4::Dates->DHTMLcalendar(),
122                                 dateformat    => C4::Context->preference("dateformat"),
123                 );
124 output_html_with_http_headers $cgi, $cookie, $template->output;