From 49c25be4ace17ab7495824a08c37a061a5a75b25 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 2 Dec 2018 16:18:14 +0000 Subject: [PATCH] More refactoring in custom fields for subgroups. --- WEB-INF/lib/ttReportHelper.class.php | 6 +++--- WEB-INF/lib/ttWeekViewHelper.class.php | 2 +- WEB-INF/templates/footer.tpl | 2 +- mobile/time.php | 2 +- mobile/time_edit.php | 2 +- mobile/timer.php | 2 +- plugins/CustomFields.class.php | 12 +++++++++--- report.php | 2 +- reports.php | 2 +- time.php | 2 +- time_edit.php | 2 +- tofile.php | 2 +- topdf.php | 2 +- week.php | 2 +- 14 files changed, 24 insertions(+), 18 deletions(-) diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 16277bd1..0d99ce88 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -157,7 +157,7 @@ class ttReportHelper { // Add custom field. $include_cf_1 = $options['show_custom_field_1'] || $grouping_by_cf_1; if ($include_cf_1) { - $custom_fields = new CustomFields($user->getGroup()); + $custom_fields = new CustomFields(); $cf_1_type = $custom_fields->fields[0]['type']; if ($cf_1_type == CustomFields::TYPE_TEXT) { array_push($fields, 'cfl.value as cf_1'); @@ -616,7 +616,7 @@ class ttReportHelper { // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) - $custom_fields = new CustomFields($user->getGroup()); + $custom_fields = new CustomFields(); // Define some styles to use in email. $style_title = 'text-align: center; font-size: 15pt; font-family: Arial, Helvetica, sans-serif;'; @@ -1460,7 +1460,7 @@ class ttReportHelper { $join .= ' left join tt_tasks t on (l.task_id = t.id)'; } if (ttReportHelper::groupingBy('cf_1', $options)) { - $custom_fields = new CustomFields($user->getGroup()); + $custom_fields = new CustomFields(); if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT) $join .= ' left join tt_custom_field_log cfl on (l.id = cfl.log_id and cfl.status = 1) left join tt_custom_field_options cfo on (cfl.value = cfo.id)'; elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN) diff --git a/WEB-INF/lib/ttWeekViewHelper.class.php b/WEB-INF/lib/ttWeekViewHelper.class.php index 2cfb3813..782f309b 100644 --- a/WEB-INF/lib/ttWeekViewHelper.class.php +++ b/WEB-INF/lib/ttWeekViewHelper.class.php @@ -45,7 +45,7 @@ class ttWeekViewHelper { $custom_field_1 = null; if ($user->isPluginEnabled('cf')) { - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); $cf_1_type = $custom_fields->fields[0]['type']; if ($cf_1_type == CustomFields::TYPE_TEXT) { $custom_field_1 = ', cfl.value as cf_1_value'; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index b0529d29..c391edf4 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4569 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4570 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mobile/time.php b/mobile/time.php index c8ec9797..9e51633b 100644 --- a/mobile/time.php +++ b/mobile/time.php @@ -60,7 +60,7 @@ $next_date = date('Y-m-d', strtotime('+1 day', strtotime($cl_date))); // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('../plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } diff --git a/mobile/time_edit.php b/mobile/time_edit.php index cbe4c935..60a14e2c 100644 --- a/mobile/time_edit.php +++ b/mobile/time_edit.php @@ -53,7 +53,7 @@ if (!$time_rec || $time_rec['invoice_id']) { // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('../plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } diff --git a/mobile/timer.php b/mobile/timer.php index bf92a89e..184e6274 100644 --- a/mobile/timer.php +++ b/mobile/timer.php @@ -54,7 +54,7 @@ $_SESSION['date'] = $cl_date; // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('../plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } diff --git a/plugins/CustomFields.class.php b/plugins/CustomFields.class.php index a2e88326..a7945aba 100644 --- a/plugins/CustomFields.class.php +++ b/plugins/CustomFields.class.php @@ -37,11 +37,16 @@ class CustomFields { var $options = array(); // Array of options for a dropdown custom field. // Constructor. - function __construct($group_id) { + function __construct() { + global $user; $mdb2 = getConnection(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + // Get fields. - $sql = "select id, type, label, required from tt_custom_fields where group_id = $group_id and status = 1 and type > 0"; + $sql = "select id, type, label, required from tt_custom_fields". + " where group_id = $group_id and org_id = $org_id and status = 1 and type > 0"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -52,7 +57,8 @@ class CustomFields { // If we have a dropdown obtain options for it. if ((count($this->fields) > 0) && ($this->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)) { - $sql = "select id, value from tt_custom_field_options where field_id = ".$this->fields[0]['id']." and status = 1 order by value"; + $sql = "select id, value from tt_custom_field_options". + " where field_id = ".$this->fields[0]['id']." and group_id = $group_id and org_id = $org_id and status = 1 order by value"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { diff --git a/report.php b/report.php index 28e086c4..1a8ce63c 100644 --- a/report.php +++ b/report.php @@ -54,7 +54,7 @@ if ($user->isPluginEnabled('iv')) { // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } diff --git a/reports.php b/reports.php index efbf9642..8310f5dd 100644 --- a/reports.php +++ b/reports.php @@ -46,7 +46,7 @@ if (!(ttAccessAllowed('view_own_reports') || ttAccessAllowed('view_reports') || // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } diff --git a/time.php b/time.php index fb507fb5..a428b9a2 100644 --- a/time.php +++ b/time.php @@ -89,7 +89,7 @@ $_SESSION['date'] = $cl_date; // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($group_id); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } diff --git a/time_edit.php b/time_edit.php index f4eb41d2..4b3f4c2c 100644 --- a/time_edit.php +++ b/time_edit.php @@ -53,7 +53,7 @@ if (!$time_rec || $time_rec['invoice_id']) { // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->getGroup()); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } diff --git a/tofile.php b/tofile.php index 445b32d9..990b8a55 100644 --- a/tofile.php +++ b/tofile.php @@ -41,7 +41,7 @@ if (!(ttAccessAllowed('view_own_reports') || ttAccessAllowed('view_reports'))) { // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); } // Report settings are stored in session bean before we get here. diff --git a/topdf.php b/topdf.php index e3801d27..fd3016e5 100644 --- a/topdf.php +++ b/topdf.php @@ -52,7 +52,7 @@ require_once('WEB-INF/lib/tcpdf/tcpdf.php'); // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); } // Report settings are stored in session bean before we get here. diff --git a/week.php b/week.php index 95dc31b1..289d9512 100644 --- a/week.php +++ b/week.php @@ -84,7 +84,7 @@ $endDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,$t_arr[3]-$t_arr[6]+6+$startWeek // Use custom fields plugin if it is enabled. if ($user->isPluginEnabled('cf')) { require_once('plugins/CustomFields.class.php'); - $custom_fields = new CustomFields($user->group_id); + $custom_fields = new CustomFields(); $smarty->assign('custom_fields', $custom_fields); } -- 2.20.1