1 package C4
::NewsChannels
;
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 use C4
::Dates
qw(format_date);
26 use vars
qw($VERSION @ISA @EXPORT);
29 $VERSION = 3.01; # set the version for version checking
33 &add_opac_new &upd_opac_new &del_opac_new &get_opac_new &get_opac_news
39 C4::NewsChannels - Functions to manage OPAC and intranet news
43 This module provides the functions needed to mange OPAC and intranet news.
50 my ($title, $new, $lang, $expirationdate, $timestamp, $number) = @_;
51 my $dbh = C4
::Context
->dbh;
52 my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, timestamp, number) VALUES (?,?,?,?,?,?)");
53 $sth->execute($title, $new, $lang, $expirationdate, $timestamp, $number);
59 my ($idnew, $title, $new, $lang, $expirationdate, $timestamp,$number) = @_;
60 my $dbh = C4
::Context
->dbh;
61 my $sth = $dbh->prepare("
71 $sth->execute($title, $new, $lang, $expirationdate, $timestamp,$number,$idnew);
79 my $dbh = C4
::Context
->dbh;
80 my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)");
91 my $dbh = C4
::Context
->dbh;
92 my $sth = $dbh->prepare("SELECT * FROM opac_news WHERE idnew = ?");
93 $sth->execute($idnew);
94 my $data = $sth->fetchrow_hashref;
95 $data->{$data->{'lang'}} = 1 if defined $data->{lang
};
96 $data->{expirationdate
} = format_date
($data->{expirationdate
});
97 $data->{timestamp
} = format_date
($data->{timestamp
});
103 my ($limit, $lang) = @_;
104 my $dbh = C4
::Context
->dbh;
105 my $query = "SELECT *, timestamp AS newdate FROM opac_news";
107 $query.= " WHERE lang = '" .$lang ."' ";
109 $query.= " ORDER BY timestamp DESC ";
111 # $query.= "LIMIT 0, " . $limit;
113 my $sth = $dbh->prepare($query);
117 while (my $row = $sth->fetchrow_hashref) {
118 if ((($limit) && ($count < $limit)) || (!$limit)) {
119 $row->{'newdate'} = format_date
($row->{'newdate'});
120 $row->{'expirationdate'} = format_date
($row->{'expirationdate'});
121 push @opac_news, $row;
125 return ($count, \
@opac_news);
128 =head2 GetNewsToDisplay
130 $news = &GetNewsToDisplay($lang);
131 C<$news> is a ref to an array which containts
132 all news with expirationdate > today or expirationdate is null.
136 sub GetNewsToDisplay
{
138 my $dbh = C4
::Context
->dbh;
139 # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
141 SELECT *,timestamp AS newdate
144 expirationdate >= CURRENT_DATE()
145 OR expirationdate IS NULL
146 OR expirationdate = '00-00-0000'
148 AND `timestamp` <= CURRENT_DATE()
151 "; # expirationdate field is NOT in ISO format?
152 my $sth = $dbh->prepare($query);
153 $sth->execute($lang);
155 while ( my $row = $sth->fetchrow_hashref ){
156 $row->{newdate
} = format_date
($row->{newdate
});