User can upload a file with barcodes or with itemnumbers
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Mon, 14 Sep 2009 13:56:13 +0000 (15:56 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Wed, 30 Sep 2009 09:30:31 +0000 (11:30 +0200)
koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod.tmpl
tools/batchMod.pl

index f339437..9cee451 100644 (file)
                 <!-- TMPL_UNLESS name="op" -->
                         <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batchMod.pl">
                             <fieldset class="rows">
-                                <legend>Use a barcode file</legend>
+                                <legend>Use a file</legend>
                                      <ol>
-                                    <li><label for="uploadbarcodes">Barcode file: </label> <input type="file" id="uploadbarcodes" name="uploadbarcodes"></input></li>
+                                     <li>
+                                       <label for="barcode_file">Barcodes file</label><input type="radio" name="filecontent" value="barcode_file" id="barcode_file" checked="checked" /><br />
+                                       <label for="itemid_file">Item Id's file</label><input type="radio" name="filecontent" value="itemid_file" id="itemid_file" />
+                                     </li>
+                                    <li><label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile"></input></li>
                                 </ol>
                             </fieldset>
                             <fieldset class="rows">
@@ -35,7 +39,7 @@
                                 <ol>
                                     <li>
                                       <label for="barcodelist">Barcodes list (one barcode per line): </label>
-                                      <textarea rows="10" cols="30" name="barcodelist"></textarea>
+                                      <textarea rows="10" cols="30" id="barcodelist" name="barcodelist"></textarea>
                                     </li>
                                 </ol>
                             </fieldset>
index e6e2270..d97921e 100755 (executable)
@@ -31,6 +31,7 @@ use C4::ClassSource;
 use C4::Dates;
 use C4::Debug;
 use YAML;
+use Switch;
 use MARC::File::XML;
 
 sub find_value {
@@ -112,22 +113,32 @@ if ($op eq "action") {
 #-------------------------------------------------------------------------------
 
 if ($op eq "show"){
-       my $barcodefh = $input->upload('uploadbarcodes');
-    my @barcodelist;
-    if ( $barcodefh){
-        while (my $barcode=<$barcodefh>){
-            chomp $barcode;
-            push @barcodelist, $barcode;
+       my $filefh = $input->upload('uploadfile');
+       my $filecontent = $input->{'filecontent'};
+
+    my @contentlist;
+    if ($filefh){
+        while (my $content=<$filefh>){
+            chomp $content;
+            push @contentlist, $content;
         }
-    }
-    if ( my $list=$input->param('barcodelist')){
-        push @barcodelist, split(/\s\n/, $list);
-    }
-       push @itemnumbers,map{GetItemnumberFromBarcode($_)} @barcodelist;
 
-       warn Dump(@itemnumbers);
+       switch ($filecontent) {
+           case "barcode_file" {
+               push @itemnumbers,map{GetItemnumberFromBarcode($_)} @contentlist;
+           }
+
+           case "itemid_file" {
+               @itemnumbers = @contentlist;
+           }
+       }
+    } else {
+       if ( my $list=$input->param('barcodelist')){
+        push my @barcodelist, split(/\s\n/, $list);
+       push @itemnumbers,map{GetItemnumberFromBarcode($_)} @barcodelist;
+    }
+}
        $items_display_hashref=BuildItemsData(@itemnumbers);
-       warn Dump($items_display_hashref);
 
 # now, build the item form for entering a new item
 my @loop_data =();
@@ -370,7 +381,7 @@ sub BuildItemsData{
 # And $tag>10
 sub UpdateMarcWith($$){
   my ($marcfrom,$marcto)=@_;
-  warn "FROM :",$marcfrom->as_formatted;
+  #warn "FROM :",$marcfrom->as_formatted;
        my (  $itemtag,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
        my $fieldfrom=$marcfrom->field($itemtag);
        my @fields_to=$marcto->field($itemtag);
@@ -379,5 +390,5 @@ sub UpdateMarcWith($$){
                                $field_to_update->update($$subfield[0]=>$$subfield[1]) if ($$subfield[1]);
                }
     }
-  warn "TO edited:",$marcto->as_formatted;
+  #warn "TO edited:",$marcto->as_formatted;
 }