handle main card inactive
[migration-tools.git] / unicorn_patron_xml2text.pl
index e075fb6..4df8e75 100755 (executable)
@@ -1,7 +1,4 @@
 #!/usr/bin/perl
-#
-# WARNING: This doesn't handle Rob's address-database-enhanced Patron XML format, with such things as Change of Address information
-#
 use strict;
 use warnings;
 
@@ -31,7 +28,18 @@ my @base_elements = (
     "middle_name",
     "suffix_name",
     "note",
-    "comment"
+    "comment",
+    "staff",
+    "webcatpref",
+    "user_category1",
+    "user_category2",
+    "user_category3",
+    "dept",
+    "guardian",
+    "user_claims_ret",
+    #"user_environment",
+    #"user_library",
+    "user_department"
 );
 
 my @addr_elements = (
@@ -40,16 +48,21 @@ my @addr_elements = (
     "std_city",
     "std_state",
     "std_zip",
+    "phone",
     "dayphone",
     "homephone",
     "workphone",
-    "email"
+    "email",
+    "location",
+    "usefor",
+    "care_of"
 );
 
 print STDOUT join("\t", @base_elements);
 foreach my $addr ( 1..3 ) {
     print STDOUT "\t" . join("\t", @addr_elements);
 }
+print STDOUT "\tinactive_barcode1\tinactive_barcode2";
 print STDOUT "\n";
 
 for my $patron ( $doc->documentElement->childNodes ) {
@@ -95,6 +108,29 @@ for my $patron ( $doc->documentElement->childNodes ) {
         }
     }
 
+    my $inactive_barcode1 = '';
+    my $inactive_barcode2 = '';
+    my $userid_active = 't';
+    my @barcodes = $patron->findnodes( "barcodes" );
+    for my $i_bc ( $barcodes[0]->findnodes( "barcode" ) ) {
+        my $active = $i_bc->getAttribute('active');
+        if ($active eq "0" && $i_bc->textContent eq $bc) {
+            $userid_active = 'f';
+        }
+        if ($active eq "0" && $i_bc->textContent ne $bc) {
+            if (! $inactive_barcode1 ) {
+                $inactive_barcode1 = $i_bc->textContent;
+            } else {
+                if (! $inactive_barcode2 ) {
+                    $inactive_barcode2 = $i_bc->textContent;
+                } else {
+                    warn "Extra barcode (" . $i_bc->textContent . ") for user with id = " . $bc . "\n";
+                }
+            }
+        }
+    }
+    print STDOUT "$userid_active\t$inactive_barcode1\t$inactive_barcode2";
+
     print STDOUT "\n";
        $count++;
 }
@@ -146,7 +182,7 @@ sub parse_date {
                }
        }
 
-       my $date;
+       my $date = $string;
        if ($y && $m && $d) {
                eval {
                        $date = sprintf('%04d-%02d-%-2d',$y, $m, $d)