[Koha-patches] [PATCH] kohabug 1679 & 1680 Fixes date formatting in guided reports wizard

Galen Charlton galen.charlton at liblime.com
Mon Aug 4 17:15:18 CEST 2008


From: Chris Nighswonger <chris.nighswonger at liblime.com>

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 <galen.charlton at liblime.com>
---
 C4/Reports.pm                                      |   25 ++++++----
 .../prog/en/modules/reports/dictionary.tmpl        |    8 ++--
 .../en/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 376196a..6be341a 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 ('</th><th>',@$colnames);
-	$row = "<tr><th>$row</th></tr>";
-	$temphash{'row'} = $row;
-	push @results, \%temphash;
+    my $colnames=$sth->{'NAME'};
+    my @results;
+    my $row;
+    my %temphash;
+    $row = join ('</th><th>',@$colnames);
+    $row = "<tr><th>$row</th></tr>";
+    $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( '</td><td>', @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 21d2c8e..9e21732 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 <select name="areas">
 <script type="text/javascript">                            
 Calendar.setup({             
 inputField     : "<!-- TMPL_VAR NAME="name" -->_start_value",    
-ifFormat       : "%Y-%m-%d",                         
+ifFormat       : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
 button         : "buttonfrom1",                            
 align          : "Tl"                  
 });
@@ -215,12 +215,12 @@ align          : "Tl"
 <td>End of date range</td>
 <td>
 <input type="text" size="10" id="<!-- TMPL_VAR NAME="name" -->_end_value" name="<!-- TMPL_VAR NAME="name" -->_end_value" value="" />      
-<img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="buttonfrom1" style="cursor: pointer;"  />    
+<img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="buttonfrom2" style="cursor: pointer;"  />
 <script type="text/javascript">                            
 Calendar.setup({             
 inputField     : "<!-- TMPL_VAR NAME="name" -->_end_value",    
-ifFormat       : "%Y-%m-%d",                         
-button         : "buttonfrom1",                            
+ifFormat       : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
+button         : "buttonfrom2",
 align          : "Tl"                  
 });
 </script>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl
index 65c61e5..b9c01b0 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tmpl
@@ -152,8 +152,7 @@ reports</p>
 <input type="submit" name="submit" value="Next &gt;&gt;" /></fieldset>
 </form>
 </div>
-<div class="yui-gb"><div class="yui-u first">Tabular:
-<img src="<!-- TMPL_VAR name="themelang" -->/../img/reports-tabular-graphic.gif" alt="" /></div>
+<div class="yui-gb"><div class="yui-u first"></div>
 
 <!--- Summary and Matrix reports have not yet been implemented-->
 <!--<div class="yui-u">Summary:
@@ -230,9 +229,9 @@ NAME="name" -->"><!-- TMPL_VAR NAME="description" --> </label>
 /><img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="buttonfrom<!-- TMPL_VAR NAME="name" -->" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />                 
 <script type="text/javascript">   
 Calendar.setup({  
-inputField     : "<!-- TMPL_VAR NAME="name" -->_value",                               
-ifFormat       : "%Y-%m-%d",                               
-button         : "buttonfrom<!-- TMPL_VAR NAME="name" -->",                               
+inputField     : "<!-- TMPL_VAR NAME="name" -->_value",
+ifFormat       : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
+button         : "buttonfrom<!-- TMPL_VAR NAME="name" -->",
 align          : "Tl" 
 });     
 </script>          
diff --git a/reports/dictionary.pl b/reports/dictionary.pl
index 56949aa..7edd1d4 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 140f48a..793eaa2 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){
-- 
1.5.5.GIT




More information about the Koha-patches mailing list