Skip to content

Commit 1b6699f

Browse files
committed
Added cc option for notifications.
1 parent eb14c12 commit 1b6699f

10 files changed

Lines changed: 54 additions & 9 deletions

WEB-INF/lib/ttNotificationHelper.class.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static function get($id)
3939

4040
$mdb2 = getConnection();
4141

42-
$sql = "select c.id, c.cron_spec, c.report_id, c.email, c.report_condition, c.status, fr.name from tt_cron c
42+
$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
4343
left join tt_fav_reports fr on (fr.id = c.report_id)
4444
where c.id = $id and c.team_id = $user->team_id";
4545
$res = $mdb2->query($sql);
@@ -75,11 +75,13 @@ static function insert($fields)
7575
$next = (int) $fields['next'];
7676
$report_id = (int) $fields['report_id'];
7777
$email = $fields['email'];
78+
$cc = $fields['cc'];
79+
$subject = $fields['subject'];
7880
$report_condition = $fields['report_condition'];
7981
$status = $fields['status'];
8082

81-
$sql = "insert into tt_cron (team_id, cron_spec, next, report_id, email, report_condition, status)
82-
values ($team_id, ".$mdb2->quote($cron_spec).", $next, $report_id, ".$mdb2->quote($email).", ".$mdb2->quote($report_condition).", ".$mdb2->quote($status).")";
83+
$sql = "insert into tt_cron (team_id, cron_spec, next, report_id, email, cc, subject, report_condition, status)
84+
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).")";
8385
$affected = $mdb2->exec($sql);
8486
if (is_a($affected, 'PEAR_Error'))
8587
return false;
@@ -98,10 +100,12 @@ static function update($fields)
98100
$next = (int) $fields['next'];
99101
$report_id = (int) $fields['report_id'];
100102
$email = $fields['email'];
103+
$cc = $fields['cc'];
104+
$subject = $fields['subject'];
101105
$report_condition = $fields['report_condition'];
102106
$status = $fields['status'];
103107

104-
$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).
108+
$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).
105109
" where id = $notification_id and team_id = $team_id";
106110
$affected = $mdb2->exec($sql);
107111
return (!is_a($affected, 'PEAR_Error'));

WEB-INF/lib/ttReportHelper.class.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ static function prepareFavReportBody($report)
15731573
}
15741574

15751575
// sendFavReport - sends a favorite report to a specified email, called from cron.php
1576-
static function sendFavReport($report, $email) {
1576+
static function sendFavReport($report, $subject, $email, $cc) {
15771577
// We are called from cron.php, we have no $bean in session.
15781578
// cron.php sets global $user and $i18n objects to match our favorite report user.
15791579
global $user;
@@ -1587,11 +1587,14 @@ static function sendFavReport($report, $email) {
15871587
$mailer->setCharSet(CHARSET);
15881588
$mailer->setContentType('text/html');
15891589
$mailer->setSender(SENDER);
1590+
if (!empty($cc))
1591+
$mailer->setReceiverCC($cc);
15901592
if (!empty($user->bcc_email))
15911593
$mailer->setReceiverBCC($user->bcc_email);
15921594
$mailer->setReceiver($email);
15931595
$mailer->setMailMode(MAIL_MODE);
1594-
if (!$mailer->send($report['name'], $body))
1596+
if (empty($subject)) $subject = $report['name'];
1597+
if (!$mailer->send($subject, $body))
15951598
return false;
15961599

15971600
return true;

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.12.0.3665 | 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.12.1.3666 | 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/notification_add.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
<td align="right">{$i18n.label.email} (*):</td>
1616
<td>{$forms.notificationForm.email.control}</td>
1717
</tr>
18+
<tr>
19+
<td align="right">{$i18n.form.mail.cc}:</td>
20+
<td>{$forms.notificationForm.cc.control}</td>
21+
</tr>
22+
<tr>
23+
<td align="right">{$i18n.form.mail.subject}:</td>
24+
<td>{$forms.notificationForm.subject.control}</td>
25+
</tr>
1826
<tr>
1927
<td align="right">{$i18n.label.condition}:</td>
2028
<td>{$forms.notificationForm.report_condition.control} <a href="https://www.anuko.com/lp/tt_9.htm" target="_blank">{$i18n.label.what_is_it}</a></td>

WEB-INF/templates/notification_edit.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
<td align="right">{$i18n.label.email} (*):</td>
1616
<td>{$forms.notificationForm.email.control}</td>
1717
</tr>
18+
<tr>
19+
<td align="right">{$i18n.form.mail.cc}:</td>
20+
<td>{$forms.notificationForm.cc.control}</td>
21+
</tr>
22+
<tr>
23+
<td align="right">{$i18n.form.mail.subject}:</td>
24+
<td>{$forms.notificationForm.subject.control}</td>
25+
</tr>
1826
<tr>
1927
<td align="right">{$i18n.label.condition}:</td>
2028
<td>{$forms.notificationForm.report_condition.control} <a href="https://www.anuko.com/lp/tt_9.htm" target="_blank">{$i18n.label.what_is_it}</a></td>

cron.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
$mdb2 = getConnection();
4848
$now = time();
4949

50-
$sql = "select c.id, c.cron_spec, c.report_id, c.email, c.report_condition from tt_cron c
50+
$sql = "select c.id, c.cron_spec, c.report_id, c.email, c.cc, c.subject, c.report_condition from tt_cron c
5151
left join tt_fav_reports fr on (c.report_id = fr.id)
5252
where $now >= c.next and fr.status = 1
5353
and c.status = 1 and c.report_id is not null and c.email is not null";
@@ -75,7 +75,7 @@
7575

7676
// Email report if condition is okay.
7777
if ($condition_ok) {
78-
if (ttReportHelper::sendFavReport($report, $val['email']))
78+
if (ttReportHelper::sendFavReport($report, $val['subject'], $val['email'], $val['cc']))
7979
echo "Report ".$val['report_id']. " sent to ".$val['email']."<br>";
8080
else
8181
echo "Error while emailing report...<br>";

dbinstall.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ function setChange($sql) {
641641
setChange("ALTER TABLE `tt_cron` ADD `report_condition` varchar(255) default NULL AFTER `email`");
642642
setChange("ALTER TABLE `tt_fav_reports` ADD `status` tinyint(4) default '1'");
643643
setChange("ALTER TABLE `tt_teams` ADD `bcc_email` varchar(100) default NULL AFTER `uncompleted_indicators`");
644+
setChange("ALTER TABLE `tt_cron` ADD `cc` varchar(100) default NULL AFTER `email`");
645+
setChange("ALTER TABLE `tt_cron` ADD `subject` varchar(100) default NULL AFTER `cc`");
644646
}
645647

646648
// The update_clients function updates projects field in tt_clients table.

mysql.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ CREATE TABLE `tt_cron` (
229229
`next` int(11) default NULL, # UNIX timestamp of when to run next job
230230
`report_id` int(11) default NULL, # report id from tt_fav_reports, a report to mail on schedule
231231
`email` varchar(100) default NULL, # email to send results to
232+
`cc` varchar(100) default NULL, # cc email to send results to
233+
`subject` varchar(100) default NULL, # email subject
232234
`report_condition` varchar(255) default NULL, # report condition, "count > 0" for sending not empty reports
233235
`status` tinyint(4) default '1', # entry status
234236
PRIMARY KEY (`id`)

notification_add.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
$cl_fav_report = trim($request->getParameter('fav_report'));
4646
$cl_cron_spec = trim($request->getParameter('cron_spec'));
4747
$cl_email = trim($request->getParameter('email'));
48+
$cl_cc = trim($request->getParameter('cc'));
49+
$cl_subject = trim($request->getParameter('subject'));
4850
$cl_report_condition = trim($request->getParameter('report_condition'));
4951
} else {
5052
$cl_cron_spec = '0 4 * * 1'; // Default schedule - weekly on Mondays at 04:00 (server time).
@@ -61,6 +63,8 @@
6163
));
6264
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'cron_spec','style'=>'width: 250px;','value'=>$cl_cron_spec));
6365
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','style'=>'width: 250px;','value'=>$cl_email));
66+
$form->addInput(array('type'=>'text','name'=>'cc','style'=>'width: 300px;','value'=>$cl_cc));
67+
$form->addInput(array('type'=>'text','name'=>'subject','style'=>'width: 300px;','value'=>$cl_subject));
6468
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'report_condition','style'=>'width: 250px;','value'=>$cl_report_condition));
6569
$form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->getKey('button.add')));
6670

@@ -69,6 +73,8 @@
6973
if (!$cl_fav_report) $err->add($i18n->getKey('error.report'));
7074
if (!ttValidCronSpec($cl_cron_spec)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.cron_schedule'));
7175
if (!ttValidEmail($cl_email)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email'));
76+
if (!ttValidEmail($cl_cc, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.cc'));
77+
if (!ttValidString($cl_subject, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.subject'));
7278
if (!ttValidCondition($cl_report_condition)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.condition'));
7379

7480
if ($err->no()) {
@@ -81,6 +87,8 @@
8187
'next' => $next,
8288
'report_id' => $cl_fav_report,
8389
'email' => $cl_email,
90+
'cc' => $cl_cc,
91+
'subject' => $cl_subject,
8492
'report_condition' => $cl_report_condition,
8593
'status' => ACTIVE))) {
8694
header('Location: notifications.php');

notification_edit.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@
4646
$cl_fav_report = trim($request->getParameter('fav_report'));
4747
$cl_cron_spec = trim($request->getParameter('cron_spec'));
4848
$cl_email = trim($request->getParameter('email'));
49+
$cl_cc = trim($request->getParameter('cc'));
50+
$cl_subject = trim($request->getParameter('subject'));
4951
$cl_report_condition = trim($request->getParameter('report_condition'));
5052
} else {
5153
$notification = ttNotificationHelper::get($notification_id);
5254
$cl_fav_report = $notification['report_id'];
5355
$cl_cron_spec = $notification['cron_spec'];
5456
$cl_email = $notification['email'];
57+
$cl_cc = $notification['cc'];
58+
$cl_subject = $notification['subject'];
5559
$cl_report_condition = $notification['report_condition'];
5660
}
5761

@@ -66,6 +70,8 @@
6670
'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
6771
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'cron_spec','style'=>'width: 250px;','value'=>$cl_cron_spec));
6872
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','style'=>'width: 250px;','value'=>$cl_email));
73+
$form->addInput(array('type'=>'text','name'=>'cc','style'=>'width: 300px;','value'=>$cl_cc));
74+
$form->addInput(array('type'=>'text','name'=>'subject','style'=>'width: 300px;','value'=>$cl_subject));
6975
$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'report_condition','style'=>'width: 250px;','value'=>$cl_report_condition));
7076
$form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.save')));
7177

@@ -74,6 +80,8 @@
7480
if (!$cl_fav_report) $err->add($i18n->getKey('error.report'));
7581
if (!ttValidCronSpec($cl_cron_spec)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.cron_schedule'));
7682
if (!ttValidEmail($cl_email)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.email'));
83+
if (!ttValidEmail($cl_cc, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.cc'));
84+
if (!ttValidString($cl_subject, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('form.mail.subject'));
7785
if (!ttValidCondition($cl_report_condition)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.condition'));
7886

7987
if ($err->no()) {
@@ -87,6 +95,8 @@
8795
'next' => $next,
8896
'report_id' => $cl_fav_report,
8997
'email' => $cl_email,
98+
'cc' => $cl_cc,
99+
'subject' => $cl_subject,
90100
'report_condition' => $cl_report_condition,
91101
'status' => ACTIVE))) {
92102
header('Location: notifications.php');

0 commit comments

Comments
 (0)