Improved new export-import by adding custom field options.
authorNik Okuntseff <support@anuko.com>
Sun, 11 Nov 2018 13:25:11 +0000 (13:25 +0000)
committerNik Okuntseff <support@anuko.com>
Sun, 11 Nov 2018 13:25:11 +0000 (13:25 +0000)
.gitignore
WEB-INF/lib/ttGroupExportHelper.class.php
WEB-INF/lib/ttOrgImportHelper.class.php
WEB-INF/templates/footer.tpl

index 9bfa047..dc348cf 100644 (file)
@@ -1,5 +1,6 @@
 config.php
 WEB-INF/templates_c/*.*
+WEB-INF/templates_c/import_*
 WEB-INF/lib/tcpdf/
 nbproject/
 upload/
index 1b7e74a..f1ea228 100644 (file)
@@ -399,6 +399,18 @@ class ttGroupExportHelper {
     fwrite($this->file, $this->indentation."  </custom_fields>\n");
     unset($custom_fields);
 
+    // Write custom field options.
+    fwrite($this->file, $this->indentation."  <custom_field_options>\n");
+    foreach ($custom_field_options as $option) {
+      $custom_field_option_part = $this->indentation.'    '."<custom_field_option id=\"".$this->customFieldOptionMap[$option['id']]."\"";
+      $custom_field_option_part .= " field_id=\"".$this->customFieldMap[$option['field_id']]."\"";
+      $custom_field_option_part .= " value=\"".htmlentities($option['value'])."\"";
+      $custom_field_option_part .= "></custom_field_option>\n";
+      fwrite($this->file, $custom_field_option_part);
+    }
+    fwrite($this->file, $this->indentation."  </custom_field_options>\n");
+    unset($custom_field_options);
+
     // Call self recursively for all subgroups.
     foreach ($this->subgroups as $subgroup) {
       $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.'  ');
index 2cb6934..9c39810 100644 (file)
@@ -336,6 +336,26 @@ class ttOrgImportHelper {
           $this->currentGroupCustomFieldMap[$attrs['ID']] = $custom_field_id;
         } else $this->errors->add($i18n->get('error.db'));
       }
+
+      if ($name == 'CUSTOM_FIELD_OPTIONS') {
+        // If we get here, we have to recycle $currentGroupCustomFieldOptionMap.
+        unset($this->currentGroupCustomFieldOptionMap);
+        $this->currentGroupCustomFieldOptionMap = array();
+        // Custom field option map is reconstructed after processing <custom_field_option> elements in XML. See below.
+      }
+
+      if ($name == 'CUSTOM_FIELD_OPTION') {
+        // We get here when processing <custom_field_option> tags for the current group.
+        $custom_field_option_id = ttCustomFieldHelper::insertOption(array(
+          // 'group_id' => $this->current_group_id, TODO: add this when group_id field is added to the table.
+          // 'org_id' => $this->org_id, TODO: add this when org_id field is added to the table.
+          'field_id' => $this->currentGroupCustomFieldMap[$attrs['FIELD_ID']],
+          'value' => $attrs['VALUE']));
+        if ($custom_field_option_id) {
+          // Add a mapping.
+          $this->currentGroupCustomFieldOptionMap[$attrs['ID']] = $custom_field_option_id;
+        } else $this->errors->add($i18n->get('error.db'));
+      }
     }
   }
 
index 4e17b95..bd9cdf5 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.12.4412 | 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.12.4413 | 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>