From 35b3df2e9558677f832f52bdb5b11aac6ef8e53c Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Mon, 4 Aug 2008 10:15:18 -0500 Subject: [PATCH] kohabug 1679 & 1680 Fixes date formatting in guided reports wizard This patch corrects date formatting when defining dictionary definitions in the guided reports wizard so that dates display according to syspref. Date formating is also corrected in the report creation section of the guided reports wizard. It also corrects a javascript bug which caused some of the calander widgets not to function properly. Signed-off-by: Galen Charlton Signed-off-by: Joshua Ferraro --- C4/Reports.pm | 25 ++++++---- .../prog/en/modules/reports/dictionary.tmpl | 8 ++-- .../modules/reports/guided_reports_start.tmpl | 9 ++-- reports/dictionary.pl | 48 ++++++++++++------- reports/guided_reports.pl | 30 +++++++----- 5 files changed, 72 insertions(+), 48 deletions(-) diff --git a/C4/Reports.pm b/C4/Reports.pm index 376196aac6..6be341acba 100644 --- a/C4/Reports.pm +++ b/C4/Reports.pm @@ -340,18 +340,23 @@ sub execute_query { } my $sth = $dbh->prepare($sql); $sth->execute(); - my $colnames=$sth->{'NAME'}; - my @results; - my $row; - my %temphash; - $row = join ('',@$colnames); - $row = "$row"; - $temphash{'row'} = $row; - push @results, \%temphash; + my $colnames=$sth->{'NAME'}; + my @results; + my $row; + my %temphash; + $row = join ('',@$colnames); + $row = "$row"; + $temphash{'row'} = $row; + push @results, \%temphash; my $string; - my @xmlarray; + my @xmlarray; while ( my @data = $sth->fetchrow_array() ) { - + # if the field is a date field, it needs formatting + foreach my $data (@data) { + next unless $data =~ C4::Dates->regexp("iso"); + my $date = C4::Dates->new($data, "iso"); + $data = $date->output(); + } # tabular my %temphash; my $row = join( '', @data ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl index 21d2c8e148..9e217327f3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/dictionary.tmpl @@ -204,7 +204,7 @@ Filter by area -
Tabular: -/../img/reports-tabular-graphic.gif" alt="" />
+
"> />/lib/calendar/cal.gif" id="buttonfrom" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" /> diff --git a/reports/dictionary.pl b/reports/dictionary.pl index 56949aa5b6..7edd1d4295 100755 --- a/reports/dictionary.pl +++ b/reports/dictionary.pl @@ -22,6 +22,7 @@ use C4::Auth; use CGI; use C4::Output; use C4::Reports; +use C4::Dates qw( DHTMLcalendar ); =head1 NAME @@ -127,7 +128,7 @@ elsif ($phase eq 'New Term step 4'){ 'definition_description' => $definition_description, 'columns' => \@column_loop, 'columnstring' => $columnstring, - + 'DHTMLcalendar_dateformat' => C4::Dates->DHTMLcalendar(), ); } @@ -145,28 +146,39 @@ elsif ($phase eq 'New Term step 5'){ foreach my $crit (@criteria) { my $value = $input->param( $crit . "_value" ); if ($value) { - $query_criteria .= " AND $crit='$value'"; - my %tmp_hash; - $tmp_hash{'name'}=$crit; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; + 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) { - $query_criteria .= " AND $crit > '$value'"; - my %tmp_hash; - $tmp_hash{'name'}="$crit Start"; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; + 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) { - $query_criteria .= " AND $crit <= '$value'"; - my %tmp_hash; - $tmp_hash{'name'}="$crit End"; - $tmp_hash{'value'} = $value; - push @criteria_loop,\%tmp_hash; + 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, @@ -195,7 +207,7 @@ elsif ($phase eq 'Delete Definition'){ $no_html=1; my $id = $input->param('id'); delete_definition($id); - print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=View%20Dictionary"); + print $input->redirect("/cgi-bin/koha/reports/dictionary.pl?phase=View%20Dictionary"); } $template->param( 'referer' => $referer ); diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl index 140f48a349..793eaa2868 100755 --- a/reports/guided_reports.pl +++ b/reports/guided_reports.pl @@ -22,6 +22,8 @@ use CGI; use C4::Reports; use C4::Auth; use C4::Output; +use C4::Dates qw( DHTMLcalendar ); + =head1 NAME Script to control the guided report creation @@ -172,6 +174,10 @@ elsif ( $phase eq 'Choose these criteria' ) { foreach my $crit (@criteria) { my $value = $input->param( $crit . "_value" ); if ($value) { + if ($value =~ C4::Dates->regexp(C4::Context->preference('dateformat'))) { + my $date = C4::Dates->new($value); + $value = $date->output("iso"); + } $query_criteria .= " AND $crit='$value'"; } } @@ -181,7 +187,7 @@ elsif ( $phase eq 'Choose these criteria' ) { 'area' => $area, 'type' => $type, 'column' => $column, - 'definition' => $definition, + 'definition' => $definition, 'criteriastring' => $query_criteria, ); @@ -239,7 +245,7 @@ elsif ( $phase eq 'Choose These Operations' ) { 'column' => $column, 'criteriastring' => $criteria, 'totals' => $totals, - 'definition' => $definition, + 'definition' => $definition, ); # get columns @@ -331,7 +337,7 @@ elsif ( $phase eq 'Execute' ) { my $results = execute_query($sql,$type); $template->param( 'results' => $results, - 'sql' => $sql, + 'sql' => $sql, 'execute' => 1 ); } @@ -341,13 +347,13 @@ elsif ($phase eq 'Run this report'){ my $report = $input->param('reports'); my ($sql,$type,$name,$notes) = get_saved_report($report); my $results = execute_query($sql,$type); - $template->param( - 'results' => $results, - 'sql' => $sql, - 'execute' => 1, - 'name' => $name, - 'notes' => $notes, - ); + $template->param( + 'results' => $results, + 'sql' => $sql, + 'execute' => 1, + 'name' => $name, + 'notes' => $notes, + ); } elsif ($phase eq 'Export'){ @@ -389,7 +395,9 @@ elsif ($phase eq 'Save Compound'){ } -$template->param( 'referer' => $referer ); +$template->param( 'referer' => $referer, + 'DHTMLcalendar_dateformat' => C4::Dates->DHTMLcalendar(), + ); if (!$no_html){ -- 2.39.5