Bug 16256 - Can't edit library EAN if you leave EAN empty
[koha.git] / reports / guided_reports.pl
index 6a03e11..4b45f95 100755 (executable)
@@ -28,11 +28,13 @@ use C4::Reports::Guided;
 use C4::Auth qw/:DEFAULT get_session/;
 use C4::Output;
 use C4::Debug;
-use C4::Branch; # XXX subfield_is_koha_internal_p
-use C4::Koha qw/IsAuthorisedValueCategory GetFrameworksLoop/;
+use C4::Koha qw/GetFrameworksLoop/;
+use C4::Branch;
 use C4::Context;
 use C4::Log;
 use Koha::DateUtils qw/dt_from_string output_pref/;
+use Koha::AuthorisedValue;
+use Koha::AuthorisedValues;
 
 =head1 NAME
 
@@ -47,7 +49,7 @@ Script to control the guided report creation
 my $input = new CGI;
 my $usecache = C4::Context->ismemcached;
 
-my $phase = $input->param('phase');
+my $phase = $input->param('phase') // '';
 my $flagsrequired;
 if ( $phase eq 'Build new' or $phase eq 'Delete Saved' ) {
     $flagsrequired = 'create_reports';
@@ -705,7 +707,7 @@ elsif ($phase eq 'Run this report'){
                         #---- "true" authorised value
                     }
                     else {
-                        if ( IsAuthorisedValueCategory($authorised_value) ) {
+                        if ( Koha::AuthorisedValues->search({ category => $authorised_value })->count ) {
                             my $query = '
                             SELECT authorised_value,lib
                             FROM authorised_values
@@ -998,12 +1000,21 @@ sub create_non_existing_group_and_subgroup {
         my $report_groups = C4::Reports::Guided::get_report_groups;
         if (not exists $report_groups->{$group}) {
             my $groupdesc = $input->param('groupdesc') // $group;
-            C4::Koha::AddAuthorisedValue('REPORT_GROUP', $group, $groupdesc);
+            Koha::AuthorisedValue->new({
+                category => 'REPORT_GROUP',
+                authorised_value => $group,
+                lib => $groupdesc,
+            })->store;
         }
         if (defined $subgroup and $subgroup ne '') {
             if (not exists $report_groups->{$group}->{subgroups}->{$subgroup}) {
                 my $subgroupdesc = $input->param('subgroupdesc') // $subgroup;
-                C4::Koha::AddAuthorisedValue('REPORT_SUBGROUP', $subgroup, $subgroupdesc, $group);
+                Koha::AuthorisedValue->new({
+                    category => 'REPORT_SUBGROUP',
+                    authorised_value => $subgroup,
+                    lib => $subgroupdesc,
+                    lib_opac => $group,
+                })->store;
             }
         }
     }