Permalink
Browse files

Ver. 0.1 commit

  • Loading branch information...
0 parents commit 63c4ab6ade8349187ca79241064dabbd54dffbef @alenkovich alenkovich committed Jan 15, 2011
Showing with 113 additions and 0 deletions.
  1. +19 −0 README
  2. +7 −0 conf/config.yml.example
  3. +87 −0 koha-recent.pl
19 README
@@ -0,0 +1,19 @@
+Version: 0.1
+
+Description:
+Script generates web page or html table containing recently acquired titles from your Koha database.
+It fetches last X records and shows randomly Y of X .. hope you understand :D.
+It will work only if you use acquisition module in Koha!
+
+Installation:
+As you already got the files, just rename ./conf/config.yml.example to ./conf/config.yml and edit this file according to your setup
+
+Usage:
+koha-recent [number_of_retrived_records] [number_shown] [table|html] [blank|parent|self]
+
+
+Example:
+# cd /usr/local/src/Koha-recently-acquired-books && koha-recent.pl 10 3 html blank > /var/www/koha-static/recent.html
+
+Hint:
+Cron is your friend.
7 conf/config.yml.example
@@ -0,0 +1,7 @@
+---
+dbHost: localhost
+dbName: koha
+dbUser: kohauser
+dbPass: kohapass
+kohaOpacUrl: http://www.example.org/cgi-bin/koha
+coverBgUrl: http://www.example.org/koha-static/recent-home/cover_bg.png
87 koha-recent.pl
@@ -0,0 +1,87 @@
+#!/usr/bin/perl
+
+use strict;
+use DBI();
+use Business::ISBN;
+use YAML::XS;
+use Data::Dumper;
+use File::Basename;
+
+my $config = do{local(@ARGV,$/)="conf/config.yml";<>};
+my $conf = Load $config;
+
+my $sqlNumGet = $ARGV[0];
+my $sqlNumShow = $ARGV[1];
+my $layout = $ARGV[2];
+my $target = $ARGV[3];
+
+my $dbh = DBI->connect("DBI:mysql:database=$conf->{'dbName'};host=$conf->{'dbHost'}",
+ $conf->{'dbUser'}, $conf->{'dbPass'},
+ {'RaiseError' => 1});
+
+my $isbn;
+my $isbn10;
+my $amazonImg;
+
+my $sqlQuery = "select * from (select aqorders.biblionumber as bnum, biblio.title, biblio.author, biblioitems.isbn from aqorders,biblio,biblioitems where biblioitems.biblionumber=aqorders.biblionumber and biblio.biblionumber=aqorders.biblionumber order by datereceived desc limit 25) as recent order by rand() limit " . $sqlNumShow . ";";
+
+my $uni = $dbh->prepare("set names utf8;");
+my $sth = $dbh->prepare($sqlQuery);
+$uni->execute();
+$sth->execute();
+
+
+if ($layout eq 'html') {
+print <<HEADER;
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ </head>
+<body>
+HEADER
+}
+
+print <<CSS;
+<style type="text/css">
+td { font-family: Arial, Verdana; font-size: 12px; }
+p.cover { height: 185px; width: 150px; background: url($conf->{'coverBgUrl'}) no-repeat center; align: center; }
+</style>
+CSS
+print "\t<table width=\"100%\">\n\t\t<tr>\n\t\t\t";
+
+while (my $ref = $sth->fetchrow_hashref()) {
+ if (defined($ref->{'isbn'})) {
+ $isbn = Business::ISBN->new($ref->{'isbn'});
+ $isbn = $isbn->as_isbn10;
+ $isbn10 = $isbn->isbn;
+ $amazonImg = '<img src="http://images.amazon.com/images/P/'. $isbn10 .'.01._THUMBZZZ_PB_PU_PU0_.jpg" alt="" border="0" />';
+ } else {
+ $isbn10 = '';
+ $amazonImg = '';
+ }
+ $ref->{'title'} =~ s/\ (:|\/)$//g;
+print <<MAIN
+ <td valign="top" width="20" align="center" border="0">
+ <p class="cover"><a border="0" target="_$target" href="$conf->{'kohaOpacUrl'}/opac-detail.pl?biblionumber=$ref->{'bnum'}">$amazonImg</a></p>
+ <br />
+ <a border="0" target="_$target" href="$conf->{'kohaOpacUrl'}/opac-detail.pl?biblionumber=$ref->{'bnum'}"><b>$ref->{'title'}</b></a>
+ <br />
+ $ref->{'author'}
+ </td>
+MAIN
+
+}
+
+print "\n\t\t</tr>\n\t</table>\n";
+
+if ($layout eq 'html') {
+print <<FOOTER;
+</body>
+</html>
+FOOTER
+}
+
+$sth->finish();
+
+# Disconnect from the database.
+$dbh->disconnect();

0 comments on commit 63c4ab6

Please sign in to comment.