From 3fe430d82ad416d1766b9f0cd558e2e1f26900a9 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Mon, 19 Nov 2018 15:41:51 +0000 Subject: [PATCH] Added notifications to import. --- WEB-INF/lib/ttOrgImportHelper.class.php | 72 +++++++++++++++++++++++-- WEB-INF/templates/footer.tpl | 2 +- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/WEB-INF/lib/ttOrgImportHelper.class.php b/WEB-INF/lib/ttOrgImportHelper.class.php index c57cc640..0da0a7ea 100644 --- a/WEB-INF/lib/ttOrgImportHelper.class.php +++ b/WEB-INF/lib/ttOrgImportHelper.class.php @@ -59,6 +59,7 @@ class ttOrgImportHelper { var $currentGroupLogMap = array(); var $currentGroupCustomFieldMap = array(); var $currentGroupCustomFieldOptionMap = array(); + var $currentGroupFavReportMap = array(); // Constructor. function __construct(&$errors) { @@ -455,6 +456,14 @@ class ttOrgImportHelper { return; } + if ($name == 'FAV_REPORTS') { + // If we get here, we have to recycle $currentGroupFavReportMap. + unset($this->currentGroupFavReportMap); + $this->currentGroupFavReportMap = array(); + // Favorite report map is reconstructed after processing elements in XML. See below. + return; + } + if ($name == 'FAV_REPORT') { $user_list = ''; if (strlen($attrs['USERS']) > 0) { @@ -462,7 +471,7 @@ class ttOrgImportHelper { foreach ($arr as $v) $user_list .= (strlen($user_list) == 0 ? '' : ',').$this->currentGroupUserMap[$v]; } - if (!$this->insertFavReport(array( + $fav_report_id = $this->insertFavReport(array( 'name' => $attrs['NAME'], 'user_id' => $this->currentGroupUserMap[$attrs['USER_ID']], 'group_id' => $this->current_group_id, @@ -492,10 +501,30 @@ class ttOrgImportHelper { 'group_by1' => $attrs['GROUP_BY1'], 'group_by2' => $attrs['GROUP_BY2'], 'group_by3' => $attrs['GROUP_BY3'], - 'chtotalsonly' => (int) $attrs['SHOW_TOTALS_ONLY']))) { - $this->errors->add($i18n->get('error.db')); - } - return; + 'chtotalsonly' => (int) $attrs['SHOW_TOTALS_ONLY'])); + if ($fav_report_id) { + // Add a mapping. + $this->currentGroupFavReportMap[$attrs['ID']] = $fav_report_id; + } else $this->errors->add($i18n->get('error.db')); + return; + } + + if ($name == 'NOTIFICATION') { + if (!$this->insertNotification(array( + 'group_id' => $this->current_group_id, + 'org_id' => $this->org_id, + 'cron_spec' => $attrs['CRON_SPEC'], + 'last' => $attrs['LAST'], + 'next' => $attrs['NEXT'], + 'report_id' => $this->currentGroupFavReportMap[$attrs['REPORT_ID']], + 'email' => $attrs['EMAIL'], + 'cc' => $attrs['CC'], + 'subject' => $attrs['SUBJECT'], + 'report_condition' => $attrs['REPORT_CONDITION'], + 'status' => $attrs['STATUS']))) { + $this->errors->add($i18n->get('error.db')); + } + return; } } } @@ -778,6 +807,39 @@ class ttOrgImportHelper { $mdb2->quote($fields['group_by1']).", ".$mdb2->quote($fields['group_by2']).", ". $mdb2->quote($fields['group_by3']).", ".$fields['chtotalsonly'].")"; $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + $sql = "select last_insert_id() as last_id"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) + return false; + + $val = $res->fetchRow(); + return $val['last_id']; + } + + // insertNotification function inserts a new notification into database. + static function insertNotification($fields) + { + $mdb2 = getConnection(); + + $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; + $cron_spec = $fields['cron_spec']; + $last = (int) $fields['last']; + $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". + " (group_id, org_id, cron_spec, last, next, report_id, email, cc, subject, report_condition, status)". + " values ($group_id, $org_id, ".$mdb2->quote($cron_spec).", $last, $next, $report_id, ".$mdb2->quote($email).", ".$mdb2->quote($cc).", ".$mdb2->quote($subject).", ".$mdb2->quote($report_condition).", ".$mdb2->quote($status).")"; + $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 855cc77e..01941ccc 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.20.4458 | Copyright © Anuko | +  Anuko Time Tracker 1.18.20.4459 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1