Fixed creation of group by tag for XML report export.
authorNik Okuntseff <support@anuko.com>
Wed, 31 Oct 2018 18:31:50 +0000 (18:31 +0000)
committerNik Okuntseff <support@anuko.com>
Wed, 31 Oct 2018 18:31:50 +0000 (18:31 +0000)
WEB-INF/lib/ttReportHelper.class.php
WEB-INF/templates/footer.tpl
tofile.php

index 7a4ba26..60cac07 100644 (file)
@@ -468,11 +468,6 @@ class ttReportHelper {
     $res = $mdb2->query($sql);
     if (is_a($res, 'PEAR_Error')) die($res->getMessage());
     while ($val = $res->fetchRow()) {
-// TODO: consider writing a function that properly formats a date part in a multi-part key.
-//
-//      if ('date' == $group_by_option) {
-//        $val['group_field'] = ttDateToUserFormat($val['group_field']);
-//      }
       $time = $val['time'] ? sec_to_time_fmt_hm($val['time']) : null;
       $rowLabel = ttReportHelper::makeGroupByLabel($val['group_field'], $options);
       if ($options['show_cost']) {
@@ -1478,6 +1473,25 @@ class ttReportHelper {
     return $group_by_header;
   }
 
+  // makeGroupByXmlTag creates an xml tag for a totals only report using group_by1,
+  // group_by2, and group_by3 values passed in $options.
+  static function makeGroupByXmlTag($options) {
+    if ($options['group_by1'] != null && $options['group_by1'] != 'no_grouping') {
+      // We have group_by1.
+      $tag .= '_'.$options['group_by1'];
+    }
+    if ($options['group_by2'] != null && $options['group_by2'] != 'no_grouping') {
+      // We have group_by2.
+      $tag .= '_'.$options['group_by2'];
+    }
+    if ($options['group_by3'] != null && $options['group_by3'] != 'no_grouping') {
+      // We have group_by3.
+      $tag .= '_'.$options['group_by3'];
+    }
+    $tag = ltrim($tag, '_');
+    return $tag;
+  }
+
   // makeGroupByLabel builds a label for one row in a "Totals only" report of grouped by items.
   // It does one thing: if we are grouping by date, the date format is converted for user.
   static function makeGroupByLabel($key, $options) {
index d8a4447..996c8df 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.18.04.4338 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.04.4339 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index d996098..07bbc11 100644 (file)
@@ -84,12 +84,14 @@ if ('xml' == $type) {
   print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   print "<rows>\n";
 
-  $group_by1 = $bean->getAttribute('group_by1');
   if ($totals_only) {
-    // Totals only report. Print subtotals.
+    // Totals only report.
+    $group_by_tag = ttReportHelper::makeGroupByXmlTag($options);
+
+    // Print subtotals.
     foreach ($subtotals as $subtotal) {
       print "<row>\n";
-      print "\t<".$group_by1."><![CDATA[".$subtotal['name']."]]></".$group_by1.">\n";
+      print "\t<".$group_by_tag."><![CDATA[".$subtotal['name']."]]></".$group_by_tag.">\n";
       if ($bean->getAttribute('chduration')) {
         $val = $subtotal['time'];
         if($val && defined('EXPORT_DECIMAL_DURATION') && isTrue(EXPORT_DECIMAL_DURATION))
@@ -161,7 +163,6 @@ if ('csv' == $type) {
   $bom = chr(239).chr(187).chr(191); // 0xEF 0xBB 0xBF in the beginning of the file is UTF8 BOM.
   print $bom; // Without this Excel does not display UTF8 characters properly.
 
-  $group_by1 = $bean->getAttribute('group_by1');
   if ($totals_only) {
     // Totals only report.
     $group_by_header = ttReportHelper::makeGroupByHeader($options);