1 package C4::NewsChannels;
3 # This file is part of Koha.
5 # Copyright (C) 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use C4::Dates qw(format_date);
26 use vars qw($VERSION @ISA @EXPORT);
29 $VERSION = 3.07.00.049; # 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);
58 my ($idnew, $title, $new, $lang, $expirationdate, $timestamp,$number) = @_;
59 my $dbh = C4::Context->dbh;
60 my $sth = $dbh->prepare("
70 $sth->execute($title, $new, $lang, $expirationdate, $timestamp,$number,$idnew);
77 my $dbh = C4::Context->dbh;
78 my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)");
88 my $dbh = C4::Context->dbh;
89 my $sth = $dbh->prepare("SELECT * FROM opac_news WHERE idnew = ?");
90 $sth->execute($idnew);
91 my $data = $sth->fetchrow_hashref;
92 $data->{$data->{'lang'}} = 1 if defined $data->{lang};
93 $data->{expirationdate} = format_date($data->{expirationdate});
94 $data->{timestamp} = format_date($data->{timestamp});
99 my ($limit, $lang) = @_;
100 my $dbh = C4::Context->dbh;
101 my $query = "SELECT *, timestamp AS newdate FROM opac_news";
103 $query.= " WHERE lang = '" .$lang ."' ";
105 $query.= " ORDER BY timestamp DESC ";
107 # $query.= "LIMIT 0, " . $limit;
109 my $sth = $dbh->prepare($query);
113 while (my $row = $sth->fetchrow_hashref) {
114 if ((($limit) && ($count < $limit)) || (!$limit)) {
115 push @opac_news, $row;
119 return ($count, \@opac_news);
122 =head2 GetNewsToDisplay
124 $news = &GetNewsToDisplay($lang);
125 C<$news> is a ref to an array which containts
126 all news with expirationdate > today or expirationdate is null.
130 sub GetNewsToDisplay {
132 my $dbh = C4::Context->dbh;
133 # SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
135 SELECT *,timestamp AS newdate
138 expirationdate >= CURRENT_DATE()
139 OR expirationdate IS NULL
140 OR expirationdate = '00-00-0000'
142 AND `timestamp` <= CURRENT_DATE()
145 "; # expirationdate field is NOT in ISO format?
146 my $sth = $dbh->prepare($query);
147 $sth->execute($lang);
149 while ( my $row = $sth->fetchrow_hashref ){
150 $row->{newdate} = format_date($row->{newdate});