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 (!ttAccessCheck(right_manage_team)) {
38 header('Location: access_denied.php');
42 $notification_id = (int) $request->getParameter('id');
43 $fav_reports = ttFavReportHelper::getReports($user->id);
45 if ($request->isPost()) {
46 $cl_fav_report = trim($request->getParameter('fav_report'));
47 $cl_cron_spec = trim($request->getParameter('cron_spec'));
48 $cl_email = trim($request->getParameter('email'));
50 $notification = ttNotificationHelper::get($notification_id);
51 $cl_fav_report = $notification['report_id'];
52 $cl_cron_spec = $notification['cron_spec'];
53 $cl_email = $notification['email'];
56 $form = new Form('notificationForm');
57 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$notification_id));
58 $form->addInput(array('type'=>'combobox',
60 'style'=>'width: 250px;',
61 'value'=>$cl_fav_report,
63 'datakeys'=>array('id','name'),
64 'empty'=>array(''=>$i18n->getKey('dropdown.select'))));
65 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'cron_spec','style'=>'width: 250px;','value'=>$cl_cron_spec));
66 $form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'email','style'=>'width: 250px;','value'=>$cl_email));
67 $form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->getKey('button.save')));
69 if ($request->isPost()) {
70 // Validate user input.
71 if (!$cl_fav_report) $errors->add($i18n->getKey('error.report'));
72 if (!ttValidCronSpec($cl_cron_spec)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.cron_schedule'));
73 if (!ttValidEmail($cl_email)) $errors->add($i18n->getKey('error.field'), $i18n->getKey('label.email'));
76 // Calculate next execution time.
77 $next = tdCron::getNextOccurrence($cl_cron_spec, mktime());
79 if (ttNotificationHelper::update(array(
80 'id' => $notification_id,
81 'team_id' => $user->team_id,
82 'cron_spec' => $cl_cron_spec,
84 'report_id' => $cl_fav_report,
86 'status' => ACTIVE))) {
87 header('Location: notifications.php');
90 $errors->add($i18n->getKey('error.db'));
94 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
95 $smarty->assign('title', $i18n->getKey('title.add_notification'));
96 $smarty->assign('content_page_name', 'notification_edit.tpl');
97 $smarty->display('index.tpl');