Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ver. 0.1 commit

  • Loading branch information...
commit 63c4ab6ade8349187ca79241064dabbd54dffbef 0 parents
Alen Vodopijevec authored January 15, 2011
19  README
... ...
@@ -0,0 +1,19 @@
  1
+Version: 0.1
  2
+
  3
+Description: 
  4
+Script generates web page or html table containing recently acquired titles from your Koha database. 
  5
+It fetches last X records and shows randomly Y of X .. hope you understand :D. 
  6
+It will work only if you use acquisition module in Koha!
  7
+
  8
+Installation:
  9
+As you already got the files, just rename ./conf/config.yml.example to ./conf/config.yml and edit this file according to your setup
  10
+
  11
+Usage:
  12
+koha-recent [number_of_retrived_records] [number_shown] [table|html] [blank|parent|self]
  13
+
  14
+
  15
+Example:
  16
+# cd /usr/local/src/Koha-recently-acquired-books && koha-recent.pl 10 3 html blank > /var/www/koha-static/recent.html 
  17
+
  18
+Hint:
  19
+Cron is your friend.
7  conf/config.yml.example
... ...
@@ -0,0 +1,7 @@
  1
+---
  2
+dbHost: localhost 
  3
+dbName: koha
  4
+dbUser: kohauser
  5
+dbPass: kohapass
  6
+kohaOpacUrl: http://www.example.org/cgi-bin/koha
  7
+coverBgUrl: http://www.example.org/koha-static/recent-home/cover_bg.png 
87  koha-recent.pl
... ...
@@ -0,0 +1,87 @@
  1
+#!/usr/bin/perl
  2
+
  3
+use strict;
  4
+use DBI();
  5
+use Business::ISBN;
  6
+use YAML::XS;
  7
+use Data::Dumper;
  8
+use File::Basename;
  9
+
  10
+my $config = do{local(@ARGV,$/)="conf/config.yml";<>};
  11
+my $conf = Load $config;
  12
+
  13
+my $sqlNumGet = $ARGV[0];
  14
+my $sqlNumShow = $ARGV[1];
  15
+my $layout = $ARGV[2];
  16
+my $target = $ARGV[3];
  17
+
  18
+my $dbh = DBI->connect("DBI:mysql:database=$conf->{'dbName'};host=$conf->{'dbHost'}",
  19
+                       $conf->{'dbUser'}, $conf->{'dbPass'},
  20
+                       {'RaiseError' => 1});
  21
+
  22
+my $isbn;
  23
+my $isbn10;
  24
+my $amazonImg;
  25
+
  26
+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 . ";";
  27
+
  28
+my $uni = $dbh->prepare("set names utf8;");
  29
+my $sth = $dbh->prepare($sqlQuery);
  30
+$uni->execute();
  31
+$sth->execute();
  32
+
  33
+
  34
+if ($layout eq 'html') {
  35
+print <<HEADER;
  36
+<html>
  37
+  <head>
  38
+	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  39
+  </head>
  40
+<body>
  41
+HEADER
  42
+}
  43
+
  44
+print <<CSS;
  45
+<style type="text/css">
  46
+td { font-family: Arial, Verdana; font-size: 12px; }
  47
+p.cover { height: 185px; width: 150px; background: url($conf->{'coverBgUrl'}) no-repeat center; align: center; }
  48
+</style>
  49
+CSS
  50
+print "\t<table width=\"100%\">\n\t\t<tr>\n\t\t\t";
  51
+
  52
+while (my $ref = $sth->fetchrow_hashref()) {
  53
+  if (defined($ref->{'isbn'})) {
  54
+    $isbn = Business::ISBN->new($ref->{'isbn'});
  55
+    $isbn = $isbn->as_isbn10;
  56
+    $isbn10 = $isbn->isbn;
  57
+    $amazonImg = '<img src="http://images.amazon.com/images/P/'. $isbn10 .'.01._THUMBZZZ_PB_PU_PU0_.jpg" alt="" border="0" />'; 
  58
+  } else {
  59
+    $isbn10 = '';
  60
+    $amazonImg = '';
  61
+  }
  62
+  $ref->{'title'} =~ s/\ (:|\/)$//g;
  63
+print <<MAIN
  64
+			<td valign="top" width="20" align="center" border="0">
  65
+				<p class="cover"><a border="0" target="_$target" href="$conf->{'kohaOpacUrl'}/opac-detail.pl?biblionumber=$ref->{'bnum'}">$amazonImg</a></p>
  66
+				<br />
  67
+				<a border="0" target="_$target" href="$conf->{'kohaOpacUrl'}/opac-detail.pl?biblionumber=$ref->{'bnum'}"><b>$ref->{'title'}</b></a>
  68
+				<br />
  69
+				$ref->{'author'}
  70
+			</td>
  71
+MAIN
  72
+
  73
+}
  74
+
  75
+print "\n\t\t</tr>\n\t</table>\n";
  76
+
  77
+if ($layout eq 'html') {
  78
+print <<FOOTER;
  79
+</body>
  80
+</html>
  81
+FOOTER
  82
+}
  83
+
  84
+$sth->finish();
  85
+
  86
+# Disconnect from the database.
  87
+$dbh->disconnect();

0 notes on commit 63c4ab6

Please sign in to comment.
Something went wrong with that request. Please try again.