use strict;
require Exporter;
use C4::Context;
+use CGI;
use vars qw($VERSION @ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
&checkdigit &checkvalidisbn
+ &buildCGIsort
);
# FIXME - This is never used.
# 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;
use strict;
use CGI;
use C4::Context;
+use C4::Input;
use C4::Database;
use C4::Auth;
use C4::Acquisition;
-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,
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;
<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)">
<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>
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') {
-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,
expiry => format_date($data->{'expiry'}),
cardnumber => $cardnumber,
dateofbirth => $data->{'dateofbirth'},
- sort1 => $data->{'sort1'},
- sort2 => $data->{'sort2'},
dateformat => display_date_format(),
modify => $modify,
CGIbranch => $CGIbranch);