X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttReportHelper.class.php;h=c66cb33aa3a25e2a54d6f4482513b19eb5cc72c3;hb=1b6699f3d4ad1961fa4055ec0033bc10f0b06b83;hp=9d0fc87f1803fee73c70b21c0e80aea3d7bb6fd5;hpb=7ddf5c391598126ec473db7b25884ee0bd94f153;p=timetracker.git diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 9d0fc87f..c66cb33a 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -517,7 +517,7 @@ class ttReportHelper { // with an exception of sorting part, that is added in the end. // However, when we have expenses, we need to do a union with a separate query for expense items from tt_expense_items table. - if ($report['show_cost'] && in_array('ex', explode(',', $user->plugins))) { // if ex(penses) plugin is enabled + if ($report['show_cost'] && $user->isPluginEnabled('ex')) { // if ex(penses) plugin is enabled $fields = array(); // An array of fields for database query. array_push($fields, 'ei.id'); @@ -697,7 +697,7 @@ class ttReportHelper { // By now we have sql for time items. // However, when we have expenses, we need to do a union with a separate query for expense items from tt_expense_items table. - if ($bean->getAttribute('chcost') && in_array('ex', explode(',', $user->plugins))) { // if ex(penses) plugin is enabled + if ($bean->getAttribute('chcost') && $user->isPluginEnabled('ex')) { // if ex(penses) plugin is enabled // Determine group by field and a required join. $group_join = null; @@ -825,7 +825,7 @@ class ttReportHelper { // By now we have sql for time items. // However, when we have expenses, we need to do a union with a separate query for expense items from tt_expense_items table. - if ($report['show_cost'] && in_array('ex', explode(',', $user->plugins))) { // if ex(penses) plugin is enabled + if ($report['show_cost'] && $user->isPluginEnabled('ex')) { // if ex(penses) plugin is enabled // Determine group by field and a required join. $group_join = null; @@ -912,7 +912,7 @@ class ttReportHelper { $sql = "select sum(time_to_sec(l.duration)) as time, null as cost, null as expenses from tt_log l $where"; // If we have expenses, query becomes a bit more complex. - if ($bean->getAttribute('chcost') && in_array('ex', explode(',', $user->plugins))) { + if ($bean->getAttribute('chcost') && $user->isPluginEnabled('ex')) { $where = ttReportHelper::getExpenseWhere($bean); $sql_for_expenses = "select null as time, sum(cost) as cost, sum(cost) as expenses from tt_expense_items ei $where"; // Create a combined query. @@ -982,7 +982,7 @@ class ttReportHelper { $sql = "select sum(time_to_sec(l.duration)) as time, null as cost, null as expenses from tt_log l $where"; // If we have expenses, query becomes a bit more complex. - if ($report['show_cost'] && in_array('ex', explode(',', $user->plugins))) { + if ($report['show_cost'] && $user->isPluginEnabled('ex')) { $where = ttReportHelper::getFavExpenseWhere($report); $sql_for_expenses = "select null as time, sum(cost) as cost, sum(cost) as expenses from tt_expense_items ei $where"; // Create a combined query. @@ -1055,7 +1055,7 @@ class ttReportHelper { $totals = ttReportHelper::getTotals($bean); // Use custom fields plugin if it is enabled. - if (in_array('cf', explode(',', $user->plugins))) + if ($user->isPluginEnabled('cf')) $custom_fields = new CustomFields($user->team_id); // Define some styles to use in email. @@ -1300,6 +1300,20 @@ class ttReportHelper { return $body; } + // checkFavReportCondition - checks whether it is okay to send fav report. + static function checkFavReportCondition($report, $condition) + { + $items = ttReportHelper::getFavItems($report); + + $condition = str_replace('count', '', $condition); + $count_required = intval(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($report) { @@ -1313,7 +1327,7 @@ class ttReportHelper { $totals = ttReportHelper::getFavTotals($report); // Use custom fields plugin if it is enabled. - if (in_array('cf', explode(',', $user->plugins))) + if ($user->isPluginEnabled('cf')) $custom_fields = new CustomFields($user->team_id); // Define some styles to use in email. @@ -1559,9 +1573,9 @@ class ttReportHelper { } // sendFavReport - sends a favorite report to a specified email, called from cron.php - static function sendFavReport($report, $email) { + static function sendFavReport($report, $subject, $email, $cc) { // We are called from cron.php, we have no $bean in session. - // cron.php set global $user and $i18n objects to match our favorite report user. + // cron.php sets global $user and $i18n objects to match our favorite report user. global $user; global $i18n; @@ -1573,9 +1587,14 @@ class ttReportHelper { $mailer->setCharSet(CHARSET); $mailer->setContentType('text/html'); $mailer->setSender(SENDER); + if (!empty($cc)) + $mailer->setReceiverCC($cc); + if (!empty($user->bcc_email)) + $mailer->setReceiverBCC($user->bcc_email); $mailer->setReceiver($email); - $mailer->setSendType(MAIL_MODE); - if (!$mailer->send($report['name'], $body)) + $mailer->setMailMode(MAIL_MODE); + if (empty($subject)) $subject = $report['name']; + if (!$mailer->send($subject, $body)) return false; return true;