Cleanup - whitespace.
[timetracker.git] / report.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 require_once('initialize.php');
30 import('form.Form');
31 import('form.ActionForm');
32 import('ttReportHelper');
33 import('ttTeamHelper');
34
35 // Access check.
36 if (!ttAccessCheck(right_view_reports)) {
37   header('Location: access_denied.php');
38   exit();
39 }
40
41 // Use custom fields plugin if it is enabled.
42 if ($user->isPluginEnabled('cf')) {
43   require_once('plugins/CustomFields.class.php');
44   $custom_fields = new CustomFields($user->team_id);
45   $smarty->assign('custom_fields', $custom_fields);
46 }
47
48 $form = new Form('reportForm');
49
50 // Report settings are stored in session bean before we get here from reports.php.
51 $bean = new ActionForm('reportBean', $form, $request);
52 $client_id = $bean->getAttribute('client');
53 if ($client_id && $bean->getAttribute('chinvoice') && ('no_grouping' == $bean->getAttribute('group_by')) && !$user->isClient()) {
54   // Client is selected and we are displaying the invoice column.
55   $recent_invoices = ttTeamHelper::getRecentInvoices($user->team_id, $client_id);
56   if ($recent_invoices) {
57     $form->addInput(array('type'=>'combobox',
58       'name'=>'recent_invoice',
59       'data'=>$recent_invoices,
60       'datakeys'=>array('id','name'),
61       'empty'=>array(''=>$i18n->getKey('dropdown.select_invoice'))));
62     $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.submit')));
63     $smarty->assign('use_checkboxes', true);
64   }
65 }
66
67 if ($request->isPost()) {
68   foreach($_POST as $key => $val) {
69     if ('log_id_' == substr($key, 0, 7))
70       $time_log_ids[] = substr($key, 7);
71     if ('item_id_' == substr($key, 0, 8))
72       $expense_item_ids[] = substr($key, 8);
73     if ('recent_invoice' == $key)
74        $invoice_id = $val;
75   }
76   if ($time_log_ids || $expense_item_ids) {
77     // Some records are checked for invoice editing. Adjust their invoice accordingly.
78     ttReportHelper::assignToInvoice($invoice_id, $time_log_ids, $expense_item_ids);
79   }
80   // Re-display this form.
81   header('Location: report.php');
82   exit();
83 } // isPost
84
85 $group_by = $bean->getAttribute('group_by');
86
87 $report_items = ttReportHelper::getItems($bean);
88 if ('no_grouping' != $group_by)
89   $subtotals = ttReportHelper::getSubtotals($bean);
90 $totals = ttReportHelper::getTotals($bean);
91
92 // Assign variables that are used to print subtotals.
93 if ($report_items && 'no_grouping' != $group_by) {
94   $smarty->assign('print_subtotals', true);
95   $smarty->assign('first_pass', true);
96   $smarty->assign('group_by', $group_by);
97   $smarty->assign('prev_grouped_by', '');
98   $smarty->assign('cur_grouped_by', '');
99 }
100 // Determine group by header.
101 if ('no_grouping' != $group_by) {
102   if ('cf_1' == $group_by)
103     $smarty->assign('group_by_header', $custom_fields->fields[0]['label']);
104   else {
105     $key = 'label.'.$group_by;
106     $smarty->assign('group_by_header', $i18n->getKey($key));
107   }
108 }
109 // Assign variables that are used to alternate color of rows for different dates.
110 $smarty->assign('prev_date', '');
111 $smarty->assign('cur_date', '');
112 $smarty->assign('report_row_class', 'rowReportItem');
113
114 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
115
116 $smarty->assign('report_items', $report_items);
117 $smarty->assign('subtotals', $subtotals);
118 $smarty->assign('totals', $totals);
119 $smarty->assign('bean', $bean);
120 $smarty->assign('title', $i18n->getKey('title.report').": ".$totals['start_date']." - ".$totals['end_date']);
121 $smarty->assign('content_page_name', 'report.tpl');
122 $smarty->display('index.tpl');