From: Nik Okuntseff Date: Mon, 6 Aug 2018 14:41:50 +0000 (+0000) Subject: Merged prepareReportBody and prepareFavReportBody into one function. X-Git-Tag: timetracker_1.19-1~774 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6e023fcc8768de908976357682d951d9f9a42226;p=timetracker.git Merged prepareReportBody and prepareFavReportBody into one function. --- diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 1f165478..01929320 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -657,327 +657,7 @@ class ttReportHelper { } // prepareReportBody - prepares an email body for report. - static function prepareReportBody($bean, $options, $comment) - { - global $user; - global $i18n; - - // Determine these once as they are used in multiple places in this function. - $canViewReports = $user->can('view_reports') || $user->can('view_all_reports'); - $isClient = $user->isClient(); - - $items = ttReportHelper::getItems($options); - $group_by = $options['group_by']; - if ($group_by && 'no_grouping' != $group_by) - $subtotals = ttReportHelper::getSubtotals($options); - $totals = ttReportHelper::getTotals($options); - - // Use custom fields plugin if it is enabled. - if ($user->isPluginEnabled('cf')) - $custom_fields = new CustomFields($user->group_id); - - // Define some styles to use in email. - $style_title = 'text-align: center; font-size: 15pt; font-family: Arial, Helvetica, sans-serif;'; - $tableHeader = 'font-weight: bold; background-color: #a6ccf7; text-align: left;'; - $tableHeaderCentered = 'font-weight: bold; background-color: #a6ccf7; text-align: center;'; - $rowItem = 'background-color: #ffffff;'; - $rowItemAlt = 'background-color: #f5f5f5;'; - $rowSubtotal = 'background-color: #e0e0e0;'; - $cellLeftAligned = 'text-align: left; vertical-align: top;'; - $cellRightAligned = 'text-align: right; vertical-align: top;'; - $cellLeftAlignedSubtotal = 'font-weight: bold; text-align: left; vertical-align: top;'; - $cellRightAlignedSubtotal = 'font-weight: bold; text-align: right; vertical-align: top;'; - - // Start creating email body. - $body = ''; - $body .= ''; - $body .= ''; - - // Output title. - $body .= '

'.$i18n->get('form.mail.report_subject').': '.$totals['start_date'].' - '.$totals['end_date'].'

'; - - // Output comment. - if ($comment) $body .= '

'.htmlspecialchars($comment).'

'; - - if ($options['show_totals_only']) { - // Totals only report. Output subtotals. - - // Determine group_by header. - if ('cf_1' == $group_by) - $group_by_header = htmlspecialchars($custom_fields->fields[0]['label']); - else { - $key = 'label.'.$group_by; - $group_by_header = $i18n->get($key); - } - - $body .= ''; - $body .= ''; - $body .= ''; - if ($options['show_duration']) - $body .= ''; - if ($options['show_work_units']) - $body .= ''; - if ($options['show_cost']) - $body .= ''; - $body .= ''; - foreach($subtotals as $subtotal) { - $body .= ''; - $body .= ''; - if ($options['show_duration']) { - $body .= ''; - } - if ($options['show_work_units']) { - $body .= ''; - } - if ($options['show_cost']) { - $body .= ''; - } - $body .= ''; - } - -// TODO: refactoring ongoing down from here... - - - - - // Print totals. - $body .= ''; - $body .= ''; - $body .= ''; - if ($bean->getAttribute('chduration')) { - $body .= ''; - } - if ($bean->getAttribute('chunits')) { - $body .= ''; - } - if ($bean->getAttribute('chcost')) { - $body .= ''; - } - $body .= ''; - - $body .= '
'.$group_by_header.''.$i18n->get('label.duration').''.$i18n->get('label.work_units_short').''.$i18n->get('label.cost').'
'.($subtotal['name'] ? htmlspecialchars($subtotal['name']) : ' ').''; - if ($subtotal['time'] <> '0:00') $body .= $subtotal['time']; - $body .= ''; - $body .= $subtotal['units']; - $body .= ''; - $body .= ($canViewReports || $isClient) ? $subtotal['cost'] : $subtotal['expenses']; - $body .= '
 
'.$i18n->get('label.total').''; - if ($totals['time'] <> '0:00') $body .= $totals['time']; - $body .= ''; - $body .= $totals['units']; - $body .= ''.htmlspecialchars($user->currency).' '; - $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses']; - $body .= '
'; - } else { - // Regular report. - - // Print table header. - $body .= ''; - $body .= ''; - $body .= ''; - if ($canViewReports || $isClient) - $body .= ''; - if ($bean->getAttribute('chclient')) - $body .= ''; - if ($bean->getAttribute('chproject')) - $body .= ''; - if ($bean->getAttribute('chtask')) - $body .= ''; - if ($bean->getAttribute('chcf_1')) - $body .= ''; - if ($bean->getAttribute('chstart')) - $body .= ''; - if ($bean->getAttribute('chfinish')) - $body .= ''; - if ($bean->getAttribute('chduration')) - $body .= ''; - if ($bean->getAttribute('chunits')) - $body .= ''; - if ($bean->getAttribute('chnote')) - $body .= ''; - if ($bean->getAttribute('chcost')) - $body .= ''; - if ($bean->getAttribute('chpaid')) - $body .= ''; - if ($bean->getAttribute('chip')) - $body .= ''; - if ($bean->getAttribute('chinvoice')) - $body .= ''; - $body .= ''; - - // Initialize variables to print subtotals. - if ($items && 'no_grouping' != $group_by) { - $print_subtotals = true; - $first_pass = true; - $prev_grouped_by = ''; - $cur_grouped_by = ''; - } - // Initialize variables to alternate color of rows for different dates. - $prev_date = ''; - $cur_date = ''; - $row_style = $rowItem; - - // Print report items. - if (is_array($items)) { - foreach ($items as $record) { - $cur_date = $record['date']; - // Print a subtotal row after a block of grouped items. - if ($print_subtotals) { - $cur_grouped_by = $record['grouped_by']; - if ($cur_grouped_by != $prev_grouped_by && !$first_pass) { - $body .= ''; - $body .= ''; - $subtotal_name = htmlspecialchars($subtotals[$prev_grouped_by]['name']); - if ($canViewReports || $isClient) $body .= ''; - if ($bean->getAttribute('chclient')) $body .= ''; - if ($bean->getAttribute('chproject')) $body .= ''; - if ($bean->getAttribute('chtask')) $body .= ''; - if ($bean->getAttribute('chcf_1')) $body .= ''; - if ($bean->getAttribute('chstart')) $body .= ''; - if ($bean->getAttribute('chfinish')) $body .= ''; - if ($bean->getAttribute('chduration')) $body .= ''; - if ($bean->getAttribute('chunits')) $body .= ''; - if ($bean->getAttribute('chnote')) $body .= ''; - if ($bean->getAttribute('chcost')) { - $body .= ''; - } - if ($bean->getAttribute('chpaid')) $body .= ''; - if ($bean->getAttribute('chip')) $body .= ''; - if ($bean->getAttribute('chinvoice')) $body .= ''; - $body .= ''; - $body .= ''; - } - $first_pass = false; - } - - // Print a regular row. - if ($cur_date != $prev_date) - $row_style = ($row_style == $rowItem) ? $rowItemAlt : $rowItem; - $body .= ''; - $body .= ''; - if ($canViewReports || $isClient) - $body .= ''; - if ($bean->getAttribute('chclient')) - $body .= ''; - if ($bean->getAttribute('chproject')) - $body .= ''; - if ($bean->getAttribute('chtask')) - $body .= ''; - if ($bean->getAttribute('chcf_1')) - $body .= ''; - if ($bean->getAttribute('chstart')) - $body .= ''; - if ($bean->getAttribute('chfinish')) - $body .= ''; - if ($bean->getAttribute('chduration')) - $body .= ''; - if ($bean->getAttribute('chunits')) - $body .= ''; - if ($bean->getAttribute('chnote')) - $body .= ''; - if ($bean->getAttribute('chcost')) - $body .= ''; - if ($bean->getAttribute('chpaid')) { - $body .= ''; - } - if ($bean->getAttribute('chip')) { - $body .= ''; - } - if ($bean->getAttribute('chinvoice')) - $body .= ''; - $body .= ''; - - $prev_date = $record['date']; - if ($print_subtotals) - $prev_grouped_by = $record['grouped_by']; - } - } - - // Print a terminating subtotal. - if ($print_subtotals) { - $body .= ''; - $body .= ''; - $subtotal_name = htmlspecialchars($subtotals[$cur_grouped_by]['name']); - if ($canViewReports || $isClient) $body .= ''; - if ($bean->getAttribute('chclient')) $body .= ''; - if ($bean->getAttribute('chproject')) $body .= ''; - if ($bean->getAttribute('chtask')) $body .= ''; - if ($bean->getAttribute('chcf_1')) $body .= ''; - if ($bean->getAttribute('chstart')) $body .= ''; - if ($bean->getAttribute('chfinish')) $body .= ''; - if ($bean->getAttribute('chduration')) $body .= ''; - if ($bean->getAttribute('chunits')) $body .= ''; - if ($bean->getAttribute('chnote')) $body .= ''; - if ($bean->getAttribute('chcost')) { - $body .= ''; - } - if ($bean->getAttribute('chpaid')) $body .= ''; - if ($bean->getAttribute('chip')) $body .= ''; - if ($bean->getAttribute('chinvoice')) $body .= ''; - $body .= ''; - } - - // Print totals. - $body .= ''; - $body .= ''; - $body .= ''; - if ($canViewReports || $isClient) $body .= ''; - if ($bean->getAttribute('chclient')) $body .= ''; - if ($bean->getAttribute('chproject')) $body .= ''; - if ($bean->getAttribute('chtask')) $body .= ''; - if ($bean->getAttribute('chcf_1')) $body .= ''; - if ($bean->getAttribute('chstart')) $body .= ''; - if ($bean->getAttribute('chfinish')) $body .= ''; - if ($bean->getAttribute('chduration')) $body .= ''; - if ($bean->getAttribute('chunits')) $body .= ''; - if ($bean->getAttribute('chnote')) $body .= ''; - if ($bean->getAttribute('chcost')) { - $body .= ''; - } - if ($bean->getAttribute('chpaid')) $body .= ''; - if ($bean->getAttribute('chip')) $body .= ''; - if ($bean->getAttribute('chinvoice')) $body .= ''; - $body .= ''; - - $body .= '
'.$i18n->get('label.date').''.$i18n->get('label.user').''.$i18n->get('label.client').''.$i18n->get('label.project').''.$i18n->get('label.task').''.htmlspecialchars($custom_fields->fields[0]['label']).''.$i18n->get('label.start').''.$i18n->get('label.finish').''.$i18n->get('label.duration').''.$i18n->get('label.work_units_short').''.$i18n->get('label.note').''.$i18n->get('label.cost').''.$i18n->get('label.paid').''.$i18n->get('label.ip').''.$i18n->get('label.invoice').'
'.$i18n->get('label.subtotal').''.($group_by == 'user' ? $subtotal_name : '').''.($group_by == 'client' ? $subtotal_name : '').''.($group_by == 'project' ? $subtotal_name : '').''.($group_by == 'task' ? $subtotal_name : '').''.($group_by == 'cf_1' ? $subtotal_name : '').''.$subtotals[$prev_grouped_by]['time'].''.$subtotals[$prev_grouped_by]['units'].''; - $body .= ($canViewReports || $isClient) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses']; - $body .= '
 
'.$record['date'].''.htmlspecialchars($record['user']).''.htmlspecialchars($record['client']).''.htmlspecialchars($record['project']).''.htmlspecialchars($record['task']).''.htmlspecialchars($record['cf_1']).''.$record['start'].''.$record['finish'].''.$record['duration'].''.$record['units'].''.htmlspecialchars($record['note']).''.$record['cost'].''; - $body .= $record['paid'] == 1 ? $i18n->get('label.yes') : $i18n->get('label.no'); - $body .= ''; - $body .= $record['modified'] ? $record['modified_ip'].' '.$record['modified'] : $record['created_ip'].' '.$record['created']; - $body .= ''.htmlspecialchars($record['invoice']).'
'.$i18n->get('label.subtotal').''.($group_by == 'user' ? $subtotal_name : '').''.($group_by == 'client' ? $subtotal_name : '').''.($group_by == 'project' ? $subtotal_name : '').''.($group_by == 'task' ? $subtotal_name : '').''.($group_by == 'cf_1' ? $subtotal_name : '').''.$subtotals[$cur_grouped_by]['time'].''.$subtotals[$cur_grouped_by]['units'].''; - $body .= ($canViewReports || $isClient) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses']; - $body .= '
 
'.$i18n->get('label.total').''.$totals['time'].''.$totals['units'].''.htmlspecialchars($user->currency).' '; - $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses']; - $body .= '
'; - } - - // Output footer. - if (!defined('REPORT_FOOTER') || !(REPORT_FOOTER == false)) - $body .= '

'.$i18n->get('form.mail.footer').'

'; - - // Finish creating email body. - $body .= ''; - - return $body; - } - - // checkFavReportCondition - checks whether it is okay to send fav report. - static function checkFavReportCondition($options, $condition) - { - $items = ttReportHelper::getItems($options); - - $condition = str_replace('count', '', $condition); - $count_required = (int) trim(str_replace('>', '', $condition)); - - if (count($items) > $count_required) - return true; // Condition ok. - - return false; - } - - // prepareFavReportBody - prepares an email body for a favorite report. - static function prepareFavReportBody($options, $comment = null) + static function prepareReportBody($options, $comment = null) { global $user; global $i18n; @@ -1277,6 +957,20 @@ class ttReportHelper { return $body; } + // checkFavReportCondition - checks whether it is okay to send fav report. + static function checkFavReportCondition($options, $condition) + { + $items = ttReportHelper::getItems($options); + + $condition = str_replace('count', '', $condition); + $count_required = (int) trim(str_replace('>', '', $condition)); + + if (count($items) > $count_required) + return true; // Condition ok. + + return false; + } + // sendFavReport - sends a favorite report to a specified email, called from cron.php static function sendFavReport($options, $subject, $email, $cc) { // We are called from cron.php, we have no $bean in session. @@ -1285,7 +979,7 @@ class ttReportHelper { global $i18n; // Prepare report body. - $body = ttReportHelper::prepareFavReportBody($options); + $body = ttReportHelper::prepareReportBody($options); import('mail.Mailer'); $mailer = new Mailer(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index cdbd8cbb..1b7d29ce 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.17.98.4318 | Copyright © Anuko | +  Anuko Time Tracker 1.17.98.4319 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/report_send.php b/report_send.php index ea6c555b..9bbf9f51 100644 --- a/report_send.php +++ b/report_send.php @@ -75,7 +75,7 @@ if ($request->isPost()) { $options = ttReportHelper::getReportOptions($bean); // Prepare report body. - $body = ttReportHelper::prepareReportBody($bean, $options, $cl_comment); + $body = ttReportHelper::prepareReportBody($options, $cl_comment); import('mail.Mailer'); $mailer = new Mailer();