Because of the way that the older fine and issuing
rule editors generate the HTML form, if a branch code,
patron category code, or item type code happened to have a
'-' or '.', the HTML form would not be parsed properly, thus
adding an implicit (rather than explicit) limit on the
characters allowed in one of those codes.
This fix removes this limitation by Base64-encoding the codes
when constructing the names for the <input> elements.
Two functions are added to C4::Koha:
str_to_base64() - UTF-8 string to Base64
base64_to_str() - reverse
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
use strict;
use C4::Context;
use C4::Output;
use strict;
use C4::Context;
use C4::Output;
+
+use MIME::Base64 qw(encode_base64 decode_base64);
+use Encode qw(encode decode);
+
use vars qw($VERSION @ISA @EXPORT $DEBUG);
BEGIN {
use vars qw($VERSION @ISA @EXPORT $DEBUG);
BEGIN {
&GetKohaAuthorisedValues
&GetAuthValCode
&GetManagedTagSubfields
&GetKohaAuthorisedValues
&GetAuthValCode
&GetManagedTagSubfields
+ &str_to_base64
+ &base64_to_str
+=head2 str_to_base64
+
+=over 4
+
+my $base64 = str_to_base64($string_containing_unicode);
+
+=back
+
+Get a Base64 version of a string that is in UTF-8. This
+function can be used to convert an arbitrary coded value
+(like a branch code) into a form that can be safely concatenated
+with similarly encoded values for a HTML form input name, as
+in admin/issuingrules.pl.
+
+=cut
+
+sub str_to_base64 {
+ my $in = shift;
+ return encode_base64(encode("UTF-8", $in), '');
+}
+
+=head2 base64_to_str
+
+=over 4
+
+my $base64 = base64_to_str($string_containing_unicode);
+
+=back
+
+Converse of C<str_to_base64()>.
+
+=cut
+
+sub base64_to_str {
+ my $in = shift;
+ return decode("UTF-8", decode_base64($in));
+}
+
foreach my $key (@names){
# FINES
foreach my $key (@names){
# FINES
- if ($key =~ /F-(.*)-(.*)\.(.*)/) {
- my $br = $1; # branch
- my $bor = $2; # borrower category
- my $cat = $3; # item type
+ if ($key =~ /F-(.*)-(.*)-(.*)/) {
+ my $br = base64_to_str($1); # branch
+ my $bor = base64_to_str($2); # borrower category
+ my $cat = base64_to_str($3); # item type
my $data=$input->param($key);
my ($fine,$firstremind,$chargeperiod)=split(',',$data);
$bor="*" unless ($bor);
my $data=$input->param($key);
my ($fine,$firstremind,$chargeperiod)=split(',',$data);
$bor="*" unless ($bor);
$fine =~ s/\.*0*$//g;
my $finesvalue;
$finesvalue= "$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}" if $fine ne '';
$fine =~ s/\.*0*$//g;
my $finesvalue;
$finesvalue= "$fine,$dat->{'firstremind'},$dat->{'chargeperiod'}" if $fine ne '';
- my %row = (finesname=> "F-$branch-$trow3[$i].$$data->{'itemtype'}",
+ my $finesname = join("-", "F", map { str_to_base64($_) } ($branch, $trow3[$i], $$data->{'itemtype'}));
+ my %row = (finesname=> $finesname,
finesvalue => $finesvalue,
toggle => $toggle,
);
finesvalue => $finesvalue,
toggle => $toggle,
);
my $sth_Idelete=$dbh->prepare("DELETE FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
foreach my $key (@names){
# ISSUES
my $sth_Idelete=$dbh->prepare("DELETE FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
foreach my $key (@names){
# ISSUES
- if ($key =~ /I-(.*)-(.*)\.(.*)/) {
- my $br = $1; # branch
- my $bor = $2; # borrower category
- my $cat = $3; # item type
+ if ($key =~ /I-(.*)-(.*)-(.*)/) {
+ my $br = base64_to_str($1); # branch
+ my $bor = base64_to_str($2); # borrower category
+ my $cat = base64_to_str($3); # item type
my $data=$input->param($key);
my ($issuelength,$maxissueqty,$rentaldiscount)=split(',',$data);
if ($maxissueqty) {
my $data=$input->param($key);
my ($issuelength,$maxissueqty,$rentaldiscount)=split(',',$data);
if ($maxissueqty) {
my $issuelength = $dat->{'issuelength'};
my $issuingvalue;
$issuingvalue = "$issuelength,$maxissueqty" if $maxissueqty ne '';
my $issuelength = $dat->{'issuelength'};
my $issuingvalue;
$issuingvalue = "$issuelength,$maxissueqty" if $maxissueqty ne '';
- my %row = (issuingname => "I-$branch-$trow3[$i].$$data->{itemtype}",
+ my $issuingname = join("-", "I", map { str_to_base64($_) } ($branch, $trow3[$i], $$data->{itemtype}) );
+ my %row = (issuingname => $issuingname,
issuingvalue => $issuingvalue,
toggle => $toggle,
);
issuingvalue => $issuingvalue,
toggle => $toggle,
);