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