[Koha-cvs] CVS: koha/acqui.simple addbiblio.pl,1.3,1.4 isbnsearch.pl,1.4,1.5 marcimport.pl,1.20,1.21

Paul POULAIN tipaul at users.sourceforge.net
Tue Oct 22 17:50:25 CEST 2002


Update of /cvsroot/koha/koha/acqui.simple
In directory usw-pr-cvs1:/tmp/cvs-serv30797/acqui.simple

Modified Files:
	addbiblio.pl isbnsearch.pl marcimport.pl 
Log Message:
road to 1.3.2 : adding a biblio in MARC format.
seems to work a few.
still to do :
* manage html checks (mandatory subfields...)
* add list of acceptable values (authorities)
* manage ## in MARC format
* manage correctly repeatable fields
and probably a LOT of bugfixes

Index: addbiblio.pl
===================================================================
RCS file: /cvsroot/koha/koha/acqui.simple/addbiblio.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** addbiblio.pl	13 Oct 2002 07:38:29 -0000	1.3
--- addbiblio.pl	22 Oct 2002 15:50:23 -0000	1.4
***************
*** 30,101 ****
  use strict;
  use C4::Output;
  
! 
  my $input = new CGI;
  my $error = $input->param('error');
! 
! print $input->header;
! print startpage();
! print startmenu('acquisitions');
! 
! print << "EOF";
! <FONT SIZE=6><em>Adding a new Biblio</em></FONT><br>
! 
! <table bgcolor="#ffcc00" width="80%" cellpadding="5">
! <tr>
! <td><FONT SIZE=5>Section One: Copyright Information </font></td>
! </tr>
! </table>
! EOF
! 
! if ($error eq "notitle") {
!     print << "EOF";
! <p />
! <center>
! <font color="#FF0000">Please Specify a Title</font>
! </center>
! EOF
! } # if
! 
! print << "EOF";
! <FORM action="savebiblio.pl" method="post">
! <table align="center">
! <tr>
! <td>Title: *</td>
! <td><INPUT name="title" size="40" /></td>
! </tr>
! <tr>
! <td>Subtitle:</td>
! <td><INPUT name="subtitle" size="40" /></td>
! </tr>
! <tr>
! <td>Author:</td>
! <td><INPUT name="author" size="40" /></td>
! </tr>
!     <tr valign="top">
!         <td>Series Title:<br />
!         <i>(if applicable)</i></td>
!         <td><INPUT name="seriestitle" size="40" /></td>
!     </tr>
! <tr>
! <td>Copyright Date:</td>
! <td><INPUT name="copyrightdate" size="40" /></td>
! </tr>
! <tr valign="top">
! <td>Abstract:</td>
! <td><textarea cols="30" rows="6" name="abstract"></textarea></td>
! </tr>
!     <tr valign="top">
!         <td>Notes:</td>
!         <td><textarea cols="30" rows="6" name="notes"></textarea></td>
!     </tr>
! <tr valign="top">
! <td colspan="2"><center><input type="submit" value="Submit"></center></td>
! </tr>
! </table>
! </FORM>
! * Required
! EOF
! 
! print endmenu();
! print endpage();
--- 30,263 ----
  use strict;
  use C4::Output;
+ use C4::Biblio;
+ use C4::Context;
+ use HTML::Template;
+ use MARC::File::USMARC;
+ 
+ sub find_value {
+ 	my ($tagfield,$subfield,$record) = @_;
+ 	my $result;
+ 	foreach my $field ($record->field($tagfield)) {
+ 		my @subfields = $field->subfields();
+ 		foreach my $subfield (@subfields) {
+ 			if (@$subfield[0] eq $subfield) {
+ 				$result .= @$subfield[1];
+ 			}
+ 		}
+ 	}
+ }
+ 
+ sub MARCfindbreeding {
+ 	my ($dbh,$isbn) = @_;
+ 	my $sth = $dbh->prepare("select file,marc from marc_breeding where isbn=?");
+ 	$sth->execute($isbn);
+ 	my ($file,$marc) = $sth->fetchrow;
+ 	if ($marc) {
+ 		my $record = MARC::File::USMARC::decode($marc);
+ 		if (ref($record) eq undef) {
+ 			warn "not a MARC record !";
+ 			return -1;
+ 		} else {
+ 			return $record;
+ 		}
+ 	}
+ 	warn "not MARC";
+ 	return -1;
  
! }
  my $input = new CGI;
  my $error = $input->param('error');
! my $oldbiblionumber=$input->param('bib'); # if bib exists, it's a modif, not a new biblio.
! my $isbn = $input->param('isbn');
! my $op = $input->param('op');
! my $dbh = C4::Context->dbh;
! my $bibid;
! if ($oldbiblionumber) {;
! 	$bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber)
! }else {
! 	$bibid = $input->param('bibid');
! }
! my $template;
! 
! my $tagslib = &MARCgettagslib($dbh,1);
! 
! my $record = MARCgetbiblio($dbh,$bibid) if ($oldbiblionumber);
! #my $record = MARCfindbreeding($dbh,$isbn) if ($isbn);
! 
! #------------------------------------------------------------------------------------------------------------------------------
! if ($op eq "addbiblio") {
! #------------------------------------------------------------------------------------------------------------------------------
! 	# rebuild
! 	my @tags = $input->param('tag[]');
! 	my @subfields = $input->param('subfield[]');
! 	my @values = $input->param('value[]');
! 	my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values);
! # MARC::Record builded => now, record in DB
! 	my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record);
! # build item screen. There is no item for instance.
! 	my @loop_data =();
! 	my $i=0;
! 	foreach my $tag (keys %{$tagslib}) {
! 		my $previous_tag = '';
! 	# loop through each subfield
! 		foreach my $subfield (keys %{$tagslib->{$tag}}) {
! 			next if ($subfield eq 'lib');
! 			next if ($subfield eq 'tab');
! 			next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "10");
! 			my %subfield_data;
! 			$subfield_data{tag}=$tag;
! 			$subfield_data{subfield}=$subfield;
! 			$subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
! 			$subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
! 			$subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
! 			$subfield_data{marc_value}="<input type=\"text\" name=\"value[]\">";
! 			push(@loop_data, \%subfield_data);
! 			$i++
! 		}
! 	}
! 	$template = gettemplate("acqui.simple/addbiblio2.tmpl");
! 	$template->param(bibid => $bibid,
! 							item => \@loop_data);
! #------------------------------------------------------------------------------------------------------------------------------
! } elsif ($op eq "additem") {
! #------------------------------------------------------------------------------------------------------------------------------
! 	my @tags = $input->param('tag[]');
! 	my @subfields = $input->param('subfield[]');
! 	my @values = $input->param('value[]');
! 	my $record = MARChtml2marc($dbh,\@tags,\@subfields,\@values);
! 	my ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewitem($dbh,$record,$bibid);
! 	# now, build existiing item list
! 	my $temp = MARCgetbiblio($dbh,$bibid);
! 	my @fields = $temp->fields();
! 	my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
! 	my @big_array;
! 	foreach my $field (@fields) {
! 		my @subf=$field->subfields;
! 		my %this_row;
! 	# loop through each subfield
! 		for my $i (0..$#subf) {
! 			next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  ne 10);
! 			$witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
! 			$this_row{$subf[$i][0]} =$subf[$i][1];
! 		}
! 		if (%this_row) {
! 			push(@big_array, \%this_row);
! 		}
! 	}
! 	#fill big_row with missing datas
! 	foreach my $subfield_code  (keys(%witness)) {
! 		for (my $i=0;$i<=$#big_array;$i++) {
! 			$big_array[$i]{$subfield_code}="&nbsp;" unless ($big_array[$i]{$subfield_code});
! 		}
! 	}
! 	# now, construct template !
! 	my @item_value_loop;
! 	my @header_value_loop;
! 	for (my $i=0;$i<=$#big_array; $i++) {
! 		my $items_data;
! 		foreach my $subfield_code (keys(%witness)) {
! 			$items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
! 		}
! 		my %row_data;
! 		$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};
! 		push(@header_value_loop, \%header_value);
! 	}
! 
! # next item form
! 	my @loop_data =();
! 	my $i=0;
! 	foreach my $tag (keys %{$tagslib}) {
! 		my $previous_tag = '';
! 	# loop through each subfield
! 		foreach my $subfield (keys %{$tagslib->{$tag}}) {
! 			next if ($subfield eq 'lib');
! 			next if ($subfield eq 'tab');
! 			next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "10");
! 			my %subfield_data;
! 			$subfield_data{tag}=$tag;
! 			$subfield_data{subfield}=$subfield;
! 			$subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
! 			$subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
! 			$subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
! 			$subfield_data{marc_value}="<input type=\"text\" name=\"value[]\">";
! 			push(@loop_data, \%subfield_data);
! 			$i++
! 		}
! 	}
! 	$template = gettemplate("acqui.simple/addbiblio2.tmpl");
! 	$template->param(item_loop => \@item_value_loop,
! 							item_header_loop => \@header_value_loop,
! 							bibid => $bibid,
! 							item => \@loop_data);
! #------------------------------------------------------------------------------------------------------------------------------
! } else {
! #------------------------------------------------------------------------------------------------------------------------------
! 	$template = gettemplate("acqui.simple/addbiblio.tmpl");
! 	# fill arrays
! 	my @loop_data =();
! 	my $tag;
! 	# loop through each tab 0 through 9
! 	for (my $tabloop = 0; $tabloop<=9;$tabloop++) {
! 	# loop through each tag
! 	#	my @fields = $record->fields();
! 		my @loop_data =();
! 		foreach my $tag (keys %{$tagslib}) {
! 			my $previous_tag = '';
! 			my @subfields_data;
! 	# loop through each subfield
! 			foreach my $subfield (keys %{$tagslib->{$tag}}) {
! 				next if ($subfield eq 'lib');
! 				next if ($subfield eq 'tab');
! 				next if ($tagslib->{$tag}->{$subfield}->{tab}  ne $tabloop);
! 				my %subfield_data;
! 				$subfield_data{tag}=$tag;
! 				$subfield_data{subfield}=$subfield;
! 				$subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
! 				$subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
! 				$subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
! 				if ($record ne -1) {
! 					my $value ="";# &find_value($tag,$subfield,$record);
! 					$subfield_data{marc_value}="<input type=\"text\" name=\"value[]\" value=\"$value\">";
! 				} else {
! 					$subfield_data{marc_value}="<input type=\"text\" name=\"value[]\">";
! 				}
! 				push(@subfields_data, \%subfield_data);
! 			}
! 			if ($#subfields_data>=0) {
! 				my %tag_data;
! 				$tag_data{tag}=$tag.' -'. $tagslib->{$tag}->{lib};
! 				$tag_data{subfield} = \@subfields_data;
! 				push (@loop_data, \%tag_data);
! 			}
! 		}
! 		$template->param($tabloop."XX" =>\@loop_data);
! 	}
! 	# now, build hidden datas => we store everything, even if we show only requested subfields.
! 	my @loop_data =();
! 	my $i=0;
! 	foreach my $tag (keys %{$tagslib}) {
! 		my $previous_tag = '';
! 	# loop through each subfield
! 		foreach my $subfield (keys %{$tagslib->{$tag}}) {
! 			next if ($subfield eq 'lib');
! 			next if ($subfield eq 'tab');
! 			next if ($tagslib->{$tag}->{$subfield}->{'tab'}  ne "-1");
! 			my %subfield_data;
! 			$subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
! 			$subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory};
! 			$subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable};
! 			$subfield_data{marc_value}="<input type=\"hidden\" name=\"value[]\">";
! 			push(@loop_data, \%subfield_data);
! 			$i++
! 		}
! 	}
! 	$template->param(
! 							biblionumber => $oldbiblionumber,
! 							bibid => $bibid);
! }
! print "Content-Type: text/html\n\n", $template->output;

Index: isbnsearch.pl
===================================================================
RCS file: /cvsroot/koha/koha/acqui.simple/isbnsearch.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** isbnsearch.pl	14 Aug 2002 18:12:52 -0000	1.4
--- isbnsearch.pl	22 Oct 2002 15:50:23 -0000	1.5
***************
*** 25,28 ****
--- 25,29 ----
  use C4::Search;
  use C4::Output;
+ use HTML::Template;
  
  my $input      = new CGI;
***************
*** 34,125 ****
  my $count;
  my @results;
! 
  if (! $isbn) {
!     print $input->redirect('addbooks.pl');
  } else {
!     if (! $offset) {
! 	$offset     = 0;
! 	$showoffset = 1;
!     };
!     if (! $num) { $num = 10 };
!     ($count, @results) = isbnsearch($isbn);
! 
!     if ($count < ($offset + $num)) {
!         $total = $count;
!     } else {
! 	$total = $offset + $num;
!     } # else
! 
!     print $input->header;
!     print startpage();
!     print startmenu('acquisitions');
! 
!     print << "EOF";
! <font size="6"><em>Biblio Search Results</em></font><br />
! <CENTER>
! You searched on <b>ISBN $isbn,</b> $count results found <br />
! Results $showoffset to $total displayed
! <div align="right">
! <h2><a href="addbiblio.pl">Add New Biblio</a></h2>
! </div>
! <p />
! <table border="0" cellspacing="0" cellpadding="5">
! <tr valign=top bgcolor=#cccc99>
! <td background="/images/background-mem.gif"><b>TITLE</b></td>
! <td background="/images/background-mem.gif"><b>AUTHOR</b></td>
! <td background="/images/background-mem.gif"><b>&copy;</b></td>
! </tr>
! EOF
  
!     for (my $i = $offset; $i < $total; $i++) {
! 	if ($i % 2) {
! 	    print << "EOF";
! <tr valign="top" bgcolor="#ffffcc">
! EOF
  	} else {
! 	    print << "EOF";
! <tr valign="top" bgcolor="#ffffff">
! EOF
  	} # else
  
! 	print << "EOF";
! <td><a href="additem.pl?biblionumber=$results[$i]->{'biblionumber'}">$results[$i]->{'title'}</a></td>
! <td><a href="additem.pl?biblionumber=$results[$i]->{'biblionumber'}">$results[$i]->{'author'}</a></td>
! <td>$results[$i]->{'copyrightdate'}</td>
! </tr>
! EOF
!     } # for
! 
!     print << "EOF";
! <tr valign=top bgcolor=#cccc99>
! <td background="/images/background-mem.gif">&nbsp;</td>
! <td background="/images/background-mem.gif">&nbsp;</td>
! <td background="/images/background-mem.gif">&nbsp;</td>
! </tr>
! </table>
! <br />
! EOF
! 
!     for (my $i = 0; ($i * $num) < $count; $i++) {
! 	my $newoffset = $i * $num;
! 	my $shownumber = $i + 1;
! 	print << "EOF";
! <a href="isbnsearch.pl?isbn=$isbn&offset=$newoffset&num=$num">$shownumber</a>
! EOF
!     } # for
! 
!     print << "EOF";
! <p />
! Results per page:
! <a href="isbnsearch.pl?isbn=$isbn&offset=$offset&num=5">5</a>
! <a href="isbnsearch.pl?isbn=$isbn&offset=$offset&num=10">10</a>
! <a href="isbnsearch.pl?isbn=$isbn&offset=$offset&num=20">20</a>
! <a href="isbnsearch.pl?isbn=$isbn&offset=$offset&num=50">50</a>
! </CENTER>
! <br clear="all" />
! <p>&nbsp;</p>
! EOF
  
!     print endmenu();
!     print endpage();
  } # else
--- 35,86 ----
  my $count;
  my @results;
! my $template = gettemplate("acqui.simple/isbnsearch.tmpl");
  if (! $isbn) {
! 	print $input->redirect('addbooks.pl');
  } else {
! 	if (! $offset) {
! 		$offset     = 0;
! 		$showoffset = 1;
! 	};
! 	if (! $num) { $num = 10 };
! 	($count, @results) = isbnsearch($isbn);
  
! 	if ($count < ($offset + $num)) {
! 		$total = $count;
  	} else {
! 		$total = $offset + $num;
  	} # else
  
! 	my @loop_data = ();
! 	my $toggle;
! 	for (my $i = $offset; $i < $total; $i++) {
! 		if ($i % 2) {
! 			$toggle="#ffffcc";
! 	  	} else {
! 			$toggle="white";
! 	  	}
! 		my %row_data;  # get a fresh hash for the row data
! 		$row_data{toggle} = $toggle;
! 		$row_data{biblionumber} =$results[$i]->{'biblionumber'};
! 		$row_data{title} = $results[$i]->{'title'};
! 		$row_data{author} = $results[$i]->{'author'};
! 		$row_data{copyrightdate} = $results[$i]->{'copyrightdate'};
! 		push(@loop_data, \%row_data);
! 	}
! 	my @loop_links = ();
! 	for (my $i = 0; ($i * $num) < $count; $i++) {
! 		my %row_data;
! 		$row_data{newoffset} = $i * $num;
! 		$row_data{shownumber} = $i + 1;
! 		$row_data{num} = $num;
! 		push (@loop_links,\%row_data);
! 	} # for
! 	$template->param(isbn => $isbn,
! 							showoffset => $showoffset,
! 							total => $total,
! 							offset => $offset,
! 							loop => \@loop_data,
! 							loop_links => \@loop_links);
  
! 	print "Content-Type: text/html\n\n", $template->output;
  } # else

Index: marcimport.pl
===================================================================
RCS file: /cvsroot/koha/koha/acqui.simple/marcimport.pl,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** marcimport.pl	16 Oct 2002 12:46:19 -0000	1.20
--- marcimport.pl	22 Oct 2002 15:50:23 -0000	1.21
***************
*** 37,41 ****
  use C4::Context;
  #use C4::Database;
! use C4::Acquisitions;
  use C4::Output;
  use C4::Input;
--- 37,41 ----
  use C4::Context;
  #use C4::Database;
! #use C4::Acquisitions;
  use C4::Output;
  use C4::Input;
***************
*** 118,121 ****
--- 118,124 ----
  					}
  					if (!$breedingresult || $overwrite_biblio) {
+ 						if ($oldbiblio->{isbn} eq '0025003402') {
+ 							warn "IMPORT => $marcarray[$i]\x1D')";
+ 						}
  						$insertsql ->execute($filename,$oldbiblio->{isbn}.$oldbiblio->{issn},$marcarray[$i]."\x1D')");
  						$imported++;
***************
*** 794,797 ****
--- 797,810 ----
  # log cleared, as marcimport is (almost) rewritten from scratch.
  # $Log$
+ # Revision 1.21  2002/10/22 15:50:23  tipaul
+ # road to 1.3.2 : adding a biblio in MARC format.
+ # seems to work a few.
+ # still to do :
+ # * manage html checks (mandatory subfields...)
+ # * add list of acceptable values (authorities)
+ # * manage ## in MARC format
+ # * manage correctly repeatable fields
+ # and probably a LOT of bugfixes
+ #
  # Revision 1.20  2002/10/16 12:46:19  arensb
  # Added a FIXME comment.





More information about the Koha-cvs mailing list