From 2745c7b2182e585dc8f7a08d6498bfb714b49cbe Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 15 Oct 2002 10:14:43 +0000 Subject: [PATCH] road to 1.3.2. Full rewrite of marcimport.pl. The acquisition system in MARC version will work like this : * marcimport will put marc records into a "breeding farm" table. * when the user want to add a biblio, he enters first the ISBN/ISSN of the biblio. koha searches into breeding farm and if the record exists, it is shown to the user to help him adding the biblio. When the biblio is added, it's deleted from the breeding farm. This commit : * modify acqui.simple home page (addbooks.pl) * adds import into breeding farm Please note that : * z3950 functionnality is dropped from "marcimport" will be added somewhere else. * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic --- acqui.simple/addbooks.pl | 108 +---- acqui.simple/marcimport.pl | 445 ++++-------------- .../default/en/acqui.simple/addbooks.tmpl | 96 ++++ .../default/en/acqui.simple/marcimport.tmpl | 52 ++ 4 files changed, 243 insertions(+), 458 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbooks.tmpl create mode 100644 koha-tmpl/intranet-tmpl/default/en/acqui.simple/marcimport.tmpl diff --git a/acqui.simple/addbooks.pl b/acqui.simple/addbooks.pl index f212496a6a..c1bcedfa92 100755 --- a/acqui.simple/addbooks.pl +++ b/acqui.simple/addbooks.pl @@ -38,107 +38,11 @@ use strict; use C4::Catalogue; use C4::Biblio; use C4::Output; -use C4::Circulation::Circ2; +use HTML::Template; -my $input = new CGI; -my $error = $input->param('error'); -my $success = $input->param('biblioitem'); +my $query = new CGI; -print $input->header; -print startpage(); -print startmenu('acquisitions'); - -&searchscreen(); -print endmenu('acquisitions'); -print endpage(); - - -sub searchscreen { - print << "EOF"; -Adding new items to the Library Inventory -

-EOF - - if ($error eq "notfound") { - print << "EOF"; -No items found -

-EOF - } elsif ($success eq "added") { - print << "EOF"; -Website Biblioitem Added -

-EOF - } # elsif - - print << "EOF"; - - - - -
To add a new item, scan or type the ISBN number:
- - - - - - - - - - - - - - - - -
Keyword:
ISBN:
-

-


-

- - - - -
Tools for importing MARC records into Koha
-
-

-
-

- - - - -
Add New Website
-

- - - - - - -
Keyword:
-
-

- - - - -
Help
-Koha stores data in three sections -

-

Biblio

-The first section records bibliographic data such as title, author and copyright for a particular work. -

-

Group

-The second records bibliographic data for a particular publication of that work, such as ISBN number, physical description, publisher information, etc -

-

Item

-The third section holds specific item information, such as the bar code number -

-EOF -} # sub searchscreen +my $error = $query->param('error'); +my $success = $query->param('biblioitem'); +my $template= gettemplate("acqui.simple/addbooks.tmpl"); +print "Content-Type: text/html\n\n",$template->output; \ No newline at end of file diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index 92f75f417e..1f421694b3 100755 --- a/acqui.simple/marcimport.pl +++ b/acqui.simple/marcimport.pl @@ -35,13 +35,13 @@ use DBI; # Koha modules used use C4::Context; -use C4::Database; +#use C4::Database; use C4::Acquisitions; use C4::Output; use C4::Input; use C4::Biblio; -use C4::SimpleMarc; -use C4::Z3950; +#use C4::SimpleMarc; +#use C4::Z3950; use MARC::File::USMARC; use HTML::Template; @@ -64,59 +64,82 @@ my $userid=$ENV{'REMOTE_USER'}; my $input = new CGI; my $dbh = C4::Context->dbh; -#------------- -# Display output -#print $input->header; -#print startpage(); -#print startmenu('acquisitions'); - -#------------- -# Process input parameters - -my $file=$input->param('file'); -my $menu = $input->param('menu'); - -# -# -# TODO : parameter decoding and function call is quite dirty. -# should be rewritten... -# -# -if ($input->param('z3950queue')) { - AcceptZ3950Queue($dbh,$input); -} - -if ($input->param('uploadmarc')) { - AcceptMarcUpload($dbh,$input) -} - -if ($input->param('insertnewrecord')) { - # Add biblio item, and set up menu for adding item copies - my ($biblionumber,$biblioitemnumber)=AcceptBiblioitem($dbh,$input); - exit; -} +my $uploadmarc=$input->param('uploadmarc'); +my $overwrite_biblio = $input->param('overwrite_biblio'); +my $filename = $input->param('filename'); + +my $template = gettemplate("acqui.simple/marcimport.tmpl"); +$template->param(SCRIPT_NAME => $ENV{'SCRIPT_NAME'}, + uploadmarc => $uploadmarc); +if ($uploadmarc && length($uploadmarc)>0) { + my $marcrecord=''; + while (<$uploadmarc>) { + $marcrecord.=$_; + } + my @marcarray = split /\x1D/, $marcrecord; + my $dbh = C4::Context->dbh; + my $searchisbn = $dbh->prepare("select biblioitemnumber from biblioitems where isbn=?"); + my $searchissn = $dbh->prepare("select biblioitemnumber from biblioitems where issn=?"); + my $searchbreeding = $dbh->prepare("select isbn from marc_breeding where isbn=?"); + my $insertsql = $dbh->prepare("replace into marc_breeding (file,isbn,marc) values(?,?,?)"); + # fields used for import results + my $imported=0; + my $alreadyindb = 0; + my $alreadyinfarm = 0; + my $notmarcrecord = 0; + for (my $i=0;$i<=$#marcarray;$i++) { + my $marcrecord = MARC::File::USMARC::decode($marcarray[$i]."\x1D"); + if (ref($marcrecord) eq undef) { + $notmarcrecord++; + } else { + my $oldbiblio = MARCmarc2koha($dbh,$marcrecord); + # if isbn found and biblio does not exist, add it. If isbn found and biblio exists, overwrite or ignore depending on user choice + if ($oldbiblio->{isbn} || $oldbiblio->{issn}) { + # search if biblio exists + my $biblioitemnumber; + if ($oldbiblio->{isbn}) { + $searchisbn->execute($oldbiblio->{isbn}); + ($biblioitemnumber) = $searchisbn->fetchrow; + } else { + $searchissn->execute($oldbiblio->{issn}); + ($biblioitemnumber) = $searchissn->fetchrow; + } + if ($biblioitemnumber) { + $alreadyindb++; + } else { + # search in breeding farm + my $breedingresult; + if ($oldbiblio->{isbn}) { + $searchbreeding->execute($oldbiblio->{isbn}); + ($breedingresult) = $searchbreeding->fetchrow; + } else { + $searchbreeding->execute($oldbiblio->{issn}); + ($breedingresult) = $searchbreeding->fetchrow; + } + if (!$breedingresult || $overwrite_biblio) { + $insertsql ->execute($filename,$oldbiblio->{isbn}.$oldbiblio->{issn},$marcarray[$i]."\x1D')"); + $imported++; + } else { + $alreadyinfarm++; + } + } + } else { + $notmarcrecord++; + } + } + } + $template->param(imported => $imported, + alreadyindb => $alreadyindb, + alreadyinfarm => $alreadyinfarm, + notmarcrecord => $notmarcrecord, + total => $imported+$alreadyindb+$alreadyinfarm+$notmarcrecord, + ); -if ($input->param('newitem')) { - # Add item copy - &AcceptItemCopy($dbh,$input); - exit; -} # if newitem - - -if ($file) { - ProcessFile($dbh,$input); -} else { - SWITCH: - { - if ($menu eq 'z3950') { z3950menu($dbh,$input); last SWITCH; } - if ($menu eq 'uploadmarc') { uploadmarc($dbh); last SWITCH; } - if ($menu eq 'manual') { manual(); last SWITCH; } - mainmenu(); - } } -#print endmenu(); -#print endpage(); +print "Content-Type: text/html\n\n",$template->output; +my $menu; +my $file; # Process a MARC file : show list of records, of 1 record detail, if numrecord exists sub ProcessFile { @@ -124,7 +147,6 @@ sub ProcessFile { use strict; # Input params my ( - $dbh, # FIXME - Unused argument $input, )=@_; @@ -136,8 +158,6 @@ sub ProcessFile { my $debug=0; - $dbh = C4::Context->dbh; - # See if a particular result item was specified my $numrecord = $input->param('numrecord'); if ($numrecord) { @@ -172,8 +192,7 @@ sub ProcessRecord { my $file=MARC::File::USMARC->indata ($data); my $oldkoha; - # FIXME - This "==" should be "=", right? - for (my $i==1;$i<$numrecord;$i++) { + for (my $i=1;$i<$numrecord;$i++) { $record = $file->next; } if ($record) { @@ -423,162 +442,6 @@ sub ResultRecordLink { #--------------------------------- -sub z3950menu { - use strict; - my ( - $dbh, # FIXME - Unused argument - $input, - )=@_; - - my ( - $sth, $sti, - $processing, - $realenddate, - $totalrecords, - $elapsed, - $elapsedtime, - $resultstatus, $statuscolor, - $id, $term, $type, $done, - $startdate, $enddate, $servers, - $record,$bib,$title, - ); - - $dbh = C4::Context->dbh; - - # FIXME - This print statement doesn't belong here. It's just here - # so the script will display SOMEthing. But this section really - # ought to be properly templated. - print < - -EOT - - print "Main Menu


\n"; - print "\n"; - # End of query listing - - #------------------------------ - # Search input form - print "
\n"; - print "

Results of Z39.50 searches

\n"; - print "Refresh
\n" . - "
    \n"; - - # Check queued queries - $sth=$dbh->prepare("select id,term,type,done, - startdate,enddate,servers - from z3950queue - order by id desc - limit 20 "); - $sth->execute; - while ( ($id, $term, $type, $done, - $startdate, $enddate, $servers) = $sth->fetchrow) { - $type=uc($type); - $term=~s//>/g; - - $title=""; - # See if query produced results - $sti=$dbh->prepare("select id,server,startdate,enddate,numrecords,results - from z3950results - where queryid=?"); - $sti->execute($id); - if ($sti->rows) { - $processing=0; - $realenddate=0; - $totalrecords=0; - while (my ($r_id,$r_server,$r_startdate,$r_enddate,$r_numrecords,$r_marcdata) - = $sti->fetchrow) { - if ($r_enddate==0) { - # It hasn't finished yet - $processing=1; - } else { - # It finished, see how long it took. - if ($r_enddate>$realenddate) { - $realenddate=$r_enddate; - } - # Snag any title from the results if there were any - if ( ! $title && $r_marcdata ) { - ($record)=parsemarcfileformat($r_marcdata); - $bib=extractmarcfields($record); - if ( $bib->{title} ) { $title=$bib->{title} }; - } # if no title yet - } # if finished - - $totalrecords+=$r_numrecords; - } # while results - - if ($processing) { - $elapsed=time()-$startdate; - $resultstatus="Processing..."; - $statuscolor="red"; - } else { - $elapsed=$realenddate-$startdate; - $resultstatus="Done."; - $statuscolor="black"; - } - - if ($elapsed>60) { - $elapsedtime=sprintf "%d minutes",($elapsed/60); - } else { - $elapsedtime=sprintf "%d seconds",$elapsed; - } - if ($totalrecords) { - $totalrecords="$totalrecords found."; - } else { - $totalrecords=''; - } - print "
  • ". - "$type=$term" . - "$resultstatus $totalrecords " . - "($elapsedtime) $title
    \n"; - } else { - print "
  • - $type=$term Pending
    \n"; - } # if results done - } # while queries - print "
\n"; - - my $sth=$dbh->prepare("select id,name,checked - from z3950servers - order by rank"); - # FIXME - There's already a $sth in this function. - $sth->execute; - my $serverlist=''; - while (my ($id, $name, $checked) = $sth->fetchrow) { - ($checked) ? ($checked='checked') : ($checked=''); - $serverlist.=" $name
\n"; - } - $serverlist.=" \n"; - - my $rand=rand(1000000000); -print << "EOF"; -
- - -

- - - - - - - - -
Search for MARC records
Query Term
-  ISBN -  LCCN
-  Author -  Title -  Keyword
$serverlist
- -

-EOF - print "
\n"; -} # sub z3950menu -#--------------------------------- sub uploadmarc { use strict; @@ -615,75 +478,6 @@ sub mainmenu { print "Content-Type: text/html\n\n", $template->output; } # sub mainmenu -#---------------------------- -# Accept form results to add query to z3950 queue -sub AcceptZ3950Queue { - use strict; - - # input parameters - my ( - $dbh, # DBI handle - # FIXME - Unused argument - $input, # CGI parms - )=@_; - - my @serverlist; - my $error; - - $dbh = C4::Context->dbh; - - my $query=$input->param('query'); - - my $isbngood=1; - if ($input->param('type') eq 'isbn') { - $isbngood=checkvalidisbn($query); - } - if ($isbngood) { - foreach ($input->param) { - if (/S-(.*)/) { - my $server=$1; - if ($server eq 'MAN') { - push @serverlist, "MAN/".$input->param('manualz3950server')."//" -; - } else { - push @serverlist, $server; - } - } - } - - $error=addz3950queue($dbh,$input->param('query'), $input->param('type'), - $input->param('rand'), @serverlist); - if ( $error ) { - print qq| - - - -
Error
-$error

-|; - if ( $error =~ /daemon/i ) { - print qq| -There is a launcher for the Z39.50 client daemon in your intranet installation
-directory under ./scripts/z3950daemon/z3950-daemon-launch.sh. This
-script should be run as root, and it will start up the program running with the
-privileges of your apache user. Ideally, this script should be started from a
-system init directory so that is running after the machine starts up. -|; - - } # if daemon - print qq| -

- -$query is not a valid ISBN - Number

\n"; - } -} # sub AcceptZ3950Queue - #--------------------------------------------- sub AcceptMarcUpload { use strict; @@ -995,80 +789,19 @@ sub FormatMarcText { #--------------- +# log cleared, as marcimport is (almost) rewritten from scratch. # $Log$ -# Revision 1.18 2002/10/14 07:41:04 tipaul -# merging arens + my modifs/bugfixes -# -# Revision 1.17 2002/10/13 07:39:26 arensb -# Added magic RCS comment. -# Removed trailing whitespace. -# -# Revision 1.16 2002/10/11 12:45:10 arensb -# Replaced &requireDBI with C4::Context->dbh, thus making the "use -# Fixed muffed quotes in &gettemplate calls. -# Added a temporary print statement in &z3950menu, so it'll print -# something instead of giving a browser error. -# -# Revision 1.15 2002/10/09 18:09:16 tonnesen -# switched from picktemplate() to gettemplate() -# -# Revision 1.14 2002/10/05 09:56:14 arensb -# Merged with arensb-context branch: use C4::Context->dbh instead of -# &C4Connect, and generally prefer C4::Context over C4::Database. -# -# Revision 1.13.2.1 2002/10/04 02:52:50 arensb -# Use C4::Connect instead of C4::Database, C4::Connect->dbh instead -# C4Connect. -# Removed old code for reading /etc/koha.conf. -# -# Revision 1.13 2002/08/14 18:12:52 tonnesen -# Added copyright statement to all .pl and .pm files -# -# Revision 1.12 2002/07/24 16:24:20 tipaul -# Now, the acqui.simple system... -# marcimport.pl has been almost completly rewritten, so LOT OF BUGS TO COME !!! You've been warned. It seems to work, but... -# -# As with my former messages, nothing seems to have been changed... but ... -# * marcimport now uses HTML::Template. -# * marcimport now uses MARC::Record. that means that when you import a record, the old-DB is populated with the data as in version 1.2, but the MARC-DB part is filled with full MARC::Record. -# -# -# to get correct response times, you MUST add an index on isbn, issn and lccn rows in biblioitem table. Note this should be done in 1.2 too... -# -# -# -# acqui.simple manage biblio, biblioitems and items tables quite properly. Normal acquisition system manages biblio, biblioitems BUT NOT items. That will be done in the near future... -# -# -# what's next now ? -# * bug tracking, of course... Surely a dozen of dozens... -# * LOT of developpments, i'll surely write a mail to koha-devel tomorrow (as it's time for dinner in France, and i plan to play NeverwinterNights after dinner ;-) ... -# -# Revision 1.6.2.32 2002/06/29 17:33:47 amillar -# Allow DEFAULT as input to addz3950search. -# Check for existence of pid file (cat crashed otherwise). -# Return error messages in addz3950search. -# -# Revision 1.6.2.31 2002/06/28 18:50:46 tonnesen -# Got rid of white text on black, replaced with black on background-acq.gif -# -# Revision 1.6.2.30 2002/06/28 18:07:27 tonnesen -# marcimport.pl will print an error message if it can not signal the -# processz3950queue program. The message contains instructions for starting the -# daemon. -# -# Revision 1.6.2.29 2002/06/27 18:35:01 tonnesen -# $deweyinput was always defined (it's an HTML input field). Check against -# $bib->{dewey} instead. -# -# Revision 1.6.2.28 2002/06/27 17:41:26 tonnesen -# Applying patch from Matt Kraai to pick F or NF based on presense of a dewey -# number when adding a book via marcimport.pl +# Revision 1.19 2002/10/15 10:14:44 tipaul +# road to 1.3.2. Full rewrite of marcimport.pl. +# The acquisition system in MARC version will work like this : +# * marcimport will put marc records into a "breeding farm" table. +# * when the user want to add a biblio, he enters first the ISBN/ISSN of the biblio. koha searches into breeding farm and if the record exists, it is shown to the user to help him adding the biblio. When the biblio is added, it's deleted from the breeding farm. # -# Revision 1.6.2.27 2002/06/26 15:52:55 amillar -# Fix display of marc tag labels and indicators +# This commit : +# * modify acqui.simple home page (addbooks.pl) +# * adds import into breeding farm # -# Revision 1.6.2.26 2002/06/26 14:28:35 amillar -# Removed subroutines now existing in modules: extractmarcfields, -# parsemarcfileformat, addz3950queue, getkeytableselectoptions +# Please note that : +# * z3950 functionnality is dropped from "marcimport" will be added somewhere else. +# * templates are in a new acqui.simple sub directory, and the marcimport template directory will become obsolete soon.I think this is more logic # diff --git a/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbooks.tmpl b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbooks.tmpl new file mode 100644 index 0000000000..2651784cab --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbooks.tmpl @@ -0,0 +1,96 @@ + + +MARC import and BIBLIO management + +

+ No items found + + +

+ Website Biblioitem Added + + +

+

+ + + +
To add a new biblio/item, scan or type the ISBN number:
+ + + + + + + + + +
ISBN:If the ISBN is found into the biblio table, it will be retrieved and can be modified.
+ If the ISBN is found into the breeding farm, it will be retrieved. and a biblio added.
+ Otherwise, a biblio can be added from scratch.
+ +

+

+ + + + +
Tools for importing MARC records into breeding farm
+ + + + + + + + +
 
  • Upload MARC records
  •  The breeding farm is a table where are stored imported MARC records.
    + A MARC record is stored in the breeding farm as long as you've no item. When you type the ISBN of a biblio, it's searched in the breeding farm. + If found, the biblio is added to koha active table, and removed from breeding farm. +
    + + + +
    Tools for importing MARC from a z3950 server
    + + + + + + + +
     
  • Z39.50 Search Tool
  •  does not work
    + + + + + +
    Add New Website
    +

    + + + + + + +
    Keyword:
    +
    + +

    + + + + +
    Help
    +Koha stores data in three sections +

    +

    Biblio

    +The first section records bibliographic data such as title, author and copyright for a particular work. +

    +

    Group

    +The second records bibliographic data for a particular publication of that work, such as ISBN number, physical description, publisher information, etc +

    +

    Item

    +The third section holds specific item information, such as the bar code number +

    + diff --git a/koha-tmpl/intranet-tmpl/default/en/acqui.simple/marcimport.tmpl b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/marcimport.tmpl new file mode 100644 index 0000000000..e649da29b9 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/marcimport.tmpl @@ -0,0 +1,52 @@ + +

    MARC acquisition system

    + + + + + +
    Import into breeding farm
    + + +

    Import results :

    + + +
      Select a file to import into breeding farm. It will be parsed, and for each ISBN found, a new baby will be created in breeding farm. +If an ISBN already exists in the breeding farm, you can choose wether to ignore the new one, or overwrite the old one.
      +You can enter a name for this import. It may be useful, when creating a biblio, to remember where the suggested marc data comes !
      +Of course, if the ISBN already exists in active DB, the biblio will be ignored.
    +
    " enctype="multipart/form-data"> + + + + + + + + + + + + + + + + + + +
    Select the file to import : +
    +
    Name of this import : +
    +
    If ISBN already in breeding farm : Ignore this one, keep the existing one
    + Overwrite the existing one with this
     
    +
    +
    + -- 2.39.5