X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttReportHelper.class.php;h=019293207c26e6cf2b208878e67e0ca5db515814;hb=98dfff814b103b57c450173804f92a255909a3ba;hp=4d510bbb2962f99670158708f217a65b2a499dca;hpb=a58bca2afc5d6457d07c886c7c20fb10c941752a;p=timetracker.git diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 4d510bbb..01929320 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -657,323 +657,7 @@ class ttReportHelper { } // prepareReportBody - prepares an email body for report. - static function prepareReportBody($bean, $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(); - $options = ttReportHelper::getReportOptions($bean); - - $items = ttReportHelper::getItems($options); - $group_by = $bean->getAttribute('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 ($bean->getAttribute('chtotalsonly')) { - // 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 .= ''.$group_by_header.' | '; - if ($bean->getAttribute('chduration')) - $body .= ''.$i18n->get('label.duration').' | '; - if ($bean->getAttribute('chunits')) - $body .= ''.$i18n->get('label.work_units_short').' | '; - if ($bean->getAttribute('chcost')) - $body .= ''.$i18n->get('label.cost').' | '; - $body .= '
'.($subtotal['name'] ? htmlspecialchars($subtotal['name']) : ' ').' | '; - if ($bean->getAttribute('chduration')) { - $body .= ''; - if ($subtotal['time'] <> '0:00') $body .= $subtotal['time']; - $body .= ' | '; - } - if ($bean->getAttribute('chunits')) { - $body .= ''; - $body .= $subtotal['units']; - $body .= ' | '; - } - if ($bean->getAttribute('chcost')) { - $body .= ''; - $body .= ($canViewReports || $isClient) ? $subtotal['cost'] : $subtotal['expenses']; - $body .= ' | '; - } - $body .= '
'.$i18n->get('label.total').' | '; - if ($bean->getAttribute('chduration')) { - $body .= ''; - if ($totals['time'] <> '0:00') $body .= $totals['time']; - $body .= ' | '; - } - if ($bean->getAttribute('chunits')) { - $body .= ''; - $body .= $totals['units']; - $body .= ' | '; - } - if ($bean->getAttribute('chcost')) { - $body .= ''.htmlspecialchars($user->currency).' '; - $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses']; - $body .= ' | '; - } - $body .= '
'.$i18n->get('label.date').' | '; - if ($canViewReports || $isClient) - $body .= ''.$i18n->get('label.user').' | '; - if ($bean->getAttribute('chclient')) - $body .= ''.$i18n->get('label.client').' | '; - if ($bean->getAttribute('chproject')) - $body .= ''.$i18n->get('label.project').' | '; - if ($bean->getAttribute('chtask')) - $body .= ''.$i18n->get('label.task').' | '; - if ($bean->getAttribute('chcf_1')) - $body .= ''.htmlspecialchars($custom_fields->fields[0]['label']).' | '; - if ($bean->getAttribute('chstart')) - $body .= ''.$i18n->get('label.start').' | '; - if ($bean->getAttribute('chfinish')) - $body .= ''.$i18n->get('label.finish').' | '; - if ($bean->getAttribute('chduration')) - $body .= ''.$i18n->get('label.duration').' | '; - if ($bean->getAttribute('chunits')) - $body .= ''.$i18n->get('label.work_units_short').' | '; - if ($bean->getAttribute('chnote')) - $body .= ''.$i18n->get('label.note').' | '; - if ($bean->getAttribute('chcost')) - $body .= ''.$i18n->get('label.cost').' | '; - if ($bean->getAttribute('chpaid')) - $body .= ''.$i18n->get('label.paid').' | '; - if ($bean->getAttribute('chip')) - $body .= ''.$i18n->get('label.ip').' | '; - if ($bean->getAttribute('chinvoice')) - $body .= ''.$i18n->get('label.invoice').' | '; - $body .= '
'.$i18n->get('label.subtotal').' | '; - $subtotal_name = htmlspecialchars($subtotals[$prev_grouped_by]['name']); - if ($canViewReports || $isClient) $body .= ''.($group_by == 'user' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chclient')) $body .= ''.($group_by == 'client' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chproject')) $body .= ''.($group_by == 'project' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chtask')) $body .= ''.($group_by == 'task' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chcf_1')) $body .= ''.($group_by == 'cf_1' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chstart')) $body .= ''; - if ($bean->getAttribute('chfinish')) $body .= ' | '; - if ($bean->getAttribute('chduration')) $body .= ' | '.$subtotals[$prev_grouped_by]['time'].' | '; - if ($bean->getAttribute('chunits')) $body .= ''.$subtotals[$prev_grouped_by]['units'].' | '; - if ($bean->getAttribute('chnote')) $body .= ''; - if ($bean->getAttribute('chcost')) { - $body .= ' | '; - $body .= ($canViewReports || $isClient) ? $subtotals[$prev_grouped_by]['cost'] : $subtotals[$prev_grouped_by]['expenses']; - $body .= ' | '; - } - if ($bean->getAttribute('chpaid')) $body .= ''; - if ($bean->getAttribute('chip')) $body .= ' | '; - if ($bean->getAttribute('chinvoice')) $body .= ' | '; - $body .= ' |
'.$record['date'].' | '; - if ($canViewReports || $isClient) - $body .= ''.htmlspecialchars($record['user']).' | '; - if ($bean->getAttribute('chclient')) - $body .= ''.htmlspecialchars($record['client']).' | '; - if ($bean->getAttribute('chproject')) - $body .= ''.htmlspecialchars($record['project']).' | '; - if ($bean->getAttribute('chtask')) - $body .= ''.htmlspecialchars($record['task']).' | '; - if ($bean->getAttribute('chcf_1')) - $body .= ''.htmlspecialchars($record['cf_1']).' | '; - if ($bean->getAttribute('chstart')) - $body .= ''.$record['start'].' | '; - if ($bean->getAttribute('chfinish')) - $body .= ''.$record['finish'].' | '; - if ($bean->getAttribute('chduration')) - $body .= ''.$record['duration'].' | '; - if ($bean->getAttribute('chunits')) - $body .= ''.$record['units'].' | '; - if ($bean->getAttribute('chnote')) - $body .= ''.htmlspecialchars($record['note']).' | '; - if ($bean->getAttribute('chcost')) - $body .= ''.$record['cost'].' | '; - if ($bean->getAttribute('chpaid')) { - $body .= ''; - $body .= $record['paid'] == 1 ? $i18n->get('label.yes') : $i18n->get('label.no'); - $body .= ' | '; - } - if ($bean->getAttribute('chip')) { - $body .= ''; - $body .= $record['modified'] ? $record['modified_ip'].' '.$record['modified'] : $record['created_ip'].' '.$record['created']; - $body .= ' | '; - } - if ($bean->getAttribute('chinvoice')) - $body .= ''.htmlspecialchars($record['invoice']).' | '; - $body .= '
'.$i18n->get('label.subtotal').' | '; - $subtotal_name = htmlspecialchars($subtotals[$cur_grouped_by]['name']); - if ($canViewReports || $isClient) $body .= ''.($group_by == 'user' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chclient')) $body .= ''.($group_by == 'client' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chproject')) $body .= ''.($group_by == 'project' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chtask')) $body .= ''.($group_by == 'task' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chcf_1')) $body .= ''.($group_by == 'cf_1' ? $subtotal_name : '').' | '; - if ($bean->getAttribute('chstart')) $body .= ''; - if ($bean->getAttribute('chfinish')) $body .= ' | '; - if ($bean->getAttribute('chduration')) $body .= ' | '.$subtotals[$cur_grouped_by]['time'].' | '; - if ($bean->getAttribute('chunits')) $body .= ''.$subtotals[$cur_grouped_by]['units'].' | '; - if ($bean->getAttribute('chnote')) $body .= ''; - if ($bean->getAttribute('chcost')) { - $body .= ' | '; - $body .= ($canViewReports || $isClient) ? $subtotals[$cur_grouped_by]['cost'] : $subtotals[$cur_grouped_by]['expenses']; - $body .= ' | '; - } - if ($bean->getAttribute('chpaid')) $body .= ''; - if ($bean->getAttribute('chip')) $body .= ' | '; - if ($bean->getAttribute('chinvoice')) $body .= ' | '; - $body .= ' |
'.$i18n->get('label.total').' | '; - 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 .= ' | '.$totals['time'].' | '; - if ($bean->getAttribute('chunits')) $body .= ''.$totals['units'].' | '; - if ($bean->getAttribute('chnote')) $body .= ''; - if ($bean->getAttribute('chcost')) { - $body .= ' | '.htmlspecialchars($user->currency).' '; - $body .= ($canViewReports || $isClient) ? $totals['cost'] : $totals['expenses']; - $body .= ' | '; - } - if ($bean->getAttribute('chpaid')) $body .= ''; - if ($bean->getAttribute('chip')) $body .= ' | '; - if ($bean->getAttribute('chinvoice')) $body .= ' | '; - $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) + static function prepareReportBody($options, $comment = null) { global $user; global $i18n; @@ -1013,7 +697,7 @@ class ttReportHelper { $body .= ''.$i18n->get('form.mail.report_subject').': '.$totals['start_date'].' - '.$totals['end_date'].'
'; // Output comment. - // if ($comment) $body .= ''.htmlspecialchars($comment).'
'; // No comment for fav. reports. + if ($comment) $body .= ''.htmlspecialchars($comment).'
'; if ($options['show_totals_only']) { // Totals only report. Output subtotals. @@ -1273,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. @@ -1281,7 +979,7 @@ class ttReportHelper { global $i18n; // Prepare report body. - $body = ttReportHelper::prepareFavReportBody($options); + $body = ttReportHelper::prepareReportBody($options); import('mail.Mailer'); $mailer = new Mailer();