Refactoring in export to use a generic get function to keep things simple.
[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   // getRecordsFromTable - obtains all fields from a given table for a group.
86   function getRecordsFromTable($table_name) {
87     global $user;
88     $mdb2 = getConnection();
89
90     $result = array();
91     $sql = "select * from $table_name where group_id = $this->group_id and org_id = $user->org_id";
92     $res = $mdb2->query($sql);
93     $result = array();
94     if (!is_a($res, 'PEAR_Error')) {
95       while ($val = $res->fetchRow()) {
96         $result[] = $val;
97       }
98       return $result;
99     }
100     return false;
101   }
102
103   // writeData writes group data into file.
104   function writeData() {
105
106     // Write group info.
107     $group = $this->getGroupAttrs();
108     $group_part = "<group name=\"".htmlspecialchars($group['name'])."\"";
109     $group_part .= " currency=\"".htmlspecialchars($group['currency'])."\"";
110     $group_part .= " decimal_mark=\"".$group['decimal_mark']."\"";
111     $group_part .= " lang=\"".$group['lang']."\"";
112     $group_part .= " date_format=\"".$group['date_format']."\"";
113     $group_part .= " time_format=\"".$group['time_format']."\"";
114     $group_part .= " week_start=\"".$group['week_start']."\"";
115     $group_part .= " tracking_mode=\"".$group['tracking_mode']."\"";
116     $group_part .= " project_required=\"".$group['project_required']."\"";
117     $group_part .= " task_required=\"".$group['task_required']."\"";
118     $group_part .= " record_type=\"".$group['record_type']."\"";
119     $group_part .= " bcc_email=\"".$group['bcc_email']."\"";
120     $group_part .= " allow_ip=\"".$group['allow_ip']."\"";
121     $group_part .= " password_complexity=\"".$group['password_complexity']."\"";
122     $group_part .= " plugins=\"".$group['plugins']."\"";
123     $group_part .= " lock_spec=\"".$group['lock_spec']."\"";
124     $group_part .= " workday_minutes=\"".$group['workday_minutes']."\"";
125     $group_part .= " custom_logo=\"".$group['custom_logo']."\"";
126     $group_part .= " config=\"".$group['config']."\"";
127     $group_part .= ">\n";
128
129     // Write group info.
130     fwrite($this->file, $this->indentation.$group_part);
131     unset($group);
132     unset($group_part);
133
134     // Prepare user map.
135     $users = $this->getRecordsFromTable('tt_users');
136     foreach ($users as $key=>$user_item)
137       $this->userMap[$user_item['id']] = $key + 1;
138
139     // Prepare role map.
140     $roles = $this->getRecordsFromTable('tt_roles');
141     foreach ($roles as $key=>$role_item)
142       $this->roleMap[$role_item['id']] = $key + 1;
143
144     // Prepare task map.
145     $tasks = $this->getRecordsFromTable('tt_tasks');
146     foreach ($tasks as $key=>$task_item)
147       $this->taskMap[$task_item['id']] = $key + 1;
148
149     // Prepare project map.
150     $projects = $this->getRecordsFromTable('tt_projects');
151     foreach ($projects as $key=>$project_item)
152       $this->projectMap[$project_item['id']] = $key + 1;
153
154     // Prepare client map.
155     $clients = $this->getRecordsFromTable('tt_clients');
156     foreach ($clients as $key=>$client_item)
157       $this->clientMap[$client_item['id']] = $key + 1;
158
159     // Prepare invoice map.
160     $invoices = ttTeamHelper::getAllInvoices();
161     foreach ($invoices as $key=>$invoice_item)
162       $this->invoiceMap[$invoice_item['id']] = $key + 1;
163
164     // Prepare custom fields map.
165     $custom_fields = ttTeamHelper::getAllCustomFields($this->group_id);
166     foreach ($custom_fields as $key=>$custom_field)
167       $this->customFieldMap[$custom_field['id']] = $key + 1;
168
169     // Prepare custom field options map.
170     $custom_field_options = ttTeamHelper::getAllCustomFieldOptions($this->group_id);
171     foreach ($custom_field_options as $key=>$option)
172       $this->customFieldOptionMap[$option['id']] = $key + 1;
173
174     // Prepare favorite report map.
175     $fav_reports = $this->getRecordsFromTable('tt_fav_reports');
176     foreach ($fav_reports as $key=>$fav_report)
177       $this->favReportMap[$fav_report['id']] = $key + 1;
178
179     // Write roles.
180     fwrite($this->file, $this->indentation."  <roles>\n");
181     foreach ($roles as $role) {
182       $role_part = $this->indentation.'    '."<role id=\"".$this->roleMap[$role['id']]."\"";
183       $role_part .= " name=\"".htmlspecialchars($role['name'])."\"";
184       $role_part .= " description=\"".htmlspecialchars($role['description'])."\"";
185       $role_part .= " rank=\"".$role['rank']."\"";
186       $role_part .= " rights=\"".htmlspecialchars($role['rights'])."\"";
187       $role_part .= " status=\"".$role['status']."\"";
188       $role_part .= "></role>\n";
189       fwrite($this->file, $role_part);
190     }
191     fwrite($this->file, $this->indentation."  </roles>\n");
192     unset($roles);
193     unset($role_part);
194
195     // Write tasks.
196     fwrite($this->file, $this->indentation."  <tasks>\n");
197     foreach ($tasks as $task) {
198       $task_part = $this->indentation.'    '."<task id=\"".$this->taskMap[$task['id']]."\"";
199       $task_part .= " name=\"".htmlspecialchars($task['name'])."\"";
200       $task_part .= " description=\"".htmlspecialchars($task['description'])."\"";
201       $task_part .= " status=\"".$task['status']."\"";
202       $task_part .= "></task>\n";
203       fwrite($this->file, $task_part);
204     }
205     fwrite($this->file, $this->indentation."  </tasks>\n");
206     unset($tasks);
207     unset($task_part);
208
209     // Write projects.
210     fwrite($this->file, $this->indentation."  <projects>\n");
211     foreach ($projects as $project_item) {
212       $tasks_str = null;
213       if($project_item['tasks']){
214         $tasks = explode(',', $project_item['tasks']);
215         $tasks_mapped = array();
216         foreach ($tasks as $item)
217           $tasks_mapped[] = $this->taskMap[$item];
218         $tasks_str = implode(',', $tasks_mapped);
219       }
220       $project_part = $this->indentation.'    '."<project id=\"".$this->projectMap[$project_item['id']]."\"";
221       $project_part .= " name=\"".htmlspecialchars($project_item['name'])."\"";
222       $project_part .= " description=\"".htmlspecialchars($project_item['description'])."\"";
223       $project_part .= " tasks=\"".$tasks_str."\"";
224       $project_part .= " status=\"".$project_item['status']."\"";
225       $project_part .= "></project>\n";
226       fwrite($this->file, $project_part);
227     }
228     fwrite($this->file, $this->indentation."  </projects>\n");
229     unset($projects);
230     unset($project_part);
231
232     // Write clients.
233     fwrite($this->file, $this->indentation."  <clients>\n");
234     foreach ($clients as $client_item) {
235       if($client_item['projects']){
236         $projects_db = explode(',', $client_item['projects']);
237         $projects_mapped = array();
238         foreach ($projects_db as $item)
239           $projects_mapped[] = $this->projectMap[$item];
240         $projects_str = implode(',', $projects_mapped);
241       }
242       $client_part = $this->indentation.'    '."<client id=\"".$this->clientMap[$client_item['id']]."\"";
243       $client_part .= " name=\"".htmlspecialchars($client_item['name'])."\"";
244       $client_part .= " address=\"".htmlspecialchars($client_item['address'])."\"";
245       $client_part .= " tax=\"".$client_item['tax']."\"";
246       $client_part .= " projects=\"".$projects_str."\"";
247       $client_part .= " status=\"".$client_item['status']."\"";
248       $client_part .= "></client>\n";
249       fwrite($this->file, $client_part);
250     }
251     fwrite($this->file, $this->indentation."  </clients>\n");
252     unset($clients);
253     unset($client_part);
254
255     // Write users.
256     fwrite($this->file, $this->indentation."  <users>\n");
257     foreach ($users as $user_item) {
258       $role_id = $user_item['rank'] == 512 ? 0 : $this->roleMap[$user_item['role_id']]; // Special role_id 0 (not null) for top manager.
259       $user_part = $this->indentation.'    '."<user id=\"".$this->userMap[$user_item['id']]."\"";
260       $user_part .= " name=\"".htmlspecialchars($user_item['name'])."\"";
261       $user_part .= " login=\"".htmlspecialchars($user_item['login'])."\"";
262       $user_part .= " password=\"".$user_item['password']."\"";
263       $user_part .= " role_id=\"".$role_id."\"";
264       $user_part .= " client_id=\"".$this->clientMap[$user_item['client_id']]."\"";
265       $user_part .= " rate=\"".$user_item['rate']."\"";
266       $user_part .= " email=\"".$user_item['email']."\"";
267       $user_part .= " status=\"".$user_item['status']."\"";
268       $user_part .= "></user>\n";
269       fwrite($this->file, $user_part);
270     }
271     fwrite($this->file, $this->indentation."  </users>\n");
272     unset($users);
273     unset($user_part);
274
275     // Write user to project binds.
276     fwrite($this->file, $this->indentation."  <user_project_binds>\n");
277     $user_binds = ttTeamHelper::getUserToProjectBinds($this->group_id);
278     foreach ($user_binds as $bind) {
279       $user_id = $this->userMap[$bind['user_id']];
280       $project_id = $this->projectMap[$bind['project_id']];
281       $bind_part = $this->indentation.'    '."<user_project_bind user_id=\"".$user_id."\"";
282       $bind_part .= " project_id=\"".$project_id."\"";
283       $bind_part .= " rate=\"".$bind['rate']."\"";
284       $bind_part .= " status=\"".$bind['status']."\"";
285       $bind_part .= "></user_project_bind>\n";
286       fwrite($this->file, $bind_part);
287     }
288     fwrite($this->file, $this->indentation."  </user_project_binds>\n");
289     unset($user_binds);
290     unset($bind_part);
291
292     // Write invoices.
293     fwrite($this->file, $this->indentation."  <invoices>\n");
294     foreach ($invoices as $invoice_item) {
295       $invoice_part = $this->indentation.'    '."<invoice id=\"".$this->invoiceMap[$invoice_item['id']]."\"";
296       $invoice_part .= " name=\"".htmlspecialchars($invoice_item['name'])."\"";
297       $invoice_part .= " date=\"".$invoice_item['date']."\"";
298       $invoice_part .= " client_id=\"".$this->clientMap[$invoice_item['client_id']]."\"";
299       $invoice_part .= " status=\"".$invoice_item['status']."\"";
300       $invoice_part .= "></invoice>\n";
301       fwrite($this->file, $invoice_part);
302     }
303     fwrite($this->file, $this->indentation."  </invoices>\n");
304     unset($invoices);
305     unset($invoice_part);
306
307     // Write time log entries and build logMap at the same time.
308     fwrite($this->file, $this->indentation."  <log>\n");
309     $key = 0;
310     foreach ($this->userMap as $key => $value) {
311       $user_id = $key;
312       $records = ttTimeHelper::getAllRecords($user_id);
313       foreach ($records as $record) {
314         $key++;
315         $this->logMap[$record['id']] = $key;
316         $log_part = $this->indentation.'    '."<log_item id=\"$key\"";
317         $log_part .= " user_id=\"".$this->userMap[$record['user_id']]."\"";
318         $log_part .= " date=\"".$record['date']."\"";
319         $log_part .= " start=\"".$record['start']."\"";
320         $log_part .= " finish=\"".$record['finish']."\"";
321         $log_part .= " duration=\"".($record['start']?"":$record['duration'])."\"";
322         $log_part .= " client_id=\"".$this->clientMap[$record['client_id']]."\"";
323         $log_part .= " project_id=\"".$this->projectMap[$record['project_id']]."\"";
324         $log_part .= " task_id=\"".$this->taskMap[$record['task_id']]."\"";
325         $log_part .= " invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\"";
326         $log_part .= " comment=\"".htmlspecialchars($record['comment'])."\"";
327         $log_part .= " billable=\"".$record['billable']."\"";
328         $log_part .= " paid=\"".$record['paid']."\"";
329         $log_part .= " status=\"".$record['status']."\"";
330         $log_part .= "></log_item>\n";
331         fwrite($this->file, $log_part);
332       }
333     }
334     fwrite($this->file, $this->indentation."  </log>\n");
335     unset($records);
336     unset($log_part);
337
338     // Write custom fields.
339     fwrite($this->file, $this->indentation."  <custom_fields>\n");
340     foreach ($custom_fields as $custom_field) {
341       $custom_field_part = $this->indentation.'    '."<custom_field id=\"".$this->customFieldMap[$custom_field['id']]."\"";
342       $custom_field_part .= " type=\"".$custom_field['type']."\"";
343       $custom_field_part .= " label=\"".htmlspecialchars($custom_field['label'])."\"";
344       $custom_field_part .= " required=\"".$custom_field['required']."\"";
345       $custom_field_part .= " status=\"".$custom_field['status']."\"";
346       $custom_field_part .= "></custom_field>\n";
347       fwrite($this->file, $custom_field_part);
348     }
349     fwrite($this->file, $this->indentation."  </custom_fields>\n");
350     unset($custom_fields);
351     unset($custom_field_part);
352
353     // Write custom field options.
354     fwrite($this->file, $this->indentation."  <custom_field_options>\n");
355     foreach ($custom_field_options as $option) {
356       $custom_field_option_part = $this->indentation.'    '."<custom_field_option id=\"".$this->customFieldOptionMap[$option['id']]."\"";
357       $custom_field_option_part .= " field_id=\"".$this->customFieldMap[$option['field_id']]."\"";
358       $custom_field_option_part .= " value=\"".htmlspecialchars($option['value'])."\"";
359       $custom_field_option_part .= "></custom_field_option>\n";
360       fwrite($this->file, $custom_field_option_part);
361     }
362     fwrite($this->file, $this->indentation."  </custom_field_options>\n");
363     unset($custom_field_options);
364     unset($custom_field_option_part);
365
366     // Write custom field log.
367     $custom_field_log = ttTeamHelper::getCustomFieldLog($this->group_id);
368     fwrite($this->file, $this->indentation."  <custom_field_log>\n");
369     foreach ($custom_field_log as $entry) {
370       $custom_field_log_part = $this->indentation.'    '."<custom_field_log_entry log_id=\"".$this->logMap[$entry['log_id']]."\"";
371       $custom_field_log_part .= " field_id=\"".$this->customFieldMap[$entry['field_id']]."\"";
372       $custom_field_log_part .= " option_id=\"".$this->customFieldOptionMap[$entry['option_id']]."\"";
373       $custom_field_log_part .= " value=\"".htmlspecialchars($entry['value'])."\"";
374       $custom_field_log_part .= " status=\"".$entry['status']."\"";
375       $custom_field_log_part .= "></custom_field_log_entry>\n";
376       fwrite($this->file, $custom_field_log_part);
377     }
378     fwrite($this->file, $this->indentation."  </custom_field_log>\n");
379     unset($custom_field_log);
380     unset($custom_field_log_part);
381
382     // Write expense items.
383     $expense_items = ttTeamHelper::getExpenseItems($this->group_id);
384     fwrite($this->file, $this->indentation."  <expense_items>\n");
385     foreach ($expense_items as $expense_item) {
386       $expense_item_part = $this->indentation.'    '."<expense_item date=\"".$expense_item['date']."\"";
387       $expense_item_part .= " user_id=\"".$this->userMap[$expense_item['user_id']]."\"";
388       $expense_item_part .= " client_id=\"".$this->clientMap[$expense_item['client_id']]."\"";
389       $expense_item_part .= " project_id=\"".$this->projectMap[$expense_item['project_id']]."\"";
390       $expense_item_part .= " name=\"".htmlspecialchars($expense_item['name'])."\"";
391       $expense_item_part .= " cost=\"".$expense_item['cost']."\"";
392       $expense_item_part .= " invoice_id=\"".$this->invoiceMap[$expense_item['invoice_id']]."\"";
393       $expense_item_part .= " paid=\"".$expense_item['paid']."\"";
394       $expense_item_part .= " status=\"".$expense_item['status']."\"";
395       $expense_item_part .= "></expense_item>\n";
396       fwrite($this->file, $expense_item_part);
397     }
398     fwrite($this->file, $this->indentation."  </expense_items>\n");
399     unset($expense_items);
400     unset($expense_item_part);
401
402     // Write predefined expenses.
403     $predefined_expenses = $this->getRecordsFromTable('tt_predefined_expenses');
404     fwrite($this->file, $this->indentation."  <predefined_expenses>\n");
405     foreach ($predefined_expenses as $predefined_expense) {
406       $predefined_expense_part = $this->indentation.'    '."<predefined_expense name=\"".htmlspecialchars($predefined_expense['name'])."\"";
407       $predefined_expense_part .= " cost=\"".$predefined_expense['cost']."\"";
408       $predefined_expense_part .= "></predefined_expense>\n";
409       fwrite($this->file, $predefined_expense_part);
410     }
411     fwrite($this->file, $this->indentation."  </predefined_expenses>\n");
412     unset($predefined_expenses);
413     unset($predefined_expense_part);
414
415     // Write monthly quotas.
416     $quotas = ttTeamHelper::getMonthlyQuotas($this->group_id);
417     fwrite($this->file, $this->indentation."  <monthly_quotas>\n");
418     foreach ($quotas as $quota) {
419       $quota_part = $this->indentation.'    '."<monthly_quota year=\"".$quota['year']."\"";
420       $quota_part .= " month=\"".$quota['month']."\"";
421       $quota_part .= " minutes=\"".$quota['minutes']."\"";
422       $quota_part .= "></monthly_quota>\n";
423       fwrite($this->file, $quota_part);
424     }
425     fwrite($this->file, $this->indentation."  </monthly_quotas>\n");
426     unset($quotas);
427     unset($quota_part);
428
429     // Write fav reports.
430     fwrite($this->file, $this->indentation."  <fav_reports>\n");
431     foreach ($fav_reports as $fav_report) {
432       $user_list = '';
433       if (strlen($fav_report['users']) > 0) {
434         $arr = explode(',', $fav_report['users']);
435         foreach ($arr as $k=>$v) {
436           if (array_key_exists($arr[$k], $this->userMap))
437             $user_list .= (strlen($user_list) == 0? '' : ',').$this->userMap[$v];
438         }
439       }
440       $fav_report_part = $this->indentation.'    '."<fav_report id=\"".$this->favReportMap[$fav_report['id']]."\"";
441       $fav_report_part .= " user_id=\"".$this->userMap[$fav_report['user_id']]."\"";
442       $fav_report_part .= " name=\"".htmlspecialchars($fav_report['name'])."\"";
443       $fav_report_part .= " client_id=\"".$this->clientMap[$fav_report['client_id']]."\"";
444       $fav_report_part .= " cf_1_option_id=\"".$this->customFieldOptionMap[$fav_report['cf_1_option_id']]."\"";
445       $fav_report_part .= " project_id=\"".$this->projectMap[$fav_report['project_id']]."\"";
446       $fav_report_part .= " task_id=\"".$this->taskMap[$fav_report['task_id']]."\"";
447       $fav_report_part .= " billable=\"".$fav_report['billable']."\"";
448       $fav_report_part .= " users=\"".$user_list."\"";
449       $fav_report_part .= " period=\"".$fav_report['period']."\"";
450       $fav_report_part .= " period_start=\"".$fav_report['period_start']."\"";
451       $fav_report_part .= " period_end=\"".$fav_report['period_end']."\"";
452       $fav_report_part .= " show_client=\"".$fav_report['show_client']."\"";
453       $fav_report_part .= " show_invoice=\"".$fav_report['show_invoice']."\"";
454       $fav_report_part .= " show_paid=\"".$fav_report['show_paid']."\"";
455       $fav_report_part .= " show_ip=\"".$fav_report['show_ip']."\"";
456       $fav_report_part .= " show_project=\"".$fav_report['show_project']."\"";
457       $fav_report_part .= " show_start=\"".$fav_report['show_start']."\"";
458       $fav_report_part .= " show_duration=\"".$fav_report['show_duration']."\"";
459       $fav_report_part .= " show_cost=\"".$fav_report['show_cost']."\"";
460       $fav_report_part .= " show_task=\"".$fav_report['show_task']."\"";
461       $fav_report_part .= " show_end=\"".$fav_report['show_end']."\"";
462       $fav_report_part .= " show_note=\"".$fav_report['show_note']."\"";
463       $fav_report_part .= " show_custom_field_1=\"".$fav_report['show_custom_field_1']."\"";
464       $fav_report_part .= " show_work_units=\"".$fav_report['show_work_units']."\"";
465       $fav_report_part .= " group_by1=\"".$fav_report['group_by1']."\"";
466       $fav_report_part .= " group_by2=\"".$fav_report['group_by2']."\"";
467       $fav_report_part .= " group_by3=\"".$fav_report['group_by3']."\"";
468       $fav_report_part .= " show_totals_only=\"".$fav_report['show_totals_only']."\"";
469       $fav_report_part .= "></fav_report>\n";
470       fwrite($this->file, $fav_report_part);
471     }
472     fwrite($this->file, $this->indentation."  </fav_reports>\n");
473     unset($fav_reports);
474     unset($fav_report_part);
475
476     // Write notifications.
477     $notifications = $this->getRecordsFromTable('tt_cron');
478     fwrite($this->file, $this->indentation."  <notifications>\n");
479     foreach ($notifications as $notification) {
480       $notification_part = $this->indentation.'    '."<notification cron_spec=\"".$notification['cron_spec']."\"";
481       $notification_part .= " last=\"".$notification['last']."\"";
482       $notification_part .= " next=\"".$notification['next']."\"";
483       $notification_part .= " report_id=\"".$this->favReportMap[$notification['report_id']]."\"";
484       $notification_part .= " email=\"".htmlspecialchars($notification['email'])."\"";
485       $notification_part .= " cc=\"".htmlspecialchars($notification['cc'])."\"";
486       $notification_part .= " subject=\"".htmlspecialchars($notification['subject'])."\"";
487       $notification_part .= " report_condition=\"".htmlspecialchars($notification['report_condition'])."\"";
488       $notification_part .= " status=\"".$notification['status']."\"";
489       $notification_part .= "></notification>\n";
490       fwrite($this->file, $notification_part);
491     }
492     fwrite($this->file, $this->indentation."  </notifications>\n");
493     unset($notifications);
494     unset($notification_part);
495
496     // Write user config parameters.
497     $user_params = $this->getRecordsFromTable('tt_config');
498     fwrite($this->file, $this->indentation."  <user_params>\n");
499     foreach ($user_params as $user_param) {
500       $user_param_part = $this->indentation.'    '."<user_param user_id=\"".$this->userMap[$user_param['user_id']]."\"";
501       $user_param_part .= " param_name=\"".htmlspecialchars($user_param['param_name'])."\"";
502       $user_param_part .= " param_value=\"".htmlspecialchars($user_param['param_value'])."\"";
503       $user_param_part .= "></user_param>\n";
504       fwrite($this->file, $user_param_part);
505     }
506     fwrite($this->file, $this->indentation."  </user_params>\n");
507     unset($user_params);
508     unset($user_param_part);
509
510     // We are mostly done with writing this group data, destroy all maps.
511     unset($this->roleMap);
512     unset($this->userMap);
513     unset($this->taskMap);
514     unset($this->projectMap);
515     unset($this->clientMap);
516     unset($this->invoiceMap);
517     unset($this->logMap);
518     unset($this->customFieldMap);
519     unset($this->customFieldOptionMap);
520
521     // Call self recursively for all subgroups.
522     foreach ($this->subgroups as $subgroup) {
523       $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.'  ');
524       $subgroup_helper->writeData();
525     }
526     unset($this->subgroups);
527
528     fwrite($this->file, $this->indentation."</group>\n");
529   }
530 }