New XML API
[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
27 use C4::Auth;
28 use C4::Koha;
29 use C4::Context;
30 use C4::Output;
31 use C4::Interface::CGI::Output;
32 use C4::NewsChannels;
33
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 $lang        = $cgi->param('lang');
41 my $new_detail = get_opac_new($id);
42
43 my ($template, $borrowernumber, $cookie)
44     = get_template_and_user({template_name => "tools/koha-news.tmpl",
45                              query => $cgi,
46                              type => "intranet",
47                              authnotrequired => 0,
48                              flagsrequired => {management => 1},
49                              debug => 1,
50                              });
51
52 # get lang list
53 my @lang_list;
54
55 foreach my $language (getalllanguages()) {
56         push @lang_list, { language => $language,
57                                                 selected => ($new_detail->{lang} eq $language?1:0),
58                                         };
59 }
60 $template->param(lang_list => \@lang_list);
61
62 my $op = $cgi->param('op');
63
64 if ($op eq 'add_form') {
65         $template->param(add_form => 1);
66         if ($id) {
67                 $template->param(op => 'edit');
68                 $template->param($new_detail);
69                 $template->param(id => $new_detail->{'idnew'});
70         } else {
71                 $template->param(op => 'add');
72         }
73         
74 } elsif ($op eq 'add') {
75
76         add_opac_new($title, $new, $lang);
77         print $cgi->redirect('/cgi-bin/koha/tools/koha-news.pl');
78
79 } elsif ($op eq 'edit') {
80
81         upd_opac_new($id, $title, $new, $lang);
82         print $cgi->redirect('/cgi-bin/koha/tools/koha-news.pl');
83
84 } elsif ($op eq 'del') {
85         my @ids = $cgi->param('ids');
86         del_opac_new(join ",", @ids);
87         print $cgi->redirect('/cgi-bin/koha/tools/koha-news.pl');
88
89 } else { 
90
91         my ($opac_news_count, $opac_news) = &get_opac_news(undef, $lang);
92         $template->param($lang => 1);
93         $template->param(opac_news => $opac_news);
94         $template->param(opac_news_count => $opac_news_count);
95
96 }
97
98 output_html_with_http_headers $cgi, $cookie, $template->output;