3 # Copyright 2007 Liblime ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use C4::Reports::Guided;
25 use C4::Auth qw/:DEFAULT get_session/;
27 use C4::Dates qw/format_date/;
29 use C4::Branch; # XXX subfield_is_koha_internal_p
30 use C4::Koha qw/IsAuthorisedValueCategory/;
38 Script to control the guided report creation
43 my $usecache = C4::Context->ismemcached;
45 my $phase = $input->param('phase');
47 if ( $phase eq 'Build new' or $phase eq 'Delete Saved' ) {
48 $flagsrequired = 'create_reports';
50 elsif ( $phase eq 'Use saved' ) {
51 $flagsrequired = 'execute_reports';
56 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
58 template_name => "reports/guided_reports_start.tmpl",
62 flagsrequired => { reports => $flagsrequired },
66 my $session = $cookie ? get_session($cookie->value) : undef;
69 if ( $input->param("filter_set") ) {
71 $filter->{$_} = $input->param("filter_$_") foreach qw/date author keyword group subgroup/;
72 $session->param('report_filter', $filter) if $session;
73 $template->param( 'filter_set' => 1 );
76 $filter = $session->param('report_filter');
82 $template->param( 'start' => 1 );
85 elsif ( $phase eq 'Build new' ) {
87 $template->param( 'build1' => 1 );
88 my $areas = get_report_areas();
90 'areas' => [map { id => $_->[0], name => $_->[1] }, @$areas],
91 'usecache' => $usecache,
92 'cache_expiry' => 300,
95 } elsif ( $phase eq 'Use saved' ) {
98 # get list of reports and display them
99 my $group = $input->param('group');
100 my $subgroup = $input->param('subgroup');
101 $filter->{group} = $group;
102 $filter->{subgroup} = $subgroup;
105 'savedreports' => get_saved_reports($filter),
106 'usecache' => $usecache,
107 'groups_with_subgroups'=> groups_with_subgroups($group, $subgroup),
108 dateformat => C4::Context->preference('dateformat'),
112 elsif ( $phase eq 'Delete Saved') {
114 # delete a report from the saved reports list
115 my $id = $input->param('reports');
117 print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved");
121 elsif ( $phase eq 'Show SQL'){
123 my $id = $input->param('reports');
124 my $report = get_saved_report($id);
127 'reportname' => $report->{report_name},
128 'notes' => $report->{notes},
129 'sql' => $report->{savedsql},
134 elsif ( $phase eq 'Edit SQL'){
135 my $id = $input->param('reports');
136 my $report = get_saved_report($id);
137 my $group = $report->{report_group};
138 my $subgroup = $report->{report_subgroup};
140 'sql' => $report->{savedsql},
141 'reportname' => $report->{report_name},
142 'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
143 'notes' => $report->{notes},
145 'cache_expiry' => $report->{cache_expiry},
146 'public' => $report->{public},
147 'usecache' => $usecache,
152 elsif ( $phase eq 'Update SQL'){
153 my $id = $input->param('id');
154 my $sql = $input->param('sql');
155 my $reportname = $input->param('reportname');
156 my $group = $input->param('group');
157 my $subgroup = $input->param('subgroup');
158 my $notes = $input->param('notes');
159 my $cache_expiry = $input->param('cache_expiry');
160 my $cache_expiry_units = $input->param('cache_expiry_units');
161 my $public = $input->param('public');
162 my $save_anyway = $input->param('save_anyway');
166 # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
167 if( $cache_expiry_units ){
168 if( $cache_expiry_units eq "minutes" ){
170 } elsif( $cache_expiry_units eq "hours" ){
171 $cache_expiry *= 3600; # 60 * 60
172 } elsif( $cache_expiry_units eq "days" ){
173 $cache_expiry *= 86400; # 60 * 60 * 24
176 # check $cache_expiry isnt too large, Memcached::set requires it to be less than 30 days or it will be treated as if it were an absolute time stamp
177 if( $cache_expiry >= 2592000 ){
178 push @errors, {cache_expiry => $cache_expiry};
181 create_non_existing_group_and_subgroup($input, $group, $subgroup);
183 if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) {
184 push @errors, {sqlerr => $1};
186 elsif ($sql !~ /^(SELECT)/i) {
187 push @errors, {queryerr => 1};
192 'errors' => \@errors,
197 # Check defined SQL parameters for authorised value validity
198 my $problematic_authvals = ValidateSQLParameters($sql);
200 if ( scalar @$problematic_authvals > 0 && not $save_anyway ) {
201 # There's at least one problematic parameter, report to the
202 # GUI and provide all user input for further actions
206 'reportname' => $reportname,
208 'subgroup' => $subgroup,
210 'cache_expiry' => $cache_expiry,
211 'cache_expiry_units' => $cache_expiry_units,
213 'problematic_authvals' => $problematic_authvals,
214 'warn_authval_problem' => 1,
219 # No params problem found or asked to save anyway
224 subgroup => $subgroup,
226 cache_expiry => $cache_expiry,
230 'save_successful' => 1,
231 'reportname' => $reportname,
238 elsif ($phase eq 'retrieve results') {
239 my $id = $input->param('id');
240 my ($results,$name,$notes) = format_results($id);
244 'results' => $results,
250 elsif ( $phase eq 'Report on this Area' ) {
251 my $cache_expiry_units = $input->param('cache_expiry_units'),
252 my $cache_expiry = $input->param('cache_expiry');
254 # we need to handle converting units
255 if( $cache_expiry_units eq "minutes" ){
257 } elsif( $cache_expiry_units eq "hours" ){
258 $cache_expiry *= 3600; # 60 * 60
259 } elsif( $cache_expiry_units eq "days" ){
260 $cache_expiry *= 86400; # 60 * 60 * 24
262 # check $cache_expiry isnt too large, Memcached::set requires it to be less than 30 days or it will be treated as if it were an absolute time stamp
263 if( $cache_expiry >= 2592000 ){ # oops, over the limit of 30 days
264 # report error to user
268 'areas' => get_report_areas(),
269 'cache_expiry' => $cache_expiry,
270 'usecache' => $usecache,
271 'public' => $input->param('public'),
274 # they have choosen a new report and the area to report on
277 'area' => $input->param('area'),
278 'types' => get_report_types(),
279 'cache_expiry' => $cache_expiry,
280 'public' => $input->param('public'),
285 elsif ( $phase eq 'Choose this type' ) {
286 # they have chosen type and area
287 # get area and type and pass them to the template
288 my $area = $input->param('area');
289 my $type = $input->param('types');
294 columns => get_columns($area,$input),
295 'cache_expiry' => $input->param('cache_expiry'),
296 'public' => $input->param('public'),
300 elsif ( $phase eq 'Choose these columns' ) {
301 # we now know type, area, and columns
302 # next step is the constraints
303 my $area = $input->param('area');
304 my $type = $input->param('type');
305 my @columns = $input->param('columns');
306 my $column = join( ',', @columns );
312 definitions => get_from_dictionary($area),
313 criteria => get_criteria($area,$input),
314 'cache_expiry' => $input->param('cache_expiry'),
315 'cache_expiry_units' => $input->param('cache_expiry_units'),
316 'public' => $input->param('public'),
320 elsif ( $phase eq 'Choose these criteria' ) {
321 my $area = $input->param('area');
322 my $type = $input->param('type');
323 my $column = $input->param('column');
324 my @definitions = $input->param('definition');
325 my $definition = join (',',@definitions);
326 my @criteria = $input->param('criteria_column');
328 foreach my $crit (@criteria) {
329 my $value = $input->param( $crit . "_value" );
331 # If value is not defined, then it may be range values
332 if (!defined $value) {
334 my $fromvalue = $input->param( "from_" . $crit . "_value" );
335 my $tovalue = $input->param( "to_" . $crit . "_value" );
337 # If the range values are dates
338 if ($fromvalue =~ C4::Dates->regexp('syspref') && $tovalue =~ C4::Dates->regexp('syspref')) {
339 $fromvalue = C4::Dates->new($fromvalue)->output("iso");
340 $tovalue = C4::Dates->new($tovalue)->output("iso");
343 if ($fromvalue && $tovalue) {
344 $query_criteria .= " AND $crit >= '$fromvalue' AND $crit <= '$tovalue'";
350 if ($value =~ C4::Dates->regexp('syspref')) {
351 $value = C4::Dates->new($value)->output("iso");
353 # don't escape runtime parameters, they'll be at runtime
354 if ($value =~ /<<.*>>/) {
355 $query_criteria .= " AND $crit=$value";
357 $query_criteria .= " AND $crit='$value'";
366 'definition' => $definition,
367 'criteriastring' => $query_criteria,
368 'cache_expiry' => $input->param('cache_expiry'),
369 'cache_expiry_units' => $input->param('cache_expiry_units'),
370 'public' => $input->param('public'),
374 my @columns = split( ',', $column );
377 # build structue for use by tmpl_loop to choose columns to order by
378 # need to do something about the order of the order :)
379 # we also want to use the %columns hash to get the plain english names
380 foreach my $col (@columns) {
381 my %total = (name => $col);
382 my @selects = map {+{ value => $_ }} (qw(sum min max avg count));
383 $total{'select'} = \@selects;
384 push @total_by, \%total;
387 $template->param( 'total_by' => \@total_by );
390 elsif ( $phase eq 'Choose these operations' ) {
391 my $area = $input->param('area');
392 my $type = $input->param('type');
393 my $column = $input->param('column');
394 my $criteria = $input->param('criteria');
395 my $definition = $input->param('definition');
396 my @total_by = $input->param('total_by');
398 foreach my $total (@total_by) {
399 my $value = $input->param( $total . "_tvalue" );
400 $totals .= "$value($total),";
408 'criteriastring' => $criteria,
410 'definition' => $definition,
411 'cache_expiry' => $input->param('cache_expiry'),
412 'public' => $input->param('public'),
416 my @columns = split( ',', $column );
419 # build structue for use by tmpl_loop to choose columns to order by
420 # need to do something about the order of the order :)
421 foreach my $col (@columns) {
422 my %order = (name => $col);
423 my @selects = map {+{ value => $_ }} (qw(asc desc));
424 $order{'select'} = \@selects;
425 push @order_by, \%order;
428 $template->param( 'order_by' => \@order_by );
431 elsif ( $phase eq 'Build report' ) {
433 # now we have all the info we need and can build the sql
434 my $area = $input->param('area');
435 my $type = $input->param('type');
436 my $column = $input->param('column');
437 my $crit = $input->param('criteria');
438 my $totals = $input->param('totals');
439 my $definition = $input->param('definition');
440 my $query_criteria=$crit;
441 # split the columns up by ,
442 my @columns = split( ',', $column );
443 my @order_by = $input->param('order_by');
446 foreach my $order (@order_by) {
447 my $value = $input->param( $order . "_ovalue" );
448 if ($query_orderby) {
449 $query_orderby .= ",$order $value";
452 $query_orderby = " ORDER BY $order $value";
458 build_query( \@columns, $query_criteria, $query_orderby, $area, $totals, $definition );
464 'cache_expiry' => $input->param('cache_expiry'),
465 'public' => $input->param('public'),
469 elsif ( $phase eq 'Save' ) {
470 # Save the report that has just been built
471 my $area = $input->param('area');
472 my $sql = $input->param('sql');
473 my $type = $input->param('type');
479 'cache_expiry' => $input->param('cache_expiry'),
480 'public' => $input->param('public'),
481 'groups_with_subgroups' => groups_with_subgroups($area), # in case we have a report group that matches area
485 elsif ( $phase eq 'Save Report' ) {
486 # save the sql pasted in by a user
487 my $area = $input->param('area');
488 my $group = $input->param('group');
489 my $subgroup = $input->param('subgroup');
490 my $sql = $input->param('sql');
491 my $name = $input->param('reportname');
492 my $type = $input->param('types');
493 my $notes = $input->param('notes');
494 my $cache_expiry = $input->param('cache_expiry');
495 my $cache_expiry_units = $input->param('cache_expiry_units');
496 my $public = $input->param('public');
497 my $save_anyway = $input->param('save_anyway');
500 # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
501 if( $cache_expiry_units ){
502 if( $cache_expiry_units eq "minutes" ){
504 } elsif( $cache_expiry_units eq "hours" ){
505 $cache_expiry *= 3600; # 60 * 60
506 } elsif( $cache_expiry_units eq "days" ){
507 $cache_expiry *= 86400; # 60 * 60 * 24
510 # check $cache_expiry isnt too large, Memcached::set requires it to be less than 30 days or it will be treated as if it were an absolute time stamp
511 if( $cache_expiry && $cache_expiry >= 2592000 ){
512 push @errors, {cache_expiry => $cache_expiry};
515 create_non_existing_group_and_subgroup($input, $group, $subgroup);
517 ## FIXME this is AFTER entering a name to save the report under
518 if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) {
519 push @errors, {sqlerr => $1};
521 elsif ($sql !~ /^(SELECT)/i) {
522 push @errors, {queryerr => "No SELECT"};
527 'errors' => \@errors,
529 'reportname'=> $name,
532 'cache_expiry' => $cache_expiry,
536 # Check defined SQL parameters for authorised value validity
537 my $problematic_authvals = ValidateSQLParameters($sql);
539 if ( scalar @$problematic_authvals > 0 && not $save_anyway ) {
540 # There's at least one problematic parameter, report to the
541 # GUI and provide all user input for further actions
545 'subgroup' => $subgroup,
547 'reportname' => $name,
550 'cache_expiry' => $cache_expiry,
551 'cache_expiry_units' => $cache_expiry_units,
553 'problematic_authvals' => $problematic_authvals,
554 'warn_authval_problem' => 1,
558 # No params problem found or asked to save anyway
559 my $id = save_report( {
560 borrowernumber => $borrowernumber,
565 subgroup => $subgroup,
568 cache_expiry => $cache_expiry,
572 'save_successful' => 1,
573 'reportname' => $name,
580 elsif ($phase eq 'Run this report'){
581 # execute a saved report
582 my $limit = $input->param('limit') || 20;
584 my $report_id = $input->param('reports');
585 my @sql_params = $input->param('sql_params');
587 if ($input->param('page')) {
588 $offset = ($input->param('page') - 1) * $limit;
593 'report_id' => $report_id,
596 my ( $sql, $type, $name, $notes );
597 if (my $report = get_saved_report($report_id)) {
598 $sql = $report->{savedsql};
599 $name = $report->{report_name};
600 $notes = $report->{notes};
603 # if we have at least 1 parameter, and it's not filled, then don't execute but ask for parameters
604 if ($sql =~ /<</ && !@sql_params) {
605 # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
606 my @split = split /<<|>>/,$sql;
609 for(my $i=0;$i<($#split/2);$i++) {
610 my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
613 if ( not defined $authorised_value ) {
614 # no authorised value input, provide a text box
616 } elsif ( $authorised_value eq "date" ) {
617 # require a date, provide a date picker
620 # defined $authorised_value, and not 'date'
621 my $dbh=C4::Context->dbh;
622 my @authorised_values;
624 # builds list, depending on authorised value...
625 if ( $authorised_value eq "branches" ) {
626 my $branches = GetBranchesLoop();
627 foreach my $thisbranch (@$branches) {
628 push @authorised_values, $thisbranch->{value};
629 $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
632 elsif ( $authorised_value eq "itemtypes" ) {
633 my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
635 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
636 push @authorised_values, $itemtype;
637 $authorised_lib{$itemtype} = $description;
640 elsif ( $authorised_value eq "cn_source" ) {
641 my $class_sources = GetClassSources();
642 my $default_source = C4::Context->preference("DefaultClassificationSource");
643 foreach my $class_source (sort keys %$class_sources) {
644 next unless $class_sources->{$class_source}->{'used'} or
645 ($class_source eq $default_source);
646 push @authorised_values, $class_source;
647 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
650 elsif ( $authorised_value eq "categorycode" ) {
651 my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
653 while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
654 push @authorised_values, $categorycode;
655 $authorised_lib{$categorycode} = $description;
658 #---- "true" authorised value
661 if ( IsAuthorisedValueCategory($authorised_value) ) {
663 SELECT authorised_value,lib
664 FROM authorised_values
668 my $authorised_values_sth = $dbh->prepare($query);
669 $authorised_values_sth->execute( $authorised_value);
671 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
672 push @authorised_values, $value;
673 $authorised_lib{$value} = $lib;
674 # For item location, we show the code and the libelle
675 $authorised_lib{$value} = $lib;
678 # not exists $authorised_value_categories{$authorised_value})
679 push @authval_errors, {'entry' => $text,
680 'auth_val' => $authorised_value };
681 # tell the template there's an error
682 $template->param( auth_val_error => 1 );
683 # skip scrolling list creation and params push
689 $input =CGI::scrolling_list( # FIXME: factor out scrolling_list
690 -name => "sql_params",
691 -id => "sql_params_".$labelid,
692 -values => \@authorised_values,
693 # -default => $value,
694 -labels => \%authorised_lib,
702 push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid };
704 $template->param('sql' => $sql,
706 'sql_params' => \@tmpl_parameters,
707 'auth_val_errors' => \@authval_errors,
709 'reports' => $report_id,
712 # OK, we have parameters, or there are none, we run the report
713 # if there were parameters, replace before running
714 # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
715 my @split = split /<<|>>/,$sql;
717 for(my $i=0;$i<$#split/2;$i++) {
718 my $quoted = C4::Context->dbh->quote($sql_params[$i]);
719 # if there are special regexp chars, we must \ them
720 $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
721 $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
723 my ($sth, $errors) = execute_query($sql, $offset, $limit);
724 my $total = nb_rows($sql) || 0;
726 die "execute_query failed to return sth for report $report_id: $sql";
728 my $headers= header_cell_loop($sth);
729 $template->param(header_row => $headers);
730 while (my $row = $sth->fetchrow_arrayref()) {
731 my @cells = map { +{ cell => $_ } } @$row;
732 push @rows, { cells => \@cells };
736 my $totpages = int($total/$limit) + (($total % $limit) > 0 ? 1 : 0);
737 my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report_id&phase=Run%20this%20report&limit=$limit";
739 $url = join('&sql_params=', $url, map { URI::Escape::uri_escape_utf8($_) } @sql_params);
749 'pagination_bar' => pagination_bar($url, $totpages, $input->param('page')),
750 'unlimited_total' => $total,
755 push @errors, { no_sql_for_id => $report_id };
759 elsif ($phase eq 'Export'){
760 binmode STDOUT, ':encoding(UTF-8)';
762 # export results to tab separated text or CSV
763 my $sql = $input->param('sql'); # FIXME: use sql from saved report ID#, not new user-supplied SQL!
764 my $format = $input->param('format');
765 my ($sth, $q_errors) = execute_query($sql);
766 unless ($q_errors and @$q_errors) {
767 print $input->header( -type => 'application/octet-stream',
768 -attachment=>"reportresults.$format"
770 if ($format eq 'tab') {
771 print join("\t", header_cell_values($sth)), "\n";
772 while (my $row = $sth->fetchrow_arrayref()) {
773 print join("\t", @$row), "\n";
776 my $csv = Text::CSV->new({binary => 1});
777 $csv or die "Text::CSV->new({binary => 1}) FAILED: " . Text::CSV->error_diag();
778 if ($csv->combine(header_cell_values($sth))) {
779 print $csv->string(), "\n";
781 push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ;
783 while (my $row = $sth->fetchrow_arrayref()) {
784 if ($csv->combine(@$row)) {
785 print $csv->string(), "\n";
787 push @$q_errors, { combine => $csv->error_diag() } ;
791 foreach my $err (@$q_errors, @errors) {
792 print "# ERROR: " . (map {$_ . ": " . $err->{$_}} keys %$err) . "\n";
793 } # here we print all the non-fatal errors at the end. Not super smooth, but better than nothing.
799 'name' => 'Error exporting report!',
801 'errors' => $q_errors,
805 elsif ( $phase eq 'Create report from SQL' ) {
807 my ($group, $subgroup);
808 # allow the user to paste in sql
809 if ( $input->param('sql') ) {
810 $group = $input->param('report_group');
811 $subgroup = $input->param('report_subgroup');
813 'sql' => $input->param('sql') // '',
814 'reportname' => $input->param('reportname') // '',
815 'notes' => $input->param('notes') // '',
820 'groups_with_subgroups' => groups_with_subgroups($group, $subgroup),
822 'cache_expiry' => 300,
823 'usecache' => $usecache,
827 elsif ($phase eq 'Create Compound Report'){
828 $template->param( 'savedreports' => get_saved_reports(),
833 elsif ($phase eq 'Save Compound'){
834 my $master = $input->param('master');
835 my $subreport = $input->param('subreport');
836 my ($mastertables,$subtables) = create_compound($master,$subreport);
837 $template->param( 'save_compound' => 1,
838 master=>$mastertables,
843 # pass $sth, get back an array of names for the column headers
844 sub header_cell_values {
845 my $sth = shift or return ();
847 foreach my $c (@{$sth->{NAME}}) {
848 #FIXME apparently DBI still needs a utf8 fix for this?
855 # pass $sth, get back a TMPL_LOOP-able set of names for the column headers
856 sub header_cell_loop {
857 my @headers = map { +{ cell => $_ } } header_cell_values (shift);
862 $template->{VARS}->{'build' . $_} and $template->{VARS}->{'buildx' . $_} and last;
864 $template->param( 'referer' => $input->referer(),
867 output_html_with_http_headers $input, $cookie, $template->output;
869 sub groups_with_subgroups {
870 my ($group, $subgroup) = @_;
872 my $groups_with_subgroups = get_report_groups();
874 my @sorted_keys = sort {
875 $groups_with_subgroups->{$a}->{name} cmp $groups_with_subgroups->{$b}->{name}
876 } keys %$groups_with_subgroups;
877 foreach my $g_id (@sorted_keys) {
878 my $v = $groups_with_subgroups->{$g_id};
880 if (my $sg = $v->{subgroups}) {
881 foreach my $sg_id (sort { $sg->{$a} cmp $sg->{$b} } keys %$sg) {
884 name => $sg->{$sg_id},
885 selected => ($group && $g_id eq $group && $subgroup && $sg_id eq $subgroup ),
892 selected => ($group && $g_id eq $group),
893 subgroups => \@subgroups,
899 sub create_non_existing_group_and_subgroup {
900 my ($input, $group, $subgroup) = @_;
902 if (defined $group and $group ne '') {
903 my $report_groups = C4::Reports::Guided::get_report_groups;
904 if (not exists $report_groups->{$group}) {
905 my $groupdesc = $input->param('groupdesc') // $group;
906 C4::Koha::AddAuthorisedValue('REPORT_GROUP', $group, $groupdesc);
908 if (defined $subgroup and $subgroup ne '') {
909 if (not exists $report_groups->{$group}->{subgroups}->{$subgroup}) {
910 my $subgroupdesc = $input->param('subgroupdesc') // $subgroup;
911 C4::Koha::AddAuthorisedValue('REPORT_SUBGROUP', $subgroup, $subgroupdesc, $group);