From 9caec6fffb0c037849fc1fa887bc3635f081761b Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 24 Feb 2012 23:29:58 +0000 Subject: [PATCH] Fix for empty spreadsheet dates in XML & OO.o getting a date anyway --- etemplate/inc/class.bo_merge.inc.php | 46 ++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index fead2ed055..057541b984 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -1004,16 +1004,49 @@ abstract class bo_merge */ protected function format_spreadsheet_dates(&$content, $names, &$values, $mimetype) { + if(!in_array($mimetype, array( + 'application/vnd.oasis.opendocument.spreadsheet', // open office calc + 'application/xmlExcel.Sheet', // Excel 2003 + //'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'//Excel WTF + ))) return; + + // Properly format values for spreadsheet + foreach($names as $idx => $field) + { + $key = '$$'.$field.'$$'; + if($values[$key]) + { + $date = new egw_time($values[$key]); + + if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')//Excel WTF + { + $interval = $date->diff(new egw_time('1900-01-00 0:00')); + $values[$key] = $interval->format('%a')+1;// 1900-02-29 did not exist + // 1440 minutes in a day - fractional part + $values[$key] += ($date->format('H') * 60 + $date->format('i'))/1440; + } + else + { + $values[$key] = date('Y-m-d\TH:i:s',egw_time::to($date,'ts')); + } + } + else + { + unset($names[$idx]); + } + } switch($mimetype) { case 'application/vnd.oasis.opendocument.spreadsheet': // open office calc - $format = '/]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>..('.implode('|',$names).')..<\/\3>.?<\/table:table-cell>/s'; + $format = '/]+?)office:value-type="[^"]+"([^>]*?)>.?<([a-z].*?)[^>]*>\$\$('.implode('|',$names).')\$\$<\/\3>.?<\/table:table-cell>/s'; $replacement = '<$3>\$\$$4\$\$'; break; case 'application/xmlExcel.Sheet': // Excel 2003 $format = '/'.preg_quote('','/').'..('.implode('|',$names).')..'.preg_quote('','/').'/'; $replacement = '\$\$$1\$\$'; + break; + case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': break; } if($format && $names) @@ -1034,17 +1067,6 @@ abstract class bo_merge error_log('Backtrack limit exceeded @ ' . ini_get('pcre.backtrack_limit') . ', some cells left as text.'); } } - - // Properly format values for spreadsheet - foreach($names as $field) - { - $key = '$$'.$field.'$$'; - if($values[$key]) - { - $date = new egw_time($values[$key]); - $values[$key] = date('Y-m-d\TH:i:s',egw_time::to($date,'ts')); - } - } } /**