From: Nik Okuntseff Date: Tue, 11 Dec 2018 16:12:33 +0000 (+0000) Subject: More refactoring in reports for subgroups. X-Git-Tag: timetracker_1.19-1~431 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=24759567f66e185d193d48b81acef9b842d96c84;p=timetracker.git More refactoring in reports for subgroups. --- diff --git a/WEB-INF/lib/ttFavReportHelper.class.php b/WEB-INF/lib/ttFavReportHelper.class.php index d3783009..165f42a3 100644 --- a/WEB-INF/lib/ttFavReportHelper.class.php +++ b/WEB-INF/lib/ttFavReportHelper.class.php @@ -90,10 +90,16 @@ class ttFavReportHelper { } // getReportByName - returns a report identified by its name. - static function getReportByName($user_id, $report_name) { + static function getReportByName($report_name) { + global $user; $mdb2 = getConnection(); - $sql = "select * from tt_fav_reports where user_id = $user_id and status = 1 and name = ".$mdb2->quote($report_name); + $user_id = $user->getUser(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select id from tt_fav_reports". + " where user_id = $user_id and group_id = $group_id and org_id = $org_id and status = 1 and name = ".$mdb2->quote($report_name); $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { if ($val = $res->fetchRow()) { @@ -108,6 +114,7 @@ class ttFavReportHelper { global $user; $mdb2 = getConnection(); + $user_id = $user->getUser(); $group_id = $user->getGroup(); $org_id = $user->org_id; @@ -119,7 +126,7 @@ class ttFavReportHelper { " show_task, show_end, show_note, show_custom_field_1, show_work_units,". " group_by1, group_by2, group_by3, show_totals_only)". " values(". - $mdb2->quote($fields['name']).", ".$fields['user_id'].", $group_id, $org_id, ". + $mdb2->quote($fields['name']).", $user_id, $group_id, $org_id, ". $mdb2->quote($fields['client']).", ".$mdb2->quote($fields['option']).", ". $mdb2->quote($fields['project']).", ".$mdb2->quote($fields['task']).", ". $mdb2->quote($fields['billable']).", ".$mdb2->quote($fields['invoice']).", ". @@ -140,8 +147,14 @@ class ttFavReportHelper { } // updateReport - updates report options in the database. - function updateReport($fields) { + static function updateReport($fields) { + global $user; $mdb2 = getConnection(); + + $user_id = $user->getUser(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $sql = "update tt_fav_reports set ". "name = ".$mdb2->quote($fields['name']).", ". "client_id = ".$mdb2->quote($fields['client']).", ". @@ -172,7 +185,7 @@ class ttFavReportHelper { "group_by2 = ".$mdb2->quote($fields['group_by2']).", ". "group_by3 = ".$mdb2->quote($fields['group_by3']).", ". "show_totals_only = ".$fields['chtotalsonly']. - " where id = ".$fields['id']; + " where id = ".$fields['id']." and user_id = $user_id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -183,7 +196,6 @@ class ttFavReportHelper { // saveReport - saves report options in the database. static function saveReport($bean) { global $user; - $user_id = $user->getUser(); // Set default value of 0 for not set checkboxes (in bean). // Later in this function we use it to construct $fields array to update database. @@ -247,12 +259,11 @@ class ttFavReportHelper { 'chtotalsonly'=>$bean->getAttribute('chtotalsonly')); $id = false; - $report = ttFavReportHelper::getReportByName($user_id, $fields['name']); + $report = ttFavReportHelper::getReportByName($fields['name']); if ($report) { $fields['id'] = $report['id']; $id = ttFavReportHelper::updateReport($fields); } else { - $fields['user_id'] = $user_id; $id = ttFavReportHelper::insertReport($fields); } @@ -261,9 +272,21 @@ class ttFavReportHelper { // deleteReport - deletes a favorite report. static function deleteReport($id) { + global $user; $mdb2 = getConnection(); - $sql = "delete from tt_fav_reports where id = $id"; + $user_id = $user->getUser(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "delete from tt_cron". + " where report_id = $id and group_id = $group_id and org_id = $org_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + $sql = "delete from tt_fav_reports". + " where id = $id and user_id = $user_id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } @@ -273,7 +296,7 @@ class ttFavReportHelper { global $user; $user_id = $user->getUser(); - $val = ttFavReportHelper::getReport($bean->getAttribute('favorite_report')); + $val = ttFavReportHelper::get($bean->getAttribute('favorite_report')); if ($val) { $bean->setAttribute('client', $val['client_id']); $bean->setAttribute('option', $val['cf_1_option_id']); diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 780e39ed..ad231675 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -564,4 +564,23 @@ class ttGroupHelper { return true; // All is good. } + + // The getUsers obtains all active and inactive (but not deleted) users in a group. + static function getUsers() { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select id, name from tt_users where group_id = $group_id and org_id = $org_id and (status = 1 or status = 0) order by upper(name)"; + $res = $mdb2->query($sql); + $user_list = array(); + if (is_a($res, 'PEAR_Error')) + return false; + while ($val = $res->fetchRow()) { + $user_list[] = $val; + } + return $user_list; + } } diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 0d99ce88..13226ca4 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -1010,7 +1010,7 @@ class ttReportHelper { // Check users. $users_in_bean = $bean->getAttribute('users'); if (is_array($users_in_bean)) { - $users_in_group = ttTeamHelper::getUsers(); + $users_in_group = ttGroupHelper::getUsers(); foreach ($users_in_group as $user_in_group) { $valid_ids[] = $user_in_group['id']; } diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index 3fc06cc7..4dd2f9aa 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -104,21 +104,6 @@ class ttTeamHelper { return $user_list; } - // The getUsers obtains all active and inactive (but not deleted) users in a group. - static function getUsers() { - global $user; - $mdb2 = getConnection(); - $sql = "select id, name from tt_users where group_id = $user->group_id and (status = 1 or status = 0) order by upper(name)"; - $res = $mdb2->query($sql); - $user_list = array(); - if (is_a($res, 'PEAR_Error')) - return false; - while ($val = $res->fetchRow()) { - $user_list[] = $val; - } - return $user_list; - } - // The getInactiveUsers obtains all inactive users in a group. static function getInactiveUsers($group_id, $all_fields = false) { $mdb2 = getConnection(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index c49c2e56..244dc313 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4633 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4634 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/reports.php b/reports.php index 7c7ac011..c3bb8809 100644 --- a/reports.php +++ b/reports.php @@ -332,12 +332,12 @@ if ($request->isPost()) { } else { // Generate button pressed. Check some values. if (!$bean->getAttribute('period')) { - $start_date = new DateAndTime($user->date_format, $bean->getAttribute('start_date')); + $start_date = new DateAndTime($user->getDateFormat(), $bean->getAttribute('start_date')); if ($start_date->isError() || !$bean->getAttribute('start_date')) $err->add($i18n->get('error.field'), $i18n->get('label.start_date')); - $end_date = new DateAndTime($user->date_format, $bean->getAttribute('end_date')); + $end_date = new DateAndTime($user->getDateFormat(), $bean->getAttribute('end_date')); if ($end_date->isError() || !$bean->getAttribute('end_date')) $err->add($i18n->get('error.field'), $i18n->get('label.end_date'));