MT 2071, 2072 : Check that barcodes are found and that items are allowed to be deleted
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Mon, 26 Oct 2009 13:40:39 +0000 (14:40 +0100)
committerMatthias Meusburger <matthias.meusburger@biblibre.com>
Mon, 26 Oct 2009 13:40:39 +0000 (14:40 +0100)
koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tmpl
tools/batchMod.pl

index abc3a73..99b817a 100644 (file)
     <div id="bd">
         <div id="yui-main">
             <div class="yui-b">
-           show : <!-- TMPL_VAR NAME="show" --> <br />
-           action : <!-- TMPL_VAR NAME="action" --><br />
-           results : <!-- TMPL_VAR NAME="results" --><br />
-           nextop : <!-- TMPL_VAR NAME="op" -->
                 <h1>Batch deletion</h1>
            <!-- TMPL_IF NAME="barcode_not_unique" --><div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div><!-- /TMPL_IF -->
            <!-- TMPL_IF NAME="no_next_barcode" --><div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div><!-- /TMPL_IF -->
 
 <!-- TMPL_IF name="item_loop" -->
     <!-- TMPL_UNLESS name="action" -->
+
+    <!-- TMPL_IF name="notfoundbarcodes" -->
+           <div class="error"><p>Warning, the following barcodes were not found :</p>
+           <table>
+               <thead>
+                   <tr>
+                       <th>Barcode</th>
+                   </tr>
+               </thead>
+               <tbody>
+                   <!-- TMPL_LOOP name="notfoundbarcodes" -->
+                       <tr><td><!-- TMPL_VAR name="barcode" --></td></tr>
+                   <!-- /TMPL_LOOP -->
+               </tbody>
+           </table></div>
+           <p>The following barcodes were found : </p>
+       <!-- /TMPL_IF -->
+
+
        <form name="f" action="batchMod.pl" method="post">
        <div id="cataloguing_additem_itemlist">
                <div style="overflow:auto">
@@ -59,7 +74,7 @@
                </div>
        </div>
        <!-- TMPL_IF name="show" -->
-       <div id="cataloguing_additem_newitem">
+               <div id="cataloguing_additem_newitem">
             <input type="hidden" name="op" value="<!-- TMPL_VAR NAME="op" -->" />
             <p>This will delete the selected items.</p>
             <input type="hidden" name="del" value="1" />
 
 <!-- TMPL_IF name="action" -->
        <p><!-- TMPL_VAR NAME="deleted_items" --> item(s) deleted.</p>
-       <!-- TMPL_IF NAME="not_deleted_items" --><p><!-- TMPL_VAR NAME="not_deleted_items" --> item(s) could not be deleted : <!-- TMPL_LOOP NAME="not_deleted_itemnumbers" --><!-- TMPL_VAR NAME="itemnumber" --></p>
+       <!-- TMPL_IF NAME="not_deleted_items" -->
+           <p><!-- TMPL_VAR NAME="not_deleted_items" --> item(s) could not be deleted : <!-- TMPL_LOOP NAME="not_deleted_itemnumbers" --><!-- TMPL_VAR NAME="itemnumber" --><!-- /TMPL_LOOP --></p>
+       <!-- /TMPL_IF -->
+       <!-- TMPL_IF NAME="not_deleted_loop" -->
+       <table id="itemst">
+               <thead>
+                   <tr>
+                       <th>Itemnumber</th>
+                       <th>Barcode</th>
+                       <th>Reason</th>
+                   </tr>
+               </thead>
+               <tbody>
+                   <!-- TMPL_LOOP name="not_deleted_loop" -->
+                       <tr>
+                           <td><!-- TMPL_VAR name="itemnumber" --></td>
+                           <td><!-- TMPL_VAR name="barcode" --></td>
+                           <td><!-- TMPL_IF name="book_on_loan" -->Item is checked out<!-- TMPL_ELSIF name="book_reserved" -->Item has a waiting hold<!-- /TMPL_IF --></td>
+                       </tr>
+                   <!-- /TMPL_LOOP -->
+               </tbody>
+           </table>
+
+       <!-- /TMPL_IF -->
+
+       <p><a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Back</a></p>
 <!-- /TMPL_IF -->
 
 </div>
index ed46561..077d565 100644 (file)
 <div id="breadcrumbs">
        <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
        <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
-       <!-- TMPL_IF name="del" -->
-       <a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Delete batches of notices</a>
-       <!-- TMPL_ELSE -->
        <a href="/cgi-bin/koha/tools/batchMod.pl">Modify batches of notices</a>
-       <!-- /TMPL_IF -->
 </div>
 
 <div id="doc3" class="yui-t2">
     <div id="bd">
         <div id="yui-main">
             <div class="yui-b">
-                <h1>Batch <!-- TMPL_IF name="del" -->deletion<!-- TMPL_ELSE -->modification<!-- /TMPL_IF --></h1>
-                <!-- TMPL_UNLESS name="op" -->
-                        <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batchMod.pl">
-                            <fieldset class="rows">
-                                <legend>Use a file</legend>
-                                     <ol>
-                                     <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">
-                                <legend>Or scan items one-by-one</legend>
-                                <ol>
-                                    <li>
-                                      <label for="barcodelist">Barcodes list (one barcode per line): </label>
-                                      <textarea rows="10" cols="30" id="barcodelist" name="barcodelist"></textarea>
-                                    </li>
-                                </ol>
-                            </fieldset>
-                            <input type="hidden" name="op" value="show" />
-                            <!-- TMPL_IF name="del" --><input type="hidden" name="del" value="1" /><!-- /TMPL_IF -->
-                            <fieldset class="action">
-                                <input type="submit" value="Continue" class="button" />
-                            </fieldset>
-                        </form>
-                    </div>
-                <!-- /TMPL_UNLESS -->
+                <h1>Batch modification</h1>
 <!-- TMPL_IF NAME="barcode_not_unique" --><div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div><!-- /TMPL_IF -->
 <!-- TMPL_IF NAME="no_next_barcode" --><div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div><!-- /TMPL_IF -->
 <!-- TMPL_IF NAME="book_on_loan" --><div class="dialog alert"><strong>Cannot Delete</strong>: item is checked out.</div><!-- /TMPL_IF -->
 <!-- TMPL_IF NAME="book_reserved" --><div class="dialogalert"><strong>Cannot Delete</strong>: item has a waiting hold.</div><!-- /TMPL_IF -->
 
+    <!-- TMPL_IF name="notfoundbarcodes" -->
+           <div class="error"><p>Warning, the following barcodes were not found :</p>
+           <table>
+               <thead>
+                   <tr>
+                       <th>Barcode</th>
+                   </tr>
+               </thead>
+               <tbody>
+                   <!-- TMPL_LOOP name="notfoundbarcodes" -->
+                       <tr><td><!-- TMPL_VAR name="barcode" --></td></td>
+                   <!-- /TMPL_LOOP -->
+               </tbody>
+           </table></div>
+           <p>The following barcodes were found : </p>
+       <!-- /TMPL_IF -->
+
 <!-- TMPL_IF name="item_loop" -->
 <form name="f" action="batchMod.pl" method="post">
 <div id="cataloguing_additem_itemlist">
 <!-- TMPL_IF name="show" -->
 <div id="cataloguing_additem_newitem">
      <input type="hidden" name="op" value="<!-- TMPL_VAR NAME="op" -->" />
-    <!-- TMPL_IF name="del" -->
-                            <p>This will delete the selected items.</p>
-                            <input type="hidden" name="del" value="1" />
-    <!-- TMPL_ELSE -->
         <h2>Edit Items</h2>
        <fieldset class="rows">
        <ol>
         <!-- /TMPL_LOOP -->
     </ol>
     </fieldset>
-    <!-- /TMPL_IF -->  
 <fieldset class="action">    
     <input type="submit" name="submit" value="Go" />
 </fieldset>
 </div>
 <!-- TMPL_ELSE --> <!-- // ACTION -->
-    <!-- TMPL_IF NAME="del" -->
-       <p><!-- TMPL_VAR NAME="deleted_items" --> item(s) deleted.</p>
-       <!-- TMPL_IF NAME="not_deleted_items" --><p><!-- TMPL_VAR NAME="not_deleted_items" --> item(s) could not be deleted.<p>
-    <!-- TMPL_ELSE -->
          <h3>No results!</h3>
          <a href="javascript:window.history.back()">Go back</a>
-    <!-- /TMPL_IF -->
 <!-- /TMPL_IF -->
 
 </div>
index b2a71d4..791d250 100755 (executable)
@@ -94,7 +94,7 @@ if ($op eq "action") {
                        $deleted_items++;
                    } else {
                        $not_deleted_items++;
-                       push @not_deleted, $itemdata->{'itemnumber'};
+                       push @not_deleted, { itemnumber => $itemdata->{'itemnumber'}, barcode => $itemdata->{'barcode'}, title => $itemdata->{'title'}, $return => 1 };
                    }
            } else {
                    my $localmarcitem=Item2Marc($itemdata);
@@ -113,6 +113,7 @@ if ($op eq "action") {
 if ($op eq "show"){
        my $filefh = $input->upload('uploadfile');
        my $filecontent = $input->param('filecontent');
+       my @notfoundbarcodes;
 
     my @contentlist;
     if ($filefh){
@@ -123,9 +124,16 @@ if ($op eq "show"){
 
        switch ($filecontent) {
            case "barcode_file" {
-               push @itemnumbers,map{GetItemnumberFromBarcode($_)} @contentlist;
-               # Remove not found barcodes
-               @itemnumbers = grep(!/^$/, @itemnumbers);
+               foreach my $barcode (@contentlist) {
+
+                   my $itemnumber = GetItemnumberFromBarcode($barcode);
+                   if ($itemnumber) {
+                       push @itemnumbers,$itemnumber;
+                   } else {
+                       push @notfoundbarcodes, $barcode;
+                   }
+               }
+
            }
 
            case "itemid_file" {
@@ -135,9 +143,16 @@ if ($op eq "show"){
     } else {
        if ( my $list=$input->param('barcodelist')){
         push my @barcodelist, split(/\s\n/, $list);
-       push @itemnumbers,map{GetItemnumberFromBarcode($_)} @barcodelist;
-       # Remove not found barcodes
-       @itemnumbers = grep(!/^$/, @itemnumbers);
+
+       foreach my $barcode (@barcodelist) {
+
+           my $itemnumber = GetItemnumberFromBarcode($barcode);
+           if ($itemnumber) {
+               push @itemnumbers,$itemnumber;
+           } else {
+               push @notfoundbarcodes, $barcode;
+           }
+       }
 
     }
 }
@@ -300,6 +315,10 @@ foreach my $tag (sort keys %{$tagslib}) {
 
     # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
     $template->param(item => \@loop_data);
+    if (@notfoundbarcodes) { 
+       my @notfoundbarcodesloop = map{{barcode=>$_}}@notfoundbarcodes;
+       $template->param(notfoundbarcodes => \@notfoundbarcodesloop);
+    }
     $nextop="action"
 } # -- End action="show"
 
@@ -311,12 +330,12 @@ $template->param(
 
 if ($op eq "action") {
 
-    my @not_deleted_loop = map{{itemnumber=>$_}}@not_deleted;
+    #my @not_deleted_loop = map{{itemnumber=>$_}}@not_deleted;
 
     $template->param(
        not_deleted_items => $not_deleted_items,
        deleted_items => $deleted_items,
-       not_deleted_itemnumbers => \@not_deleted_loop 
+       not_deleted_loop => \@not_deleted 
     );
 }