use vars qw($VERSION @ISA @EXPORT);\r
\r
# set the version for version checking\r
-$VERSION = 0.01;\r
+$VERSION = do { my @v = '$Revision$' =~ /\d+/g;\r
+ shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );\r
+};\r
\r
=head1 NAME\r
\r
\r
\r
@ISA = qw(Exporter);\r
-@EXPORT = qw(\r
+@EXPORT = qw(
+ &GetNewsToDisplay\r
&news_channels &get_new_channel &del_channels &add_channel &update_channel\r
&news_channels_categories &get_new_channel_category &del_channels_categories\r
&add_channel_category &update_channel_category &news_channels_by_category\r
=cut\r
\r
sub news_channels {\r
- my ($channel_name, $id_category, $unclassified) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my @channels;\r
- my $query = "SELECT * FROM news_channels LEFT JOIN news_channels_categories ON news_channels.id_category = news_channels_categories.id_category";\r
- if ( ($channel_name ne '') && ($id_category ne '') ) {\r
- $query.= " WHERE channel_name like '" . $channel_name . "%' AND news_channels.id_category = " . $id_category;\r
- } elsif ($channel_name ne '') {\r
- $query.= " WHERE channel_name like '" . $channel_name . "%'";\r
- } elsif ($id_category ne '') {\r
- $query.= " WHERE news_channels.id_category = " . $id_category;\r
- } elsif ($unclassified) {\r
- $query.= " WHERE news_channels.id_category IS NULL ";\r
- }\r
- my $sth = $dbh->prepare($query);\r
- $sth->execute();\r
- while (my $row = $sth->fetchrow_hashref) {\r
- push @channels, $row;\r
- }\r
- $sth->finish;\r
- return (scalar(@channels), @channels);\r
+ my ($channel_name, $id_category, $unclassified) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my @channels;\r
+ my $query = "SELECT * FROM news_channels LEFT JOIN news_channels_categories ON news_channels.id_category = news_channels_categories.id_category";\r
+ if ( ($channel_name ne '') && ($id_category ne '') ) {\r
+ $query.= " WHERE channel_name like '" . $channel_name . "%' AND news_channels.id_category = " . $id_category;\r
+ } elsif ($channel_name ne '') {\r
+ $query.= " WHERE channel_name like '" . $channel_name . "%'";\r
+ } elsif ($id_category ne '') {\r
+ $query.= " WHERE news_channels.id_category = " . $id_category;\r
+ } elsif ($unclassified) {\r
+ $query.= " WHERE news_channels.id_category IS NULL ";\r
+ }\r
+ my $sth = $dbh->prepare($query);\r
+ $sth->execute();\r
+ while (my $row = $sth->fetchrow_hashref) {\r
+ push @channels, $row;\r
+ }\r
+ $sth->finish;\r
+ return (scalar(@channels), @channels);\r
}\r
\r
=item news_channels_by_category\r
=cut\r
\r
sub news_channels_by_category {\r
- \r
- my ($categories_count, @results) = &news_channels_categories();\r
- foreach my $row (@results) {\r
-\r
- my ($channels_count, @channels) = &news_channels('', $row->{'id_category'});\r
- $row->{'channels_count'} = $channels_count;\r
- $row->{'channels'} = \@channels;\r
- }\r
-\r
- my ($channels_count, @channels) = &news_channels('', '', 1);\r
- my %row;\r
- $row{'id_category'} = -1;\r
- $row{'unclassified'} = 1;\r
- $row{'channels_count'} = $channels_count;\r
- $row{'channels'} = \@channels;\r
- push @results, \%row;\r
-\r
- return (scalar(@results), @results);\r
+ \r
+ my ($categories_count, @results) = &news_channels_categories();\r
+ foreach my $row (@results) {\r
+\r
+ my ($channels_count, @channels) = &news_channels('', $row->{'id_category'});\r
+ $row->{'channels_count'} = $channels_count;\r
+ $row->{'channels'} = \@channels;\r
+ }\r
+\r
+ my ($channels_count, @channels) = &news_channels('', '', 1);\r
+ my %row;\r
+ $row{'id_category'} = -1;\r
+ $row{'unclassified'} = 1;\r
+ $row{'channels_count'} = $channels_count;\r
+ $row{'channels'} = \@channels;\r
+ push @results, \%row;\r
+\r
+ return (scalar(@results), @results);\r
}\r
\r
sub get_new_channel {\r
- my ($id) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("SELECT * FROM news_channels WHERE id = ?");\r
- $sth->execute($id);\r
- my $channel = $sth->fetchrow_hashref;\r
- $sth->finish;\r
- return $channel;\r
+ my ($id) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("SELECT * FROM news_channels WHERE id = ?");\r
+ $sth->execute($id);\r
+ my $channel = $sth->fetchrow_hashref;\r
+ $sth->finish;\r
+ return $channel;\r
}\r
\r
sub del_channels {\r
- my ($ids) = @_;\r
- if ($ids ne '') {\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("DELETE FROM news_channels WHERE id IN ($ids) ");\r
- $sth->execute();\r
- $sth->finish;\r
- return $ids;\r
- }\r
- return 0;\r
+ my ($ids) = @_;\r
+ if ($ids ne '') {\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("DELETE FROM news_channels WHERE id IN ($ids) ");\r
+ $sth->execute();\r
+ $sth->finish;\r
+ return $ids;\r
+ }\r
+ return 0;\r
}\r
\r
sub add_channel {\r
- my ($name, $url, $id_category, $notes) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("INSERT INTO news_channels (channel_name, url, id_category, notes) VALUES (?,?,?,?)");\r
- $sth->execute($name, $url, $id_category, $notes);\r
- $sth->finish;\r
- return 1;\r
+ my ($name, $url, $id_category, $notes) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("INSERT INTO news_channels (channel_name, url, id_category, notes) VALUES (?,?,?,?)");\r
+ $sth->execute($name, $url, $id_category, $notes);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
sub update_channel {\r
- my ($id, $name, $url, $id_category, $notes) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("UPDATE news_channels SET channel_name = ?, url = ?, id_category = ?, notes = ? WHERE id = ?");\r
- $sth->execute($name, $url, $id_category, $notes, $id);\r
- $sth->finish;\r
- return 1;\r
+ my ($id, $name, $url, $id_category, $notes) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("UPDATE news_channels SET channel_name = ?, url = ?, id_category = ?, notes = ? WHERE id = ?");\r
+ $sth->execute($name, $url, $id_category, $notes, $id);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
sub news_channels_categories {\r
- my $dbh = C4::Context->dbh;\r
- my @categories;\r
- my $query = "SELECT * FROM news_channels_categories";\r
- my $sth = $dbh->prepare($query);\r
- $sth->execute();\r
- while (my $row = $sth->fetchrow_hashref) {\r
- push @categories, $row;\r
- }\r
- $sth->finish;\r
- return (scalar(@categories), @categories);\r
+ my $dbh = C4::Context->dbh;\r
+ my @categories;\r
+ my $query = "SELECT * FROM news_channels_categories";\r
+ my $sth = $dbh->prepare($query);\r
+ $sth->execute();\r
+ while (my $row = $sth->fetchrow_hashref) {\r
+ push @categories, $row;\r
+ }\r
+ $sth->finish;\r
+ return (scalar(@categories), @categories);\r
\r
}\r
\r
sub get_new_channel_category {\r
- my ($id) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("SELECT * FROM news_channels_categories WHERE id_category = ?");\r
- $sth->execute($id);\r
- my $category = $sth->fetchrow_hashref;\r
- $sth->finish;\r
- return $category;\r
+ my ($id) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("SELECT * FROM news_channels_categories WHERE id_category = ?");\r
+ $sth->execute($id);\r
+ my $category = $sth->fetchrow_hashref;\r
+ $sth->finish;\r
+ return $category;\r
}\r
\r
sub del_channels_categories {\r
- my ($ids) = @_;\r
- if ($ids ne '') {\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("UPDATE news_channels SET id_category = NULL WHERE id_category IN ($ids) "); \r
- $sth->execute();\r
- $sth = $dbh->prepare("DELETE FROM news_channels_categories WHERE id_category IN ($ids) ");\r
- $sth->execute();\r
- $sth->finish;\r
- return $ids;\r
- }\r
- return 0;\r
+ my ($ids) = @_;\r
+ if ($ids ne '') {\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("UPDATE news_channels SET id_category = NULL WHERE id_category IN ($ids) ");\r
+ $sth->execute();\r
+ $sth = $dbh->prepare("DELETE FROM news_channels_categories WHERE id_category IN ($ids) ");\r
+ $sth->execute();\r
+ $sth->finish;\r
+ return $ids;\r
+ }\r
+ return 0;\r
}\r
\r
sub add_channel_category {\r
- my ($name) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("INSERT INTO news_channels_categories (category_name) VALUES (?)");\r
- $sth->execute($name);\r
- $sth->finish;\r
- return 1;\r
+ my ($name) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("INSERT INTO news_channels_categories (category_name) VALUES (?)");\r
+ $sth->execute($name);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
sub update_channel_category {\r
- my ($id, $name) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("UPDATE news_channels_categories SET category_name = ? WHERE id_category = ?");\r
- $sth->execute($name, $id);\r
- $sth->finish;\r
- return 1;\r
+ my ($id, $name) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("UPDATE news_channels_categories SET category_name = ? WHERE id_category = ?");\r
+ $sth->execute($name, $id);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
-\r
sub add_opac_new {\r
- my ($title, $new, $lang) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang) VALUES (?,?,?)");\r
- $sth->execute($title, $new, $lang);\r
- $sth->finish;\r
- return 1;\r
+ my ($title, $new, $lang, $expirationdate, $number) = @_;
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("INSERT INTO opac_news (title, new, lang, expirationdate, number) VALUES (?,?,?,?,?)");\r
+ $sth->execute($title, $new, $lang, $expirationdate, $number);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
sub upd_opac_new {\r
- my ($idnew, $title, $new, $lang) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("UPDATE opac_news SET title = ?, new = ?, lang = ? WHERE idnew = ?");\r
- $sth->execute($title, $new, $lang, $idnew);\r
- $sth->finish;\r
- return 1;\r
+ my ($idnew, $title, $new, $lang, $expirationdate, $number) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("
+ UPDATE opac_news SET
+ title = ?,
+ new = ?,
+ lang = ?,
+ expirationdate = ?,
+ number = ?
+ WHERE idnew = ?
+ ");\r
+ $sth->execute($title, $new, $lang, $expirationdate,$number,$idnew);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
sub del_opac_new {\r
- my ($ids) = @_;\r
- if ($ids) {\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)");\r
- $sth->execute();\r
- $sth->finish;\r
- return 1;\r
- } else {\r
- return 0;\r
- }\r
+ my ($ids) = @_;\r
+ if ($ids) {\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("DELETE FROM opac_news WHERE idnew IN ($ids)");\r
+ $sth->execute();\r
+ $sth->finish;\r
+ return 1;\r
+ } else {\r
+ return 0;\r
+ }\r
}\r
\r
sub get_opac_new {\r
- my ($idnew) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("SELECT * FROM opac_news WHERE idnew = ?");\r
- $sth->execute($idnew);\r
- my $data = $sth->fetchrow_hashref;\r
- $data->{$data->{'lang'}} = 1;\r
- $sth->finish;\r
- return $data;\r
+ my ($idnew) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("SELECT * FROM opac_news WHERE idnew = ?");\r
+ $sth->execute($idnew);\r
+ my $data = $sth->fetchrow_hashref;\r
+ $data->{$data->{'lang'}} = 1;\r
+ $sth->finish;\r
+ return $data;\r
}\r
\r
sub get_opac_news {\r
- my ($limit, $lang) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $query = "SELECT *, DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate FROM opac_news";\r
- if ($lang) {\r
- $query.= " WHERE lang = '" .$lang ."' ";\r
- }\r
- $query.= " ORDER BY timestamp DESC ";\r
- #if ($limit) {\r
- # $query.= "LIMIT 0, " . $limit;\r
- #}\r
- my $sth = $dbh->prepare($query);\r
- $sth->execute();\r
- my @opac_news;\r
- my $count = 0;\r
- while (my $row = $sth->fetchrow_hashref) {\r
- if ((($limit) && ($count < $limit)) || (!$limit)) {\r
- $row->{'newdate'} = format_date($row->{'newdate'});\r
- push @opac_news, $row; \r
- }\r
- $count++;\r
- }\r
- return ($count, \@opac_news);\r
+ my ($limit, $lang) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $query = "SELECT *, DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate FROM opac_news";\r
+ if ($lang) {\r
+ $query.= " WHERE lang = '" .$lang ."' ";\r
+ }\r
+ $query.= " ORDER BY timestamp DESC ";\r
+ #if ($limit) {\r
+ # $query.= "LIMIT 0, " . $limit;\r
+ #}\r
+ my $sth = $dbh->prepare($query);\r
+ $sth->execute();\r
+ my @opac_news;\r
+ my $count = 0;\r
+ while (my $row = $sth->fetchrow_hashref) {\r
+ if ((($limit) && ($count < $limit)) || (!$limit)) {\r
+ $row->{'newdate'} = format_date($row->{'newdate'});\r
+ push @opac_news, $row;\r
+ }\r
+ $count++;\r
+ }\r
+ return ($count, \@opac_news);\r
}\r
+
+=head2 GetNewsToDisplay
+
+ $news = &GetNewsToDisplay($lang);
+ C<$news> is a ref to an array which containts
+ all news with expirationdate > today or expirationdate is null.
+
+=cut
+
+sub GetNewsToDisplay {
+ my $lang = shift;
+ my $dbh = C4::Context->dbh;\r
+ my $query = "
+ SELECT *,DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate
+ FROM opac_news
+ WHERE (
+ expirationdate > CURRENT_DATE()
+ OR expirationdate IS NULL
+ OR expirationdate = '00-00-0000'
+ )
+ AND lang = ?
+ ORDER BY number
+ ";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($lang);
+ my @results;
+ while ( my $row = $sth->fetchrow_hashref ){
+ push @results, $row;
+ }
+ return \@results;
+}
\r
### get electronic databases\r
\r
sub add_opac_electronic {\r
- my ($title, $edata, $lang,$image,$href,$section) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("INSERT INTO opac_electronic (title, edata, lang,image,href,section) VALUES (?,?,?,?,?,?)");\r
- $sth->execute($title, $edata, $lang,$image,$href,$section);\r
- $sth->finish;\r
- return 1;\r
+ my ($title, $edata, $lang,$image,$href,$section) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("INSERT INTO opac_electronic (title, edata, lang,image,href,section) VALUES (?,?,?,?,?,?)");\r
+ $sth->execute($title, $edata, $lang,$image,$href,$section);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
sub upd_opac_electronic {\r
- my ($idelectronic, $title, $edata, $lang, $image, $href,$section) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("UPDATE opac_electronic SET title = ?, edata = ?, lang = ? , image=?, href=? ,section=? WHERE idelectronic = ?");\r
- $sth->execute($title, $edata, $lang, $image,$href ,$section, $idelectronic);\r
- $sth->finish;\r
- return 1;\r
+ my ($idelectronic, $title, $edata, $lang, $image, $href,$section) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("UPDATE opac_electronic SET title = ?, edata = ?, lang = ? , image=?, href=? ,section=? WHERE idelectronic = ?");\r
+ $sth->execute($title, $edata, $lang, $image,$href ,$section, $idelectronic);\r
+ $sth->finish;\r
+ return 1;\r
}\r
\r
sub del_opac_electronic {\r
- my ($ids) = @_;\r
- if ($ids) {\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("DELETE FROM opac_electronic WHERE idelectronic IN ($ids)");\r
- $sth->execute();\r
- $sth->finish;\r
- return 1;\r
- } else {\r
- return 0;\r
- }\r
+ my ($ids) = @_;\r
+ if ($ids) {\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("DELETE FROM opac_electronic WHERE idelectronic IN ($ids)");\r
+ $sth->execute();\r
+ $sth->finish;\r
+ return 1;\r
+ } else {\r
+ return 0;\r
+ }\r
}\r
\r
sub get_opac_electronic {\r
- my ($idelectronic) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $sth = $dbh->prepare("SELECT * FROM opac_electronic WHERE idelectronic = ?");\r
- $sth->execute($idelectronic);\r
- my $data = $sth->fetchrow_hashref;\r
- $data->{$data->{'lang'}} = 1;\r
- $data->{$data->{'section'}} = 1;\r
- $sth->finish;\r
- return $data;\r
+ my ($idelectronic) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $sth = $dbh->prepare("SELECT * FROM opac_electronic WHERE idelectronic = ?");\r
+ $sth->execute($idelectronic);\r
+ my $data = $sth->fetchrow_hashref;\r
+ $data->{$data->{'lang'}} = 1;\r
+ $data->{$data->{'section'}} = 1;\r
+ $sth->finish;\r
+ return $data;\r
}\r
\r
sub get_opac_electronics {\r
- my ($section, $lang) = @_;\r
- my $dbh = C4::Context->dbh;\r
- my $query = "SELECT *, DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate FROM opac_electronic";\r
- if ($lang) {\r
- $query.= " WHERE lang = '" .$lang ."' ";\r
- }\r
- if ($section) {\r
- $query.= " and section= '" . $section."' ";\r
- }\r
- $query.= " ORDER BY title ";\r
- \r
- my $sth = $dbh->prepare($query);\r
- $sth->execute();\r
- my @opac_electronic;\r
- my $count = 0;\r
- while (my $row = $sth->fetchrow_hashref) {\r
- push @opac_electronic, $row; \r
-\r
- \r
- $count++;\r
- }\r
-\r
- return ($count,\@opac_electronic);\r
+ my ($section, $lang) = @_;\r
+ my $dbh = C4::Context->dbh;\r
+ my $query = "SELECT *, DATE_FORMAT(timestamp, '%d/%m/%Y') AS newdate FROM opac_electronic";\r
+ if ($lang) {\r
+ $query.= " WHERE lang = '" .$lang ."' ";\r
+ }\r
+ if ($section) {\r
+ $query.= " and section= '" . $section."' ";\r
+ }\r
+ $query.= " ORDER BY title ";\r
+ \r
+ my $sth = $dbh->prepare($query);\r
+ $sth->execute();\r
+ my @opac_electronic;\r
+ my $count = 0;\r
+ while (my $row = $sth->fetchrow_hashref) {\r
+ push @opac_electronic, $row;\r
+\r
+ \r
+ $count++;\r
+ }\r
+\r
+ return ($count,\@opac_electronic);\r
}\r
END { } # module clean-up code here (global destructor)\r
\r