From: anuko Date: Sat, 9 Sep 2017 20:50:17 +0000 (+0000) Subject: Added cc option for notifications. X-Git-Tag: timetracker_1.19-1~1482 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1b6699f3d4ad1961fa4055ec0033bc10f0b06b83;p=timetracker.git Added cc option for notifications. --- diff --git a/WEB-INF/lib/ttNotificationHelper.class.php b/WEB-INF/lib/ttNotificationHelper.class.php index addbcdb6..ee7880c4 100644 --- a/WEB-INF/lib/ttNotificationHelper.class.php +++ b/WEB-INF/lib/ttNotificationHelper.class.php @@ -39,7 +39,7 @@ class ttNotificationHelper { $mdb2 = getConnection(); - $sql = "select c.id, c.cron_spec, c.report_id, c.email, c.report_condition, c.status, fr.name from tt_cron c + $sql = "select c.id, c.cron_spec, c.report_id, c.email, c.cc, c.subject, c.report_condition, c.status, fr.name from tt_cron c left join tt_fav_reports fr on (fr.id = c.report_id) where c.id = $id and c.team_id = $user->team_id"; $res = $mdb2->query($sql); @@ -75,11 +75,13 @@ class ttNotificationHelper { $next = (int) $fields['next']; $report_id = (int) $fields['report_id']; $email = $fields['email']; + $cc = $fields['cc']; + $subject = $fields['subject']; $report_condition = $fields['report_condition']; $status = $fields['status']; - $sql = "insert into tt_cron (team_id, cron_spec, next, report_id, email, report_condition, status) - values ($team_id, ".$mdb2->quote($cron_spec).", $next, $report_id, ".$mdb2->quote($email).", ".$mdb2->quote($report_condition).", ".$mdb2->quote($status).")"; + $sql = "insert into tt_cron (team_id, cron_spec, next, report_id, email, cc, subject, report_condition, status) + values ($team_id, ".$mdb2->quote($cron_spec).", $next, $report_id, ".$mdb2->quote($email).", ".$mdb2->quote($cc).", ".$mdb2->quote($subject).", ".$mdb2->quote($report_condition).", ".$mdb2->quote($status).")"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -98,10 +100,12 @@ class ttNotificationHelper { $next = (int) $fields['next']; $report_id = (int) $fields['report_id']; $email = $fields['email']; + $cc = $fields['cc']; + $subject = $fields['subject']; $report_condition = $fields['report_condition']; $status = $fields['status']; - $sql = "update tt_cron set cron_spec = ".$mdb2->quote($cron_spec).", next = $next, report_id = $report_id, email = ".$mdb2->quote($email).", report_condition = ".$mdb2->quote($report_condition).", status = ".$mdb2->quote($status). + $sql = "update tt_cron set cron_spec = ".$mdb2->quote($cron_spec).", next = $next, report_id = $report_id, email = ".$mdb2->quote($email).", cc = ".$mdb2->quote($cc).", subject = ".$mdb2->quote($subject).", report_condition = ".$mdb2->quote($report_condition).", status = ".$mdb2->quote($status). " where id = $notification_id and team_id = $team_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index f1fc5908..c66cb33a 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -1573,7 +1573,7 @@ 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 sets global $user and $i18n objects to match our favorite report user. global $user; @@ -1587,11 +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->setMailMode(MAIL_MODE); - if (!$mailer->send($report['name'], $body)) + if (empty($subject)) $subject = $report['name']; + if (!$mailer->send($subject, $body)) return false; return true; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1b3cff08..9a0e3d54 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- + + + + + + + + diff --git a/WEB-INF/templates/notification_edit.tpl b/WEB-INF/templates/notification_edit.tpl index 7080d0d9..ed810670 100644 --- a/WEB-INF/templates/notification_edit.tpl +++ b/WEB-INF/templates/notification_edit.tpl @@ -15,6 +15,14 @@ + + + + + + + + diff --git a/cron.php b/cron.php index eb7965a2..5f342ddf 100644 --- a/cron.php +++ b/cron.php @@ -47,7 +47,7 @@ import('ttReportHelper'); $mdb2 = getConnection(); $now = time(); - $sql = "select c.id, c.cron_spec, c.report_id, c.email, c.report_condition from tt_cron c + $sql = "select c.id, c.cron_spec, c.report_id, c.email, c.cc, c.subject, c.report_condition from tt_cron c left join tt_fav_reports fr on (c.report_id = fr.id) where $now >= c.next and fr.status = 1 and c.status = 1 and c.report_id is not null and c.email is not null"; @@ -75,7 +75,7 @@ while ($val = $res->fetchRow()) { // Email report if condition is okay. if ($condition_ok) { - if (ttReportHelper::sendFavReport($report, $val['email'])) + if (ttReportHelper::sendFavReport($report, $val['subject'], $val['email'], $val['cc'])) echo "Report ".$val['report_id']. " sent to ".$val['email']."
"; else echo "Error while emailing report...
"; diff --git a/dbinstall.php b/dbinstall.php index 9a0451b5..cb5f1c63 100755 --- a/dbinstall.php +++ b/dbinstall.php @@ -641,6 +641,8 @@ if ($_POST) { setChange("ALTER TABLE `tt_cron` ADD `report_condition` varchar(255) default NULL AFTER `email`"); setChange("ALTER TABLE `tt_fav_reports` ADD `status` tinyint(4) default '1'"); setChange("ALTER TABLE `tt_teams` ADD `bcc_email` varchar(100) default NULL AFTER `uncompleted_indicators`"); + setChange("ALTER TABLE `tt_cron` ADD `cc` varchar(100) default NULL AFTER `email`"); + setChange("ALTER TABLE `tt_cron` ADD `subject` varchar(100) default NULL AFTER `cc`"); } // The update_clients function updates projects field in tt_clients table. diff --git a/mysql.sql b/mysql.sql index e9262923..de5060da 100644 --- a/mysql.sql +++ b/mysql.sql @@ -229,6 +229,8 @@ CREATE TABLE `tt_cron` ( `next` int(11) default NULL, # UNIX timestamp of when to run next job `report_id` int(11) default NULL, # report id from tt_fav_reports, a report to mail on schedule `email` varchar(100) default NULL, # email to send results to + `cc` varchar(100) default NULL, # cc email to send results to + `subject` varchar(100) default NULL, # email subject `report_condition` varchar(255) default NULL, # report condition, "count > 0" for sending not empty reports `status` tinyint(4) default '1', # entry status PRIMARY KEY (`id`) diff --git a/notification_add.php b/notification_add.php index a12f6ff5..b33f6807 100644 --- a/notification_add.php +++ b/notification_add.php @@ -45,6 +45,8 @@ if ($request->isPost()) { $cl_fav_report = trim($request->getParameter('fav_report')); $cl_cron_spec = trim($request->getParameter('cron_spec')); $cl_email = trim($request->getParameter('email')); + $cl_cc = trim($request->getParameter('cc')); + $cl_subject = trim($request->getParameter('subject')); $cl_report_condition = trim($request->getParameter('report_condition')); } else { $cl_cron_spec = '0 4 * * 1'; // Default schedule - weekly on Mondays at 04:00 (server time). @@ -61,6 +63,8 @@ $form->addInput(array('type'=>'combobox', )); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'cron_spec','style'=>'width: 250px;','value'=>$cl_cron_spec)); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','style'=>'width: 250px;','value'=>$cl_email)); +$form->addInput(array('type'=>'text','name'=>'cc','style'=>'width: 300px;','value'=>$cl_cc)); +$form->addInput(array('type'=>'text','name'=>'subject','style'=>'width: 300px;','value'=>$cl_subject)); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'report_condition','style'=>'width: 250px;','value'=>$cl_report_condition)); $form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->getKey('button.add'))); @@ -69,6 +73,8 @@ if ($request->isPost()) { if (!$cl_fav_report) $err->add($i18n->getKey('error.report')); if (!ttValidCronSpec($cl_cron_spec)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.cron_schedule')); if (!ttValidEmail($cl_email)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + if (!ttValidEmail($cl_cc, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.cc')); + if (!ttValidString($cl_subject, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.subject')); if (!ttValidCondition($cl_report_condition)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.condition')); if ($err->no()) { @@ -81,6 +87,8 @@ if ($request->isPost()) { 'next' => $next, 'report_id' => $cl_fav_report, 'email' => $cl_email, + 'cc' => $cl_cc, + 'subject' => $cl_subject, 'report_condition' => $cl_report_condition, 'status' => ACTIVE))) { header('Location: notifications.php'); diff --git a/notification_edit.php b/notification_edit.php index 11a7ac0e..6751eb07 100644 --- a/notification_edit.php +++ b/notification_edit.php @@ -46,12 +46,16 @@ if ($request->isPost()) { $cl_fav_report = trim($request->getParameter('fav_report')); $cl_cron_spec = trim($request->getParameter('cron_spec')); $cl_email = trim($request->getParameter('email')); + $cl_cc = trim($request->getParameter('cc')); + $cl_subject = trim($request->getParameter('subject')); $cl_report_condition = trim($request->getParameter('report_condition')); } else { $notification = ttNotificationHelper::get($notification_id); $cl_fav_report = $notification['report_id']; $cl_cron_spec = $notification['cron_spec']; $cl_email = $notification['email']; + $cl_cc = $notification['cc']; + $cl_subject = $notification['subject']; $cl_report_condition = $notification['report_condition']; } @@ -66,6 +70,8 @@ $form->addInput(array('type'=>'combobox', 'empty'=>array(''=>$i18n->getKey('dropdown.select')))); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'cron_spec','style'=>'width: 250px;','value'=>$cl_cron_spec)); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','style'=>'width: 250px;','value'=>$cl_email)); +$form->addInput(array('type'=>'text','name'=>'cc','style'=>'width: 300px;','value'=>$cl_cc)); +$form->addInput(array('type'=>'text','name'=>'subject','style'=>'width: 300px;','value'=>$cl_subject)); $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'report_condition','style'=>'width: 250px;','value'=>$cl_report_condition)); $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.save'))); @@ -74,6 +80,8 @@ if ($request->isPost()) { if (!$cl_fav_report) $err->add($i18n->getKey('error.report')); if (!ttValidCronSpec($cl_cron_spec)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.cron_schedule')); if (!ttValidEmail($cl_email)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + if (!ttValidEmail($cl_cc, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.cc')); + if (!ttValidString($cl_subject, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.subject')); if (!ttValidCondition($cl_report_condition)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.condition')); if ($err->no()) { @@ -87,6 +95,8 @@ if ($request->isPost()) { 'next' => $next, 'report_id' => $cl_fav_report, 'email' => $cl_email, + 'cc' => $cl_cc, + 'subject' => $cl_subject, 'report_condition' => $cl_report_condition, 'status' => ACTIVE))) { header('Location: notifications.php');
 Anuko Time Tracker 1.12.0.3665 | Copyright © Anuko | +  Anuko Time Tracker 1.12.1.3666 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/notification_add.tpl b/WEB-INF/templates/notification_add.tpl index 0cd37db1..e565eda0 100644 --- a/WEB-INF/templates/notification_add.tpl +++ b/WEB-INF/templates/notification_add.tpl @@ -15,6 +15,14 @@ {$i18n.label.email} (*): {$forms.notificationForm.email.control}
{$i18n.form.mail.cc}:{$forms.notificationForm.cc.control}
{$i18n.form.mail.subject}:{$forms.notificationForm.subject.control}
{$i18n.label.condition}: {$forms.notificationForm.report_condition.control} {$i18n.label.what_is_it}{$i18n.label.email} (*): {$forms.notificationForm.email.control}
{$i18n.form.mail.cc}:{$forms.notificationForm.cc.control}
{$i18n.form.mail.subject}:{$forms.notificationForm.subject.control}
{$i18n.label.condition}: {$forms.notificationForm.report_condition.control} {$i18n.label.what_is_it}