Adding scrolling list for sort1 and sort2
authorhdl <hdl>
Wed, 22 Jun 2005 09:36:24 +0000 (09:36 +0000)
committerhdl <hdl>
Wed, 22 Jun 2005 09:36:24 +0000 (09:36 +0000)
C4/Input.pm
acqui/newbiblio.pl
koha-tmpl/intranet-tmpl/default/en/acqui/newbiblio.tmpl
koha-tmpl/intranet-tmpl/default/en/members/memberentry.tmpl
members/memberentry.pl

index 528f680..430a276 100644 (file)
@@ -21,6 +21,7 @@ package C4::Input; #assumes C4/Input
 use strict;
 require Exporter;
 use C4::Context;
+use CGI;
 
 use vars qw($VERSION @ISA @EXPORT);
 
@@ -49,6 +50,7 @@ number or ISBN is valid.
 @ISA = qw(Exporter);
 @EXPORT = qw(
        &checkdigit &checkvalidisbn
+       &buildCGIsort
 );
 
 # FIXME - This is never used.
@@ -140,37 +142,74 @@ digit at the end.
 # Determine if a number is a valid ISBN number, according to length
 #   of 10 digits and valid checksum
 sub checkvalidisbn {
-        use strict;
-        my ($q)=@_ ;   # Input: ISBN number
-
-        my $isbngood = 0; # Return: true or false
-
-        $q=~s/x$/X/g;           # upshift lower case X
-        $q=~s/[^X\d]//g;
-        $q=~s/X.//g;
-        
-       #return 0 if $q is not ten digits long
-       if (length($q)!=10) {
-               return 0;
-       }
+       use strict;
+       my ($q)=@_ ;    # Input: ISBN number
+       
+       my $isbngood = 0; # Return: true or false
        
-       #If we get to here, length($q) must be 10
-        my $checksum=substr($q,9,1);
-        my $isbn=substr($q,0,9);
-        my $i;
-        my $c=0;
-        for ($i=0; $i<9; $i++) {
-            my $digit=substr($q,$i,1);
-            $c+=$digit*(10-$i);
-        }
+       $q=~s/x$/X/g;   # upshift lower case X
+       $q=~s/[^X\d]//g;
+       $q=~s/X.//g;
+       
+               #return 0 if $q is not ten digits long
+               if (length($q)!=10) {
+                       return 0;
+               }
+               
+               #If we get to here, length($q) must be 10
+       my $checksum=substr($q,9,1);
+       my $isbn=substr($q,0,9);
+       my $i;
+       my $c=0;
+       for ($i=0; $i<9; $i++) {
+               my $digit=substr($q,$i,1);
+               $c+=$digit*(10-$i);
+       }
        $c %= 11;
-        ($c==10) && ($c='X');
-        $isbngood = $c eq $checksum;
-
-        return $isbngood;
+       ($c==10) && ($c='X');
+       $isbngood = $c eq $checksum;
+       return $isbngood;
 
 } # sub checkvalidisbn
 
+=item buildCGISort
+
+  $CGIScrollingList = &BuildCGISort($name string, $input_name string);
+
+Returns the scrolling list with name $input_name, built on authorised Values named $name.
+Returns NULL if no authorised values found
+
+=cut
+#'
+#--------------------------------------
+# Determine if a number is a valid ISBN number, according to length
+#   of 10 digits and valid checksum
+sub buildCGIsort {
+    use strict;
+       my ($name,$input_name,$data) = @_;
+       my $dbh=C4::Context->dbh;
+       my $query=qq{SELECT * FROM authorised_values WHERE category=?};
+       my $sth=$dbh->prepare($query);
+       $sth->execute($name);
+       my $CGISort;
+       if ($sth->rows>0){
+               my @values;
+               my %labels;
+               for (my $i =0;$i<=$sth->rows;$i++){
+                       my $results = $sth->fetchrow_hashref;
+                       push @values, $results->{authorised_value};
+                       $labels{$results->{authorised_value}}=$results->{lib};
+               }
+               $CGISort= CGI::scrolling_list(
+                                       -name => $input_name,
+                                       -values => \@values,
+                                       -labels => \%labels,
+                                       -default=> $data,
+                                       -size => 1,
+                                       -multiple => 0);
+       } 
+       return $CGISort;
+}
 END { }       # module clean-up code here (global destructor)
 
 1;
index 00283a1..08e8fe8 100755 (executable)
@@ -24,6 +24,7 @@
 use strict;
 use CGI;
 use C4::Context;
+use C4::Input;
 use C4::Database;
 use C4::Auth;
 use C4::Acquisition;
@@ -139,6 +140,21 @@ my $CGIbookfund=CGI::scrolling_list( -name     => 'bookfund',
                        -size     => 1,
                        -multiple => 0 );
 
+my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
+if ($CGIsort1) {
+       $template->param(CGIsort1 => $CGIsort1);
+} else {
+       $template->param( sort1 => $data->{'sort1'});
+}
+
+my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
+if ($CGIsort2) {
+       $template->param(CGIsort2 =>$CGIsort2);
+} else {
+       $template->param( sort2 => $data->{'sort2'});
+}
+                       
+                       
 # fill template
 $template->param( existing => $biblio,
                                                title => $title,
@@ -172,8 +188,6 @@ $template->param( existing => $biblio,
                                                invoice => $data->{'booksellerinvoicenumber'},
                                                ecost => $data->{'ecost'},
                                                notes => $data->{'notes'},
-                                               sort1 => $data->{'sort1'},
-                                               sort2 => $data->{'sort2'},
                                                publishercode => $data->{'publishercode'});
 
 output_html_with_http_headers $input, $cookie, $template->output;
index c141257..2627a98 100644 (file)
@@ -198,11 +198,19 @@ function check(f) {
                <p>The 2 following fields are available for your own usage. They can be useful for stat purposes</p>
                <p>
                        <label class="label100">Sort field 1</label>
-                       <input type="text" size="20" name=sort1 value="<!-- TMPL_VAR NAME="sort1" -->">
+                       <!-- TMPL_IF Name="CGIsort1" -->
+                               <!-- TMPL_VAR Name="CGIsort1" -->
+                       <!-- TMPL_ELSE -->
+                               <input type="text" size="20" name="sort1" value="<!-- TMPL_VAR NAME="sort1" -->">
+                       <!--/TMPL_IF -->
                </p>
                <p>
                        <label class="label100">Sort field 2</label>
-                       <input type="text" size="20" name=sort2 value="<!-- TMPL_VAR NAME="sort2" -->">
+                       <!-- TMPL_IF Name="CGIsort2" -->
+                               <!-- TMPL_VAR Name="CGIsort2" -->
+                       <!-- TMPL_ELSE -->
+                               <input type="text" size="20" name="sort2" value="<!-- TMPL_VAR NAME="sort2" -->">
+                       <!--/TMPL_IF -->
                </p>
                <p>
                        <input type="button" value="OK" class="button acquisition" onClick="check(this.form)">
index b0ca6ff..654fd66 100644 (file)
                        <tr>
                                <td>Sorting field 1</td>
                                <td colspan="4">
-                                       <input type="text" name="sort1" value="<!-- TMPL_VAR NAME="sort1" -->">
+                                       <!-- TMPL_IF Name="CGIsort1" -->
+                                               <!-- TMPL_VAR Name="CGIsort1" -->
+                                       <!-- TMPL_ELSE -->
+                                               <input type="text" name="sort1" value="<!-- TMPL_VAR NAME="sort1" -->">
+                                       <!--/TMPL_IF -->
                                </td>
                        </tr>
                        <tr>
                                <td>Sorting field 2</td>
                                <td colspan="4">
-                                       <input type="text" name="sort2" value="<!-- TMPL_VAR NAME="sort2" -->">
+                                       <!-- TMPL_IF Name="CGIsort2" -->
+                                               <!-- TMPL_VAR Name="CGIsort2" -->
+                                       <!-- TMPL_ELSE -->
+                                               <input type="text" name="sort2" value="<!-- TMPL_VAR NAME="sort2" -->">
+                                       <!--/TMPL_IF -->
                                </td>
                        </tr>
 
index d09cd88..c13142a 100755 (executable)
@@ -60,6 +60,8 @@ my $op=$input->param('op');
 my $categorycode=$input->param('categorycode');
 my $destination=$input->param('destination');
 
+
+
 my $nok;
 # if a add or modify is requested => check validity of data.
 if ($op eq 'add' or $op eq 'modify') {
@@ -232,7 +234,22 @@ if ($delete){
                                -labels   => \%select_branches,
                                -size     => 1,
                                -multiple => 0 );
+                               
 
+       my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
+       if ($CGIsort1) {
+               $template->param(CGIsort1 => $CGIsort1);
+       } else {
+               $template->param( sort1 => $data->{'sort1'});
+       }
+
+       my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
+       if ($CGIsort2) {
+               $template->param(CGIsort2 =>$CGIsort2);
+       } else {
+               $template->param( sort2 => $data->{'sort2'});
+       }
+       
        $template->param(       actionType              => $actionType,
                                destination => $destination,
                                borrowernumber          => $borrowernumber,
@@ -265,8 +282,6 @@ if ($delete){
                                expiry          => format_date($data->{'expiry'}),
                                cardnumber      => $cardnumber,
                                dateofbirth     => $data->{'dateofbirth'},
-                               sort1 => $data->{'sort1'},
-                               sort2 => $data->{'sort2'},
                                dateformat      => display_date_format(),
                                modify          => $modify,
                                CGIbranch => $CGIbranch);