From 02c6eacdb7ab20a6896a1f58b86592a644a2bb84 Mon Sep 17 00:00:00 2001 From: hdl Date: Wed, 22 Jun 2005 09:36:24 +0000 Subject: [PATCH] Adding scrolling list for sort1 and sort2 --- C4/Input.pm | 91 +++++++++++++------ acqui/newbiblio.pl | 18 +++- .../default/en/acqui/newbiblio.tmpl | 12 ++- .../default/en/members/memberentry.tmpl | 12 ++- members/memberentry.pl | 19 +++- 5 files changed, 118 insertions(+), 34 deletions(-) diff --git a/C4/Input.pm b/C4/Input.pm index 528f6800ea..430a276192 100644 --- a/C4/Input.pm +++ b/C4/Input.pm @@ -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; diff --git a/acqui/newbiblio.pl b/acqui/newbiblio.pl index 00283a1b61..08e8fe8770 100755 --- a/acqui/newbiblio.pl +++ b/acqui/newbiblio.pl @@ -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; diff --git a/koha-tmpl/intranet-tmpl/default/en/acqui/newbiblio.tmpl b/koha-tmpl/intranet-tmpl/default/en/acqui/newbiblio.tmpl index c1412578b2..2627a98db1 100644 --- a/koha-tmpl/intranet-tmpl/default/en/acqui/newbiblio.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/acqui/newbiblio.tmpl @@ -198,11 +198,19 @@ function check(f) {

The 2 following fields are available for your own usage. They can be useful for stat purposes

- "> + + + + "> +

- "> + + + + "> +

diff --git a/koha-tmpl/intranet-tmpl/default/en/members/memberentry.tmpl b/koha-tmpl/intranet-tmpl/default/en/members/memberentry.tmpl index b0ca6fff8a..654fd66efa 100644 --- a/koha-tmpl/intranet-tmpl/default/en/members/memberentry.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/members/memberentry.tmpl @@ -269,13 +269,21 @@ Sorting field 1 - "> + + + + "> + Sorting field 2 - "> + + + + "> + diff --git a/members/memberentry.pl b/members/memberentry.pl index d09cd88972..c13142ac48 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -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); -- 2.39.5