2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 require_once('initialize.php');
30 require_once(LIBRARY_DIR.'/tdcron/class.tdcron.php');
31 require_once(LIBRARY_DIR.'/tdcron/class.tdcron.entry.php');
33 import('ttFavReportHelper');
34 import('ttNotificationHelper');
37 if (!ttAccessAllowed('manage_advanced_settings')) {
38 header('Location: access_denied.php');
41 if (!$user->isPluginEnabled('no')) {
42 header('Location: feature_disabled.php');
45 if (!$user->exists()) {
46 header('Location: access_denied.php'); // No users in subgroup.
49 $notification_id = (int)$request->getParameter('id');
50 $notification = ttNotificationHelper::get($notification_id);
52 header('Location: access_denied.php'); // Wrong notification id.
55 if ($request->isPost()) {
56 $cl_fav_report_id = (int) $request->getParameter('fav_report');
57 if ($cl_fav_report_id && !ttFavReportHelper::get($cl_fav_report_id)) {
58 header('Location: access_denied.php'); // Invalid fav report id in post.
62 // End of access checks.
64 $fav_reports = ttFavReportHelper::getReports();
66 if ($request->isPost()) {
67 $cl_cron_spec = trim($request->getParameter('cron_spec'));
68 $cl_email = trim($request->getParameter('email'));
69 $cl_cc = trim($request->getParameter('cc'));
70 $cl_subject = trim($request->getParameter('subject'));
71 $cl_report_condition = trim($request->getParameter('report_condition'));
73 $notification = ttNotificationHelper::get($notification_id);
74 $cl_fav_report_id = $notification['report_id'];
75 $cl_cron_spec = $notification['cron_spec'];
76 $cl_email = $notification['email'];
77 $cl_cc = $notification['cc'];
78 $cl_subject = $notification['subject'];
79 $cl_report_condition = $notification['report_condition'];
82 $form = new Form('notificationForm');
83 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$notification_id));
84 $form->addInput(array('type'=>'combobox',
86 'style'=>'width: 250px;',
87 'value'=>$cl_fav_report_id,
89 'datakeys'=>array('id','name'),
90 'empty'=>array(''=>$i18n->get('dropdown.select'))));
91 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'cron_spec','style'=>'width: 250px;','value'=>$cl_cron_spec));
92 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','style'=>'width: 250px;','value'=>$cl_email));
93 $form->addInput(array('type'=>'text','name'=>'cc','style'=>'width: 300px;','value'=>$cl_cc));
94 $form->addInput(array('type'=>'text','name'=>'subject','style'=>'width: 300px;','value'=>$cl_subject));
95 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'report_condition','style'=>'width: 250px;','value'=>$cl_report_condition));
96 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.save')));
98 if ($request->isPost()) {
99 // Validate user input.
100 if (!$cl_fav_report_id) $err->add($i18n->get('error.report'));
101 if (!ttValidCronSpec($cl_cron_spec)) $err->add($i18n->get('error.field'), $i18n->get('label.schedule'));
102 if (!ttValidEmail($cl_email)) $err->add($i18n->get('error.field'), $i18n->get('label.email'));
103 if (!ttValidEmail($cl_cc, true)) $err->add($i18n->get('error.field'), $i18n->get('label.cc'));
104 if (!ttValidString($cl_subject, true)) $err->add($i18n->get('error.field'), $i18n->get('label.subject'));
105 if (!ttValidCondition($cl_report_condition)) $err->add($i18n->get('error.field'), $i18n->get('label.condition'));
108 // Calculate next execution time.
109 $next = tdCron::getNextOccurrence($cl_cron_spec, mktime());
111 if (ttNotificationHelper::update(array(
112 'id' => $notification_id,
113 'cron_spec' => $cl_cron_spec,
115 'report_id' => $cl_fav_report_id,
116 'email' => $cl_email,
118 'subject' => $cl_subject,
119 'report_condition' => $cl_report_condition,
120 'status' => ACTIVE))) {
121 header('Location: notifications.php');
124 $err->add($i18n->get('error.db'));
128 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
129 $smarty->assign('title', $i18n->get('title.edit_notification'));
130 $smarty->assign('content_page_name', 'notification_edit.tpl');
131 $smarty->display('index.tpl');