[Koha-cvs] koha acqui.simple/addbiblio.pl C4/Koha.pm koha-... [rel_2_2]

Henri-Damien LAURENT laurenthdl at alinto.com
Fri Nov 3 11:56:59 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_2_2
Changes by:	Henri-Damien LAURENT <hdl>	06/11/03 10:56:59

Modified files:
	acqui.simple   : addbiblio.pl 
	C4             : Koha.pm 
	koha-tmpl/intranet-tmpl/default/en/z3950: searchresult.tmpl 
	z3950          : search.pl 

Log message:
	Fixing some encoding problems with z3950 and fixing latest commit for z3950 serach and results.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/acqui.simple/addbiblio.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.52.2.57&r2=1.52.2.58
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Koha.pm?cvsroot=koha&only_with_tag=rel_2_2&r1=1.22.2.4&r2=1.22.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/default/en/z3950/searchresult.tmpl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.4.2.3&r2=1.4.2.4
http://cvs.savannah.gnu.org/viewcvs/koha/z3950/search.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.3.2.9&r2=1.3.2.10

Patches:
Index: acqui.simple/addbiblio.pl
===================================================================
RCS file: /sources/koha/koha/acqui.simple/Attic/addbiblio.pl,v
retrieving revision 1.52.2.57
retrieving revision 1.52.2.58
diff -u -b -r1.52.2.57 -r1.52.2.58
--- acqui.simple/addbiblio.pl	13 Oct 2006 08:33:34 -0000	1.52.2.57
+++ acqui.simple/addbiblio.pl	3 Nov 2006 10:56:59 -0000	1.52.2.58
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: addbiblio.pl,v 1.52.2.57 2006/10/13 08:33:34 tipaul Exp $
+# $Id: addbiblio.pl,v 1.52.2.58 2006/11/03 10:56:59 hdl Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -94,7 +94,7 @@
 	$sth->execute($id);
 	my ($file,$marc,$encoding) = $sth->fetchrow;
 	if ($marc) {
-		my $record = MARC::File::USMARC::decode($marc);
+		my $record = fixEncoding($marc);
 		if (ref($record) eq undef) {
 			return -1;
 		} else {

Index: C4/Koha.pm
===================================================================
RCS file: /sources/koha/koha/C4/Koha.pm,v
retrieving revision 1.22.2.4
retrieving revision 1.22.2.5
diff -u -b -r1.22.2.4 -r1.22.2.5
--- C4/Koha.pm	7 Feb 2006 15:33:35 -0000	1.22.2.4
+++ C4/Koha.pm	3 Nov 2006 10:56:59 -0000	1.22.2.5
@@ -52,6 +52,7 @@
 @ISA = qw(Exporter);
 @EXPORT = qw(&slashifyDate
 			&fixEthnicity
+            &fixEncoding
 			&borrowercategories
 			&ethnicitycategories
 			&subfield_is_koha_internal_p
@@ -652,7 +653,54 @@
     return @themes;
 }
 
+=item fixEncoding
 
+  $marcrecord = &fixEncoding($marcblob);
+
+Returns a well encoded marcrecord.
+
+=cut
+sub fixEncoding {
+  my $marc=shift;
+  my $record = MARC::Record->new_from_usmarc($marc);
+  if (C4::Context->preference("MARCFLAVOUR") eq "UNIMARC"){
+    use Encode::Guess;
+    my $targetcharset="utf8" if (C4::Context->preference("TemplateEncoding") eq "utf-8");
+    $targetcharset="latin1" if (C4::Context->preference("TemplateEncoding") eq "iso-8859-1");
+    my $decoder = guess_encoding($marc, qw/utf8 latin1/);
+    die $decoder unless ref($decoder);
+    warn "decodage : ".$decoder->name;
+    warn "decodage cible : ".$targetcharset;
+    my $newRecord=MARC::Record->new();
+    foreach my $field ($record->fields()){
+      if ($field->tag()<'010'){
+        $newRecord->insert_grouped_field($field);
+      } else {
+        my $newField;
+        my $createdfield=0;
+        foreach my $subfield ($field->subfields()){
+          if ($createdfield){
+            if (($newField->tag eq '100')) {
+              substr($subfield->[1],26,2,"0103") if ($targetcharset eq "latin1");
+              substr($subfield->[1],26,4,"5050") if ($targetcharset eq "utf8");
+            }
+            map {C4::Biblio::char_decode($_,"UNIMARC");Encode::from_to($_,$decoder->name,$targetcharset);$_=~tr#\r##} @$subfield;
+            $newField->add_subfields($subfield->[0]=>$subfield->[1]);
+          } else {
+            map {C4::Biblio::char_decode($_,"UNIMARC");Encode::from_to($_,$decoder->name,$targetcharset);$_=~tr#\r##} @$subfield;
+            $newField=MARC::Field->new($field->tag(),$field->indicator(1),$field->indicator(2),$subfield->[0]=>$subfield->[1]);
+            $createdfield=1;
+          }
+        }
+        $newRecord->insert_grouped_field($newField);
+      }
+    }
+    warn $newRecord->as_formatted(); 
+    return $newRecord;
+  } else {
+    return $record;
+  }
+}
 1;
 __END__
 

Index: koha-tmpl/intranet-tmpl/default/en/z3950/searchresult.tmpl
===================================================================
RCS file: /sources/koha/koha/koha-tmpl/intranet-tmpl/default/en/z3950/Attic/searchresult.tmpl,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -b -r1.4.2.3 -r1.4.2.4
--- koha-tmpl/intranet-tmpl/default/en/z3950/searchresult.tmpl	29 Jun 2006 19:17:02 -0000	1.4.2.3
+++ koha-tmpl/intranet-tmpl/default/en/z3950/searchresult.tmpl	3 Nov 2006 10:56:59 -0000	1.4.2.4
@@ -1,58 +1,81 @@
-<HTML>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
+<title>Z39.50 Search Results</title>
 	<!-- TMPL_IF NAME="TemplateEncoding" --><meta http-equiv="Content-Type" content="text/html; charset=<!-- TMPL_VAR NAME="TemplateEncoding" -->"><!-- TMPL_ELSE --><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><!-- /TMPL_IF -->
-	<!-- TMPL_IF NAME="refresh" -->
-		<meta http-equiv="refresh" content="2; url=<!-- TMPL_VAR NAME="refresh" -->">
-	<!-- /TMPL_IF -->
-	<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR name="themelang" -->/includes/common-style.css">
-	<style type="text/css">
-	.catalogue {
-		background-color:#ad11ad;
-		color:#FFFFFF;
-		background-image:none;
-		text-decoration: normal;
-		}
-	a.catalogue:hover {
-		background-color: #ad11ad;
-		color: #FFFFFF;
-		text-decoration: none;
-		}
-	</style>
+<link rel="shortcut icon" href="/intranet-tmpl/npl/en/includes/favicon.ico" type="image/x-icon" />
+<style type="text/css"> 
+	<!-- TMPL_IF NAME="intranetstylesheet" -->@import url(<!-- TMPL_VAR NAME='themelang' -->/includes/<!-- TMPL_VAR NAME="intranetstylesheet" -->);<!-- TMPL_ELSE -->@import url(<!-- TMPL_VAR NAME='themelang' -->/includes/intranet.css);<!-- /TMPL_IF -->
+	<!-- TMPL_IF NAME="intranetcolorstylesheet" -->@import url(<!-- TMPL_VAR NAME='themelang' -->/includes/<!-- TMPL_VAR NAME="intranetcolorstylesheet" -->);<!-- /TMPL_IF -->
+</style>
 </head>
+
 <body>
-<div id="mainbloc">
-	<h2 class="catalogue">Z3950 Search Results</h2>
+<div id="main-compact">
+<table>
+<!-- TMPL_IF name="opsearch" -->
+<h3>Select Search Libraries</h3>
+
+
+<form method="post" action="search.pl" name="f">
+
+<input type="hidden" name="op" id="op" value="do_search" />
+<input type="hidden" name="title" value=<!-- TMPL_VAR NAME="title" --> />
+<input type="hidden" name="author" value=<!-- TMPL_VAR NAME="author" --> />
+<input type="hidden" name="isbn" value=<!-- TMPL_VAR NAME="isbn" --> />
+<input type="hidden" name="issn" value=<!-- TMPL_VAR NAME="issn" --> />
+<input type="hidden" name="oldbiblionumber" value="<!-- TMPL_VAR NAME="oldbiblionumber" -->" />
+
+<tr>
+		<th>Library</th>
+		<th>Select</th>
+</tr>
+<!-- TMPL_LOOP name="serverloop" -->
+		<tr bgcolor="<!-- TMPL_VAR NAME="toggle" -->">
+			<td><!-- TMPL_VAR NAME="server" --></td>
 	
-	<!-- TMPL_IF NAME="breeding_loop" -->
-		<table>
+			<td> <input type="checkbox" name="id" value=<!-- TMPL_VAR NAME="id" --> <!-- TMPL_IF name="checked" -->checked="1"<!-- /TMPL_IF --> ></td>
+	</tr>
+	<!-- /TMPL_LOOP -->
+	<tr><td><input type="submit"  class="submit" value="Search internet" onclick="cursor :'wait'";
+	 /></td></tr></form>
+<!-- TMPL_ELSE -->
+
+<caption>Bibliographic Records Found in <!-- TMPL_VAR NAME="server" --></caption>
 			<tr>
-				<th class="catalogue">Title</th>
-				<th class="catalogue">Author</th>
-				<th class="catalogue">ISBN</th>
-				<th class="catalogue">coming from</th>
-				<th class="catalogue">&nbsp;</th>
-				<th class="catalogue">&nbsp;</th>
+		<th>Title</th>
+		<th>Author</th>
+		<th>ISBN</th>
+		<th>&nbsp;</th>
+		<th>&nbsp;</th>
 			</tr>
-				<!-- TMPL_LOOP NAME="breeding_loop" -->
-					<!-- TMPL_IF NAME="toggle" --><tr class="hilighted"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
-						<td><!-- TMPL_VAR NAME="title" --></td>
+	<!-- TMPL_IF name="breeding_loop" -->
+	<!-- TMPL_LOOP name="breeding_loop" --> 
+		<tr bgcolor="<!-- TMPL_VAR NAME="toggle" -->">
+			<td><!-- TMPL_VAR NAME="title" --></a>
 						<td><!-- TMPL_VAR NAME="author" --></td>
 						<td><!-- TMPL_VAR NAME="isbn" --></td>
-						<td><!-- TMPL_VAR NAME="file" --></td>
-						<td><a href="javascript:Import(<!-- TMPL_VAR NAME="id" -->)">Import this biblio</a></td>
+			<td><a href="javascript:Import(<!-- TMPL_VAR NAME="id" -->,<!-- TMPL_VAR NAME="oldbiblionumber" -->)">Import</a></td> 
+		
 					</tr>
 				<!-- /TMPL_LOOP -->
-		</table>
 	<!-- TMPL_ELSE -->
-				<p>Nothing found</p>
+		<tr><td colspan="6">Nothing found</td></tr>
 	<!-- /TMPL_IF -->
-	<!-- TMPL_IF NAME="numberpending" --><h1 class="catalogue">Still <!-- TMPL_VAR NAME="numberpending" --> requests to go</h1><!-- /TMPL_IF -->
-	<script language="javascript" type="text/javascript">
-		function Import(GetThisOne) {
-			opener.document.location= "../acqui.simple/addbiblio.pl?z3950=1&oldbiblionumber=<!-- TMPL_VAR NAME="oldbiblionumber" -->&breedingid="+GetThisOne;
+</table>
+<!-- /TMPL_IF -->
+
+</div>
+<!-- TMPL_IF name="numberpending" --><h3 align="center">Still <!-- TMPL_VAR NAME="numberpending" --> servers to search</h3><!-- /TMPL_IF -->
+<script language="JavaScript" type="text/javascript">
+	function Import(GetThisOne,biblionumber) {
+		opener.document.location= "../acqui.simple/addbiblio.pl?oldbiblionumber="+biblionumber+"&z3950=1&breedingid="+GetThisOne;
 			self.close();
 			return false;
 		}
-	</script>
+</script>
 </div>
-<!-- TMPL_INCLUDE NAME="acquisitions-bottom.inc" -->
+</body>
+</html>
+

Index: z3950/search.pl
===================================================================
RCS file: /sources/koha/koha/z3950/search.pl,v
retrieving revision 1.3.2.9
retrieving revision 1.3.2.10
diff -u -b -r1.3.2.9 -r1.3.2.10
--- z3950/search.pl	3 Nov 2006 03:29:30 -0000	1.3.2.9
+++ z3950/search.pl	3 Nov 2006 10:56:59 -0000	1.3.2.10
@@ -26,7 +26,7 @@
 use C4::Biblio;
 use C4::Context;
 use C4::Breeding;
-use MARC::File::USMARC;
+use C4::Koha;
 use ZOOM;
 
 my $input = new CGI;
@@ -61,6 +61,7 @@
 my @serverhost;
 my @breeding_loop = ();
 
+
 unless ($random) { # this var is not useful anymore just kept to keep rel2_2 compatibility
 	$random =rand(1000000000);
 }
@@ -103,9 +104,10 @@
 							
 	if ($isbn ne "/" || $issn ne "/") {
 		$attr='1=7';
-		$term=$isbn if ($isbn ne"/");
-		$term=$issn if ($issn ne"/");
-	} elsif ($title ne"/") {
+        warn "isbn : $isbn";
+		$term=$isbn if ($isbn ne "/");
+		$term=$issn if ($issn ne "/");
+	} elsif ($title ne "/") {
 		$attr='1=4 @attr 4=1  ';
 		$term=$title;
 	} elsif ($author ne "/") {
@@ -114,6 +116,7 @@
 	} 
 
 	my $query="\@attr $attr \"$term\"";	
+    warn "query ".$query;
 	foreach my $servid (@id){
 		my $sth=$dbh->prepare("select * from z3950servers where id=?");
 		$sth->execute($servid);
@@ -169,7 +172,7 @@
 				my $rec=$oResult[$k]->record($i); 										
 				my $marcrecord;
 				$marcdata = $rec->raw();											
-				$marcrecord = MARC::File::USMARC::decode($marcdata);
+                $marcrecord= fixEncoding($marcdata);
 ####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc
 ## In HEAD i change everything to UTF-8
 # In rel2_2 i am not sure what encoding is so no character conversion is done here





More information about the Koha-cvs mailing list