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),
111 elsif ( $phase eq 'Delete Saved') {
113 # delete a report from the saved reports list
114 my $id = $input->param('reports');
116 print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved");
120 elsif ( $phase eq 'Show SQL'){
122 my $id = $input->param('reports');
123 my $report = get_saved_report
($id);
126 'reportname' => $report->{report_name
},
127 'notes' => $report->{notes
},
128 'sql' => $report->{savedsql
},
133 elsif ( $phase eq 'Edit SQL'){
134 my $id = $input->param('reports');
135 my $report = get_saved_report
($id);
136 my $group = $report->{report_group
};
137 my $subgroup = $report->{report_subgroup
};
139 'sql' => $report->{savedsql
},
140 'reportname' => $report->{report_name
},
141 'groups_with_subgroups' => groups_with_subgroups
($group, $subgroup),
142 'notes' => $report->{notes
},
144 'cache_expiry' => $report->{cache_expiry
},
145 'public' => $report->{public
},
146 'usecache' => $usecache,
151 elsif ( $phase eq 'Update SQL'){
152 my $id = $input->param('id');
153 my $sql = $input->param('sql');
154 my $reportname = $input->param('reportname');
155 my $group = $input->param('group');
156 my $subgroup = $input->param('subgroup');
157 my $notes = $input->param('notes');
158 my $cache_expiry = $input->param('cache_expiry');
159 my $cache_expiry_units = $input->param('cache_expiry_units');
160 my $public = $input->param('public');
161 my $save_anyway = $input->param('save_anyway');
165 # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
166 if( $cache_expiry_units ){
167 if( $cache_expiry_units eq "minutes" ){
169 } elsif( $cache_expiry_units eq "hours" ){
170 $cache_expiry *= 3600; # 60 * 60
171 } elsif( $cache_expiry_units eq "days" ){
172 $cache_expiry *= 86400; # 60 * 60 * 24
175 # 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
176 if( $cache_expiry >= 2592000 ){
177 push @errors, {cache_expiry
=> $cache_expiry};
180 create_non_existing_group_and_subgroup
($input, $group, $subgroup);
182 if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) {
183 push @errors, {sqlerr
=> $1};
185 elsif ($sql !~ /^(SELECT)/i) {
186 push @errors, {queryerr
=> 1};
191 'errors' => \
@errors,
196 # Check defined SQL parameters for authorised value validity
197 my $problematic_authvals = ValidateSQLParameters
($sql);
199 if ( scalar @
$problematic_authvals > 0 && not $save_anyway ) {
200 # There's at least one problematic parameter, report to the
201 # GUI and provide all user input for further actions
205 'reportname' => $reportname,
207 'subgroup' => $subgroup,
209 'cache_expiry' => $cache_expiry,
210 'cache_expiry_units' => $cache_expiry_units,
212 'problematic_authvals' => $problematic_authvals,
213 'warn_authval_problem' => 1,
218 # No params problem found or asked to save anyway
223 subgroup
=> $subgroup,
225 cache_expiry
=> $cache_expiry,
229 'save_successful' => 1,
230 'reportname' => $reportname,
237 elsif ($phase eq 'retrieve results') {
238 my $id = $input->param('id');
239 my ($results,$name,$notes) = format_results
($id);
243 'results' => $results,
249 elsif ( $phase eq 'Report on this Area' ) {
250 my $cache_expiry_units = $input->param('cache_expiry_units'),
251 my $cache_expiry = $input->param('cache_expiry');
253 # we need to handle converting units
254 if( $cache_expiry_units eq "minutes" ){
256 } elsif( $cache_expiry_units eq "hours" ){
257 $cache_expiry *= 3600; # 60 * 60
258 } elsif( $cache_expiry_units eq "days" ){
259 $cache_expiry *= 86400; # 60 * 60 * 24
261 # 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
262 if( $cache_expiry >= 2592000 ){ # oops, over the limit of 30 days
263 # report error to user
267 'areas' => get_report_areas
(),
268 'cache_expiry' => $cache_expiry,
269 'usecache' => $usecache,
270 'public' => $input->param('public'),
273 # they have choosen a new report and the area to report on
276 'area' => $input->param('area'),
277 'types' => get_report_types
(),
278 'cache_expiry' => $cache_expiry,
279 'public' => $input->param('public'),
284 elsif ( $phase eq 'Choose this type' ) {
285 # they have chosen type and area
286 # get area and type and pass them to the template
287 my $area = $input->param('area');
288 my $type = $input->param('types');
293 columns
=> get_columns
($area,$input),
294 'cache_expiry' => $input->param('cache_expiry'),
295 'public' => $input->param('public'),
299 elsif ( $phase eq 'Choose these columns' ) {
300 # we now know type, area, and columns
301 # next step is the constraints
302 my $area = $input->param('area');
303 my $type = $input->param('type');
304 my @columns = $input->param('columns');
305 my $column = join( ',', @columns );
311 definitions
=> get_from_dictionary
($area),
312 criteria
=> get_criteria
($area,$input),
313 'cache_expiry' => $input->param('cache_expiry'),
314 'cache_expiry_units' => $input->param('cache_expiry_units'),
315 'public' => $input->param('public'),
319 elsif ( $phase eq 'Choose these criteria' ) {
320 my $area = $input->param('area');
321 my $type = $input->param('type');
322 my $column = $input->param('column');
323 my @definitions = $input->param('definition');
324 my $definition = join (',',@definitions);
325 my @criteria = $input->param('criteria_column');
327 foreach my $crit (@criteria) {
328 my $value = $input->param( $crit . "_value" );
330 # If value is not defined, then it may be range values
331 if (!defined $value) {
333 my $fromvalue = $input->param( "from_" . $crit . "_value" );
334 my $tovalue = $input->param( "to_" . $crit . "_value" );
336 # If the range values are dates
337 if ($fromvalue =~ C4
::Dates
->regexp('syspref') && $tovalue =~ C4
::Dates
->regexp('syspref')) {
338 $fromvalue = C4
::Dates
->new($fromvalue)->output("iso");
339 $tovalue = C4
::Dates
->new($tovalue)->output("iso");
342 if ($fromvalue && $tovalue) {
343 $query_criteria .= " AND $crit >= '$fromvalue' AND $crit <= '$tovalue'";
349 if ($value =~ C4
::Dates
->regexp('syspref')) {
350 $value = C4
::Dates
->new($value)->output("iso");
352 # don't escape runtime parameters, they'll be at runtime
353 if ($value =~ /<<.*>>/) {
354 $query_criteria .= " AND $crit=$value";
356 $query_criteria .= " AND $crit='$value'";
365 'definition' => $definition,
366 'criteriastring' => $query_criteria,
367 'cache_expiry' => $input->param('cache_expiry'),
368 'cache_expiry_units' => $input->param('cache_expiry_units'),
369 'public' => $input->param('public'),
373 my @columns = split( ',', $column );
376 # build structue for use by tmpl_loop to choose columns to order by
377 # need to do something about the order of the order :)
378 # we also want to use the %columns hash to get the plain english names
379 foreach my $col (@columns) {
380 my %total = (name
=> $col);
381 my @selects = map {+{ value
=> $_ }} (qw(sum min max avg count));
382 $total{'select'} = \
@selects;
383 push @total_by, \
%total;
386 $template->param( 'total_by' => \
@total_by );
389 elsif ( $phase eq 'Choose these operations' ) {
390 my $area = $input->param('area');
391 my $type = $input->param('type');
392 my $column = $input->param('column');
393 my $criteria = $input->param('criteria');
394 my $definition = $input->param('definition');
395 my @total_by = $input->param('total_by');
397 foreach my $total (@total_by) {
398 my $value = $input->param( $total . "_tvalue" );
399 $totals .= "$value($total),";
407 'criteriastring' => $criteria,
409 'definition' => $definition,
410 'cache_expiry' => $input->param('cache_expiry'),
411 'public' => $input->param('public'),
415 my @columns = split( ',', $column );
418 # build structue for use by tmpl_loop to choose columns to order by
419 # need to do something about the order of the order :)
420 foreach my $col (@columns) {
421 my %order = (name
=> $col);
422 my @selects = map {+{ value
=> $_ }} (qw(asc desc));
423 $order{'select'} = \
@selects;
424 push @order_by, \
%order;
427 $template->param( 'order_by' => \
@order_by );
430 elsif ( $phase eq 'Build report' ) {
432 # now we have all the info we need and can build the sql
433 my $area = $input->param('area');
434 my $type = $input->param('type');
435 my $column = $input->param('column');
436 my $crit = $input->param('criteria');
437 my $totals = $input->param('totals');
438 my $definition = $input->param('definition');
439 my $query_criteria=$crit;
440 # split the columns up by ,
441 my @columns = split( ',', $column );
442 my @order_by = $input->param('order_by');
445 foreach my $order (@order_by) {
446 my $value = $input->param( $order . "_ovalue" );
447 if ($query_orderby) {
448 $query_orderby .= ",$order $value";
451 $query_orderby = " ORDER BY $order $value";
457 build_query
( \
@columns, $query_criteria, $query_orderby, $area, $totals, $definition );
463 'cache_expiry' => $input->param('cache_expiry'),
464 'public' => $input->param('public'),
468 elsif ( $phase eq 'Save' ) {
469 # Save the report that has just been built
470 my $area = $input->param('area');
471 my $sql = $input->param('sql');
472 my $type = $input->param('type');
478 'cache_expiry' => $input->param('cache_expiry'),
479 'public' => $input->param('public'),
480 'groups_with_subgroups' => groups_with_subgroups
($area), # in case we have a report group that matches area
484 elsif ( $phase eq 'Save Report' ) {
485 # save the sql pasted in by a user
486 my $area = $input->param('area');
487 my $group = $input->param('group');
488 my $subgroup = $input->param('subgroup');
489 my $sql = $input->param('sql');
490 my $name = $input->param('reportname');
491 my $type = $input->param('types');
492 my $notes = $input->param('notes');
493 my $cache_expiry = $input->param('cache_expiry');
494 my $cache_expiry_units = $input->param('cache_expiry_units');
495 my $public = $input->param('public');
496 my $save_anyway = $input->param('save_anyway');
499 # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
500 if( $cache_expiry_units ){
501 if( $cache_expiry_units eq "minutes" ){
503 } elsif( $cache_expiry_units eq "hours" ){
504 $cache_expiry *= 3600; # 60 * 60
505 } elsif( $cache_expiry_units eq "days" ){
506 $cache_expiry *= 86400; # 60 * 60 * 24
509 # 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
510 if( $cache_expiry && $cache_expiry >= 2592000 ){
511 push @errors, {cache_expiry
=> $cache_expiry};
514 create_non_existing_group_and_subgroup
($input, $group, $subgroup);
516 ## FIXME this is AFTER entering a name to save the report under
517 if ($sql =~ /;?\W?(UPDATE|DELETE|DROP|INSERT|SHOW|CREATE)\W/i) {
518 push @errors, {sqlerr
=> $1};
520 elsif ($sql !~ /^(SELECT)/i) {
521 push @errors, {queryerr
=> "No SELECT"};
526 'errors' => \
@errors,
528 'reportname'=> $name,
531 'cache_expiry' => $cache_expiry,
535 # Check defined SQL parameters for authorised value validity
536 my $problematic_authvals = ValidateSQLParameters
($sql);
538 if ( scalar @
$problematic_authvals > 0 && not $save_anyway ) {
539 # There's at least one problematic parameter, report to the
540 # GUI and provide all user input for further actions
544 'subgroup' => $subgroup,
546 'reportname' => $name,
549 'cache_expiry' => $cache_expiry,
550 'cache_expiry_units' => $cache_expiry_units,
552 'problematic_authvals' => $problematic_authvals,
553 'warn_authval_problem' => 1,
557 # No params problem found or asked to save anyway
558 my $id = save_report
( {
559 borrowernumber
=> $borrowernumber,
564 subgroup
=> $subgroup,
567 cache_expiry
=> $cache_expiry,
571 'save_successful' => 1,
572 'reportname' => $name,
579 elsif ($phase eq 'Run this report'){
580 # execute a saved report
581 my $limit = $input->param('limit') || 20;
583 my $report_id = $input->param('reports');
584 my @sql_params = $input->param('sql_params');
586 if ($input->param('page')) {
587 $offset = ($input->param('page') - 1) * $limit;
592 'report_id' => $report_id,
595 my ( $sql, $type, $name, $notes );
596 if (my $report = get_saved_report
($report_id)) {
597 $sql = $report->{savedsql
};
598 $name = $report->{report_name
};
599 $notes = $report->{notes
};
602 # if we have at least 1 parameter, and it's not filled, then don't execute but ask for parameters
603 if ($sql =~ /<</ && !@sql_params) {
604 # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
605 my @split = split /<<|>>/,$sql;
608 for(my $i=0;$i<($#split/2);$i++) {
609 my ($text,$authorised_value) = split /\|/,$split[$i*2+1];
612 if ( not defined $authorised_value ) {
613 # no authorised value input, provide a text box
615 } elsif ( $authorised_value eq "date" ) {
616 # require a date, provide a date picker
619 # defined $authorised_value, and not 'date'
620 my $dbh=C4
::Context
->dbh;
621 my @authorised_values;
623 # builds list, depending on authorised value...
624 if ( $authorised_value eq "branches" ) {
625 my $branches = GetBranchesLoop
();
626 foreach my $thisbranch (@
$branches) {
627 push @authorised_values, $thisbranch->{value
};
628 $authorised_lib{$thisbranch->{value
}} = $thisbranch->{branchname
};
631 elsif ( $authorised_value eq "itemtypes" ) {
632 my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
634 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
635 push @authorised_values, $itemtype;
636 $authorised_lib{$itemtype} = $description;
639 elsif ( $authorised_value eq "cn_source" ) {
640 my $class_sources = GetClassSources
();
641 my $default_source = C4
::Context
->preference("DefaultClassificationSource");
642 foreach my $class_source (sort keys %$class_sources) {
643 next unless $class_sources->{$class_source}->{'used'} or
644 ($class_source eq $default_source);
645 push @authorised_values, $class_source;
646 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
649 elsif ( $authorised_value eq "categorycode" ) {
650 my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
652 while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
653 push @authorised_values, $categorycode;
654 $authorised_lib{$categorycode} = $description;
657 #---- "true" authorised value
660 if ( IsAuthorisedValueCategory
($authorised_value) ) {
662 SELECT authorised_value,lib
663 FROM authorised_values
667 my $authorised_values_sth = $dbh->prepare($query);
668 $authorised_values_sth->execute( $authorised_value);
670 while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
671 push @authorised_values, $value;
672 $authorised_lib{$value} = $lib;
673 # For item location, we show the code and the libelle
674 $authorised_lib{$value} = $lib;
677 # not exists $authorised_value_categories{$authorised_value})
678 push @authval_errors, {'entry' => $text,
679 'auth_val' => $authorised_value };
680 # tell the template there's an error
681 $template->param( auth_val_error
=> 1 );
682 # skip scrolling list creation and params push
688 $input =CGI
::scrolling_list
( # FIXME: factor out scrolling_list
689 -name
=> "sql_params",
690 -id
=> "sql_params_".$labelid,
691 -values => \
@authorised_values,
692 # -default => $value,
693 -labels
=> \
%authorised_lib,
701 push @tmpl_parameters, {'entry' => $text, 'input' => $input, 'labelid' => $labelid };
703 $template->param('sql' => $sql,
705 'sql_params' => \
@tmpl_parameters,
706 'auth_val_errors' => \
@authval_errors,
708 'reports' => $report_id,
711 # OK, we have parameters, or there are none, we run the report
712 # if there were parameters, replace before running
713 # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill
714 my @split = split /<<|>>/,$sql;
716 for(my $i=0;$i<$#split/2;$i++) {
717 my $quoted = C4
::Context
->dbh->quote($sql_params[$i]);
718 # if there are special regexp chars, we must \ them
719 $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
720 $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
722 my ($sth, $errors) = execute_query
($sql, $offset, $limit);
723 my $total = nb_rows
($sql) || 0;
725 die "execute_query failed to return sth for report $report_id: $sql";
727 my $headers= header_cell_loop
($sth);
728 $template->param(header_row
=> $headers);
729 while (my $row = $sth->fetchrow_arrayref()) {
730 my @cells = map { +{ cell
=> $_ } } @
$row;
731 push @rows, { cells
=> \
@cells };
735 my $totpages = int($total/$limit) + (($total % $limit) > 0 ?
1 : 0);
736 my $url = "/cgi-bin/koha/reports/guided_reports.pl?reports=$report_id&phase=Run%20this%20report&limit=$limit";
738 $url = join('&sql_params=', $url, map { URI
::Escape
::uri_escape
($_) } @sql_params);
748 'pagination_bar' => pagination_bar
($url, $totpages, $input->param('page')),
749 'unlimited_total' => $total,
750 'sql_params' => \
@sql_params,
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);