MT 2269 : Do not display all the items if there is a large amount of items
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Wed, 10 Mar 2010 21:26:14 +0000 (22:26 +0100)
committerGalen Charlton <gmcharlt@gmail.com>
Fri, 30 Apr 2010 01:52:15 +0000 (21:52 -0400)
Also fix the barcode not found problem (due to empty lines)

Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
Signed-off-by: Galen Charlton <gmcharlt@gmail.com>

C4/Biblio.pm
C4/Items.pm
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 e24bee8..91e9027 100644 (file)
@@ -58,6 +58,7 @@ BEGIN {
       &GetBiblioItemInfosOf
       &GetBiblioItemByBiblioNumber
       &GetBiblioFromItemNumber
+      &GetBiblionumberFromItemnumber
 
       &GetRecordValue
       &GetFieldMapping
@@ -716,6 +717,24 @@ sub GetBiblioItemByBiblioNumber {
     return @results;
 }
 
+=head2 GetBiblionumberFromItemnumber
+
+=over 4
+
+=back
+
+=cut
+
+sub GetBiblionumberFromItemnumber {
+    my ($itemnumber) = @_;
+    my $dbh            = C4::Context->dbh;
+    my $sth            = $dbh->prepare("Select biblionumber FROM items WHERE itemnumber = ?");
+
+    $sth->execute($itemnumber);
+    my ($result) = $sth->fetchrow;
+    return ($result);
+}
+
 =head2 GetBiblioFromItemNumber
 
 =over 4
index 7f31cdc..3b2e620 100644 (file)
@@ -66,6 +66,7 @@ BEGIN {
         GetItemsInfo
         get_itemnumbers_of
         GetItemnumberFromBarcode
+        GetBarcodeFromItemnumber
 
                DelItemCheck
                MoveItemFromBiblio 
@@ -1517,6 +1518,27 @@ sub GetItemnumberFromBarcode {
     return ($result);
 }
 
+=head2 GetBarcodeFromItemnumber
+
+=over 4
+
+$result = GetBarcodeFromItemnumber($itemnumber);
+
+=back
+
+=cut
+
+sub GetBarcodeFromItemnumber {
+    my ($itemnumber) = @_;
+    my $dbh = C4::Context->dbh;
+
+    my $rq =
+      $dbh->prepare("SELECT barcode FROM items WHERE items.itemnumber=?");
+    $rq->execute($itemnumber);
+    my ($result) = $rq->fetchrow;
+    return ($result);
+}
+
 =head3 get_item_authorised_values
 
   find the types and values for all authorised values assigned to this item.
index 7e7b98b..1ba9b24 100644 (file)
@@ -30,7 +30,6 @@
            <!-- 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="item_loop" -->
     <!-- TMPL_UNLESS name="action" -->
 
     <!-- TMPL_IF name="notfoundbarcodes" -->
                    <!-- /TMPL_LOOP -->
                </tbody>
            </table></div>
+           <!-- TMPL_UNLESS name="too_many_items" -->
            <p>The following barcodes were found : </p>
+           <!-- /TMPL_UNLESS -->
        <!-- /TMPL_IF -->
 
 
-       <form name="f" action="batchMod.pl" method="post">
+<form name="f" action="batchMod.pl" method="post">
+<!-- TMPL_IF name="item_loop" -->
        <div id="cataloguing_additem_itemlist">
                <div style="overflow:auto">
                <table id="itemst">
                </table>
                </div>
        </div>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF NAME="simple_items_display" -->
+    <ul>
+    <!-- TMPL_LOOP NAME="simple_items_display" -->
+        <li>
+            <a href="<!-- TMPL_VAR NAME="itemnumber" -->"><!-- TMPL_VAR NAME="barcode" --></a>
+        </li>
+    <!-- /TMPL_LOOP -->
+    </ul>
+<!-- /TMPL_IF -->
+
+
+
        <!-- TMPL_IF name="show" -->
+
+<!-- TMPL_IF name="too_many_items" -->
+    <p>Too many items (<!-- TMPL_VAR NAME="too_many_items" -->): not displaying each one individually.</p>
+    <!-- TMPL_LOOP name="itemnumbers_hashref" -->
+        <input type="hidden" name="itemnumber" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
+    <!-- /TMPL_LOOP -->
+<!-- /TMPL_IF -->   
+
+
                <div id="cataloguing_additem_newitem">
             <input type="hidden" name="op" value="<!-- TMPL_VAR NAME="op" -->" />
-            <p>This will delete the selected items.</p>
+            <p>This will delete <!-- TMPL_IF NAME="too_many_items" -->all the<!-- TMPL_ELSE -->the selected<!-- /TMPL_IF --> items.</p>
             <input type="hidden" name="del" value="1" />
             <fieldset class="action">    
                <input type="submit" name="submit" value="Go" />
        </div>
        <!-- /TMPL_IF -->
     <!-- /TMPL_UNLESS -->
-<!-- TMPL_ELSE -->
-    <p>No item found</p>
-<!-- /TMPL_IF -->
 
 <!-- TMPL_IF name="action" -->
        <p><!-- TMPL_VAR NAME="deleted_items" --> item(s) deleted.</p>
index 40640cc..acc9e12 100644 (file)
                    <!-- /TMPL_LOOP -->
                </tbody>
            </table></div>
+           <!-- TMPL_UNLESS name="too_many_items" -->
            <p>The following barcodes were found : </p>
+           <!-- /TMPL_UNLESS -->
        <!-- /TMPL_IF -->
 
-<!-- TMPL_IF name="item_loop" -->
 <form name="f" action="batchMod.pl" method="post">
+<!-- TMPL_IF name="item_loop" -->
 <div id="cataloguing_additem_itemlist">
         <div style="overflow:auto">
         <table id="itemst">
         </table>
         </div>
 </div>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF NAME="simple_items_display" -->
+    <p>The following items were modified:</p>
+    <ul>
+    <!-- TMPL_LOOP NAME="simple_items_display" -->
+       <li>
+           <a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=12<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->"><!-- TMPL_VAR NAME="barcode" --></a>
+       </li>
+    <!-- /TMPL_LOOP -->
+    </ul>
+<!-- /TMPL_IF -->
+
 <!-- TMPL_IF name="show" -->
+
+<!-- TMPL_IF name="too_many_items" -->
+    <p>Too many items (<!-- TMPL_VAR NAME="too_many_items" -->): not displaying each one individually.</p>
+    <!-- TMPL_LOOP name="itemnumbers_hashref" -->
+       <input type="hidden" name="itemnumber" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
+    <!-- /TMPL_LOOP -->
+<!-- /TMPL_IF -->
+
 <div id="cataloguing_additem_newitem">
      <input type="hidden" name="op" value="<!-- TMPL_VAR NAME="op" -->" />
         <h2>Edit Items</h2>
index 6c3caf8..f7e9557 100755 (executable)
@@ -90,7 +90,6 @@ if ($op eq "action") {
     my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
     my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
     my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
-
     foreach my $itemnumber(@itemnumbers){
            my $itemdata=GetItem($itemnumber);
            if ($input->param("del")){
@@ -107,7 +106,14 @@ if ($op eq "action") {
                    eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
            }
     }
-    $items_display_hashref=BuildItemsData(@itemnumbers);
+    # If we have a reasonable amount of items, we display them
+    if (scalar(@itemnumbers) <= 1000) {
+       $items_display_hashref=BuildItemsData(@itemnumbers);
+    } else {
+       # Else, we only display the barcode
+       my @simple_items_display = map {{ itemnumber => $_, barcode => GetBarcodeFromItemnumber($_), biblionumber => GetBiblionumberFromItemnumber($_) }} @itemnumbers;
+       $template->param("simple_items_display" => \@simple_items_display);
+    }
 }
 
 #
@@ -124,7 +130,7 @@ if ($op eq "show"){
     if ($filefh){
         while (my $content=<$filefh>){
             chomp $content;
-            push @contentlist, $content;
+            push @contentlist, $content if $content;
         }
 
        switch ($filecontent) {
@@ -161,8 +167,15 @@ if ($op eq "show"){
 
     }
 }
+    # Only display the items if there are no more than 1000
+    if (scalar(@itemnumbers) <= 1000) {
        $items_display_hashref=BuildItemsData(@itemnumbers);
-
+    } else {
+       $template->param("too_many_items" => scalar(@itemnumbers));
+       # Even if we do not display the items, we need the itemnumbers
+       my @itemnumbers_hashref = map {{itemnumber => $_}} @itemnumbers;
+       $template->param("itemnumbers_hashref" => \@itemnumbers_hashref);
+    }
 # now, build the item form for entering a new item
 my @loop_data =();
 my $i=0;