[Koha-cvs] CVS: koha/acqui.simple marcimport.pl,1.6.2.8,1.6.2.9

Alan Millar amillar at users.sourceforge.net
Mon Jun 3 21:16:05 CEST 2002


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

Modified Files:
      Tag: rel-1-2
	marcimport.pl 
Log Message:
Split z3950 search results into subroutines

Index: marcimport.pl
===================================================================
RCS file: /cvsroot/koha/koha/acqui.simple/marcimport.pl,v
retrieving revision 1.6.2.8
retrieving revision 1.6.2.9
diff -C2 -r1.6.2.8 -r1.6.2.9
*** marcimport.pl	2 Jun 2002 15:16:08 -0000	1.6.2.8
--- marcimport.pl	3 Jun 2002 19:16:02 -0000	1.6.2.9
***************
*** 129,133 ****
--- 129,156 ----
  
  if ($file) {
+     ProcessFile($dbh,$input);
+ } else {
+ 
+ SWITCH:
+     {
+ 	if ($menu eq 'z3950') { z3950menu($dbh,$input); last SWITCH; }
+ 	if ($menu eq 'uploadmarc') { uploadmarc(); last SWITCH; }
+ 	if ($menu eq 'manual') { manual(); last SWITCH; }
+ 	mainmenu();
+     }
+ 
+ }
+ print endmenu();
+ print endpage();
+ 
+ 
+ sub ProcessFile {
      # A MARC file has been specified; process it for review form
+ 
+     my (
+ 	$dbh,
+ 	$input,
+     )=@_;
+ 
      my $sth;
      print "<a href=$ENV{'SCRIPT_NAME'}>Main Menu</a><hr>\n";
***************
*** 136,139 ****
--- 159,164 ----
      my $qlccn=$input->param('lccn');
      my $qcontrolnumber=$input->param('controlnumber');
+ 
+     # See if a particular result record was specified
      if ($qisbn || $qissn || $qlccn || $qcontrolnumber) {
  	print "<a href=$ENV{'SCRIPT_NAME'}>New File</a><hr>\n";
***************
*** 470,473 ****
--- 495,512 ----
  	} # foreach record
      } else {
+ 
+ 	ListSearchResults($dbh,$input);
+     } # if
+ } # sub ProcessFile
+ 
+ sub ListSearchResults {
+     #use strict;
+ 
+     my (
+ 	$dbh,
+ 	$input,
+     )=@_;
+ 
+         # No result record specified, list records
  	#open (F, "$file");
  	#my $data=<F>;
***************
*** 475,488 ****
  	my $name;
  	my $z3950=0;
  	if ($file=~/Z-(\d+)/) {
  	    print << "EOF";
! <center>
! <p>
! <a href=$ENV{'SCRIPT_NAME'}?menu=$menu>Select a New File</a>
! <p>
! <table border=0 cellpadding=10 cellspacing=0>
! <tr><th bgcolor=black><font color=white>Select a Record to Import</font></th></tr>
! <tr><td bgcolor=#dddddd>
  EOF
  	    my $id=$1;
  	    my $sth=$dbh->prepare("select servers from z3950queue where id=$id");
--- 514,542 ----
  	my $name;
  	my $z3950=0;
+ 	my $recordsource;
+ 
+ 	# File can be results of z3950 search or uploaded MARC data
+ 
+ 	# if z3950 results
  	if ($file=~/Z-(\d+)/) {
+ 	    $recordsource='';
+ 	} else {
+ 	    my $sth=$dbh->prepare("select marc,name from uploadedmarc where id=$file");
+ 	    $sth->execute;
+ 	    ($data, $name) = $sth->fetchrow;
+ 	    $recordsource="from $name";
+ 	}
  	    print << "EOF";
! 	<center>
! 	<p>
! 	<a href=$ENV{'SCRIPT_NAME'}?menu=$menu>Select a New File</a>
! 	<p>
! 	<table border=0 cellpadding=10 cellspacing=0>
! 	<tr><th bgcolor=black>
! 	  <font color=white>Select a Record to Import $recordsource</font>
! 	</th></tr>
! 	<tr><td bgcolor=#dddddd>
  EOF
+ 	if ($file=~/Z-(\d+)/) {
  	    my $id=$1;
  	    my $sth=$dbh->prepare("select servers from z3950queue where id=$id");
***************
*** 556,563 ****
  		    my @records=split(/$splitchar/, $data);
  		    $data='';
  		    for ($i=$startrecord; $i<$startrecord+10; $i++) {
  			$data.=$records[$i].$splitchar;
  		    }
! 		    @records=parsemarcdata($data);
  		    my $counter=0;
  		    foreach $record (@records) {
--- 610,619 ----
  		    my @records=split(/$splitchar/, $data);
  		    $data='';
+ 		    my $i;
+ 		    my $record;
  		    for ($i=$startrecord; $i<$startrecord+10; $i++) {
  			$data.=$records[$i].$splitchar;
  		    }
! 		    @records=parsemarcfileformat($data);
  		    my $counter=0;
  		    foreach $record (@records) {
***************
*** 637,654 ****
  	    print "<hr>It took $elapsed seconds to process this page.\n";
  	} else {
- 	    my $sth=$dbh->prepare("select marc,name from uploadedmarc where id=$file");
- 	    $sth->execute;
- 	    ($data, $name) = $sth->fetchrow;
- 	    print << "EOF";
- <center>
- <p>
- <a href=$ENV{'SCRIPT_NAME'}?menu=$menu>Select a New File</a>
- <p>
- <table border=0 cellpadding=10 cellspacing=0>
- <tr><th bgcolor=black><font color=white>Select a Record to Import<br>from $name</font></th></tr>
- <tr><td bgcolor=#dddddd>
- EOF
  	    
! 	    my @records=parsemarcdata($data);
  	    foreach $record (@records) {
  		my ($lccn, $isbn, $issn, $dewey, $author, $title, $place, $publisher, $publicationyear, $volume, $number, @subjects, $notes, $controlnumber);
--- 693,699 ----
  	    print "<hr>It took $elapsed seconds to process this page.\n";
  	} else {
  	    
! 	    my @records=parsemarcfileformat($data);
! 	    $counter=$#records+1;
  	    foreach $record (@records) {
  		my ($lccn, $isbn, $issn, $dewey, $author, $title, $place, $publisher, $publicationyear, $volume, $number, @subjects, $notes, $controlnumber);
***************
*** 718,735 ****
  	}
  	print "</td></tr></table>\n";
!     }
! } else {
! 
! SWITCH:
!     {
! 	if ($menu eq 'z3950') { z3950menu($dbh,$input); last SWITCH; }
! 	if ($menu eq 'uploadmarc') { uploadmarc(); last SWITCH; }
! 	if ($menu eq 'manual') { manual(); last SWITCH; }
! 	mainmenu();
!     }
! 
! }
! print endmenu();
! print endpage();
  
  
--- 763,767 ----
  	}
  	print "</td></tr></table>\n";
! } # sub ListSearchResults
  
  
***************
*** 931,937 ****
  }
  
! sub parsemarcdata {
      my $data=shift;
      my $splitchar=chr(29);
      my @records;
      my $record;
--- 963,973 ----
  }
  
! sub parsemarcfileformat {
!     #use strict;
      my $data=shift;
      my $splitchar=chr(29);
+     my $splitchar2=chr(30);
+     my $splitchar3=chr(31);
+     my $debug=1;
      my @records;
      my $record;
***************
*** 940,944 ****
  	#print "<tr><td>Leader:</td><td>$leader</td></tr>\n";
  	$record=substr($record,24);
- 	my $splitchar2=chr(30);
  	my $directory=0;
  	my $tagcounter=0;
--- 976,979 ----
***************
*** 948,956 ****
  	foreach $field (split(/$splitchar2/, $record)) {
  	    my %field;
! 	    ($color eq $lc1) ? ($color=$lc2) : ($color=$lc1);
  	    unless ($directory) {
  		$directory=$field;
  		my $itemcounter=1;
! 		$counter=0;
  		while ($item=substr($directory,0,12)) {
  		    $tag=substr($directory,0,3);
--- 983,995 ----
  	foreach $field (split(/$splitchar2/, $record)) {
  	    my %field;
! 	    my $tag;
! 	    my $indicator;
  	    unless ($directory) {
  		$directory=$field;
  		my $itemcounter=1;
! 		my $counter2=0;
! 		my $item;
! 		my $length;
! 		my $start;
  		while ($item=substr($directory,0,12)) {
  		    $tag=substr($directory,0,3);
***************
*** 958,963 ****
  		    $start=substr($directory,7,6);
  		    $directory=substr($directory,12);
! 		    $tag{$counter}=$tag;
! 		    $counter++;
  		}
  		$directory=1;
--- 997,1002 ----
  		    $start=substr($directory,7,6);
  		    $directory=substr($directory,12);
! 		    $tag{$counter2}=$tag;
! 		    $counter2++;
  		}
  		$directory=1;
***************
*** 967,971 ****
  	    $tagcounter++;
  	    $field{'tag'}=$tag;
- 	    $splitchar3=chr(31);
  	    my @subfields=split(/$splitchar3/, $field);
  	    $indicator=$subfields[0];
--- 1006,1009 ----
***************
*** 974,977 ****
--- 1012,1016 ----
  	    unless ($#subfields==0) {
  		my %subfields;
+ 		my $i;
  		for ($i=1; $i<=$#subfields; $i++) {
  		    my $text=$subfields[$i];
***************
*** 998,1002 ****
  	} # foreach field in record
  	push (@records, \@record);
! 	$counter++;
      }
      print "</pre>" if $debug;
--- 1037,1041 ----
  	} # foreach field in record
  	push (@records, \@record);
! 	# $counter++;
      }
      print "</pre>" if $debug;





More information about the Koha-cvs mailing list