[Koha-cvs] koha acqui/finishreceive.pl admin/koha2marclink... [rel_3_0]

Antoine Farnault antoine at koha-fr.org
Tue Dec 5 12:35:33 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	Antoine Farnault <toins>	06/12/05 11:35:32

Modified files:
	acqui          : finishreceive.pl 
	admin          : koha2marclinks.pl marc_subfields_structure.pl 
	authorities    : auth_finder.pl auth_linker.pl 
	bookshelves    : addbookbybiblionumber.pl 
	C4             : Biblio.pm Koha.pm Log.pm Maintainance.pm 
	                 Reserves2.pm Search.pm Serials.pm 
	C4/Circulation : Circ2.pm Returns.pm 
	catalogue      : detail.pl detailprint.pl ISBDdetail.pl 
	                 MARCdetail.pl moredetail.pl 
	cataloguing    : addbiblio.pl additem-nomarc.pl additem.pl 
	                 savebiblio.pl 
	cataloguing/value_builder: unimarc_field_4XX.pl 
	circ           : bookcount.pl circulation.pl 
	export         : export.pl marc.pl 
	koha-tmpl/intranet-tmpl/prog/en/catalogue: detail.tmpl 
	                                           suggest.tmpl 
	koha-tmpl/intranet-tmpl/prog/en/z3950: searchresult.tmpl 
	koha-tmpl/opac-tmpl/prog/en: opac-detail.tmpl 
	maint          : catmaintain.pl 
	members        : moremember.pl 
	misc           : bulkauthimport.pl fines2.pl merge_authority.pl 
	                 missing090field.pl rebuildnonmarc.pl 
	                 rebuildthesaurus.pl 
	misc/cronjobs  : reservelist.pl 
	misc/migration_tools/22_to_30: missing090field.pl 
	                               move_marc_to_biblioitems.pl 
	misc/migration_tools: build6xx.pl buildEDITORS.pl 
	                      bulkmarcimport.pl rebuild_zebra_idx.pl 
	                      rebuild_zebra.pl 
	misc/notifys   : fines.pl 
	opac           : opac-addbookbybiblionumber.pl opac-basket.pl 
	                 opac-detail.pl opac-detailprint.pl 
	                 opac-ISBDdetail.pl opac-MARCdetail.pl 
	                 opac-reserve.pl opac-review.pl 
	                 opac-sendbasket.pl opac-showreviews.pl 
	reserve        : request.pl 
	serials        : serials-edit.pl serials-recieve.pl 
	tools          : export.pl 

Log message:
	Biblio.pm cleaned.
	additionalauthors, bibliosubject, bibliosubtitle tables are now unused.
	Some functions renamed according to the coding guidelines.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/acqui/finishreceive.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.20.2.4&r2=1.20.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/admin/koha2marclinks.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.13.2.1&r2=1.13.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/admin/marc_subfields_structure.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.38.2.3&r2=1.38.2.4
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/auth_finder.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.11.2.2&r2=1.11.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/auth_linker.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/bookshelves/addbookbybiblionumber.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.4&r2=1.4.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Biblio.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.178.2.32&r2=1.178.2.33
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Koha.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.40.2.25&r2=1.40.2.26
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Log.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5&r2=1.5.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Maintainance.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.18.2.1&r2=1.18.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Reserves2.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.46.2.7&r2=1.46.2.8
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.120.2.33&r2=1.120.2.34
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Serials.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5.2.13&r2=1.5.2.14
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Circ2.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.114.2.22&r2=1.114.2.23
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Circulation/Returns.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.10.2.2&r2=1.10.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/catalogue/detail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.6.2.9&r2=1.6.2.10
http://cvs.savannah.gnu.org/viewcvs/koha/catalogue/detailprint.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.4&r2=1.1.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/catalogue/ISBDdetail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2.2.1&r2=1.2.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/catalogue/MARCdetail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5.2.5&r2=1.5.2.6
http://cvs.savannah.gnu.org/viewcvs/koha/catalogue/moredetail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.4&r2=1.4.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/cataloguing/addbiblio.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.14.2.14&r2=1.14.2.15
http://cvs.savannah.gnu.org/viewcvs/koha/cataloguing/additem-nomarc.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.1&r2=1.4.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/cataloguing/additem.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.7.2.9&r2=1.7.2.10
http://cvs.savannah.gnu.org/viewcvs/koha/cataloguing/savebiblio.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/cataloguing/value_builder/unimarc_field_4XX.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.5&r2=1.1.2.6
http://cvs.savannah.gnu.org/viewcvs/koha/circ/bookcount.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.5&r2=1.1.2.6
http://cvs.savannah.gnu.org/viewcvs/koha/circ/circulation.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.97.2.11&r2=1.97.2.12
http://cvs.savannah.gnu.org/viewcvs/koha/export/export.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.4.3&r2=1.1.4.4
http://cvs.savannah.gnu.org/viewcvs/koha/export/marc.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.7.2.2&r2=1.7.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/prog/en/catalogue/detail.tmpl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2.2.11&r2=1.2.2.12
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/prog/en/catalogue/suggest.tmpl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/prog/en/z3950/searchresult.tmpl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1&r2=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/opac-tmpl/prog/en/opac-detail.tmpl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.3&r2=1.1.2.4
http://cvs.savannah.gnu.org/viewcvs/koha/maint/catmaintain.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.7.2.1&r2=1.7.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/members/moremember.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.28.2.13&r2=1.28.2.14
http://cvs.savannah.gnu.org/viewcvs/koha/misc/bulkauthimport.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1&r2=1.1.8.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/fines2.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.12.2.2&r2=1.12.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/misc/merge_authority.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2&r2=1.2.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/missing090field.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1&r2=1.1.4.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/rebuildnonmarc.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5.2.1&r2=1.5.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/misc/rebuildthesaurus.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2&r2=1.2.8.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/cronjobs/reservelist.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2.2.1&r2=1.2.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/22_to_30/missing090field.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/22_to_30/move_marc_to_biblioitems.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.1&r2=1.1.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/build6xx.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2&r2=1.2.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/buildEDITORS.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2&r2=1.2.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/bulkmarcimport.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.7.2.2&r2=1.7.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/rebuild_zebra_idx.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1&r2=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/misc/migration_tools/rebuild_zebra.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.5&r2=1.4.2.6
http://cvs.savannah.gnu.org/viewcvs/koha/misc/notifys/fines.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.3&r2=1.3.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-addbookbybiblionumber.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5.2.1&r2=1.5.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-basket.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.8.2.1&r2=1.8.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-detail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.32.2.3&r2=1.32.2.4
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-detailprint.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.3.2.2&r2=1.3.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-ISBDdetail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.16.2.2&r2=1.16.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-MARCdetail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.14.2.2&r2=1.14.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-reserve.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.29.2.4&r2=1.29.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-review.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2.2.1&r2=1.2.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-sendbasket.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.10.2.3&r2=1.10.2.4
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-showreviews.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2.2.2&r2=1.2.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/reserve/request.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.6.2.10&r2=1.6.2.11
http://cvs.savannah.gnu.org/viewcvs/koha/serials/serials-edit.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.4&r2=1.1.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/serials/serials-recieve.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.4&r2=1.4.2.5
http://cvs.savannah.gnu.org/viewcvs/koha/tools/export.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.3&r2=1.1.2.4

Patches:
Index: acqui/finishreceive.pl
===================================================================
RCS file: /sources/koha/koha/acqui/finishreceive.pl,v
retrieving revision 1.20.2.4
retrieving revision 1.20.2.5
diff -u -b -r1.20.2.4 -r1.20.2.5
--- acqui/finishreceive.pl	30 Nov 2006 18:23:50 -0000	1.20.2.4
+++ acqui/finishreceive.pl	5 Dec 2006 11:35:29 -0000	1.20.2.5
@@ -103,7 +103,7 @@
   $input->param('createbibitem');    # user wants to create a new bibitem
 
 #get additional info on biblionumber and bibitem from db for additional needed fields before modbiblio.
-( my $bibliocount,     my @biblios )     = &getbiblio($biblionumber);
+( my $bibliocount,     my @biblios )     = &GetBiblio($biblionumber);
 my @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber);
 my $biblioitemcount = scalar @biblioitems;
 

Index: admin/koha2marclinks.pl
===================================================================
RCS file: /sources/koha/koha/admin/Attic/koha2marclinks.pl,v
retrieving revision 1.13.2.1
retrieving revision 1.13.2.2
diff -u -b -r1.13.2.1 -r1.13.2.2
--- admin/koha2marclinks.pl	30 Nov 2006 18:23:51 -0000	1.13.2.1
+++ admin/koha2marclinks.pl	5 Dec 2006 11:35:29 -0000	1.13.2.2
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-
 # Copyright 2000-2002 Katipo Communications
 #
 # This file is part of Koha.
@@ -28,116 +27,163 @@
 use HTML::Template;
 
 my $input = new CGI;
-my $tablename=$input->param('tablename');
-$tablename="biblio" unless ($tablename);
+my $tablename   = $input->param('tablename');
+$tablename      = "biblio" unless ($tablename);
 my $kohafield = $input->param('kohafield');
-my $op=$input->param('op');
+my $op          = $input->param('op');
 my $script_name = 'koha2marclinks.pl';
 
-my ($template, $borrowernumber, $cookie)
-    = get_template_and_user({template_name => "admin/koha2marclinks.tmpl",
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
+    {
+        template_name   => "admin/koha2marclinks.tmpl",
 			     query => $input,
 			     type => "intranet",
 			     authnotrequired => 0,
-			     flagsrequired => {parameters => 1},
+        flagsrequired   => { parameters => 1 },
 			     debug => 1,
-			     });
+    }
+);
 
 if ($op) {
-$template->param(script_name => $script_name,
-						$op              => 1); # we show only the TMPL_VAR names $op
-} else {
-$template->param(script_name => $script_name,
-						else              => 1); # we show only the TMPL_VAR names $op
+    $template->param(
+        script_name => $script_name,
+        $op         => 1
+    );    # we show only the TMPL_VAR names $op
+}
+else {
+    $template->param(
+        script_name => $script_name,
+        else        => 1
+    );    # we show only the TMPL_VAR names $op
 }
 
 my $dbh = C4::Context->dbh;
 
 ################## ADD_FORM ##################################
 # called by default. Used to create form to add or  modify a record
-if ($op eq 'add_form') {
+if ( $op eq 'add_form' ) {
 	my $data;
-	my $sth = $dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?");
-	$sth->execute($tablename.".".$kohafield);
-	my ($defaulttagfield, $defaulttagsubfield,$defaultliblibrarian) = $sth->fetchrow;
-
-	for (my $i=0;$i<=9;$i++) {
-		my $sth2=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ?");
+    my $sth =
+      $dbh->prepare(
+"select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where kohafield=?"
+      );
+    $sth->execute( $tablename . "." . $kohafield );
+    my ( $defaulttagfield, $defaulttagsubfield, $defaultliblibrarian ) =
+      $sth->fetchrow;
+
+    for ( my $i = 0 ; $i <= 9 ; $i++ ) {
+        my $sth2 =
+          $dbh->prepare(
+"select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure where tagfield like ?"
+          );
 		$sth2->execute("$i%");
 		my @marcarray;
-		push @marcarray," ";
-		while (my ($field, $tagsubfield, $liblibrarian) = $sth2->fetchrow_array) {
+        push @marcarray, " ";
+        while ( my ( $field, $tagsubfield, $liblibrarian ) =
+            $sth2->fetchrow_array )
+        {
 			push @marcarray, "$field $tagsubfield - $liblibrarian";
 		}
-		my $marclist = CGI::scrolling_list(-name=>"marc",
-						-values=> \@marcarray,
-						-default=>"$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
-						-size=>1,
-			 			-tabindex=>'',
-						-multiple=>0,
+        my $marclist = CGI::scrolling_list(
+            -name    => "marc",
+            -values  => \@marcarray,
+            -default =>
+              "$defaulttagfield $defaulttagsubfield - $defaultliblibrarian",
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
 						);
-		$template->param("marclist$i" => $marclist);
+        $template->param( "marclist$i" => $marclist );
 	}
-	$template->param(	tablename => $tablename,
-							kohafield => $kohafield);
+    $template->param(
+        tablename => $tablename,
+        kohafield => $kohafield
+    );
 
 													# END $OP eq ADD_FORM
 ################## ADD_VALIDATE ##################################
-# called by add_form, used to insert/modify data in DB
-} elsif ($op eq 'add_validate') {
+    # called by add_form, used to insert/modify data in DB
+}
+elsif ( $op eq 'add_validate' ) {
+
 	#----- empty koha field :
-	$dbh->do("update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'");
+    $dbh->do(
+"update marc_subfield_structure set kohafield='' where kohafield='$tablename.$kohafield'"
+    );
+
 	#---- reload if not empty
-	my @temp = split / /,$input->param('marc');
-	$dbh->do("update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'");
-	print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
+    my @temp = split / /, $input->param('marc');
+    $dbh->do(
+"update marc_subfield_structure set kohafield='$tablename.$kohafield' where tagfield='$temp[0]' and tagsubfield='$temp[1]'"
+    );
+    print
+"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=koha2marclinks.pl?tablename=$tablename\"></html>";
 	exit;
 
 													# END $OP eq ADD_VALIDATE
 ################## DEFAULT ##################################
-} else { # DEFAULT
+}
+else {    # DEFAULT
 	my $env;
-	my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure");
+    my $sth =
+      $dbh->prepare(
+"Select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structure"
+      );
 	$sth->execute;
 	my %fields;
-	while ((my $tagfield,my $tagsubfield,my $liblibrarian,my $kohafield) = $sth->fetchrow) {
+    while ( ( my $tagfield, my $tagsubfield, my $liblibrarian, my $kohafield ) =
+        $sth->fetchrow )
+    {
 		$fields{$kohafield}->{tagfield} = $tagfield;
 		$fields{$kohafield}->{tagsubfield} = $tagsubfield;
 		$fields{$kohafield}->{liblibrarian} = $liblibrarian;
 	}
+
 	#XXX: This might not work. Maybe should use a DBI call instead of SHOW COLUMNS
-	my $sth2=$dbh->prepare("SHOW COLUMNS from $tablename");
+    my $sth2 = $dbh->prepare("SHOW COLUMNS from $tablename");
 	$sth2->execute;
 
-	my $toggle="white";
+    my $toggle    = "white";
 	my @loop_data = ();
-	while ((my $field) = $sth2->fetchrow_array) {
-	  	if ($toggle eq 'white'){
-			$toggle="#ffffcc";
-	  	} else {
-			$toggle="white";
+    while ( ( my $field ) = $sth2->fetchrow_array ) {
+        if ( $toggle eq 'white' ) {
+            $toggle = "#ffffcc";
+        }
+        else {
+            $toggle = "white";
 	  	}
 		my %row_data;  # get a fresh hash for the row data
-		$row_data{tagfield} = $fields{$tablename.".".$field}->{tagfield};
-		$row_data{tagsubfield} = $fields{$tablename.".".$field}->{tagsubfield};
-		$row_data{liblibrarian} = $fields{$tablename.".".$field}->{liblibrarian};
+        $row_data{tagfield} = $fields{ $tablename . "." . $field }->{tagfield};
+        $row_data{tagsubfield} =
+          $fields{ $tablename . "." . $field }->{tagsubfield};
+        $row_data{liblibrarian} =
+          $fields{ $tablename . "." . $field }->{liblibrarian};
 		$row_data{kohafield} = $field;
-		$row_data{edit} = "$script_name?op=add_form&amp;tablename=$tablename&amp;kohafield=$field";
+        $row_data{edit}      =
+"$script_name?op=add_form&amp;tablename=$tablename&amp;kohafield=$field";
 		$row_data{bgcolor} = $toggle;
-		push(@loop_data,\%row_data);
+        push( @loop_data, \%row_data );
 	}
-	$template->param(loop => \@loop_data,
-							tablename => CGI::scrolling_list(-name=>'tablename',
-																	-values=>['biblio','biblioitems','items','bibliosubject','bibliosubtitle','additionalauthors'],
-						-default=>$tablename,
-						-size=>1,
-			 			-tabindex=>'',
-						-multiple=>0
+    $template->param(
+        loop      => \@loop_data,
+        tablename => CGI::scrolling_list(
+            -name   => 'tablename',
+            -values => [
+                'biblio',
+                'biblioitems',
+                'items',
+            ],
+            -default  => $tablename,
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0
 						)
 				);
 } #---- END $OP eq DEFAULT
-$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+$template->param(
+    intranetcolorstylesheet =>
+      C4::Context->preference("intranetcolorstylesheet"),
 		intranetstylesheet => C4::Context->preference("intranetstylesheet"),
 		IntranetNav => C4::Context->preference("IntranetNav"),
-		);
+);
 output_html_with_http_headers $input, $cookie, $template->output;

Index: admin/marc_subfields_structure.pl
===================================================================
RCS file: /sources/koha/koha/admin/Attic/marc_subfields_structure.pl,v
retrieving revision 1.38.2.3
retrieving revision 1.38.2.4
diff -u -b -r1.38.2.3 -r1.38.2.4
--- admin/marc_subfields_structure.pl	30 Nov 2006 18:23:51 -0000	1.38.2.3
+++ admin/marc_subfields_structure.pl	5 Dec 2006 11:35:29 -0000	1.38.2.4
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-
 # Copyright 2000-2002 Katipo Communications
 #
 # This file is part of Koha.
@@ -27,304 +26,375 @@
 use HTML::Template;
 
 sub StringSearch  {
-    my ($env,$searchstring,$frameworkcode)=@_;
+    my ( $env, $searchstring, $frameworkcode ) = @_;
     my $dbh = C4::Context->dbh;
-    $searchstring=~ s/\'/\\\'/g;
-    my @data=split(' ',$searchstring);
-    my $count=@data;
-    my $sth=$dbh->prepare("Select * from marc_subfield_structure where (tagfield like ? and frameworkcode=?) order by tagfield");
-    $sth->execute("$searchstring%",$frameworkcode);
+    $searchstring =~ s/\'/\\\'/g;
+    my @data  = split( ' ', $searchstring );
+    my $count = @data;
+    my $sth   =
+      $dbh->prepare(
+"Select * from marc_subfield_structure where (tagfield like ? and frameworkcode=?) order by tagfield"
+      );
+    $sth->execute( "$searchstring%", $frameworkcode );
     my @results;
-    my $cnt=0;
-    my $u=1;
-    while (my $data=$sth->fetchrow_hashref){
-        push(@results,$data);
-        $cnt ++;
+    my $cnt = 0;
+    my $u   = 1;
+
+    while ( my $data = $sth->fetchrow_hashref ) {
+        push( @results, $data );
+        $cnt++;
         $u++;
     }
     $sth->finish;
     $dbh->disconnect;
-    return ($cnt,\@results);
+    return ( $cnt, \@results );
 }
 
 my $input = new CGI;
-my $tagfield=$input->param('tagfield');
-my $tagsubfield=$input->param('tagsubfield');
-my $frameworkcode=$input->param('frameworkcode');
-my $pkfield="tagfield";
-my $offset=$input->param('offset');
-my $script_name="/cgi-bin/koha/admin/marc_subfields_structure.pl";
-
-my ($template, $borrowernumber, $cookie)
-    = get_template_and_user({template_name => "admin/marc_subfields_structure.tmpl",
+my $tagfield      = $input->param('tagfield');
+my $tagsubfield   = $input->param('tagsubfield');
+my $frameworkcode = $input->param('frameworkcode');
+my $pkfield       = "tagfield";
+my $offset        = $input->param('offset');
+my $script_name   = "/cgi-bin/koha/admin/marc_subfields_structure.pl";
+
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+    {
+        template_name   => "admin/marc_subfields_structure.tmpl",
                 query => $input,
                 type => "intranet",
                 authnotrequired => 0,
-                flagsrequired => {parameters => 1},
+        flagsrequired   => { parameters => 1 },
                 debug => 1,
-                });
-my $pagesize=30;
+    }
+);
+my $pagesize = 30;
 my $op = $input->param('op');
-$tagfield=~ s/\,//g;
+$tagfield =~ s/\,//g;
 
 if ($op) {
-$template->param(script_name => $script_name,
-                        tagfield =>$tagfield,
+    $template->param(
+        script_name   => $script_name,
+        tagfield      => $tagfield,
                         frameworkcode => $frameworkcode,
-                        $op              => 1); # we show only the TMPL_VAR names $op
-} else {
-$template->param(script_name => $script_name,
-                        tagfield =>$tagfield,
+        $op           => 1
+    );    # we show only the TMPL_VAR names $op
+}
+else {
+    $template->param(
+        script_name   => $script_name,
+        tagfield      => $tagfield,
                         frameworkcode => $frameworkcode,
-                        else              => 1); # we show only the TMPL_VAR names $op
+        else          => 1
+    );    # we show only the TMPL_VAR names $op
 }
 
 ################## ADD_FORM ##################################
 # called by default. Used to create form to add or  modify a record
-if ($op eq 'add_form') {
+if ( $op eq 'add_form' ) {
     my $data;
     my $dbh = C4::Context->dbh;
-    my $more_subfields = $input->param("more_subfields")+1;
+    my $more_subfields = $input->param("more_subfields") + 1;
+
     # builds kohafield tables
     my @kohafields;
     push @kohafields, "";
-    my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
+    my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
     $sth2->execute;
-    while ((my $field) = $sth2->fetchrow_array) {
-        push @kohafields, "biblio.".$field;
+    while ( ( my $field ) = $sth2->fetchrow_array ) {
+        push @kohafields, "biblio." . $field;
     }
-    my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
+    my $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
     $sth2->execute;
-    while ((my $field) = $sth2->fetchrow_array) {
-        if ($field eq 'notes') { $field = 'bnotes'; }
-        push @kohafields, "biblioitems.".$field;
+    while ( ( my $field ) = $sth2->fetchrow_array ) {
+        if ( $field eq 'notes' ) { $field = 'bnotes'; }
+        push @kohafields, "biblioitems." . $field;
     }
-    my $sth2=$dbh->prepare("SHOW COLUMNS from items");
+    my $sth2 = $dbh->prepare("SHOW COLUMNS from items");
     $sth2->execute;
-    while ((my $field) = $sth2->fetchrow_array) {
-        push @kohafields, "items.".$field;
+    while ( ( my $field ) = $sth2->fetchrow_array ) {
+        push @kohafields, "items." . $field;
     }
     
-    # other subfields
-    push @kohafields, "additionalauthors.author";
-    push @kohafields, "bibliosubject.subject";
-    push @kohafields, "bibliosubtitle.subtitle";
     # build authorised value list
     $sth2->finish;
     $sth2 = $dbh->prepare("select distinct category from authorised_values");
     $sth2->execute;
     my @authorised_values;
-    push @authorised_values,"";
-    while ((my $category) = $sth2->fetchrow_array) {
+    push @authorised_values, "";
+    while ( ( my $category ) = $sth2->fetchrow_array ) {
         push @authorised_values, $category;
     }
-    push (@authorised_values,"branches");
-    push (@authorised_values,"itemtypes");
+    push( @authorised_values, "branches" );
+    push( @authorised_values, "itemtypes" );
+
     # build thesaurus categories list
     $sth2->finish;
     $sth2 = $dbh->prepare("select authtypecode from auth_types");
     $sth2->execute;
     my @authtypes;
-    push @authtypes,"";
-    while ((my $authtypecode) = $sth2->fetchrow_array) {
+    push @authtypes, "";
+    while ( ( my $authtypecode ) = $sth2->fetchrow_array ) {
         push @authtypes, $authtypecode;
     }
+
     # build value_builder list
-    my @value_builder=('');
+    my @value_builder = ('');
 
     # read value_builder directory.
     # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
     # on a standard install, /cgi-bin need to be added. 
     # test one, then the other
-    my $cgidir = C4::Context->intranetdir ."/cgi-bin";
-    unless (opendir(DIR, "$cgidir/cataloguing/value_builder")) {
+    my $cgidir = C4::Context->intranetdir . "/cgi-bin";
+    unless ( opendir( DIR, "$cgidir/cataloguing/value_builder" ) ) {
         $cgidir = C4::Context->intranetdir;
-        opendir(DIR, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
+        opendir( DIR, "$cgidir/cataloguing/value_builder" )
+          || die "can't opendir $cgidir/value_builder: $!";
     } 
-    while (my $line = readdir(DIR)) {
-        if ($line =~ /\.pl$/) {
-            push (@value_builder,$line);
+    while ( my $line = readdir(DIR) ) {
+        if ( $line =~ /\.pl$/ ) {
+            push( @value_builder, $line );
         }
     }
     closedir DIR;
 
     # build values list
-    my $sth=$dbh->prepare("select * from marc_subfield_structure where tagfield=? and frameworkcode=?"); # and tagsubfield='$tagsubfield'");
-    $sth->execute($tagfield,$frameworkcode);
+    my $sth =
+      $dbh->prepare(
+"select * from marc_subfield_structure where tagfield=? and frameworkcode=?"
+      );    # and tagsubfield='$tagsubfield'");
+    $sth->execute( $tagfield, $frameworkcode );
     my @loop_data = ();
-    my $toggle=1;
-    my $i=0;
-    while ($data =$sth->fetchrow_hashref) {
+    my $toggle    = 1;
+    my $i         = 0;
+    while ( $data = $sth->fetchrow_hashref ) {
         my %row_data;  # get a fresh hash for the row data
-        if ($toggle eq 1){
-            $toggle=0;
-        } else {
-            $toggle=1;
-        }
-        $row_data{tab} = CGI::scrolling_list(-name=>'tab',
-                    -id=>"tab$i",
-                    -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
-                    -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
-                                    '2' =>'2','3'=>'3','4'=>'4',
-                                    '5' =>'5','6'=>'6','7'=>'7',
-                                    '8' =>'8','9'=>'9','10'=>'items (10)',
+        if ( $toggle eq 1 ) {
+            $toggle = 0;
+        }
+        else {
+            $toggle = 1;
+        }
+        $row_data{tab} = CGI::scrolling_list(
+            -name   => 'tab',
+            -id     => "tab$i",
+            -values =>
+              [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
+            -labels => {
+                '-1' => 'ignore',
+                '0'  => '0',
+                '1'  => '1',
+                '2'  => '2',
+                '3'  => '3',
+                '4'  => '4',
+                '5'  => '5',
+                '6'  => '6',
+                '7'  => '7',
+                '8'  => '8',
+                '9'  => '9',
+                '10' => 'items (10)',
                                     },
-                    -default=>$data->{'tab'},
-                    -size=>1,
-                    -tabindex=>'',
-                    -multiple=>0,
-                    );
-        $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\">";
-        $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
-        $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
-        $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
-        $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
-                                -id=>"kohafield$i",
-                                -values=> \@kohafields,
-                                -default=> "$data->{'kohafield'}",
-                                -size=>1,
-                                -tabindex=>'',
-                                -multiple=>0,
-                                );
-        $row_data{authorised_value}  = CGI::scrolling_list(-name=>'authorised_value',
-                                        -id=>'authorised_value',
-                                        -values=> \@authorised_values,
-                                        -default=>$data->{'authorised_value'},
-                                        -size=>1,
-                                        -tabindex=>'',
-                                        -multiple=>0,
-                                        );
-        $row_data{value_builder}  = CGI::scrolling_list(-name=>'value_builder',
-                                    -id=>'value_builder',
-                                    -values=> \@value_builder,
-                                    -default=>$data->{'value_builder'},
-                                    -size=>1,
-                                    -tabindex=>'',
-                                    -multiple=>0,
-                                    );
-        $row_data{authtypes}  = CGI::scrolling_list(-name=>'authtypecode',
-                                -id=>'authtypecode',
-                                -values=> \@authtypes,
-                                -default=>$data->{'authtypecode'},
-                                -size=>1,
-                                -tabindex=>'',
-                                -multiple=>0,
+            -default  => $data->{'tab'},
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
+        );
+        $row_data{tagsubfield} =
+            $data->{'tagsubfield'}
+          . "<input type=\"hidden\" name=\"tagsubfield\" value=\""
+          . $data->{'tagsubfield'}
+          . "\" id=\"tagsubfield\">";
+        $row_data{liblibrarian} = CGI::escapeHTML( $data->{'liblibrarian'} );
+        $row_data{libopac}      = CGI::escapeHTML( $data->{'libopac'} );
+        $row_data{seealso}      = CGI::escapeHTML( $data->{'seealso'} );
+        $row_data{kohafield}    = CGI::scrolling_list(
+            -name     => "kohafield",
+            -id       => "kohafield$i",
+            -values   => \@kohafields,
+            -default  => "$data->{'kohafield'}",
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
+        );
+        $row_data{authorised_value} = CGI::scrolling_list(
+            -name     => 'authorised_value',
+            -id       => 'authorised_value',
+            -values   => \@authorised_values,
+            -default  => $data->{'authorised_value'},
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
+        );
+        $row_data{value_builder} = CGI::scrolling_list(
+            -name     => 'value_builder',
+            -id       => 'value_builder',
+            -values   => \@value_builder,
+            -default  => $data->{'value_builder'},
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
                                 );
-        $row_data{repeatable} = CGI::checkbox(-name=>"repeatable$i",
-                                -checked => $data->{'repeatable'}?'checked':'',
+        $row_data{authtypes} = CGI::scrolling_list(
+            -name     => 'authtypecode',
+            -id       => 'authtypecode',
+            -values   => \@authtypes,
+            -default  => $data->{'authtypecode'},
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
+        );
+        $row_data{repeatable} = CGI::checkbox(
+            -name     => "repeatable$i",
+            -checked  => $data->{'repeatable'} ? 'checked' : '',
                                 -value => 1,
-                                -tabindex=>'',
+            -tabindex => '',
                                 -label => '',
-                                -id => "repeatable$i");
-        $row_data{mandatory} = CGI::checkbox(-name => "mandatory$i",
-                                -checked => $data->{'mandatory'}?'checked':'',
+            -id       => "repeatable$i"
+        );
+        $row_data{mandatory} = CGI::checkbox(
+            -name     => "mandatory$i",
+            -checked  => $data->{'mandatory'} ? 'checked' : '',
                                 -value => 1,
-                                -tabindex=>'',
+            -tabindex => '',
                                 -label => '',
-                                -id => "mandatory$i");
-        $row_data{hidden} = CGI::escapeHTML($data->{hidden});
-        $row_data{isurl} = CGI::checkbox( -name => "isurl$i",
+            -id       => "mandatory$i"
+        );
+        $row_data{hidden} = CGI::escapeHTML( $data->{hidden} );
+        $row_data{isurl}  = CGI::checkbox(
+            -name     => "isurl$i",
                             -id => "isurl$i",
-                            -checked => $data->{'isurl'}?'checked':'',
+            -checked  => $data->{'isurl'} ? 'checked' : '',
                             -value => 1,
-                            -tabindex=>'',
-                            -label => '');
+            -tabindex => '',
+            -label    => ''
+        );
         $row_data{row} = $i;
         $row_data{toggle} = $toggle;
-        $row_data{link} = CGI::escapeHTML($data->{'link'});
-        push(@loop_data, \%row_data);
+        $row_data{link}   = CGI::escapeHTML( $data->{'link'} );
+        push( @loop_data, \%row_data );
         $i++;
     }
+
     # add more_subfields empty lines for add if needed
-    for (my $j=$i;$j<=$more_subfields+$i;$j++) {
+    for ( my $j = $i ; $j <= $more_subfields + $i ; $j++ ) {
         my %row_data;  # get a fresh hash for the row data
-        $row_data{tab} = CGI::scrolling_list(-name=>'tab',
+        $row_data{tab} = CGI::scrolling_list(
+            -name   => 'tab',
                     -id => "tab$j",
-                    -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
-                    -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
-                                    '2' =>'2','3'=>'3','4'=>'4',
-                                    '5' =>'5','6'=>'6','7'=>'7',
-                                    '8' =>'8','9'=>'9','10'=>'items (10)',
+            -values =>
+              [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
+            -labels => {
+                '-1' => 'ignore',
+                '0'  => '0',
+                '1'  => '1',
+                '2'  => '2',
+                '3'  => '3',
+                '4'  => '4',
+                '5'  => '5',
+                '6'  => '6',
+                '7'  => '7',
+                '8'  => '8',
+                '9'  => '9',
+                '10' => 'items (10)',
                                     },
-                    -default=>"",
-                    -size=>1,
-                    -tabindex=>'',
-                    -multiple=>0,
-                    );
-        $row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\">";
+            -default  => "",
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
+        );
+        $row_data{tagsubfield} =
+            "<input type=\"text\" name=\"tagsubfield\" value=\""
+          . $data->{'tagsubfield'}
+          . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\">";
         $row_data{liblibrarian} = "";
         $row_data{libopac} = "";
         $row_data{seealso} = "";
-        $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
+        $row_data{kohafield}    = CGI::scrolling_list(
+            -name     => 'kohafield',
                                 -id => "kohafield$j",
-                                -values=> \@kohafields,
-                                -default=> "",
-                                -size=>1,
-                                -tabindex=>'',
-                                -multiple=>0,
+            -values   => \@kohafields,
+            -default  => "",
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
                                 );
         $row_data{hidden} = "";
-        $row_data{repeatable} = CGI::checkbox( -name=> "repeatable$j",
+        $row_data{repeatable} = CGI::checkbox(
+            -name     => "repeatable$j",
                                 -id => "repeatable$j",
                                 -checked => '',
                                 -value => 1,
-                                -tabindex=>'',
-                                -label => '');
-        $row_data{mandatory} = CGI::checkbox( -name=> "mandatory$j",
+            -tabindex => '',
+            -label    => ''
+        );
+        $row_data{mandatory} = CGI::checkbox(
+            -name     => "mandatory$j",
                                 -id => "mandatory$j",
                                 -checked => '',
                                 -value => 1,
-                                -tabindex=>'',
-                                -label => '');
-        $row_data{isurl} = CGI::checkbox(-name => "isurl$j",
+            -tabindex => '',
+            -label    => ''
+        );
+        $row_data{isurl} = CGI::checkbox(
+            -name     => "isurl$j",
                             -id => "isurl$j",
                             -checked => '',
                             -value => 1,
-                            -tabindex=>'',
-                            -label => '');
-        $row_data{value_builder}  = CGI::scrolling_list(-name=>'value_builder',
-                                    -id=>'value_builder',
-                                    -values=> \@value_builder,
-                                    -default=>$data->{'value_builder'},
-                                    -size=>1,
-                                    -tabindex=>'',
-                                    -multiple=>0,
+            -tabindex => '',
+            -label    => ''
+        );
+        $row_data{value_builder} = CGI::scrolling_list(
+            -name     => 'value_builder',
+            -id       => 'value_builder',
+            -values   => \@value_builder,
+            -default  => $data->{'value_builder'},
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
                                     );
-        $row_data{authorised_value}  = CGI::scrolling_list(-name=>'authorised_value',
+        $row_data{authorised_value} = CGI::scrolling_list(
+            -name     => 'authorised_value',
                                         -id => 'authorised_value',
-                                        -values=> \@authorised_values,
-                                        -size=>1,
-                                        -tabindex=>'',
-                                        -multiple=>0,
+            -values   => \@authorised_values,
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
                                         );
-        $row_data{authtypes}  = CGI::scrolling_list(-name=>'authtypecode',
+        $row_data{authtypes} = CGI::scrolling_list(
+            -name     => 'authtypecode',
                                 -id => 'authtypecode',
-                                -values=> \@authtypes,
-                                -size=>1,
-                                -tabindex=>'',
-                                -multiple=>0,
+            -values   => \@authtypes,
+            -size     => 1,
+            -tabindex => '',
+            -multiple => 0,
                                 );
-        $row_data{link} = CGI::escapeHTML($data->{'link'});
+        $row_data{link}   = CGI::escapeHTML( $data->{'link'} );
         $row_data{toggle} = $toggle;
         $row_data{row} = $j;
-        push(@loop_data, \%row_data);
+        push( @loop_data, \%row_data );
     }
-    $template->param('use-heading-flags-p' => 1);
-    $template->param('heading-edit-subfields-p' => 1);
-    $template->param(action => "Edit subfields",
-                            tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
+    $template->param( 'use-heading-flags-p'      => 1 );
+    $template->param( 'heading-edit-subfields-p' => 1 );
+    $template->param(
+        action   => "Edit subfields",
+        tagfield =>
+"<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
                             loop => \@loop_data,
                             more_subfields => $more_subfields,
-                            more_tag => $tagfield);
+        more_tag       => $tagfield
+    );
 
                                                 # END $OP eq ADD_FORM
 ################## ADD_VALIDATE ##################################
-# called by add_form, used to insert/modify data in DB
-} elsif ($op eq 'add_validate') {
+    # called by add_form, used to insert/modify data in DB
+}
+elsif ( $op eq 'add_validate' ) {
     my $dbh = C4::Context->dbh;
-    $template->param(tagfield => "$input->param('tagfield')");
-    my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link)
-                                    values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+    $template->param( tagfield => "$input->param('tagfield')" );
+    my $sth = $dbh->prepare(
+"replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl,frameworkcode, link)
+                                    values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
+    );
     my @tagsubfield	= $input->param('tagsubfield');
     my @liblibrarian	= $input->param('liblibrarian');
     my @libopac		= $input->param('libopac');
@@ -334,28 +404,31 @@
     my @hidden		= $input->param('hidden');
     my @authorised_values	= $input->param('authorised_value');
     my @authtypecodes	= $input->param('authtypecode');
-    my @value_builder	=$input->param('value_builder');
-    my @link		=$input->param('link');
-    for (my $i=0; $i<= $#tagsubfield ; $i++) {
-        my $tagfield			=$input->param('tagfield');
-        my $tagsubfield		=$tagsubfield[$i];
-        $tagsubfield="@" unless $tagsubfield ne '';
-        my $liblibrarian		=$liblibrarian[$i];
-        my $libopac			=$libopac[$i];
-        my $repeatable		=$input->param("repeatable$i")?1:0;
-        my $mandatory		=$input->param("mandatory$i")?1:0;
-        my $kohafield		=$kohafield[$i];
-        my $tab				=$tab[$i];
-        my $seealso				=$seealso[$i];
-        my $authorised_value		=$authorised_values[$i];
-        my $authtypecode		=$authtypecodes[$i];
-        my $value_builder=$value_builder[$i];
+    my @value_builder     = $input->param('value_builder');
+    my @link              = $input->param('link');
+
+    for ( my $i = 0 ; $i <= $#tagsubfield ; $i++ ) {
+        my $tagfield    = $input->param('tagfield');
+        my $tagsubfield = $tagsubfield[$i];
+        $tagsubfield = "@" unless $tagsubfield ne '';
+        my $liblibrarian     = $liblibrarian[$i];
+        my $libopac          = $libopac[$i];
+        my $repeatable       = $input->param("repeatable$i") ? 1 : 0;
+        my $mandatory        = $input->param("mandatory$i") ? 1 : 0;
+        my $kohafield        = $kohafield[$i];
+        my $tab              = $tab[$i];
+        my $seealso          = $seealso[$i];
+        my $authorised_value = $authorised_values[$i];
+        my $authtypecode     = $authtypecodes[$i];
+        my $value_builder    = $value_builder[$i];
         my $hidden = $hidden[$i]; #input->param("hidden$i");
-        my $isurl = $input->param("isurl$i")?1:0;
+        my $isurl  = $input->param("isurl$i") ? 1 : 0;
         my $link = $link[$i];
+
         if ($liblibrarian) {
-            unless (C4::Context->config('demo') eq 1) {
-                $sth->execute ($tagfield,
+            unless ( C4::Context->config('demo') eq 1 ) {
+                $sth->execute(
+                    $tagfield,
                                     $tagsubfield,
                                     $liblibrarian,
                                     $libopac,
@@ -377,51 +450,72 @@
         }
     }
     $sth->finish;
-    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+    print
+"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
     exit;
 
                                                     # END $OP eq ADD_VALIDATE
 ################## DELETE_CONFIRM ##################################
-# called by default form, used to confirm deletion of data in DB
-} elsif ($op eq 'delete_confirm') {
+    # called by default form, used to confirm deletion of data in DB
+}
+elsif ( $op eq 'delete_confirm' ) {
     my $dbh = C4::Context->dbh;
-    my $sth=$dbh->prepare("select * from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
+    my $sth =
+      $dbh->prepare(
+"select * from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
+      );
+
     #FIXME : called with 2 bind variables when 3 are needed
-    $sth->execute($tagfield,$tagsubfield);
-    my $data=$sth->fetchrow_hashref;
+    $sth->execute( $tagfield, $tagsubfield );
+    my $data = $sth->fetchrow_hashref;
     $sth->finish;
-    $template->param(liblibrarian => $data->{'liblibrarian'},
+    $template->param(
+        liblibrarian  => $data->{'liblibrarian'},
                             tagsubfield => $data->{'tagsubfield'},
                             delete_link => $script_name,
-                            tagfield      =>$tagfield,
+        tagfield      => $tagfield,
                             tagsubfield => $tagsubfield,
                             frameworkcode => $frameworkcode,
                             );
+
                                                     # END $OP eq DELETE_CONFIRM
 ################## DELETE_CONFIRMED ##################################
-# called by delete_confirm, used to effectively confirm deletion of data in DB
-} elsif ($op eq 'delete_confirmed') {
+  # called by delete_confirm, used to effectively confirm deletion of data in DB
+}
+elsif ( $op eq 'delete_confirmed' ) {
     my $dbh = C4::Context->dbh;
-    unless (C4::Context->config('demo') eq 1) {
-        my $sth=$dbh->prepare("delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
-        $sth->execute($tagfield,$tagsubfield,$frameworkcode);
+    unless ( C4::Context->config('demo') eq 1 ) {
+        my $sth =
+          $dbh->prepare(
+"delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
+          );
+        $sth->execute( $tagfield, $tagsubfield, $frameworkcode );
         $sth->finish;
     }
-    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
+    print
+"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode\"></html>";
     exit;
-    $template->param(tagfield => $tagfield);
+    $template->param( tagfield => $tagfield );
+
                                                     # END $OP eq DELETE_CONFIRMED
 ################## DEFAULT ##################################
-} else { # DEFAULT
+}
+else {    # DEFAULT
     my $env;
-    my ($count,$results)=StringSearch($env,$tagfield,$frameworkcode);
-    my $toggle=1;
+    my ( $count, $results ) = StringSearch( $env, $tagfield, $frameworkcode );
+    my $toggle    = 1;
     my @loop_data = ();
-    for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
-        if ($toggle eq 1){
-            $toggle=0;
-        } else {
-            $toggle=1;
+    for (
+        my $i = $offset ;
+        $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ;
+        $i++
+      )
+    {
+        if ( $toggle eq 1 ) {
+            $toggle = 0;
+        }
+        else {
+            $toggle = 1;
         }
         my %row_data;  # get a fresh hash for the row data
         $row_data{tagfield} = $results->[$i]{'tagfield'};
@@ -438,29 +532,39 @@
         $row_data{hidden}	= $results->[$i]{'hidden'};
         $row_data{isurl}	= $results->[$i]{'isurl'};
         $row_data{link}	= $results->[$i]{'link'};
-        $row_data{delete} = "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&frameworkcode=$frameworkcode";
+        $row_data{delete}           =
+"$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield="
+          . $results->[$i]{'tagsubfield'}
+          . "&frameworkcode=$frameworkcode";
         $row_data{toggle} = $toggle;
-        if ($row_data{tab} eq -1) {
+
+        if ( $row_data{tab} eq -1 ) {
             $row_data{subfield_ignored} = 1;
         }
 
-        push(@loop_data, \%row_data);
+        push( @loop_data, \%row_data );
     }
-    $template->param(loop => \@loop_data);
-    $template->param(edit_tagfield => $tagfield,
-        edit_frameworkcode => $frameworkcode);
-    
-    if ($offset>0) {
-        my $prevpage = $offset-$pagesize;
-        $template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">");
-    }
-    if ($offset+$pagesize<$count) {
-        my $nextpage =$offset+$pagesize;
-        $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
+    $template->param( loop => \@loop_data );
+    $template->param(
+        edit_tagfield      => $tagfield,
+        edit_frameworkcode => $frameworkcode
+    );
+
+    if ( $offset > 0 ) {
+        my $prevpage = $offset - $pagesize;
+        $template->param(
+            prev => "<a href=\"$script_name?offset=$prevpage\">" );
+    }
+    if ( $offset + $pagesize < $count ) {
+        my $nextpage = $offset + $pagesize;
+        $template->param(
+            next => "<a href=\"$script_name?offset=$nextpage\">" );
     }
 } #---- END $OP eq DEFAULT
-$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+$template->param(
+    intranetcolorstylesheet =>
+      C4::Context->preference("intranetcolorstylesheet"),
         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
         IntranetNav => C4::Context->preference("IntranetNav"),
-        );
+);
 output_html_with_http_headers $input, $cookie, $template->output;

Index: authorities/auth_finder.pl
===================================================================
RCS file: /sources/koha/koha/authorities/auth_finder.pl,v
retrieving revision 1.11.2.2
retrieving revision 1.11.2.3
diff -u -b -r1.11.2.2 -r1.11.2.3
--- authorities/auth_finder.pl	30 Nov 2006 18:23:51 -0000	1.11.2.2
+++ authorities/auth_finder.pl	5 Dec 2006 11:35:29 -0000	1.11.2.3
@@ -88,8 +88,8 @@
 
 	my @field_data = ();
 
-
-	my @marclist_ini = $query->param('marclist'); # get marclist again, as the previous one has been modified by catalogsearch (mainentry replaced by field name
+    # get marclist again, as the previous one has been modified by catalogsearch
+    my @marclist_ini = $query->param('marclist');
 	for(my $i = 0 ; $i <= $#marclist ; $i++) {
 		push @field_data, { term => "marclist", val=>$marclist_ini[$i] };
 		push @field_data, { term => "and_or", val=>$and_or[$i] };

Index: authorities/auth_linker.pl
===================================================================
RCS file: /sources/koha/koha/authorities/auth_linker.pl,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- authorities/auth_linker.pl	30 Nov 2006 18:23:51 -0000	1.1.2.2
+++ authorities/auth_linker.pl	5 Dec 2006 11:35:29 -0000	1.1.2.3
@@ -89,8 +89,8 @@
 
 	my @field_data = ();
 
-
-	my @marclist_ini = $query->param('marclist'); # get marclist again, as the previous one has been modified by catalogsearch (mainentry replaced by field name
+    # get marclist again, as the previous one has been modified by catalogsearch
+    my @marclist_ini = $query->param('marclist');
 	for(my $i = 0 ; $i <= $#marclist ; $i++) {
 		push @field_data, { term => "marclist", val=>$marclist_ini[$i] };
 		push @field_data, { term => "and_or", val=>$and_or[$i] };

Index: bookshelves/addbookbybiblionumber.pl
===================================================================
RCS file: /sources/koha/koha/bookshelves/addbookbybiblionumber.pl,v
retrieving revision 1.4.2.4
retrieving revision 1.4.2.5
diff -u -b -r1.4.2.4 -r1.4.2.5
--- bookshelves/addbookbybiblionumber.pl	30 Nov 2006 18:23:51 -0000	1.4.2.4
+++ bookshelves/addbookbybiblionumber.pl	5 Dec 2006 11:35:29 -0000	1.4.2.5
@@ -20,7 +20,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: addbookbybiblionumber.pl,v 1.4.2.4 2006/11/30 18:23:51 toins Exp $
+# $Id: addbookbybiblionumber.pl,v 1.4.2.5 2006/12/05 11:35:29 toins Exp $
 
 =head1 NAME
 
@@ -90,7 +90,7 @@
     print "Content-Type: text/html\n\n<html><body onload=\"window.close()\"></body></html>";
     exit;
 } else {    # this shelf doesn't already exist.
-    my  ( $bibliocount, @biblios )  = getbiblio($biblionumber);
+    my  ( $bibliocount, @biblios )  = GetBiblio($biblionumber);
 
     my ($shelflist) = GetShelves($loggedinuser,3);
     my @shelvesloop;
@@ -122,6 +122,11 @@
 }
 
 # $Log: addbookbybiblionumber.pl,v $
+# Revision 1.4.2.5  2006/12/05 11:35:29  toins
+# Biblio.pm cleaned.
+# additionalauthors, bibliosubject, bibliosubtitle tables are now unused.
+# Some functions renamed according to the coding guidelines.
+#
 # Revision 1.4.2.4  2006/11/30 18:23:51  toins
 # theses scripts don't need to use C4::Search.
 #

Index: C4/Biblio.pm
===================================================================
RCS file: /sources/koha/koha/C4/Biblio.pm,v
retrieving revision 1.178.2.32
retrieving revision 1.178.2.33
diff -u -b -r1.178.2.32 -r1.178.2.33
--- C4/Biblio.pm	4 Dec 2006 17:39:57 -0000	1.178.2.32
+++ C4/Biblio.pm	5 Dec 2006 11:35:29 -0000	1.178.2.33
@@ -1,5 +1,5 @@
 package C4::Biblio;
-# New subs added by tgarip at neu.edu.tr 05/11/05
+
 # Copyright 2000-2002 Katipo Communications
 #
 # This file is part of Koha.
@@ -18,7 +18,6 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
-use warnings; no warnings 'uninitialized';
 
 require Exporter;
 use C4::Context;
@@ -34,57 +33,90 @@
 use vars qw($VERSION @ISA @EXPORT);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.178.2.32 $' =~ /\d+/g; shift(@v).".".join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.178.2.33 $' =~ /\d+/g; shift(@v).".".join( "_", map { sprintf "%03d", $_ } @v ); };
 
- at ISA = qw(Exporter);
+ at ISA = qw( Exporter );
 
- at EXPORT = qw(
-  &AddBiblio &AddItem
-  &ModBiblio &ModItem
-  &DelBiblio &DelItem
-  &ModBiblioframework
-  &bibdata
-  &PrepareItemrecordDisplay
-  &updateBiblio &updateBiblioItem &updateItem
-  &itemcount &newbiblio &newbiblioitem
-  &modnote &newsubject &newsubtitle
-  &modbiblio &checkitems
-  &newitems &modbibitem
-  &modsubtitle &modsubject &modaddauthor &moditem &countitems
-  &delitem &deletebiblioitem &delbiblio
-  &getbiblio &getstacks
+# EXPORTED FUNCTIONS.
+
+# to add biblios or items
+push @EXPORT, qw( &AddBiblio &AddItem );
+
+# to get something
+push @EXPORT, qw(
+  &GetBiblio
+  &GetBiblioData
+  &GetBiblioItemData
+  &GetBiblioItemInfosOf
   &GetBiblioItemByBiblioNumber
-  &getbiblioitembybiblionumber
-  &getbibliofromitemnumber
+  &GetBiblioFromItemNumber
+  
+  &GetItemInfosOf
+  &GetItemStatus
+  &GetItemLocation
+
   &GetItemsInfo
   &GetItemFromBarcode
-  &getbiblioitem &getitemsbybiblioitem
-  &skip &getitemtypes
+  &getitemsbybiblioitem
   &get_itemnumbers_of
+);
+
+# To modify something
+push @EXPORT, qw(
+  &ModBiblio
+  &ModItem
+  &ModBiblioframework
+);
+
+# To delete something
+push @EXPORT, qw(
+  &DelBiblio
+  &DelItem
+);
+
+# Marc related functions
+push @EXPORT, qw(
   &MARCfind_marc_from_kohafield
-  &MARCfindsubfield
   &MARCfind_frameworkcode
   &MARCgettagslib
   &MARCmoditemonefield
-  &zebraop
-  &MARCaddbiblio &MARCadditem &MARCmodLCindex
-  &MARCmodsubfield
-  &MARCmodbiblio &MARCmoditem
-  &MARCkoha2marcBiblio &MARCmarc2koha
-  &MARCkoha2marcItem &MARChtml2marc &MARChtml2xml
-  &MARCgetbiblio &MARCgetitem &XMLgetbiblio
-  &MARCaddword &MARCdelword 
+  &MARCaddbiblio
+  &MARCadditem
+  &MARCmodbiblio
+  &MARCmoditem
+  &MARCkoha2marcBiblio
+  &MARCmarc2koha
+  &MARCkoha2marcItem
+  &MARChtml2marc
+  &MARChtml2xml
+  &MARCgetitem
+  &MARCaddword
+  &MARCdelword
   &MARCdelsubfield
+  &GetMarcNotes
+  &GetMarcSubjects
+  &GetMarcBiblio
+  &GetMarcAuthors
+);
+
+# Others functions
+push @EXPORT, qw(
+  &PrepareItemrecordDisplay
+  &zebraop
   &char_decode
-  &DisplayISBN
-  &itemcalculator &calculatelc
-  &GetItemInfosOf &GetItemStatus &GetItemLocation
-  &GetBiblioItemInfosOf
-  &bibitemdata
-  &itemissues
-  &addauthor
-  &getMARCnotes
-  &getMARCsubjects
+  &itemcalculator
+  &calculatelc
+);
+
+# OLD functions,
+push @EXPORT, qw(
+  &newbiblio
+  &newbiblioitem
+  &newitems
+  &modbiblio
+  &modbibitem
+  &moditem
+  &checkitems
 );
 
 =head1 NAME
@@ -97,11 +129,11 @@
 
 =over 4
 
-1. in the biblio,biblioitems,items, etc tables, which are limited to a one-to-one mapping to underlying MARC data
+=item 1. in the biblio,biblioitems,items, etc tables, which are limited to a one-to-one mapping to underlying MARC data
 
-2. as raw MARC in the Zebra index and storage engine
+=item 2. as raw MARC in the Zebra index and storage engine
 
-3. as raw MARC the biblioitems.marc
+=item 3. as raw MARC the biblioitems.marc
 
 =back
 
@@ -111,9 +143,9 @@
 
 =over 4
 
-1. Compared with MySQL, Zebra is slow to update an index for small data changes -- especially for proc-intensive operations like circulation
+=item 1. Compared with MySQL, Zebra is slow to update an index for small data changes -- especially for proc-intensive operations like circulation
 
-2. Zebra's index has been known to crash and a backup of the data is necessary to rebuild it in such cases
+=item 2. Zebra's index has been known to crash and a backup of the data is necessary to rebuild it in such cases
 
 =back
 
@@ -121,17 +153,17 @@
 
 =over 4
 
-1. Add*/Mod*/Del*/ - high-level external functions suitable for being called from external scripts to manage the collection
+=item 1. Add*/Mod*/Del*/ - high-level external functions suitable for being called from external scripts to manage the collection
 
-2. _koha_* - low-level internal functions for managing the koha tables
+=item 2. _koha_* - low-level internal functions for managing the koha tables
 
-3. MARC* functions for interacting with the MARC data in both biblioitems.marc Zebra (biblioitems.marc is authoritative)
+=item 3. MARC* functions for interacting with the MARC data in both biblioitems.marc Zebra (biblioitems.marc is authoritative)
 
-4. Zebra functions used to update the Zebra index
+=item 4. Zebra functions used to update the Zebra index
 
-5. internal helper functions such as char_decode, checkitems, etc. Some of these probably belong in Koha.pm
+=item 5. internal helper functions such as char_decode, checkitems, etc. Some of these probably belong in Koha.pm
 
-6. other functions that don't belong in Biblio.pm that will be cleaned out in time. (like MARCfind_marc_from_kohafield which belongs in Search.pm)
+=item 6. other functions that don't belong in Biblio.pm that will be cleaned out in time. (like MARCfind_marc_from_kohafield which belongs in Search.pm)
 
 In time, as we solidify the new API these older functions will be weeded out.
 
@@ -141,104 +173,83 @@
 
 =head2 AddBiblio
 
-=over 4
-
-($biblionumber,$oldbibnum,$oldbibitemnum) = AddBiblio($dbh,$record,$frameworkcode);
+($biblionumber,$oldbibnum,$oldbibitemnum) = AddBiblio($record,$frameworkcode);
 
 Exported function (core API) for adding a new biblio to koha.
 
-=back
-
 =cut
 
 sub AddBiblio {
-    my ( $dbh, $record, $frameworkcode) = @_;
+    my ( $record, $frameworkcode ) = @_;
     my $oldbibnum;
     my $oldbibitemnum;
-
+    my $dbh = C4::Context->dbh;
     # transform the data into koha-table style data
-    my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
-    $oldbibnum = _koha_add_biblio( $dbh, $olddata,$frameworkcode );
+    my $olddata = MARCmarc2koha( $dbh, $record, $frameworkcode );
+    $oldbibnum = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
     $olddata->{'biblionumber'} = $oldbibnum;
     $oldbibitemnum = _koha_add_biblioitem( $dbh, $olddata );
 
-    # search subtiles, addiauthors and subjects
-    my ( $tagfield, $tagsubfield ) = MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
-    my @addiauthfields = $record->field($tagfield);
-    foreach my $addiauthfield (@addiauthfields) {
-        my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
-        foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
-            _koha_modify_additionalauthor( $dbh, $oldbibnum, $addiauthsubfields[$subfieldcount] );
-        }
-    }
-    ( $tagfield, $tagsubfield ) = MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.subtitle",$frameworkcode );
-    my @subtitlefields = $record->field($tagfield);
-    foreach my $subtitlefield (@subtitlefields) {
-        my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
-        foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
-            _koha_add_subtitle( $dbh, $oldbibnum, $subtitlesubfields[$subfieldcount] );
-        }
-    }
-    ( $tagfield, $tagsubfield ) = MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
-    my @subj = $record->field($tagfield);
-    my @subjects;
-    foreach my $subject (@subj) {
-        my @subjsubfield = $subject->subfield($tagsubfield);
-        foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
-            push @subjects, $subjsubfield[$subfieldcount];
-        }
-    }
-    _koha_modify_subject( $dbh, $oldbibnum, 1, @subjects );
-
     # we must add bibnum and bibitemnum in MARC::Record...
     # we build the new field with biblionumber and biblioitemnumber
     # we drop the original field
     # we add the new builded field.
     # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
     # (steve and paul : thinks 090 is a good choice)
-    my $sth = $dbh->prepare("SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE kohafield=?");
+    my $sth =
+      $dbh->prepare(
+        "SELECT tagfield,tagsubfield
+         FROM marc_subfield_structure
+         WHERE kohafield=?"
+      );
     $sth->execute("biblio.biblionumber");
     ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
     $sth->execute("biblioitems.biblioitemnumber");
    ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
 
     my $newfield;
+
     # biblionumber & biblioitemnumber are in different fields
     if ( $tagfield1 != $tagfield2 ) {
+
         # deal with biblionumber
-        if ($tagfield1<10) {
-            $newfield = MARC::Field->new(
-                $tagfield1, $oldbibnum,
-            );
-        } else {
-            $newfield = MARC::Field->new(
-                $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
-            );
+        if ( $tagfield1 < 10 ) {
+            $newfield = MARC::Field->new( $tagfield1, $oldbibnum, );
+        }
+        else {
+            $newfield =
+              MARC::Field->new( $tagfield1, '', '',
+                "$tagsubfield1" => $oldbibnum, );
         }
+
         # drop old field and create new one...
         my $old_field = $record->field($tagfield1);
         $record->delete_field($old_field);
         $record->append_fields($newfield);
+
         # deal with biblioitemnumber
-        if ($tagfield2<10) {
-            $newfield = MARC::Field->new(
-                $tagfield2, $oldbibitemnum,
-            );
-        } else {
-            $newfield = MARC::Field->new(
-                $tagfield2, '', '', "$tagsubfield2" => $oldbibitemnum,
-            );
+        if ( $tagfield2 < 10 ) {
+            $newfield = MARC::Field->new( $tagfield2, $oldbibitemnum, );
+        }
+        else {
+            $newfield =
+              MARC::Field->new( $tagfield2, '', '',
+                "$tagsubfield2" => $oldbibitemnum, );
         }
         # drop old field and create new one...
         $old_field = $record->field($tagfield2);
         $record->delete_field($old_field);
         $record->insert_fields_ordered($newfield);
-    # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
-    } else {
+
+# biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
+    }
+    else {
         my $newfield = MARC::Field->new(
-            $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
+            $tagfield1, '', '',
+            "$tagsubfield1" => $oldbibnum,
             "$tagsubfield2" => $oldbibitemnum
         );
+
         # drop old field and create new one...
         my $old_field = $record->field($tagfield1);
         $record->delete_field($old_field);
@@ -246,173 +257,150 @@
     }
 
     ###NEU specific add cataloguers cardnumber as well
-    my $cardtag=C4::Context->preference('cataloguersfield');
+    my $cardtag = C4::Context->preference('cataloguersfield');
     if ($cardtag) {
-        my $tag=substr($cardtag,0,3);
-        my $subf=substr($cardtag,3,1);
-        my $me= C4::Context->userenv;
-        my $cataloger=$me->{'cardnumber'} if ($me);
-        my $newtag=  MARC::Field->new($tag, '', '', $subf => $cataloger) if ($me);
+        my $tag  = substr( $cardtag, 0, 3 );
+        my $subf = substr( $cardtag, 3, 1 );
+        my $me        = C4::Context->userenv;
+        my $cataloger = $me->{'cardnumber'} if ($me);
+        my $newtag    = MARC::Field->new( $tag, '', '', $subf => $cataloger )
+          if ($me);
         $record->delete_field($newtag);
         $record->insert_fields_ordered($newtag);
     }
 
     # now add the record
-    my $biblionumber = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
+    my $biblionumber =
+      MARCaddbiblio( $record, $oldbibnum, $frameworkcode );
     return ( $biblionumber, $oldbibnum, $oldbibitemnum );
 }
 
 =head2 AddItem
 
-=over 4
-
-$biblionumber = AddItem( $dbh, $record, $biblionumber)
+$biblionumber = AddItem( $record, $biblionumber)
 
 Exported function (core API) for adding a new item to Koha
 
-=back
-
 =cut
 
 sub AddItem {
-    my ( $dbh, $record, $biblionumber ) = @_;
+    my ( $record, $biblionumber ) = @_;
+    my $dbh = C4::Context->dbh;
+    
     # add item in old-DB
-    my $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
-    my $item = &MARCmarc2koha( $dbh, $record,$frameworkcode );
+    my $frameworkcode = MARCfind_frameworkcode( $dbh, $biblionumber );
+    my $item = &MARCmarc2koha( $dbh, $record, $frameworkcode );
+
     # needs old biblionumber and biblioitemnumber
     $item->{'biblionumber'} = $biblionumber;
     my $sth =
       $dbh->prepare(
-        "select biblioitemnumber,itemtype from biblioitems where biblionumber=?");
+        "select biblioitemnumber,itemtype from biblioitems where biblionumber=?"
+      );
     $sth->execute( $item->{'biblionumber'} );
     my $itemtype;
     ( $item->{'biblioitemnumber'}, $itemtype ) = $sth->fetchrow;
-    $sth=$dbh->prepare("select notforloan from itemtypes where itemtype='$itemtype'");
+    $sth =
+      $dbh->prepare(
+        "select notforloan from itemtypes where itemtype='$itemtype'");
     $sth->execute();
-    my $notforloan=$sth->fetchrow;
+    my $notforloan = $sth->fetchrow;
     ##Change the notforloan field if $notforloan found
-    if ($notforloan >0){
-        $item->{'notforloan'}=$notforloan;
-        &MARCitemchange($dbh,$record,"items.notforloan",$notforloan);
+    if ( $notforloan > 0 ) {
+        $item->{'notforloan'} = $notforloan;
+        &MARCitemchange( $record, "items.notforloan", $notforloan );
     }
-    if(!$item->{'dateaccessioned'}||$item->{'dateaccessioned'} eq ''){
+    if ( !$item->{'dateaccessioned'} || $item->{'dateaccessioned'} eq '' ) {
+
         # find today's date
-        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
-            localtime(time); $year +=1900; $mon +=1;
-        my $date = "$year-".sprintf ("%0.2d", $mon)."-".sprintf("%0.2d",$mday);
-        $item->{'dateaccessioned'}=$date;
-        &MARCitemchange($dbh,$record,"items.dateaccessioned",$date);
+        my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
+          localtime(time);
+        $year += 1900;
+        $mon  += 1;
+        my $date =
+          "$year-" . sprintf( "%0.2d", $mon ) . "-" . sprintf( "%0.2d", $mday );
+        $item->{'dateaccessioned'} = $date;
+        &MARCitemchange( $record, "items.dateaccessioned", $date );
     }
-    my ( $itemnumber, $error ) = &_koha_new_items( $dbh, $item, $item->{barcode} );
+    my ( $itemnumber, $error ) =
+      &_koha_new_items( $dbh, $item, $item->{barcode} );
+
     # add itemnumber to MARC::Record before adding the item.
     $sth =
       $dbh->prepare(
 "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
     );
-    &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,$frameworkcode );
+    &MARCkoha2marcOnefield( $sth, $record, "items.itemnumber", $itemnumber,
+        $frameworkcode );
 
     ##NEU specific add cataloguers cardnumber as well
-    my $cardtag=C4::Context->preference('itemcataloguersubfield');
-    if ($cardtag){
-        $sth->execute($frameworkcode,"items.itemnumber");
-        my ($itemtag,$subtag)=$sth->fetchrow;
-        my $me= C4::Context->userenv;
-        my $cataloguer=$me->{'cardnumber'} if ($me);
-        my $newtag= $record->field($itemtag);
-        $newtag->update($cardtag=>$cataloguer) if ($me);
+    my $cardtag = C4::Context->preference('itemcataloguersubfield');
+    if ($cardtag) {
+        $sth->execute( $frameworkcode, "items.itemnumber" );
+        my ( $itemtag, $subtag ) = $sth->fetchrow;
+        my $me         = C4::Context->userenv;
+        my $cataloguer = $me->{'cardnumber'} if ($me);
+        my $newtag     = $record->field($itemtag);
+        $newtag->update( $cardtag => $cataloguer ) if ($me);
         $record->delete_field($newtag);
         $record->append_fields($newtag);
     }
+
     # add the item
-    &MARCadditem( $dbh, $record, $item->{'biblionumber'},$frameworkcode );
+    &MARCadditem( $record, $item->{'biblionumber'},$frameworkcode );
     return ($item->{biblionumber}, $item->{biblioitemnumber},$itemnumber);
 }
 
 =head2 ModBiblio
 
-=over 4
-
-ModBiblio($dbh,$record,$biblionumber,$frameworkcode);
+ModBiblio( $record,$biblionumber,$frameworkcode);
 
 Exported function (core API) to modify a biblio
 
-=back
-
 =cut
 
 sub ModBiblio {
-    my ($dbh,$record,$biblionumber,$frameworkcode) =@_;
+    my ( $record, $biblionumber, $frameworkcode ) = @_;
+    my $dbh = C4::Context->dbh;
 
-    $frameworkcode="" unless $frameworkcode;
+    $frameworkcode = "" unless $frameworkcode;
 
     # update the MARC record with the new record data
-    &MARCmodbiblio($dbh,$biblionumber,$record,$frameworkcode,1);
+    &MARCmodbiblio( $dbh, $biblionumber, $record, $frameworkcode, 1 );
 
     # load the koha-table data object
-    my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
+    my $oldbiblio = MARCmarc2koha( $dbh, $record, $frameworkcode );
 
     # modify the other koha tables
-    my $oldbiblionumber = _koha_modify_biblio($dbh,$oldbiblio);
-    _koha_modify_biblioitem($dbh,$oldbiblio);
+    my $oldbiblionumber = _koha_modify_biblio( $dbh, $oldbiblio );
+    _koha_modify_biblioitem( $dbh, $oldbiblio );
 
-    # now, modify addi authors, subject, addititles.
-    my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
-    my @addiauthfields = $record->field($tagfield);
-    foreach my $addiauthfield (@addiauthfields) {
-        my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
-        foreach my $subfieldcount (0..$#addiauthsubfields) {
-            _koha_modify_additionalauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
-        }
-    }
-    ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
-    my @subtitlefields = $record->field($tagfield);
-    foreach my $subtitlefield (@subtitlefields) {
-        my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
-        # delete & create subtitle again because _koha_modify_subtitle can't handle new subtitles
-        # between 2 modifs
-        $dbh->do("DELETE FROM bibliosubtitle WHERE biblionumber=$oldbiblionumber");
-        foreach my $subfieldcount (0..$#subtitlesubfields) {
-            foreach my $subtit(split /\||#/,$subtitlesubfields[$subfieldcount]) {
-                _koha_add_subtitle($dbh,$oldbiblionumber,$subtit);
-            }
-        }
-    }
-    ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
-    my @subj = $record->field($tagfield);
-    my @subjects;
-    foreach my $subject (@subj) {
-        my @subjsubfield = $subject->subfield($tagsubfield);
-        foreach my $subfieldcount (0..$#subjsubfield) {
-            push @subjects,$subjsubfield[$subfieldcount];
-        }
-    }
-    _koha_modify_subject($dbh,$oldbiblionumber,1, at subjects);
     return 1;
 }
 
 =head2 ModItem
 
-=over 4
-
 Exported function (core API) for modifying an item in Koha.
 
-=back
-
 =cut
 
 sub ModItem {
-    my ( $dbh, $record, $biblionumber, $itemnumber, $delete, $new_item_hashref) = @_;
+    my ( $record, $biblionumber, $itemnumber, $delete, $new_item_hashref )
+      = @_;
+    my $dbh = C4::Context->dbh;
+    
     # if we have a MARC record, we're coming from cataloging and so
     # we do the whole routine: update the MARC and zebra, then update the koha
     # tables
     if ($record) {
-        MARCmoditem( $dbh, $record, $biblionumber, $itemnumber, $delete );
-    my $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
-    my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
+        MARCmoditem( $record, $biblionumber, $itemnumber, $delete );
+        my $frameworkcode = MARCfind_frameworkcode( $dbh, $biblionumber );
+        my $olditem       = MARCmarc2koha( $dbh, $record, $frameworkcode );
     _koha_modify_item( $dbh, $olditem );
-        $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
+        $frameworkcode    = MARCfind_frameworkcode( $dbh, $biblionumber );
         return $biblionumber;
     }
+
     # otherwise, we're just looking to modify something quickly
     # (like a status) so we just update the koha tables
     elsif ($new_item_hashref) {
@@ -420,9 +408,25 @@
     }
 }
 
-=head2 DelBiblio
+=head2 ModBiblioframework
 
-=over 4
+ModBiblioframework($biblionumber,$frameworkcode);
+
+Exported function to modify a biblio framework
+
+=cut
+
+sub ModBiblioframework {
+    my ( $biblionumber, $frameworkcode ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth =
+      $dbh->prepare(
+        "UPDATE biblio SET frameworkcode=? WHERE biblionumber=$biblionumber");
+    $sth->execute($frameworkcode);
+    return 1;
+}
+
+=head2 DelBiblio
 
 my $error = &DelBiblio($dbh,$biblionumber);
 
@@ -437,24 +441,29 @@
 return:
 C<$error> : undef unless an error occurs
 
-=back
-
 =cut
 
 sub DelBiblio {
-    my ( $dbh, $biblionumber ) = @_;
+    my ( $biblionumber ) = @_;
+    my $dbh = C4::Context->dbh;
     my $error; # for error handling
 
     # First make sure there are no items with issues are still attached
-    my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
+    my $sth =
+      $dbh->prepare(
+        "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
     $sth->execute($biblionumber);
     while ( my $biblioitemnumber = $sth->fetchrow ) {
         my @issues = itemissues($biblioitemnumber);
         foreach my $issue (@issues) {
-            if ( ($issue->{date_due}) && ($issue->{date_due} ne "Available") ) {
-                #FIXME: we need a status system in Biblio like in Circ to return standard codes and messages
-                # instead of hard-coded strings
-                $error.="Item is checked out to a patron -- you must return it before deleting the Biblio";
+            if (   ( $issue->{date_due} )
+                && ( $issue->{date_due} ne "Available" ) )
+            {
+
+#FIXME: we need a status system in Biblio like in Circ to return standard codes and messages
+# instead of hard-coded strings
+                $error .=
+"Item is checked out to a patron -- you must return it before deleting the Biblio";
             }
         }
     }
@@ -462,16 +471,19 @@
 
     # Delete from Zebra
     # get the xml of the record from Zebra
-    my $xmlrecord = getRecord("biblioserver","Local-number=$biblionumber");
+    my $xmlrecord = getRecord( "biblioserver", "Local-number=$biblionumber" );
     my $serviceOptions;
-    $serviceOptions->{'databaseName'} = "biblios";
+    $serviceOptions->{'databaseName'} = "biblios";  # FIXME :: hardcoded value
     $serviceOptions->{'record'} = $xmlrecord;
-    $error = &z3950_extended_services("biblioserver","update","recordDelete",$serviceOptions);
+    $error                            =
+      &z3950_extended_services( "biblioserver", "update", "recordDelete",
+        $serviceOptions );
     return $error if $error;
 
     # run commit operation
     #if ( (C4::Context->preference("commitImmediately")) ) {
-    $error = &z3950_extended_services("biblioserver","commit");
+    $error = &z3950_extended_services( "biblioserver", "commit" );
+
     #}
     zebraop($dbh,$biblionumber,"recordDelete","biblioserver");
     return $error if $error;
@@ -480,8 +492,10 @@
     $error = &_koha_delete_biblio( $dbh, $biblionumber );
     return $error if $error;
 
-    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
-    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
+# delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
+    $sth =
+      $dbh->prepare(
+        "SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
     $sth->execute($biblionumber);
     while ( my $biblioitemnumber = $sth->fetchrow ) {
 
@@ -490,52 +504,44 @@
         return $error if $error;
 
         # delete items
-        my $items_sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblioitemnumber=?");
+        my $items_sth =
+          $dbh->prepare(
+            "SELECT itemnumber FROM items WHERE biblioitemnumber=?");
         $items_sth->execute($biblioitemnumber);
         while ( my $itemnumber = $items_sth->fetchrow ) {
             $error = &_koha_delete_items( $dbh, $itemnumber );
             return $error if $error;
         }
     }
-    # delete from other koha tables
-    $sth = $dbh->prepare("DELETE FROM bibliosubject WHERE biblionumber=?");
-    $sth->execute($biblionumber);
-    $sth = $dbh->prepare("DELETE FROM additionalauthors WHERE biblionumber=?");
-    $sth->execute($biblionumber);
     return undef;
 }
 
-
 =head2 DelItem
 
-=over 4
-
-DelItem( $dbh, $biblionumber, $itemnumber );
+DelItem( $biblionumber, $itemnumber );
 
 Exported function (core API) for deleting an item record in Koha.
 
-=back
-
 =cut
 
 sub DelItem {
-    my ( $dbh, $biblionumber, $itemnumber ) = @_;
+    my ( $biblionumber, $itemnumber ) = @_;
+    my $dbh = C4::Context->dbh;
     &_koha_delete_item( $dbh, $itemnumber );
-    my $newrec=&MARCdelitem( $dbh, $biblionumber, $itemnumber );
-    &MARCaddbiblio($dbh,$newrec,$biblionumber,);
+    my $newrec = &MARCdelitem( $dbh, $biblionumber, $itemnumber );
+    &MARCaddbiblio( $newrec, $biblionumber, );
 }
 
+=head2 GetBiblioData
 
-=head2 bibdata
-
-  $data = &bibdata($biblionumber, $type);
+  $data = &GetBiblioData($biblionumber, $type);
 
 Returns information about the book with the given biblionumber.
 
 C<$type> is ignored.
 
-C<&bibdata> returns a reference-to-hash. The keys are the fields in
-the C<biblio>, C<biblioitems>, and C<bibliosubtitle> tables in the
+C<&GetBiblioData> returns a reference-to-hash. The keys are the fields in
+the C<biblio> and C<biblioitems> tables in the
 Koha database.
 
 In addition, C<$data-E<gt>{subject}> is the list of the book's
@@ -547,7 +553,7 @@
 =cut
 
 #'
-sub bibdata {
+sub GetBiblioData {
     my ( $bibnum, $type ) = @_;
     my $dbh = C4::Context->dbh;
 
@@ -555,7 +561,6 @@
         SELECT * , biblioitems.notes AS bnotes, biblio.notes
         FROM biblio
             LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
-            LEFT JOIN bibliosubtitle ON biblio.biblionumber = bibliosubtitle.biblionumber
             LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
         WHERE biblio.biblionumber = ?
             AND biblioitems.biblionumber = biblio.biblionumber
@@ -566,1415 +571,1799 @@
     $data = $sth->fetchrow_hashref;
     $sth->finish;
 
-    # handle management of repeated subtitle
-    $sth = $dbh->prepare("Select * from bibliosubtitle where biblionumber = ?");
-    $sth->execute($bibnum);
-    my @subtitles;
-    while ( my $dat = $sth->fetchrow_hashref ) {
-        my %line;
-        $line{subtitle} = $dat->{subtitle};
-        push @subtitles, \%line;
-    }    # while
-    $data->{subtitles} = \@subtitles;
-    $sth->finish;
-    $sth = $dbh->prepare("Select * from bibliosubject where biblionumber = ?");
-    $sth->execute($bibnum);
-    my @subjects;
-    while ( my $dat = $sth->fetchrow_hashref ) {
-        my %line;
-        $line{subject} = $dat->{'subject'};
-        push @subjects, \%line;
-    }    # while
-    $data->{subjects} = \@subjects;
-    $sth->finish;
-    $sth =
-      $dbh->prepare("Select * from additionalauthors where biblionumber = ?");
-    $sth->execute($bibnum);
-    while ( my $dat = $sth->fetchrow_hashref ) {
-        $data->{'additionalauthors'} .= "$dat->{'author'} - ";
-    }    # while
-    chop $data->{'additionalauthors'};
-    chop $data->{'additionalauthors'};
-    chop $data->{'additionalauthors'};
-    $sth->finish;
     return ($data);
-}    # sub bibdata
+}    # sub GetBiblioData
 
 
-=head2 z3950_extended_services
+=head2 GetItemsInfo
 
-=over 4
+  @results = &GetItemsInfo($biblionumber, $type);
 
-z3950_extended_services($serviceType,$serviceOptions,$record);
+Returns information about books with the given biblionumber.
 
-    z3950_extended_services is used to handle all interactions with Zebra's extended serices package, which is employed to perform all management of the MARC data stored in Zebra.
+C<$type> may be either C<intra> or anything else. If it is not set to
+C<intra>, then the search will exclude lost, very overdue, and
+withdrawn items.
 
-C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
+C<&GetItemsInfo> returns a list of references-to-hash. Each element
+contains a number of keys. Most of them are table items from the
+C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
+Koha database. Other keys include:
 
-C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
+=over 4
 
-    action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
+=item C<$data-E<gt>{branchname}>
 
-and maybe
+The name (not the code) of the branch to which the book belongs.
 
-    recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
-    syntax => the record syntax (transfer syntax)
-    databaseName = Database from connection object
+=item C<$data-E<gt>{datelastseen}>
 
-    To set serviceOptions, call set_service_options($serviceType)
+This is simply C<items.datelastseen>, except that while the date is
+stored in YYYY-MM-DD format in the database, here it is converted to
+DD/MM/YYYY format. A NULL date is returned as C<//>.
 
-C<$record> the record, if one is needed for the service type
+=item C<$data-E<gt>{datedue}>
 
-    A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
+=item C<$data-E<gt>{class}>
 
-=back
+This is the concatenation of C<biblioitems.classification>, the book's
+Dewey code, and C<biblioitems.subclass>.
 
-=cut
+=item C<$data-E<gt>{ocount}>
 
-sub z3950_extended_services {
-    my ($server,$serviceType,$action,$serviceOptions) = @_;
+I think this is the number of copies of the book available.
 
-    # get our connection object
-    my $Zconn = C4::Context->Zconn($server,0,1);
+=item C<$data-E<gt>{order}>
 
-    # create a new package object
-    my $Zpackage = $Zconn->package();
+If this is set, it is set to C<One Order>.
 
-    # set our options
-    $Zpackage->option(action => $action);
+=back
 
-    if ($serviceOptions->{'databaseName'}) {
-        $Zpackage->option(databaseName => $serviceOptions->{'databaseName'});
-    }
-    if ($serviceOptions->{'recordIdNumber'}) {
-        $Zpackage->option(recordIdNumber => $serviceOptions->{'recordIdNumber'});
-    }
-    if ($serviceOptions->{'recordIdOpaque'}) {
-        $Zpackage->option(recordIdOpaque => $serviceOptions->{'recordIdOpaque'});
-    }
+=cut
 
-    # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
-    #if ($serviceType eq 'itemorder') {
-    #   $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
-    #   $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
-    #   $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
-    #   $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
-    #}
+#'
+sub GetItemsInfo {
+    my ( $biblionumber, $type ) = @_;
+    my $dbh   = C4::Context->dbh;
+    my $query = "SELECT *,items.notforloan as itemnotforloan
+                 FROM items, biblio, biblioitems
+                 LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype
+                WHERE items.biblionumber = ?
+                    AND biblioitems.biblioitemnumber = items.biblioitemnumber
+                    AND biblio.biblionumber = items.biblionumber
+                ORDER BY items.dateaccessioned desc
+                 ";
+    my $sth = $dbh->prepare($query);
+    $sth->execute($biblionumber);
+    my $i = 0;
+    my @results;
+    my ( $date_due, $count_reserves );
+
+    while ( my $data = $sth->fetchrow_hashref ) {
+        my $datedue = '';
+        my $isth    = $dbh->prepare(
+            "SELECT issues.*,borrowers.cardnumber
+            FROM   issues, borrowers
+            WHERE  itemnumber = ?
+                AND returndate IS NULL
+                AND issues.borrowernumber=borrowers.borrowernumber"
+        );
+        $isth->execute( $data->{'itemnumber'} );
+        if ( my $idata = $isth->fetchrow_hashref ) {
+            $data->{borrowernumber} = $idata->{borrowernumber};
+            $data->{cardnumber}     = $idata->{cardnumber};
+            $datedue                = format_date( $idata->{'date_due'} );
+        }
+        if ( $datedue eq '' ) {
 
-    if ($serviceOptions->{record}) {
-        $Zpackage->option(record => $serviceOptions->{record});
+            #$datedue="Available";
+            my ( $restype, $reserves ) =
+              C4::Reserves2::CheckReserves( $data->{'itemnumber'} );
+            if ($restype) {
 
-        # can be xml or marc
-        if ($serviceOptions->{'syntax'}) {
-            $Zpackage->option(syntax => $serviceOptions->{'syntax'});
+                #$datedue=$restype;
+                $count_reserves = $restype;
         }
     }
+        $isth->finish;
 
-    # send the request, handle any exception encountered
-    eval { $Zpackage->send($serviceType) };
-        if ($@ && $@->isa("ZOOM::Exception")) {
-            return "error:  ".$@->code()." ".$@->message()."\n";
+        #get branch information.....
+        my $bsth = $dbh->prepare(
+            "SELECT * FROM branches WHERE branchcode = ?
+        "
+        );
+        $bsth->execute( $data->{'holdingbranch'} );
+        if ( my $bdata = $bsth->fetchrow_hashref ) {
+            $data->{'branchname'} = $bdata->{'branchname'};
         }
-    # free up package resources
-    $Zpackage->destroy();
-}
-
-=head2 set_service_options
-
-=over 4
+        my $date = format_date( $data->{'datelastseen'} );
+        $data->{'datelastseen'}   = $date;
+        $data->{'datedue'}        = $datedue;
+        $data->{'count_reserves'} = $count_reserves;
 
-my $serviceOptions = set_service_options($serviceType);
+        # get notforloan complete status if applicable
+        my $sthnflstatus = $dbh->prepare(
+            'SELECT authorised_value
+            FROM   marc_subfield_structure
+            WHERE  kohafield="items.notforloan"
+        '
+        );
 
-C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
+        $sthnflstatus->execute;
+        my ($authorised_valuecode) = $sthnflstatus->fetchrow;
+        if ($authorised_valuecode) {
+            $sthnflstatus = $dbh->prepare(
+                "SELECT lib FROM authorised_values
+                 WHERE  category=?
+                 AND authorised_value=?"
+            );
+            $sthnflstatus->execute( $authorised_valuecode,
+                $data->{itemnotforloan} );
+            my ($lib) = $sthnflstatus->fetchrow;
+            $data->{notforloan} = $lib;
+        }
 
-Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
+        # my stack procedures
+        my $stackstatus = $dbh->prepare(
+            'SELECT authorised_value
+             FROM   marc_subfield_structure
+             WHERE  kohafield="items.stack"
+        '
+        );
+        $stackstatus->execute;
 
-=back
+        ($authorised_valuecode) = $stackstatus->fetchrow;
+        if ($authorised_valuecode) {
+            $stackstatus = $dbh->prepare(
+                "SELECT lib
+                 FROM   authorised_values
+                 WHERE  category=?
+                 AND    authorised_value=?
+            "
+            );
+            $stackstatus->execute( $authorised_valuecode, $data->{stack} );
 
-=cut
+            my ($lib) = $stackstatus->fetchrow;
+            $data->{stack} = $lib;
+        }
+        $results[$i] = $data;
+        $i++;
+    }
+    $sth->finish;
 
-sub set_service_options {
-    my ($serviceType) = @_;
-    my $serviceOptions;
+    return (@results);
+}
+
+=head2 getitemstatus
 
-    # FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
-    #   $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
+  $itemstatushash = &getitemstatus($fwkcode);
+  returns information about status.
+  Can be MARC dependant.
+  fwkcode is optional.
+  But basically could be can be loan or not
+  Create a status selector with the following code
 
-    if ($serviceType eq 'commit') {
-    # nothing to do
-    }
-    if ($serviceType eq 'create') {
-    # nothing to do
-    }
-    if ($serviceType eq 'drop') {
-        die "ERROR: 'drop' not currently supported (by Zebra)";
-    }
-    return $serviceOptions;
+=head3 in PERL SCRIPT
+
+my $itemstatushash = getitemstatus;
+my @itemstatusloop;
+foreach my $thisstatus (keys %$itemstatushash) {
+    my %row =(value => $thisstatus,
+                statusname => $itemstatushash->{$thisstatus}->{'statusname'},
+            );
+    push @itemstatusloop, \%row;
 }
+$template->param(statusloop=>\@itemstatusloop);
 
-=head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
 
-=head2 MARCgettagslib
+=head3 in TEMPLATE  
+            <select name="statusloop">
+                <option value="">Default</option>
+            <!-- TMPL_LOOP name="statusloop" -->
+                <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
+            <!-- /TMPL_LOOP -->
+            </select>
 
 =cut
 
-sub MARCgettagslib {
-    my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
-    $frameworkcode = "" unless $frameworkcode;
-    my $sth;
-    my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
+sub GetItemStatus {
 
-    # check that framework exists
-    $sth =
-      $dbh->prepare(
-        "select count(*) from marc_tag_structure where frameworkcode=?");
-    $sth->execute($frameworkcode);
-    my ($total) = $sth->fetchrow;
-    $frameworkcode = "" unless ( $total > 0 );
-    $sth =
+    # returns a reference to a hash of references to status...
+    my ($fwk) = @_;
+    my %itemstatus;
+    my $dbh = C4::Context->dbh;
+    my $sth;
+    $fwk = '' unless ($fwk);
+    my ( $tag, $subfield ) =
+      MARCfind_marc_from_kohafield( $dbh, "items.notforloan", $fwk );
+    if ( $tag and $subfield ) {
+        my $sth =
       $dbh->prepare(
-"select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
+"select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
     );
-    $sth->execute($frameworkcode);
-    my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
-
-    while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) = $sth->fetchrow ) {
-        $res->{$tag}->{lib}        = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
-        $res->{$tab}->{tab}        = "";            # XXX
-        $res->{$tag}->{mandatory}  = $mandatory;
-        $res->{$tag}->{repeatable} = $repeatable;
-    }
-
-    $sth =
+        $sth->execute( $tag, $subfield, $fwk );
+        if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
+            my $authvalsth =
       $dbh->prepare(
-"select tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
+"select authorised_value, lib from authorised_values where category=? order by lib"
     );
-    $sth->execute($frameworkcode);
-
-    my $subfield;
-    my $authorised_value;
-    my $authtypecode;
-    my $value_builder;
-    my $kohafield;
-    my $seealso;
-    my $hidden;
-    my $isurl;
-    my $link;
+            $authvalsth->execute($authorisedvaluecat);
+            while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
+                $itemstatus{$authorisedvalue} = $lib;
+            }
+            $authvalsth->finish;
+            return \%itemstatus;
+            exit 1;
+        }
+        else {
 
-    while (
-        ( $tag,         $subfield,   $liblibrarian,   , $libopac,      $tab,
-        $mandatory,     $repeatable, $authorised_value, $authtypecode,
-        $value_builder, $kohafield,  $seealso,          $hidden,
-        $isurl,            $link )
-        = $sth->fetchrow
-      )
-    {
-        $res->{$tag}->{$subfield}->{lib}              = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
-        $res->{$tag}->{$subfield}->{tab}              = $tab;
-        $res->{$tag}->{$subfield}->{mandatory}        = $mandatory;
-        $res->{$tag}->{$subfield}->{repeatable}       = $repeatable;
-        $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
-        $res->{$tag}->{$subfield}->{authtypecode}     = $authtypecode;
-        $res->{$tag}->{$subfield}->{value_builder}    = $value_builder;
-        $res->{$tag}->{$subfield}->{kohafield}        = $kohafield;
-        $res->{$tag}->{$subfield}->{seealso}          = $seealso;
-        $res->{$tag}->{$subfield}->{hidden}           = $hidden;
-        $res->{$tag}->{$subfield}->{isurl}            = $isurl;
-        $res->{$tag}->{$subfield}->{link}            = $link;
+            #No authvalue list
+            # build default
+        }
+        $sth->finish;
     }
-    return $res;
-}
 
-=head2 MARCfind_marc_from_kohafield
+    #No authvalue list
+    #build default
+    $itemstatus{"1"} = "Not For Loan";
+    return \%itemstatus;
+}
 
-=cut
+=head2 getitemlocation
 
-sub MARCfind_marc_from_kohafield {
-    my ( $dbh, $kohafield,$frameworkcode ) = @_;
-    return 0, 0 unless $kohafield;
-    my $relations = C4::Context->marcfromkohafield;
-    return ($relations->{$frameworkcode}->{$kohafield}->[0],$relations->{$frameworkcode}->{$kohafield}->[1]);
-}
+  $itemlochash = &getitemlocation($fwk);
+  returns informations about location.
+  where fwk stands for an optional framework code.
+  Create a location selector with the following code
 
-=head2 MARCaddbiblio
+=head3 in PERL SCRIPT
 
-&MARCaddbiblio($dbh,$newrec,$biblionumber,$frameworkcode);
+my $itemlochash = getitemlocation;
+my @itemlocloop;
+foreach my $thisloc (keys %$itemlochash) {
+    my $selected = 1 if $thisbranch eq $branch;
+    my %row =(locval => $thisloc,
+                selected => $selected,
+                locname => $itemlochash->{$thisloc},
+            );
+    push @itemlocloop, \%row;
+}
+$template->param(itemlocationloop => \@itemlocloop);
 
-Add MARC data for a biblio to koha 
+=head3 in TEMPLATE  
+            <select name="location">
+                <option value="">Default</option>
+            <!-- TMPL_LOOP name="itemlocationloop" -->
+                <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
+            <!-- /TMPL_LOOP -->
+            </select>
 
 =cut
 
-sub MARCaddbiblio {
+sub GetItemLocation {
 
-# pass the MARC::Record to this function, and it will create the records in the marc tables
-    my ($dbh,$record,$biblionumber,$frameworkcode) = @_;
-    my @fields=$record->fields();
-    if (!$frameworkcode){
-        $frameworkcode="";
+    # returns a reference to a hash of references to location...
+    my ($fwk) = @_;
+    my %itemlocation;
+    my $dbh = C4::Context->dbh;
+    my $sth;
+    $fwk = '' unless ($fwk);
+    my ( $tag, $subfield ) =
+      MARCfind_marc_from_kohafield( $dbh, "items.location", $fwk );
+    if ( $tag and $subfield ) {
+        my $sth =
+          $dbh->prepare(
+"select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
+          );
+        $sth->execute( $tag, $subfield, $fwk );
+        if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
+            my $authvalsth =
+              $dbh->prepare(
+"select authorised_value, lib from authorised_values where category=? order by lib"
+              );
+            $authvalsth->execute($authorisedvaluecat);
+            while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
+                $itemlocation{$authorisedvalue} = $lib;
     }
-    my $sth = $dbh->prepare("update  biblio set frameworkcode=? where biblionumber=?" );
-    $sth->execute(  $frameworkcode,$biblionumber );
-    $sth->finish;
-    my $encoding = C4::Context->preference("marcflavour");
-    # deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
-    if ($encoding eq "UNIMARC") {
-        my $string;
-        if ($record->subfield(100,"a")) {
-            $string = $record->subfield(100,"a");
-            my $f100 = $record->field(100);
-            $record->delete_field($f100);
-        } else {
-            $string = POSIX::strftime("%Y%m%d", localtime);
-            $string=~s/\-//g;
-            $string = sprintf("%-*s",35, $string);
-        }
-        substr($string,22,6,"frey50");
-        unless ($record->subfield(100,"a")){
-            $record->insert_grouped_field(MARC::Field->new(100,"","","a"=>$string));
+            $authvalsth->finish;
+            return \%itemlocation;
+            exit 1;
         }
+        else {
+
+            #No authvalue list
+            # build default
     }
-    $sth =$dbh->prepare("update biblioitems set marc=?,marcxml=?  where biblionumber=?"   );
-    $sth->execute( $record->as_usmarc(),$record->as_xml_record() , $biblionumber);
-    warn $record->as_xml_record();
     $sth->finish;
-    zebraop($dbh,$biblionumber,"specialUpdate","biblioserver");
-    return $biblionumber;
+    }
+
+    #No authvalue list
+    #build default
+    $itemlocation{"1"} = "Not For Loan";
+    return \%itemlocation;
 }
 
-=head2 MARCadditem
+=head2 &GetBiblioItemData
 
-=cut
+  $itemdata = &&GetBiblioItemData($biblioitemnumber);
 
-sub MARCadditem {
-# pass the MARC::Record to this function, and it will create the records in the marc tables
-    my ($dbh,$record,$biblionumber,$frameworkcode) = @_;
-my $newrec=&MARCgetbiblio($dbh,$biblionumber);
+Looks up the biblioitem with the given biblioitemnumber. Returns a
+reference-to-hash. The keys are the fields from the C<biblio>,
+C<biblioitems>, and C<itemtypes> tables in the Koha database, except
+that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
 
-# 2nd recreate it
-    my @fields = $record->fields();
-     foreach my $field (@fields) {
-      $newrec->append_fields($field);
-    }
-    # FIXME: should we be making sure the biblionumbers are the same?
-    my $newbiblionumber=&MARCaddbiblio($dbh,$newrec,$biblionumber,$frameworkcode);
-    return $newbiblionumber;
-}
+=cut
 
-=head2 MARCgetbiblio
+#'
+sub GetBiblioItemData {
+    my ($bibitem) = @_;
+    my $dbh       = C4::Context->dbh;
+    my $sth       =
+      $dbh->prepare(
+"Select *,biblioitems.notes as bnotes from biblioitems, biblio,itemtypes where biblio.biblionumber = biblioitems.biblionumber and biblioitemnumber = ? and biblioitems.itemtype = itemtypes.itemtype"
+      );
+    my $data;
 
-Returns MARC::Record of the biblio passed in parameter.
+    $sth->execute($bibitem);
 
-=cut
+    $data = $sth->fetchrow_hashref;
 
-sub MARCgetbiblio {
-    my ( $dbh, $biblionumber ) = @_;
-    my $sth=$dbh->prepare("select marcxml from biblioitems where biblionumber=? "  );
-    $sth->execute($biblionumber);
-    my ($marcxml)=$sth->fetchrow;
-    $marcxml =~ s/\x1e//g;
-    $marcxml =~ s/\x1f//g;
-    $marcxml =~ s/\x1d//g;
-    $marcxml =~ s/\x0f//g;
-    my $record = MARC::Record->new();
-    $record = MARC::Record::new_from_xml( $marcxml,"utf8",C4::Context->preference('marcflavour')) if $marcxml;
-    return $record;
-}
+    $sth->finish;
+    return ($data);
+}    # sub &GetBiblioItemData
 
-=head2 XMLgetbiblio
+=head2 GetItemFromBarcode
 
-Returns MARC::XML of the biblio passed in parameter.
+$result = GetItemFromBarcode($barcode);
 
 =cut
 
-sub XMLgetbiblio {
-    my ( $dbh, $biblionumber ) = @_;
-    my $sth = $dbh->prepare("select marcxml from biblioitems where biblionumber=? "  );
+sub GetItemFromBarcode {
+    my ($barcode) = @_;
+    my $dbh = C4::Context->dbh;
 
-    $sth->execute($biblionumber);
-       my ($marcxml)=$sth->fetchrow;
-#     $marc=MARC::File::USMARC::decode($marc);
-    # print Dumper($marc);
-#     my $marcxml=$marc->as_xml_record();
-#     print Dumper($marcxml);
-     return $marcxml;
+    my $rq =
+      $dbh->prepare("SELECT itemnumber from items where items.barcode=?");
+    $rq->execute($barcode);
+    my ($result) = $rq->fetchrow;
+    return ($result);
 }
 
-=head2 MARCgetitem_frombarcode
+=head2 GetBiblioItemByBiblioNumber
+
+NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
 
 =cut
 
-sub MARCgetitem_frombarcode {
+sub GetBiblioItemByBiblioNumber {
+    my ($biblionumber) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
+    my $count = 0;
+    my @results;
 
-    my ( $dbh, $biblionumber, $barcode ) = @_;
-    my $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
-    # get the complete MARC record
+    $sth->execute($biblionumber);
     
-    my $record = MARCgetbiblio($dbh,$biblionumber);
-#    warn "ITEMRECORD".$record->as_formatted;
-    # now, find the relevant itemnumber
-    my ($itemnumberfield,$itemnumbersubfield) = MARCfind_marc_from_kohafield($dbh,'items.barcode','');
-    # prepare the new item record
-    my $itemrecord = MARC::Record->new();
-    # parse all fields fields from the complete record
-    foreach ($record->field($itemnumberfield)) {
-        # when the item field is found, save it
-#        warn "Itenumberfield = $itemnumberfield";
-        if ($_->subfield($itemnumbersubfield) == $barcode) {
-#            warn "Inside if subfield=$itemnumbersubfield";
-            $itemrecord->append_fields($_);
+    while ( my $data = $sth->fetchrow_hashref ) {
+        push @results, $data;
         }
-    }
-#    warn "ITEMS".$itemrecord->as_formatted;
-    return $itemrecord;
+
+    $sth->finish;
+    return @results;
 }
 
-=head2 MARCgetitem
+=head2 GetBiblioFromItemNumber
+
+  $item = &GetBiblioFromItemNumber($itemnumber);
+
+Looks up the item with the given itemnumber.
+
+C<&itemnodata> returns a reference-to-hash whose keys are the fields
+from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
+database.
 
 =cut
 
-sub MARCgetitem {
-    # Returns MARC::Record of the item passed in parameter.
-    my ( $dbh, $biblionumber, $itemnumber ) = @_;
-    my $newrecord = MARC::Record->new();
-    # retrieve the XML record
-    my $sth = $dbh->prepare("select marcxml from biblioitems where biblionumber=?"  );
-    $sth->execute($biblionumber);
-    my ($marcxml)=$sth->fetchrow;
-    my $record = MARC::Record->new();
-    $record = MARC::Record::new_from_xml( $marcxml,"utf8",C4::Context->preference('marcflavour'));
+#'
+sub GetBiblioFromItemNumber {
+    my ( $itemnumber ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $env;
+    my $sth = $dbh->prepare(
+        "SELECT * FROM biblio,items,biblioitems
+         WHERE items.itemnumber = ?
+           AND biblio.biblionumber = items.biblionumber
+           AND biblioitems.biblioitemnumber = items.biblioitemnumber"
+    );
     
-    # now, find where the itemnumber is stored & extract only the item
-    my ($itemnumberfield,$itemnumbersubfield) = MARCfind_marc_from_kohafield($dbh,'items.itemnumber','');
-    my @fields = $record->field($itemnumberfield);
-    foreach my $field (@fields) {
-        if ($field->subfield($itemnumbersubfield) eq $itemnumber ) {
-            $newrecord->insert_fields_ordered($field);
-        }
-    }
-    return $newrecord;
+    $sth->execute($itemnumber);
+    my $data = $sth->fetchrow_hashref;
+    $sth->finish;
+    return ($data);
 }
 
-=head2 MARCmodbiblio
+=head2 GetBiblio
 
-MARCmodbibio($dbh,$biblionumber,$record,$frameworkcode,1);
+( $count, @results ) = &GetBiblio($biblionumber);
 
-Modify a biblio record with the option to save items data
+=cut
+
+sub GetBiblio {
+    my ($biblionumber) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
+    my $count = 0;
+    my @results;
+    $sth->execute($biblionumber);
+    while ( my $data = $sth->fetchrow_hashref ) {
+        $results[$count] = $data;
+        $count++;
+    }    # while
+    $sth->finish;
+    return ( $count, @results );
+}    # sub GetBiblio
+
+=head2 getitemsbybiblioitem
+
+( $count, @results ) = &getitemsbybiblioitem($biblioitemnum);
 
 =cut
 
-sub MARCmodbiblio {
-    my ($dbh,$biblionumber,$record,$frameworkcode,$keep_items)=@_;
+sub getitemsbybiblioitem {
+    my ($biblioitemnum) = @_;
+    my $dbh             = C4::Context->dbh;
+    my $sth             = $dbh->prepare(
+        "Select * from items, biblio where
+biblio.biblionumber = items.biblionumber and biblioitemnumber
+= ?"
+    );
 
-    # delete original record but save the items
-    my $newrec=&MARCdelbiblio($dbh,$biblionumber,$keep_items);
+    # || die "Cannot prepare $query\n" . $dbh->errstr;
+    my $count = 0;
+    my @results;
 
-    # recreate it and add the new fields
-    my @fields = $record->fields();
-     foreach my $field (@fields) {
-        # this requires a more recent version of MARC::Record
-        # but ensures the fields are in order
-        $newrec->insert_fields_ordered($field);
-    }
+    $sth->execute($biblioitemnum);
 
-    # give back our old leader
-    $newrec->leader($record->leader());
-    # add the record back with the items info preserved
-    &MARCaddbiblio($dbh,$newrec,$biblionumber,$frameworkcode);
-}
+    # || die "Cannot execute $query\n" . $sth->errstr;
+    while ( my $data = $sth->fetchrow_hashref ) {
+        $results[$count] = $data;
+        $count++;
+    }    # while
 
-=head2 find_biblioitemnumber
+    $sth->finish;
+    return ( $count, @results );
+}    # sub getitemsbybiblioitem
 
-my $biblioitemnumber = find_biblioitemnumber($dbh,$biblionumber);
+=head2 get_itemnumbers_of
 
-=over 4
+  my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
 
-Returns the 1st biblioitemnumber related to $biblionumber. When MARC=ON we should have 1 biblionumber = 1 and only 1 biblioitemnumber
-This sub is useless when MARC=OFF
+Given a list of biblionumbers, return the list of corresponding itemnumbers
+for each biblionumber.
 
-=back
+Return a reference on a hash where keys are biblionumbers and values are
+references on array of itemnumbers.
 
 =cut
 
-sub find_biblioitemnumber {
-    my ( $dbh, $biblionumber ) = @_;
-    my $sth = $dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?");
-    $sth->execute($biblionumber);
-    my ($biblioitemnumber) = $sth->fetchrow;
-    return $biblioitemnumber;
-}
+sub get_itemnumbers_of {
+    my @biblionumbers = @_;
 
-=head2 MARCdelbiblio
+    my $dbh = C4::Context->dbh;
 
-=cut
+    my $query = '
+        SELECT itemnumber,
+            biblionumber
+        FROM items
+        WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
+    ';
+    my $sth = $dbh->prepare($query);
+    $sth->execute(@biblionumbers);
 
-sub MARCdelbiblio {
-    my ( $dbh, $biblionumber, $keep_items ) = @_;
+    my %itemnumbers_of;
 
-    # if the keep_item is set to 1, then all items are preserved.
-    # This flag is set when the delbiblio is called by modbiblio
-    # due to a too complex structure of MARC (repeatable fields and subfields),
-    # the best solution for a modif is to delete / recreate the record.
-
-# 1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
-# if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
-    # exist in deletedbiblio table
-    my $record = MARCgetbiblio( $dbh, $biblionumber );
-    my $oldbiblionumber = $biblionumber;
-    my $copy2deleted = $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
-    $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
- my @fields = $record->fields();
-  # now, delete in MARC tables.
-    if ( $keep_items eq 1 ) {
+    while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
+        push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
+    }
 
-        #search item field code
-        my $sth = $dbh->prepare("select tagfield from marc_subfield_structure where kohafield like 'items.%'");
-        $sth->execute;
-        my $itemtag = $sth->fetchrow_hashref->{tagfield};
+    return \%itemnumbers_of;
+}
 
+=head2 getRecord
 
-     foreach my $field (@fields) {
+$record = getRecord( $server, $koha_query, $recordSyntax );
 
-      if ($field->tag() ne $itemtag){
-    $record->delete_field($field);
-    }#if
-    }#foreach
-           }
-    else {
-   foreach my $field (@fields) {
+get a single record in piggyback mode from Zebra and return it in the requested record syntax
 
-    $record->delete_field($field);
+default record syntax is XML
+
+=cut
 
-    }#foreach
+sub getRecord {
+    my ( $server, $koha_query, $recordSyntax ) = @_;
+    $recordSyntax = "xml" unless $recordSyntax;
+    my $Zconn = C4::Context->Zconn( $server, 0, 1, 1, $recordSyntax );
+    my $rs = $Zconn->search( new ZOOM::Query::CCL2RPN( $koha_query, $Zconn ) );
+    if ( $rs->record(0) ) {
+        return $rs->record(0)->raw();
            }
-      return $record;     
 }
 
-=head2 MARCdelitem
+=head2 GetItemInfosOf
 
-delete the item field from the MARC record for the itemnumber specified
+GetItemInfosOf(@itemnumbers);
 
 =cut
 
-sub MARCdelitem {
-    my ( $dbh, $biblionumber, $itemnumber ) = @_;
+sub GetItemInfosOf {
+    my @itemnumbers = @_;
 
-    # get the MARC record
-    my $record = MARCgetbiblio( $dbh, $biblionumber);
+    my $query = '
+        SELECT *
+        FROM items
+        WHERE itemnumber IN (' . join( ',', @itemnumbers ) . ')
+    ';
+    return get_infos_of( $query, 'itemnumber' );
+}
 
-    # backup the record
-    my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
-    $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
+=head2 GetBiblioItemInfosOf
 
-    #search item field code
-    my $sth = $dbh->prepare("SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE kohafield LIKE 'items.itemnumber'");
-        $sth->execute;
-        my ($itemtag,$itemsubfield) = $sth->fetchrow;
- my @fields = $record->field($itemtag);
+GetBiblioItemInfosOf(@biblioitemnumbers);
  
-    # delete the item specified
-     foreach my $field (@fields) {
-      if ($field->subfield($itemsubfield) eq $itemnumber ){
-    $record->delete_field($field);
-        }
-    }
-return $record;
+=cut
+
+sub GetBiblioItemInfosOf {
+    my @biblioitemnumbers = @_;
+
+    my $query = '
+        SELECT biblioitemnumber,
+            publicationyear,
+            itemtype
+        FROM biblioitems
+        WHERE biblioitemnumber IN (' . join( ',', @biblioitemnumbers ) . ')
+    ';
+    return get_infos_of( $query, 'biblioitemnumber' );
 }
 
-=head2 MARCmoditemonefield
+=head2 z3950_extended_services
 
-=cut
+z3950_extended_services($serviceType,$serviceOptions,$record);
 
-sub MARCmoditemonefield{
-my ($dbh,$biblionumber,$itemnumber,$itemfield,$newvalue)=@_;
-if (!defined $newvalue){
-$newvalue="";
-}
+    z3950_extended_services is used to handle all interactions with Zebra's extended serices package, which is employed to perform all management of the MARC data stored in Zebra.
 
-my $record = MARCgetitem($dbh,$biblionumber,$itemnumber);
+C<$serviceType> one of: itemorder,create,drop,commit,update,xmlupdate
 
-my $sth =
-      $dbh->prepare(
-"select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
-    );
-    my $tagfield;
-    my $tagsubfield;
-    $sth->execute($itemfield);
-    if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
- my $tag = $record->field($tagfield);
+C<$serviceOptions> a has of key/value pairs. For instance, if service_type is 'update', $service_options should contain:
 
-        if ( $tag)  {
+    action => update action, one of specialUpdate, recordInsert, recordReplace, recordDelete, elementUpdate.
            
-        my $tagsubs=$record->field($tagfield)->subfield($tagsubfield);
+and maybe
            
-        $tag->update($tagsubfield =>$newvalue);
-        $record->delete_field($tag);
-                $record->insert_fields_ordered($tag);
+    recordidOpaque => Opaque Record ID (user supplied) or recordidNumber => Record ID number (system number).
+    syntax => the record syntax (transfer syntax)
+    databaseName = Database from connection object
     
-    &MARCmoditem($dbh,$record,$biblionumber,$itemnumber,0);
-    }
-     }    
+    To set serviceOptions, call set_service_options($serviceType)
 
-}
+C<$record> the record, if one is needed for the service type
 
-=head2 MARCmoditem
+    A record should be in XML. You can convert it to XML from MARC by running it through marc2xml().
 
 =cut
 
-sub MARCmoditem {
-    my ($dbh,$record,$biblionumber,$itemnumber,$delete)=@_;
+sub z3950_extended_services {
+    my ( $server, $serviceType, $action, $serviceOptions ) = @_;
 
-    # delete this item from MARC
-    my $newrec=&MARCdelitem($dbh,$biblionumber,$itemnumber);
+    # get our connection object
+    my $Zconn = C4::Context->Zconn( $server, 0, 1 );
 
-# 2nd recreate it
-    my @fields = $record->fields();
- ###NEU specific add cataloguers cardnumber as well
-my $cardtag=C4::Context->preference('itemcataloguersubfield');
+    # create a new package object
+    my $Zpackage = $Zconn->package();
 
-     foreach my $field (@fields) {
-    if ($cardtag){
-    my $me= C4::Context->userenv;
-    my $cataloguer=$me->{'cardnumber'} if ($me);
-    $field->update($cardtag=>$cataloguer) if ($me);
+    # set our options
+    $Zpackage->option( action => $action );
+
+    if ( $serviceOptions->{'databaseName'} ) {
+        $Zpackage->option( databaseName => $serviceOptions->{'databaseName'} );
     }
-      $newrec->append_fields($field);
+    if ( $serviceOptions->{'recordIdNumber'} ) {
+        $Zpackage->option(
+            recordIdNumber => $serviceOptions->{'recordIdNumber'} );
+    }
+    if ( $serviceOptions->{'recordIdOpaque'} ) {
+        $Zpackage->option(
+            recordIdOpaque => $serviceOptions->{'recordIdOpaque'} );
     }
-    &MARCaddbiblio($dbh,$newrec,$biblionumber);
 
-}
-=head2 MARCfind_frameworkcode
+ # this is an ILL request (Zebra doesn't support it, but Koha could eventually)
+ #if ($serviceType eq 'itemorder') {
+ #   $Zpackage->option('contact-name' => $serviceOptions->{'contact-name'});
+ #   $Zpackage->option('contact-phone' => $serviceOptions->{'contact-phone'});
+ #   $Zpackage->option('contact-email' => $serviceOptions->{'contact-email'});
+ #   $Zpackage->option('itemorder-item' => $serviceOptions->{'itemorder-item'});
+ #}
 
-=cut
+    if ( $serviceOptions->{record} ) {
+        $Zpackage->option( record => $serviceOptions->{record} );
 
-sub MARCfind_frameworkcode {
-    my ( $dbh, $biblionumber ) = @_;
-    my $sth = $dbh->prepare("select frameworkcode from biblio where biblionumber=?");
-    $sth->execute($biblionumber);
-    my ($frameworkcode) = $sth->fetchrow;
-    return $frameworkcode;
+        # can be xml or marc
+        if ( $serviceOptions->{'syntax'} ) {
+            $Zpackage->option( syntax => $serviceOptions->{'syntax'} );
+        }
+    }
+
+    # send the request, handle any exception encountered
+    eval { $Zpackage->send($serviceType) };
+    if ( $@ && $@->isa("ZOOM::Exception") ) {
+        return "error:  " . $@->code() . " " . $@->message() . "\n";
+    }
+
+    # free up package resources
+    $Zpackage->destroy();
 }
 
-=head MARCkoha2marcBiblio
+=head2 set_service_options
+
+my $serviceOptions = set_service_options($serviceType);
+
+C<$serviceType> itemorder,create,drop,commit,update,xmlupdate
+
+Currently, we only support 'create', 'commit', and 'update'. 'drop' support will be added as soon as Zebra supports it.
 
 =cut
 
-sub MARCkoha2marcBiblio {
+sub set_service_options {
+    my ($serviceType) = @_;
+    my $serviceOptions;
 
-    # this function builds partial MARC::Record from the old koha-DB fields
-    my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
-    my $sth =
-      $dbh->prepare(
-"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
-    );
-    my $record = MARC::Record->new();
+# FIXME: This needs to be an OID ... if we ever need 'syntax' this sub will need to change
+#   $serviceOptions->{ 'syntax' } = ''; #zebra doesn't support syntaxes other than xml
 
-    #--- if biblionumber, then retrieve old-style koha data
-    if ( $biblionumber > 0 ) {
-        my $sth2 =
-          $dbh->prepare(
-"select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
-        from biblio where biblionumber=?"
-        );
-        $sth2->execute($biblionumber);
-        my $row = $sth2->fetchrow_hashref;
-        my $code;
-        foreach $code ( keys %$row ) {
-            if ( $row->{$code} ) {
-                &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
-                    $row->{$code}, '');
+    if ( $serviceType eq 'commit' ) {
+
+        # nothing to do
             }
+    if ( $serviceType eq 'create' ) {
+
+        # nothing to do
         }
+    if ( $serviceType eq 'drop' ) {
+        die "ERROR: 'drop' not currently supported (by Zebra)";
     }
+    return $serviceOptions;
+}
 
-    #--- if biblioitem, then retrieve old-style koha data
-    if ( $biblioitemnumber > 0 ) {
-        my $sth2 =
+=head1 FUNCTIONS FOR HANDLING MARC MANAGEMENT
+
+=head2 MARCgettagslib
+
+=cut
+
+sub MARCgettagslib {
+    my ( $dbh, $forlibrarian, $frameworkcode ) = @_;
+    $frameworkcode = "" unless $frameworkcode;
+    my $sth;
+    my $libfield = ( $forlibrarian eq 1 ) ? 'liblibrarian' : 'libopac';
+
+    # check that framework exists
+    $sth =
           $dbh->prepare(
-            " SELECT biblioitemnumber,biblionumber,volume,number,classification,
-                        itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
-                        volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
-                    FROM biblioitems
-                    WHERE biblioitemnumber=?
-                    "
+        "select count(*) from marc_tag_structure where frameworkcode=?");
+    $sth->execute($frameworkcode);
+    my ($total) = $sth->fetchrow;
+    $frameworkcode = "" unless ( $total > 0 );
+    $sth =
+      $dbh->prepare(
+"select tagfield,liblibrarian,libopac,mandatory,repeatable from marc_tag_structure where frameworkcode=? order by tagfield"
         );
-        $sth2->execute($biblioitemnumber);
-        my $row = $sth2->fetchrow_hashref;
-        my $code;
-        foreach $code ( keys %$row ) {
-            if ( $row->{$code} ) {
-                &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
-                    $row->{$code},'' );
-            }
-        }
-    }
+    $sth->execute($frameworkcode);
+    my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
 
-    # other fields => additional authors, subjects, subtitles
-    my $sth2 =
-      $dbh->prepare(
-        " SELECT author FROM additionalauthors WHERE biblionumber=?");
-    $sth2->execute($biblionumber);
-    while ( my $row = $sth2->fetchrow_hashref ) {
-        &MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author",
-            $row->{'author'},'' );
-    }
-    $sth2 =
-      $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
-    $sth2->execute($biblionumber);
-    while ( my $row = $sth2->fetchrow_hashref ) {
-        &MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject",
-            $row->{'subject'},'' );
+    while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) =
+        $sth->fetchrow )
+    {
+        $res->{$tag}->{lib} =
+          ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
+        $res->{$tab}->{tab}        = "";            # XXX
+        $res->{$tag}->{mandatory}  = $mandatory;
+        $res->{$tag}->{repeatable} = $repeatable;
     }
-    $sth2 =
+
+    $sth =
       $dbh->prepare(
-        " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
-    $sth2->execute($biblionumber);
-    while ( my $row = $sth2->fetchrow_hashref ) {
-        &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
-            $row->{'subtitle'},'' );
+"select tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl,link from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"
+      );
+    $sth->execute($frameworkcode);
+
+    my $subfield;
+    my $authorised_value;
+    my $authtypecode;
+    my $value_builder;
+    my $kohafield;
+    my $seealso;
+    my $hidden;
+    my $isurl;
+    my $link;
+
+    while (
+        (
+            $tag,          $subfield,      $liblibrarian,
+            ,              $libopac,       $tab,
+            $mandatory,    $repeatable,    $authorised_value,
+            $authtypecode, $value_builder, $kohafield,
+            $seealso,      $hidden,        $isurl,
+            $link
+        )
+        = $sth->fetchrow
+      )
+    {
+        $res->{$tag}->{$subfield}->{lib} =
+          ( $forlibrarian or !$libopac ) ? $liblibrarian : $libopac;
+        $res->{$tag}->{$subfield}->{tab}              = $tab;
+        $res->{$tag}->{$subfield}->{mandatory}        = $mandatory;
+        $res->{$tag}->{$subfield}->{repeatable}       = $repeatable;
+        $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
+        $res->{$tag}->{$subfield}->{authtypecode}     = $authtypecode;
+        $res->{$tag}->{$subfield}->{value_builder}    = $value_builder;
+        $res->{$tag}->{$subfield}->{kohafield}        = $kohafield;
+        $res->{$tag}->{$subfield}->{seealso}          = $seealso;
+        $res->{$tag}->{$subfield}->{hidden}           = $hidden;
+        $res->{$tag}->{$subfield}->{isurl}            = $isurl;
+        $res->{$tag}->{$subfield}->{link}             = $link;
     }
-    return $record;
+    return $res;
 }
 
-=head2 MARCkoha2marcItem
+=head2 MARCfind_marc_from_kohafield
 
 =cut
 
-sub MARCkoha2marcItem {
+sub MARCfind_marc_from_kohafield {
+    my ( $dbh, $kohafield, $frameworkcode ) = @_;
+    return 0, 0 unless $kohafield;
+    my $relations = C4::Context->marcfromkohafield;
+    return (
+        $relations->{$frameworkcode}->{$kohafield}->[0],
+        $relations->{$frameworkcode}->{$kohafield}->[1]
+    );
+}
 
-    # this function builds partial MARC::Record from the old koha-DB fields
-    my ( $dbh, $biblionumber, $itemnumber ) = @_;
+=head2 MARCaddbiblio
 
-    #    my $dbh=&C4Connect;
-    my $sth =      $dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
-    my $record = MARC::Record->new();
+&MARCaddbiblio($newrec,$biblionumber,$frameworkcode);
 
-    #--- if item, then retrieve old-style koha data
-    if ( $itemnumber > 0 ) {
+Add MARC data for a biblio to koha 
 
-        #    print STDERR "prepare $biblionumber,$itemnumber\n";
-        my $sth2 =
-          $dbh->prepare(
-"SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
-                        booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
-                        datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
-                    reserves,restricted,binding,itemnotes,holdingbranch,timestamp,onloan,Cutterextra
-                    FROM items
-                    WHERE itemnumber=?"
-        );
-        $sth2->execute($itemnumber);
-        my $row = $sth2->fetchrow_hashref;
-        my $code;
-        foreach $code ( keys %$row ) {
-            if ( $row->{$code} ) {
-                &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
-                    $row->{$code},'' );
+=cut
+
+sub MARCaddbiblio {
+
+# pass the MARC::Record to this function, and it will create the records in the marc tables
+    my ( $record, $biblionumber, $frameworkcode ) = @_;
+    my $dbh = C4::Context->dbh;
+    my @fields = $record->fields();
+    if ( !$frameworkcode ) {
+        $frameworkcode = "";
+    }
+    my $sth =
+      $dbh->prepare("update  biblio set frameworkcode=? where biblionumber=?");
+    $sth->execute( $frameworkcode, $biblionumber );
+    $sth->finish;
+    my $encoding = C4::Context->preference("marcflavour");
+
+# deal with UNIMARC field 100 (encoding) : create it if needed & set encoding to unicode
+    if ( $encoding eq "UNIMARC" ) {
+        my $string;
+        if ( $record->subfield( 100, "a" ) ) {
+            $string = $record->subfield( 100, "a" );
+            my $f100 = $record->field(100);
+            $record->delete_field($f100);
             }
+        else {
+            $string = POSIX::strftime( "%Y%m%d", localtime );
+            $string =~ s/\-//g;
+            $string = sprintf( "%-*s", 35, $string );
+        }
+        substr( $string, 22, 6, "frey50" );
+        unless ( $record->subfield( 100, "a" ) ) {
+            $record->insert_grouped_field(
+                MARC::Field->new( 100, "", "", "a" => $string ) );
         }
     }
-    return $record;
+    $sth =
+      $dbh->prepare(
+        "update biblioitems set marc=?,marcxml=?  where biblionumber=?");
+    $sth->execute( $record->as_usmarc(), $record->as_xml_record(),
+        $biblionumber );
+    warn $record->as_xml_record();
+    $sth->finish;
+    zebraop($dbh,$biblionumber,"specialUpdate","biblioserver");
+    return $biblionumber;
 }
 
-=head2 MARCkoha2marcSubtitle
+=head2 MARCadditem
+
+$newbiblionumber = MARCadditem( $record, $biblionumber, $frameworkcode );
 
 =cut
 
-sub MARCkoha2marcSubtitle {
+sub MARCadditem {
 
-    # this function builds partial MARC::Record from the old koha-DB fields
-    my ( $dbh, $bibnum, $subtitle ) = @_;
+# pass the MARC::Record to this function, and it will create the records in the marc tables
+    my ( $record, $biblionumber, $frameworkcode ) = @_;
+    my $newrec = &GetMarcBiblio($biblionumber);
+
+    # 2nd recreate it
+    my @fields = $record->fields();
+    foreach my $field (@fields) {
+        $newrec->append_fields($field);
+    }
+
+    # FIXME: should we be making sure the biblionumbers are the same?
+    my $newbiblionumber =
+      &MARCaddbiblio( $newrec, $biblionumber, $frameworkcode );
+    return $newbiblionumber;
+}
+
+=head2 GetMarcBiblio
+
+Returns MARC::Record of the biblionumber passed in parameter.
+
+=cut
+
+sub GetMarcBiblio {
+    my $biblionumber = shift;
+    my $dbh          = C4::Context->dbh;
     my $sth =
-      $dbh->prepare(
-"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
-    );
+      $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
+    $sth->execute($biblionumber);
+    my ($marcxml) = $sth->fetchrow;
+    $marcxml =~ s/\x1e//g;
+    $marcxml =~ s/\x1f//g;
+    $marcxml =~ s/\x1d//g;
+    $marcxml =~ s/\x0f//g;
     my $record = MARC::Record->new();
-    &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
-        $subtitle,'' );
+    $record =
+      MARC::Record::new_from_xml( $marcxml, "utf8",
+        C4::Context->preference('marcflavour') )
+      if $marcxml;
     return $record;
 }
 
-=head2 MARCkoha2marcOnefield
+=head2 GetXmlBiblio
 
-=cut
+my $marcxml = GetXmlBiblio($biblionumber);
 
-sub MARCkoha2marcOnefield {
-    my ( $sth, $record, $kohafieldname, $value,$frameworkcode ) = @_;
-    my $tagfield;
-    my $tagsubfield;
+Returns biblioitems.marcxml of the biblionumber passed in parameter.
 
-if (!defined $sth){
-my $dbh=C4::Context->dbh;
-        $sth = $dbh->prepare(
-"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
-    );
-}
-    $sth->execute($frameworkcode,$kohafieldname);
-    if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
-            my $tag = $record->field($tagfield);
-        if ($tag) {
-                $tag->update( $tagsubfield=> $value );
-                $record->delete_field($tag);
-                $record->insert_fields_ordered($tag);      
-        }else {
-            $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
-        }
-    }
-    return $record;
+=cut
+
+sub GetXmlBiblio {
+    my ( $biblionumber ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth =
+      $dbh->prepare("select marcxml from biblioitems where biblionumber=? ");
+    $sth->execute($biblionumber);
+    my ($marcxml) = $sth->fetchrow;
+    return $marcxml;
 }
 
-=head MARChtml2xml
+=head2 MARCgetitem
+
+Returns MARC::Record of the item passed in parameter.
 
 =cut
 
-sub MARChtml2xml {
-    my ($tags,$subfields,$values,$indicator,$ind_tag) = @_;
-    my $xml= MARC::File::XML::header('UTF-8');
-    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
-        MARC::File::XML->default_record_format( 'UNIMARC' );
-        use POSIX qw(strftime);
-        my $string=strftime ("%Y%m%d",localtime(time));
-        $string = sprintf("%-*s",35, $string);
-        substr($string,22,6,"frey50");
-        $xml.="<datafield tag=\"100\" ind1=\"\" ind2=\"\">\n";
-        $xml.="<subfield code=\"a\">$string</subfield>\n";
-        $xml.="</datafield>\n";
-    }
-    my $prevvalue;
-    my $prevtag=-1;
-    my $first=1;
-    my $j = -1;
-    for (my $i=0;$i<=@$tags;$i++){
-        @$values[$i] =~ s/&/&amp;/g;
-        @$values[$i] =~ s/</&lt;/g;
-        @$values[$i] =~ s/>/&gt;/g;
-        @$values[$i] =~ s/"/&quot;/g;
-        @$values[$i] =~ s/'/&apos;/g;
-        if (! utf8::is_utf8(@$values[$i])) {
-          utf8::decode(@$values[$i]);
-        }
-        if ((@$tags[$i] ne $prevtag)){
-            $j++ unless (@$tags[$i] eq "");
-            if (!$first){
-                $xml.="</datafield>\n";
-                if ((@$tags[$i] && @$tags[$i] > 10)  && (@$values[$i] ne "")){
-                        my $ind1 = substr(@$indicator[$j],0,1);
-                        my $ind2;
-                        if (@$indicator[$j]) {
-                            $ind2 = substr(@$indicator[$j],1,1);
-                        }
-                        else {
-                            warn "Indicator in @$tags[$i] is empty";
-                            $ind2 = " ";
-                        }
-                        $xml.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
-                        $xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
-                        $first=0;
-                } else {
-                $first=1;
-                }
-            } else {
-                if (@$values[$i] ne "") {
-                    # leader
-                    if (@$tags[$i] eq "000") {
-                        $xml.="<leader>@$values[$i]</leader>\n";
-                        $first=1;
-                    # rest of the fixed fields
-                    } elsif (@$tags[$i] < 10) {
-                        $xml.="<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
-                        $first=1;
-                    } else {
-                        my $ind1 = substr(@$indicator[$j],0,1);
-                        my $ind2 = substr(@$indicator[$j],1,1);
-                        $xml.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
-                        $xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
-                        $first=0;
-                    }
-                }
-            }
-        } else { # @$tags[$i] eq $prevtag
-                if (@$values[$i] eq "") {
-                }
-                else {
-                    if ($first){
-                        my $ind1 = substr(@$indicator[$j],0,1);
-                        my $ind2 = substr(@$indicator[$j],1,1);
-                        $xml.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
-                        $first=0;
-                    }
-                $xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
-                }
+sub MARCgetitem {
+    my ( $biblionumber, $itemnumber ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $newrecord = MARC::Record->new();
+    my $marcflavour = C4::Context->preference('marcflavour');
+    
+    my $marcxml = GetXmlBiblio($biblionumber);
+    my $record = MARC::Record->new();
+    $record = MARC::Record::new_from_xml( $marcxml, "utf8", $marcflavour );
+
+    # now, find where the itemnumber is stored & extract only the item
+    my ( $itemnumberfield, $itemnumbersubfield ) =
+      MARCfind_marc_from_kohafield( $dbh, 'items.itemnumber', '' );
+    my @fields = $record->field($itemnumberfield);
+    foreach my $field (@fields) {
+        if ( $field->subfield($itemnumbersubfield) eq $itemnumber ) {
+            $newrecord->insert_fields_ordered($field);
         }
-        $prevtag = @$tags[$i];
     }
-    $xml.= MARC::File::XML::footer();
-    #warn $xml;
-    return $xml;
+    return $newrecord;
 }
 
-=head2 MARChtml2marc
+=head2 GetMarcNotes
 
-=cut
+$marcnotesarray = GetMarcNotes( $record, $marcflavour );
 
-sub MARChtml2marc {
-    my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
-    my $prevtag = -1;
-    my $record = MARC::Record->new();
-#     my %subfieldlist=();
-    my $prevvalue; # if tag <10
-    my $field; # if tag >=10
-    for (my $i=0; $i< @$rtags; $i++) {
-        next unless @$rvalues[$i];
-        # rebuild MARC::Record
-#             warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
-        if (@$rtags[$i] ne $prevtag) {
-            if ($prevtag < 10) {
-                if ($prevvalue) {
+get a single record in piggyback mode from Zebra and return it in the requested record syntax
 
-                    if ($prevtag ne '000') {
-                        $record->insert_fields_ordered((sprintf "%03s",$prevtag),$prevvalue);
-                    } else {
+default record syntax is XML
 
-                        $record->leader($prevvalue);
+=cut
 
+sub GetMarcNotes {
+    my ( $record, $marcflavour ) = @_;
+    my $scope;
+    if ( $marcflavour eq "MARC21" ) {
+        $scope = '5..';
                     }
+    else {    # assume unimarc if not marc21
+        $scope = '3..';
                 }
-            } else {
-                if ($field) {
-                    $record->insert_fields_ordered($field);
+    my @marcnotes;
+    my $note = "";
+    my $tag  = "";
+    my $marcnote;
+    foreach my $field ( $record->field($scope) ) {
+        my $value = $field->as_string();
+        if ( $note ne "" ) {
+            $marcnote = { marcnote => $note, };
+            push @marcnotes, $marcnote;
+            $note = $value;
                 }
+        if ( $note ne $value ) {
+            $note = $note . " " . $value;
             }
-            $indicators{@$rtags[$i]}.='  ';
-            if (@$rtags[$i] <10) {
-                $prevvalue= @$rvalues[$i];
-                undef $field;
-            } else {
-                undef $prevvalue;
-                $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
-#             warn "1=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
             }
-            $prevtag = @$rtags[$i];
-        } else {
-            if (@$rtags[$i] <10) {
-                $prevvalue=@$rvalues[$i];
-            } else {
-                if (length(@$rvalues[$i])>0) {
-                    $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
-#             warn "2=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ".$field->as_formatted;
+
+    if ( $note ) {
+        $marcnote = { marcnote => $note };
+        push @marcnotes, $marcnote;    #load last tag into array
+    }
+    return \@marcnotes;
+}    # end GetMarcNotes
+
+=head2 GetMarcSubjects
+
+$marcsubjcts = GetMarcSubjects($record,$marcflavour);
+
+=cut
+
+sub GetMarcSubjects {
+    my ( $record, $marcflavour ) = @_;
+    my ( $mintag, $maxtag );
+    if ( $marcflavour eq "MARC21" ) {
+        $mintag = "600";
+        $maxtag = "699";
                 }
+    else {    # assume unimarc if not marc21
+        $mintag = "600";
+        $maxtag = "619";
             }
-            $prevtag= @$rtags[$i];
+
+    my @marcsubjcts;
+    my $subjct   = "";
+    my $subfield = "";
+    my $marcsubjct;
+
+    foreach my $field ( $record->fields ) {
+        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
+        my @subfields = $field->subfields();
+        my $counter = 0;
+        my @link_loop;
+        for my $subject_subfield ( @subfields ) {
+            my $code      = $subject_subfield->[0];
+            my $value     = $subject_subfield->[1];
+            my $linkvalue = $value;
+            $linkvalue    =~ s/(\(|\))//g;
+            my $operator = " and " unless $counter == 0;
+            push @link_loop,
+              {
+                link => $linkvalue,
+                operator => $operator,
+                KohaAuthNumber => ($code == 9)?(1):(0)
+              };
+            my $separator = C4::Context->preference("authoritysep")
+              unless $counter == 0;
+            push @marcsubjcts,
+              {
+                tag            => $field->tag(),
+                code           => $code,
+                value          => $value,
+                link_loop      => \@link_loop,
+                separator      => $separator,
+                KohaAuthNumber => ($code == 9)?(1):(0)
+              };
+            $counter++;
         }
     }
-    # the last has not been included inside the loop... do it now !
-    $record->insert_fields_ordered($field) if $field;
-#     warn "HTML2MARC=".$record->as_formatted;
-    $record->encoding( 'UTF-8' );
-#    $record->MARC::File::USMARC::update_leader();
-    return $record;
-}
+    return \@marcsubjcts;
+}    #end GetMarcSubjects
+
+=head2 GetMarcAuthors
 
-=head MARCmarc2koha
+authors = GetMarcAuthors($record,$marcflavour);
 
 =cut
 
-sub MARCmarc2koha {
-    my ($dbh,$record,$frameworkcode) = @_;
-    my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
-    my $result;
-    my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
-    $sth2->execute;
-    my $field;
-    while (($field)=$sth2->fetchrow) {
-        $result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result,$frameworkcode);
-    }
-    $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
-    $sth2->execute;
-    while (($field)=$sth2->fetchrow) {
-        if ($field eq 'notes') { $field = 'bnotes'; }
-        $result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result,$frameworkcode);
+sub GetMarcAuthors {
+    my ( $record, $marcflavour ) = @_;
+    my ( $mintag, $maxtag );
+    if ( $marcflavour eq "MARC21" ) {
+        $mintag = "";    # FIXME
+        $maxtag = "";    # FIXME
     }
-    $sth2=$dbh->prepare("SHOW COLUMNS from items");
-    $sth2->execute;
-    while (($field)=$sth2->fetchrow) {
-        $result=&MARCmarc2kohaOneField($sth,"items",$field,$record,$result,$frameworkcode);
+    else {    # assume unimarc if not marc21
+        $mintag = "700";
+        $maxtag = "712";
     }
-    # additional authors : specific
-    $result = &MARCmarc2kohaOneField($sth,"bibliosubtitle","subtitle",$record,$result,$frameworkcode);
-    $result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result,$frameworkcode);
-    $result = &MARCmarc2kohaOneField($sth,"bibliosubject","subject",$record,$result,$frameworkcode);
-#
-# modify copyrightdate to keep only the 1st year found
-    my $temp = $result->{'copyrightdate'};
-    $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
-    if ($1>0) {
-        $result->{'copyrightdate'} = $1;
-    } else { # if no cYYYY, get the 1st date.
-        $temp =~ m/(\d\d\d\d)/;
-        $result->{'copyrightdate'} = $1;
+
+    my @marcauthors;
+
+    foreach my $field ( $record->fields ) {
+        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
+        my %hash;
+        my @subfields = $field->subfields();
+        for my $authors_subfield (@subfields) {
+            my $subfieldcode     = $authors_subfield->[0];
+            my $value            = $authors_subfield->[1];
+            $hash{'tag'}         = $field->tag;
+            $hash{$subfieldcode} = $value;
     }
-# modify publicationyear to keep only the 1st year found
-    $temp = $result->{'publicationyear'};
-    $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
-    if ($1>0) {
-        $result->{'publicationyear'} = $1;
-    } else { # if no cYYYY, get the 1st date.
-        $temp =~ m/(\d\d\d\d)/;
-        $result->{'publicationyear'} = $1;
+        push @marcauthors, \%hash;
     }
-    return $result;
+    return \@marcauthors;
 }
 
-=head2 MARCmarc2kohaOneField
+=head2 MARCmodbiblio
+
+MARCmodbibio($dbh,$biblionumber,$record,$frameworkcode,1);
+
+Modify a biblio record with the option to save items data
 
 =cut
 
-sub MARCmarc2kohaOneField {
+sub MARCmodbiblio {
+    my ( $dbh, $biblionumber, $record, $frameworkcode, $keep_items ) = @_;
 
-# FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
-    my ( $sth, $kohatable, $kohafield, $record, $result,$frameworkcode ) = @_;
-    #    warn "kohatable / $kohafield / $result / ";
-    my $res = "";
-    my $tagfield;
-    my $subfield;
-    ( $tagfield, $subfield ) = MARCfind_marc_from_kohafield("",$kohatable.".".$kohafield,$frameworkcode);
-    foreach my $field ( $record->field($tagfield) ) {
-        if ($field->tag()<10) {
-            if ($result->{$kohafield}) {
-                $result->{$kohafield} .= " | ".$field->data();
-            } else {
-                $result->{$kohafield} = $field->data();
-            }
-        } else {
-            if ( $field->subfields ) {
-                my @subfields = $field->subfields();
-                foreach my $subfieldcount ( 0 .. $#subfields ) {
-                    if ($subfields[$subfieldcount][0] eq $subfield) {
-                        if ( $result->{$kohafield} ) {
-                            $result->{$kohafield} .= " | " . $subfields[$subfieldcount][1];
-                        }
-                        else {
-                            $result->{$kohafield} = $subfields[$subfieldcount][1];
-                        }
-                    }
-                }
-            }
-        }
+    # delete original record but save the items
+    my $newrec = &MARCdelbiblio( $biblionumber, $keep_items );
+
+    # recreate it and add the new fields
+    my @fields = $record->fields();
+    foreach my $field (@fields) {
+
+        # this requires a more recent version of MARC::Record
+        # but ensures the fields are in order
+        $newrec->insert_fields_ordered($field);
     }
-#     warn "OneField for $kohatable.$kohafield and $frameworkcode=> $tagfield, $subfield";
-    return $result;
+
+    # give back our old leader
+    $newrec->leader( $record->leader() );
+
+    # add the record back with the items info preserved
+    &MARCaddbiblio( $newrec, $biblionumber, $frameworkcode );
 }
 
+=head2 MARCdelbiblio
 
+&MARCdelbiblio( $biblionumber, $keep_items )
 
-=head2 MARCitemchange
+if the keep_item is set to 1, then all items are preserved.
+This flag is set when the delbiblio is called by modbiblio
+due to a too complex structure of MARC (repeatable fields and subfields),
+the best solution for a modif is to delete / recreate the record.
+
+1st of all, copy the MARC::Record to deletedbiblio table => if a true deletion, MARC data will be kept.
+if deletion called before MARCmodbiblio => won't do anything, as the oldbiblionumber doesn't
+exist in deletedbiblio table
 
 =cut
 
-sub MARCitemchange {
-    my ($dbh,$record,$itemfield,$newvalue)=@_;
-    my ($tagfield, $tagsubfield)=MARCfind_marc_from_kohafield($dbh,$itemfield,"");
-    if (($tagfield) && ($tagsubfield))  {
-        my $tag = $record->field($tagfield);
-        if ( $tag)  {
-            $tag->update($tagsubfield => $newvalue);
-            $record->delete_field($tag);
-            $record->insert_fields_ordered($tag);
+sub MARCdelbiblio {
+    my ( $biblionumber, $keep_items ) = @_;
+    my $dbh = C4::Context->dbh;
+    
+    my $record          = GetMarcBiblio($biblionumber);
+    my $oldbiblionumber = $biblionumber;
+    my $copy2deleted    =
+      $dbh->prepare("update deletedbiblio set marc=? where biblionumber=?");
+    $copy2deleted->execute( $record->as_usmarc(), $oldbiblionumber );
+    my @fields = $record->fields();
+
+    # now, delete in MARC tables.
+    if ( $keep_items eq 1 ) {
+        #search item field code
+        my $sth =
+          $dbh->prepare(
+"select tagfield from marc_subfield_structure where kohafield like 'items.%'"
+          );
+        $sth->execute;
+        my $itemtag = $sth->fetchrow_hashref->{tagfield};
+
+        foreach my $field (@fields) {
+
+            if ( $field->tag() ne $itemtag ) {
+                $record->delete_field($field);
+            }    #if
+        }    #foreach
         }
+    else {
+        foreach my $field (@fields) {
+
+            $record->delete_field($field);
+        }    #foreach
     }
+    return $record;
 }
 
+=head2 MARCdelitem
 
-=item bibitemdata
-
-  $itemdata = &bibitemdata($biblioitemnumber);
+MARCdelitem( $biblionumber, $itemnumber )
 
-Looks up the biblioitem with the given biblioitemnumber. Returns a
-reference-to-hash. The keys are the fields from the C<biblio>,
-C<biblioitems>, and C<itemtypes> tables in the Koha database, except
-that C<biblioitems.notes> is given as C<$itemdata-E<gt>{bnotes}>.
+delete the item field from the MARC record for the itemnumber specified
 
 =cut
 
-#'
-sub bibitemdata {
-    my ($bibitem) = @_;
+sub MARCdelitem {
+    my ( $biblionumber, $itemnumber ) = @_;
     my $dbh   = C4::Context->dbh;
-    my $sth   = $dbh->prepare("Select *,biblioitems.notes as bnotes from biblioitems, biblio,itemtypes where biblio.biblionumber = biblioitems.biblionumber and biblioitemnumber = ? and biblioitems.itemtype = itemtypes.itemtype");
-    my $data;
 
-    $sth->execute($bibitem);
+    # get the MARC record
+    my $record = GetMarcBiblio($biblionumber);
 
-    $data = $sth->fetchrow_hashref;
+    # backup the record
+    my $copy2deleted =
+      $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
+    $copy2deleted->execute( $record->as_usmarc(), $itemnumber );
 
-    $sth->finish;
-    return($data);
-} # sub bibitemdata
+    #search item field code
+    my $sth =
+      $dbh->prepare(
+"SELECT tagfield,tagsubfield FROM marc_subfield_structure WHERE kohafield LIKE 'items.itemnumber'"
+      );
+    $sth->execute;
+    my ( $itemtag, $itemsubfield ) = $sth->fetchrow;
+    my @fields = $record->field($itemtag);
 
+    # delete the item specified
+    foreach my $field (@fields) {
+        if ( $field->subfield($itemsubfield) eq $itemnumber ) {
+            $record->delete_field($field);
+        }
+    }
+    return $record;
+}
 
-=head2 ModBiblioframework
+=head2 MARCmoditemonefield
 
-=over 4
+&MARCmoditemonefield( $biblionumber, $itemnumber, $itemfield, $newvalue )
 
-ModBiblioframework($dbh,$biblionumber,$frameworkcode);
+=cut
 
-Exported function to modify a biblio framework
+sub MARCmoditemonefield {
+    my ( $biblionumber, $itemnumber, $itemfield, $newvalue ) = @_;
+    my $dbh = C4::Context->dbh;
+    if ( !defined $newvalue ) {
+        $newvalue = "";
+    }
 
-=back
+    my $record = MARCgetitem( $biblionumber, $itemnumber );
+
+    my $sth =
+      $dbh->prepare(
+"select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
+      );
+    my $tagfield;
+    my $tagsubfield;
+    $sth->execute($itemfield);
+    if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
+        my $tag = $record->field($tagfield);
+        if ($tag) {
+            my $tagsubs = $record->field($tagfield)->subfield($tagsubfield);
+            $tag->update( $tagsubfield => $newvalue );
+            $record->delete_field($tag);
+            $record->insert_fields_ordered($tag);
+            &MARCmoditem( $record, $biblionumber, $itemnumber, 0 );
+        }
+    }
+}
+
+=head2 MARCmoditem
+
+&MARCmoditem( $record, $biblionumber, $itemnumber, $delete )
 
 =cut
 
-sub ModBiblioframework {
-    my ($dbh,$biblionumber,$frameworkcode) =@_;
-    my $sth = $dbh->prepare("UPDATE biblio SET frameworkcode=? WHERE biblionumber=$biblionumber");
-    $sth->execute($frameworkcode);
-    return 1;
+sub MARCmoditem {
+    my ( $record, $biblionumber, $itemnumber, $delete ) = @_;
+    my $dbh = C4::Context->dbh;
+    
+    # delete this item from MARC
+    my $newrec = &MARCdelitem( $biblionumber, $itemnumber );
+
+    # 2nd recreate it
+    my @fields = $record->fields();
+    ###NEU specific add cataloguers cardnumber as well
+    my $cardtag = C4::Context->preference('itemcataloguersubfield');
+
+    foreach my $field (@fields) {
+        if ($cardtag) {
+            my $me = C4::Context->userenv;
+            my $cataloguer = $me->{'cardnumber'} if ($me);
+            $field->update( $cardtag => $cataloguer ) if ($me);
+        }
+        $newrec->append_fields($field);
+    }
+    &MARCaddbiblio( $newrec, $biblionumber );
 }
 
-=head2 PrepareItemrecordDisplay
+=head2 MARCfind_frameworkcode
 
-=over 4
+$frameworkcode = MARCfind_frameworkcode( $biblionumber )
 
-PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
+=cut
 
-Returns a hash with all the fields for Display a given item data in a template
+sub MARCfind_frameworkcode {
+    my ( $biblionumber ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth =
+      $dbh->prepare("select frameworkcode from biblio where biblionumber=?");
+    $sth->execute($biblionumber);
+    my ($frameworkcode) = $sth->fetchrow;
+    return $frameworkcode;
+}
 
-=back
+=head2 MARCkoha2marcBiblio
+
+$record = MARCkoha2marcBiblio( $biblionumber, $biblioitemnumber )
+
+this function builds partial MARC::Record from the old koha-DB fields
 
 =cut
-sub PrepareItemrecordDisplay{
       
-  my ($itemnum,$bibnum)=@_;
+sub MARCkoha2marcBiblio {
   
+    my ( $biblionumber, $biblioitemnumber ) = @_;
   my $dbh = C4::Context->dbh;
-  my $frameworkcode = &MARCfind_frameworkcode($dbh,$bibnum);
-  my ($itemtagfield,$itemtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.itemnumber",$frameworkcode);
-  my $tagslib = &MARCgettagslib($dbh,1,$frameworkcode);
-  my $itemrecord= MARCgetitem($dbh, $itemnum,$bibnum) if ($itemnum);
-  my @loop_data;
-  my $authorised_values_sth = $dbh->prepare("select authorised_value,lib from authorised_values where category=? order by lib");
-  foreach my $tag (sort keys %{$tagslib}) {
-	my $previous_tag = '';
-    if ($tag ne ''){
-# loop through each subfield
-    my $cntsubf;
-	foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
-		next if (subfield_is_koha_internal_p($subfield));
-		next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "10");
-		my %subfield_data;
-		$subfield_data{tag}=$tag;
-		$subfield_data{subfield}=$subfield;
-		$subfield_data{countsubfield}=$cntsubf++;
-		$subfield_data{kohafield}=$tagslib->{$tag}->{$subfield}->{'kohafield'};
-#		$subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
-		$subfield_data{marc_lib}="<span id=\"error\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".substr($tagslib->{$tag}->{$subfield}->{lib},0,12)."</span>";
-		$subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
-		$subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
-		$subfield_data{hidden}= "display:none" if $tagslib->{$tag}->{$subfield}->{hidden};
-		my ($x,$value);
-		($x,$value) = _find_value($tag,$subfield,$itemrecord) if ($itemrecord);
-		$value =~ s/"/&quot;/g;
-		# search for itemcallnumber if applicable
-		if ($tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && C4::Context->preference('itemcallnumber')) {
-			my $CNtag = substr(C4::Context->preference('itemcallnumber'),0,3);
-			my $CNsubfield = substr(C4::Context->preference('itemcallnumber'),3,1);
-			my $temp = $itemrecord->field($CNtag) if ($itemrecord);
-			if ($temp) {
-				$value = $temp->subfield($CNsubfield);
+    my $sth =
+      $dbh->prepare(
+"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
+      );
+    my $record = MARC::Record->new();
+
+    #--- if biblionumber, then retrieve old-style koha data
+    if ( $biblionumber > 0 ) {
+        my $sth2 = $dbh->prepare(
+"select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
+        from biblio where biblionumber=?"
+        );
+        $sth2->execute($biblionumber);
+        my $row = $sth2->fetchrow_hashref;
+        my $code;
+        foreach $code ( keys %$row ) {
+            if ( $row->{$code} ) {
+                &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
+                    $row->{$code}, '' );
 			}
 		}
-		if ($tagslib->{$tag}->{$subfield}->{authorised_value}) {
-			my @authorised_values;
-			my %authorised_lib;
-			# builds list, depending on authorised value...
-			#---- branch
-			if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-				if ((C4::Context->preference("IndependantBranches")) && (C4::Context->userenv->{flags} != 1)){
-						my $sth=$dbh->prepare("select branchcode,branchname from branches where branchcode = ? order by branchname");
-						$sth->execute(C4::Context->userenv->{branch});
-						push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
-						while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
-							push @authorised_values, $branchcode;
-							$authorised_lib{$branchcode}=$branchname;
 						}
-				} else {
-					my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname");
-					$sth->execute;
-					push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
-					while (my ($branchcode,$branchname) = $sth->fetchrow_array) {
-						push @authorised_values, $branchcode;
-						$authorised_lib{$branchcode}=$branchname;
+
+    #--- if biblioitem, then retrieve old-style koha data
+    if ( $biblioitemnumber > 0 ) {
+        my $sth2 = $dbh->prepare(
+            " SELECT biblioitemnumber,biblionumber,volume,number,classification,
+                        itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
+                        volumedate,volumeddesc,timestamp,illus,pages,notes AS bnotes,size,place
+                    FROM biblioitems
+                    WHERE biblioitemnumber=?
+                    "
+        );
+        $sth2->execute($biblioitemnumber);
+        my $row = $sth2->fetchrow_hashref;
+        my $code;
+        foreach $code ( keys %$row ) {
+            if ( $row->{$code} ) {
+                &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
+                    $row->{$code}, '' );
 					}
 				}
-			#----- itemtypes
-			} elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") {
-				my $sth=$dbh->prepare("select itemtype,description from itemtypes order by description");
-				$sth->execute;
-				push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
-				while (my ($itemtype,$description) = $sth->fetchrow_array) {
-					push @authorised_values, $itemtype;
-					$authorised_lib{$itemtype}=$description;
 				}
-			#---- "true" authorised value
-			} else {
-				$authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value});
-				push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory});
-				while (my ($value,$lib) = $authorised_values_sth->fetchrow_array) {
-					push @authorised_values, $value;
-					$authorised_lib{$value}=$lib;
+    return $record;
+}
+
+=head2 MARCkoha2marcItem
+
+$record = MARCkoha2marcItem( $dbh, $biblionumber, $itemnumber );
+
+=cut
+
+sub MARCkoha2marcItem {
+
+    # this function builds partial MARC::Record from the old koha-DB fields
+    my ( $dbh, $biblionumber, $itemnumber ) = @_;
+
+    #    my $dbh=&C4Connect;
+    my $sth =
+      $dbh->prepare(
+"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
+      );
+    my $record = MARC::Record->new();
+
+    #--- if item, then retrieve old-style koha data
+    if ( $itemnumber > 0 ) {
+
+        #    print STDERR "prepare $biblionumber,$itemnumber\n";
+        my $sth2 = $dbh->prepare(
+"SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
+                        booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
+                        datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,itemcallnumber,issues,renewals,
+                    reserves,restricted,binding,itemnotes,holdingbranch,timestamp,onloan,Cutterextra
+                    FROM items
+                    WHERE itemnumber=?"
+        );
+        $sth2->execute($itemnumber);
+        my $row = $sth2->fetchrow_hashref;
+        my $code;
+        foreach $code ( keys %$row ) {
+            if ( $row->{$code} ) {
+                &MARCkoha2marcOnefield( $sth, $record, "items." . $code,
+                    $row->{$code}, '' );
 				}
 			}
-			$subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value',
-																		-values=> \@authorised_values,
-																		-default=>"$value",
-																		-labels => \%authorised_lib,
-																		-size=>1,
- 																		-tabindex=>'',
-																		-multiple=>0,
-																		);
-		} elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) {
-			$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\"  size=47 maxlength=255> <a href=\"javascript:Dopop('cataloguing/thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=',)\">...</a>";
-			#"
-# COMMENTED OUT because No $i is provided with this API.
-# And thus, no value_builder can be activated.
-# BUT could be thought over.
-# 		} elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
-# 			my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
-# 			require $plugin;
-# 			my $extended_param = plugin_parameters($dbh,$itemrecord,$tagslib,$i,0);
-# 			my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0);
-# 			$subfield_data{marc_value}="<input type=\"text\" value=\"$value\" name=\"field_value\"  size=47 maxlength=255 DISABLE READONLY OnFocus=\"javascript:Focus$function_name()\" OnBlur=\"javascript:Blur$function_name()\"> <a href=\"javascript:Clic$function_name()\">...</a> $javascript";
-		} else {
-			$subfield_data{marc_value}="<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
 		}
-		push(@loop_data, \%subfield_data);
+    return $record;
+}
+
+=head2 MARCkoha2marcOnefield
+
+$record = MARCkoha2marcOnefield( $sth, $record, $kohafieldname, $value, $frameworkcode );
+
+=cut
+
+sub MARCkoha2marcOnefield {
+    my ( $sth, $record, $kohafieldname, $value, $frameworkcode ) = @_;
+    my $tagfield;
+    my $tagsubfield;
+
+    if ( !defined $sth ) {
+        my $dbh = C4::Context->dbh;
+        $sth =
+          $dbh->prepare(
+"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
+          );
+    }
+    $sth->execute( $frameworkcode, $kohafieldname );
+    if ( ( $tagfield, $tagsubfield ) = $sth->fetchrow ) {
+        my $tag = $record->field($tagfield);
+        if ($tag) {
+            $tag->update( $tagsubfield => $value );
+            $record->delete_field($tag);
+            $record->insert_fields_ordered($tag);
 	}
+        else {
+            $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
     }
   }
-  my $itemnumber=$itemrecord->subfield($itemtagfield,$itemtagsubfield) if ($itemrecord && $itemrecord->field($itemtagfield));
-  return {'itemtagfield'=>$itemtagfield,
-          'itemtagsubfield'=>$itemtagsubfield,
-          'itemnumber'=>$itemnumber,
-          'iteminformation'=>\@loop_data};
+    return $record;
 }
 
+=head2 MARChtml2xml
 
-=item _find_value
-
-    ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
-
-Find the given $subfield in the given $tag in the given
-MARC::Record $record.  If the subfield is found, returns
-the (indicators, value) pair; otherwise, (undef, undef) is
-returned.
+$xml = MARChtml2xml( $tags, $subfields, $values, $indicator, $ind_tag )
 
-PROPOSITION :
-Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities.
-I suggest we export it from this module.
 =cut
 
-sub _find_value {
-	my ($tagfield,$insubfield,$record,$encoding) = @_;
-	my @result;
-	my $indicator;
-	if ($tagfield <10) {
-		if ($record->field($tagfield)) {
-			push @result, $record->field($tagfield)->data();
-		} else {
-			push @result,"";
+sub MARChtml2xml {
+    my ( $tags, $subfields, $values, $indicator, $ind_tag ) = @_;
+    my $xml = MARC::File::XML::header('UTF-8');
+    if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
+        MARC::File::XML->default_record_format('UNIMARC');
+        use POSIX qw(strftime);
+        my $string = strftime( "%Y%m%d", localtime(time) );
+        $string = sprintf( "%-*s", 35, $string );
+        substr( $string, 22, 6, "frey50" );
+        $xml .= "<datafield tag=\"100\" ind1=\"\" ind2=\"\">\n";
+        $xml .= "<subfield code=\"a\">$string</subfield>\n";
+        $xml .= "</datafield>\n";
 		}
-	} else {
-		foreach my $field ($record->field($tagfield)) {
-			my @subfields = $field->subfields();
-			foreach my $subfield (@subfields) {
-				if (@$subfield[0] eq $insubfield) {
-					push @result,@$subfield[1];
-					$indicator = $field->indicator(1).$field->indicator(2);
+    my $prevvalue;
+    my $prevtag = -1;
+    my $first   = 1;
+    my $j       = -1;
+    for ( my $i = 0 ; $i <= @$tags ; $i++ ) {
+        @$values[$i] =~ s/&/&amp;/g;
+        @$values[$i] =~ s/</&lt;/g;
+        @$values[$i] =~ s/>/&gt;/g;
+        @$values[$i] =~ s/"/&quot;/g;
+        @$values[$i] =~ s/'/&apos;/g;
+        if ( !utf8::is_utf8( @$values[$i] ) ) {
+            utf8::decode( @$values[$i] );
+        }
+        if ( ( @$tags[$i] ne $prevtag ) ) {
+            $j++ unless ( @$tags[$i] eq "" );
+            if ( !$first ) {
+                $xml .= "</datafield>\n";
+                if (   ( @$tags[$i] && @$tags[$i] > 10 )
+                    && ( @$values[$i] ne "" ) )
+                {
+                    my $ind1 = substr( @$indicator[$j], 0, 1 );
+                    my $ind2;
+                    if ( @$indicator[$j] ) {
+                        $ind2 = substr( @$indicator[$j], 1, 1 );
 				}
+                    else {
+                        warn "Indicator in @$tags[$i] is empty";
+                        $ind2 = " ";
 			}
+                    $xml .=
+"<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+                    $xml .=
+"<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
+                    $first = 0;
 		}
+                else {
+                    $first = 1;
 	}
-	return($indicator, at result);
-}
-
+            }
+            else {
+                if ( @$values[$i] ne "" ) {
 
-=head2 GetItemFromBarcode
+                    # leader
+                    if ( @$tags[$i] eq "000" ) {
+                        $xml .= "<leader>@$values[$i]</leader>\n";
+                        $first = 1;
 
-=cut
-sub GetItemFromBarcode {
-    my ($barcode)=@_;
-    my $dbh=C4::Context->dbh;
+                        # rest of the fixed fields
+                    }
+                    elsif ( @$tags[$i] < 10 ) {
+                        $xml .=
+"<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
+                        $first = 1;
+                    }
+                    else {
+                        my $ind1 = substr( @$indicator[$j], 0, 1 );
+                        my $ind2 = substr( @$indicator[$j], 1, 1 );
+                        $xml .=
+"<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+                        $xml .=
+"<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
+                        $first = 0;
+                    }
+                }
+            }
+        }
+        else {    # @$tags[$i] eq $prevtag
+            if ( @$values[$i] eq "" ) {
+            }
+            else {
+                if ($first) {
+                    my $ind1 = substr( @$indicator[$j], 0, 1 );
+                    my $ind2 = substr( @$indicator[$j], 1, 1 );
+                    $xml .=
+"<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+                    $first = 0;
+                }
+                $xml .=
+"<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
+            }
+        }
+        $prevtag = @$tags[$i];
+    }
+    $xml .= MARC::File::XML::footer();
 	
-    my $rq=$dbh->prepare("SELECT itemnumber from items where items.barcode=?");
-    $rq->execute($barcode);
-    my($result)=$rq->fetchrow;
-	return($result);
+    return $xml;
 }
 
-=head1 INTERNAL FUNCTIONS
+=head2 MARChtml2marc
 
-=head2 _koha_add_biblio
+$record = MARChtml2marc( $dbh, $rtags, $rsubfields, $rvalues, %indicators )
 
-=over 4
+=cut
 
-_koha_add_biblio($dbh,$biblioitem);
+sub MARChtml2marc {
+    my ( $dbh, $rtags, $rsubfields, $rvalues, %indicators ) = @_;
+    my $prevtag = -1;
+    my $record  = MARC::Record->new();
 
-Internal function to add a biblio ($biblio is a hash with the values)
+    #     my %subfieldlist=();
+    my $prevvalue;    # if tag <10
+    my $field;        # if tag >=10
+    for ( my $i = 0 ; $i < @$rtags ; $i++ ) {
+        next unless @$rvalues[$i];
 
-=back
+ # rebuild MARC::Record
+ #             warn "0=>".@$rtags[$i].@$rsubfields[$i]." = ".@$rvalues[$i].": ";
+        if ( @$rtags[$i] ne $prevtag ) {
+            if ( $prevtag < 10 ) {
+                if ($prevvalue) {
 
-=cut
+                    if ( $prevtag ne '000' ) {
+                        $record->insert_fields_ordered(
+                            ( sprintf "%03s", $prevtag ), $prevvalue );
+                    }
+                    else {
 
-sub _koha_add_biblio {
-    my ( $dbh, $biblio,$frameworkcode ) = @_;
-    my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
-    $sth->execute;
-    my $data   = $sth->fetchrow_arrayref;
-    my $biblionumber = $$data[0] + 1;
-    my $series = 0;
+                        $record->leader($prevvalue);
 
-    if ( $biblio->{'seriestitle'} ) { $series = 1 }
-    $sth->finish;
-    $sth = $dbh->prepare(
-    "INSERT INTO biblio
-    SET biblionumber  = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?, frameworkcode = ? "
-    );
-    $sth->execute(
-        $biblionumber,$biblio->{'title'},
-        $biblio->{'author'}, $biblio->{'copyrightdate'},
-        $biblio->{'serial'},             $biblio->{'seriestitle'},
-        $biblio->{'notes'},  $biblio->{'abstract'},
-        $biblio->{'unititle'},$frameworkcode
+                    }
+                }
+            }
+            else {
+                if ($field) {
+                    $record->insert_fields_ordered($field);
+                }
+            }
+            $indicators{ @$rtags[$i] } .= '  ';
+            if ( @$rtags[$i] < 10 ) {
+                $prevvalue = @$rvalues[$i];
+                undef $field;
+            }
+            else {
+                undef $prevvalue;
+                $field = MARC::Field->new(
+                    ( sprintf "%03s", @$rtags[$i] ),
+                    substr( $indicators{ @$rtags[$i] }, 0, 1 ),
+                    substr( $indicators{ @$rtags[$i] }, 1, 1 ),
+                    @$rsubfields[$i] => @$rvalues[$i]
     );
+            }
+            $prevtag = @$rtags[$i];
+        }
+        else {
+            if ( @$rtags[$i] < 10 ) {
+                $prevvalue = @$rvalues[$i];
+            }
+            else {
+                if ( length( @$rvalues[$i] ) > 0 ) {
+                    $field->add_subfields( @$rsubfields[$i] => @$rvalues[$i] );
+                }
+            }
+            $prevtag = @$rtags[$i];
+        }
+    }
 
-    $sth->finish;
-    return ($biblionumber);
-}
+    # the last has not been included inside the loop... do it now !
+    $record->insert_fields_ordered($field) if $field;
 
-=head2 _koha_modify_biblio
+    #     warn "HTML2MARC=".$record->as_formatted;
+    $record->encoding('UTF-8');
 
-over 4
+    #    $record->MARC::File::USMARC::update_leader();
+    return $record;
+}
 
-Internal function for updating the biblio table
+=head2 MARCmarc2koha
 
-=back
+$result = MARCmarc2koha( $dbh, $record, $frameworkcode )
 
 =cut
 
-sub _koha_modify_biblio {
-    my ( $dbh, $biblio ) = @_;
-    # FIXME: this code could be made more portable by not hard-coding the values that are supposed to be in biblio table
-    my $sth = $dbh->prepare("Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?");
-    $sth->execute(
-        $biblio->{'title'},       $biblio->{'author'},
-        $biblio->{'abstract'},    $biblio->{'copyrightdate'},
-        $biblio->{'seriestitle'}, $biblio->{'serial'},
-        $biblio->{'unititle'},    $biblio->{'notes'},
-        $biblio->{'biblionumber'}
+sub MARCmarc2koha {
+    my ( $dbh, $record, $frameworkcode ) = @_;
+    my $sth =
+      $dbh->prepare(
+"select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
     );
-    $sth->finish;
-    return ( $biblio->{'biblionumber'} );
+    my $result;
+    my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
+    $sth2->execute;
+    my $field;
+    while ( ($field) = $sth2->fetchrow ) {
+        $result =
+          &MARCmarc2kohaOneField( "biblio", $field, $record, $result,
+            $frameworkcode );
+    }
+    $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
+    $sth2->execute;
+    while ( ($field) = $sth2->fetchrow ) {
+        if ( $field eq 'notes' ) { $field = 'bnotes'; }
+        $result =
+          &MARCmarc2kohaOneField( "biblioitems", $field, $record, $result,
+            $frameworkcode );
+    }
+    $sth2 = $dbh->prepare("SHOW COLUMNS from items");
+    $sth2->execute;
+    while ( ($field) = $sth2->fetchrow ) {
+        $result =
+          &MARCmarc2kohaOneField( "items", $field, $record, $result,
+            $frameworkcode );
+    }
+
+    #
+    # modify copyrightdate to keep only the 1st year found
+    my $temp = $result->{'copyrightdate'};
+    $temp =~ m/c(\d\d\d\d)/;    # search cYYYY first
+    if ( $1 > 0 ) {
+        $result->{'copyrightdate'} = $1;
+    }
+    else {                      # if no cYYYY, get the 1st date.
+        $temp =~ m/(\d\d\d\d)/;
+        $result->{'copyrightdate'} = $1;
+    }
+
+    # modify publicationyear to keep only the 1st year found
+    $temp = $result->{'publicationyear'};
+    $temp =~ m/c(\d\d\d\d)/;    # search cYYYY first
+    if ( $1 > 0 ) {
+        $result->{'publicationyear'} = $1;
+    }
+    else {                      # if no cYYYY, get the 1st date.
+        $temp =~ m/(\d\d\d\d)/;
+        $result->{'publicationyear'} = $1;
+    }
+    return $result;
 }
 
-=head2 _koha_modify_subtitle
+=head2 MARCmarc2kohaOneField
+
+$result = MARCmarc2kohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode )
 
 =cut
 
-sub _koha_modify_subtitle {
-    my ( $dbh, $bibnum, $subtitle ) = @_;
-    my $sth =
-      $dbh->prepare(
-        "update bibliosubtitle set subtitle = ? where biblionumber = ?");
-    $sth->execute( $subtitle, $bibnum );
-    $sth->finish;
-}    # sub modsubtitle
+sub MARCmarc2kohaOneField {
 
-sub _koha_modify_additionalauthor {
-    my ( $dbh, $bibnum, @authors ) = @_;
+# FIXME ? if a field has a repeatable subfield that is used in old-db, only the 1st will be retrieved...
+    my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_;
 
-    #    my $dbh   = C4Connect;
-    my $sth =
-      $dbh->prepare("Delete from additionalauthors where biblionumber = ?");
+    my $res = "";
+    my ( $tagfield, $subfield ) =
+      MARCfind_marc_from_kohafield( "", $kohatable . "." . $kohafield,
+        $frameworkcode );
+    foreach my $field ( $record->field($tagfield) ) {
+        if ( $field->tag() < 10 ) {
+            if ( $result->{$kohafield} ) {
+                $result->{$kohafield} .= " | " . $field->data();
+            }
+            else {
+                $result->{$kohafield} = $field->data();
+            }
+        }
+        else {
+            if ( $field->subfields ) {
+                my @subfields = $field->subfields();
+                foreach my $subfieldcount ( 0 .. $#subfields ) {
+                    if ( $subfields[$subfieldcount][0] eq $subfield ) {
+                        if ( $result->{$kohafield} ) {
+                            $result->{$kohafield} .=
+                              " | " . $subfields[$subfieldcount][1];
+                        }
+                        else {
+                            $result->{$kohafield} =
+                              $subfields[$subfieldcount][1];
+                        }
+                    }
+                }
+            }
+        }
+    }
+    return $result;
+}
 
-    $sth->execute($bibnum);
-    $sth->finish;
-    foreach my $author (@authors) {
-        if ( $author ne '' ) {
-            $sth =
-              $dbh->prepare(
-                "Insert into additionalauthors set author = ?, biblionumber = ?"
-            );
+=head2 MARCitemchange
 
-            $sth->execute( $author, $bibnum );
+&MARCitemchange( $record, $itemfield, $newvalue )
 
-            $sth->finish;
-        }    # if
+=cut
+
+sub MARCitemchange {
+    my ( $record, $itemfield, $newvalue ) = @_;
+    my $dbh = C4::Context->dbh;
+    
+    my ( $tagfield, $tagsubfield ) =
+      MARCfind_marc_from_kohafield( $dbh, $itemfield, "" );
+    if ( ($tagfield) && ($tagsubfield) ) {
+        my $tag = $record->field($tagfield);
+        if ($tag) {
+            $tag->update( $tagsubfield => $newvalue );
+            $record->delete_field($tag);
+            $record->insert_fields_ordered($tag);
+        }
     }
-}    # sub modaddauthor
+}
 
-sub _koha_modify_subject {
-    my ( $dbh, $bibnum, $force, @subject ) = @_;
+=head1 INTERNAL FUNCTIONS
 
-    #  my $dbh   = C4Connect;
-    my $count = @subject;
-    my $error;
-    for ( my $i = 0 ; $i < $count ; $i++ ) {
-        $subject[$i] =~ s/^ //g;
-        $subject[$i] =~ s/ $//g;
-        my $sth =
-          $dbh->prepare(
-"select * from catalogueentry where entrytype = 's' and catalogueentry = ?"
-        );
-        $sth->execute( $subject[$i] );
+=head2 _koha_add_biblio
 
-        if ( my $data = $sth->fetchrow_hashref ) {
-        }
-        else {
-            if ( $force eq $subject[$i] || $force == 1 ) {
+_koha_add_biblio($dbh,$biblioitem);
 
-                # subject not in aut, chosen to force anway
-                # so insert into cataloguentry so its in auth file
-                my $sth2 =
-                  $dbh->prepare(
-"Insert into catalogueentry (entrytype,catalogueentry) values ('s',?)"
+Internal function to add a biblio ($biblio is a hash with the values)
+
+=cut
+
+sub _koha_add_biblio {
+    my ( $dbh, $biblio, $frameworkcode ) = @_;
+    my $sth = $dbh->prepare("Select max(biblionumber) from biblio");
+    $sth->execute;
+    my $data         = $sth->fetchrow_arrayref;
+    my $biblionumber = $$data[0] + 1;
+    my $series       = 0;
+
+    if ( $biblio->{'seriestitle'} ) { $series = 1 }
+    $sth->finish;
+    $sth = $dbh->prepare(
+        "INSERT INTO biblio
+    SET biblionumber  = ?, title = ?, author = ?, copyrightdate = ?, serial = ?, seriestitle = ?, notes = ?, abstract = ?, unititle = ?, frameworkcode = ? "
+    );
+    $sth->execute(
+        $biblionumber,         $biblio->{'title'},
+        $biblio->{'author'},   $biblio->{'copyrightdate'},
+        $biblio->{'serial'},   $biblio->{'seriestitle'},
+        $biblio->{'notes'},    $biblio->{'abstract'},
+        $biblio->{'unititle'}, $frameworkcode
                 );
 
-                $sth2->execute( $subject[$i] ) if ( $subject[$i] );
-                $sth2->finish;
+    $sth->finish;
+    return ($biblionumber);
+}
+
+=head2 _find_value
+
+    ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
+
+Find the given $subfield in the given $tag in the given
+MARC::Record $record.  If the subfield is found, returns
+the (indicators, value) pair; otherwise, (undef, undef) is
+returned.
+
+PROPOSITION :
+Such a function is used in addbiblio AND additem and serial-edit and maybe could be used in Authorities.
+I suggest we export it from this module.
+
+=cut
+
+sub _find_value {
+    my ( $tagfield, $insubfield, $record, $encoding ) = @_;
+    my @result;
+    my $indicator;
+    if ( $tagfield < 10 ) {
+        if ( $record->field($tagfield) ) {
+            push @result, $record->field($tagfield)->data();
             }
             else {
-                $error =
-                  "$subject[$i]\n does not exist in the subject authority file";
-                my $sth2 =
-                  $dbh->prepare(
-"Select * from catalogueentry where entrytype = 's' and (catalogueentry like ? or catalogueentry like ? or catalogueentry like ?)"
-                );
-                $sth2->execute( "$subject[$i] %", "% $subject[$i] %",
-                    "% $subject[$i]" );
-                while ( my $data = $sth2->fetchrow_hashref ) {
-                    $error .= "<br>$data->{'catalogueentry'}";
-                }    # while
-                $sth2->finish;
-            }    # else
-        }    # else
-        $sth->finish;
-    }    # else
-    if ( $error eq '' ) {
+            push @result, "";
+        }
+    }
+    else {
+        foreach my $field ( $record->field($tagfield) ) {
+            my @subfields = $field->subfields();
+            foreach my $subfield (@subfields) {
+                if ( @$subfield[0] eq $insubfield ) {
+                    push @result, @$subfield[1];
+                    $indicator = $field->indicator(1) . $field->indicator(2);
+                }
+            }
+        }
+    }
+    return ( $indicator, @result );
+}
+
+=head2 _koha_modify_biblio
+
+Internal function for updating the biblio table
+
+=cut
+
+sub _koha_modify_biblio {
+    my ( $dbh, $biblio ) = @_;
+
+# FIXME: this code could be made more portable by not hard-coding the values that are supposed to be in biblio table
         my $sth =
-          $dbh->prepare("Delete from bibliosubject where biblionumber = ?");
-        $sth->execute($bibnum);
-        $sth->finish;
-        $sth =
           $dbh->prepare(
-            "Insert into bibliosubject (subject,biblionumber) values (?,?)");
-        my $query;
-        foreach $query (@subject) {
-            $sth->execute( $query, $bibnum ) if ( $query && $bibnum );
-        }    # foreach
+"Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
+      );
+    $sth->execute(
+        $biblio->{'title'},       $biblio->{'author'},
+        $biblio->{'abstract'},    $biblio->{'copyrightdate'},
+        $biblio->{'seriestitle'}, $biblio->{'serial'},
+        $biblio->{'unititle'},    $biblio->{'notes'},
+        $biblio->{'biblionumber'}
+    );
         $sth->finish;
-    }    # if
+    return ( $biblio->{'biblionumber'} );
+}
 
-    #  $dbh->disconnect;
-    return ($error);
-}    # sub modsubject
+=head2 _koha_modify_biblioitem
+
+_koha_modify_biblioitem( $dbh, $biblioitem );
+
+=cut
 
 sub _koha_modify_biblioitem {
     my ( $dbh, $biblioitem ) = @_;
@@ -1985,9 +2374,12 @@
     $biblioitem->{'url'}             = $dbh->quote( $biblioitem->{'url'} );
     $biblioitem->{'isbn'}            = $dbh->quote( $biblioitem->{'isbn'} );
     $biblioitem->{'issn'}            = $dbh->quote( $biblioitem->{'issn'} );
-    $biblioitem->{'publishercode'}   = $dbh->quote( $biblioitem->{'publishercode'} );
-    $biblioitem->{'publicationyear'} = $dbh->quote( $biblioitem->{'publicationyear'} );
-    $biblioitem->{'classification'}  = $dbh->quote( $biblioitem->{'classification'} );
+    $biblioitem->{'publishercode'} =
+      $dbh->quote( $biblioitem->{'publishercode'} );
+    $biblioitem->{'publicationyear'} =
+      $dbh->quote( $biblioitem->{'publicationyear'} );
+    $biblioitem->{'classification'} =
+      $dbh->quote( $biblioitem->{'classification'} );
     $biblioitem->{'dewey'}           = $dbh->quote( $biblioitem->{'dewey'} );
     $biblioitem->{'subclass'}        = $dbh->quote( $biblioitem->{'subclass'} );
     $biblioitem->{'illus'}           = $dbh->quote( $biblioitem->{'illus'} );
@@ -1997,36 +2389,39 @@
     $biblioitem->{'size'}            = $dbh->quote( $biblioitem->{'size'} );
     $biblioitem->{'place'}           = $dbh->quote( $biblioitem->{'place'} );
     $biblioitem->{'ccode'}       = $dbh->quote( $biblioitem->{'ccode'} );
-    $biblioitem->{'biblionumber'} = $dbh->quote ($biblioitem->{'biblionumber'} );
-
-#    my($lcsort) = calculatelc($biblioitem->{'classification'}).$biblioitem->{'subclass'};
-#    $lcsort=$dbh->quote($lcsort);
-
+    $biblioitem->{'biblionumber'} =
+      $dbh->quote( $biblioitem->{'biblionumber'} );
 
  $query = "Update biblioitems set
-itemtype        = $biblioitem->{'itemtype'},
-url             = $biblioitem->{'url'},
-isbn            = $biblioitem->{'isbn'},
-issn            = $biblioitem->{'issn'},
-publishercode   = $biblioitem->{'publishercode'},
-publicationyear = $biblioitem->{'publicationyear'},
-classification  = $biblioitem->{'classification'},
-dewey           = $biblioitem->{'dewey'},
-subclass        = $biblioitem->{'subclass'},
-illus           = $biblioitem->{'illus'},
-pages           = $biblioitem->{'pages'},
-volumeddesc     = $biblioitem->{'volumeddesc'},
-notes         = $biblioitem->{'bnotes'},
-size        = $biblioitem->{'size'},
-place        = $biblioitem->{'place'},
-ccode        = $biblioitem->{'ccode'}
-where biblionumber = $biblioitem->{'biblionumber'}";
+        itemtype        = $biblioitem->{'itemtype'},
+        url             = $biblioitem->{'url'},
+        isbn            = $biblioitem->{'isbn'},
+        issn            = $biblioitem->{'issn'},
+        publishercode   = $biblioitem->{'publishercode'},
+        publicationyear = $biblioitem->{'publicationyear'},
+        classification  = $biblioitem->{'classification'},
+        dewey           = $biblioitem->{'dewey'},
+        subclass        = $biblioitem->{'subclass'},
+        illus           = $biblioitem->{'illus'},
+        pages           = $biblioitem->{'pages'},
+        volumeddesc     = $biblioitem->{'volumeddesc'},
+        notes           = $biblioitem->{'bnotes'},
+        size            = $biblioitem->{'size'},
+        place           = $biblioitem->{'place'},
+        ccode           = $biblioitem->{'ccode'}
+        where biblionumber = $biblioitem->{'biblionumber'}";
 
     $dbh->do($query);
     if ( $dbh->errstr ) {
         warn "$query";
     }
-    }
+}
+
+=head2 _koha_modify_note
+
+_koha_modify_note( $dbh, $bibitemnum, $note );
+
+=cut
 
 sub _koha_modify_note {
     my ( $dbh, $bibitemnum, $note ) = @_;
@@ -2037,25 +2432,21 @@
     my $sth = $dbh->prepare($query);
     $sth->execute;
     $sth->finish;
-
-    #  $dbh->disconnect;
 }
 
-=item
+=head2 _koha_add_biblioitem
 
-=over 4
+_koha_add_biblioitem( $dbh, $biblioitem );
 
 Internal function to add a biblioitem
 
-=back
-
 =cut
 
 sub _koha_add_biblioitem {
     my ( $dbh, $biblioitem ) = @_;
 
     #  my $dbh   = C4Connect;
-    my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
+    my $sth = $dbh->prepare("SELECT max(biblioitemnumber) FROM biblioitems");
     my $data;
     my $bibitemnum;
 
@@ -2065,7 +2456,8 @@
 
     $sth->finish;
 
-    $sth = $dbh->prepare( "insert into biblioitems set
+    $sth = $dbh->prepare(
+        "INSERT INTO biblioitems SET
                                     biblioitemnumber = ?,        biblionumber      = ?,
                                     volume         = ?,            number         = ?,
                                     classification  = ?,            itemtype         = ?,
@@ -2076,12 +2468,13 @@
                                     volumeddesc     = ?,        illus         = ?,
                                     pages         = ?,                notes         = ?,
                                     size         = ?,                lccn         = ?,
-                                    marc         = ?,
-    
-                                    place         = ?, lcsort=?, ccode = ?
+            marc             = ?, lcsort          =?,
+            place            = ?, ccode           = ?
                                     "
     );
-my ($lcsort)=calculatelc($biblioitem->{'classification'}).$biblioitem->{'subclass'};
+    my ($lcsort) =
+      calculatelc( $biblioitem->{'classification'} )
+      . $biblioitem->{'subclass'};
     $sth->execute(
         $bibitemnum,                     $biblioitem->{'biblionumber'},
         $biblioitem->{'volume'},         $biblioitem->{'number'},
@@ -2093,30 +2486,18 @@
         $biblioitem->{'volumeddesc'},    $biblioitem->{'illus'},
         $biblioitem->{'pages'},          $biblioitem->{'bnotes'},
         $biblioitem->{'size'},           $biblioitem->{'lccn'},
-        $biblioitem->{'marc'},           $biblioitem->{'place'},$lcsort,$biblioitem->{'ccode'}
+        $biblioitem->{'marc'},           $biblioitem->{'place'},
+        $lcsort,                         $biblioitem->{'ccode'}
     );
     $sth->finish;
-
-    #    $dbh->disconnect;
     return ($bibitemnum);
 }
 
-sub _koha_add_subject {
-    my ( $dbh, $bibnum ) = @_;
-    my $sth =
-      $dbh->prepare("insert into bibliosubject (biblionumber) values (?)");
-    $sth->execute($bibnum);
-    $sth->finish;
-}
+=head2 _koha_new_items
 
-sub _koha_add_subtitle {
-    my ( $dbh, $bibnum, $subtitle ) = @_;
-    my $sth =
-      $dbh->prepare(
-        "insert into bibliosubtitle set biblionumber = ?, subtitle = ?");
-    $sth->execute( $bibnum, $subtitle ) if $subtitle;
-    $sth->finish;
-}
+_koha_new_items( $dbh, $item, $barcode );
+
+=cut
 
 sub _koha_new_items {
     my ( $dbh, $item, $barcode ) = @_;
@@ -2131,9 +2512,13 @@
     $data       = $sth->fetchrow_hashref;
     $itemnumber = $data->{'max(itemnumber)'} + 1;
     $sth->finish;
-    $sth->finish;
 ## Now calculate lccalnumber
-my ($cutterextra)=itemcalculator($dbh,$item->{'biblioitemnumber'},$item->{'itemcallnumber'});
+    my ($cutterextra) = itemcalculator(
+        $dbh,
+        $item->{'biblioitemnumber'},
+        $item->{'itemcallnumber'}
+    );
+
 # FIXME the "notforloan" field seems to be named "loan" in some places. workaround bugfix.
     if ( $item->{'loan'} ) {
         $item->{'notforloan'} = $item->{'loan'};
@@ -2142,7 +2527,8 @@
     # if dateaccessioned is provided, use it. Otherwise, set to NOW()
     if ( $item->{'dateaccessioned'} eq '' || !$item->{'dateaccessioned'} ) {
 
-        $sth = $dbh->prepare( "Insert into items set
+        $sth = $dbh->prepare(
+            "Insert into items set
                             itemnumber           = ?,            biblionumber         = ?,
                             multivolumepart      = ?,
                             biblioitemnumber     = ?,            barcode              = ?,
@@ -2154,26 +2540,25 @@
                             itemlost            = ?,            wthdrawn            = ?,
                             paidfor                = ?,            itemnotes            = ?,
                             itemcallnumber    =?,                             notforloan = ?,
-                            location = ?,
-                            Cutterextra=?
+            location             = ?,     Cutterextra      = ?
                             "
         );
         $sth->execute(
             $itemnumber,                $item->{'biblionumber'},
-            $item->{'multivolumepart'},
-            $item->{'biblioitemnumber'},$barcode,
-            $item->{'booksellerid'},
+            $item->{'multivolumepart'}, $item->{'biblioitemnumber'},
+            $barcode,                   $item->{'booksellerid'},
             $item->{'homebranch'},        $item->{'holdingbranch'},
             $item->{'price'},            $item->{'replacementprice'},
             $item->{multivolume},        $item->{stack},
             $item->{itemlost},            $item->{wthdrawn},
             $item->{paidfor},            $item->{'itemnotes'},
             $item->{'itemcallnumber'},    $item->{'notforloan'},
-            $item->{'location'},$cutterextra
+            $item->{'location'},        $cutterextra
         );
     }
     else {
-        $sth = $dbh->prepare( "Insert into items set
+        $sth = $dbh->prepare(
+            "INSERT INTO items SET
                             itemnumber           = ?,            biblionumber         = ?,
                             multivolumepart      = ?,
                             biblioitemnumber     = ?,            barcode              = ?,
@@ -2184,41 +2569,48 @@
                             multivolume            = ?,            stack                = ?,
                             itemlost            = ?,            wthdrawn            = ?,
                             paidfor                = ?,            itemnotes            = ?,
-                            itemcallnumber    =?,                             notforloan = ?,
+            itemcallnumber       = ?,     notforloan       = ?,
                             location = ?,
-                            Cutterextra=?
+            Cutterextra          = ?
                             "
         );
         $sth->execute(
             $itemnumber,                $item->{'biblionumber'},
-            $item->{'multivolumepart'},
-            $item->{'biblioitemnumber'},$barcode,
-            $item->{'booksellerid'},    $item->{'dateaccessioned'},
-            $item->{'homebranch'},        $item->{'holdingbranch'},
-            $item->{'price'},            $item->{'replacementprice'},
-            $item->{multivolume},        $item->{stack},
-            $item->{itemlost},            $item->{wthdrawn},
-            $item->{paidfor},            $item->{'itemnotes'},
-            $item->{'itemcallnumber'},    $item->{'notforloan'},
-            $item->{'location'},$cutterextra
+            $item->{'multivolumepart'},  $item->{'biblioitemnumber'},
+            $barcode,                    $item->{'booksellerid'},
+            $item->{'dateaccessioned'},  $item->{'homebranch'},
+            $item->{'holdingbranch'},    $item->{'price'},
+            $item->{'replacementprice'}, $item->{multivolume},
+            $item->{stack},              $item->{itemlost},
+            $item->{wthdrawn},           $item->{paidfor},
+            $item->{'itemnotes'},        $item->{'itemcallnumber'},
+            $item->{'notforloan'},       $item->{'location'},
+            $cutterextra
         );
     }
     if ( defined $sth->errstr ) {
         $error .= $sth->errstr;
     }
-
     return ( $itemnumber, $error );
 }
 
+=head2 _koha_modify_item
+
+_koha_modify_item( $dbh, $item, $op );
+
+=cut
+
 sub _koha_modify_item {
     my ( $dbh, $item, $op ) = @_;
     $item->{'itemnum'} = $item->{'itemnumber'} unless $item->{'itemnum'};
 
     # if all we're doing is setting statuses, just update those and get out
-    if ($op eq "setstatus") {
-        my $query = "UPDATE items SET itemlost=?,wthdrawn=?,binding=? WHERE itemnumber=?";
+    if ( $op eq "setstatus" ) {
+        my $query =
+          "UPDATE items SET itemlost=?,wthdrawn=?,binding=? WHERE itemnumber=?";
         my @bind = (
-            $item->{'itemlost'}, $item->{'wthdrawn'}, $item->{'binding'},$item->{'itemnumber'}
+            $item->{'itemlost'}, $item->{'wthdrawn'},
+            $item->{'binding'},  $item->{'itemnumber'}
             );
         my $sth = $dbh->prepare($query);
         $sth->execute(@bind);
@@ -2226,7 +2618,8 @@
         return undef;
     }
 ## Now calculate lccalnumber
-my ($cutterextra)=itemcalculator($dbh,$item->{'bibitemnum'},$item->{'itemcallnumber'});
+    my ($cutterextra) =
+      itemcalculator( $dbh, $item->{'bibitemnum'}, $item->{'itemcallnumber'} );
 
     my $query = "UPDATE items SET
 barcode=?,itemnotes=?,itemcallnumber=?,notforloan=?,location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,homebranch=?,cutterextra=?, onloan=?, binding=?";
@@ -2236,10 +2629,13 @@
         $item->{'itemcallnumber'},    $item->{'notforloan'},
         $item->{'location'},        $item->{multivolumepart},
         $item->{multivolume},        $item->{stack},
-        $item->{wthdrawn},$item->{holdingbranch},$item->{homebranch},$cutterextra,$item->{onloan},$item->{binding}
+        $item->{wthdrawn},         $item->{holdingbranch},
+        $item->{homebranch},       $cutterextra,
+        $item->{onloan},           $item->{binding}
     );
     if ( $item->{'lost'} ne '' ) {
-        $query = "update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
+        $query =
+"update items set biblioitemnumber=?,barcode=?,itemnotes=?,homebranch=?,
                             itemlost=?,wthdrawn=?,itemcallnumber=?,notforloan=?,
                              location=?,multivolumepart=?,multivolume=?,stack=?,wthdrawn=?,holdingbranch=?,cutterextra=?,onloan=?, binding=?";
         @bind = (
@@ -2249,19 +2645,21 @@
             $item->{'itemcallnumber'}, $item->{'notforloan'},
             $item->{'location'},        $item->{multivolumepart},
             $item->{multivolume},        $item->{stack},
-            $item->{wthdrawn},$item->{holdingbranch},$cutterextra,$item->{onloan},$item->{binding}
+            $item->{wthdrawn},         $item->{holdingbranch},
+            $cutterextra,              $item->{onloan},
+            $item->{binding}
         );
-        if ($item->{homebranch}) {
-            $query.=",homebranch=?";
+        if ( $item->{homebranch} ) {
+            $query .= ",homebranch=?";
             push @bind, $item->{homebranch};
         }
-        if ($item->{holdingbranch}) {
-            $query.=",holdingbranch=?";
+        if ( $item->{holdingbranch} ) {
+            $query .= ",holdingbranch=?";
             push @bind, $item->{holdingbranch};
         }
     }
-    $query.=" where itemnumber=?";
-    push @bind,$item->{'itemnum'};
+    $query .= " where itemnumber=?";
+    push @bind, $item->{'itemnum'};
    if ( $item->{'replacement'} ne '' ) {
         $query =~ s/ where/,replacementprice='$item->{'replacement'}' where/;
     }
@@ -2272,12 +2670,10 @@
 
 =head2 _koha_delete_item
 
-=over 4
+_koha_delete_item( $dbh, $itemnum );
 
 Internal function to delete an item record from the koha tables
 
-=back
-
 =cut
 
 sub _koha_delete_item {
@@ -2291,7 +2687,7 @@
     my @bind  = ();
     foreach my $temp ( keys %$data ) {
         $query .= "$temp = ?,";
-        push ( @bind, $data->{$temp} );
+        push( @bind, $data->{$temp} );
     }
     $query =~ s/\,$//;
 
@@ -2302,74 +2698,9 @@
     $sth = $dbh->prepare("Delete from items where itemnumber=?");
     $sth->execute($itemnum);
     $sth->finish;
-
-    #  $dbh->disconnect;
-}
-
-sub _koha_delete_biblioitem {
-    my ( $dbh, $biblioitemnumber ) = @_;
-
-    #    my $dbh   = C4Connect;
-    my $sth = $dbh->prepare( "Select * from biblioitems
-where biblioitemnumber = ?"
-    );
-    my $results;
-
-    $sth->execute($biblioitemnumber);
-
-    if ( $results = $sth->fetchrow_hashref ) {
-        $sth->finish;
-        $sth =
-          $dbh->prepare(
-"Insert into deletedbiblioitems (biblioitemnumber, biblionumber, volume, number, classification, itemtype,
-                    isbn, issn ,dewey ,subclass ,publicationyear ,publishercode ,volumedate ,volumeddesc ,timestamp ,illus ,
-                         pages ,notes ,size ,url ,lccn ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
-        );
-
-        $sth->execute(
-            $results->{biblioitemnumber}, $results->{biblionumber},
-            $results->{volume},           $results->{number},
-            $results->{classification},   $results->{itemtype},
-            $results->{isbn},             $results->{issn},
-            $results->{dewey},            $results->{subclass},
-            $results->{publicationyear},  $results->{publishercode},
-            $results->{volumedate},       $results->{volumeddesc},
-            $results->{timestamp},        $results->{illus},
-            $results->{pages},            $results->{notes},
-            $results->{size},             $results->{url},
-            $results->{lccn}
-        );
-        my $sth2 =
-          $dbh->prepare("Delete from biblioitems where biblioitemnumber = ?");
-        $sth2->execute($biblioitemnumber);
-        $sth2->finish();
-    }    # if
-    $sth->finish;
-
-    # Now delete all the items attached to the biblioitem
-    $sth = $dbh->prepare("Select * from items where biblioitemnumber = ?");
-    $sth->execute($biblioitemnumber);
-    my @results;
-#    while ( my $data = $sth->fetchrow_hashref ) {
-#        my $query = "Insert into deleteditems set ";
-#        my @bind  = ();
-#        foreach my $temp ( keys %$data ) {
-#            $query .= "$temp = ?,";
-#           push ( @bind, $data->{$temp} );
-#        }
-#        $query =~ s/\,$//;
-#        my $sth2 = $dbh->prepare($query);
-#        $sth2->execute(@bind);
-#    }    # while
-    $sth->finish;
-    $sth = $dbh->prepare("Delete from items where biblioitemnumber = ?");
-    $sth->execute($biblioitemnumber);
-    $sth->finish();
-
-    #    $dbh->disconnect;
 }    
 
-=item _koha_delete_biblio
+=head2 _koha_delete_biblio
 
 $error = _koha_delete_biblio($dbh,$biblionumber);
 
@@ -2379,6 +2710,7 @@
 C<$biblionumber> - the biblionumber of the biblio to be deleted
 
 =cut
+
 # FIXME: add error handling
 
 sub _koha_delete_biblio {
@@ -2389,13 +2721,14 @@
     $sth->execute($biblionumber);
 
     if ( my $data = $sth->fetchrow_hashref ) {
+
         # save the record in deletedbiblio
         # find the fields to save
         my $query = "INSERT INTO deletedbiblio SET ";
         my @bind  = ();
         foreach my $temp ( keys %$data ) {
             $query .= "$temp = ?,";
-            push ( @bind, $data->{$temp} );
+            push( @bind, $data->{$temp} );
         }
 
         # replace the last , by ",?)"
@@ -2413,7 +2746,7 @@
     return undef;
 }
 
-=item _koha_delete_biblioitems
+=head2 _koha_delete_biblioitems
 
 $error = _koha_delete_biblioitems($dbh,$biblioitemnumber);
 
@@ -2423,23 +2756,26 @@
 C<$biblionumber> - the biblioitemnumber of the biblioitem to be deleted
 
 =cut
+
 # FIXME: add error handling
 
 sub _koha_delete_biblioitems {
     my ( $dbh, $biblioitemnumber ) = @_;
 
     # get all the data for this biblioitem
-    my $sth = $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
+    my $sth =
+      $dbh->prepare("SELECT * FROM biblioitems WHERE biblioitemnumber=?");
     $sth->execute($biblioitemnumber);
 
     if ( my $data = $sth->fetchrow_hashref ) {
+
         # save the record in deletedbiblioitems
         # find the fields to save
         my $query = "INSERT INTO deletedbiblioitems SET ";
         my @bind  = ();
         foreach my $temp ( keys %$data ) {
             $query .= "$temp = ?,";
-            push ( @bind, $data->{$temp} );
+            push( @bind, $data->{$temp} );
         }
 
         # replace the last , by ",?)"
@@ -2448,847 +2784,221 @@
         $bkup_sth->execute(@bind);
         $bkup_sth->finish;
 
-        # delete the biblioitem
-        my $del_sth = $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
-        $del_sth->execute($biblioitemnumber);
-        $del_sth->finish;
-    }
-    $sth->finish;
-    return undef;
-}
-
-
-=item _koha_delete_items
-
-$error = _koha_delete_items($dbh,$itemnumber);
-
-Internal sub for deleting from items table -- also saves to deleteditems
-
-C<$dbh> - the database handle
-C<$itemnumber> - the itemnumber of the item to be deleted
-
-=cut
-# FIXME: add error handling
-
-sub _koha_delete_items {
-    my ( $dbh, $itemnumber ) = @_;
-
-    # get all the data for this item
-    my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
-    $sth->execute($itemnumber);
-
-    if ( my $data = $sth->fetchrow_hashref ) {
-        # save the record in deleteditems
-        # find the fields to save
-        my $query = "INSERT INTO deleteditems SET ";
-        my @bind  = ();
-        foreach my $temp ( keys %$data ) {
-            $query .= "$temp = ?,";
-            push ( @bind, $data->{$temp} );
-        }
-
-        # replace the last , by ",?)"
-        $query =~ s/\,$//;
-        my $bkup_sth = $dbh->prepare($query);
-        $bkup_sth->execute(@bind);
-        $bkup_sth->finish;
-
-        # delete the item
-        my $del_sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?");
-        $del_sth->execute($itemnumber);
-        $del_sth->finish;
-    }
-    $sth->finish;
-    return undef;
-}
-
-#
-#
-# old functions
-#
-#
-
-sub itemcount {
-    my ($biblio) = @_;
-    my $dbh = C4::Context->dbh;
-
-    #  print $query;
-    my $sth = $dbh->prepare("Select count(*) from items where biblionumber=?");
-    $sth->execute($biblio);
-    my $data = $sth->fetchrow_hashref;
-    $sth->finish;
-    return ( $data->{'count(*)'} );
-}
-
-sub newbiblio {
-    my ($biblio) = @_;
-    my $dbh    = C4::Context->dbh;
-    my $bibnum = _koha_add_biblio( $dbh, $biblio );
-    my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
-    MARCaddbiblio($dbh,$record, $bibnum,'' );
-    return ($bibnum);
-}
-
-=item modbiblio
-
-  $biblionumber = &modbiblio($biblio);
-
-Update a biblio record.
-
-C<$biblio> is a reference-to-hash whose keys are the fields in the
-biblio table in the Koha database. All fields must be present, not
-just the ones you wish to change.
-
-C<&modbiblio> updates the record defined by
-C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
-
-C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
-successful or not.
-
-=cut
-
-sub modbiblio {
-    my ($biblio) = @_;
-    my $dbh  = C4::Context->dbh;
-    my $biblionumber=_koha_modify_biblio($dbh,$biblio);
-    my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
-    MARCmodbiblio($dbh,$biblionumber,$record,"",0);
-    return($biblionumber);
-} # sub modbiblio
-
-=item modsubtitle
-
-  &modsubtitle($biblionumber, $subtitle);
-
-Sets the subtitle of a book.
-
-C<$biblionumber> is the biblionumber of the book to modify.
-
-C<$subtitle> is the new subtitle.
-
-=cut
-
-sub modsubtitle {
-    my ( $bibnum, $subtitle ) = @_;
-    my $dbh = C4::Context->dbh;
-    &_koha_modify_subtitle( $dbh, $bibnum, $subtitle );
-}    # sub modsubtitle
-
-=item modaddauthor
-
-  &modaddauthor($biblionumber, $author);
-
-Replaces all additional authors for the book with biblio number
-C<$biblionumber> with C<$author>. If C<$author> is the empty string,
-C<&modaddauthor> deletes all additional authors.
-
-=cut
-
-sub modaddauthor {
-    my ( $bibnum, @authors ) = @_;
-    my $dbh = C4::Context->dbh;
-    &_koha_modify_additionalauthor( $dbh, $bibnum, @authors );
-}    # sub modaddauthor
-
-=item modsubject
-
-  $error = &modsubject($biblionumber, $force, @subjects);
-
-$force - a subject to force
-
-$error - Error message, or undef if successful.
-
-=cut
-
-sub modsubject {
-    my ( $biblionumber, $force, @subject ) = @_;
-    my $dbh = C4::Context->dbh;
-    my $error = &_koha_modify_subject( $dbh, $biblionumber, $force, @subject );
-    if ($error eq ''){
-        # When MARC is off, ensures that the MARC biblio table gets updated with new
-        # subjects, of course, it deletes the biblio in marc, and then recreates.
-        # This check is to ensure that no MARC data exists to lose.
-        if (C4::Context->preference("MARC") eq '0'){
-            my $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber);
-            &MARCmodbiblio($dbh,$biblionumber, $MARCRecord);
-        }
-    }
-    return ($error);
-}    # sub modsubject
-
-sub modbibitem {
-    my ($biblioitem) = @_;
-    my $dbh = C4::Context->dbh;
-    &_koha_modify_biblio( $dbh, $biblioitem );
-}    # sub modbibitem
-
-sub modnote {
-    my ( $bibitemnum, $note ) = @_;
-    my $dbh = C4::Context->dbh;
-    &_koha_modify_note( $dbh, $bibitemnum, $note );
-}
-
-sub newbiblioitem {
-    my ($biblioitem) = @_;
-    my $dbh        = C4::Context->dbh;
-    my $bibitemnum = &_koha_add_biblioitem( $dbh, $biblioitem );
-
-    my $MARCbiblio =
-      MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
-      ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
-
-    &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, '' );
-    return ($bibitemnum);
-}
-
-sub newsubject {
-    my ($bibnum) = @_;
-    my $dbh = C4::Context->dbh;
-    &_koha_add_subject( $dbh, $bibnum );
-}
-
-sub newsubtitle {
-    my ( $bibnum, $subtitle ) = @_;
-    my $dbh = C4::Context->dbh;
-    &_koha_add_subtitle( $dbh, $bibnum, $subtitle );
-}
-
-sub newitems {
-    my ( $item, @barcodes ) = @_;
-    my $dbh = C4::Context->dbh;
-    my $errors;
-    my $itemnumber;
-    my $error;
-    foreach my $barcode (@barcodes) {
-        ( $itemnumber, $error ) = &_koha_new_items( $dbh, $item, uc($barcode) );
-        $errors .= $error;
-        my $MARCitem = &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
-        &MARCadditem( $dbh, $MARCitem, $item->{biblionumber} );
-    }
-    return ($errors);
-}
-
-sub moditem {
-    my ($item,$op) = @_;
-    my $dbh = C4::Context->dbh;
-    &_koha_modify_item( $dbh, $item, $op);
-    # if we're just setting statuses, just update items table
-    # it's faster and zebra and marc will be synched anyway by the cron job
-    unless ($op eq "setstatus") {
-        my $MARCitem = &MARCkoha2marcItem( $dbh, $item->{'biblionumber'}, $item->{'itemnum'} );
-        &MARCmoditem( $dbh, $MARCitem, $item->{biblionumber}, $item->{itemnum}, 0 );
-    }
-}
-
-sub checkitems {
-    my ( $count, @barcodes ) = @_;
-    my $dbh = C4::Context->dbh;
-    my $error;
-    my $sth = $dbh->prepare("Select * from items where barcode=?");
-    for ( my $i = 0 ; $i < $count ; $i++ ) {
-        $barcodes[$i] = uc $barcodes[$i];
-        $sth->execute( $barcodes[$i] );
-        if ( my $data = $sth->fetchrow_hashref ) {
-            $error .= " Duplicate Barcode: $barcodes[$i]";
-        }
-    }
-    $sth->finish;
-    return ($error);
-}
-
-=item GetItemsInfo
-
-  @results = &GetItemsInfo($biblionumber, $type);
-
-Returns information about books with the given biblionumber.
-
-C<$type> may be either C<intra> or anything else. If it is not set to
-C<intra>, then the search will exclude lost, very overdue, and
-withdrawn items.
-
-C<&GetItemsInfo> returns a list of references-to-hash. Each element
-contains a number of keys. Most of them are table items from the
-C<biblio>, C<biblioitems>, C<items>, and C<itemtypes> tables in the
-Koha database. Other keys include:
-
-=over 4
-
-=item C<$data-E<gt>{branchname}>
-
-The name (not the code) of the branch to which the book belongs.
-
-=item C<$data-E<gt>{datelastseen}>
-
-This is simply C<items.datelastseen>, except that while the date is
-stored in YYYY-MM-DD format in the database, here it is converted to
-DD/MM/YYYY format. A NULL date is returned as C<//>.
-
-=item C<$data-E<gt>{datedue}>
-
-=item C<$data-E<gt>{class}>
-
-This is the concatenation of C<biblioitems.classification>, the book's
-Dewey code, and C<biblioitems.subclass>.
-
-=item C<$data-E<gt>{ocount}>
-
-I think this is the number of copies of the book available.
-
-=item C<$data-E<gt>{order}>
-
-If this is set, it is set to C<One Order>.
-
-=back
-
-=cut
-
-#'
-sub GetItemsInfo {
-    my ($biblionumber,$type) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $query = "SELECT *,items.notforloan as itemnotforloan
-                 FROM items, biblio, biblioitems
-                 LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype
-                WHERE items.biblionumber = ?
-                    AND biblioitems.biblioitemnumber = items.biblioitemnumber
-                    AND biblio.biblionumber = items.biblionumber
-                ORDER BY items.dateaccessioned desc
-                 ";
-    my $sth=$dbh->prepare($query);
-    $sth->execute($biblionumber);
-    my $i=0;
-    my @results;
-    my ($date_due, $count_reserves);
-    while (my $data=$sth->fetchrow_hashref){
-        my $datedue = '';
-        my $isth=$dbh->prepare(
-           "SELECT issues.*,borrowers.cardnumber
-            FROM   issues, borrowers
-            WHERE  itemnumber = ?
-                AND returndate IS NULL
-                AND issues.borrowernumber=borrowers.borrowernumber"
-        );
-        $isth->execute($data->{'itemnumber'});
-        if (my $idata=$isth->fetchrow_hashref){
-            $data->{borrowernumber} = $idata->{borrowernumber};
-            $data->{cardnumber} = $idata->{cardnumber};
-            $datedue = format_date($idata->{'date_due'});
-        }
-        if ($datedue eq ''){
-            #$datedue="Available";
-            my ($restype,$reserves)=C4::Reserves2::CheckReserves($data->{'itemnumber'});
-            if ($restype) {
-                #$datedue=$restype;
-                $count_reserves = $restype;
-            }
-        }
-        $isth->finish;
-    
-        #get branch information.....
-        my $bsth=$dbh->prepare(
-            "SELECT * FROM branches WHERE branchcode = ?
-        ");
-        $bsth->execute($data->{'holdingbranch'});
-        if (my $bdata=$bsth->fetchrow_hashref){
-            $data->{'branchname'} = $bdata->{'branchname'};
-        }
-        my $date=format_date($data->{'datelastseen'});
-        $data->{'datelastseen'}=$date;
-        $data->{'datedue'}=$datedue;
-        $data->{'count_reserves'} = $count_reserves;
-    
-        # get notforloan complete status if applicable
-        my $sthnflstatus = $dbh->prepare(
-            'SELECT authorised_value
-            FROM   marc_subfield_structure
-            WHERE  kohafield="items.notforloan"
-        ');
-    
-        $sthnflstatus->execute;
-        my ($authorised_valuecode) = $sthnflstatus->fetchrow;
-        if ($authorised_valuecode) {
-            $sthnflstatus = $dbh->prepare(
-                "SELECT lib FROM authorised_values
-                 WHERE  category=?
-                 AND authorised_value=?"
-            );
-            $sthnflstatus->execute($authorised_valuecode,$data->{itemnotforloan});
-            my ($lib) = $sthnflstatus->fetchrow;
-            $data->{notforloan} = $lib;
-        }
-
-        # my stack procedures
-        my $stackstatus = $dbh->prepare(
-            'SELECT authorised_value
-             FROM   marc_subfield_structure
-             WHERE  kohafield="items.stack"
-        ');
-        $stackstatus->execute;
-    
-        ($authorised_valuecode) = $stackstatus->fetchrow;
-        if ($authorised_valuecode) {
-            $stackstatus = $dbh->prepare(
-                "SELECT lib
-                 FROM   authorised_values
-                 WHERE  category=?
-                 AND    authorised_value=?
-            ");
-            $stackstatus->execute($authorised_valuecode,$data->{stack});
-    
-            my ($lib) = $stackstatus->fetchrow;
-            $data->{stack} = $lib;
-        }
-        $results[$i]=$data;
-        $i++;
-    }
-    $sth->finish;
-
-    return(@results);
-}
-=head2 getitemstatus
-
-  $itemstatushash = &getitemstatus($fwkcode);
-  returns information about status.
-  Can be MARC dependant.
-  fwkcode is optional.
-  But basically could be can be loan or not
-  Create a status selector with the following code
-  
-=head3 in PERL SCRIPT
-
-my $itemstatushash = getitemstatus;
-my @itemstatusloop;
-foreach my $thisstatus (keys %$itemstatushash) {
-    my %row =(value => $thisstatus,
-                statusname => $itemstatushash->{$thisstatus}->{'statusname'},
-            );
-    push @itemstatusloop, \%row;
-}
-$template->param(statusloop=>\@itemstatusloop);
-
-
-=head3 in TEMPLATE  
-            <select name="statusloop">
-                <option value="">Default</option>
-            <!-- TMPL_LOOP name="statusloop" -->
-                <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
-            <!-- /TMPL_LOOP -->
-            </select>
-
-=cut
-sub GetItemStatus {
-# returns a reference to a hash of references to status...
-    my ($fwk)=@_;
-    my %itemstatus;
-     my $dbh = C4::Context->dbh;
-     my $sth;
-    $fwk='' unless ($fwk);
-     my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.notforloan",$fwk);
-    if ($tag and $subfield){
-        my $sth = $dbh->prepare("select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
-        $sth->execute($tag,$subfield,$fwk);
-        if (my ($authorisedvaluecat)=$sth->fetchrow){
-            my $authvalsth=$dbh->prepare("select authorised_value, lib from authorised_values where category=? order by lib");
-            $authvalsth->execute($authorisedvaluecat);
-            while (my ($authorisedvalue, $lib)=$authvalsth->fetchrow){
-                $itemstatus{$authorisedvalue}=$lib;
-            }
-            $authvalsth->finish;
-            return \%itemstatus;
-            exit 1;
-        } else{
-            #No authvalue list
-            # build default
-        }
-        $sth->finish;
-    }
-    #No authvalue list
-    #build default
-    $itemstatus{"1"}="Not For Loan";
-    return \%itemstatus;
-}
-=head2 getitemlocation
-
-  $itemlochash = &getitemlocation($fwk);
-  returns informations about location.
-  where fwk stands for an optional framework code.
-  Create a location selector with the following code
-  
-=head3 in PERL SCRIPT
-
-my $itemlochash = getitemlocation;
-my @itemlocloop;
-foreach my $thisloc (keys %$itemlochash) {
-    my $selected = 1 if $thisbranch eq $branch;
-    my %row =(locval => $thisloc,
-                selected => $selected,
-                locname => $itemlochash->{$thisloc},
-            );
-    push @itemlocloop, \%row;
-}
-$template->param(itemlocationloop => \@itemlocloop);
-
-=head3 in TEMPLATE  
-            <select name="location">
-                <option value="">Default</option>
-            <!-- TMPL_LOOP name="itemlocationloop" -->
-                <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
-            <!-- /TMPL_LOOP -->
-            </select>
-
-=cut
-sub GetItemLocation {
-# returns a reference to a hash of references to location...
-    my ($fwk)=@_;
-    my %itemlocation;
-     my $dbh = C4::Context->dbh;
-     my $sth;
-    $fwk='' unless ($fwk);
-     my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.location",$fwk);
-    if ($tag and $subfield){
-        my $sth = $dbh->prepare("select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?");
-        $sth->execute($tag,$subfield,$fwk);
-        if (my ($authorisedvaluecat)=$sth->fetchrow){
-            my $authvalsth=$dbh->prepare("select authorised_value, lib from authorised_values where category=? order by lib");
-            $authvalsth->execute($authorisedvaluecat);
-            while (my ($authorisedvalue, $lib)=$authvalsth->fetchrow){
-                $itemlocation{$authorisedvalue}=$lib;
-            }
-            $authvalsth->finish;
-            return \%itemlocation;
-            exit 1;
-        } else{
-            #No authvalue list
-            # build default
-        }
-        $sth->finish;
-    }
-    #No authvalue list
-    #build default
-    $itemlocation{"1"}="Not For Loan";
-    return \%itemlocation;
-}
-
-sub countitems {
-    my ($bibitemnum) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $query = "";
-    my $sth   =
-      $dbh->prepare("Select count(*) from items where biblioitemnumber=?");
-    $sth->execute($bibitemnum);
-    my $data = $sth->fetchrow_hashref;
-    $sth->finish;
-    return ( $data->{'count(*)'} );
-}
-
-sub delitem {
-    my ($itemnum) = @_;
-    my $dbh = C4::Context->dbh;
-    &OLDdelitem( $dbh, $itemnum );
-}
-
-sub deletebiblioitem {
-    my ($biblioitemnumber) = @_;
-    my $dbh = C4::Context->dbh;
-    &OLDdeletebiblioitem( $dbh, $biblioitemnumber );
-}    # sub deletebiblioitem
-
-sub delbiblio {
-    my ($biblionumber) = @_;
-    my $dbh = C4::Context->dbh;
-    &OLDdelbiblio( $dbh, $biblionumber );
-    &MARCdelbiblio( $dbh, $biblionumber, 0 );
-}
-
-=item GetBiblioItemByBiblioNumber
-
-NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
-
-=cut
-
-sub GetBiblioItemByBiblioNumber {
-    my ($biblionumber) = @_;
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
-    my $count = 0;
-    my @results;
-
-    $sth->execute($biblionumber);
-
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push @results, $data;
+        # delete the biblioitem
+        my $del_sth =
+          $dbh->prepare("DELETE FROM biblioitems WHERE biblioitemnumber=?");
+        $del_sth->execute($biblioitemnumber);
+        $del_sth->finish;
     }
-
     $sth->finish;
-    return @results;
+    return undef;
 }
 
-=head2 getbibliofromitemnumber
+=head2 _koha_delete_items
 
-  $item = &getbibliofromitemnumber($env, $dbh, $itemnumber);
-
-Looks up the item with the given itemnumber.
+$error = _koha_delete_items($dbh,$itemnumber);
 
-C<$env> and C<$dbh> are ignored.
+Internal sub for deleting from items table -- also saves to deleteditems
 
-C<&itemnodata> returns a reference-to-hash whose keys are the fields
-from the C<biblio>, C<biblioitems>, and C<items> tables in the Koha
-database.
+C<$dbh> - the database handle
+C<$itemnumber> - the itemnumber of the item to be deleted
 
 =cut
-#'
-sub getbibliofromitemnumber {
-  my ($env,$dbh,$itemnumber) = @_;
-  $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("Select * from biblio,items,biblioitems
-    where items.itemnumber = ?
-    and biblio.biblionumber = items.biblionumber
-    and biblioitems.biblioitemnumber = items.biblioitemnumber");
-#  print $query;
-  $sth->execute($itemnumber);
-  my $data=$sth->fetchrow_hashref;
-  $sth->finish;
-  return($data);
-}
 
-sub getbiblio {
-    my ($biblionumber) = @_;
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
+# FIXME: add error handling
 
-    # || die "Cannot prepare $query\n" . $dbh->errstr;
-    my $count = 0;
-    my @results;
+sub _koha_delete_items {
+    my ( $dbh, $itemnumber ) = @_;
 
-    $sth->execute($biblionumber);
+    # get all the data for this item
+    my $sth = $dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
+    $sth->execute($itemnumber);
 
-    # || die "Cannot execute $query\n" . $sth->errstr;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        $results[$count] = $data;
-        $count++;
-    }    # while
+    if ( my $data = $sth->fetchrow_hashref ) {
+
+        # save the record in deleteditems
+        # find the fields to save
+        my $query = "INSERT INTO deleteditems SET ";
+        my @bind  = ();
+        foreach my $temp ( keys %$data ) {
+            $query .= "$temp = ?,";
+            push( @bind, $data->{$temp} );
+        }
 
+        # replace the last , by ",?)"
+        $query =~ s/\,$//;
+        my $bkup_sth = $dbh->prepare($query);
+        $bkup_sth->execute(@bind);
+        $bkup_sth->finish;
+
+        # delete the item
+        my $del_sth = $dbh->prepare("DELETE FROM items WHERE itemnumber=?");
+        $del_sth->execute($itemnumber);
+        $del_sth->finish;
+    }
     $sth->finish;
-    return ( $count, @results );
-}    # sub getbiblio
+    return undef;
+}
 
-sub getbiblioitem {
-    my ($biblioitemnum) = @_;
-    my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare( "Select * from biblioitems where
-biblioitemnumber = ?"
-    );
-    my $count = 0;
-    my @results;
+=head1  OLD FUNCTIONS
 
-    $sth->execute($biblioitemnum);
+=head2 newbiblio
 
-    while ( my $data = $sth->fetchrow_hashref ) {
-        $results[$count] = $data;
-        $count++;
-    }    # while
+$biblionumber = newbiblio($biblio);
 
-    $sth->finish;
-    return ( $count, @results );
-}    # sub getbiblioitem
+=cut
 
-sub getbiblioitembybiblionumber {
-    my ($biblionumber) = @_;
+sub newbiblio {
+    my ($biblio) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?");
-    my $count = 0;
-    my @results;
+    my $bibnum = _koha_add_biblio( $dbh, $biblio );
+    my $record = &MARCkoha2marcBiblio( $bibnum );
+    MARCaddbiblio( $record, $bibnum, '' );
+    return ($bibnum);
+}
 
-    $sth->execute($biblionumber);
+=head2 modbiblio
 
-    while ( my $data = $sth->fetchrow_hashref ) {
-        $results[$count] = $data;
-        $count++;
-    }    # while
+  $biblionumber = &modbiblio($biblio);
 
-    $sth->finish;
-    return ( $count, @results );
-}    # sub
+Update a biblio record.
 
-sub getstacks{
-  my $dbh   = C4::Context->dbh;
-  my $i=0;
-my @results;
-my $stackstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield="items.stack"');
-        $stackstatus->execute;
+C<$biblio> is a reference-to-hash whose keys are the fields in the
+biblio table in the Koha database. All fields must be present, not
+just the ones you wish to change.
     
-        my ($authorised_valuecode) = $stackstatus->fetchrow;
-        if ($authorised_valuecode) {
-            $stackstatus = $dbh->prepare("select * from authorised_values where category=? ");
-            $stackstatus->execute($authorised_valuecode);
+C<&modbiblio> updates the record defined by
+C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
     
-            while (my $data = $stackstatus->fetchrow_hashref){
-            $results[$i]=$data;
-            $i++;
-        }#while
-        }#if
-$stackstatus->finish;
-        return ( $i, @results );
+C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
+successful or not.
 
-}
+=cut
 
-sub getitemsbybiblioitem {
-    my ($biblioitemnum) = @_;
+sub modbiblio {
+    my ($biblio) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare( "Select * from items, biblio where
-biblio.biblionumber = items.biblionumber and biblioitemnumber
-= ?"
-    );
+    my $biblionumber = _koha_modify_biblio( $dbh, $biblio );
+    my $record = MARCkoha2marcBiblio( $biblionumber, $biblionumber );
+    MARCmodbiblio( $dbh, $biblionumber, $record, "", 0 );
+    return ($biblionumber);
+}    # sub modbiblio
 
-    # || die "Cannot prepare $query\n" . $dbh->errstr;
-    my $count = 0;
-    my @results;
+=head2 modbibitem
 
-    $sth->execute($biblioitemnum);
+&modbibitem($biblioitem)
 
-    # || die "Cannot execute $query\n" . $sth->errstr;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        $results[$count] = $data;
-        $count++;
-    }    # while
+=cut
 
-    $sth->finish;
-    return ( $count, @results );
-}    # sub getitemsbybiblioitem
+sub modbibitem {
+    my ($biblioitem) = @_;
+    my $dbh = C4::Context->dbh;
+    &_koha_modify_biblio( $dbh, $biblioitem );
+}    # sub modbibitem
 
+=head2 newbiblioitem
 
-=head2 get_itemnumbers_of
+&newbiblioitem($biblioitem)
 
-  my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
+=cut
 
-Given a list of biblionumbers, return the list of corresponding itemnumbers
-for each biblionumber.
+sub newbiblioitem {
+    my ($biblioitem) = @_;
+    my $dbh = C4::Context->dbh;
+    my $bibitemnum = &_koha_add_biblioitem( $dbh, $biblioitem );
 
-Return a reference on a hash where keys are biblionumbers and values are
-references on array of itemnumbers.
+    my $MARCbiblio =
+      MARCkoha2marcBiblio( 0, $bibitemnum )
+      ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
 
-=cut
-sub get_itemnumbers_of {
-    my @biblionumbers = @_;
+    &MARCaddbiblio( $MARCbiblio, $biblioitem->{biblionumber}, '' );
+    return ($bibitemnum);
+}
 
-    my $dbh = C4::Context->dbh;
+=head2 newitems
 
-    my $query = '
-SELECT itemnumber,
-       biblionumber
-  FROM items
-  WHERE biblionumber IN (?'.(',?' x scalar @biblionumbers - 1).')
-';
-    my $sth = $dbh->prepare($query);
-    $sth->execute(@biblionumbers);
+$errors = &newitems( $item, @barcodes );
 
-    my %itemnumbers_of;
+=cut
 
-    while (my ($itemnumber, $biblionumber) = $sth->fetchrow_array) {
-        push @{$itemnumbers_of{$biblionumber}}, $itemnumber;
+sub newitems {
+    my ( $item, @barcodes ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $errors;
+    my $itemnumber;
+    my $error;
+    foreach my $barcode (@barcodes) {
+        ( $itemnumber, $error ) = &_koha_new_items( $dbh, $item, uc($barcode) );
+        $errors .= $error;
+        my $MARCitem =
+          &MARCkoha2marcItem( $dbh, $item->{biblionumber}, $itemnumber );
+        &MARCadditem( $MARCitem, $item->{biblionumber} );
     }
-
-    return \%itemnumbers_of;
+    return ($errors);
 }
 
+=head2 moditem
+
+$errors = &moditem( $item, $op );
 
-sub logchange {
+=cut
+
+sub moditem {
+    my ( $item, $op ) = @_;
+    my $dbh = C4::Context->dbh;
+    &_koha_modify_item( $dbh, $item, $op );
 
-    # Subroutine to log changes to databases
-# Eventually, this subroutine will be used to create a log of all changes made,
-    # with the possibility of "undo"ing some changes
-    my $database = shift;
-    if ( $database eq 'kohadb' ) {
-        my $type     = shift;
-        my $section  = shift;
-        my $item     = shift;
-        my $original = shift;
-        my $new      = shift;
-
-        #    print STDERR "KOHA: $type $section $item $original $new\n";
-    }
-    elsif ( $database eq 'marc' ) {
-        my $type        = shift;
-        my $Record_ID   = shift;
-        my $tag         = shift;
-        my $mark        = shift;
-        my $subfield_ID = shift;
-        my $original    = shift;
-        my $new         = shift;
-
-#    print STDERR "MARC: $type $Record_ID $tag $mark $subfield_ID $original $new\n";
+    # if we're just setting statuses, just update items table
+    # it's faster and zebra and marc will be synched anyway by the cron job
+    unless ( $op eq "setstatus" ) {
+        my $MARCitem = &MARCkoha2marcItem( $dbh, $item->{'biblionumber'},
+            $item->{'itemnum'} );
+        &MARCmoditem( $MARCitem, $item->{biblionumber}, $item->{itemnum},
+            0 );
     }
 }
 
-#------------------------------------------------
-
-#---------------------------------------
-# Find a biblio entry, or create a new one if it doesn't exist.
-#  If a "subtitle" entry is in hash, add it to subtitle table
-sub getoraddbiblio {
-
-    # input params
-    my (
-        $dbh,       # db handle
-                    # FIXME - Unused argument
-        $biblio,    # hash ref to fields
-    ) = @_;
+=head2 checkitems
 
-    # return
-    my $biblionumber;
+$errors = &checkitems( $count, @barcodes );
 
-    my $debug = 0;
-    my $sth;
+=cut
+
+sub checkitems {
+    my ( $count, @barcodes ) = @_;
+    my $dbh = C4::Context->dbh;
     my $error;
+    my $sth = $dbh->prepare("Select * from items where barcode=?");
+    for ( my $i = 0 ; $i < $count ; $i++ ) {
+        $barcodes[$i] = uc $barcodes[$i];
+        $sth->execute( $barcodes[$i] );
+        if ( my $data = $sth->fetchrow_hashref ) {
+            $error .= " Duplicate Barcode: $barcodes[$i]";
+        }
+    }
+    $sth->finish;
+    return ($error);
+}
 
-    #-----
-    $dbh = C4::Context->dbh;
+=head1  OTHER FUNCTIONS
 
-    print "<PRE>Looking for biblio </PRE>\n" if $debug;
-    $sth = $dbh->prepare( "select biblionumber
-        from biblio
-        where title=? and author=?
-          and copyrightdate=? and seriestitle=?"
-    );
-    $sth->execute(
-        $biblio->{title},     $biblio->{author},
-        $biblio->{copyright}, $biblio->{seriestitle}
-    );
-    if ( $sth->rows ) {
-        ($biblionumber) = $sth->fetchrow;
-        print "<PRE>Biblio exists with number $biblionumber</PRE>\n" if $debug;
-    }
-    else {
+=head2 char_decode
 
-        # Doesn't exist.  Add new one.
-        print "<PRE>Adding biblio</PRE>\n" if $debug;
-        ( $biblionumber, $error ) = &newbiblio($biblio);
-        if ($biblionumber) {
-            print "<PRE>Added with biblio number=$biblionumber</PRE>\n"
-              if $debug;
-            if ( $biblio->{subtitle} ) {
-                &newsubtitle( $biblionumber, $biblio->{subtitle} );
-            }    # if subtitle
-        }
-        else {
-            print "<PRE>Couldn't add biblio: $error</PRE>\n" if $debug;
-        }    # if added
-    }
+my $string = char_decode( $string, $encoding );
 
-    return $biblionumber, $error;
+converts ISO 5426 coded string to UTF-8
+sloppy code : should be improved in next issue
 
-}    # sub getoraddbiblio
+=cut
 
 sub char_decode {
-
-    # converts ISO 5426 coded string to UTF-8
-    # sloppy code : should be improved in next issue
     my ( $string, $encoding ) = @_;
     $_ = $string;
 
          $encoding = C4::Context->preference("marcflavour") unless $encoding;
     if ( $encoding eq "UNIMARC" ) {
-#         s/\xe1/Æ/gm;
+
+        #         s/\xe1/Æ/gm;
         s/\xe2/Äž/gm;
         s/\xe9/Ø/gm;
         s/\xec/ÅŸ/gm;
@@ -3417,7 +3127,8 @@
             s/\xe9\x75/u/gm;
             s/\xea\x41/A/gm;
             s/\xea\x61/a/gm;
-#Additional Turkish characters
+
+        #Additional Turkish characters
   s/\x1b//gm;
   s/\x1e//gm;
  s/(\xf0)s/\xc5\x9f/gm; 
@@ -3429,19 +3140,214 @@
     s/(\xe6)g/ÄŸ\xc4\x9f/gm;
     s/\xB8/ı/gm;
     s/\xB9/£/gm;
-      s/(\xe8|\xc8)o/ö/gm ;
-       s/(\xe8|\xc8)O/Ö/gm ;
-       s/(\xe8|\xc8)u/ü/gm ;
-       s/(\xe8|\xc8)U/Ü/gm ;
+        s/(\xe8|\xc8)o/ö/gm;
+        s/(\xe8|\xc8)O/Ö/gm;
+        s/(\xe8|\xc8)u/ü/gm;
+        s/(\xe8|\xc8)U/Ü/gm;
     s/\xc2\xb8/\xc4\xb1/gm;
     s/¸/\xc4\xb1/gm;
+
             # this handles non-sorting blocks (if implementation requires this)
             $string = nsb_clean($_);
+    }
+    return ($string);
+}
+
+=head2 PrepareItemrecordDisplay
+
+PrepareItemrecordDisplay($itemrecord,$bibnum,$itemumber);
+
+Returns a hash with all the fields for Display a given item data in a template
+
+=cut
+
+sub PrepareItemrecordDisplay {
+
+    my ( $itemnum, $bibnum ) = @_;
+
+    my $dbh = C4::Context->dbh;
+    my $frameworkcode = &MARCfind_frameworkcode( $dbh, $bibnum );
+    my ( $itemtagfield, $itemtagsubfield ) =
+      &MARCfind_marc_from_kohafield( $dbh, "items.itemnumber", $frameworkcode );
+    my $tagslib = &MARCgettagslib( $dbh, 1, $frameworkcode );
+    my $itemrecord = MARCgetitem( $itemnum, $bibnum ) if ($itemnum);
+    my @loop_data;
+    my $authorised_values_sth =
+      $dbh->prepare(
+"select authorised_value,lib from authorised_values where category=? order by lib"
+      );
+    foreach my $tag ( sort keys %{$tagslib} ) {
+        my $previous_tag = '';
+        if ( $tag ne '' ) {
+            # loop through each subfield
+            my $cntsubf;
+            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
+                next if ( subfield_is_koha_internal_p($subfield) );
+                next if ( $tagslib->{$tag}->{$subfield}->{'tab'} ne "10" );
+                my %subfield_data;
+                $subfield_data{tag}           = $tag;
+                $subfield_data{subfield}      = $subfield;
+                $subfield_data{countsubfield} = $cntsubf++;
+                $subfield_data{kohafield}     =
+                  $tagslib->{$tag}->{$subfield}->{'kohafield'};
+
+         #        $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
+                $subfield_data{marc_lib} =
+                    "<span id=\"error\" title=\""
+                  . $tagslib->{$tag}->{$subfield}->{lib} . "\">"
+                  . substr( $tagslib->{$tag}->{$subfield}->{lib}, 0, 12 )
+                  . "</span>";
+                $subfield_data{mandatory} =
+                  $tagslib->{$tag}->{$subfield}->{mandatory};
+                $subfield_data{repeatable} =
+                  $tagslib->{$tag}->{$subfield}->{repeatable};
+                $subfield_data{hidden} = "display:none"
+                  if $tagslib->{$tag}->{$subfield}->{hidden};
+                my ( $x, $value );
+                ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord )
+                  if ($itemrecord);
+                $value =~ s/"/&quot;/g;
+
+                # search for itemcallnumber if applicable
+                if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq
+                    'items.itemcallnumber'
+                    && C4::Context->preference('itemcallnumber') )
+                {
+                    my $CNtag =
+                      substr( C4::Context->preference('itemcallnumber'), 0, 3 );
+                    my $CNsubfield =
+                      substr( C4::Context->preference('itemcallnumber'), 3, 1 );
+                    my $temp = $itemrecord->field($CNtag) if ($itemrecord);
+                    if ($temp) {
+                        $value = $temp->subfield($CNsubfield);
+                    }
+                }
+                if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
+                    my @authorised_values;
+                    my %authorised_lib;
+
+                    # builds list, depending on authorised value...
+                    #---- branch
+                    if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq
+                        "branches" )
+                    {
+                        if ( ( C4::Context->preference("IndependantBranches") )
+                            && ( C4::Context->userenv->{flags} != 1 ) )
+                        {
+                            my $sth =
+                              $dbh->prepare(
+"select branchcode,branchname from branches where branchcode = ? order by branchname"
+                              );
+                            $sth->execute( C4::Context->userenv->{branch} );
+                            push @authorised_values, ""
+                              unless (
+                                $tagslib->{$tag}->{$subfield}->{mandatory} );
+                            while ( my ( $branchcode, $branchname ) =
+                                $sth->fetchrow_array )
+                            {
+                                push @authorised_values, $branchcode;
+                                $authorised_lib{$branchcode} = $branchname;
+                            }
+                        }
+                        else {
+                            my $sth =
+                              $dbh->prepare(
+"select branchcode,branchname from branches order by branchname"
+                              );
+                            $sth->execute;
+                            push @authorised_values, ""
+                              unless (
+                                $tagslib->{$tag}->{$subfield}->{mandatory} );
+                            while ( my ( $branchcode, $branchname ) =
+                                $sth->fetchrow_array )
+                            {
+                                push @authorised_values, $branchcode;
+                                $authorised_lib{$branchcode} = $branchname;
+                            }
+                        }
         
+                        #----- itemtypes
     }
-    return ($string);
+                    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq
+                        "itemtypes" )
+                    {
+                        my $sth =
+                          $dbh->prepare(
+"select itemtype,description from itemtypes order by description"
+                          );
+                        $sth->execute;
+                        push @authorised_values, ""
+                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+                        while ( my ( $itemtype, $description ) =
+                            $sth->fetchrow_array )
+                        {
+                            push @authorised_values, $itemtype;
+                            $authorised_lib{$itemtype} = $description;
+                        }
+
+                        #---- "true" authorised value
+                    }
+                    else {
+                        $authorised_values_sth->execute(
+                            $tagslib->{$tag}->{$subfield}->{authorised_value} );
+                        push @authorised_values, ""
+                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
+                        while ( my ( $value, $lib ) =
+                            $authorised_values_sth->fetchrow_array )
+                        {
+                            push @authorised_values, $value;
+                            $authorised_lib{$value} = $lib;
+                        }
+                    }
+                    $subfield_data{marc_value} = CGI::scrolling_list(
+                        -name     => 'field_value',
+                        -values   => \@authorised_values,
+                        -default  => "$value",
+                        -labels   => \%authorised_lib,
+                        -size     => 1,
+                        -tabindex => '',
+                        -multiple => 0,
+                    );
+                }
+                elsif ( $tagslib->{$tag}->{$subfield}->{thesaurus_category} ) {
+                    $subfield_data{marc_value} =
+"<input type=\"text\" name=\"field_value\"  size=47 maxlength=255> <a href=\"javascript:Dopop('cataloguing/thesaurus_popup.pl?category=$tagslib->{$tag}->{$subfield}->{thesaurus_category}&index=',)\">...</a>";
+
+#"
+# COMMENTED OUT because No $i is provided with this API.
+# And thus, no value_builder can be activated.
+# BUT could be thought over.
+#         } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) {
+#             my $plugin="value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'};
+#             require $plugin;
+#             my $extended_param = plugin_parameters($dbh,$itemrecord,$tagslib,$i,0);
+#             my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0);
+#             $subfield_data{marc_value}="<input type=\"text\" value=\"$value\" name=\"field_value\"  size=47 maxlength=255 DISABLE READONLY OnFocus=\"javascript:Focus$function_name()\" OnBlur=\"javascript:Blur$function_name()\"> <a href=\"javascript:Clic$function_name()\">...</a> $javascript";
+                }
+                else {
+                    $subfield_data{marc_value} =
+"<input type=\"text\" name=\"field_value\" value=\"$value\" size=50 maxlength=255>";
+                }
+                push( @loop_data, \%subfield_data );
+            }
+        }
+    }
+    my $itemnumber = $itemrecord->subfield( $itemtagfield, $itemtagsubfield )
+      if ( $itemrecord && $itemrecord->field($itemtagfield) );
+    return {
+        'itemtagfield'    => $itemtagfield,
+        'itemtagsubfield' => $itemtagsubfield,
+        'itemnumber'      => $itemnumber,
+        'iteminformation' => \@loop_data
+    };
 }
 
+=head2 nsb_clean
+
+my $string = nsb_clean( $string, $encoding );
+
+=cut
+
 sub nsb_clean {
     my $NSB = '\x88';    # NSB : begin Non Sorting Block
     my $NSE = '\x89';    # NSE : Non Sorting Block end
@@ -3454,140 +3360,122 @@
     return ($string);
 }
 
+=head2 zebraopfiles
+
+&zebraopfiles( $dbh, $biblionumber, $record, $folder, $server );
 
+=cut
+
+sub zebraopfiles {
 
-sub DisplayISBN {
-    my ($isbn)=@_;
-    my $seg1;
-    if(substr($isbn, 0, 1) <=7) {
-        $seg1 = substr($isbn, 0, 1);
-    } elsif(substr($isbn, 0, 2) <= 94) {
-        $seg1 = substr($isbn, 0, 2);
-    } elsif(substr($isbn, 0, 3) <= 995) {
-        $seg1 = substr($isbn, 0, 3);
-    } elsif(substr($isbn, 0, 4) <= 9989) {
-        $seg1 = substr($isbn, 0, 4);
-    } else {
-        $seg1 = substr($isbn, 0, 5);
-    }
-    my $x = substr($isbn, length($seg1));
-    my $seg2;
-    if(substr($x, 0, 2) <= 19) {
-#         if(sTmp2 < 10) sTmp2 = "0" sTmp2;
-        $seg2 = substr($x, 0, 2);
-    } elsif(substr($x, 0, 3) <= 699) {
-        $seg2 = substr($x, 0, 3);
-    } elsif(substr($x, 0, 4) <= 8399) {
-        $seg2 = substr($x, 0, 4);
-    } elsif(substr($x, 0, 5) <= 89999) {
-        $seg2 = substr($x, 0, 5);
-    } elsif(substr($x, 0, 6) <= 9499999) {
-        $seg2 = substr($x, 0, 6);
-    } else {
-        $seg2 = substr($x, 0, 7);
-    }
-    my $seg3=substr($x,length($seg2));
-    $seg3=substr($seg3,0,length($seg3)-1) ;
-    my $seg4 = substr($x, -1, 1);
-    return "$seg1-$seg2-$seg3-$seg4";
-}
-sub zebraopfiles{
-
-my ($dbh,$biblionumber,$record,$folder,$server)=@_;
-#my $record = XMLgetbiblio($dbh,$biblionumber);
-my $op;
-my $zebradir = C4::Context->zebraconfig($server)->{directory}."/".$folder."/";
-    unless (opendir(DIR, "$zebradir")) {
+    my ( $dbh, $biblionumber, $record, $folder, $server ) = @_;
+
+    my $op;
+    my $zebradir =
+      C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/";
+    unless ( opendir( DIR, "$zebradir" ) ) {
             warn "$zebradir not found";
             return;
     }
     closedir DIR;
-    my $filename = $zebradir.$biblionumber;
+    my $filename = $zebradir . $biblionumber;
 
-if ($record){
-    open (OUTPUT,">", $filename.".xml");
+    if ($record) {
+        open( OUTPUT, ">", $filename . ".xml" );
     print OUTPUT $record;
     close OUTPUT;
+    }
 }
-}
-=item zebraop
-
-=over 4
 
+=head2 zebraop
 
-
-=back
+zebraop( $dbh, $biblionumber, $op, $server );
 
 =cut
 
-sub zebraop{
+sub zebraop {
 ###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
-    my ($dbh,$biblionumber,$op,$server) = @_;
+    my ( $dbh, $biblionumber, $op, $server ) = @_;
+
     #warn "SERVER:".$server;
     my @Zconnbiblio;
-    my $tried=0;
-    my $recon=0;
-    my $reconnect=0;
+    my $tried     = 0;
+    my $recon     = 0;
+    my $reconnect = 0;
     my $record;
     my $shadow;
 
-reconnect:
-    $Zconnbiblio[0]=C4::Context->Zconn($server,0,1);
+  reconnect:
+    $Zconnbiblio[0] = C4::Context->Zconn( $server, 0, 1 );
+
+    if ( $server eq "biblioserver" ) {
 
-    if ($server eq "biblioserver"){
         # it's unclear to me whether this should be in xml or MARC format
         # but it is clear it should be nabbed from zebra rather than from
         # the koha tables
-        $record=MARCgetbiblio($dbh,$biblionumber);
+        $record = GetMarcBiblio($biblionumber);
         $record = $record->as_xml_record() if $record;
 #            warn "RECORD $biblionumber => ".$record;
         $shadow="biblioservershadow";
 
-    }elsif($server eq "authorityserver"){
-        $record =C4::AuthoritiesMarc::XMLgetauthority($dbh,$biblionumber);
-        $shadow="authorityservershadow";
+        #           warn "RECORD $biblionumber => ".$record;
+        $shadow = "biblioservershadow";
+
+    }
+    elsif ( $server eq "authorityserver" ) {
+        $record = C4::AuthoritiesMarc::XMLgetauthority( $dbh, $biblionumber );
+        $shadow = "authorityservershadow";
     } ## Add other servers as necessary
 
     my $Zpackage = $Zconnbiblio[0]->package();
-    $Zpackage->option(action => $op);
-    $Zpackage->option(record => $record);
+    $Zpackage->option( action => $op );
+    $Zpackage->option( record => $record );
 
-retry:
+  retry:
     $Zpackage->send("update");
     my $i;
     my $event;
 
-    while (($i = ZOOM::event(\@Zconnbiblio)) != 0) {
+    while ( ( $i = ZOOM::event( \@Zconnbiblio ) ) != 0 ) {
         $event = $Zconnbiblio[0]->last_event();
         last if $event == ZOOM::Event::ZEND;
     }
 
-    my($error, $errmsg, $addinfo, $diagset) = $Zconnbiblio[0]->error_x();
-    if ($error==10000 && $reconnect==0) { ## This is serious ZEBRA server is not available -reconnect
+    my ( $error, $errmsg, $addinfo, $diagset ) = $Zconnbiblio[0]->error_x();
+    if ( $error == 10000 && $reconnect == 0 )
+    {    ## This is serious ZEBRA server is not available -reconnect
         warn "problem with zebra server connection";
-        $reconnect=1;
-        my $res=system('sc start "Z39.50 Server" >c:/zebraserver/error.log');
+        $reconnect = 1;
+        my $res = system('sc start "Z39.50 Server" >c:/zebraserver/error.log');
+
         #warn "Trying to restart ZEBRA Server";
         #goto "reconnect";
-        }elsif ($error==10007 && $tried<2) {## timeout --another 30 looonng seconds for this update
-        $tried=$tried+1;
+    }
+    elsif ( $error == 10007 && $tried < 2 )
+    {    ## timeout --another 30 looonng seconds for this update
+        $tried = $tried + 1;
         warn "warn: timeout, trying again";
         goto "retry";
-    }elsif($error==10004 && $recon==0){##Lost connection -reconnect
-        $recon=1;
+    }
+    elsif ( $error == 10004 && $recon == 0 ) {    ##Lost connection -reconnect
+        $recon = 1;
         warn "error: reconnecting to zebra";
         goto "reconnect";
+
     # as a last resort, we save the data to the filesystem to be indexed in batch
-    }elsif ($error){
-        warn "Error-$server   $op $biblionumber /errcode:, $error, /MSG:,$errmsg,$addinfo \n";
+    }
+    elsif ($error) {
+        warn
+"Error-$server   $op $biblionumber /errcode:, $error, /MSG:,$errmsg,$addinfo \n";
         $Zpackage->destroy();
         $Zconnbiblio[0]->destroy();
-        zebraopfiles($dbh,$biblionumber,$record,$op,$server);
+        zebraopfiles( $dbh, $biblionumber, $record, $op, $server );
         return;
     }
-      if (C4::Context->$shadow){
+    if ( C4::Context->$shadow ) {
         $Zpackage->send('commit');
-        while (($i = ZOOM::event(\@Zconnbiblio)) != 0) {
+        while ( ( $i = ZOOM::event( \@Zconnbiblio ) ) != 0 ) {
+
             #waiting zebra to finish;
          }
     }
@@ -3595,380 +3483,90 @@
     $Zconnbiblio[0]->destroy();
 }
 
+=head2 calculatelc
 
-sub calculatelc{
-my  ($classification)=@_;
-$classification=~s/^\s+|\s+$//g;
-my $i=0;
-my $lc2;
-my $lc1;
-
-
-for  ($i=0; $i<length($classification);$i++){
-my $c=(substr($classification,$i,1));
-    if ($c ge '0' && $c le '9'){
-    
-    $lc2=substr($classification,$i);
-    last;
-    }else{
-    $lc1.=substr($classification,$i,1);
-    
-    }
-}#while
-
-my $other=length($lc1);
-if (!$lc1) {
-    $other=0;
-}
-
-my $extras;
-if ($other<4){
-    for (1..(4-$other)){
-    $extras.="0";
-    }
-}
- $lc1.=$extras;
-$lc2=~ s/^ //g;
-
-$lc2=~ s/ //g;
-$extras="";
-##Find the decimal part of $lc2
-my $pos=index($lc2,".");
-if ($pos<0){$pos=length($lc2);}
-if ($pos>=0 && $pos<5){
-##Pad lc2 with zeros to create a 5digit decimal needed in marc record to sort as numeric
-
-    for (1..(5-$pos)){
-    $extras.="0";
-    }
-}
-$lc2=$extras.$lc2;
-return($lc1.$lc2);
-}
-
-sub itemcalculator{
-my ($dbh,$biblioitem,$callnumber)=@_;
-my $sth=$dbh->prepare("select classification, subclass from biblioitems where biblioitemnumber=?");
-
-$sth->execute($biblioitem);
-my ($classification,$subclass)=$sth->fetchrow;
-my $all=$classification." ".$subclass;
-my $total=length($all);
-my $cutterextra=substr($callnumber,$total-1);
-
-return $cutterextra;
-
-}
-
-=item getRecord
-
-get a single record in piggyback mode from Zebra and return it in the requested record syntax
-
-default record syntax is XML
+$lc = calculatelc($classification);
 
 =cut
 
-sub getRecord {
-    my ($server,$koha_query,$recordSyntax) = @_;
-    $recordSyntax = "xml" unless $recordSyntax;
-    my $Zconn = C4::Context->Zconn($server,0,1,1,$recordSyntax);
-    my $rs = $Zconn->search(new ZOOM::Query::CCL2RPN($koha_query,$Zconn));
-    if ($rs->record(0)) {
-        return $rs->record(0)->raw();
-    }
-}
-
-sub getMARCnotes {
-    my ( $dbh, $biblionumber, $marcflavour ) = @_;
-    my $scope;
-    if ( $marcflavour eq "MARC21" ) {
-        $scope = '5..';
-    }
-    else {    # assume unimarc if not marc21
-        $scope = '3..';
-    }
+sub calculatelc {
+    my ($classification) = @_;
+    $classification =~ s/^\s+|\s+$//g;
+    my $i = 0;
+    my $lc2;
+    my $lc1;
 
-    my $record = MARCgetbiblio( $dbh, $biblionumber );
-    my @marcnotes;
-    my $note = "";
-    my $tag  = "";
-    my $marcnote;
+    for ( $i = 0 ; $i < length($classification) ; $i++ ) {
+        my $c = ( substr( $classification, $i, 1 ) );
+        if ( $c ge '0' && $c le '9' ) {
 
-    foreach my $field ( $record->field($scope) ) {
-        my $value = $field->as_string();
-        if ( $note ne "" ) {
-            $marcnote = { marcnote => $note, };
-            push @marcnotes, $marcnote;
-            $note = $value;
-        }
-        if ( $note ne $value ) {
-            $note = $note . " " . $value;
-        }
+            $lc2 = substr( $classification, $i );
+            last;
     }
+        else {
+            $lc1 .= substr( $classification, $i, 1 );
 
-    if ($note) {
-        $marcnote = { marcnote => $note };
-        push @marcnotes, $marcnote;    #load last tag into array
     }
+    }    #while
 
-    my $marcnotesarray = \@marcnotes;
-    return $marcnotesarray;
-}    # end getMARCnotes
+    my $other = length($lc1);
+    if ( !$lc1 ) {
+        $other = 0;
+    }
 
-sub getMARCsubjects {
-    my ( $dbh, $biblionumber, $marcflavour ) = @_;
-    my ( $mintag, $maxtag );
-    if ( $marcflavour eq "MARC21" ) {
-        $mintag = "600";
-        $maxtag = "699";
+    my $extras;
+    if ( $other < 4 ) {
+        for ( 1 .. ( 4 - $other ) ) {
+            $extras .= "0";
     }
-    else {    # assume unimarc if not marc21
-        $mintag = "600";
-        $maxtag = "619";
     }
-    my $record = MARCgetbiblio( $dbh, $biblionumber );
-    my @marcsubjcts;
-    my $subjct   = "";
-    my $subfield = "";
-    my $marcsubjct;
-
-    foreach my $field ( $record->fields ) {
-        next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
-        my @subfields_loop;
+    $lc1 .= $extras;
+    $lc2 =~ s/^ //g;
 
-        #my $value = $field->subfield('a');
-        #$marcsubjct = {MARCSUBJCT => $value,};
-        my @subfields = $field->subfields();
+    $lc2 =~ s/ //g;
+    $extras = "";
+    ##Find the decimal part of $lc2
+    my $pos = index( $lc2, "." );
+    if ( $pos < 0 ) { $pos = length($lc2); }
+    if ( $pos >= 0 && $pos < 5 ) {
+        ##Pad lc2 with zeros to create a 5digit decimal needed in marc record to sort as numeric
 
-        #warn "subfields:".join " ", @$subfields;
-        my $counter = 0;
-        my @link_loop;
-        for my $subject_subfield (@subfields) {
-            my $code      = $subject_subfield->[0];
-            my $value     = $subject_subfield->[1];
-            my $linkvalue = $value;
-            $linkvalue =~ s/(\(|\))//g;
-            my $operator = " and " unless $counter == 0;
-            push @link_loop, { link => $linkvalue, operator => $operator };
-            my $separator = C4::Context->preference("authoritysep")
-              unless $counter == 0;
-            push @subfields_loop,
-              {
-                code      => $code,
-                value     => $value,
-                link_loop => \@link_loop,
-                separator => $separator
-              };
-            $counter++;
+        for ( 1 .. ( 5 - $pos ) ) {
+            $extras .= "0";
         }
-        push @marcsubjcts, { MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop };
-
-        #$marcsubjct = {MARCSUBJCT => $field->as_string(),};
-        #push @marcsubjcts, $marcsubjct;
-        #$subjct = $value;
-
     }
-    my $marcsubjctsarray = \@marcsubjcts;
-    return $marcsubjctsarray;
-}    #end getMARCsubjects
-
-sub GetItemInfosOf {
-    my @itemnumbers = @_;
-
-    my $query = '
-SELECT *
-  FROM items
-  WHERE itemnumber IN ('.join(',', @itemnumbers).')
-';
-    return get_infos_of($query, 'itemnumber');
-}
-
-sub GetBiblioItemInfosOf {
-    my @biblioitemnumbers = @_;
-
-    my $query = '
-SELECT biblioitemnumber,
-       publicationyear,
-       itemtype
-  FROM biblioitems
-  WHERE biblioitemnumber IN ('.join(',', @biblioitemnumbers).')
-';
-
-    return get_infos_of($query, 'biblioitemnumber');
+    $lc2 = $extras . $lc2;
+    return ( $lc1 . $lc2 );
 }
 
+=head2 itemcalculator
 
-=head2 itemissues
-
-  @issues = &itemissues($biblioitemnumber, $biblio);
-
-Looks up information about who has borrowed the bookZ<>(s) with the
-given biblioitemnumber.
-
-C<$biblio> is ignored.
-
-C<&itemissues> returns an array of references-to-hash. The keys
-include the fields from the C<items> table in the Koha database.
-Additional keys include:
-
-=over 4
-
-=item C<date_due>
-
-If the item is currently on loan, this gives the due date.
-
-If the item is not on loan, then this is either "Available" or
-"Cancelled", if the item has been withdrawn.
-
-=item C<card>
-
-If the item is currently on loan, this gives the card number of the
-patron who currently has the item.
-
-=item C<timestamp0>, C<timestamp1>, C<timestamp2>
-
-These give the timestamp for the last three times the item was
-borrowed.
-
-=item C<card0>, C<card1>, C<card2>
-
-The card number of the last three patrons who borrowed this item.
-
-=item C<borrower0>, C<borrower1>, C<borrower2>
-
-The borrower number of the last three patrons who borrowed this item.
-
-=back
+$cutterextra = itemcalculator( $dbh, $biblioitem, $callnumber );
 
 =cut
 
-#'
-sub itemissues {
-    my ( $bibitem, $biblio ) = @_;
-    my $dbh = C4::Context->dbh;
-
-    # FIXME - If this function die()s, the script will abort, and the
-    # user won't get anything; depending on how far the script has
-    # gotten, the user might get a blank page. It would be much better
-    # to at least print an error message. The easiest way to do this
-    # is to set $SIG{__DIE__}.
+sub itemcalculator {
+    my ( $dbh, $biblioitem, $callnumber ) = @_;
     my $sth =
-      $dbh->prepare("Select * from items where items.biblioitemnumber = ?")
-      || die $dbh->errstr;
-    my $i = 0;
-    my @results;
-
-    $sth->execute($bibitem) || die $sth->errstr;
-
-    while ( my $data = $sth->fetchrow_hashref ) {
-
-        # Find out who currently has this item.
-        # FIXME - Wouldn't it be better to do this as a left join of
-        # some sort? Currently, this code assumes that if
-        # fetchrow_hashref() fails, then the book is on the shelf.
-        # fetchrow_hashref() can fail for any number of reasons (e.g.,
-        # database server crash), not just because no items match the
-        # search criteria.
-        my $sth2 = $dbh->prepare(
-            "select * from issues,borrowers
-where itemnumber = ?
-and returndate is NULL
-and issues.borrowernumber = borrowers.borrowernumber"
+      $dbh->prepare(
+"select classification, subclass from biblioitems where biblioitemnumber=?"
         );
 
-        $sth2->execute( $data->{'itemnumber'} );
-        if ( my $data2 = $sth2->fetchrow_hashref ) {
-            $data->{'date_due'} = $data2->{'date_due'};
-            $data->{'card'}     = $data2->{'cardnumber'};
-            $data->{'borrower'} = $data2->{'borrowernumber'};
-        }
-        else {
-            if ( $data->{'wthdrawn'} eq '1' ) {
-                $data->{'date_due'} = 'Cancelled';
-            }
-            else {
-                $data->{'date_due'} = 'Available';
-            }    # else
-        }    # else
-
-        $sth2->finish;
-
-        # Find the last 3 people who borrowed this item.
-        $sth2 = $dbh->prepare(
-            "select * from issues, borrowers
-                        where itemnumber = ?
-                                    and issues.borrowernumber = borrowers.borrowernumber
-                                    and returndate is not NULL
-                                    order by returndate desc,timestamp desc"
-        );
-
-#        $sth2 = $dbh->prepare("
-#            SELECT *
-#            FROM issues
-#                LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber
-#            WHERE   itemnumber = ?
-#                AND returndate is not NULL
-#            ORDER BY returndate DESC,timestamp DESC
-#        ");
-
-        $sth2->execute( $data->{'itemnumber'} );
-        for ( my $i2 = 0 ; $i2 < 2 ; $i2++ )
-        {    # FIXME : error if there is less than 3 pple borrowing this item
-            if ( my $data2 = $sth2->fetchrow_hashref ) {
-                $data->{"timestamp$i2"} = $data2->{'timestamp'};
-                $data->{"card$i2"}      = $data2->{'cardnumber'};
-                $data->{"borrower$i2"}  = $data2->{'borrowernumber'};
-            }    # if
-        }    # for
-
-        $sth2->finish;
-        $results[$i] = $data;
-        $i++;
-    }
-
-    $sth->finish;
-    return (@results);
-}
-
-=head2 addauthor
-
-  ($count, $authors) = &addauthors($biblionumber);
-
-Looks up the additional authors for the book with the given
-biblionumber.
+    $sth->execute($biblioitem);
+    my ( $classification, $subclass ) = $sth->fetchrow;
+    my $all         = $classification . " " . $subclass;
+    my $total       = length($all);
+    my $cutterextra = substr( $callnumber, $total - 1 );
 
-Returns a two-element list. C<$authors> is a reference-to-array, where
-each element is an additional author, and C<$count> is the number of
-elements in C<$authors>.
-
-=cut
-
-#'
-sub addauthor {
-    my ($bibnum) = @_;
-    my $dbh      = C4::Context->dbh;
-    my $sth      =
-      $dbh->prepare("Select * from additionalauthors where biblionumber=?");
-    $sth->execute($bibnum);
-    my @results;
-    my $i = 0;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        $results[$i] = $data;
-        $i++;
-    }
-    $sth->finish;
-    return ( $i, \@results );
+    return $cutterextra;
 }
 
-
 END { }    # module clean-up code here (global destructor)
 
 1;
 
 __END__
 
-=back
-
 =head1 AUTHOR
 
 Koha Developement team <info at koha.org>
@@ -3979,8 +3577,13 @@
 
 =cut
 
-# $Id: Biblio.pm,v 1.178.2.32 2006/12/04 17:39:57 alaurin Exp $
+# $Id: Biblio.pm,v 1.178.2.33 2006/12/05 11:35:29 toins Exp $
 # $Log: Biblio.pm,v $
+# Revision 1.178.2.33  2006/12/05 11:35:29  toins
+# Biblio.pm cleaned.
+# additionalauthors, bibliosubject, bibliosubtitle tables are now unused.
+# Some functions renamed according to the coding guidelines.
+#
 # Revision 1.178.2.32  2006/12/04 17:39:57  alaurin
 # bugfix :
 #
@@ -4094,55 +3697,4 @@
 # Revision 1.178.2.7  2006/09/20 13:44:14  hdl
 # Bug Fixing : Cataloguing was broken for UNIMARC.
 # Please test.
-#
-# Revision 1.178.2.6  2006/09/18 15:10:23  toins
-# add a missing function : find_biblioitemnumber.
-#
-# Revision 1.178.2.5  2006/09/18 12:10:10  alaurin
-# bugfixing :
-# add use::date for the fonction format_date ;
-#
-# Revision 1.178.2.4  2006/08/31 13:28:52  alaurin
-# changing the name of variables, according to the recommendation of developement .
-#
-# Revision 1.178.2.3  2006/08/31 09:59:23  alaurin
-# bugfixing for the branchreserves.pl program
-#
-# restore the fonctions :
-#
-# - get_item_infos_of
-# - get_infos_of
-# - GetBiblioItemInfosOf
-#
-# and remove the %env variable . in branchreserves.pl
-#
-# Revision 1.178.2.2  2006/08/29 09:39:39  toins
-# ItemInfo renamed to GetItemsInfo and moved from Search.pm to Biblio.pm
-#
-# Revision 1.178.2.1  2006/08/25 12:32:40  btoumi
-# bug fix:add declaration of function (getbibliofromitemnumber)
-#
-# Revision 1.178  2006/08/21 09:51:15  toins
-# Add a forgetted function : getbibliofromitemnumber
-#
-# Revision 1.177  2006/08/11 16:04:07  toins
-# re-input an old function.
-#
-# Revision 1.176  2006/08/10 12:44:12  toins
-# sync with dev_week.
-#
-# Revision 1.115.2.51.2.14  2006/07/15 19:22:46  kados
-# comment out warns
-#
-# Revision 1.115.2.51.2.13  2006/07/03 16:05:26  kados
-# fix shadow call to ZOOM
-#
-# Revision 1.115.2.51.2.12  2006/06/02 23:11:23  kados
-# Committing my working dev_week. It's been tested only with
-# searching, and there's quite a lot of config stuff to set up
-# beforehand. As things get closer to a release, we'll be making
-# some scripts to do it for us
-#
-# Revision 1.115.2.51.2.11  2006/05/28 18:49:12  tgarip1957
-# This is an unusual commit. The main purpose is a working model of Zebra on a modified rel2_2.
-# Any questions regarding these commits should be asked to Joshua Ferraro unless you are Joshua whom I'll report to
+

Index: C4/Koha.pm
===================================================================
RCS file: /sources/koha/koha/C4/Koha.pm,v
retrieving revision 1.40.2.25
retrieving revision 1.40.2.26
diff -u -b -r1.40.2.25 -r1.40.2.26
--- C4/Koha.pm	29 Nov 2006 11:51:23 -0000	1.40.2.25
+++ C4/Koha.pm	5 Dec 2006 11:35:29 -0000	1.40.2.26
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Koha.pm,v 1.40.2.25 2006/11/29 11:51:23 toins Exp $
+# $Id: Koha.pm,v 1.40.2.26 2006/12/05 11:35:29 toins Exp $
 
 use strict;
 require Exporter;
@@ -25,7 +25,7 @@
 use C4::Output;
 use vars qw($VERSION @ISA @EXPORT);
 
-$VERSION = do { my @v = '$Revision: 1.40.2.25 $' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.40.2.26 $' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
 
 =head1 NAME
 
@@ -47,7 +47,9 @@
 =cut
 
 @ISA    = qw(Exporter);
- at EXPORT = qw(&slashifyDate
+ at EXPORT = qw(
+  &slashifyDate
+  &DisplayISBN
   &borrowercategories
   &subfield_is_koha_internal_p
   &GetBranches &GetBranch &getbranchdetail
@@ -79,7 +81,8 @@
   &getitemtypeimagesrc
   &getbranchname
   &GetAuthorisedValues
-  $DEBUG);
+  $DEBUG
+  );
 
 use vars qw();
 
@@ -102,6 +105,60 @@
     return ("$dateOut[2]/$dateOut[1]/$dateOut[0]");
 }
 
+
+=head2 DisplayISBN
+
+my $string = DisplayISBN( $isbn );
+
+=cut
+
+sub DisplayISBN {
+    my ($isbn) = @_;
+    my $seg1;
+    if ( substr( $isbn, 0, 1 ) <= 7 ) {
+        $seg1 = substr( $isbn, 0, 1 );
+    }
+    elsif ( substr( $isbn, 0, 2 ) <= 94 ) {
+        $seg1 = substr( $isbn, 0, 2 );
+    }
+    elsif ( substr( $isbn, 0, 3 ) <= 995 ) {
+        $seg1 = substr( $isbn, 0, 3 );
+    }
+    elsif ( substr( $isbn, 0, 4 ) <= 9989 ) {
+        $seg1 = substr( $isbn, 0, 4 );
+    }
+    else {
+        $seg1 = substr( $isbn, 0, 5 );
+    }
+    my $x = substr( $isbn, length($seg1) );
+    my $seg2;
+    if ( substr( $x, 0, 2 ) <= 19 ) {
+
+        #         if(sTmp2 < 10) sTmp2 = "0" sTmp2;
+        $seg2 = substr( $x, 0, 2 );
+    }
+    elsif ( substr( $x, 0, 3 ) <= 699 ) {
+        $seg2 = substr( $x, 0, 3 );
+    }
+    elsif ( substr( $x, 0, 4 ) <= 8399 ) {
+        $seg2 = substr( $x, 0, 4 );
+    }
+    elsif ( substr( $x, 0, 5 ) <= 89999 ) {
+        $seg2 = substr( $x, 0, 5 );
+    }
+    elsif ( substr( $x, 0, 6 ) <= 9499999 ) {
+        $seg2 = substr( $x, 0, 6 );
+    }
+    else {
+        $seg2 = substr( $x, 0, 7 );
+    }
+    my $seg3 = substr( $x, length($seg2) );
+    $seg3 = substr( $seg3, 0, length($seg3) - 1 );
+    my $seg4 = substr( $x, -1, 1 );
+    return "$seg1-$seg2-$seg3-$seg4";
+}
+
+
 # FIXME.. this should be moved to a MARC-specific module
 sub subfield_is_koha_internal_p ($) {
     my ($subfield) = @_;

Index: C4/Log.pm
===================================================================
RCS file: /sources/koha/koha/C4/Log.pm,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -b -r1.5 -r1.5.2.1
--- C4/Log.pm	14 Apr 2006 09:33:56 -0000	1.5
+++ C4/Log.pm	5 Dec 2006 11:35:30 -0000	1.5.2.1
@@ -104,7 +104,7 @@
 		$strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
 	
 		$strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
-		$strsth .=" AND action_logs.module = 'acqui.simple' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
+        $strsth .=" AND action_logs.module = 'cataloguing' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
 		if (@filters){
 			foreach my $filter (@filters){
 				if ($filter->{name} =~ /user/){
@@ -126,7 +126,7 @@
 		$strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
 	
 		$strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
-		$strsth .= "AND action_logs.module = 'acqui.simple' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
+        $strsth .= "AND action_logs.module = 'cataloguing' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
 		if (@filters){
 			foreach my $filter (@filters){
 				if ($filter->{name} =~ /user/){

Index: C4/Maintainance.pm
===================================================================
RCS file: /sources/koha/koha/C4/Attic/Maintainance.pm,v
retrieving revision 1.18.2.1
retrieving revision 1.18.2.2
diff -u -b -r1.18.2.1 -r1.18.2.2
--- C4/Maintainance.pm	17 Nov 2006 13:18:58 -0000	1.18.2.1
+++ C4/Maintainance.pm	5 Dec 2006 11:35:30 -0000	1.18.2.2
@@ -51,7 +51,7 @@
 =cut
 
 @ISA = qw(Exporter);
- at EXPORT = qw(&listsubjects &updatesub &shiftgroup &deletedbib &undeletebib
+ at EXPORT = qw(&listsubjects &shiftgroup &deletedbib &undeletebib
 &updatetype &logaction);
 
 =item listsubjects
@@ -100,23 +100,6 @@
   return($i,\@results);
 }
 
-=item updatesub
-
-  &updatesub($newsubject, $oldsubject);
-
-Renames a subject from C<$oldsubject> to C<$newsubject> in the
-bibliosubject table of the Koha database.
-
-=cut
-#'
-sub updatesub{
-  my ($sub,$oldsub)=@_;
-  my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("update bibliosubject set subject=? where subject=?");
-  $sth->execute($sub,$oldsub);
-  $sth->finish;
-}
-
 =item shiftgroup
 
   &shiftgroup($biblionumber, $biblioitemnumber);

Index: C4/Reserves2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.46.2.7
retrieving revision 1.46.2.8
diff -u -b -r1.46.2.7 -r1.46.2.8
--- C4/Reserves2.pm	20 Nov 2006 10:26:10 -0000	1.46.2.7
+++ C4/Reserves2.pm	5 Dec 2006 11:35:30 -0000	1.46.2.8
@@ -20,7 +20,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Reserves2.pm,v 1.46.2.7 2006/11/20 10:26:10 toins Exp $
+# $Id: Reserves2.pm,v 1.46.2.8 2006/12/05 11:35:30 toins Exp $
 
 use strict;
 require Exporter;
@@ -31,7 +31,7 @@
 my $library_name = C4::Context->preference("LibraryName");
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.46.2.7 $' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.46.2.8 $' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
 
 =head1 NAME
 
@@ -383,13 +383,13 @@
             my $bdata;
             if ( $count > 1 ) {
                 warn "bibitemno $bibitemno[$i]";
-                $bdata = bibitemdata( $bibitemno[$i] );
+                $bdata = GetBiblioItemData( $bibitemno[$i] );
                 $i++;
             }
             else {
 
                 # Look up the book we just found.
-                $bdata = bibitemdata( $bibitemno[0] );
+                $bdata = GetBiblioItemData( $bibitemno[0] );
             }
             $csth->finish;
 

Index: C4/Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.120.2.33
retrieving revision 1.120.2.34
diff -u -b -r1.120.2.33 -r1.120.2.34
--- C4/Search.pm	30 Nov 2006 17:22:18 -0000	1.120.2.33
+++ C4/Search.pm	5 Dec 2006 11:35:30 -0000	1.120.2.34
@@ -25,7 +25,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.120.2.33 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.120.2.34 $' =~ /\d+/g;
     shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
 };
 
@@ -87,7 +87,6 @@
 
 =cut
 
-# FIXME :: why 2 $biblionumber ?
 sub FindDuplicate {
     my ($record) = @_;
     my $dbh = C4::Context->dbh;
@@ -111,11 +110,13 @@
         $query = "ti,ext=$result->{title}";
     }
     my ($possible_duplicate_record) =
-      C4::Biblio::getRecord( "biblioserver", $query, "usmarc" );
+      C4::Biblio::getRecord( "biblioserver", $query, "usmarc" ); # FIXME :: hardcoded !
     if ($possible_duplicate_record) {
         my $marcrecord =
           MARC::Record->new_from_usmarc($possible_duplicate_record);
         my $result = MARCmarc2koha( $dbh, $marcrecord, '' );
+        
+        # FIXME :: why 2 $biblionumber ?
         return $result->{'biblionumber'}, $result->{'biblionumber'},
           $result->{'title'}
           if $result;

Index: C4/Serials.pm
===================================================================
RCS file: /sources/koha/koha/C4/Serials.pm,v
retrieving revision 1.5.2.13
retrieving revision 1.5.2.14
diff -u -b -r1.5.2.13 -r1.5.2.14
--- C4/Serials.pm	30 Nov 2006 17:22:19 -0000	1.5.2.13
+++ C4/Serials.pm	5 Dec 2006 11:35:30 -0000	1.5.2.14
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Serials.pm,v 1.5.2.13 2006/11/30 17:22:19 toins Exp $
+# $Id: Serials.pm,v 1.5.2.14 2006/12/05 11:35:30 toins Exp $
 
 use strict;
 use C4::Date;
@@ -32,7 +32,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.5.2.13 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.5.2.14 $' =~ /\d+/g;
     shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
 };
 
@@ -1365,7 +1365,7 @@
 
         # check for existing biblioitem relating to serial issue
         my ( $count, @results ) =
-          getbiblioitembybiblionumber( $data->{'biblionumber'} );
+          GetBiblioItemByBiblioNumber( $data->{'biblionumber'} );
         my $bibitemno = 0;
         for ( my $i = 0 ; $i < $count ; $i++ ) {
             if (  $results[$i]->{'volumeddesc'} eq $data->{'serialseq'} . ' ('
@@ -1399,7 +1399,7 @@
         }
     }
 
-    my $fwk = MARCfind_frameworkcode( $dbh, $data->{'biblionumber'} );
+    my $fwk = MARCfind_frameworkcode( $data->{'biblionumber'} );
     if ( $info->{barcode} ) {
         my @errors;
         my $exists = itemdata( $info->{'barcode'} );
@@ -1524,7 +1524,7 @@
                     $marcrecord->insert_fields_ordered($newField);
                 }
             }
-            AddItem( $dbh, $marcrecord, $data->{'biblionumber'} );
+            AddItem( $marcrecord, $data->{'biblionumber'} );
             return 1;
         }
         return ( 0, @errors );

Index: C4/Circulation/Circ2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Circ2.pm,v
retrieving revision 1.114.2.22
retrieving revision 1.114.2.23
diff -u -b -r1.114.2.22 -r1.114.2.23
--- C4/Circulation/Circ2.pm	5 Dec 2006 11:23:55 -0000	1.114.2.22
+++ C4/Circulation/Circ2.pm	5 Dec 2006 11:35:30 -0000	1.114.2.23
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Circ2.pm,v 1.114.2.22 2006/12/05 11:23:55 tipaul Exp $
+# $Id: Circ2.pm,v 1.114.2.23 2006/12/05 11:35:30 toins Exp $
 
 use strict;
 require Exporter;
@@ -38,7 +38,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.114.2.22 $' =~ /\d+/g; shift(@v).".".join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.114.2.23 $' =~ /\d+/g; shift(@v).".".join( "_", map { sprintf "%03d", $_ } @v ); };
 
 =head1 NAME
 
@@ -608,7 +608,7 @@
       );
     $sth->execute();
     while ( my ( $biblionumber, $holdingbranch ) = $sth->fetchrow ) {
-        &MARCmoditemonefield( $dbh, $biblionumber, $itemnumber,
+        &MARCmoditemonefield( $biblionumber, $itemnumber,
             'items.holdingbranch', $holdingbranch, 0 );
     }
     return;
@@ -850,6 +850,138 @@
     return;
 }
 
+=head2 itemissues
+
+  @issues = &itemissues($biblioitemnumber, $biblio);
+
+Looks up information about who has borrowed the bookZ<>(s) with the
+given biblioitemnumber.
+
+C<$biblio> is ignored.
+
+C<&itemissues> returns an array of references-to-hash. The keys
+include the fields from the C<items> table in the Koha database.
+Additional keys include:
+
+=over 4
+
+=item C<date_due>
+
+If the item is currently on loan, this gives the due date.
+
+If the item is not on loan, then this is either "Available" or
+"Cancelled", if the item has been withdrawn.
+
+=item C<card>
+
+If the item is currently on loan, this gives the card number of the
+patron who currently has the item.
+
+=item C<timestamp0>, C<timestamp1>, C<timestamp2>
+
+These give the timestamp for the last three times the item was
+borrowed.
+
+=item C<card0>, C<card1>, C<card2>
+
+The card number of the last three patrons who borrowed this item.
+
+=item C<borrower0>, C<borrower1>, C<borrower2>
+
+The borrower number of the last three patrons who borrowed this item.
+
+=back
+
+=cut
+
+#'
+sub itemissues {
+    my ( $bibitem, $biblio ) = @_;
+    my $dbh = C4::Context->dbh;
+
+    # FIXME - If this function die()s, the script will abort, and the
+    # user won't get anything; depending on how far the script has
+    # gotten, the user might get a blank page. It would be much better
+    # to at least print an error message. The easiest way to do this
+    # is to set $SIG{__DIE__}.
+    my $sth =
+      $dbh->prepare("Select * from items where items.biblioitemnumber = ?")
+      || die $dbh->errstr;
+    my $i = 0;
+    my @results;
+
+    $sth->execute($bibitem) || die $sth->errstr;
+
+    while ( my $data = $sth->fetchrow_hashref ) {
+
+        # Find out who currently has this item.
+        # FIXME - Wouldn't it be better to do this as a left join of
+        # some sort? Currently, this code assumes that if
+        # fetchrow_hashref() fails, then the book is on the shelf.
+        # fetchrow_hashref() can fail for any number of reasons (e.g.,
+        # database server crash), not just because no items match the
+        # search criteria.
+        my $sth2 = $dbh->prepare(
+            "select * from issues,borrowers
+where itemnumber = ?
+and returndate is NULL
+and issues.borrowernumber = borrowers.borrowernumber"
+        );
+
+        $sth2->execute( $data->{'itemnumber'} );
+        if ( my $data2 = $sth2->fetchrow_hashref ) {
+            $data->{'date_due'} = $data2->{'date_due'};
+            $data->{'card'}     = $data2->{'cardnumber'};
+            $data->{'borrower'} = $data2->{'borrowernumber'};
+        }
+        else {
+            if ( $data->{'wthdrawn'} eq '1' ) {
+                $data->{'date_due'} = 'Cancelled';
+            }
+            else {
+                $data->{'date_due'} = 'Available';
+            }    # else
+        }    # else
+
+        $sth2->finish;
+
+        # Find the last 3 people who borrowed this item.
+        $sth2 = $dbh->prepare(
+            "select * from issues, borrowers
+                        where itemnumber = ?
+                                    and issues.borrowernumber = borrowers.borrowernumber
+                                    and returndate is not NULL
+                                    order by returndate desc,timestamp desc"
+        );
+
+#        $sth2 = $dbh->prepare("
+#            SELECT *
+#            FROM issues
+#                LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber
+#            WHERE   itemnumber = ?
+#                AND returndate is not NULL
+#            ORDER BY returndate DESC,timestamp DESC
+#        ");
+
+        $sth2->execute( $data->{'itemnumber'} );
+        for ( my $i2 = 0 ; $i2 < 2 ; $i2++ )
+        {    # FIXME : error if there is less than 3 pple borrowing this item
+            if ( my $data2 = $sth2->fetchrow_hashref ) {
+                $data->{"timestamp$i2"} = $data2->{'timestamp'};
+                $data->{"card$i2"}      = $data2->{'cardnumber'};
+                $data->{"borrower$i2"}  = $data2->{'borrowernumber'};
+            }    # if
+        }    # for
+
+        $sth2->finish;
+        $results[$i] = $data;
+        $i++;
+    }
+
+    $sth->finish;
+    return (@results);
+}
+
 =head2 canbookbeissued
 
 $issuingimpossible, $needsconfirmation = 
@@ -2959,7 +3091,7 @@
         WHERE  itemlost IS NOT NULL
           AND  itemlost <> 0
     ";
-    foreach my $key (keys %$where){
+    foreach my $key (keys %$where) {
         $query .= " AND " . $key . " LIKE '%" . $where->{$key} . "%'";
     }
     $query .= " ORDER BY ".$orderby if defined $orderby;

Index: C4/Circulation/Returns.pm
===================================================================
RCS file: /sources/koha/koha/C4/Circulation/Attic/Returns.pm,v
retrieving revision 1.10.2.2
retrieving revision 1.10.2.3
diff -u -b -r1.10.2.2 -r1.10.2.3
--- C4/Circulation/Returns.pm	17 Nov 2006 14:57:21 -0000	1.10.2.2
+++ C4/Circulation/Returns.pm	5 Dec 2006 11:35:30 -0000	1.10.2.3
@@ -1,6 +1,6 @@
 package C4::Circulation::Returns;
 
-# $Id: Returns.pm,v 1.10.2.2 2006/11/17 14:57:21 tipaul Exp $
+# $Id: Returns.pm,v 1.10.2.3 2006/12/05 11:35:30 toins Exp $
 
 #package to deal with Returns
 #written 3/11/99 by olwen at katipo.co.nz
@@ -91,7 +91,7 @@
       if ($resp ne "") {
         #if ($resp eq "Returned") {
 	if ($itemno ne "" ) {
-	  my $item = getbibliofromitemnumber($env,$dbh,$itemno);
+      my $item = GetBiblioFromItemNumber($itemno);
 	  # FIXME - This relies on C4::Circulation::Main to have a
 	  # "use C4::Circulation::Issues;" line, which is bogus.
 	  my $fmtitem = C4::Circulation::Issues::formatitem($env,$item,"",$amt_owing);
@@ -284,7 +284,7 @@
 sub find_reserves {
   my ($env,$dbh,$itemno) = @_;
 	warn "!!!!! SHOULD NOT BE HERE : Returns::find_reserves is deprecated !!!";
-  my $itemdata = getbibliofromitemnumber($env,$dbh,$itemno);
+  my $itemdata = GetBiblioFromItemNumber($itemno);
   my $sth = $dbh->prepare("select * from reserves where found is null
   and biblionumber = ? and cancellationdate is NULL
   order by priority,reservedate ");

Index: catalogue/detail.pl
===================================================================
RCS file: /sources/koha/koha/catalogue/detail.pl,v
retrieving revision 1.6.2.9
retrieving revision 1.6.2.10
diff -u -b -r1.6.2.9 -r1.6.2.10
--- catalogue/detail.pl	30 Nov 2006 18:23:51 -0000	1.6.2.9
+++ catalogue/detail.pl	5 Dec 2006 11:35:30 -0000	1.6.2.10
@@ -15,7 +15,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: detail.pl,v 1.6.2.9 2006/11/30 18:23:51 toins Exp $
+# $Id: detail.pl,v 1.6.2.10 2006/12/05 11:35:30 toins Exp $
 
 use strict;
 require Exporter;
@@ -23,58 +23,67 @@
 use C4::Auth;
 use C4::Serials; #uses getsubscriptionfrom biblionumber
 use C4::Interface::CGI::Output;
-use HTML::Template;
 use C4::Biblio;
 
-my $query=new CGI;
-my ($template, $borrowernumber, $cookie)
-    = get_template_and_user({template_name => "catalogue/detail.tmpl",
+my $query = new CGI;
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+    {
+        template_name   => "catalogue/detail.tmpl",
                  query => $query,
                  type => "intranet",
                  authnotrequired => 0,
-                 flagsrequired => {catalogue => 1},
-                 });
+        flagsrequired   => { catalogue => 1 },
+    }
+);
 
-my $biblionumber=$query->param('biblionumber');
+my $biblionumber = $query->param('biblionumber');
 
 # change back when ive fixed request.pl
-my @items                                 = &GetItemsInfo($biblionumber, 'intra');
-my $dat                                   = &bibdata($biblionumber);
-my ($authorcount, $addauthor)             = &addauthor($biblionumber);
+my @items = &GetItemsInfo( $biblionumber, 'intra' );
+my $dat = &GetBiblioData($biblionumber);
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
-
-$dat->{'count'}=@items;
-
-$dat->{'additional'}=$addauthor->[0]->{'author'};
-for (my $i = 1; $i < $authorcount; $i++) {
-        $dat->{'additional'} .= " ; " . $addauthor->[$i]->{'author'};
-} # for
+$dat->{'count'} = @items;
 
 my $norequests = 1;
 foreach my $itm (@items) {
-    $norequests = 0 unless (($itm->{'notforloan'}>0) || ($itm->{'itemnotforloan'}>0));
-    $itm->{$itm->{'publictype'}} = 1;
+    $norequests = 0
+      unless ( ( $itm->{'notforloan'} > 0 )
+        || ( $itm->{'itemnotforloan'} > 0 ) );
+    $itm->{ $itm->{'publictype'} } = 1;
 }
 
-$template->param(norequests => $norequests);
+$template->param( norequests => $norequests );
 
-  ## get notes and subjects from MARC record
-if (C4::Context->preference("marc")) {
+## get notes and subjects from MARC record
+if ( C4::Context->preference("marc") ) {
     my $dbh = C4::Context->dbh;
     my $marcflavour = C4::Context->preference("marcflavour");
-    my $marcnotesarray = &getMARCnotes($dbh,$biblionumber,$marcflavour);
-    my $marcsubjctsarray = &getMARCsubjects($dbh,$biblionumber,$marcflavour);
-
-    $template->param(MARCNOTES => $marcnotesarray);
-    $template->param(MARCSUBJCTS => $marcsubjctsarray);
+    my $record           = GetMarcBiblio($biblionumber);
+    my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
+    my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
+    
+    my $marcsubjctsarray         = GetMarcSubjects( $record, $marcflavour );
+#     my @marcsubjctsarray;
+#     foreach ( $subjects ) {
+#         if ( $_->{"code"} eq 'a' ) {
+#             push @marcsubjctsarray , $_;
+#         }
+#     }
+    
+     warn "subjects=>" . Data::Dumper::Dumper($marcsubjctsarray);
+    
+    $template->param( MARCNOTES   => $marcnotesarray );
+    $template->param( MARCSUBJCTS => $marcsubjctsarray );
+    $template->param( MARCAUTHORS => $marcauthorsarray );
 }
 
-my @results = ($dat,);
-
-foreach (keys %{$dat}) {
-    $template->param("$_" => $dat->{$_}."");
+my @results = ( $dat, );
+foreach ( keys %{$dat} ) {
+    $template->param( "$_" => $dat->{$_} . "" );
 }
-$template->param(ITEM_RESULTS => \@items,
+
+$template->param(
+    ITEM_RESULTS        => \@items,
                 subscriptionsnumber => $subscriptionsnumber,
                 biblionumber => $biblionumber,
 );

Index: catalogue/detailprint.pl
===================================================================
RCS file: /sources/koha/koha/catalogue/detailprint.pl,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- catalogue/detailprint.pl	30 Nov 2006 18:23:51 -0000	1.1.2.4
+++ catalogue/detailprint.pl	5 Dec 2006 11:35:30 -0000	1.1.2.5
@@ -18,7 +18,6 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-use HTML::Template;
 use strict;
 require Exporter;
 use C4::Context;
@@ -42,19 +41,20 @@
      $norequests = 0 unless $itm->{'notforloan'};
 }
 
+my $dat         = GetBiblioData($biblionumber);
+my $record      = GetMarcBiblio($biblionumber);
+my $addauthor   = GetMarcAuthors($record,C4::Context->preference("marcflavour"));
+my $authorcount = scalar @$addauthor;
+
+$dat->{'additional'} ="";
+foreach (@$addauthor) {
+        $dat->{'additional'} .= "|" . $_->{'a'};
+} # for
 
 
-my $dat=bibdata($biblionumber);
-my ($authorcount, $addauthor)= &addauthor($biblionumber);
-
 $dat->{'count'}=@items;
 $dat->{'norequests'} = $norequests;
 
-$dat->{'additional'}=$addauthor->[0]->{'author'};
-for (my $i = 1; $i < $authorcount; $i++) {
-        $dat->{'additional'} .= "|" . $addauthor->[$i]->{'author'};
-} # for
-
 my @results;
 
 $results[0]=$dat;

Index: catalogue/ISBDdetail.pl
===================================================================
RCS file: /sources/koha/koha/catalogue/ISBDdetail.pl,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -b -r1.2.2.1 -r1.2.2.2
--- catalogue/ISBDdetail.pl	17 Nov 2006 13:18:59 -0000	1.2.2.1
+++ catalogue/ISBDdetail.pl	5 Dec 2006 11:35:30 -0000	1.2.2.2
@@ -50,10 +50,10 @@
 my $dbh=C4::Context->dbh;
 
 my $biblionumber=$query->param('biblionumber');
-my $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber);
+my $itemtype = &MARCfind_frameworkcode($biblionumber);
 my $tagslib = &MARCgettagslib($dbh,1,$itemtype);
 
-my $record =MARCgetbiblio($dbh,$biblionumber);
+my $record = GetMarcBiblio( $biblionumber );
 # open template
 my ($template, $loggedinuser, $cookie)
 		= get_template_and_user({template_name => "catalogue/ISBDdetail.tmpl",

Index: catalogue/MARCdetail.pl
===================================================================
RCS file: /sources/koha/koha/catalogue/MARCdetail.pl,v
retrieving revision 1.5.2.5
retrieving revision 1.5.2.6
diff -u -b -r1.5.2.5 -r1.5.2.6
--- catalogue/MARCdetail.pl	30 Nov 2006 17:22:19 -0000	1.5.2.5
+++ catalogue/MARCdetail.pl	5 Dec 2006 11:35:30 -0000	1.5.2.6
@@ -56,7 +56,6 @@
 use C4::Biblio;
 use C4::Acquisition;
 use C4::Serials; #uses getsubscriptionsfrombiblionumber
-#use HTML::Template;
 
 my $query=new CGI;
 
@@ -68,7 +67,7 @@
 
 my $tagslib = &MARCgettagslib($dbh,1,$itemtype);
 
-my $record =MARCgetbiblio($dbh,$biblionumber);
+my $record = GetMarcBiblio($biblionumber);
 # open template
 my ($template, $loggedinuser, $cookie)
 		= get_template_and_user({template_name => "catalogue/MARCdetail.tmpl",

Index: catalogue/moredetail.pl
===================================================================
RCS file: /sources/koha/koha/catalogue/moredetail.pl,v
retrieving revision 1.4.2.4
retrieving revision 1.4.2.5
diff -u -b -r1.4.2.4 -r1.4.2.5
--- catalogue/moredetail.pl	30 Nov 2006 18:23:51 -0000	1.4.2.4
+++ catalogue/moredetail.pl	5 Dec 2006 11:35:30 -0000	1.4.2.5
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # NOTE: Use standard 8-space tabs for this file (indents are 4 spaces)
 
-# $Id: moredetail.pl,v 1.4.2.4 2006/11/30 18:23:51 toins Exp $
+# $Id: moredetail.pl,v 1.4.2.5 2006/12/05 11:35:30 toins Exp $
 
 # Copyright 2000-2003 Katipo Communications
 #
@@ -25,7 +25,7 @@
 require Exporter;
 use C4::Koha;
 use CGI;
-use C4::Biblio; # to use &bibitemdata &itemissues
+use C4::Biblio; # to use &GetBiblioItemData &itemissues
 use C4::Acquisition;
 use C4::Output; # contains gettemplate
 use C4::Auth;
@@ -53,7 +53,7 @@
 my $title=$query->param('title');
 my $bi=$query->param('bi');
 
-my $data=bibitemdata($bi);
+my $data=GetBiblioItemData($bi);
 my $dewey = $data->{'dewey'};
 # FIXME Dewey is a string, not a number, & we should use a function
 $dewey =~ s/0+$//;

Index: cataloguing/addbiblio.pl
===================================================================
RCS file: /sources/koha/koha/cataloguing/addbiblio.pl,v
retrieving revision 1.14.2.14
retrieving revision 1.14.2.15
diff -u -b -r1.14.2.14 -r1.14.2.15
--- cataloguing/addbiblio.pl	30 Nov 2006 17:22:19 -0000	1.14.2.14
+++ cataloguing/addbiblio.pl	5 Dec 2006 11:35:30 -0000	1.14.2.15
@@ -1,6 +1,6 @@
 #!/usr/bin/perl 
 
-# $Id: addbiblio.pl,v 1.14.2.14 2006/11/30 17:22:19 toins Exp $
+# $Id: addbiblio.pl,v 1.14.2.15 2006/12/05 11:35:30 toins Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -448,7 +448,7 @@
 my $frameworkcode = $input->param('frameworkcode');
 my $dbh = C4::Context->dbh;
 
-$frameworkcode = &MARCfind_frameworkcode($dbh,$biblionumber) if ($biblionumber and not ($frameworkcode));
+$frameworkcode = &MARCfind_frameworkcode($biblionumber) if ($biblionumber and not ($frameworkcode));
 
 $frameworkcode='' if ($frameworkcode eq 'Default');
 my ($template, $loggedinuser, $cookie)
@@ -487,7 +487,7 @@
 $tagslib = &MARCgettagslib($dbh,1,$frameworkcode);
 my $record=-1;
 my $encoding="";
-$record=MARCgetbiblio($dbh,$biblionumber) if ($biblionumber);
+$record = GetMarcBiblio( $biblionumber ) if ($biblionumber);
 ($record,$encoding) = MARCfindbreeding($dbh,$breedingid) if ($breedingid);
 
 # warn "biblionumber : $biblionumber = ".$record->as_formatted;
@@ -504,9 +504,9 @@
     $sth->execute($biblionumber);
     ($biblioitemnumber) = $sth->fetchrow;
 }
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------------
 if ($op eq "addbiblio") {
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------------
     # rebuild
     my @tags = $input->param('tag');
     my @subfields = $input->param('subfield');
@@ -531,11 +531,11 @@
         my $oldbibnum;
         my $oldbibitemnum;
         if ($is_a_modif) {
-            ModBiblioframework($dbh,$biblionumber,$frameworkcode);
-            ModBiblio($dbh,$record,$biblionumber,$frameworkcode);
+            ModBiblioframework($biblionumber,$frameworkcode);
+            ModBiblio($record,$biblionumber,$frameworkcode);
         }
         else {
-            ($biblionumber,$oldbibnum,$oldbibitemnum) = AddBiblio($dbh,$record,$frameworkcode);
+            ($biblionumber,$oldbibnum,$oldbibitemnum) = AddBiblio($record,$frameworkcode);
         }
     # now, redirect to additem page
         print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
@@ -556,9 +556,9 @@
             duplicatetitle                => $duplicatetitle,
              );
     }
-#------------------------------------------------------------------------------------------------------------------------------
+#--------------------------------------------------------------------------
 } elsif ($op eq "addfield") {
-#------------------------------------------------------------------------------------------------------------------------------
+#--------------------------------------------------------------------------
     my $addedfield = $input->param('addfield_field');
     my $cntrepeatfield=$input->param('repeat_field');
     $cntrepeatfield=1 unless ($cntrepeatfield);
@@ -596,8 +596,8 @@
         biblioitemnumtagsubfield => $biblioitemnumtagsubfield,
         biblioitemnumber         => $biblioitemnumber );
 } elsif ($op eq "delete") {
-#------------------------------------------------------------------------------------------------------------------------------
-    my $error = &DelBiblio($dbh,$biblionumber);
+#-----------------------------------------------------------------------------
+    my $error = &DelBiblio($biblionumber);
     if ($error != 1) {
         print "Content-Type: text/html\n\n$error";
     }
@@ -605,10 +605,9 @@
     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=/cgi-bin/koha/catalogue/search.pl?type=intranet\"></html>";
     }
     exit;
-#------------------------------------------------------------------------------------------------------------------------------
-#------------------------------------------------------------------------------------------------------------------------------
+#----------------------------------------------------------------------------
 } else {
-#------------------------------------------------------------------------------------------------------------------------------
+#----------------------------------------------------------------------------
     # If we're in a duplication case, we have to set to "" the biblionumber
     # as we'll save the biblio as a new one.
     if ($op eq "duplicate")

Index: cataloguing/additem-nomarc.pl
===================================================================
RCS file: /sources/koha/koha/cataloguing/Attic/additem-nomarc.pl,v
retrieving revision 1.4.2.1
retrieving revision 1.4.2.2
diff -u -b -r1.4.2.1 -r1.4.2.2
--- cataloguing/additem-nomarc.pl	26 Sep 2006 16:05:05 -0000	1.4.2.1
+++ cataloguing/additem-nomarc.pl	5 Dec 2006 11:35:30 -0000	1.4.2.2
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: additem-nomarc.pl,v 1.4.2.1 2006/09/26 16:05:05 toins Exp $
+# $Id: additem-nomarc.pl,v 1.4.2.2 2006/12/05 11:35:30 toins Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -20,6 +20,11 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 # $Log: additem-nomarc.pl,v $
+# Revision 1.4.2.2  2006/12/05 11:35:30  toins
+# Biblio.pm cleaned.
+# additionalauthors, bibliosubject, bibliosubtitle tables are now unused.
+# Some functions renamed according to the coding guidelines.
+#
 # Revision 1.4.2.1  2006/09/26 16:05:05  toins
 # adding missing template & fix wrong link on scripts.
 #
@@ -79,13 +84,13 @@
 my @items;
 
 if ( !$biblionumber ) {
-	print $input->redirect('addbooks.pl');
+    print $input->redirect('/cgi-bin/koha/cataloguing/addbooks.pl');
 }
 else {
 	my $input = new CGI;
 	my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 		{
-			template_name   => "acqui.simple/additem-nomarc.tmpl",
+            template_name   => "cataloguing/additem-nomarc.tmpl",
 			query           => $input,
 			type            => "intranet",
 			authnotrequired => 0,
@@ -93,7 +98,7 @@
 			debug           => 1,
 		}
 	);
-	( $bibliocount, @biblios ) = &getbiblio($biblionumber);
+    ( $bibliocount, @biblios ) = &GetBiblio($biblionumber);
 
 	if ( !$bibliocount ) {
 		print $input->redirect('addbooks.pl');
@@ -147,7 +152,7 @@
 			branchloop  => \@branchloop,
 			itemtypeloop => \@itemtypeloop,
 
-    ( $bibliocount, @biblios ) = &getbiblio($biblionumber);
+    ( $bibliocount, @biblios ) = &GetBiblio($biblionumber);
 
     if ( !$bibliocount ) {
         print $input->redirect('addbooks.pl');

Index: cataloguing/additem.pl
===================================================================
RCS file: /sources/koha/koha/cataloguing/additem.pl,v
retrieving revision 1.7.2.9
retrieving revision 1.7.2.10
diff -u -b -r1.7.2.9 -r1.7.2.10
--- cataloguing/additem.pl	30 Nov 2006 18:23:51 -0000	1.7.2.9
+++ cataloguing/additem.pl	5 Dec 2006 11:35:30 -0000	1.7.2.10
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: additem.pl,v 1.7.2.9 2006/11/30 18:23:51 toins Exp $
+# $Id: additem.pl,v 1.7.2.10 2006/12/05 11:35:30 toins Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -65,18 +65,18 @@
 my $op = $input->param('op');
 
 # find itemtype
-my $frameworkcode = &MARCfind_frameworkcode($dbh,$biblionumber);
+my $frameworkcode = &MARCfind_frameworkcode($biblionumber);
 
 my $tagslib = &MARCgettagslib($dbh,1,$frameworkcode);
-my $record = MARCgetbiblio($dbh,$biblionumber);
+my $record = GetMarcBiblio($biblionumber);
 # warn "==>".$record->as_formatted;
 my $oldrecord = MARCmarc2koha($dbh,$record);
 my $itemrecord;
 my $nextop="additem";
 my @errors; # store errors found while checking data BEFORE saving item.
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 if ($op eq "additem") {
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 	# rebuild
 	my @tags = $input->param('tag');
 	my @subfields = $input->param('subfield');
@@ -106,23 +106,23 @@
 	my $exists = get_item_from_barcode($addedolditem->{'barcode'});
 	push @errors,"barcode_not_unique" if($exists);
 	# if barcode exists, don't create, but report The problem.
-	my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItem($dbh,$record,$biblionumber) unless ($exists);
+    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItem($record,$biblionumber) unless ($exists);
 	if ($exists) {
 	$nextop = "additem";
 		$itemrecord = $record;
 	} else {
 		$nextop = "additem";
 	}
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 } elsif ($op eq "edititem") {
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 # retrieve item if exist => then, it's a modif
-	$itemrecord = MARCgetitem($dbh,$biblionumber,$itemnumber);
+    $itemrecord = MARCgetitem($biblionumber,$itemnumber);
 	warn "ITEM : ".$itemrecord->as_formatted;
 	$nextop="saveitem";
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 } elsif ($op eq "delitem") {
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 	# check that there is no issue on this item before deletion.
 	my $sth=$dbh->prepare("select * from issues i where i.returndate is null and i.itemnumber=?");
 	$sth->execute($itemnumber);
@@ -131,13 +131,13 @@
 	if ($onloan){
 	$nextop="additem";
 	}else{
-		&DelItem($dbh,$biblionumber,$itemnumber);
+        &DelItem($biblionumber,$itemnumber);
 		print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode");
 		#$nextop="additem";
 	}
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 } elsif ($op eq "saveitem") {
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 	# rebuild
 	my @tags = $input->param('tag');
 	my @subfields = $input->param('subfield');
@@ -150,15 +150,15 @@
         my $itemrecord=MARC::Record::new_from_xml($xml, 'UTF-8');
 # MARC::Record builded => now, record in DB
 # warn "R: ".$record->as_formatted;
-	my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItem($dbh,$itemrecord,$biblionumber,$itemnumber,0);
+    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItem($itemrecord,$biblionumber,$itemnumber,0);
 	$itemnumber="";
 	$nextop="additem";
 }
 
 #
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 # build screen with existing items. and "new" one
-#------------------------------------------------------------------------------------------------------------------------------
+#-------------------------------------------------------------------------------
 my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "cataloguing/additem.tmpl",
 			     query => $input,
@@ -171,7 +171,7 @@
 my %indicators;
 $indicators{995}='  ';
 # now, build existiing item list
-my $temp = MARCgetbiblio($dbh,$biblionumber);
+my $temp = GetMarcBiblio( $biblionumber );
 my @fields = $temp->fields();
 #my @fields = $record->fields();
 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code

Index: cataloguing/savebiblio.pl
===================================================================
RCS file: /sources/koha/koha/cataloguing/Attic/savebiblio.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- cataloguing/savebiblio.pl	30 Nov 2006 18:23:51 -0000	1.1.2.1
+++ cataloguing/savebiblio.pl	5 Dec 2006 11:35:30 -0000	1.1.2.2
@@ -49,8 +49,5 @@
 }
 else {
     $biblionumber = &newbiblio($biblio);
-    &newsubtitle( $biblionumber, $biblio->{'subtitle'} );
-    my $error = modsubject( $biblionumber, 1, @subjects );
-    modaddauthor( $biblionumber, @authors );
     print $input->redirect("additem-nomarc.pl?biblionumber=$biblionumber");
 }    # else

Index: cataloguing/value_builder/unimarc_field_4XX.pl
===================================================================
RCS file: /sources/koha/koha/cataloguing/value_builder/Attic/unimarc_field_4XX.pl,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -b -r1.1.2.5 -r1.1.2.6
--- cataloguing/value_builder/unimarc_field_4XX.pl	24 Nov 2006 21:45:34 -0000	1.1.2.5
+++ cataloguing/value_builder/unimarc_field_4XX.pl	5 Dec 2006 11:35:30 -0000	1.1.2.6
@@ -87,15 +87,9 @@
 			     flagsrequired => {editcatalogue => 1},
 			     debug => 1,
 			    });
-		#get biblionumber
-# 		my $biblionumber;
-# 		my $req= $dbh->prepare("SELECT distinctrow $biblionumber,biblionumber FROM `marc_biblio` WHERE biblionumber= ?");
-# 		$req->execute($bibnum);
-# 		($biblionumber,$bibnum) = $req->fetchrow;
-		#warn "$biblionumber :".$biblionumber;
+
 		#get marc record
-		$marcrecord = MARCgetbiblio($dbh,$bibnum);
-# 		warn "record : ".$marcrecord->as_formatted;
+        $marcrecord = GetMarcBiblio($bibnum);
 		
 		my $subfield_value_9=$bibnum;
 		my $subfield_value_0;
@@ -118,7 +112,7 @@
 			$subfield_value_a.=$marcrecord->field('702')->subfield("f") if ($marcrecord->field('702')->subfield("f"));
 			$subfield_value_a.=")" if ($marcrecord->field('702')->subfield("f")) or ($marcrecord->field('702')->subfield("c"));
 		} elsif ($marcrecord->field('710')){
-			$subfield_value_a=$marcrecord->field('710')->subfield("d")."° " if ($marcrecord->field('710')->subfield("d"));
+            $subfield_value_a=$marcrecord->field('710')->subfield("d")." " if ($marcrecord->field('710')->subfield("d"));
 			$subfield_value_a.=$marcrecord->field('710')->subfield("a") if ($marcrecord->field('710')->subfield("a"));
 			$subfield_value_a.=", ".$marcrecord->field('710')->subfield("b") if ($marcrecord->field('710')->subfield("b"));
 			$subfield_value_a.=" (".$marcrecord->field('710')->subfield("f")." - " if ($marcrecord->field('710')->subfield("f"));
@@ -134,7 +128,7 @@
 			$subfield_value_a.=$marcrecord->field('701')->subfield("f") if ($marcrecord->field('701')->subfield("f"));
 			$subfield_value_a.=")" if ($marcrecord->field('701')->subfield("f")) or ($marcrecord->field('701')->subfield("c"));
 		} elsif ($marcrecord->field('712')){
-			$subfield_value_a=$marcrecord->field('712')->subfield("d")."° " if ($marcrecord->field('712')->subfield("d"));
+            $subfield_value_a=$marcrecord->field('712')->subfield("d")." " if ($marcrecord->field('712')->subfield("d"));
 			$subfield_value_a.=$marcrecord->field('712')->subfield("a") if ($marcrecord->field('712')->subfield("a"));
 			$subfield_value_a.=", ".$marcrecord->field('712')->subfield("b") if ($marcrecord->field('712')->subfield("b"));
 			$subfield_value_a.=" (".$marcrecord->field('712')->subfield("f")." - " if ($marcrecord->field('712')->subfield("f"));

Index: circ/bookcount.pl
===================================================================
RCS file: /sources/koha/koha/circ/Attic/bookcount.pl,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -b -r1.1.2.5 -r1.1.2.6
--- circ/bookcount.pl	30 Nov 2006 18:23:51 -0000	1.1.2.5
+++ circ/bookcount.pl	5 Dec 2006 11:35:30 -0000	1.1.2.6
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: bookcount.pl,v 1.1.2.5 2006/11/30 18:23:51 toins Exp $
+# $Id: bookcount.pl,v 1.1.2.6 2006/12/05 11:35:30 toins Exp $
 
 #written 7/3/2002 by Finlay
 #script to display reports
@@ -44,7 +44,7 @@
 my $branches     = GetBranches( \%env );
 
 my $idata = itemdatanum($itm);
-my $data  = bibitemdata($bi);
+my $data  = GetBiblioItemData($bi);
 
 my $homebranch    = $branches->{ $idata->{'homebranch'} }->{'branchname'};
 my $holdingbranch = $branches->{ $idata->{'holdingbranch'} }->{'branchname'};

Index: circ/circulation.pl
===================================================================
RCS file: /sources/koha/koha/circ/circulation.pl,v
retrieving revision 1.97.2.11
retrieving revision 1.97.2.12
diff -u -b -r1.97.2.11 -r1.97.2.12
--- circ/circulation.pl	28 Nov 2006 14:07:38 -0000	1.97.2.11
+++ circ/circulation.pl	5 Dec 2006 11:35:30 -0000	1.97.2.12
@@ -304,7 +304,7 @@
 
 # 		if we don't have a reserv on item, we put the biblio infos and the waiting position
         if ( $getiteminfo->{'title'} eq '' ) {
-            my $getbibinfo = bibitemdata( $num_res->{'biblionumber'} );
+            my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
             $getreserv{color}           = 'inwait';
             $getreserv{title}           = $getbibinfo->{'title'};

Index: export/export.pl
===================================================================
RCS file: /sources/koha/koha/export/Attic/export.pl,v
retrieving revision 1.1.4.3
retrieving revision 1.1.4.4
diff -u -b -r1.1.4.3 -r1.1.4.4
--- export/export.pl	17 Nov 2006 13:18:59 -0000	1.1.4.3
+++ export/export.pl	5 Dec 2006 11:35:30 -0000	1.1.4.4
@@ -28,7 +28,7 @@
 	}
 	my $i=0;
 	while (my ($biblionumber) = $sth->fetchrow) {
-		my $record = MARCgetbiblio($dbh,$biblionumber);
+		my $record = GetMarcBiblio( $biblionumber );
 		print $i++."\n";
 #		print $record->as_formatted."\n";
 		print OUT $record->as_usmarc();

Index: export/marc.pl
===================================================================
RCS file: /sources/koha/koha/export/Attic/marc.pl,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -u -b -r1.7.2.2 -r1.7.2.3
--- export/marc.pl	17 Nov 2006 13:18:59 -0000	1.7.2.2
+++ export/marc.pl	5 Dec 2006 11:35:30 -0000	1.7.2.3
@@ -57,11 +57,11 @@
 	}
 	$strsth.=" order by marc_biblio.biblionumber ";
 	$strsth.= "LIMIT 0,$limit " if ($limit);
-	warn "requête marc.pl : ".$strsth;
+    warn "requete marc.pl : ".$strsth;
 	my $req=$dbh->prepare($strsth);
 	$req->execute;
 	while (my ($bibid) = $req->fetchrow) {
-		my $record = MARCgetbiblio($dbh,$bibid);
+        my $record = GetMarcBiblio($bibid);
 
 		print $record->as_usmarc();
 	}

Index: koha-tmpl/intranet-tmpl/prog/en/catalogue/detail.tmpl
===================================================================
RCS file: /sources/koha/koha/koha-tmpl/intranet-tmpl/prog/en/catalogue/detail.tmpl,v
retrieving revision 1.2.2.11
retrieving revision 1.2.2.12
diff -u -b -r1.2.2.11 -r1.2.2.12
--- koha-tmpl/intranet-tmpl/prog/en/catalogue/detail.tmpl	1 Dec 2006 16:59:42 -0000	1.2.2.11
+++ koha-tmpl/intranet-tmpl/prog/en/catalogue/detail.tmpl	5 Dec 2006 11:35:30 -0000	1.2.2.12
@@ -49,26 +49,41 @@
     <div id="catalogue_detail_biblio">
         <h2>Biblio detail</h2>
         <!-- TMPL_IF name="subtitles" -->
-            <p><label>Subtitle(s):</label>
+            <p><label><b>Subtitle(s):</b></label>
             <!-- TMPL_LOOP name="subtitles" -->
                 <!-- TMPL_VAR NAME="subtitle" --> ;
             <!-- /TMPL_LOOP -->
-            &nbsp;</p>
+                &nbsp;
+            </p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="author" -->
-            <p><label>Author: </label><!-- TMPL_VAR NAME="author" -->&nbsp;</p>
+            <p><label><b>Author: </b></label>
+                <a href="/cgi-bin/koha/catalogue/search.pl?q=au:<!-- TMPL_VAR NAME="author" -->">
+                    <!-- TMPL_VAR NAME="author" -->&nbsp;
+                </a>
+            </p>
         <!-- /TMPL_IF -->
-        <!-- TMPL_IF name="additional" -->
-            <p><label>Additional Author:</label><!-- TMPL_VAR NAME="additional" -->&nbsp;</p>
+        <!-- TMPL_IF name="MARCAUTHORS" -->
+            <p><label><b>Additional Author:</b></label>
+                <!-- TMPL_LOOP NAME="MARCAUTHORS" -->
+                <a href="/cgi-bin/koha/catalogue/search.pl?q=au:<!-- TMPL_VAR NAME="a" -->">
+                    <!-- TMPL_VAR NAME="a" -->&nbsp;
+                </a> --
+                <!-- /TMPL_LOOP -->
+            </p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="illus" -->
-            <p><label>Illus:</label><!-- TMPL_VAR name="illus" -->&nbsp;</p>
+            <p><label><b>Illus:</b></label><!-- TMPL_VAR name="illus" -->&nbsp;</p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="publishercode" -->
-            <p><label>Published by :</label> <!-- TMPL_VAR NAME="publishercode" -->&nbsp;</p>
+            <p><label><b>Published by :</b></label>
+                <a href="/cgi-bin/koha/catalogue/search.pl?q=pu:<!-- TMPL_VAR NAME="publishercode"">
+                    <!-- TMPL_VAR NAME="publishercode" -->&nbsp;
+                </a>
+            </p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="publicationyear" -->
-            <p><label>in </label><!-- TMPL_VAR NAME="publicationyear" -->&nbsp;</p>
+            <p><label><b>in</b></label><!-- TMPL_VAR NAME="publicationyear" -->&nbsp;</p>
         <!-- /TMPL_IF -->
         <p>
             <label>&nbsp;</label>
@@ -76,38 +91,42 @@
                 <!-- TMPL_IF name="size" -->, <!-- /TMPL_IF --><!-- TMPL_VAR name="size" -->&nbsp;
         </p>
         <!-- TMPL_IF name="isbn" -->
-            <p><label>ISBN: </label><!-- TMPL_VAR NAME="isbn" -->&nbsp;</p>
+            <p><label><b>ISBN: </b></label><!-- TMPL_VAR NAME="isbn" -->&nbsp;</p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="issn" -->
-            <p><label>ISSN: </label><!-- TMPL_VAR NAME="issn" -->&nbsp;</p>
+            <p><label><b>ISSN:</b></label><!-- TMPL_VAR NAME="issn" -->&nbsp;</p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="seriestitle" -->
-            <p><label>Collection: </label>
+            <p><label><b>Collection: </b></label>
                 <!-- TMPL_VAR NAME="seriestitle" --> 
                 <!-- TMPL_IF name="volume" -->vol. <!-- TMPL_VAR name="volume" --> <!-- TMPL_VAR name="volumedate" --><!-- /TMPL_IF -->
                 <!-- TMPL_VAR name="volumedesc" -->&nbsp;
             </p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="MARCSUBJCTS" -->
-            <p><label>Subjects:</label></p>
+            <p><label><b>Subjects: </b></label></p>
             <p>
                 <!-- TMPL_LOOP NAME="MARCSUBJCTS" -->
-                    <label>-</label>
-                    <!-- TMPL_LOOP NAME="MARCSUBJECT_SUBFIELDS_LOOP" -->
-                        <!-- TMPL_IF name="Koha-Auth-Number" -->
-                            <a href="/cgi-bin/koha/catalogue/search.pl?q=Koha-Auth-Number:<!-- TMPL_VAR NAME="Koha-Auth-Number" ESCAPE="URL"-->"><!-- TMPL_VAR NAME="value" -->&nbsp;</a><br>
-                        <!-- TMPL_ELSE -->
-                            <a href="/cgi-bin/koha/catalogue/search.pl?q=su:<!-- TMPL_VAR NAME="value" ESCAPE="URL"--> and su-to:<!-- TMPL_VAR NAME="value" ESCAPE="URL"-->"><!-- TMPL_VAR NAME="value" -->&nbsp;</a>
+                    <!-- TMPL_UNLESS NAME="KohaAuthNumber" -->
+                        <!-- TMPL_IF NAME="link_loop" -->
+                            <a href="/cgi-bin/koha/catalogue/search.pl?q=su:<!-- TMPL_VAR NAME="value" ESCAPE="URL"--><!-- TMPL_LOOP NAME="link_loop" --><!-- TMPL_VAR NAME="operator"--><!-- TMPL_IF NAME="KohaAuthNumber" --> koha-internal-code:<!--TMPL_VAR NAME="link"--><!-- TMPL_ELSE -->su-to:<!--TMPL_VAR NAME="link"--><!-- /TMPL_IF --><!-- /TMPL_LOOP -->">
+                                <!-- TMPL_VAR NAME="value" -->&nbsp;
+                            </a>
+                        <!-- TMPL_ELSE -->
+                            <a href="/cgi-bin/koha/catalogue/search.pl?q=su:<!-- TMPL_VAR NAME="value" ESCAPE="URL"-->">
+                                <!-- TMPL_VAR NAME="value" -->&nbsp;
+                            </a>
                         <!-- /TMPL_IF -->
-                    <!-- /TMPL_LOOP -->
+                    <!-- /TMPL_UNLESS -->
+                    &nbsp;<!-- TMPL_VAR NAME="separator" -->&nbsp;
                 <!-- /TMPL_LOOP -->
             </p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="copyrightdate" -->
-            <p><label>Year : </label><!-- TMPL_VAR NAME="copyrightdate" --></p>
+            <p><label><b>Year : </b></label><!-- TMPL_VAR NAME="copyrightdate" --></p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="MARCNOTES" -->
-            <p><label>Notes: </label></p>
+            <p><label><b>Notes: </b></label></p>
             <p>
                 <!-- TMPL_LOOP NAME="MARCNOTES" -->
                     <p>- <!-- TMPL_VAR NAME="marcnote" --></p>
@@ -115,26 +134,26 @@
             </p>
         <!-- TMPL_ELSE -->
             <!-- TMPL_IF name="notes" -->
-                <p><label>Notes: </label><!-- TMPL_VAR NAME="notes" --></p>
+                <p><label><b>Notes: </b></label><!-- TMPL_VAR NAME="notes" --></p>
             <!-- /TMPL_IF -->
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="unititle" -->
-            <p><label>Alt title: </label><!-- TMPL_VAR NAME="unititle" --></p>
+            <p><label><b>Alt title: </b></label><!-- TMPL_VAR NAME="unititle" --></p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="classification" -->
-            <p><label>classification:</label><!-- TMPL_VAR name="subclass" --><!-- TMPL_VAR name="classification" --></p>
+            <p><label><b>classification:</b></label><!-- TMPL_VAR name="subclass" --><!-- TMPL_VAR name="classification" --></p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="dewey" -->
-            <p><label>Dewey:</label><!-- TMPL_VAR name="dewey" --></p>
+            <p><label><b>Dewey:</b></label><!-- TMPL_VAR name="dewey" --></p>
         <!-- /TMPL_IF -->
         <!-- TMPL_IF name="URLS" -->
-            <p><label>URL: </label>
+            <p><label><b>URL: </b></label>
                 <!-- TMPL_LOOP name="URLS" -->
                     <a href="<!-- TMPL_VAR name="url" -->"><!-- TMPL_VAR NAME="url" --></a>&nbsp;
                 <!-- /TMPL_LOOP -->
             </p>
         <!-- /TMPL_IF -->
-        <p><label>Item type : </label>
+        <p><label><b>Item type : </b></label>
             <!-- TMPL_IF name="description" -->
                 <!-- TMPL_VAR name="description" -->
             <!-- TMPL_ELSE -->
@@ -198,7 +217,7 @@
 function confirm_deletion() {
     var is_confirmed = confirm('Are you sure you want to delete this biblio?');
     if (is_confirmed) {
-        window.location="acqui.simple/addbiblio.pl?op=delete&amp;biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->";
+        window.location="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&amp;biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->";
     }
 }
 </script>

Index: koha-tmpl/intranet-tmpl/prog/en/catalogue/suggest.tmpl
===================================================================
RCS file: /sources/koha/koha/koha-tmpl/intranet-tmpl/prog/en/catalogue/Attic/suggest.tmpl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- koha-tmpl/intranet-tmpl/prog/en/catalogue/suggest.tmpl	13 Oct 2006 10:25:55 -0000	1.1.2.1
+++ koha-tmpl/intranet-tmpl/prog/en/catalogue/suggest.tmpl	5 Dec 2006 11:35:30 -0000	1.1.2.2
@@ -25,7 +25,7 @@
 //			if (document.forms[0].kohafield[i].value == "biblioitems.isbn" && document.forms[0].field_value[i].value.length>0) {
 //				strQuery += "&isbn="+document.forms[0].field_value[i].value;
 //			}
-//			opener.document.location= "../acqui.simple/addbiblio.pl?z3950=1&oldbiblionumber=<!-- TMPL_VAR NAME="oldbiblionumber" -->&breedingid="+GetThisOne;
+//            opener.document.location= "../cataloguing/addbiblio.pl?z3950=1&oldbiblionumber=<!-- TMPL_VAR NAME="oldbiblionumber" -->&breedingid="+GetThisOne;
 //			self.close();
 //			return false;
 		}
@@ -34,4 +34,3 @@
 
 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
 
-

Index: koha-tmpl/intranet-tmpl/prog/en/z3950/searchresult.tmpl
===================================================================
RCS file: /sources/koha/koha/koha-tmpl/intranet-tmpl/prog/en/z3950/searchresult.tmpl,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -b -r1.1 -r1.1.2.1
--- koha-tmpl/intranet-tmpl/prog/en/z3950/searchresult.tmpl	8 Aug 2005 15:55:54 -0000	1.1
+++ koha-tmpl/intranet-tmpl/prog/en/z3950/searchresult.tmpl	5 Dec 2006 11:35:31 -0000	1.1.2.1
@@ -36,7 +36,7 @@
 	<!-- TMPL_IF NAME="numberpending" --><h1>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;
+        opener.document.location= "../cataloguing/addbiblio.pl?z3950=1&oldbiblionumber=<!-- TMPL_VAR NAME="oldbiblionumber" -->&breedingid="+GetThisOne;
 		self.close();
 		return false;
 	}

Index: koha-tmpl/opac-tmpl/prog/en/opac-detail.tmpl
===================================================================
RCS file: /sources/koha/koha/koha-tmpl/opac-tmpl/prog/en/opac-detail.tmpl,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- koha-tmpl/opac-tmpl/prog/en/opac-detail.tmpl	22 Nov 2006 15:47:30 -0000	1.1.2.3
+++ koha-tmpl/opac-tmpl/prog/en/opac-detail.tmpl	5 Dec 2006 11:35:31 -0000	1.1.2.4
@@ -24,8 +24,31 @@
 <li><a href="http://www.google.com/search?q=<!-- TMPL_VAR NAME="title" ESCAPE="url" -->+site:worldcatlibraries.org">Other Libraries(WorldCat)</a></li>
 <li><a href="http://www.scholar.google.com/scholar?q=<!-- TMPL_VAR NAME="title" ESCAPE="url" -->">Other Databases (Google Scholar)</a></li></ul>
 
-<h2><!-- TMPL_VAR NAME="title" --><!-- TMPL_IF NAME="subtitle" --> <!-- TMPL_VAR NAME="subtitle" --><!-- /TMPL_IF --></h2>
-<!-- TMPL_IF NAME="author" --><h3>By <a href="/cgi-bin/koha/opac-search.pl?marclist=biblio.author&amp;and_or=and&amp;excluding=&amp;operator=contains&amp;value=<!-- TMPL_VAR NAME="author" -->&amp;resultsperpage=20&amp;orderby=biblio.title&amp;op=do_search"><!-- TMPL_VAR NAME="author" --></a></h3><!-- /TMPL_IF --> 
+<h2>
+    <!-- TMPL_VAR NAME="title" -->
+    <!-- TMPL_IF NAME="subtitle" -->
+        <!-- TMPL_VAR NAME="subtitle" -->
+    <!-- /TMPL_IF -->
+</h2>
+
+<!-- TMPL_IF NAME="author" -->
+<h3>By <a href="/cgi-bin/koha/opac-search.pl?q=au:<!-- TMPL_VAR NAME="author" -->">
+            <!-- TMPL_VAR NAME="author" -->
+        </a>
+</h3>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF name="MARCAUTHORS" -->
+<p><label><b>Additional Author:</b></label>
+    <!-- TMPL_LOOP NAME="MARCAUTHORS" -->
+    <a href="/cgi-bin/koha/opac-search.pl?q=au:<!-- TMPL_VAR NAME="a" -->">
+        <!-- TMPL_VAR NAME="a" -->&nbsp;
+    </a> --
+    <!-- /TMPL_LOOP -->
+</p>
+<!-- /TMPL_IF -->
+
+
 
 <table>
 
@@ -38,7 +61,7 @@
 	
 <!-- TMPL_UNLESS NAME="MARCSUBJCTS" -->
 
-<!-- TMPL_IF name="subjects" --><tr><th>Subject(s):</th><td><!-- TMPL_LOOP name="subjects" --><a href="/cgi-bin/koha/opac-search.pl?op=do_search&amp;marclist=bibliosubject.subject&amp;and_or=and&amp;operator=contains&amp;value=<!-- TMPL_VAR NAME="subject" escape="HTML"-->"><!-- TMPL_VAR NAME="subject" --></a>, <!-- /TMPL_LOOP --></td></tr><!-- /TMPL_IF -->
+<!-- TMPL_IF name="subjects" --><tr><th>Subject(s):</th><td><!-- TMPL_LOOP name="subjects" --><a href="/cgi-bin/koha/opac-search.pl?q=su:<!-- TMPL_VAR NAME="subject" escape="HTML"-->"><!-- TMPL_VAR NAME="subject" --></a>, <!-- /TMPL_LOOP --></td></tr><!-- /TMPL_IF -->
 
 <!-- /TMPL_UNLESS -->
 

Index: maint/catmaintain.pl
===================================================================
RCS file: /sources/koha/koha/maint/Attic/catmaintain.pl,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -b -r1.7.2.1 -r1.7.2.2
--- maint/catmaintain.pl	17 Nov 2006 11:17:30 -0000	1.7.2.1
+++ maint/catmaintain.pl	5 Dec 2006 11:35:31 -0000	1.7.2.2
@@ -60,12 +60,6 @@
 } elsif ($type eq 'modsub'){
   %params = ('sub' => $input->param('sub'));
 
-} elsif ($type eq 'upsub'){
-  my $sub=$input->param('sub');
-  my $oldsub=$input->param('oldsub');
-  updatesub($sub,$oldsub);
-  %params = ('sub' => $sub, 'oldsub' => $oldsub);
-
 } elsif ($type eq 'undel'){
   my $title=$input->param('title');
   my ($count,$results)=deletedbib($title);

Index: members/moremember.pl
===================================================================
RCS file: /sources/koha/koha/members/moremember.pl,v
retrieving revision 1.28.2.13
retrieving revision 1.28.2.14
diff -u -b -r1.28.2.13 -r1.28.2.14
--- members/moremember.pl	1 Dec 2006 17:14:16 -0000	1.28.2.13
+++ members/moremember.pl	5 Dec 2006 11:35:31 -0000	1.28.2.14
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: moremember.pl,v 1.28.2.13 2006/12/01 17:14:16 toins Exp $
+# $Id: moremember.pl,v 1.28.2.14 2006/12/05 11:35:31 toins Exp $
 
 =head1 moremember.pl
 
@@ -315,7 +315,7 @@
 
 # 		if we don't have a reserv on item, we put the biblio infos and the waiting position
         if ( $getiteminfo->{'title'} eq '' ) {
-            my $getbibinfo = bibitemdata( $num_res->{'biblionumber'} );
+            my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
             $getreserv{color}           = 'inwait';
             $getreserv{title}           = $getbibinfo->{'title'};

Index: misc/bulkauthimport.pl
===================================================================
RCS file: /sources/koha/koha/misc/bulkauthimport.pl,v
retrieving revision 1.1
retrieving revision 1.1.8.1
diff -u -b -r1.1 -r1.1.8.1
--- misc/bulkauthimport.pl	21 Jun 2004 07:51:41 -0000	1.1
+++ misc/bulkauthimport.pl	5 Dec 2006 11:35:31 -0000	1.1.8.1
@@ -36,7 +36,7 @@
 \tc : the char encoding. At the moment, only MARC21 and UNIMARC supported. MARC21 by default.
 \d : delete EVERYTHING related to biblio in koha-DB before import  :tables :
 \t\tbiblio, \t\tbiblioitems, \t\tsubjects,\titems
-\t\tadditionalauthors, \tbibliosubtitles, \tmarc_biblio,
+\tmarc_biblio,
 \t\tmarc_subfield_table, \tmarc_word, \t\tmarc_blob_subfield
 IMPORTANT : don't use this script before you've entered and checked twice (or more) your  MARC parameters tables.
 If you fail this, the import won't work correctly and you will get invalid datas.
@@ -102,13 +102,13 @@
 	warn "$i ==>".$newRecord->as_formatted() if $verbose eq 2;
 	my $authtypecode=substr($newRecord->leader(),9,1);
 	$authtypecode="NP" if ($authtypecode eq 'a'); # personnes
-	$authtypecode="CO" if ($authtypecode eq 'b'); # collectivités
-	$authtypecode="NG" if ($authtypecode eq 'c'); # géographique
+	$authtypecode="CO" if ($authtypecode eq 'b'); # collectivit�
+	$authtypecode="NG" if ($authtypecode eq 'c'); # g�graphique
 	$authtypecode="NM" if ($authtypecode eq 'd'); # marque
 	$authtypecode="NF" if ($authtypecode eq 'e'); # famille
 	$authtypecode="TI" if ($authtypecode eq 'f'); # Titre uniforme
 	$authtypecode="TI" if ($authtypecode eq 'h'); # auteur/titre
-	$authtypecode="MM" if ($authtypecode eq 'j'); # mot matière
+	$authtypecode="MM" if ($authtypecode eq 'j'); # mot mati�e
 	warn "XX => $authtypecode";
 	# now, create biblio and items with NEWnewXX call.
 	unless ($test_parameter) {

Index: misc/fines2.pl
===================================================================
RCS file: /sources/koha/koha/misc/fines2.pl,v
retrieving revision 1.12.2.2
retrieving revision 1.12.2.3
diff -u -b -r1.12.2.2 -r1.12.2.3
--- misc/fines2.pl	1 Dec 2006 09:36:08 -0000	1.12.2.2
+++ misc/fines2.pl	5 Dec 2006 11:35:31 -0000	1.12.2.3
@@ -25,7 +25,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: fines2.pl,v 1.12.2.2 2006/12/01 09:36:08 toins Exp $
+# $Id: fines2.pl,v 1.12.2.3 2006/12/05 11:35:31 toins Exp $
 
 use C4::Context;
 use C4::Circulation::Circ2;
@@ -131,7 +131,7 @@
 	my $dbh = C4::Context->dbh;
 	my $env;
 	my $accountno=C4::Circulation::Circ2::getnextacctno($env,$data->[$i]->{'borrowernumber'},$dbh);
-	my $item=getbibliofromitemnumber($env,$dbh,$data->[$i]->{'itemnumber'});
+    my $item=GetBiblioFromItemNumber($data->[$i]->{'itemnumber'});
 	if ($item->{'itemlost'} ne '1' && $item->{'itemlost'} ne '2' ){
               # FIXME
               # this should be a separate function

Index: misc/merge_authority.pl
===================================================================
RCS file: /sources/koha/koha/misc/merge_authority.pl,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -b -r1.2 -r1.2.2.1
--- misc/merge_authority.pl	1 Mar 2005 13:41:26 -0000	1.2
+++ misc/merge_authority.pl	5 Dec 2006 11:35:31 -0000	1.2.2.1
@@ -93,7 +93,7 @@
 my $nbdone;
 # and delete entries before recreating them
 while (my ($bibid,$tag,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder) = $sth->fetchrow) {
-	my $biblio = MARCgetbiblio($dbh,$bibid);
+    my $biblio = GetMarcBiblio($bibid);
 	print "BEFORE : ".$biblio->as_formatted."\n" if $verbose;
 	# now, we know what uses the authority & where.
 	# delete all subfields that are in the same tag/tagorder and that are in the authority (& that are not in tab ignore in the biblio)
@@ -106,7 +106,7 @@
 		&MARCaddsubfield($dbh,$bibid,$tag,$tag_indicator,$tagorder,$subfield->[0],$subfieldorder,$subfield->[1]);
 	}
 	&MARCaddsubfield($dbh,$bibid,$tag,$tag_indicator,$tagorder,'9',$subfieldorder,$mergeto);
-	my $biblio = MARCgetbiblio($dbh,$bibid);
+    my $biblio = GetMarcBiblio($bibid);
 	print "AFTER : ".$biblio->as_formatted."\n" if $verbose;
 	$nbdone++;
 # 	&MARCdelsubfield($dbh,$bibid,$tag,$tagorder,$subfieldcode,$subfieldorder);

Index: misc/missing090field.pl
===================================================================
RCS file: /sources/koha/koha/misc/missing090field.pl,v
retrieving revision 1.1
retrieving revision 1.1.4.1
diff -u -b -r1.1 -r1.1.4.1
--- misc/missing090field.pl	31 Mar 2006 17:51:18 -0000	1.1
+++ misc/missing090field.pl	5 Dec 2006 11:35:31 -0000	1.1.4.1
@@ -18,7 +18,7 @@
 	$sth->execute();
 
 while (my ($biblionumber,$biblioitemnumber)=$sth->fetchrow ){
- my $record = MARCgetbiblio($dbh,$biblionumber);
+ my $record = GetMarcBiblio($biblionumber);
 		
 		MARCmodbiblionumber($biblionumber,$biblioitemnumber,$record);
 		

Index: misc/rebuildnonmarc.pl
===================================================================
RCS file: /sources/koha/koha/misc/rebuildnonmarc.pl,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -b -r1.5.2.1 -r1.5.2.2
--- misc/rebuildnonmarc.pl	6 Oct 2006 13:23:49 -0000	1.5.2.1
+++ misc/rebuildnonmarc.pl	5 Dec 2006 11:35:31 -0000	1.5.2.2
@@ -51,7 +51,7 @@
 # warn "$bibidmax <<==";
 while (my ($bibid)= $sth->fetchrow) {
 	#now, parse the record, extract the item fields, and store them in somewhere else.
-	my $record = MARCgetbiblio($dbh,$bibid);
+    my $record = GetMarcBiblio($bibid);
 	my @fields = $record->field($tagfield);
 	my @items;
 	my $nbitems=0;
@@ -68,7 +68,7 @@
 	}
 # 	print "$bibid\n";
 	# now, create biblio and items with NEWnewXX call.
-	my $frameworkcode = MARCfind_frameworkcode($dbh,$bibid);
+    my $frameworkcode = MARCfind_frameworkcode($bibid);
 	localNEWmodbiblio($dbh,$record,$bibid,$frameworkcode) unless $test_parameter;
 # 	warn 'B=>'.$record->as_formatted;
 # 	print "biblio done\n";
@@ -90,44 +90,14 @@
 	$frameworkcode="" unless $frameworkcode;
 # 	&MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,0);
 	my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
-	my $oldbiblionumber = C4::Biblio::_koha_modify_biblio($dbh,$oldbiblio);
-	C4::Biblio::_koha_modify_biblioitem($dbh,$oldbiblio);
-	# now, modify addi authors, subject, addititles.
-	my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
-	my @addiauthfields = $record->field($tagfield);
-	$dbh->do("delete from bibliosubtitle where biblionumber=$oldbiblionumber");
-	foreach my $addiauthfield (@addiauthfields) {
-		my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
-		foreach my $subfieldcount (0..$#addiauthsubfields) {
-			C4::Biblio::_koha_modify_additionalauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
-		}
-	}
-	($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
-	my @subtitlefields = $record->field($tagfield);
-	foreach my $subtitlefield (@subtitlefields) {
-		my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
-		foreach my $subfieldcount (0..$#subtitlesubfields) {
-			C4::Biblio::_koha_add_subtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
-		}
-	}
-	($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
-	my @subj = $record->field($tagfield);
-	my @subjects;
-	foreach my $subject (@subj) {
-		my @subjsubfield = $subject->subfield($tagsubfield);
-		foreach my $subfieldcount (0..$#subjsubfield) {
-			push @subjects,$subjsubfield[$subfieldcount];
-		}
-	}
-	C4::Biblio::_koha_modify_subject($dbh,$oldbiblionumber,1, at subjects);
+
 	return 1;
 }
 
 sub localNEWmoditem {
     my ( $dbh, $record, $bibid, $itemnumber, $delete ) = @_;
 # 	warn "NEWmoditem $bibid / $itemnumber / $delete ".$record->as_formatted;
-#     &MARCmoditem( $dbh, $record, $bibid, $itemnumber, $delete );
-	my $frameworkcode=MARCfind_frameworkcode($dbh,$bibid);
+    my $frameworkcode=MARCfind_frameworkcode($bibid);
     my $olditem = MARCmarc2koha( $dbh, $record,$frameworkcode );
     C4::Biblio::_koha_modify_item( $dbh, $olditem );
 }

Index: misc/rebuildthesaurus.pl
===================================================================
RCS file: /sources/koha/koha/misc/rebuildthesaurus.pl,v
retrieving revision 1.2
retrieving revision 1.2.8.1
diff -u -b -r1.2 -r1.2.8.1
--- misc/rebuildthesaurus.pl	11 Feb 2004 08:42:01 -0000	1.2
+++ misc/rebuildthesaurus.pl	5 Dec 2006 11:35:31 -0000	1.2.8.1
@@ -60,7 +60,7 @@
 $sth->execute;
 my $i=1;
 while (my ($bibid) = $sth->fetchrow) {
-	my $record = MARCgetbiblio($dbh,$bibid);
+    my $record = GetMarcBiblio($bibid);
 	print ".";
 	my $timeneeded = gettimeofday - $starttime;
 	print "$i in $timeneeded s\n" unless ($i % 50);

Index: misc/cronjobs/reservelist.pl
===================================================================
RCS file: /sources/koha/koha/misc/cronjobs/reservelist.pl,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -b -r1.2.2.1 -r1.2.2.2
--- misc/cronjobs/reservelist.pl	31 Aug 2006 16:26:42 -0000	1.2.2.1
+++ misc/cronjobs/reservelist.pl	5 Dec 2006 11:35:31 -0000	1.2.2.2
@@ -40,7 +40,7 @@
     $firstname = $data->{'firstname'};
     $phone = $data->{'phone'};
     $rdate = $data->{'reservedate'};
-    my @items = GetItemsInfo(undef,$biblionumber,''); # get the items for this biblio
+    my @items = GetItemsInfo($biblionumber,''); # get the items for this biblio
     my @itemorder;   #  prepare a new array to hold re-ordered items
 
 # The following lines take the retrieved items and run them through various

Index: misc/migration_tools/22_to_30/missing090field.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/22_to_30/Attic/missing090field.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- misc/migration_tools/22_to_30/missing090field.pl	28 Nov 2006 10:10:02 -0000	1.1.2.1
+++ misc/migration_tools/22_to_30/missing090field.pl	5 Dec 2006 11:35:31 -0000	1.1.2.2
@@ -18,7 +18,7 @@
 	$sth->execute();
 
 while (my ($biblionumber,$biblioitemnumber)=$sth->fetchrow ){
- my $record = MARCgetbiblio($dbh,$biblionumber);
+ my $record = GetMarcBiblio($biblionumber);
     print "$biblionumber \n";	
  
 		MARCmodbiblionumber($biblionumber,$biblioitemnumber,$record);

Index: misc/migration_tools/22_to_30/move_marc_to_biblioitems.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/22_to_30/Attic/move_marc_to_biblioitems.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -b -r1.1.2.1 -r1.1.2.2
--- misc/migration_tools/22_to_30/move_marc_to_biblioitems.pl	28 Nov 2006 10:10:02 -0000	1.1.2.1
+++ misc/migration_tools/22_to_30/move_marc_to_biblioitems.pl	5 Dec 2006 11:35:31 -0000	1.1.2.2
@@ -27,7 +27,7 @@
     'update biblioitems set marcxml=?, marc=? where biblionumber=?');
 my $totaldone = 0;
 while ( my ( $bibid, $biblionumber ) = $sth->fetchrow ) {
-    my $record = MARCgetbiblio( $dbh, $bibid );
+    my $record = GetMarcBiblio( $bibid );
 
     #Force UTF-8 in record leader
     $record->encoding('UTF-8');

Index: misc/migration_tools/build6xx.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/build6xx.pl,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -b -r1.2 -r1.2.2.1
--- misc/migration_tools/build6xx.pl	1 Mar 2005 13:41:27 -0000	1.2
+++ misc/migration_tools/build6xx.pl	5 Dec 2006 11:35:31 -0000	1.2.2.1
@@ -75,7 +75,7 @@
 
 # loop through each biblio
 while (my ($bibid) = $sth->fetchrow) {
-	my $record = MARCgetbiblio($dbh,$bibid);
+    my $record = GetMarcBiblio($bibid);
 	my $timeneeded = gettimeofday - $starttime;
 	print "$i in $timeneeded s\n" unless ($i % 50);
 	foreach my $field ($record->field(995)) {
@@ -92,14 +92,14 @@
 			foreach my $x ($field->subfield('x')) {
 				$hashentry.=" -- $x";
 			}
-			# remove é,à,$e...
+            # remove ��$e...
 			# all the same for mysql, but NOT for perl hashes !
-			# without those lines, tôt is not tot and patée is not patee
-			$hashentry =~ s/é|ê|è/e/g;
-			$hashentry =~ s/â|à/a/g;
-			$hashentry =~ s/î/i/g;
-			$hashentry =~ s/ô/o/g;
-			$hashentry =~ s/ù|û/u/g;
+            # without those lines, t� is not tot and pat� is not patee
+            $hashentry =~ s/���e/g;
+            $hashentry =~ s/��a/g;
+            $hashentry =~ s/�i/g;
+            $hashentry =~ s/�o/g;
+            $hashentry =~ s/|/u/g;
 			# uppercase all, in case of typing error.
 			$hashentry = uc($hashentry);
 			$totdone++;
@@ -126,7 +126,7 @@
 					$sthBIBLIOS->execute($authentry);
 					while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOS->fetchrow) {
 						# check that the field does not already have a $x (if it has, it will or has been managed by another authority
-						my $inbiblio = MARCgetbiblio($dbh,$bibid);
+                        my $inbiblio = GetMarcBiblio($bibid);
 						my $isOK = 0;
 						# loop in each 606 field
 						foreach my $in606 ($inbiblio->field('606')) {
@@ -135,11 +135,11 @@
 							foreach my $x ($in606->subfield('x')) {
 								$inEntry.=" -- $x";
 							}
-							$inEntry =~ s/é|ê|è/e/g;
-							$inEntry =~ s/â|à/a/g;
-							$inEntry =~ s/î/i/g;
-							$inEntry =~ s/ô/o/g;
-							$inEntry =~ s/ù|û/u/g;
+                            $inEntry =~ s/���e/g;
+                            $inEntry =~ s/��a/g;
+                            $inEntry =~ s/�i/g;
+                            $inEntry =~ s/�o/g;
+                            $inEntry =~ s/|/u/g;
 							$inEntry = uc($inEntry);
 							# ok, it's confirmed that we must add the $9 subfield for this biblio, so...
 							$isOK=1 if $inEntry eq $hashentry;
@@ -151,18 +151,18 @@
 				if ($#x eq 0) { # one $x
 					$sthBIBLIOSx->execute($authentry,$x[0]);
 					while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOSx->fetchrow) {
-						my $inbiblio = MARCgetbiblio($dbh,$bibid);
+                        my $inbiblio = GetMarcBiblio($bibid);
 						my $isOK = 0;
 						foreach my $in606 ($inbiblio->field('606')) {
 							my $inEntry = $in606->subfield('a');
 							foreach my $x ($in606->subfield('x')) {
 								$inEntry.=" -- $x";
 							}
-							$inEntry =~ s/é|ê|è/e/g;
-							$inEntry =~ s/â|à/a/g;
-							$inEntry =~ s/î/i/g;
-							$inEntry =~ s/ô/o/g;
-							$inEntry =~ s/ù|û/u/g;
+                            $inEntry =~ s/���e/g;
+                            $inEntry =~ s/��a/g;
+                            $inEntry =~ s/�i/g;
+                            $inEntry =~ s/�o/g;
+                            $inEntry =~ s/|/u/g;
 							$inEntry = uc($inEntry);
 							$isOK=1 if $inEntry eq $hashentry;
 						}
@@ -172,18 +172,18 @@
 				if ($#x eq 1) { # two $x
 					$sthBIBLIOSxx->execute($authentry,$x[0],$x[1]);
 					while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOSxx->fetchrow) {
-						my $inbiblio = MARCgetbiblio($dbh,$bibid);
+                        my $inbiblio = GetMarcBiblio($bibid);
 						my $isOK = 0;
 						foreach my $in606 ($inbiblio->field('606')) {
 							my $inEntry = $in606->subfield('a');
 							foreach my $x ($in606->subfield('x')) {
 								$inEntry.=" -- $x";
 							}
-							$inEntry =~ s/é|ê|è/e/g;
-							$inEntry =~ s/â|à/a/g;
-							$inEntry =~ s/î/i/g;
-							$inEntry =~ s/ô/o/g;
-							$inEntry =~ s/ù|û/u/g;
+                            $inEntry =~ s/���e/g;
+                            $inEntry =~ s/��a/g;
+                            $inEntry =~ s/�i/g;
+                            $inEntry =~ s/�o/g;
+                            $inEntry =~ s/|/u/g;
 							$inEntry = uc($inEntry);
 							$isOK=1 if $inEntry eq $hashentry;
 						}
@@ -193,18 +193,18 @@
 				if ($#x eq 2) { # 3 $x
 					$sthBIBLIOSxxx->execute($authentry,$x[0],$x[1],$x[2]);
 					while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOSxxx->fetchrow) {
-						my $inbiblio = MARCgetbiblio($dbh,$bibid);
+                        my $inbiblio = GetMarcBiblio($bibid);
 						my $isOK = 0;
 						foreach my $in606 ($inbiblio->field('606')) {
 							my $inEntry = $in606->subfield('a');
 							foreach my $x ($in606->subfield('x')) {
 								$inEntry.=" -- $x";
 							}
-							$inEntry =~ s/é|ê|è/e/g;
-							$inEntry =~ s/â|à/a/g;
-							$inEntry =~ s/î/i/g;
-							$inEntry =~ s/ô/o/g;
-							$inEntry =~ s/ù|û/u/g;
+                            $inEntry =~ s/���e/g;
+                            $inEntry =~ s/��a/g;
+                            $inEntry =~ s/�i/g;
+                            $inEntry =~ s/�o/g;
+                            $inEntry =~ s/|/u/g;
 							$inEntry = uc($inEntry);
 							$isOK=1 if $inEntry eq $hashentry;
 						}
@@ -214,18 +214,18 @@
 				if ($#x eq 3) { # 3 $x
 					$sthBIBLIOSxxxx->execute($authentry,$x[0],$x[1],$x[2],$x[3]);
 					while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOSxxxx->fetchrow) {
-						my $inbiblio = MARCgetbiblio($dbh,$bibid);
+                        my $inbiblio = GetMarcBiblio($bibid);
 						my $isOK = 0;
 						foreach my $in606 ($inbiblio->field('606')) {
 							my $inEntry = $in606->subfield('a');
 							foreach my $x ($in606->subfield('x')) {
 								$inEntry.=" -- $x";
 							}
-							$inEntry =~ s/é|ê|è/e/g;
-							$inEntry =~ s/â|à/a/g;
-							$inEntry =~ s/î/i/g;
-							$inEntry =~ s/ô/o/g;
-							$inEntry =~ s/ù|û/u/g;
+                            $inEntry =~ s/���e/g;
+                            $inEntry =~ s/��a/g;
+                            $inEntry =~ s/�i/g;
+                            $inEntry =~ s/�o/g;
+                            $inEntry =~ s/|/u/g;
 							$inEntry = uc($inEntry);
 							$isOK=1 if $inEntry eq $hashentry;
 						}

Index: misc/migration_tools/buildEDITORS.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/buildEDITORS.pl,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -b -r1.2 -r1.2.2.1
--- misc/migration_tools/buildEDITORS.pl	1 Mar 2005 13:41:27 -0000	1.2
+++ misc/migration_tools/buildEDITORS.pl	5 Dec 2006 11:35:31 -0000	1.2.2.1
@@ -69,7 +69,7 @@
 my $counter;
 my %hash;
 while (my ($bibid) = $sth->fetchrow) {
-	my $record = MARCgetbiblio($dbh,$bibid);
+	my $record = GetMarcBiblio($bibid);
 	my $isbnField = $record->field('010');
 	next unless $isbnField;
 	my $isbn=$isbnField->subfield('a');
@@ -152,15 +152,15 @@
 # 	# 		print "=>".$field->as_formatted."\n";
 # 			foreach my $authentry ($field->subfield("a")) {
 # 				my $hashentry = $authentry;
-# 				# la particularité de ce script là, c'est que l'entrée dans la table d'autorité est $a -- $b (et pas $x -- $x -- $x -- $a comme pour les autorités NC)
-# 				# si nécessaire, compléter avec le $c (n'existe pas dans le fichier que j'ai migré avec cette moulinette
-# 				# supprimer les accents, certaines entrées sont sans, d'autres avec !
-# 				# mysql ne différencie pas, mais les hash perl oui !
-# 				$hashentry =~ s/é|ê|è/e/g;
-# 				$hashentry =~ s/â|à/a/g;
-# 				$hashentry =~ s/î/i/g;
-# 				$hashentry =~ s/ô/o/g;
-# 				$hashentry =~ s/ù|û/u/g;
+# 				# la particularit�de ce script l� c'est que l'entr� dans la table d'autorit�est $a -- $b (et pas $x -- $x -- $x -- $a comme pour les autorit� NC)
+# 				# si n�essaire, compl�er avec le $c (n'existe pas dans le fichier que j'ai migr�avec cette moulinette
+# 				# supprimer les accents, certaines entr�s sont sans, d'autres avec !
+# 				# mysql ne diff�encie pas, mais les hash perl oui !
+# 				$hashentry =~ s/���e/g;
+# 				$hashentry =~ s/��a/g;
+# 				$hashentry =~ s/�i/g;
+# 				$hashentry =~ s/�o/g;
+# 				$hashentry =~ s/|/u/g;
 # 				$hashentry = uc($hashentry);
 # 				print "==>$hashentry" if $hashentry =~ /.*ETATS.*/;
 # 				$totdone++;
@@ -178,21 +178,21 @@
 # 					$authorityRecord->insert_fields_ordered($newfield);
 # 					$authid=AUTHaddauthority($dbh,$authorityRecord,'','CO');
 # 					$alreadydone{$hashentry} = $authid;
-# 					# OK, on garde la notice d'autorité, on cherche les notices biblio et on les met à jour...
+# 					# OK, on garde la notice d'autorit� on cherche les notices biblio et on les met �jour...
 # 					if ($fieldnumber eq '710') {
 # 						$sthBIBLIOS710->execute($authentry);
 # 						while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOS710->fetchrow) {
-# 							my $inbiblio = MARCgetbiblio($dbh,$bibid);
+# 							my $inbiblio = GetMarcBiblio($bibid);
 # 							my $isOK = 0;
 # 							foreach my $in7xx ($inbiblio->field($fieldnumber)) {
-# 								# !!!!! ici, il faut reconstruire l'entrée de la table de hachage comme ci dessus
+# 								# !!!!! ici, il faut reconstruire l'entr� de la table de hachage comme ci dessus
 # 								# sinon, 
 # 								my $inEntry = $in7xx->subfield('a');
-# 								$inEntry =~ s/é|ê|è/e/g;
-# 								$inEntry =~ s/â|à/a/g;
-# 								$inEntry =~ s/î/i/g;
-# 								$inEntry =~ s/ô/o/g;
-# 								$inEntry =~ s/ù|û/u/g;
+# 								$inEntry =~ s/���e/g;
+# 								$inEntry =~ s/��a/g;
+# 								$inEntry =~ s/�i/g;
+# 								$inEntry =~ s/�o/g;
+# 								$inEntry =~ s/|/u/g;
 # 								$inEntry = uc($inEntry);
 # 								$isOK=1 if $inEntry eq $hashentry;
 # 							}
@@ -202,17 +202,17 @@
 # 					if ($fieldnumber eq '711') {
 # 						$sthBIBLIOS711->execute($authentry);
 # 						while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOS711->fetchrow) {
-# 							my $inbiblio = MARCgetbiblio($dbh,$bibid);
+# 							my $inbiblio = GetMarcBiblio($bibid);
 # 							my $isOK = 0;
 # 							foreach my $in7xx ($inbiblio->field($fieldnumber)) {
-# 								# !!!!! ici, il faut reconstruire l'entrée de la table de hachage comme ci dessus
+# 								# !!!!! ici, il faut reconstruire l'entr� de la table de hachage comme ci dessus
 # 								# sinon, 
 # 								my $inEntry = $in7xx->subfield('a');
-# 								$inEntry =~ s/é|ê|è/e/g;
-# 								$inEntry =~ s/â|à/a/g;
-# 								$inEntry =~ s/î/i/g;
-# 								$inEntry =~ s/ô/o/g;
-# 								$inEntry =~ s/ù|û/u/g;
+# 								$inEntry =~ s/���e/g;
+# 								$inEntry =~ s/��a/g;
+# 								$inEntry =~ s/�i/g;
+# 								$inEntry =~ s/�o/g;
+# 								$inEntry =~ s/|/u/g;
 # 								$inEntry = uc($inEntry);
 # 								$isOK=1 if $inEntry eq $hashentry;
 # 							}
@@ -222,17 +222,17 @@
 # 					if ($fieldnumber eq '712') {
 # 						$sthBIBLIOS712->execute($authentry);
 # 						while (my ($bibid,$tag,$tagorder,$subfieldorder) = $sthBIBLIOS712->fetchrow) {
-# 							my $inbiblio = MARCgetbiblio($dbh,$bibid);
+# 							my $inbiblio = GetMarcBiblio($bibid);
 # 							my $isOK = 0;
 # 							foreach my $in7xx ($inbiblio->field($fieldnumber)) {
-# 								# !!!!! ici, il faut reconstruire l'entrée de la table de hachage comme ci dessus
+# 								# !!!!! ici, il faut reconstruire l'entr� de la table de hachage comme ci dessus
 # 								# sinon, 
 # 								my $inEntry = $in7xx->subfield('a');
-# 								$inEntry =~ s/é|ê|è/e/g;
-# 								$inEntry =~ s/â|à/a/g;
-# 								$inEntry =~ s/î/i/g;
-# 								$inEntry =~ s/ô/o/g;
-# 								$inEntry =~ s/ù|û/u/g;
+# 								$inEntry =~ s/���e/g;
+# 								$inEntry =~ s/��a/g;
+# 								$inEntry =~ s/�i/g;
+# 								$inEntry =~ s/�o/g;
+# 								$inEntry =~ s/|/u/g;
 # 								$inEntry = uc($inEntry);
 # 								$isOK=1 if $inEntry eq $hashentry;
 # 							}

Index: misc/migration_tools/bulkmarcimport.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/bulkmarcimport.pl,v
retrieving revision 1.7.2.2
retrieving revision 1.7.2.3
diff -u -b -r1.7.2.2 -r1.7.2.3
--- misc/migration_tools/bulkmarcimport.pl	14 Nov 2006 16:39:00 -0000	1.7.2.2
+++ misc/migration_tools/bulkmarcimport.pl	5 Dec 2006 11:35:31 -0000	1.7.2.3
@@ -163,7 +163,7 @@
 \tsupported. MARC21 by default.
 \td : delete EVERYTHING related to biblio in koha-DB before import  :tables :
 \t\tbiblio, \t\tbiblioitems, \t\tsubjects,\titems
-\t\tadditionalauthors, \tbibliosubtitles, \tmarc_biblio,
+\tmarc_biblio,
 \t\tmarc_subfield_table, \tmarc_word, \t\tmarc_blob_subfield
 IMPORTANT : don't use this script before you've entered and checked your MARC parameters tables twice (or more!).
 Otherwise, the import won't work correctly and you will get invalid data.
@@ -183,9 +183,6 @@
 	$dbh->do("delete from biblio");
 	$dbh->do("delete from biblioitems");
 	$dbh->do("delete from items");
-	$dbh->do("delete from bibliosubject");
-	$dbh->do("delete from additionalauthors");
-	$dbh->do("delete from bibliosubtitle");
 }
 if ($test_parameter) {
 	print "TESTING MODE ONLY\n    DOING NOTHING\n===============\n";
@@ -284,11 +281,11 @@
 	print "$i : $nbitems items found\n" if $verbose;
 	# now, create biblio and items with Addbiblio call.
 	unless ($test_parameter) {
-		my ($bibid,$oldbibitemnum) = AddBiblio($dbh,$newRecord,'');
+        my ($bibid,$oldbibitemnum) = AddBiblio($newRecord,'');
 		warn "ADDED biblio NB $bibid in DB\n" if $verbose;
 		for (my $i=0;$i<=$#items;$i++) {
 		    warn "here is the biblioitemnumber $oldbibitemnum";
-			AddItem($dbh,$items[$i],$bibid,$oldbibitemnum);
+            AddItem($items[$i],$bibid,$oldbibitemnum);
 		}
 	}
 }

Index: misc/migration_tools/rebuild_zebra_idx.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/rebuild_zebra_idx.pl,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -b -r1.1 -r1.1.2.1
--- misc/migration_tools/rebuild_zebra_idx.pl	9 Feb 2006 10:59:34 -0000	1.1
+++ misc/migration_tools/rebuild_zebra_idx.pl	5 Dec 2006 11:35:31 -0000	1.1.2.1
@@ -43,7 +43,7 @@
 $sth->execute;
 my $i=0;
 while ((my $biblionumber) = $sth->fetchrow) {
-	my $record = MARCgetbiblio($dbh,$biblionumber);
+	my $record = GetMarcBiblio($biblionumber);
 	my $filename = $cgidir."/zebra/biblios/BIBLIO".$biblionumber."iso2709";
 	open F,"> $filename";
 	print F $record->as_xml();

Index: misc/migration_tools/rebuild_zebra.pl
===================================================================
RCS file: /sources/koha/koha/misc/migration_tools/rebuild_zebra.pl,v
retrieving revision 1.4.2.5
retrieving revision 1.4.2.6
diff -u -b -r1.4.2.5 -r1.4.2.6
--- misc/migration_tools/rebuild_zebra.pl	1 Dec 2006 13:44:19 -0000	1.4.2.5
+++ misc/migration_tools/rebuild_zebra.pl	5 Dec 2006 11:35:31 -0000	1.4.2.6
@@ -455,7 +455,7 @@
     $sth->execute();
     my $i=0;
     while (my ($biblionumber) = $sth->fetchrow) {
-        my $record = MARCgetbiblio($dbh,$biblionumber);
+        my $record = GetMarcBiblio($biblionumber);
         # check that biblionumber & biblioitemnumber are stored in the MARC record, otherwise, add them & update the biblioitems.marcxml data.
         my $record_correct=1;
         unless ($biblionumbertagfield<10?($record->field($biblionumbertagfield)):($record->subfield($biblionumbertagfield,$biblionumbertagsubfield))) {

Index: misc/notifys/fines.pl
===================================================================
RCS file: /sources/koha/koha/misc/notifys/fines.pl,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -b -r1.3 -r1.3.2.1
--- misc/notifys/fines.pl	12 Jul 2006 14:07:03 -0000	1.3
+++ misc/notifys/fines.pl	5 Dec 2006 11:35:31 -0000	1.3.2.1
@@ -91,7 +91,7 @@
 				        my $env;
 
 		        		my $accountno=C4::Circulation::Circ2::getnextacctno($env,$overdue->{'borrowernumber'},$dbh);
-       					my $item=getbibliofromitemnumber($env,$dbh,$overdue->{'itemnumber'});
+                           my $item=GetBiblioFromItemNumber($overdue->{'itemnumber'});
         				if ($item->{'itemlost'} ne '1' && $item->{'itemlost'} ne '2' ){
           					$item->{'title'}=~ s/\'/\\'/g;
 					      	my $query="Insert into accountlines (borrowernumber,itemnumber,accountno,date,amount, description,accounttype,amountoutstanding) 
@@ -266,7 +266,7 @@
 	                                        	my %row_data;
 							my $env;	#FIXME what is this varible for?
 						      
- 							if ( my $item = getbibliofromitemnumber($env, $dbh, $over->{'itemnumber'})){
+                             if ( my $item = GetBiblioFromItemNumber( $over->{'itemnumber'})){
 							    print "getting fine ($over->{'itemnumber'} $overdue->{'borrowernumber'} $over->{'borrowernumber'}\n";
 						        my $fine = GetFine($over->{'itemnumber'},$overdue->{'borrowernumber'}); 
 							    

Index: opac/opac-addbookbybiblionumber.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-addbookbybiblionumber.pl,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -b -r1.5.2.1 -r1.5.2.2
--- opac/opac-addbookbybiblionumber.pl	30 Nov 2006 18:23:51 -0000	1.5.2.1
+++ opac/opac-addbookbybiblionumber.pl	5 Dec 2006 11:35:31 -0000	1.5.2.2
@@ -2,7 +2,7 @@
 #script to provide bookshelf management
 # WARNING: This file uses 4-character tabs!
 #
-# $Header: /sources/koha/koha/opac/opac-addbookbybiblionumber.pl,v 1.5.2.1 2006/11/30 18:23:51 toins Exp $
+# $Header: /sources/koha/koha/opac/opac-addbookbybiblionumber.pl,v 1.5.2.2 2006/12/05 11:35:31 toins Exp $
 #
 # Copyright 2000-2002 Katipo Communications
 #
@@ -54,7 +54,7 @@
 	exit;
 } else {
 
-	my  ( $bibliocount, @biblios )  = getbiblio($biblionumber);
+    my  ( $bibliocount, @biblios )  = GetBiblio($biblionumber);
 
 	my ($shelflist) = GetShelfList($loggedinuser,3);
 	my @shelvesloop;
@@ -91,6 +91,11 @@
 	output_html_with_http_headers $query, $cookie, $template->output;
 }
 # $Log: opac-addbookbybiblionumber.pl,v $
+# Revision 1.5.2.2  2006/12/05 11:35:31  toins
+# Biblio.pm cleaned.
+# additionalauthors, bibliosubject, bibliosubtitle tables are now unused.
+# Some functions renamed according to the coding guidelines.
+#
 # Revision 1.5.2.1  2006/11/30 18:23:51  toins
 # theses scripts don't need to use C4::Search.
 #

Index: opac/opac-basket.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-basket.pl,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -u -b -r1.8.2.1 -r1.8.2.2
--- opac/opac-basket.pl	30 Nov 2006 17:22:19 -0000	1.8.2.1
+++ opac/opac-basket.pl	5 Dec 2006 11:35:31 -0000	1.8.2.2
@@ -15,7 +15,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: opac-basket.pl,v 1.8.2.1 2006/11/30 17:22:19 toins Exp $
+# $Id: opac-basket.pl,v 1.8.2.2 2006/12/05 11:35:31 toins Exp $
 
 use strict;
 require Exporter;
@@ -50,13 +50,15 @@
 foreach my $biblionumber (@bibs) {
     $template->param(biblionumber => $biblionumber);
 
-    my $dat                                   = &bibdata($biblionumber);
-    my ($authorcount, $addauthor)             = &addauthor($biblionumber);
+    my $dat         = &GetBiblioData( $biblionumber );
+    my $record      = &GetMarcBiblio( $biblionumber );
+    my $addauthor   = &GetMarcAuthors( $record, C4::Context->preference("marcflavour") );
+    my $authorcount = scalar @$addauthor;
     my @items                                 = &ItemInfo(undef, $biblionumber, 'opac');
 
-    $dat->{'additional'}=$addauthor->[0]->{'author'};
-    for (my $i = 1; $i < $authorcount; $i++) {
-            $dat->{'additional'} .= "|" . $addauthor->[$i]->{'author'};
+    $dat->{'additional'} = "";
+    foreach (@$addauthor) {
+            $dat->{'additional'} .= "|" . $_->{'a'};
     } # for
     if($num % 2 == 1){
         $dat->{'even'} = 1;

Index: opac/opac-detail.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-detail.pl,v
retrieving revision 1.32.2.3
retrieving revision 1.32.2.4
diff -u -b -r1.32.2.3 -r1.32.2.4
--- opac/opac-detail.pl	30 Nov 2006 18:23:51 -0000	1.32.2.3
+++ opac/opac-detail.pl	5 Dec 2006 11:35:31 -0000	1.32.2.4
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: opac-detail.pl,v 1.32.2.3 2006/11/30 18:23:51 toins Exp $
+# $Id: opac-detail.pl,v 1.32.2.4 2006/12/05 11:35:31 toins Exp $
 
 use strict;
 require Exporter;
@@ -31,7 +31,7 @@
 use C4::Review;
 
 my $query = new CGI;
-my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
     {
         template_name   => "opac-detail.tmpl",
         query           => $query,
@@ -46,8 +46,7 @@
 
 # change back when ive fixed request.pl
 my @items = &ItemInfo( undef, $biblionumber, 'opac' );
-my $dat = &bibdata($biblionumber);
-my ( $authorcount,        $addauthor )      = &addauthor($biblionumber);
+my $dat         = &GetBiblioData( $biblionumber );
 
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
@@ -64,20 +63,8 @@
       GetLatestSerials( $subscription->{subscriptionid}, 3 );
     push @subs, \%cell;
 }
-
 $dat->{'count'} = @items;
-my @author;
-if ( $dat->{'author'} ) {
-    my %authorpush;
-    $authorpush{author} = $dat->{'author'};
-    push @author, \%authorpush;
-}
-$dat->{'additional'} = $addauthor->[0]->{'author'};
-if ( $dat->{'additional'} ) {
-    my %authorpush;
-    $authorpush{author} = $addauthor->[0]->{'author'};
-    push @author, \%authorpush;
-}
+
 my @title;
 foreach my $word ( split( " ", $dat->{'title'} ) ) {
     unless ( length($word) == 4 ) {
@@ -90,14 +77,6 @@
     }    #it's NOT a stopword => use it. Otherwise, ignore
 }
 
-for ( my $i = 1 ; $i < $authorcount ; $i++ ) {
-    $dat->{'additional'} .= " ; " . $addauthor->[$i]->{'author'};
-
-    my %authorpush;
-    $authorpush{author} = $addauthor->[$i]->{'author'};
-    push @author, \%authorpush;
-}    # for
-
 my $norequests = 1;
 foreach my $itm (@items) {
     $norequests = 0
@@ -117,13 +96,18 @@
 if ( C4::Boolean::true_p($marc) ) {
     my $dbh = C4::Context->dbh;
     my $marcflavour = C4::Context->preference("marcflavour");
-    my $marcnotesarray = &getMARCnotes( $dbh, $biblionumber, $marcflavour );
+    my $record         = GetMarcBiblio($biblionumber);
+    my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
+    my $marcauthorarray= GetMarcAuthors( $record, C4::Context->preference("marcflavour") );
+    my $authorcount    = scalar @$marcauthorarray;
+    
     $results[0]->{MARCNOTES} = $marcnotesarray;
-    my $marcsubjctsarray = &getMARCsubjects( $dbh, $biblionumber, $marcflavour );
+    my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
     $results[0]->{MARCSUBJCTS} = $marcsubjctsarray;
 
-    # 	$template->param(MARCNOTES => $marcnotesarray);
-    # 	$template->param(MARCSUBJCTS => $marcsubjctsarray);
+    $template->param(MARCNOTES   => $marcnotesarray);
+    $template->param(MARCSUBJCTS => $marcsubjctsarray);
+    $template->param(MARCAUTHORS => $marcauthorarray);
 }
 
 # get the number of reviews
@@ -142,6 +126,7 @@
   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
 my @subs;
 foreach my $subscription (@subscriptions) {
+
     #warn "subsid :" . $subscription->{subscriptionid};
     my %cell;
     $cell{subscriptionid}    = $subscription->{subscriptionid};

Index: opac/opac-detailprint.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-detailprint.pl,v
retrieving revision 1.3.2.2
retrieving revision 1.3.2.3
diff -u -b -r1.3.2.2 -r1.3.2.3
--- opac/opac-detailprint.pl	30 Nov 2006 17:22:19 -0000	1.3.2.2
+++ opac/opac-detailprint.pl	5 Dec 2006 11:35:31 -0000	1.3.2.3
@@ -42,15 +42,17 @@
      $norequests = 0 unless $itm->{'notforloan'};
 }
 
-my $dat=bibdata($biblionumber);
-my ($authorcount, $addauthor)= &getaddauthor($biblionumber);
+my $dat = GetBiblioData($biblionumber);
+my $record      = GetMarcBiblio( $biblionumber );
+my $addauthor   = GetMarcAuthors( $record, C4::Context->preference("marcflavour") );
+my $authorcount = scalar @$addauthor;
 
 $dat->{'count'}=@items;
 $dat->{'norequests'} = $norequests;
 
-$dat->{'additional'}=$addauthor->[0]->{'author'};
-for (my $i = 1; $i < $authorcount; $i++) {
-        $dat->{'additional'} .= "|" . $addauthor->[$i]->{'author'};
+$dat->{'additional'} ="";
+foreach (@$addauthor) {
+        $dat->{'additional'} .= "|" . $_->{'a'};
 } # for
 
 my @results;

Index: opac/opac-ISBDdetail.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-ISBDdetail.pl,v
retrieving revision 1.16.2.2
retrieving revision 1.16.2.3
diff -u -b -r1.16.2.2 -r1.16.2.3
--- opac/opac-ISBDdetail.pl	30 Nov 2006 18:23:51 -0000	1.16.2.2
+++ opac/opac-ISBDdetail.pl	5 Dec 2006 11:35:31 -0000	1.16.2.3
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: opac-ISBDdetail.pl,v 1.16.2.2 2006/11/30 18:23:51 toins Exp $
+# $Id: opac-ISBDdetail.pl,v 1.16.2.3 2006/12/05 11:35:31 toins Exp $
 
 =head1 NAME
 
@@ -62,10 +62,10 @@
 my $dbh=C4::Context->dbh;
 
 my $biblionumber=$query->param('biblionumber');
-my $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber);
+my $itemtype = &MARCfind_frameworkcode($biblionumber);
 my $tagslib = &MARCgettagslib($dbh,1,$itemtype);
 
-my $record =MARCgetbiblio($dbh,$biblionumber);
+my $record =GetMarcBiblio($biblionumber);
 
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);

Index: opac/opac-MARCdetail.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-MARCdetail.pl,v
retrieving revision 1.14.2.2
retrieving revision 1.14.2.3
diff -u -b -r1.14.2.2 -r1.14.2.3
--- opac/opac-MARCdetail.pl	30 Nov 2006 18:23:51 -0000	1.14.2.2
+++ opac/opac-MARCdetail.pl	5 Dec 2006 11:35:31 -0000	1.14.2.3
@@ -37,10 +37,6 @@
 The first 10 tabs present the biblio, the 11th one presents
 the items attached to the biblio
 
-=head1 FUNCTIONS
-
-=over 2
-
 =cut
 
 
@@ -55,16 +51,17 @@
 use C4::Biblio;
 use C4::Acquisition;
 use HTML::Template;
+use C4::Koha;
 
 my $query=new CGI;
 
 my $dbh=C4::Context->dbh;
 
 my $biblionumber=$query->param('biblionumber');
-my $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber);
+my $itemtype = &MARCfind_frameworkcode($biblionumber);
 my $tagslib = &MARCgettagslib($dbh,0,$itemtype);
 
-my $record =MARCgetbiblio($dbh,$biblionumber);
+my $record =GetMarcBiblio($biblionumber);
 # open template
 my ($template, $loggedinuser, $cookie)
 		= get_template_and_user({template_name => "opac-MARCdetail.tmpl",
@@ -203,6 +200,7 @@
 	$row_data{item_value} = $items_data;
 	push(@item_value_loop,\%row_data);
 }
+
 foreach my $subfield_code (keys(%witness)) {
 	my %header_value;
 	$header_value{header_value} = $witness{$subfield_code};

Index: opac/opac-reserve.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-reserve.pl,v
retrieving revision 1.29.2.4
retrieving revision 1.29.2.5
diff -u -b -r1.29.2.4 -r1.29.2.5
--- opac/opac-reserve.pl	30 Nov 2006 18:23:51 -0000	1.29.2.4
+++ opac/opac-reserve.pl	5 Dec 2006 11:35:31 -0000	1.29.2.5
@@ -48,7 +48,7 @@
 # get biblionumber.....
 my $biblionumber = $query->param('biblionumber');
 
-my $bibdata = bibdata($biblionumber);
+my $bibdata = GetBiblioData($biblionumber);
  $template->param($bibdata);
  $template->param(biblionumber => $biblionumber);
 

Index: opac/opac-review.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-review.pl,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -u -b -r1.2.2.1 -r1.2.2.2
--- opac/opac-review.pl	30 Nov 2006 17:22:19 -0000	1.2.2.1
+++ opac/opac-review.pl	5 Dec 2006 11:35:31 -0000	1.2.2.2
@@ -48,7 +48,7 @@
 # my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
 # $template->param($borr);
 
-my $biblio = bibdata( $biblionumber, 'opac' );
+my $biblio = GetBiblioData( $biblionumber, 'opac' );
 
 my $savedreview = getreview( $biblionumber, $borrowernumber );
 if ( $type eq 'save' ) {

Index: opac/opac-sendbasket.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-sendbasket.pl,v
retrieving revision 1.10.2.3
retrieving revision 1.10.2.4
diff -u -b -r1.10.2.3 -r1.10.2.4
--- opac/opac-sendbasket.pl	30 Nov 2006 18:23:51 -0000	1.10.2.3
+++ opac/opac-sendbasket.pl	5 Dec 2006 11:35:31 -0000	1.10.2.4
@@ -62,19 +62,22 @@
 	foreach my $biblionumber (@bibs) {
 		$template2->param(biblionumber => $biblionumber);
 
-		my $dat = &bibdata($biblionumber);
-		my ($authorcount, $addauthor) = &addauthor($biblionumber);
+        my $dat         = GetBiblioData( $biblionumber );
+        my $record      = GetMarcBiblio( $biblionumber );
+        my $addauthor   = GetMarcAuthors( $record, C4::Context->preference("marcflavour") );
+        my $authorcount = scalar @$addauthor;
+        
 		my @items                     = &ItemInfo(undef, $biblionumber, 'opac');
 
-		$dat->{'additional'}=$addauthor->[0]->{'author'};
-		for (my $i = 1; $i < $authorcount; $i++) {
-			$dat->{'additional'} .= "|" . $addauthor->[$i]->{'author'};
+        $dat->{'additional'}="";
+        foreach (@$addauthor) {
+            $dat->{'additional'} .= "|" . $_->{'a'};
 		}
 
 		$dat->{'biblionumber'} = $biblionumber;
 		$dat->{ITEM_RESULTS} = \@items;
 
-		my $record = MARCgetbiblio($dbh,$biblionumber);
+        
 		$iso2709 .= $record->as_usmarc();
 
 		push (@results, $dat);

Index: opac/opac-showreviews.pl
===================================================================
RCS file: /sources/koha/koha/opac/opac-showreviews.pl,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -b -r1.2.2.2 -r1.2.2.3
--- opac/opac-showreviews.pl	30 Nov 2006 18:23:51 -0000	1.2.2.2
+++ opac/opac-showreviews.pl	5 Dec 2006 11:35:31 -0000	1.2.2.3
@@ -39,7 +39,7 @@
                  debug => 1,
                  });
 
-my $biblio=bibdata($biblionumber,'opac');
+my $biblio=GetBiblioData($biblionumber,'opac');
 my $reviews=getreviews($biblionumber,1);
 
 $template->param('reviews' => $reviews,

Index: reserve/request.pl
===================================================================
RCS file: /sources/koha/koha/reserve/request.pl,v
retrieving revision 1.6.2.10
retrieving revision 1.6.2.11
diff -u -b -r1.6.2.10 -r1.6.2.11
--- reserve/request.pl	30 Nov 2006 18:23:52 -0000	1.6.2.10
+++ reserve/request.pl	5 Dec 2006 11:35:31 -0000	1.6.2.11
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: request.pl,v 1.6.2.10 2006/11/30 18:23:52 toins Exp $
+# $Id: request.pl,v 1.6.2.11 2006/12/05 11:35:31 toins Exp $
 
 #writen 2/1/00 by chris at katipo.oc.nz
 # Copyright 2000-2002 Katipo Communications
@@ -56,7 +56,7 @@
 
 # get biblio information....
 my $biblionumber = $input->param('biblionumber');
-my $dat          = bibdata($biblionumber);
+my $dat          = GetBiblioData($biblionumber);
 
 # Select borrowers infos
 my $findborrower = $input->param('findborrower');

Index: serials/serials-edit.pl
===================================================================
RCS file: /sources/koha/koha/serials/Attic/serials-edit.pl,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -b -r1.1.2.4 -r1.1.2.5
--- serials/serials-edit.pl	23 Nov 2006 15:18:30 -0000	1.1.2.4
+++ serials/serials-edit.pl	5 Dec 2006 11:35:32 -0000	1.1.2.5
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: serials-edit.pl,v 1.1.2.4 2006/11/23 15:18:30 hdl Exp $
+# $Id: serials-edit.pl,v 1.1.2.5 2006/12/05 11:35:32 toins Exp $
 
 =head1 NAME
 
@@ -193,12 +193,12 @@
             $template->param("barcode_not_unique" => 1,'errserialseq'=>$serialseqs[$index]);
             # if barcode exists, don't create, but report The problem.
             unless ($exists){
-              my ($biblionumber,$bibitemnum,$itemnumber) = AddItem($dbh,$record,$itemhash{$item}->{'bibnum'});
+              my ($biblionumber,$bibitemnum,$itemnumber) = AddItem($record,$itemhash{$item}->{'bibnum'});
               AddItem2Serial($itemhash{$item}->{'serial'},$itemnumber);
             }
           } else {
             #modify item
-            my ($oldbiblionumber,$oldbibnum,$itemnumber) = ModItem($dbh,$record,$itemhash{$item}->{'bibnum'},$item,0);
+            my ($oldbiblionumber,$oldbibnum,$itemnumber) = ModItem($record,$itemhash{$item}->{'bibnum'},$item,0);
         }
        }
       }

Index: serials/serials-recieve.pl
===================================================================
RCS file: /sources/koha/koha/serials/Attic/serials-recieve.pl,v
retrieving revision 1.4.2.4
retrieving revision 1.4.2.5
diff -u -b -r1.4.2.4 -r1.4.2.5
--- serials/serials-recieve.pl	21 Nov 2006 10:45:54 -0000	1.4.2.4
+++ serials/serials-recieve.pl	5 Dec 2006 11:35:32 -0000	1.4.2.5
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: serials-recieve.pl,v 1.4.2.4 2006/11/21 10:45:54 toins Exp $
+# $Id: serials-recieve.pl,v 1.4.2.5 2006/12/05 11:35:32 toins Exp $
 
 =head1 NAME
 
@@ -203,7 +203,7 @@
 my ($totalissues, at serialslist) = GetSerials($subscriptionid);
 
 if (C4::Context->preference("serialsadditems")){
-    my $fwk=MARCfind_frameworkcode($dbh,$subscription->{biblionumber});
+    my $fwk=MARCfind_frameworkcode($subscription->{biblionumber});
 
     my $branches = GetBranches;
     my @branchloop;

Index: tools/export.pl
===================================================================
RCS file: /sources/koha/koha/tools/export.pl,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- tools/export.pl	17 Nov 2006 13:19:00 -0000	1.1.2.3
+++ tools/export.pl	5 Dec 2006 11:35:32 -0000	1.1.2.4
@@ -16,7 +16,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: export.pl,v 1.1.2.3 2006/11/17 13:19:00 tipaul Exp $
+# $Id: export.pl,v 1.1.2.4 2006/12/05 11:35:32 toins Exp $
 
 use HTML::Template;
 use strict;
@@ -79,7 +79,7 @@
 	my $req=$dbh->prepare($strsth);
 	$req->execute;
 	while (my ($bibid) = $req->fetchrow) {
-		my $record = MARCgetbiblio($dbh,$bibid);
+        my $record = GetMarcBiblio($bibid);
 
 		print $record->as_usmarc();
 	}





More information about the Koha-cvs mailing list