removing use MARC::Charset
[koha_fer] / acqui.simple / marcimport.pl
index 0570cfe..b8bae89 100755 (executable)
@@ -36,13 +36,13 @@ use DBI;
 # Koha modules used
 use C4::Context;
 use C4::Output;
+use C4::Charset;
 use C4::Input;
 use C4::Biblio;
 use MARC::File::USMARC;
 use HTML::Template;
 use C4::Output;
 use C4::Auth;
-use MARC::Charset;
 
 #------------------
 # Constants
@@ -86,8 +86,9 @@ if ($uploadmarc && length($uploadmarc)>0) {
        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,title,marc) values(?,?,?,?)");
+       my $searchbreeding = $dbh->prepare("select id from marc_breeding where isbn=?");
+       my $insertsql = $dbh->prepare("insert into marc_breeding (file,isbn,title,author,marc) values(?,?,?,?,?)");
+       my $replacesql = $dbh->prepare("update marc_breeding set file=?,isbn=?,title=?,author=?,marc=? where id=?");
        # fields used for import results
        my $imported=0;
        my $alreadyindb = 0;
@@ -99,42 +100,44 @@ if ($uploadmarc && length($uploadmarc)>0) {
                        $notmarcrecord++;
                } else {
                        my $oldbiblio = MARCmarc2koha($dbh,$marcrecord);
+                       $oldbiblio->{title} = char_decode($oldbiblio->{title});
+                       $oldbiblio->{author} = char_decode($oldbiblio->{author});
                        # 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}) {
-                               # drop every "special" char : spaces, - ...
-                               $oldbiblio->{isbn} =~ s/ |-|\.//g,
-                               # search if biblio exists
-                               my $biblioitemnumber;
+                       # drop every "special" char : spaces, - ...
+                       $oldbiblio->{isbn} =~ s/ |-|\.//g,
+                       # 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 $breedingid;
                                if ($oldbiblio->{isbn}) {
-                                       $searchisbn->execute($oldbiblio->{isbn});
-                                       ($biblioitemnumber) = $searchisbn->fetchrow;
+                                       $searchbreeding->execute($oldbiblio->{isbn});
+                                       ($breedingid) = $searchbreeding->fetchrow;
                                } else {
-                                       $searchissn->execute($oldbiblio->{issn});
-                                       ($biblioitemnumber) = $searchissn->fetchrow;
+                                       $searchbreeding->execute($oldbiblio->{issn});
+                                       ($breedingid) = $searchbreeding->fetchrow;
                                }
-                               if ($biblioitemnumber) {
-                                       $alreadyindb++;
+                               if (!$breedingid || $overwrite_biblio) {
+                                       my $recoded;
+                                       $recoded = $marcrecord->as_usmarc();
+                                               if ($breedingid) {
+                                                       $replacesql ->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded,$breedingid);
+                                               } else {
+                                                       $insertsql ->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded);
+                                               }
+                                       $imported++;
                                } 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) {
-                                               my $recoded;
-                                               $recoded = $marcrecord->as_usmarc();
-                                               $insertsql ->execute($filename,$oldbiblio->{isbn}.$oldbiblio->{issn},$oldbiblio->{title},$recoded);
-                                               $imported++;
-                                       } else {
-                                               $alreadyinfarm++;
-                                       }
+                                       $alreadyinfarm++;
                                }
-                       } else {
-                               $notmarcrecord++;
                        }
                }
        }
@@ -147,7 +150,10 @@ if ($uploadmarc && length($uploadmarc)>0) {
 
 }
 
-print "Content-Type: text/html\n\n",$template->output;
+print $input->header(
+    -type => guesstype($template->output),
+    -cookie => $cookie
+),$template->output;
 my $menu;
 my $file;
 
@@ -803,6 +809,19 @@ sub FormatMarcText {
 #---------------
 # log cleared, as marcimport is (almost) rewritten from scratch.
 # $Log$
+# Revision 1.29  2003/01/28 15:28:31  tipaul
+# removing use MARC::Charset
+# Was a buggy test
+#
+# Revision 1.28  2003/01/28 15:00:31  tipaul
+# user can now search in breeding farm with isbn/issn or title. Title/name are stored in breeding farm and showed when a search is done
+#
+# Revision 1.27  2003/01/26 23:21:49  acli
+# Handle non-latin1 charsets
+#
+# Revision 1.26  2003/01/23 12:26:41  tipaul
+# upgrading import in breeding farm (you can now search on ISBN or on title) AND character encoding.
+#
 # Revision 1.25  2003/01/21 08:13:50  tipaul
 # character encoding ISO646 => 8859-1, first draft
 #