add order line through z3950 search
[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::Dates qw(format_date_in_iso);
30 use C4::Output;
31 use C4::NewsChannels;
32 use C4::Languages qw(getTranslatedLanguages);
33 use Date::Calc qw/Date_to_Days Today/;
34
35 my $cgi = new CGI;
36
37 my $id             = $cgi->param('id');
38 my $title          = $cgi->param('title');
39 my $new            = $cgi->param('new');
40 my $expirationdate = format_date_in_iso($cgi->param('expirationdate'));
41 my $timestamp      = format_date_in_iso($cgi->param('timestamp'));
42 my $number         = $cgi->param('number');
43 my $lang           = $cgi->param('lang');
44
45 my $new_detail = get_opac_new($id);
46
47 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
48     {
49         template_name   => "tools/koha-news.tmpl",
50         query           => $cgi,
51         type            => "intranet",
52         authnotrequired => 0,
53         flagsrequired   => { tools => 'edit_news' },
54         debug           => 1,
55     }
56 );
57
58 # get lang list
59 my @lang_list;
60 my $tlangs = getTranslatedLanguages() ;
61 foreach my $language ( @$tlangs ) {
62     push @lang_list,
63       {
64         language => $language->{'rfc4646_subtag'},
65         selected => ( $new_detail->{lang} eq $language->{'rfc4646_subtag'} ? 1 : 0 ),
66       };
67 }
68
69 $template->param( lang_list => \@lang_list );
70
71 my $op = $cgi->param('op');
72
73 if ( $op eq 'add_form' ) {
74     $template->param( add_form => 1 );
75     if ($id) {
76         $template->param( 
77             op => 'edit',
78             id => $new_detail->{'idnew'}
79         );
80         $template->param($new_detail);
81     }
82     else {
83         $template->param( op => 'add' );
84     }
85 }
86 elsif ( $op eq 'add' ) {
87     add_opac_new( $title, $new, $lang, $expirationdate, $timestamp, $number );
88     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
89 }
90 elsif ( $op eq 'edit' ) {
91     upd_opac_new( $id, $title, $new, $lang, $expirationdate, $timestamp ,$number );
92     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
93 }
94 elsif ( $op eq 'del' ) {
95     my @ids = $cgi->param('ids');
96     del_opac_new( join ",", @ids );
97     print $cgi->redirect("/cgi-bin/koha/tools/koha-news.pl");
98 }
99
100 else {
101
102     my ( $opac_news_count, $opac_news ) = &get_opac_news( undef, $lang );
103     
104     foreach my $new ( @$opac_news ) {
105         next unless $new->{'expirationdate'};
106         #$new->{'expirationdate'}=format_date_in_iso($new->{'expirationdate'});
107         my @date = split (/-/,$new->{'expirationdate'});
108         if ($date[0]*$date[1]*$date[2]>0 && Date_to_Days( @date ) < Date_to_Days(&Today) ){
109                         $new->{'expired'} = 1;
110         }
111     }
112     
113     $template->param(
114         $lang           => 1,
115         opac_news       => $opac_news,
116         opac_news_count => $opac_news_count,
117                 );
118 }
119 $template->param(
120                                 DHTMLcalendar_dateformat =>  C4::Dates->DHTMLcalendar(),
121                                 dateformat    => C4::Context->preference("dateformat"),
122                 );
123 output_html_with_http_headers $cgi, $cookie, $template->output;