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