[Koha-patches] [PATCH] Bugfix for 1931 as well as a major overhaul in the presentation of the search results.

Chris Nighswonger cnighswonger at foundations.edu
Thu Apr 10 16:29:22 CEST 2008


---
 .../prog/en/modules/labels/result.tmpl             |   61 ++++++++++---------
 labels/label-item-search.pl                        |   64 +++++++++++--------
 2 files changed, 68 insertions(+), 57 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl
index 5b14d7d..71035fe 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl
@@ -17,15 +17,15 @@ function add_item(itemnum,batch_id,type_id){
  var getstr='';
  if (itemnum == 'checked') {
     itms= new Array;        
-    if(document.resultform.itemnumber.length > 0) {
-        for (var i=0; i < document.resultform.itemnumber.length; i++) {
-            if (document.resultform.itemnumber[i].checked) {
-                itms.push("itemnumber=" +  document.resultform.itemnumber[i].value);
+    if(document.resultform.i_itemnumber.length > 0) {
+        for (var i=0; i < document.resultform.i_itemnumber.length; i++) {
+            if (document.resultform.i_itemnumber[i].checked) {
+                itms.push("itemnumber=" +  document.resultform.i_itemnumber[i].value);
             }
         }
         getstr = itms.join("&");
     } else {
-        getstr = "itemnumber="+document.resultform.itemnumber.value;
+        getstr = "itemnumber="+document.resultform.i_itemnumber.value;
     }
   } else {
 		getstr = "itemnumber="+itemnum;
@@ -33,8 +33,8 @@ function add_item(itemnum,batch_id,type_id){
  	var myurl = "label-manager.pl?op=add&batch_id="+batch_id+"&type="+type_id+"&"+getstr;
 	window.opener.location.href = myurl;
 }
-function add_item3(itemnumber){
- var myurl = "label-manager.pl?op=add&itemnumber="+itemnumber+"";
+function add_item3(i_itemnumber){
+ var myurl = "label-manager.pl?op=add&itemnumber="+i_itemnumber+"";
      window.opener.location.href = myurl;
 }
 //]]>
@@ -72,38 +72,39 @@ function add_item3(itemnumber){
 <div id="breadcrumbs"><a href="/cgi-bin/koha/labels/label-item-search.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Search for Items for Batch <!-- TMPL_VAR NAME="batch_id" --></a> &rsaquo; Search results</div>
 <form name="resultform" class="checkboxed"><div style="float: right; margin-top: .5em;"><input type="submit" class="icon addchecked" value="Add checked" onclick="add_item('checked',<!-- TMPL_VAR NAME="batch_id" -->,'<!-- TMPL_VAR NAME="type" -->'); return false" /> <input type="button" class="close" value="Done" /></div><div style="line-height: 2em; margin-left: .7em;"><a id="CheckAll" href="/cgi-bin/koha/labels/label-item-search.pl">Select All</a></span><span class="clearall"><a id="CheckNone" href="/cgi-bin/koha/labels/label-item-search.pl">Clear All</a></div>
 
-	<table style="float: left; margin: .5em 0;">
 	<!-- TMPL_LOOP name="result" -->
+	<table width="610 pixels" frame="border" border="2" style="float: left; margin: .5em 0;">
 		<!-- TMPL_IF name="highlight" -->
 			<tr class="highlight">
 		<!-- TMPL_ELSE -->
 			<tr>
 		<!-- /TMPL_IF -->
-			<td> <input type="checkbox" name="itemnumber" id="itm<!-- TMPL_VAR NAME="itemnumber" -->" value="<!-- TMPL_VAR NAME="itemnumber" -->" />	</td>
-			<td>
-					<p><label for="itm<!-- TMPL_VAR NAME="itemnumber" -->" style="font-weight:bold;"><!-- TMPL_VAR NAME="title" --></label> 
-					<!-- TMPL_VAR NAME="author" -->
-					<p>[ <!-- TMPL_VAR NAME="itemtype" --> ]
-					<!-- TMPL_IF name="publishercode" -->- <!-- TMPL_VAR name="publishercode" --><!-- /TMPL_IF -->
-					<!-- TMPL_IF name="place" --> ; <!-- TMPL_VAR name="place" --><!-- /TMPL_IF -->
-					<!-- TMPL_IF name="pages" --> - <!-- TMPL_VAR name="pages" --><!-- /TMPL_IF -->
-					<!-- TMPL_IF name="notes" --> <br /> <!-- TMPL_VAR name="notes" --><!-- /TMPL_IF -->
-					</p>
-				</td>
+			<td colspan="5">
+					<label style="font-weight:bold;"><!-- TMPL_VAR NAME="title" --></label> by <!-- TMPL_VAR NAME="author" --><br />
+                                      [<!-- TMPL_VAR NAME="itemtype" -->], <!-- TMPL_IF name="publishercode" --><!-- TMPL_VAR name="publishercode" --> <!-- /TMPL_IF --><!-- TMPL_IF name="place" --><!-- TMPL_VAR name="place" --> <!-- /TMPL_IF --><!-- TMPL_IF name="copyrightdate" --><!-- TMPL_VAR name="copyrightdate" -->, <!-- /TMPL_IF --><!-- TMPL_IF name="pages" --><!-- TMPL_VAR name="pages" --><!-- /TMPL_IF --><!-- TMPL_IF name="isbn" -->, <b>ISBN: </b><!-- TMPL_VAR name="isbn" --><!-- /TMPL_IF --><!-- TMPL_IF name="notes" -->,<br /><!-- TMPL_VAR name="notes" --><!-- /TMPL_IF -->
+			</td>
+                        </tr>
 <!-- NEW -->
-				<td>
-					<!-- TMPL_IF name="itemcallnumber" --><!-- TMPL_VAR name="itemcallnumber" --><br /> <!-- /TMPL_IF -->
-					<!-- TMPL_IF name="dateaccessioned" -->[<!-- TMPL_VAR name="dateaccessioned" -->]<br /> <!-- /TMPL_IF -->
-					<!-- TMPL_IF name="barcode" --> <!-- TMPL_VAR name="barcode" --> <!-- /TMPL_IF -->
-				</td>
-				<td>
-					<a onclick="add_item('<!-- TMPL_VAR NAME="itemnumber" -->',<!-- TMPL_VAR NAME="batch_id" -->, '<!-- TMPL_VAR NAME="type" -->'); return false" href="/cgi-bin/koha/barcodes/label-manager.pl?itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->&amp;batch_id=<!-- TMPL_VAR name="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->&amp;op=add">Add</a>
-
+                                <tr>
+                                    <th>Select</th>
+                                    <th>Item Call Number</th>
+                                    <th>Date Accessioned</th>
+                                    <th>Barcode</th>
+                                    <th></th>
+                                </tr>
+        <!-- TMPL_LOOP name="item" -->
+					<!-- TMPL_IF name="i_itemnumber1" --><tr><td align="center"><label for="itm<!-- TMPL_VAR NAME="i_itemnumber1" -->" ><input type="checkbox" name="i_itemnumber" id="itm<!-- TMPL_VAR NAME="i_itemnumber1" -->" value="<!-- TMPL_VAR NAME="i_itemnumber1" -->" /></label></td><!-- /TMPL_IF -->
+					<!-- TMPL_IF name="i_itemcallnumber" --><td align="center"><!-- TMPL_VAR name="i_itemcallnumber" --><br /></td><!-- /TMPL_IF -->
+					<!-- TMPL_IF name="i_dateaccessioned" --><td align="center"><!-- TMPL_VAR name="i_dateaccessioned" --><br /></td><!-- /TMPL_IF -->
+					<!-- TMPL_IF name="i_barcode" --><td align="center"><!-- TMPL_VAR name="i_barcode" --></td><!-- /TMPL_IF -->
+					<!-- TMPL_IF name="i_itemnumber2" --><td align="center"> 
+					<a onclick="add_item('<!-- TMPL_VAR NAME="i_itemnumber2" -->',<!-- TMPL_VAR NAME="batch_id" -->, '<!-- TMPL_VAR NAME="type" -->'); return false" href="/cgi-bin/koha/barcodes/label-manager.pl?itemnumber=<!-- TMPL_VAR NAME="i_itemnumber2" -->&amp;batch_id=<!-- TMPL_VAR name="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->&amp;op=add">Add</a></td>
+		                        <!-- /TMPL_IF -->
 <!-- /NEW -->
-				</td>
-			</tr>
+        <!-- /TMPL_LOOP --><!-- item -->
+                                        </tr>
+	 </table>
 	<!-- /TMPL_LOOP -->
-		</table>
 </form>
 	<div class="results">
 		<p>
diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl
index 810cd21..3da74f5 100755
--- a/labels/label-item-search.pl
+++ b/labels/label-item-search.pl
@@ -32,10 +32,17 @@ use C4::Acquisition;
 use C4::Search;
 use C4::Dates qw( DHTMLcalendar );
 use C4::Koha;    # XXX subfield_is_koha_internal_p
-
+use C4::Debug;
 use List::Util qw( max min );
 #use Smart::Comments;
-use Data::Dumper;
+
+BEGIN {
+    $debug = $debug || $cgi_debug;
+    if ($debug) {
+        require Data::Dumper;
+        import Data::Dumper qw(Dumper);
+    }
+}
 
 # Creates a scrolling list with the associated default value.
 # Using more than one scrolling list in a CGI assigns the same default value to all the
@@ -79,40 +86,43 @@ if ( $op eq "do_search" ) {
 
 if ( $show_results ) {
 	my $hits = $show_results;
-	my (@results, at results2);
-    # This code needs to be refactored using these subs...
-    #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
-    #my $dat = &GetBiblioData( $biblio->{biblionumber} );
+        my (@results, @items);
+        # This code needs to be refactored using these subs...
+        #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
+        #my $dat = &GetBiblioData( $biblio->{biblionumber} );
 	for(my $i=0; $i<$hits; $i++) {
         #DEBUG Notes: Decode the MARC record from each resulting MARC record...
-	    my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
+	my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
         #DEBUG Notes: Transform it to Koha form...
-	    my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
-	    #build the hash for the template.
-	    $biblio->{highlight}       = ($i % 2)?(1):(0);
-        #DEBUG Notes: Stuff it into @results... (used below to supply fields not existing in the item data)
+	my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
+	# Begin building the hash for the template...
+        # I don't think we need this with the current template design, but I'm leaving it in place. -fbcit
+	#$biblio->{highlight}       = ($i % 2)?(1):(0);
+        #DEBUG Notes: Stuff the bib into @results...
         push @results, $biblio;
-	    my $biblionumber = $biblio->{'biblionumber'};
+	my $biblionumber = $biblio->{'biblionumber'};
         #DEBUG Notes: Grab the item numbers associated with this MARC record...
         my $itemnums = get_itemnumbers_of($biblionumber);
         #DEBUG Notes: Retrieve the item data for each number... 
         my $iii = $itemnums->{$biblionumber};
 	    if ($iii) {
-            my @titem_results = GetItemsInfo( $itemnums->{$biblionumber}, 'intra' );
 	        my $item_results =  GetItemInfosOf( @$iii );
-        	foreach my $item (keys %$item_results) {
-                for my $bibdata (keys %{$results[$i]}) {
-                    if ( !$item_results->{$item}{$bibdata} ) {      #Only add the data from the bibliodata if the data does not already exit in itemdata.
-                        #Otherwise we just build duplicate records rather than unique records per item.
-                        $item_results->{$item}{$bibdata} = $results[$i]->{$bibdata};
+                foreach my $item (keys %$item_results) {
+                    #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
+                    if ($item_results->{$item}->{'biblionumber'} eq $results[$i]->{'biblionumber'}) {
+                        # NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
+                        # This is a real hack, but I can't think of a better way right now. -fbcit
+                        push @{$results[$i]->{'item'}}, { i_itemnumber1         => $item_results->{$item}->{'itemnumber'} };
+                        push @{$results[$i]->{'item'}}, { i_itemcallnumber      => $item_results->{$item}->{'itemcallnumber'} };
+                        push @{$results[$i]->{'item'}}, { i_dateaccessioned     => $item_results->{$item}->{'dateaccessioned'} };
+                        push @{$results[$i]->{'item'}}, { i_barcode             => $item_results->{$item}->{'barcode'} };
+                        push @{$results[$i]->{'item'}}, { i_itemnumber2         => $item_results->{$item}->{'itemnumber'} };
                     }
                 }
-                #DEBUG Notes: After merging the bib and item data, stuff the results into $results2...
-                push @results2, $item_results->{$item};
-            }
-            #warn Dumper(@results2);
 	    }
-    }
+        }
+        $debug and warn "**********\@results**********\n";
+        $debug and warn Dumper(@results);
   
   ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         {
@@ -159,22 +169,22 @@ if ( $show_results ) {
     my $displaynext = 0;
     my $displayprev = $startfrom;
     # XXX Kludge. We show the "next" link if we retrieved the max number of results. There could be 0 more.
-    if ( scalar @results2 == $resultsperpage ) {
+    if ( scalar @results == $resultsperpage ) {
         $displaynext = 1;
     }
 
     $template->param(
-        result         => \@results2,
+        result         => \@results,
         startfrom      => $startfrom,
         displaynext    => $displaynext,
         displayprev    => $displayprev,
         resultsperpage => $resultsperpage,
-        startfromnext  => $startfrom + min( $resultsperpage, scalar @results2 ),
+        startfromnext  => $startfrom + min( $resultsperpage, scalar @results ),
         startfromprev  => max( $startfrom - $resultsperpage, 0 ),
         searchdata     => \@field_data,
         total          => $total,
         from           => $startfrom + 1,
-        to             => $startfrom + min( $resultsperpage, scalar @results2 ),
+        to             => $startfrom + min( $resultsperpage, scalar @results ),
         numbers        => \@numbers,
         batch_id       => $batch_id,
         type           => $type,
-- 
1.5.3.7




More information about the Koha-patches mailing list