X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=reports%2Fdictionary.pl;h=f27ce105cf7ef65ac09eea7536ca80ad6af05250;hb=570372b24ef081aca5bbb8aea8a1462fced14e68;hp=4f94d6944a8b520b89644f8868905f3b280a8781;hpb=16f1fffdd1f5d1c97db0bf664f83496864b7e24d;p=koha_fer diff --git a/reports/dictionary.pl b/reports/dictionary.pl index 4f94d6944a..f27ce105cf 100755 --- a/reports/dictionary.pl +++ b/reports/dictionary.pl @@ -37,11 +37,12 @@ my $input = new CGI; my $referer = $input->referer(); my $phase = $input->param('phase') || 'View Dictionary'; -my $area = $input->param('areas') || ''; -my $no_html = 0; # this will be set if we dont want to print out an html::template -my ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "reports/dictionary.tmpl", +my $definition_name = $input->param('definition_name'); +my $definition_description = $input->param('definition_description'); +my $area = $input->param('area') || ''; +my $no_html = 0; # this will be set if we dont want to print out an html::template +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { template_name => "reports/dictionary.tmpl", query => $input, type => "intranet", authnotrequired => 0, @@ -51,78 +52,71 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ); if ($phase eq 'View Dictionary'){ - # view the dictionary we use to set up abstract variables such as all borrowers over fifty who live in a certain town - my $areas = get_report_areas(); - foreach (@{ $areas }) { - $_->{selected} = 1 if $_->{id} eq $area; # mark active area - } - my $definitions = get_from_dictionary($area); - $template->param( 'areas' => $areas , - 'start_dictionary' => 1, - 'definitions' => $definitions, - ); -} -elsif ($phase eq 'Add New Definition'){ - # display form allowing them to add a new definition - $template->param( 'new_dictionary' => 1, - ); + # view the dictionary we use to set up abstract variables such as all borrowers over fifty who live in a certain town + my $definitions = get_from_dictionary($area); + $template->param( + 'areas'=> areas(), + 'start_dictionary' => 1, + 'definitions' => $definitions, + ); +} elsif ( $phase eq 'Add New Definition' ) { + + # display form allowing them to add a new definition + $template->param( 'new_dictionary' => 1, ); } -elsif ($phase eq 'New Term step 2'){ - # Choosing the area - my $areas = C4::Reports::Guided::get_report_areas(); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - $template->param( 'step_2' => 1, - 'areas' => $areas, - 'definition_name' => $definition_name, - 'definition_description' => $definition_description, - ); +elsif ( $phase eq 'New Term step 2' ) { + + # Choosing the area + $template->param( + 'step_2' => 1, + 'areas' => areas(), + 'definition_name' => $definition_name, + 'definition_description' => $definition_description, + ); } -elsif ($phase eq 'New Term step 3'){ - # Choosing the columns - my $area = $input->param('areas'); - my $columns = get_columns($area,$input); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - $template->param( 'step_3' => 1, - 'area' => $area, - 'columns' => $columns, - 'definition_name' => $definition_name, - 'definition_description' => $definition_description, - ); +elsif ( $phase eq 'New Term step 3' ) { + + # Choosing the columns + my $columns = get_columns( $area, $input ); + $template->param( + 'step_3' => 1, + 'area' => $area, + 'columns' => $columns, + 'definition_name' => $definition_name, + 'definition_description' => $definition_description, + ); } -elsif ($phase eq 'New Term step 4'){ - # Choosing the values - my $area=$input->param('area'); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - my @columns = $input->param('columns'); - my $columnstring = join (',',@columns); - my @column_loop; - foreach my $column (@columns){ - my %tmp_hash; - $tmp_hash{'name'}=$column; - my $type =get_column_type($column); - if ($type eq 'distinct'){ - my $values = get_distinct_values($column); - $tmp_hash{'values'} = $values; - $tmp_hash{'distinct'} = 1; - - } - if ($type eq 'DATE' || $type eq 'DATETIME'){ - $tmp_hash{'date'}=1; - } - if ($type eq 'TEXT' || $type eq 'MEDIUMTEXT'){ - $tmp_hash{'text'}=1; - } -# else { -# warn $type;# -# } - push @column_loop,\%tmp_hash; - } +elsif ( $phase eq 'New Term step 4' ) { + + # Choosing the values + my @columns = $input->param('columns'); + my $columnstring = join( ',', @columns ); + my @column_loop; + foreach my $column (@columns) { + my %tmp_hash; + $tmp_hash{'name'} = $column; + my $type = get_column_type($column); + if ( $type eq 'distinct' ) { + my $values = get_distinct_values($column); + $tmp_hash{'values'} = $values; + $tmp_hash{'distinct'} = 1; + + } + if ( $type eq 'DATE' || $type eq 'DATETIME' ) { + $tmp_hash{'date'} = 1; + } + if ($type eq 'TEXT' || $type eq 'MEDIUMTEXT'){ + $tmp_hash{'text'} = 1; + } + + # else { + # warn $type;# + # } + push @column_loop, \%tmp_hash; + } $template->param( 'step_4' => 1, 'area' => $area, @@ -134,83 +128,78 @@ elsif ($phase eq 'New Term step 4'){ ); } -elsif ($phase eq 'New Term step 5'){ - # Confirmation screen - my $areas = C4::Reports::Guided::get_report_areas(); - my $area = $input->param('area'); - my $areaname = $areas->[$area - 1]->{'name'}; - my $columnstring = $input->param('columnstring'); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - my @criteria = $input->param('criteria_column'); - my $query_criteria; - my @criteria_loop; - foreach my $crit (@criteria) { - my $value = $input->param( $crit . "_value" ); - if ($value) { - my %tmp_hash; - $tmp_hash{'name'}=$crit; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; - if ($value =~ C4::Dates->regexp(C4::Context->preference('dateformat'))) { - my $date = C4::Dates->new($value); - $value = $date->output("iso"); - } - $query_criteria .= " AND $crit='$value'"; - } - $value = $input->param( $crit . "_start_value" ); - if ($value) { - my %tmp_hash; - $tmp_hash{'name'}="$crit Start"; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; - if ($value =~ C4::Dates->regexp(C4::Context->preference('dateformat'))) { - my $date = C4::Dates->new($value); - $value = $date->output("iso"); - } - $query_criteria .= " AND $crit >= '$value'"; - } - $value = $input->param( $crit . "_end_value" ); - if ($value) { - my %tmp_hash; - $tmp_hash{'name'}="$crit End"; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; - if ($value =~ C4::Dates->regexp(C4::Context->preference('dateformat'))) { - my $date = C4::Dates->new($value); - $value = $date->output("iso"); - } - $query_criteria .= " AND $crit <= '$value'"; - } - } - $template->param( 'step_5' => 1, - 'area' => $area, - 'areaname' => $areaname, - 'definition_name' => $definition_name, - 'definition_description' => $definition_description, - 'query' => $query_criteria, - 'columnstring' => $columnstring, - 'criteria_loop' => \@criteria_loop, - ); +elsif ( $phase eq 'New Term step 5' ) { + # Confirmation screen + my $columnstring = $input->param('columnstring'); + my @criteria = $input->param('criteria_column'); + my $query_criteria; + my @criteria_loop; + + foreach my $crit (@criteria) { + my $value = $input->param( $crit . "_value" ); + if ($value) { + my %tmp_hash; + $tmp_hash{'name'} = $crit; + $tmp_hash{'value'} = $value; + push @criteria_loop, \%tmp_hash; + if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) { + my $date = C4::Dates->new($value); + $value = $date->output("iso"); + } + $query_criteria .= " AND $crit='$value'"; + } + $value = $input->param( $crit . "_start_value" ); + if ($value) { + my %tmp_hash; + $tmp_hash{'name'} = "$crit Start"; + $tmp_hash{'value'} = $value; + push @criteria_loop, \%tmp_hash; + if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) { + my $date = C4::Dates->new($value); + $value = $date->output("iso"); + } + $query_criteria .= " AND $crit >= '$value'"; + } + $value = $input->param( $crit . "_end_value" ); + if ($value) { + my %tmp_hash; + $tmp_hash{'name'} = "$crit End"; + $tmp_hash{'value'} = $value; + push @criteria_loop, \%tmp_hash; + if ( $value =~ C4::Dates->regexp( C4::Context->preference('dateformat') ) ) { + my $date = C4::Dates->new($value); + $value = $date->output("iso"); + } + $query_criteria .= " AND $crit <= '$value'"; + } + } + my %report_areas = map @$_, get_report_areas(); + $template->param( + 'step_5' => 1, + 'area' => $area, + 'areaname' => $report_areas{$area}, + 'definition_name' => $definition_name, + 'definition_description' => $definition_description, + 'query' => $query_criteria, + 'columnstring' => $columnstring, + 'criteria_loop' => \@criteria_loop, + ); } -elsif ($phase eq 'New Term step 6'){ - # Saving - my $area = $input->param('area'); - my $definition_name=$input->param('definition_name'); - my $definition_description=$input->param('definition_description'); - my $sql=$input->param('sql'); - save_dictionary($definition_name,$definition_description,$sql,$area); - $no_html=1; - print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary"); - +elsif ( $phase eq 'New Term step 6' ) { + # Saving + my $area = $input->param('area'); + my $sql = $input->param('sql'); + save_dictionary( $definition_name, $definition_description, $sql, $area ); + $no_html = 1; + print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary"); + +} elsif ( $phase eq 'Delete Definition' ) { + $no_html = 1; + my $id = $input->param('id'); + delete_definition($id); + print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary"); } -elsif ($phase eq 'Delete Definition'){ - $no_html=1; - my $id = $input->param('id'); - delete_definition($id); - print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary"); - } $template->param( 'referer' => $referer ); @@ -218,3 +207,16 @@ $template->param( 'referer' => $referer ); if (!$no_html){ output_html_with_http_headers $input, $cookie, $template->output; } + +sub areas { + my $areas = get_report_areas(); + my @a; + foreach (@$areas) { + push @a, { + id => $_->[0], + name => $_->[1], + selected => ($_->[0] eq $area), + }; + } + return \@a; +}