From: Nik Okuntseff Date: Fri, 7 Dec 2018 17:48:04 +0000 (+0000) Subject: Refactored ttNotificationHelper class for subgroups. X-Git-Tag: timetracker_1.19-1~456 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=30f870da6d0f5d73cd6f33ab284ff45559d1ee13;p=timetracker.git Refactored ttNotificationHelper class for subgroups. --- diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 3ae408af..4ba7805e 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -423,4 +423,27 @@ class ttGroupHelper { } return $result; } + + // getNotifications - obtains notification descriptions for a group. + static function getNotifications() { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $result = array(); + $sql = "select c.id, c.cron_spec, c.email, c.report_condition, fr.name from tt_cron c". + " left join tt_fav_reports fr on (fr.id = c.report_id)". + " where c.group_id = $group_id and c.org_id = $org_id and c.status = 1 and fr.status = 1"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + return $result; + } + return false; + } } diff --git a/WEB-INF/lib/ttNotificationHelper.class.php b/WEB-INF/lib/ttNotificationHelper.class.php index c9f0a1e9..8e5cb8af 100644 --- a/WEB-INF/lib/ttNotificationHelper.class.php +++ b/WEB-INF/lib/ttNotificationHelper.class.php @@ -30,15 +30,16 @@ class ttNotificationHelper { // get - gets notification details. - static function get($id) - { + static function get($id) { global $user; - $mdb2 = getConnection(); - $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.group_id = ".$user->getGroup(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $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.group_id = $group_id and c.org_id = $org_id"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); @@ -51,25 +52,27 @@ class ttNotificationHelper { // delete - deletes a notification from tt_cron table. static function delete($id) { global $user; - $mdb2 = getConnection(); - - $sql = "delete from tt_cron where id = $id and group_id = ".$user->getGroup(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "delete from tt_cron where id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; - return true; + return true; } // insert function inserts a new notification into database. - static function insert($fields) - { + static function insert($fields) { global $user; $mdb2 = getConnection(); $group_id = $user->getGroup(); $org_id = $user->org_id; + $cron_spec = $fields['cron_spec']; $next = (int) $fields['next']; $report_id = (int) $fields['report_id']; @@ -89,12 +92,14 @@ class ttNotificationHelper { } // update function - updates a notification in database. - static function update($fields) - { + static function update($fields) { + global $user; $mdb2 = getConnection(); - + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $notification_id = (int) $fields['id']; - $group_id = (int) $fields['group_id']; $cron_spec = $fields['cron_spec']; $next = (int) $fields['next']; $report_id = (int) $fields['report_id']; @@ -104,8 +109,11 @@ class ttNotificationHelper { $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).", cc = ".$mdb2->quote($cc).", subject = ".$mdb2->quote($subject).", report_condition = ".$mdb2->quote($report_condition).", status = ".$mdb2->quote($status). - " where id = $notification_id and group_id = $group_id"; + $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 group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index 16896ac5..cf455405 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -508,25 +508,6 @@ class ttTeamHelper { return false; } - // getNotifications - obtains notification descriptions for a group. - static function getNotifications($group_id) { - $mdb2 = getConnection(); - - $result = array(); - $sql = "select c.id, c.cron_spec, c.email, c.report_condition, fr.name from tt_cron c - left join tt_fav_reports fr on (fr.id = c.report_id) - where c.group_id = $group_id and c.status = 1 and fr.status = 1"; - $res = $mdb2->query($sql); - $result = array(); - if (!is_a($res, 'PEAR_Error')) { - while ($val = $res->fetchRow()) { - $result[] = $val; - } - return $result; - } - return false; - } - // getMonthlyQuotas - obtains monthly quotas for a group. static function getMonthlyQuotas($group_id) { $mdb2 = getConnection(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index cd126f2c..bdd2fd61 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4608 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4609 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/notification_edit.php b/notification_edit.php index 69535815..7442305a 100644 --- a/notification_edit.php +++ b/notification_edit.php @@ -94,7 +94,6 @@ if ($request->isPost()) { if (ttNotificationHelper::update(array( 'id' => $notification_id, - 'group_id' => $user->group_id, 'cron_spec' => $cl_cron_spec, 'next' => $next, 'report_id' => $cl_fav_report, diff --git a/notifications.php b/notifications.php index 23400beb..d70f5b48 100644 --- a/notifications.php +++ b/notifications.php @@ -28,7 +28,7 @@ require_once('initialize.php'); import('form.Form'); -import('ttTeamHelper'); +import('ttGroupHelper'); // Access checks. if (!ttAccessAllowed('manage_advanced_settings')) { @@ -50,7 +50,7 @@ if ($request->isPost()) { } } else { $form->addInput(array('type'=>'submit','name'=>'btn_add','value'=>$i18n->get('button.add'))); - $notifications = ttTeamHelper::getNotifications($user->group_id); + $notifications = ttGroupHelper::getNotifications(); } $smarty->assign('forms', array($form->getName()=>$form->toArray()));