Fixed export-import to include group descriptions.
[timetracker.git] / WEB-INF / lib / ttGroupExportHelper.class.php
1 <?php
2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
10 // |
11 // | There are only two ways to violate the license:
12 // |
13 // | 1. To redistribute this code in source form, with the copyright
14 // |    notice or license removed or altered. (Distributing in compiled
15 // |    forms without embedded copyright notices is permitted).
16 // |
17 // | 2. To redistribute modified versions of this code in *any* form
18 // |    that bears insufficient indications that the modifications are
19 // |    not the work of the original author(s).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 // ttGroupExportHelper - this class is used to write data for a single group
30 // to a file. When group contains other groups, it reuses itself recursively.
31 class ttGroupExportHelper {
32
33   var $group_id = null;     // Group we are exporting.
34   var $file     = null;     // File to write to.
35   var $indentation = null;  // A string consisting of a number of spaces.
36   var $subgroups = array(); // Immediate subgroups.
37
38   // The following arrays are maps between entity ids in the file versus the database.
39   // We write to the file sequentially (1,2,3...) while in the database the entities have different ids.
40   var $userMap    = array();
41   var $roleMap    = array();
42   var $taskMap    = array();
43   var $projectMap = array();
44   var $clientMap  = array();
45   var $invoiceMap = array();
46   var $logMap     = array();
47   var $customFieldMap = array();
48   var $customFieldOptionMap = array();
49   var $favReportMap = array();
50
51   // Constructor.
52   function __construct($group_id, $file, $indentation) {
53     global $user;
54
55     $this->group_id = $group_id;
56     $this->file = $file;
57     $this->indentation = $indentation;
58
59     // Build a list of subgroups.
60     $mdb2 = getConnection();
61     $sql =  "select id from tt_groups".
62             " where status = 1 and parent_id = $this->group_id and org_id = $user->org_id";
63     $res = $mdb2->query($sql);
64     if (!is_a($res, 'PEAR_Error')) {
65       while ($val = $res->fetchRow()) {
66         $this->subgroups[] = $val;
67       }
68     }
69   }
70
71   // getGroupAttrs obtains group attributes for export.
72   private function getGroupAttrs() {
73     global $user;
74     $mdb2 = getConnection();
75
76     $sql =  "select * from tt_groups".
77             " where status = 1 and id = $this->group_id and org_id = $user->org_id";
78     $res = $mdb2->query($sql);
79     if (!is_a($res, 'PEAR_Error')) {
80       $val = $res->fetchRow();
81     }
82     return $val;
83   }
84
85   // The getUsers obtains all users in group for the purpose of export.
86   private function getUsers() {
87     global $user;
88     $mdb2 = getConnection();
89     $sql = "select u.*, r.rank from tt_users u left join tt_roles r on (u.role_id = r.id)".
90       " where u.group_id = $this->group_id and u.org_id = $user->org_id order by upper(u.name)"; // Note: deleted users are included.
91     $res = $mdb2->query($sql);
92     $result = array();
93     if (!is_a($res, 'PEAR_Error')) {
94       while ($val = $res->fetchRow()) {
95         $result[] = $val;
96       }
97       return $result;
98     }
99     return false;
100   }
101
102   // getRecordsFromTable - obtains all fields from a given table for a group.
103   function getRecordsFromTable($table_name) {
104     global $user;
105     $mdb2 = getConnection();
106
107     $result = array();
108     $sql = "select * from $table_name where group_id = $this->group_id and org_id = $user->org_id";
109     $res = $mdb2->query($sql);
110     $result = array();
111     if (!is_a($res, 'PEAR_Error')) {
112       while ($val = $res->fetchRow()) {
113         $result[] = $val;
114       }
115       return $result;
116     }
117     return false;
118   }
119
120   // writeData writes group data into file.
121   function writeData() {
122
123     // Write group info.
124     $group = $this->getGroupAttrs();
125     $group_part = "<group name=\"".htmlspecialchars($group['name'])."\"";
126     $group_part .= " description=\"".htmlspecialchars($group['description'])."\"";
127     $group_part .= " currency=\"".htmlspecialchars($group['currency'])."\"";
128     $group_part .= " decimal_mark=\"".$group['decimal_mark']."\"";
129     $group_part .= " lang=\"".$group['lang']."\"";
130     $group_part .= " date_format=\"".$group['date_format']."\"";
131     $group_part .= " time_format=\"".$group['time_format']."\"";
132     $group_part .= " week_start=\"".$group['week_start']."\"";
133     $group_part .= " tracking_mode=\"".$group['tracking_mode']."\"";
134     $group_part .= " project_required=\"".$group['project_required']."\"";
135     $group_part .= " task_required=\"".$group['task_required']."\"";
136     $group_part .= " record_type=\"".$group['record_type']."\"";
137     $group_part .= " bcc_email=\"".$group['bcc_email']."\"";
138     $group_part .= " allow_ip=\"".$group['allow_ip']."\"";
139     $group_part .= " password_complexity=\"".$group['password_complexity']."\"";
140     $group_part .= " plugins=\"".$group['plugins']."\"";
141     $group_part .= " lock_spec=\"".$group['lock_spec']."\"";
142     $group_part .= " workday_minutes=\"".$group['workday_minutes']."\"";
143     $group_part .= " custom_logo=\"".$group['custom_logo']."\"";
144     $group_part .= " config=\"".$group['config']."\"";
145     $group_part .= ">\n";
146
147     // Write group info.
148     fwrite($this->file, $this->indentation.$group_part);
149     unset($group);
150     unset($group_part);
151
152     // Prepare user map.
153     $users = $this->getUsers();
154     foreach ($users as $key=>$user_item)
155       $this->userMap[$user_item['id']] = $key + 1;
156
157     // Prepare role map.
158     $roles = $this->getRecordsFromTable('tt_roles');
159     foreach ($roles as $key=>$role_item)
160       $this->roleMap[$role_item['id']] = $key + 1;
161
162     // Prepare task map.
163     $tasks = $this->getRecordsFromTable('tt_tasks');
164     foreach ($tasks as $key=>$task_item)
165       $this->taskMap[$task_item['id']] = $key + 1;
166
167     // Prepare project map.
168     $projects = $this->getRecordsFromTable('tt_projects');
169     foreach ($projects as $key=>$project_item)
170       $this->projectMap[$project_item['id']] = $key + 1;
171
172     // Prepare client map.
173     $clients = $this->getRecordsFromTable('tt_clients');
174     foreach ($clients as $key=>$client_item)
175       $this->clientMap[$client_item['id']] = $key + 1;
176
177     // Prepare invoice map.
178     $invoices = ttTeamHelper::getAllInvoices();
179     foreach ($invoices as $key=>$invoice_item)
180       $this->invoiceMap[$invoice_item['id']] = $key + 1;
181
182     // Prepare custom fields map.
183     $custom_fields = ttTeamHelper::getAllCustomFields($this->group_id);
184     foreach ($custom_fields as $key=>$custom_field)
185       $this->customFieldMap[$custom_field['id']] = $key + 1;
186
187     // Prepare custom field options map.
188     $custom_field_options = ttTeamHelper::getAllCustomFieldOptions($this->group_id);
189     foreach ($custom_field_options as $key=>$option)
190       $this->customFieldOptionMap[$option['id']] = $key + 1;
191
192     // Prepare favorite report map.
193     $fav_reports = $this->getRecordsFromTable('tt_fav_reports');
194     foreach ($fav_reports as $key=>$fav_report)
195       $this->favReportMap[$fav_report['id']] = $key + 1;
196
197     // Write roles.
198     fwrite($this->file, $this->indentation."  <roles>\n");
199     foreach ($roles as $role) {
200       $role_part = $this->indentation.'    '."<role id=\"".$this->roleMap[$role['id']]."\"";
201       $role_part .= " name=\"".htmlspecialchars($role['name'])."\"";
202       $role_part .= " description=\"".htmlspecialchars($role['description'])."\"";
203       $role_part .= " rank=\"".$role['rank']."\"";
204       $role_part .= " rights=\"".htmlspecialchars($role['rights'])."\"";
205       $role_part .= " status=\"".$role['status']."\"";
206       $role_part .= "></role>\n";
207       fwrite($this->file, $role_part);
208     }
209     fwrite($this->file, $this->indentation."  </roles>\n");
210     unset($roles);
211     unset($role_part);
212
213     // Write tasks.
214     fwrite($this->file, $this->indentation."  <tasks>\n");
215     foreach ($tasks as $task) {
216       $task_part = $this->indentation.'    '."<task id=\"".$this->taskMap[$task['id']]."\"";
217       $task_part .= " name=\"".htmlspecialchars($task['name'])."\"";
218       $task_part .= " description=\"".htmlspecialchars($task['description'])."\"";
219       $task_part .= " status=\"".$task['status']."\"";
220       $task_part .= "></task>\n";
221       fwrite($this->file, $task_part);
222     }
223     fwrite($this->file, $this->indentation."  </tasks>\n");
224     unset($tasks);
225     unset($task_part);
226
227     // Write projects.
228     fwrite($this->file, $this->indentation."  <projects>\n");
229     foreach ($projects as $project_item) {
230       $tasks_str = null;
231       if($project_item['tasks']){
232         $tasks = explode(',', $project_item['tasks']);
233         $tasks_mapped = array();
234         foreach ($tasks as $item)
235           $tasks_mapped[] = $this->taskMap[$item];
236         $tasks_str = implode(',', $tasks_mapped);
237       }
238       $project_part = $this->indentation.'    '."<project id=\"".$this->projectMap[$project_item['id']]."\"";
239       $project_part .= " name=\"".htmlspecialchars($project_item['name'])."\"";
240       $project_part .= " description=\"".htmlspecialchars($project_item['description'])."\"";
241       $project_part .= " tasks=\"".$tasks_str."\"";
242       $project_part .= " status=\"".$project_item['status']."\"";
243       $project_part .= "></project>\n";
244       fwrite($this->file, $project_part);
245     }
246     fwrite($this->file, $this->indentation."  </projects>\n");
247     unset($projects);
248     unset($project_part);
249
250     // Write clients.
251     fwrite($this->file, $this->indentation."  <clients>\n");
252     foreach ($clients as $client_item) {
253       if($client_item['projects']){
254         $projects_db = explode(',', $client_item['projects']);
255         $projects_mapped = array();
256         foreach ($projects_db as $item)
257           $projects_mapped[] = $this->projectMap[$item];
258         $projects_str = implode(',', $projects_mapped);
259       }
260       $client_part = $this->indentation.'    '."<client id=\"".$this->clientMap[$client_item['id']]."\"";
261       $client_part .= " name=\"".htmlspecialchars($client_item['name'])."\"";
262       $client_part .= " address=\"".htmlspecialchars($client_item['address'])."\"";
263       $client_part .= " tax=\"".$client_item['tax']."\"";
264       $client_part .= " projects=\"".$projects_str."\"";
265       $client_part .= " status=\"".$client_item['status']."\"";
266       $client_part .= "></client>\n";
267       fwrite($this->file, $client_part);
268     }
269     fwrite($this->file, $this->indentation."  </clients>\n");
270     unset($clients);
271     unset($client_part);
272
273     // Write users.
274     fwrite($this->file, $this->indentation."  <users>\n");
275     foreach ($users as $user_item) {
276       $role_id = $user_item['rank'] == 512 ? 0 : $this->roleMap[$user_item['role_id']]; // Special role_id 0 (not null) for top manager.
277       $user_part = $this->indentation.'    '."<user id=\"".$this->userMap[$user_item['id']]."\"";
278       $user_part .= " name=\"".htmlspecialchars($user_item['name'])."\"";
279       $user_part .= " login=\"".htmlspecialchars($user_item['login'])."\"";
280       $user_part .= " password=\"".$user_item['password']."\"";
281       $user_part .= " role_id=\"".$role_id."\"";
282       $user_part .= " client_id=\"".$this->clientMap[$user_item['client_id']]."\"";
283       $user_part .= " rate=\"".$user_item['rate']."\"";
284       $user_part .= " email=\"".$user_item['email']."\"";
285       $user_part .= " status=\"".$user_item['status']."\"";
286       $user_part .= "></user>\n";
287       fwrite($this->file, $user_part);
288     }
289     fwrite($this->file, $this->indentation."  </users>\n");
290     unset($users);
291     unset($user_part);
292
293     // Write user to project binds.
294     fwrite($this->file, $this->indentation."  <user_project_binds>\n");
295     $user_binds = ttTeamHelper::getUserToProjectBinds($this->group_id);
296     foreach ($user_binds as $bind) {
297       $user_id = $this->userMap[$bind['user_id']];
298       $project_id = $this->projectMap[$bind['project_id']];
299       $bind_part = $this->indentation.'    '."<user_project_bind user_id=\"".$user_id."\"";
300       $bind_part .= " project_id=\"".$project_id."\"";
301       $bind_part .= " rate=\"".$bind['rate']."\"";
302       $bind_part .= " status=\"".$bind['status']."\"";
303       $bind_part .= "></user_project_bind>\n";
304       fwrite($this->file, $bind_part);
305     }
306     fwrite($this->file, $this->indentation."  </user_project_binds>\n");
307     unset($user_binds);
308     unset($bind_part);
309
310     // Write invoices.
311     fwrite($this->file, $this->indentation."  <invoices>\n");
312     foreach ($invoices as $invoice_item) {
313       $invoice_part = $this->indentation.'    '."<invoice id=\"".$this->invoiceMap[$invoice_item['id']]."\"";
314       $invoice_part .= " name=\"".htmlspecialchars($invoice_item['name'])."\"";
315       $invoice_part .= " date=\"".$invoice_item['date']."\"";
316       $invoice_part .= " client_id=\"".$this->clientMap[$invoice_item['client_id']]."\"";
317       $invoice_part .= " status=\"".$invoice_item['status']."\"";
318       $invoice_part .= "></invoice>\n";
319       fwrite($this->file, $invoice_part);
320     }
321     fwrite($this->file, $this->indentation."  </invoices>\n");
322     unset($invoices);
323     unset($invoice_part);
324
325     // Write time log entries and build logMap at the same time.
326     fwrite($this->file, $this->indentation."  <log>\n");
327     $key = 0;
328     foreach ($this->userMap as $key => $value) {
329       $user_id = $key;
330       $records = ttTimeHelper::getAllRecords($user_id);
331       foreach ($records as $record) {
332         $key++;
333         $this->logMap[$record['id']] = $key;
334         $log_part = $this->indentation.'    '."<log_item id=\"$key\"";
335         $log_part .= " user_id=\"".$this->userMap[$record['user_id']]."\"";
336         $log_part .= " date=\"".$record['date']."\"";
337         $log_part .= " start=\"".$record['start']."\"";
338         $log_part .= " finish=\"".$record['finish']."\"";
339         $log_part .= " duration=\"".($record['start']?"":$record['duration'])."\"";
340         $log_part .= " client_id=\"".$this->clientMap[$record['client_id']]."\"";
341         $log_part .= " project_id=\"".$this->projectMap[$record['project_id']]."\"";
342         $log_part .= " task_id=\"".$this->taskMap[$record['task_id']]."\"";
343         $log_part .= " invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\"";
344         $log_part .= " comment=\"".htmlspecialchars($record['comment'])."\"";
345         $log_part .= " billable=\"".$record['billable']."\"";
346         $log_part .= " paid=\"".$record['paid']."\"";
347         $log_part .= " status=\"".$record['status']."\"";
348         $log_part .= "></log_item>\n";
349         fwrite($this->file, $log_part);
350       }
351     }
352     fwrite($this->file, $this->indentation."  </log>\n");
353     unset($records);
354     unset($log_part);
355
356     // Write custom fields.
357     fwrite($this->file, $this->indentation."  <custom_fields>\n");
358     foreach ($custom_fields as $custom_field) {
359       $custom_field_part = $this->indentation.'    '."<custom_field id=\"".$this->customFieldMap[$custom_field['id']]."\"";
360       $custom_field_part .= " type=\"".$custom_field['type']."\"";
361       $custom_field_part .= " label=\"".htmlspecialchars($custom_field['label'])."\"";
362       $custom_field_part .= " required=\"".$custom_field['required']."\"";
363       $custom_field_part .= " status=\"".$custom_field['status']."\"";
364       $custom_field_part .= "></custom_field>\n";
365       fwrite($this->file, $custom_field_part);
366     }
367     fwrite($this->file, $this->indentation."  </custom_fields>\n");
368     unset($custom_fields);
369     unset($custom_field_part);
370
371     // Write custom field options.
372     fwrite($this->file, $this->indentation."  <custom_field_options>\n");
373     foreach ($custom_field_options as $option) {
374       $custom_field_option_part = $this->indentation.'    '."<custom_field_option id=\"".$this->customFieldOptionMap[$option['id']]."\"";
375       $custom_field_option_part .= " field_id=\"".$this->customFieldMap[$option['field_id']]."\"";
376       $custom_field_option_part .= " value=\"".htmlspecialchars($option['value'])."\"";
377       $custom_field_option_part .= "></custom_field_option>\n";
378       fwrite($this->file, $custom_field_option_part);
379     }
380     fwrite($this->file, $this->indentation."  </custom_field_options>\n");
381     unset($custom_field_options);
382     unset($custom_field_option_part);
383
384     // Write custom field log.
385     $custom_field_log = ttTeamHelper::getCustomFieldLog($this->group_id);
386     fwrite($this->file, $this->indentation."  <custom_field_log>\n");
387     foreach ($custom_field_log as $entry) {
388       $custom_field_log_part = $this->indentation.'    '."<custom_field_log_entry log_id=\"".$this->logMap[$entry['log_id']]."\"";
389       $custom_field_log_part .= " field_id=\"".$this->customFieldMap[$entry['field_id']]."\"";
390       $custom_field_log_part .= " option_id=\"".$this->customFieldOptionMap[$entry['option_id']]."\"";
391       $custom_field_log_part .= " value=\"".htmlspecialchars($entry['value'])."\"";
392       $custom_field_log_part .= " status=\"".$entry['status']."\"";
393       $custom_field_log_part .= "></custom_field_log_entry>\n";
394       fwrite($this->file, $custom_field_log_part);
395     }
396     fwrite($this->file, $this->indentation."  </custom_field_log>\n");
397     unset($custom_field_log);
398     unset($custom_field_log_part);
399
400     // Write expense items.
401     $expense_items = ttTeamHelper::getExpenseItems($this->group_id);
402     fwrite($this->file, $this->indentation."  <expense_items>\n");
403     foreach ($expense_items as $expense_item) {
404       $expense_item_part = $this->indentation.'    '."<expense_item date=\"".$expense_item['date']."\"";
405       $expense_item_part .= " user_id=\"".$this->userMap[$expense_item['user_id']]."\"";
406       $expense_item_part .= " client_id=\"".$this->clientMap[$expense_item['client_id']]."\"";
407       $expense_item_part .= " project_id=\"".$this->projectMap[$expense_item['project_id']]."\"";
408       $expense_item_part .= " name=\"".htmlspecialchars($expense_item['name'])."\"";
409       $expense_item_part .= " cost=\"".$expense_item['cost']."\"";
410       $expense_item_part .= " invoice_id=\"".$this->invoiceMap[$expense_item['invoice_id']]."\"";
411       $expense_item_part .= " paid=\"".$expense_item['paid']."\"";
412       $expense_item_part .= " status=\"".$expense_item['status']."\"";
413       $expense_item_part .= "></expense_item>\n";
414       fwrite($this->file, $expense_item_part);
415     }
416     fwrite($this->file, $this->indentation."  </expense_items>\n");
417     unset($expense_items);
418     unset($expense_item_part);
419
420     // Write predefined expenses.
421     $predefined_expenses = $this->getRecordsFromTable('tt_predefined_expenses');
422     fwrite($this->file, $this->indentation."  <predefined_expenses>\n");
423     foreach ($predefined_expenses as $predefined_expense) {
424       $predefined_expense_part = $this->indentation.'    '."<predefined_expense name=\"".htmlspecialchars($predefined_expense['name'])."\"";
425       $predefined_expense_part .= " cost=\"".$predefined_expense['cost']."\"";
426       $predefined_expense_part .= "></predefined_expense>\n";
427       fwrite($this->file, $predefined_expense_part);
428     }
429     fwrite($this->file, $this->indentation."  </predefined_expenses>\n");
430     unset($predefined_expenses);
431     unset($predefined_expense_part);
432
433     // Write monthly quotas.
434     $quotas = ttTeamHelper::getMonthlyQuotas($this->group_id);
435     fwrite($this->file, $this->indentation."  <monthly_quotas>\n");
436     foreach ($quotas as $quota) {
437       $quota_part = $this->indentation.'    '."<monthly_quota year=\"".$quota['year']."\"";
438       $quota_part .= " month=\"".$quota['month']."\"";
439       $quota_part .= " minutes=\"".$quota['minutes']."\"";
440       $quota_part .= "></monthly_quota>\n";
441       fwrite($this->file, $quota_part);
442     }
443     fwrite($this->file, $this->indentation."  </monthly_quotas>\n");
444     unset($quotas);
445     unset($quota_part);
446
447     // Write fav reports.
448     fwrite($this->file, $this->indentation."  <fav_reports>\n");
449     foreach ($fav_reports as $fav_report) {
450       $user_list = '';
451       if (strlen($fav_report['users']) > 0) {
452         $arr = explode(',', $fav_report['users']);
453         foreach ($arr as $k=>$v) {
454           if (array_key_exists($arr[$k], $this->userMap))
455             $user_list .= (strlen($user_list) == 0? '' : ',').$this->userMap[$v];
456         }
457       }
458       $fav_report_part = $this->indentation.'    '."<fav_report id=\"".$this->favReportMap[$fav_report['id']]."\"";
459       $fav_report_part .= " user_id=\"".$this->userMap[$fav_report['user_id']]."\"";
460       $fav_report_part .= " name=\"".htmlspecialchars($fav_report['name'])."\"";
461       $fav_report_part .= " client_id=\"".$this->clientMap[$fav_report['client_id']]."\"";
462       $fav_report_part .= " cf_1_option_id=\"".$this->customFieldOptionMap[$fav_report['cf_1_option_id']]."\"";
463       $fav_report_part .= " project_id=\"".$this->projectMap[$fav_report['project_id']]."\"";
464       $fav_report_part .= " task_id=\"".$this->taskMap[$fav_report['task_id']]."\"";
465       $fav_report_part .= " billable=\"".$fav_report['billable']."\"";
466       $fav_report_part .= " users=\"".$user_list."\"";
467       $fav_report_part .= " period=\"".$fav_report['period']."\"";
468       $fav_report_part .= " period_start=\"".$fav_report['period_start']."\"";
469       $fav_report_part .= " period_end=\"".$fav_report['period_end']."\"";
470       $fav_report_part .= " show_client=\"".$fav_report['show_client']."\"";
471       $fav_report_part .= " show_invoice=\"".$fav_report['show_invoice']."\"";
472       $fav_report_part .= " show_paid=\"".$fav_report['show_paid']."\"";
473       $fav_report_part .= " show_ip=\"".$fav_report['show_ip']."\"";
474       $fav_report_part .= " show_project=\"".$fav_report['show_project']."\"";
475       $fav_report_part .= " show_start=\"".$fav_report['show_start']."\"";
476       $fav_report_part .= " show_duration=\"".$fav_report['show_duration']."\"";
477       $fav_report_part .= " show_cost=\"".$fav_report['show_cost']."\"";
478       $fav_report_part .= " show_task=\"".$fav_report['show_task']."\"";
479       $fav_report_part .= " show_end=\"".$fav_report['show_end']."\"";
480       $fav_report_part .= " show_note=\"".$fav_report['show_note']."\"";
481       $fav_report_part .= " show_custom_field_1=\"".$fav_report['show_custom_field_1']."\"";
482       $fav_report_part .= " show_work_units=\"".$fav_report['show_work_units']."\"";
483       $fav_report_part .= " group_by1=\"".$fav_report['group_by1']."\"";
484       $fav_report_part .= " group_by2=\"".$fav_report['group_by2']."\"";
485       $fav_report_part .= " group_by3=\"".$fav_report['group_by3']."\"";
486       $fav_report_part .= " show_totals_only=\"".$fav_report['show_totals_only']."\"";
487       $fav_report_part .= "></fav_report>\n";
488       fwrite($this->file, $fav_report_part);
489     }
490     fwrite($this->file, $this->indentation."  </fav_reports>\n");
491     unset($fav_reports);
492     unset($fav_report_part);
493
494     // Write notifications.
495     $notifications = $this->getRecordsFromTable('tt_cron');
496     fwrite($this->file, $this->indentation."  <notifications>\n");
497     foreach ($notifications as $notification) {
498       $notification_part = $this->indentation.'    '."<notification cron_spec=\"".$notification['cron_spec']."\"";
499       $notification_part .= " last=\"".$notification['last']."\"";
500       $notification_part .= " next=\"".$notification['next']."\"";
501       $notification_part .= " report_id=\"".$this->favReportMap[$notification['report_id']]."\"";
502       $notification_part .= " email=\"".htmlspecialchars($notification['email'])."\"";
503       $notification_part .= " cc=\"".htmlspecialchars($notification['cc'])."\"";
504       $notification_part .= " subject=\"".htmlspecialchars($notification['subject'])."\"";
505       $notification_part .= " report_condition=\"".htmlspecialchars($notification['report_condition'])."\"";
506       $notification_part .= " status=\"".$notification['status']."\"";
507       $notification_part .= "></notification>\n";
508       fwrite($this->file, $notification_part);
509     }
510     fwrite($this->file, $this->indentation."  </notifications>\n");
511     unset($notifications);
512     unset($notification_part);
513
514     // Write user config parameters.
515     $user_params = $this->getRecordsFromTable('tt_config');
516     fwrite($this->file, $this->indentation."  <user_params>\n");
517     foreach ($user_params as $user_param) {
518       $user_param_part = $this->indentation.'    '."<user_param user_id=\"".$this->userMap[$user_param['user_id']]."\"";
519       $user_param_part .= " param_name=\"".htmlspecialchars($user_param['param_name'])."\"";
520       $user_param_part .= " param_value=\"".htmlspecialchars($user_param['param_value'])."\"";
521       $user_param_part .= "></user_param>\n";
522       fwrite($this->file, $user_param_part);
523     }
524     fwrite($this->file, $this->indentation."  </user_params>\n");
525     unset($user_params);
526     unset($user_param_part);
527
528     // We are mostly done with writing this group data, destroy all maps.
529     unset($this->roleMap);
530     unset($this->userMap);
531     unset($this->taskMap);
532     unset($this->projectMap);
533     unset($this->clientMap);
534     unset($this->invoiceMap);
535     unset($this->logMap);
536     unset($this->customFieldMap);
537     unset($this->customFieldOptionMap);
538
539     // Call self recursively for all subgroups.
540     foreach ($this->subgroups as $subgroup) {
541       $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.'  ');
542       $subgroup_helper->writeData();
543     }
544     unset($this->subgroups);
545
546     fwrite($this->file, $this->indentation."</group>\n");
547   }
548 }