diff --git a/C4/Koha.pm b/C4/Koha.pm index d68cc96216..31ffa37b2c 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -21,6 +21,10 @@ package C4::Koha; 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 { @@ -50,6 +54,8 @@ BEGIN { &GetKohaAuthorisedValues &GetAuthValCode &GetManagedTagSubfields + &str_to_base64 + &base64_to_str $DEBUG ); @@ -920,6 +926,44 @@ ORDER BY marc_subfield_structure.tagfield, tagsubfield|); return $data; } +=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. + +=cut + +sub base64_to_str { + my $in = shift; + return decode("UTF-8", decode_base64($in)); +} + 1; __END__ diff --git a/admin/finesrules.pl b/admin/finesrules.pl index 3fea7f3848..e89e7adee3 100755 --- a/admin/finesrules.pl +++ b/admin/finesrules.pl @@ -55,10 +55,10 @@ if ($op eq 'save') { 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); @@ -129,7 +129,8 @@ foreach my $data (@itemtypes) { $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, ); diff --git a/admin/issuingrules.pl b/admin/issuingrules.pl index d1a90c1a40..54d6b79b69 100755 --- a/admin/issuingrules.pl +++ b/admin/issuingrules.pl @@ -53,10 +53,10 @@ if ($op eq 'save') { 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) { @@ -131,7 +131,8 @@ foreach my $data (@itemtypes) { 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, );