Skip to content

Commit c3e6cb4

Browse files
committed
More work in progress integrating attachments in reports.
1 parent 9c5d423 commit c3e6cb4

6 files changed

Lines changed: 55 additions & 7 deletions

File tree

WEB-INF/lib/ttReportHelper.class.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ static function getItems($options) {
154154
global $user;
155155
$mdb2 = getConnection();
156156

157+
$group_id = $user->getGroup();
158+
$org_id = $user->org_id;
159+
157160
// Determine these once as they are used in multiple places in this function.
158161
$canViewReports = $user->can('view_reports') || $user->can('view_all_reports');
159162
$isClient = $user->isClient();
@@ -251,6 +254,9 @@ static function getItems($options) {
251254
// Add timesheet name if it is selected.
252255
if ($options['show_timesheet'])
253256
array_push($fields, 'ts.name as timesheet_name');
257+
// Add has_files.
258+
if ($options['show_files'])
259+
array_push($fields, 'if(Sub1.entity_id is null, 0, 1) as has_files');
254260

255261
// Prepare sql query part for left joins.
256262
$left_joins = null;
@@ -274,6 +280,11 @@ static function getItems($options) {
274280
}
275281
if ($includeCost && MODE_TIME != $trackingMode)
276282
$left_joins .= " left join tt_user_project_binds upb on (l.user_id = upb.user_id and l.project_id = upb.project_id)";
283+
if ($options['show_files']) {
284+
$left_joins .= " left join (select distinct entity_id from tt_files".
285+
" where entity_type = 'time' and group_id = $group_id and org_id = $org_id and status = 1) Sub1".
286+
" on (l.id = Sub1.entity_id)";
287+
}
277288

278289
// Prepare sql query part for inner joins.
279290
$inner_joins = null;
@@ -1143,6 +1154,7 @@ static function getReportOptions($bean) {
11431154
$options['show_custom_field_1'] = $bean->getAttribute('chcf_1');
11441155
$options['show_work_units'] = $bean->getAttribute('chunits');
11451156
$options['show_timesheet'] = $bean->getAttribute('chtimesheet');
1157+
$options['show_files'] = $bean->getAttribute('chfiles');
11461158
$options['show_totals_only'] = $bean->getAttribute('chtotalsonly');
11471159
$options['group_by1'] = $bean->getAttribute('group_by1');
11481160
$options['group_by2'] = $bean->getAttribute('group_by2');

WEB-INF/lib/ttTimeHelper.class.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,37 @@ static function getRecord($id) {
692692
return false;
693693
}
694694

695+
// getRecordForFileView - retrieves a time record identified by its id for
696+
// attachment view operation.
697+
//
698+
// It is different from getRecord, as we want users with appropriate rights
699+
// to be able to see other users files, without changing "on behalf" user.
700+
// For example, viewing reports for all users and their attached files
701+
// from report links.
702+
static function getRecordForFileView($id) {
703+
// TODO: code this function properly. There are no security checks now.
704+
global $user;
705+
706+
// $user_id = $user->getUser();
707+
$group_id = $user->getGroup();
708+
$org_id = $user->org_id;
709+
710+
$mdb2 = getConnection();
711+
712+
$sql = "select l.id, l.timesheet_id, l.invoice_id, l.approved from tt_log l".
713+
" where l.id = $id and l.group_id = $group_id and l.org_id = $org_id and l.status = 1";
714+
$res = $mdb2->query($sql);
715+
if (!is_a($res, 'PEAR_Error')) {
716+
if (!$res->numRows()) {
717+
return false;
718+
}
719+
if ($val = $res->fetchRow()) {
720+
return $val;
721+
}
722+
}
723+
return false;
724+
}
725+
695726
// getAllRecords - returns all time records for a certain user.
696727
static function getAllRecords($user_id) {
697728
$result = array();

WEB-INF/templates/footer.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<br>
1313
<table cellspacing="0" cellpadding="4" width="100%" border="0">
1414
<tr>
15-
<td align="center">&nbsp;Anuko Time Tracker 1.18.64.4917 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
15+
<td align="center">&nbsp;Anuko Time Tracker 1.18.64.4918 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
1616
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
1717
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
1818
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>

WEB-INF/templates/report.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
{if $bean->getAttribute('chip')}<td class="tableHeaderCentered">{$i18n.label.ip}</td>{/if}
5555
{if $bean->getAttribute('chinvoice')}<td class="tableHeader">{$i18n.label.invoice}</td>{/if}
5656
{if $bean->getAttribute('chtimesheet')}<td class="tableHeader">{$i18n.label.timesheet}</td>{/if}
57+
{if $bean->getAttribute('chfiles')}<td></td>{/if}
5758
</tr>
5859
{foreach $report_items as $item}
5960
<!-- print subtotal for a block of grouped values -->
@@ -78,6 +79,7 @@
7879
{if $bean->getAttribute('chip')}<td></td>{/if}
7980
{if $bean->getAttribute('chinvoice')}<td></td>{/if}
8081
{if $bean->getAttribute('chtimesheet')}<td></td>{/if}
82+
{if $bean->getAttribute('chfiles')}<td></td>{/if}
8183
{if $use_checkboxes}<td></td>{/if}
8284
</tr>
8385
<tr><td>&nbsp;</td></tr>
@@ -105,6 +107,7 @@
105107
{if $bean->getAttribute('chip')}<td class="cellRightAligned">{if $item.modified}{$item.modified_ip} {$item.modified}{else}{$item.created_ip} {$item.created}{/if}{/if}
106108
{if $bean->getAttribute('chinvoice')}<td class="cellRightAligned">{$item.invoice|escape}</td>{/if}
107109
{if $bean->getAttribute('chtimesheet')}<td class="cellRightAligned">{$item.timesheet_name|escape}</td>{/if}
110+
{if $bean->getAttribute('chfiles')}<td class="cellRightAligned">{if $item.has_files}<a href="time_files.php?id={$item.id}"><img class="table_icon" alt="{$i18n.label.files}" src="images/icon_files.png"></a>{/if}</td>{/if}
108111
{if $use_checkboxes}
109112
{if 1 == $item.type}<td bgcolor="white"><input type="checkbox" name="log_id_{$item.id}"></td>{/if}
110113
{if 2 == $item.type}<td bgcolor="white"><input type="checkbox" name="item_id_{$item.id}"></td>{/if}
@@ -138,6 +141,7 @@
138141
{if $bean->getAttribute('chip')}<td></td>{/if}
139142
{if $bean->getAttribute('chinvoice')}<td></td>{/if}
140143
{if $bean->getAttribute('chtimesheet')}<td></td>{/if}
144+
{if $bean->getAttribute('chfiles')}<td></td>{/if}
141145
{if $use_checkboxes}<td></td>{/if}
142146
</tr>
143147
{/if}
@@ -160,6 +164,7 @@
160164
{if $bean->getAttribute('chip')}<td></td>{/if}
161165
{if $bean->getAttribute('chinvoice')}<td></td>{/if}
162166
{if $bean->getAttribute('chtimesheet')}<td></td>{/if}
167+
{if $bean->getAttribute('chfiles')}<td></td>{/if}
163168
{if $use_checkboxes}<td></td>{/if}
164169
</tr>
165170
{/if}

report.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
if ($bean->getAttribute('chip')) $colspan++;
300300
if ($bean->getAttribute('chinvoice')) $colspan++;
301301
if ($bean->getAttribute('chtimesheet')) $colspan++;
302+
if ($bean->getAttribute('chfiles')) $colspan++;
302303

303304
// Assign variables that are used to alternate color of rows for different dates.
304305
$smarty->assign('prev_date', '');

time_files.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@
3636
header('Location: access_denied.php');
3737
exit();
3838
}
39+
if (!$user->isPluginEnabled('at')) {
40+
header('Location: feature_disabled.php');
41+
exit();
42+
}
3943
$cl_id = (int)$request->getParameter('id');
40-
$time_rec = ttTimeHelper::getRecord($cl_id);
44+
$time_rec = ttTimeHelper::getRecordForFileView($cl_id);
4145
if (!$time_rec) {
4246
header('Location: access_denied.php');
4347
exit();
4448
}
45-
if (!$user->isPluginEnabled('at')) {
46-
header('Location: feature_disabled.php');
47-
exit();
48-
}
49-
// TODO: review access checks, specifically for on behalf operations.
5049
// End of access checks.
5150

5251
if ($request->isPost()) {

0 commit comments

Comments
 (0)