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.
11 // | There are only two ways to violate the license:
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).
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).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
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.
32 // Currently, it is work in progress.
33 // When done, it should handle export of organizations containing multiple groups.
34 class ttGroupExportHelper {
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.
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 var $favReportMap = array();
55 function __construct($group_id, $file, $indentation) {
58 $this->group_id = $group_id;
60 $this->indentation = $indentation;
62 // Build a list of subgroups.
63 $mdb2 = getConnection();
64 $sql = "select id from tt_groups".
65 " where status = 1 and parent_id = $this->group_id and org_id = $user->org_id";
66 $res = $mdb2->query($sql);
67 if (!is_a($res, 'PEAR_Error')) {
68 while ($val = $res->fetchRow()) {
69 $this->subgroups[] = $val;
74 // getGroupData obtains group attributes for export.
75 private function getGroupData() {
77 $mdb2 = getConnection();
79 $sql = "select * from tt_groups".
80 " where status = 1 and id = $this->group_id and org_id = $user->org_id";
81 $res = $mdb2->query($sql);
82 if (!is_a($res, 'PEAR_Error')) {
83 $val = $res->fetchRow();
88 // The getUsers obtains all users in group for the purpose of export.
89 private function getUsers() {
91 $mdb2 = getConnection();
93 $sql = "select u.*, r.rank from tt_users u left join tt_roles r on (u.role_id = r.id)".
94 " where u.group_id = $this->group_id and u.org_id = $user->org_id order by upper(u.name)"; // Note: deleted users are included.
95 $res = $mdb2->query($sql);
97 if (!is_a($res, 'PEAR_Error')) {
98 while ($val = $res->fetchRow()) {
106 // TODO: write a generic (private?) get function for exclusive use in this class, that obtains
107 // all fields from a given table.
109 // getRoles - obtains all roles defined for group.
110 function getRoles() {
112 $mdb2 = getConnection();
115 $sql = "select * from tt_roles where group_id = $this->group_id and org_id = $user->org_id";
116 $res = $mdb2->query($sql);
118 if (!is_a($res, 'PEAR_Error')) {
119 while ($val = $res->fetchRow()) {
127 // getTasks - obtains all tasks defined for group.
128 function getTasks() {
130 $mdb2 = getConnection();
133 $sql = "select * from tt_tasks where group_id = $this->group_id and org_id = $user->org_id";
134 $res = $mdb2->query($sql);
136 if (!is_a($res, 'PEAR_Error')) {
137 while ($val = $res->fetchRow()) {
145 // getProjects - obtains all projects defined for group.
146 function getProjects() {
148 $mdb2 = getConnection();
151 $sql = "select * from tt_projects where group_id = $this->group_id and org_id = $user->org_id";
152 $res = $mdb2->query($sql);
154 if (!is_a($res, 'PEAR_Error')) {
155 while ($val = $res->fetchRow()) {
163 // getClients - obtains all clients defined for group.
164 function getClients() {
166 $mdb2 = getConnection();
169 $sql = "select * from tt_clients where group_id = $this->group_id and org_id = $user->org_id";
170 $res = $mdb2->query($sql);
172 if (!is_a($res, 'PEAR_Error')) {
173 while ($val = $res->fetchRow()) {
181 // getFavReports - obtains all favorite reports defined for group.
182 function getFavReports() {
184 $mdb2 = getConnection();
187 $sql = "select * from tt_fav_reports where group_id = $this->group_id and org_id = $user->org_id";
188 $res = $mdb2->query($sql);
190 if (!is_a($res, 'PEAR_Error')) {
191 while ($val = $res->fetchRow()) {
199 // getPredefinedExpenses - obtains all predefined expenses for group.
200 function getPredefinedExpenses() {
202 $mdb2 = getConnection();
205 $sql = "select * from tt_predefined_expenses where group_id = $this->group_id and org_id = $user->org_id";
206 $res = $mdb2->query($sql);
208 if (!is_a($res, 'PEAR_Error')) {
209 while ($val = $res->fetchRow()) {
217 // getNotifications - obtains all notifications defined for group.
218 function getNotifications() {
220 $mdb2 = getConnection();
223 $sql = "select * from tt_cron where group_id = $this->group_id and org_id = $user->org_id";
224 $res = $mdb2->query($sql);
226 if (!is_a($res, 'PEAR_Error')) {
227 while ($val = $res->fetchRow()) {
235 // getRecordsFromTable - obtains all fields from a given table for a group.
236 function getRecordsFromTable($table_name) {
238 $mdb2 = getConnection();
241 $sql = "select * from $table_name where group_id = $this->group_id and org_id = $user->org_id";
242 $res = $mdb2->query($sql);
244 if (!is_a($res, 'PEAR_Error')) {
245 while ($val = $res->fetchRow()) {
253 // writeData writes group data into file.
254 function writeData() {
257 $group = $this->getGroupData();
258 $group_part = "<group name=\"".htmlspecialchars($group['name'])."\"";
259 $group_part .= " currency=\"".htmlspecialchars($group['currency'])."\"";
260 $group_part .= " decimal_mark=\"".$group['decimal_mark']."\"";
261 $group_part .= " lang=\"".$group['lang']."\"";
262 $group_part .= " date_format=\"".$group['date_format']."\"";
263 $group_part .= " time_format=\"".$group['time_format']."\"";
264 $group_part .= " week_start=\"".$group['week_start']."\"";
265 $group_part .= " tracking_mode=\"".$group['tracking_mode']."\"";
266 $group_part .= " project_required=\"".$group['project_required']."\"";
267 $group_part .= " task_required=\"".$group['task_required']."\"";
268 $group_part .= " record_type=\"".$group['record_type']."\"";
269 $group_part .= " bcc_email=\"".$group['bcc_email']."\"";
270 $group_part .= " allow_ip=\"".$group['allow_ip']."\"";
271 $group_part .= " password_complexity=\"".$group['password_complexity']."\"";
272 $group_part .= " plugins=\"".$group['plugins']."\"";
273 $group_part .= " lock_spec=\"".$group['lock_spec']."\"";
274 $group_part .= " workday_minutes=\"".$group['workday_minutes']."\"";
275 $group_part .= " custom_logo=\"".$group['custom_logo']."\"";
276 $group_part .= " config=\"".$group['config']."\"";
277 $group_part .= ">\n";
280 fwrite($this->file, $this->indentation.$group_part);
285 $users = $this->getUsers();
286 foreach ($users as $key=>$user_item)
287 $this->userMap[$user_item['id']] = $key + 1;
290 $roles = $this->getRoles();
291 foreach ($roles as $key=>$role_item)
292 $this->roleMap[$role_item['id']] = $key + 1;
295 $tasks = $this->getTasks();
296 foreach ($tasks as $key=>$task_item)
297 $this->taskMap[$task_item['id']] = $key + 1;
299 // Prepare project map.
300 $projects = $this->getProjects();
301 foreach ($projects as $key=>$project_item)
302 $this->projectMap[$project_item['id']] = $key + 1;
304 // Prepare client map.
305 $clients = $this->getClients();
306 foreach ($clients as $key=>$client_item)
307 $this->clientMap[$client_item['id']] = $key + 1;
309 // Prepare invoice map.
310 $invoices = ttTeamHelper::getAllInvoices();
311 foreach ($invoices as $key=>$invoice_item)
312 $this->invoiceMap[$invoice_item['id']] = $key + 1;
314 // Prepare custom fields map.
315 $custom_fields = ttTeamHelper::getAllCustomFields($this->group_id);
316 foreach ($custom_fields as $key=>$custom_field)
317 $this->customFieldMap[$custom_field['id']] = $key + 1;
319 // Prepare custom field options map.
320 $custom_field_options = ttTeamHelper::getAllCustomFieldOptions($this->group_id);
321 foreach ($custom_field_options as $key=>$option)
322 $this->customFieldOptionMap[$option['id']] = $key + 1;
324 // Prepare favorite report map.
325 $fav_reports = $this->getFavReports();
326 foreach ($fav_reports as $key=>$fav_report)
327 $this->favReportMap[$fav_report['id']] = $key + 1;
330 fwrite($this->file, $this->indentation." <roles>\n");
331 foreach ($roles as $role) {
332 $role_part = $this->indentation.' '."<role id=\"".$this->roleMap[$role['id']]."\"";
333 $role_part .= " name=\"".htmlspecialchars($role['name'])."\"";
334 $role_part .= " description=\"".htmlspecialchars($role['description'])."\"";
335 $role_part .= " rank=\"".$role['rank']."\"";
336 $role_part .= " rights=\"".htmlspecialchars($role['rights'])."\"";
337 $role_part .= " status=\"".$role['status']."\"";
338 $role_part .= "></role>\n";
339 fwrite($this->file, $role_part);
341 fwrite($this->file, $this->indentation." </roles>\n");
346 fwrite($this->file, $this->indentation." <tasks>\n");
347 foreach ($tasks as $task) {
348 $task_part = $this->indentation.' '."<task id=\"".$this->taskMap[$task['id']]."\"";
349 $task_part .= " name=\"".htmlspecialchars($task['name'])."\"";
350 $task_part .= " description=\"".htmlspecialchars($task['description'])."\"";
351 $task_part .= " status=\"".$task['status']."\"";
352 $task_part .= "></task>\n";
353 fwrite($this->file, $task_part);
355 fwrite($this->file, $this->indentation." </tasks>\n");
360 fwrite($this->file, $this->indentation." <projects>\n");
361 foreach ($projects as $project_item) {
363 if($project_item['tasks']){
364 $tasks = explode(',', $project_item['tasks']);
365 $tasks_mapped = array();
366 foreach ($tasks as $item)
367 $tasks_mapped[] = $this->taskMap[$item];
368 $tasks_str = implode(',', $tasks_mapped);
370 $project_part = $this->indentation.' '."<project id=\"".$this->projectMap[$project_item['id']]."\"";
371 $project_part .= " name=\"".htmlspecialchars($project_item['name'])."\"";
372 $project_part .= " description=\"".htmlspecialchars($project_item['description'])."\"";
373 $project_part .= " tasks=\"".$tasks_str."\"";
374 $project_part .= " status=\"".$project_item['status']."\"";
375 $project_part .= "></project>\n";
376 fwrite($this->file, $project_part);
378 fwrite($this->file, $this->indentation." </projects>\n");
380 unset($project_part);
383 fwrite($this->file, $this->indentation." <clients>\n");
384 foreach ($clients as $client_item) {
385 if($client_item['projects']){
386 $projects_db = explode(',', $client_item['projects']);
387 $projects_mapped = array();
388 foreach ($projects_db as $item)
389 $projects_mapped[] = $this->projectMap[$item];
390 $projects_str = implode(',', $projects_mapped);
392 $client_part = $this->indentation.' '."<client id=\"".$this->clientMap[$client_item['id']]."\"";
393 $client_part .= " name=\"".htmlspecialchars($client_item['name'])."\"";
394 $client_part .= " address=\"".htmlspecialchars($client_item['address'])."\"";
395 $client_part .= " tax=\"".$client_item['tax']."\"";
396 $client_part .= " projects=\"".$projects_str."\"";
397 $client_part .= " status=\"".$client_item['status']."\"";
398 $client_part .= "></client>\n";
399 fwrite($this->file, $client_part);
401 fwrite($this->file, $this->indentation." </clients>\n");
406 fwrite($this->file, $this->indentation." <users>\n");
407 foreach ($users as $user_item) {
408 $role_id = $user_item['rank'] == 512 ? 0 : $this->roleMap[$user_item['role_id']]; // Special role_id 0 (not null) for top manager.
409 $user_part = $this->indentation.' '."<user id=\"".$this->userMap[$user_item['id']]."\"";
410 $user_part .= " name=\"".htmlspecialchars($user_item['name'])."\"";
411 $user_part .= " login=\"".htmlspecialchars($user_item['login'])."\"";
412 $user_part .= " password=\"".$user_item['password']."\"";
413 $user_part .= " role_id=\"".$role_id."\"";
414 $user_part .= " client_id=\"".$this->clientMap[$user_item['client_id']]."\"";
415 $user_part .= " rate=\"".$user_item['rate']."\"";
416 $user_part .= " email=\"".$user_item['email']."\"";
417 $user_part .= " status=\"".$user_item['status']."\"";
418 $user_part .= "></user>\n";
419 fwrite($this->file, $user_part);
421 fwrite($this->file, $this->indentation." </users>\n");
425 // Write user to project binds.
426 fwrite($this->file, $this->indentation." <user_project_binds>\n");
427 $user_binds = ttTeamHelper::getUserToProjectBinds($this->group_id);
428 foreach ($user_binds as $bind) {
429 $user_id = $this->userMap[$bind['user_id']];
430 $project_id = $this->projectMap[$bind['project_id']];
431 $bind_part = $this->indentation.' '."<user_project_bind user_id=\"".$user_id."\"";
432 $bind_part .= " project_id=\"".$project_id."\"";
433 $bind_part .= " rate=\"".$bind['rate']."\"";
434 $bind_part .= " status=\"".$bind['status']."\"";
435 $bind_part .= "></user_project_bind>\n";
436 fwrite($this->file, $bind_part);
438 fwrite($this->file, $this->indentation." </user_project_binds>\n");
443 fwrite($this->file, $this->indentation." <invoices>\n");
444 foreach ($invoices as $invoice_item) {
445 $invoice_part = $this->indentation.' '."<invoice id=\"".$this->invoiceMap[$invoice_item['id']]."\"";
446 $invoice_part .= " name=\"".htmlspecialchars($invoice_item['name'])."\"";
447 $invoice_part .= " date=\"".$invoice_item['date']."\"";
448 $invoice_part .= " client_id=\"".$this->clientMap[$invoice_item['client_id']]."\"";
449 $invoice_part .= " status=\"".$invoice_item['status']."\"";
450 $invoice_part .= "></invoice>\n";
451 fwrite($this->file, $invoice_part);
453 fwrite($this->file, $this->indentation." </invoices>\n");
455 unset($invoice_part);
457 // Write time log entries and build logMap at the same time.
458 fwrite($this->file, $this->indentation." <log>\n");
460 foreach ($this->userMap as $key => $value) {
462 $records = ttTimeHelper::getAllRecords($user_id);
463 foreach ($records as $record) {
465 $this->logMap[$record['id']] = $key;
466 $log_part = $this->indentation.' '."<log_item id=\"$key\"";
467 $log_part .= " user_id=\"".$this->userMap[$record['user_id']]."\"";
468 $log_part .= " date=\"".$record['date']."\"";
469 $log_part .= " start=\"".$record['start']."\"";
470 $log_part .= " finish=\"".$record['finish']."\"";
471 $log_part .= " duration=\"".($record['start']?"":$record['duration'])."\"";
472 $log_part .= " client_id=\"".$this->clientMap[$record['client_id']]."\"";
473 $log_part .= " project_id=\"".$this->projectMap[$record['project_id']]."\"";
474 $log_part .= " task_id=\"".$this->taskMap[$record['task_id']]."\"";
475 $log_part .= " invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\"";
476 $log_part .= " comment=\"".htmlspecialchars($record['comment'])."\"";
477 $log_part .= " billable=\"".$record['billable']."\"";
478 $log_part .= " paid=\"".$record['paid']."\"";
479 $log_part .= " status=\"".$record['status']."\"";
480 $log_part .= "></log_item>\n";
481 fwrite($this->file, $log_part);
484 fwrite($this->file, $this->indentation." </log>\n");
488 // Write custom fields.
489 fwrite($this->file, $this->indentation." <custom_fields>\n");
490 foreach ($custom_fields as $custom_field) {
491 $custom_field_part = $this->indentation.' '."<custom_field id=\"".$this->customFieldMap[$custom_field['id']]."\"";
492 $custom_field_part .= " type=\"".$custom_field['type']."\"";
493 $custom_field_part .= " label=\"".htmlspecialchars($custom_field['label'])."\"";
494 $custom_field_part .= " required=\"".$custom_field['required']."\"";
495 $custom_field_part .= " status=\"".$custom_field['status']."\"";
496 $custom_field_part .= "></custom_field>\n";
497 fwrite($this->file, $custom_field_part);
499 fwrite($this->file, $this->indentation." </custom_fields>\n");
500 unset($custom_fields);
501 unset($custom_field_part);
503 // Write custom field options.
504 fwrite($this->file, $this->indentation." <custom_field_options>\n");
505 foreach ($custom_field_options as $option) {
506 $custom_field_option_part = $this->indentation.' '."<custom_field_option id=\"".$this->customFieldOptionMap[$option['id']]."\"";
507 $custom_field_option_part .= " field_id=\"".$this->customFieldMap[$option['field_id']]."\"";
508 $custom_field_option_part .= " value=\"".htmlspecialchars($option['value'])."\"";
509 $custom_field_option_part .= "></custom_field_option>\n";
510 fwrite($this->file, $custom_field_option_part);
512 fwrite($this->file, $this->indentation." </custom_field_options>\n");
513 unset($custom_field_options);
514 unset($custom_field_option_part);
516 // Write custom field log.
517 $custom_field_log = ttTeamHelper::getCustomFieldLog($this->group_id);
518 fwrite($this->file, $this->indentation." <custom_field_log>\n");
519 foreach ($custom_field_log as $entry) {
520 $custom_field_log_part = $this->indentation.' '."<custom_field_log_entry log_id=\"".$this->logMap[$entry['log_id']]."\"";
521 $custom_field_log_part .= " field_id=\"".$this->customFieldMap[$entry['field_id']]."\"";
522 $custom_field_log_part .= " option_id=\"".$this->customFieldOptionMap[$entry['option_id']]."\"";
523 $custom_field_log_part .= " value=\"".htmlspecialchars($entry['value'])."\"";
524 $custom_field_log_part .= " status=\"".$entry['status']."\"";
525 $custom_field_log_part .= "></custom_field_log_entry>\n";
526 fwrite($this->file, $custom_field_log_part);
528 fwrite($this->file, $this->indentation." </custom_field_log>\n");
529 unset($custom_field_log);
530 unset($custom_field_log_part);
532 // Write expense items.
533 $expense_items = ttTeamHelper::getExpenseItems($this->group_id);
534 fwrite($this->file, $this->indentation." <expense_items>\n");
535 foreach ($expense_items as $expense_item) {
536 $expense_item_part = $this->indentation.' '."<expense_item date=\"".$expense_item['date']."\"";
537 $expense_item_part .= " user_id=\"".$this->userMap[$expense_item['user_id']]."\"";
538 $expense_item_part .= " client_id=\"".$this->clientMap[$expense_item['client_id']]."\"";
539 $expense_item_part .= " project_id=\"".$this->projectMap[$expense_item['project_id']]."\"";
540 $expense_item_part .= " name=\"".htmlspecialchars($expense_item['name'])."\"";
541 $expense_item_part .= " cost=\"".$expense_item['cost']."\"";
542 $expense_item_part .= " invoice_id=\"".$this->invoiceMap[$expense_item['invoice_id']]."\"";
543 $expense_item_part .= " paid=\"".$expense_item['paid']."\"";
544 $expense_item_part .= " status=\"".$expense_item['status']."\"";
545 $expense_item_part .= "></expense_item>\n";
546 fwrite($this->file, $expense_item_part);
548 fwrite($this->file, $this->indentation." </expense_items>\n");
549 unset($expense_items);
550 unset($expense_item_part);
552 // Write predefined expenses.
553 $predefined_expenses = $this->getPredefinedExpenses();
554 fwrite($this->file, $this->indentation." <predefined_expenses>\n");
555 foreach ($predefined_expenses as $predefined_expense) {
556 $predefined_expense_part = $this->indentation.' '."<predefined_expense name=\"".htmlspecialchars($predefined_expense['name'])."\"";
557 $predefined_expense_part .= " cost=\"".$predefined_expense['cost']."\"";
558 $predefined_expense_part .= "></predefined_expense>\n";
559 fwrite($this->file, $predefined_expense_part);
561 fwrite($this->file, $this->indentation." </predefined_expenses>\n");
562 unset($predefined_expenses);
563 unset($predefined_expense_part);
565 // Write monthly quotas.
566 $quotas = ttTeamHelper::getMonthlyQuotas($this->group_id);
567 fwrite($this->file, $this->indentation." <monthly_quotas>\n");
568 foreach ($quotas as $quota) {
569 $quota_part = $this->indentation.' '."<monthly_quota year=\"".$quota['year']."\"";
570 $quota_part .= " month=\"".$quota['month']."\"";
571 $quota_part .= " minutes=\"".$quota['minutes']."\"";
572 $quota_part .= "></monthly_quota>\n";
573 fwrite($this->file, $quota_part);
575 fwrite($this->file, $this->indentation." </monthly_quotas>\n");
579 // Write fav reports.
580 $fav_reports = $this->getFavReports();
581 fwrite($this->file, $this->indentation." <fav_reports>\n");
582 foreach ($fav_reports as $fav_report) {
584 if (strlen($fav_report['users']) > 0) {
585 $arr = explode(',', $fav_report['users']);
586 foreach ($arr as $k=>$v) {
587 if (array_key_exists($arr[$k], $this->userMap))
588 $user_list .= (strlen($user_list) == 0? '' : ',').$this->userMap[$v];
591 $fav_report_part = $this->indentation.' '."<fav_report id=\"".$this->favReportMap[$fav_report['id']]."\"";
592 $fav_report_part .= " user_id=\"".$this->userMap[$fav_report['user_id']]."\"";
593 $fav_report_part .= " name=\"".htmlspecialchars($fav_report['name'])."\"";
594 $fav_report_part .= " client_id=\"".$this->clientMap[$fav_report['client_id']]."\"";
595 $fav_report_part .= " cf_1_option_id=\"".$this->customFieldOptionMap[$fav_report['cf_1_option_id']]."\"";
596 $fav_report_part .= " project_id=\"".$this->projectMap[$fav_report['project_id']]."\"";
597 $fav_report_part .= " task_id=\"".$this->taskMap[$fav_report['task_id']]."\"";
598 $fav_report_part .= " billable=\"".$fav_report['billable']."\"";
599 $fav_report_part .= " users=\"".$user_list."\"";
600 $fav_report_part .= " period=\"".$fav_report['period']."\"";
601 $fav_report_part .= " period_start=\"".$fav_report['period_start']."\"";
602 $fav_report_part .= " period_end=\"".$fav_report['period_end']."\"";
603 $fav_report_part .= " show_client=\"".$fav_report['show_client']."\"";
604 $fav_report_part .= " show_invoice=\"".$fav_report['show_invoice']."\"";
605 $fav_report_part .= " show_paid=\"".$fav_report['show_paid']."\"";
606 $fav_report_part .= " show_ip=\"".$fav_report['show_ip']."\"";
607 $fav_report_part .= " show_project=\"".$fav_report['show_project']."\"";
608 $fav_report_part .= " show_start=\"".$fav_report['show_start']."\"";
609 $fav_report_part .= " show_duration=\"".$fav_report['show_duration']."\"";
610 $fav_report_part .= " show_cost=\"".$fav_report['show_cost']."\"";
611 $fav_report_part .= " show_task=\"".$fav_report['show_task']."\"";
612 $fav_report_part .= " show_end=\"".$fav_report['show_end']."\"";
613 $fav_report_part .= " show_note=\"".$fav_report['show_note']."\"";
614 $fav_report_part .= " show_custom_field_1=\"".$fav_report['show_custom_field_1']."\"";
615 $fav_report_part .= " show_work_units=\"".$fav_report['show_work_units']."\"";
616 $fav_report_part .= " group_by1=\"".$fav_report['group_by1']."\"";
617 $fav_report_part .= " group_by2=\"".$fav_report['group_by2']."\"";
618 $fav_report_part .= " group_by3=\"".$fav_report['group_by3']."\"";
619 $fav_report_part .= " show_totals_only=\"".$fav_report['show_totals_only']."\"";
620 $fav_report_part .= "></fav_report>\n";
621 fwrite($this->file, $fav_report_part);
623 fwrite($this->file, $this->indentation." </fav_reports>\n");
625 unset($fav_report_part);
627 // Write notifications.
628 $notifications = $this->getNotifications();
629 fwrite($this->file, $this->indentation." <notifications>\n");
630 foreach ($notifications as $notification) {
631 $notification_part = $this->indentation.' '."<notification cron_spec=\"".$notification['cron_spec']."\"";
632 $notification_part .= " last=\"".$notification['last']."\"";
633 $notification_part .= " next=\"".$notification['next']."\"";
634 $notification_part .= " report_id=\"".$this->favReportMap[$notification['report_id']]."\"";
635 $notification_part .= " email=\"".htmlspecialchars($notification['email'])."\"";
636 $notification_part .= " cc=\"".htmlspecialchars($notification['cc'])."\"";
637 $notification_part .= " subject=\"".htmlspecialchars($notification['subject'])."\"";
638 $notification_part .= " report_condition=\"".htmlspecialchars($notification['report_condition'])."\"";
639 $notification_part .= " status=\"".$notification['status']."\"";
640 $notification_part .= "></notification>\n";
641 fwrite($this->file, $notification_part);
643 fwrite($this->file, $this->indentation." </notifications>\n");
644 unset($notifications);
645 unset($notification_part);
647 // Write user config parameters.
648 $user_params = $this->getRecordsFromTable('tt_config');
649 fwrite($this->file, $this->indentation." <user_params>\n");
650 foreach ($user_params as $user_param) {
651 $user_param_part = $this->indentation.' '."<user_param user_id=\"".$this->userMap[$user_param['user_id']]."\"";
652 $user_param_part .= " param_name=\"".htmlspecialchars($user_param['param_name'])."\"";
653 $user_param_part .= " param_value=\"".htmlspecialchars($user_param['param_value'])."\"";
654 $user_param_part .= "></user_param>\n";
655 fwrite($this->file, $user_param_part);
657 fwrite($this->file, $this->indentation." </user_params>\n");
659 unset($user_param_part);
661 // We are mostly done with writing this group data, destroy all maps.
662 unset($this->roleMap);
663 unset($this->userMap);
664 unset($this->taskMap);
665 unset($this->projectMap);
666 unset($this->clientMap);
667 unset($this->invoiceMap);
668 unset($this->logMap);
669 unset($this->customFieldMap);
670 unset($this->customFieldOptionMap);
672 // Call self recursively for all subgroups.
673 foreach ($this->subgroups as $subgroup) {
674 $subgroup_helper = new ttGroupExportHelper($subgroup['id'], $this->file, $this->indentation.' ');
675 $subgroup_helper->writeData();
677 unset($this->subgroups);
679 fwrite($this->file, $this->indentation."</group>\n");