[Koha-patches] [PATCH] Adding the two sort fields as a way to search for borrowers

Michael Hafen mdhafen at washk12.org
Tue May 27 20:16:19 CEST 2008


The depends on my other patch to add GetMemberSortValues and
SearchMemberSort.
---
 .../en/modules/labels/pcard-members-search.tmpl    |   25 +++++++++++++++++-
 labels/pcard-member-search.pl                      |   28 +++++++++++++++++--
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/pcard-members-search.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/pcard-members-search.tmpl
index 2c6bc6d..951e665 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/pcard-members-search.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/pcard-members-search.tmpl
@@ -81,9 +81,32 @@ function add_item3(borrowernumber){
     <a href="/cgi-bin/koha/labels/pcard-member-search.pl?member=z&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=<!-- TMPL_VAR NAME="type" -->">Z</a>
 </div>
 
+<!-- TMPL_IF NAME="sort1_loop" -->
+<div class="browse">
+Search by sort1 field:
+ <select name="sort1" onchange="if ( this.options[this.selectedIndex].value != '' ) { window.location = '/cgi-bin/koha/labels/pcard-member-search.pl?sort1='+ this.options[this.selectedIndex].value +'&batch_id=<!-- TMPL_VAR NAME="batch_id" -->&type=<!-- TMPL_VAR NAME="type" -->'; }">
+<option value=""></option>
+<!-- TMPL_LOOP NAME="sort1_loop" -->
+<option value="<!-- TMPL_VAR NAME="value" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="value" --></option>
+<!-- /TMPL_LOOP -->
+</select>
+</div>
+<!-- /TMPL_IF -->
+
+<!-- TMPL_IF NAME="sort2_loop" -->
+<div class="browse">
+Search by sort2 field:
+ <select name="sort2" onchange="if ( this.options[this.selectedIndex].value != '' ) { window.location = '/cgi-bin/koha/labels/pcard-member-search.pl?sort2='+ this.options[this.selectedIndex].value +'&batch_id=<!-- TMPL_VAR NAME="batch_id" -->&type=<!-- TMPL_VAR NAME="type" -->'; }">
+<option value=""></option>
+<!-- TMPL_LOOP NAME="sort2_loop" -->
+<option value="<!-- TMPL_VAR NAME="value" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="value" --></option>
+<!-- /TMPL_LOOP -->
+</select>
+</div>
+<!-- /TMPL_IF -->
 
 <!-- TMPL_IF NAME="resultsloop" -->
-<div id="searchheader"> <h3>Results <!-- TMPL_VAR Name ="from" --> to <!-- TMPL_VAR Name ="to" --> of <!-- TMPL_VAR Name ="numresults" --> found for '<span class="ex"><!-- TMPL_VAR NAME="member" --></span>'</h3></div>
+<div id="searchheader"> <h3>Results <!-- TMPL_VAR Name ="from" --> to <!-- TMPL_VAR Name ="to" --> of <!-- TMPL_VAR Name ="numresults" --> found for '<span class="ex"><!-- TMPL_VAR NAME="member" --> <!-- TMPL_VAR NAME="sort1" --> <!-- TMPL_VAR NAME="sort2" --></span>'</h3></div>
 <!-- TMPL_IF NAME="paginationbar" --><div id="pagination_top"><!-- TMPL_VAR Name ="paginationbar" --></div><!-- /TMPL_IF -->
 <form name="resultform" action="/cgi-bin/koha/labels/pcard-member-search.pl" method="get" 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/pcard-member-search.pl">Select All</a><a id="CheckNone" href="/cgi-bin/koha/labels/pcard-member-search.pl">Clear All</a></div>
diff --git a/labels/pcard-member-search.pl b/labels/pcard-member-search.pl
index 484ff31..5041349 100755
--- a/labels/pcard-member-search.pl
+++ b/labels/pcard-member-search.pl
@@ -70,12 +70,24 @@ my $theme = $input->param('theme') || "default";
 
 
 my $member=$input->param('member');
+my $sort1=$input->param('sort1');
+my $sort2=$input->param('sort2');
 my $orderby=$input->param('orderby');
 $orderby = "surname,firstname" unless $orderby;
 $member =~ s/,//g;   #remove any commas from search string
 $member =~ s/\*/%/g;
 
-unless ($member) {
+my ( $sort1_values, $sort2_values ) = GetMemberSortValues();
+my ( $sort1_loop, $sort2_loop );
+foreach ( sort @$sort1_values ) {
+    push @$sort1_loop, { value => $_ } if ( $_ );
+}
+foreach ( sort @$sort2_values ) {
+    push @$sort2_loop, { value => $_ } if ( $_ );
+}
+$template->param( sort1_loop => $sort1_loop, sort2_loop => $sort2_loop );
+
+unless ($member||$sort1||$sort2) {
     $template->param( batch_id => $batch_id, type => $batch_type,);
     output_html_with_http_headers $input, $cookie, $template->output;
     exit;
@@ -87,11 +99,14 @@ if(length($member) == 1)
 {
     ($count,$results)=SearchMember($member,$orderby,"simple");
 }
-else
+elsif($member)
 {
     ($count,$results)=SearchMember($member,$orderby,"advanced");
 }
-
+elsif($sort1 || $sort2)
+{
+    ($count,$results)=SearchMemberSort($sort1,$sort2,$orderby);
+}
 
 my @resultsdata;
 my $toggle = 0;
@@ -127,12 +142,17 @@ for (my $i=($startfrom-1)*$resultsperpage; $i < $to; $i++){
   if ( $toggle ) { $toggle = 0; } else {$toggle = 1; }
   push(@resultsdata, \%row);
 }
+# URL encode the sort strings
+$sort1 =~ s/\s/\+/g;
+$sort2 =~ s/\s/\+/g;
 my $base_url =
     'pcard-member-search.pl?'
   . join(
     '&amp;',
     map { $_->{term} . '=' . $_->{val} } (
         { term => 'member',         val => $member         },
+	{ term => 'sort1',          val => $sort1          },
+	{ term => 'sort2',          val => $sort2          },
         { term => 'orderby',        val => $orderby        },
         { term => 'resultsperpage', val => $resultsperpage },
         { term => 'type',           val => 'intranet'      },
@@ -153,6 +173,8 @@ $template->param(
 $template->param( 
         searching       => "1",
         member          => $member,
+        sort1           => $sort1,
+        sort2           => $sort2,
         numresults      => $count,
         resultsloop     => \@resultsdata,
         batch_id        => $batch_id,
-- 
1.5.4.3




More information about the Koha-patches mailing list