adding volume and volumeddesc field in the result list. Kados, pls check that it...
[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 with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use CGI;
26 use C4::Auth;
27 use C4::Koha;
28 use C4::Context;
29 use C4::Output;
30 use C4::NewsChannels;
31 use C4::Languages;
32 use Date::Calc qw/Date_to_Days Today/;
33
34 my $cgi = new CGI;
35
36 my $id             = $cgi->param('id');
37 my $title          = $cgi->param('title');
38 my $new            = $cgi->param('new');
39 my $expirationdate = $cgi->param('expirationdate');
40 my $number         = $cgi->param('number');
41 my $lang           = $cgi->param('lang');
42
43 my $new_detail = get_opac_new($id);
44
45 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
46     {
47         template_name   => "tools/koha-news.tmpl",
48         query           => $cgi,
49         type            => "intranet",
50         authnotrequired => 0,
51         flagsrequired   => { tools => 1 },
52         debug           => 1,
53     }
54 );
55
56 # get lang list
57 my @lang_list;
58 my $tlangs = getTranslatedLanguages() ;
59 foreach my $language ( @$tlangs ) {
60     push @lang_list,
61       {
62         language => $language->{'language_code'},
63         selected => ( $new_detail->{lang} eq $language->{'language_code'} ? 1 : 0 ),
64       };
65 }
66
67 $template->param( lang_list => \@lang_list );
68
69 my $op = $cgi->param('op');
70
71 if ( $op eq 'add_form' ) {
72     $template->param( add_form => 1 );
73     if ($id) {
74         $template->param( 
75             op => 'edit',
76             id => $new_detail->{'idnew'}
77         );
78         $template->param($new_detail);
79     }
80     else {
81         $template->param( op => 'add' );
82     }
83 }
84 elsif ( $op eq 'add' ) {
85     add_opac_new( $title, $new, $lang, $expirationdate, $number );
86     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
87 }
88 elsif ( $op eq 'edit' ) {
89     upd_opac_new( $id, $title, $new, $lang, $expirationdate, $number );
90     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
91 }
92 elsif ( $op eq 'del' ) {
93     my @ids = $cgi->param('ids');
94     del_opac_new( join ",", @ids );
95     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
96 }
97
98 else {
99
100     my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, $lang );
101     
102     foreach my $new ( @$opac_news ) {
103         next unless $new->{'expirationdate'};
104         next if $new->{'expirationdate'} eq '0000-00-00';
105         if (Date_to_Days( split "-" ,$new->{'expirationdate'} ) < Date_to_Days(&Today) ){
106             $new->{'hasexpirated'} = 1;
107         }
108     }
109     
110     $template->param(
111         $lang           => 1,
112         opac_news       => $opac_news,
113         opac_news_count => $opac_news_count 
114     );
115 }
116
117 output_html_with_http_headers $cgi, $cookie, $template->output;