From d74142948db5d27a3bf144a8ee485318cc1330c3 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Thu, 20 Dec 2018 17:43:55 +0000 Subject: [PATCH] Introduced ttBehalfUser class for quote percent work. --- WEB-INF/lib/ttBehalfUser.class.php | 61 ++++++++++++++++++++++++++++++ WEB-INF/lib/ttGroup.class.php | 2 + WEB-INF/lib/ttUser.class.php | 19 +++++++--- WEB-INF/templates/footer.tpl | 2 +- 4 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 WEB-INF/lib/ttBehalfUser.class.php diff --git a/WEB-INF/lib/ttBehalfUser.class.php b/WEB-INF/lib/ttBehalfUser.class.php new file mode 100644 index 00000000..7f7a5ffa --- /dev/null +++ b/WEB-INF/lib/ttBehalfUser.class.php @@ -0,0 +1,61 @@ +query($sql); + if (is_a($res, 'PEAR_Error')) return; + + $val = $res->fetchRow(); + if ($val['id'] > 0) { + $this->name = $val['name']; + $this->id = $val['id']; + if ($val['quota_percent']) $this->quota_percent = $val['quota_percent']; + } + } +} diff --git a/WEB-INF/lib/ttGroup.class.php b/WEB-INF/lib/ttGroup.class.php index 5ef258ca..9c12e95b 100644 --- a/WEB-INF/lib/ttGroup.class.php +++ b/WEB-INF/lib/ttGroup.class.php @@ -63,6 +63,8 @@ class ttGroup { // We need a non-zero count to display some menus. // Constructor. + // Note: org_id is needed because we construct an object in ttUser constructor, + // when global $user object does not yet exist. function __construct($id, $org_id) { $mdb2 = getConnection(); diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index ab2b4bce..4145f603 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -28,6 +28,7 @@ import('ttConfigHelper'); import('ttGroupHelper'); +import('ttBehalfUser'); import('ttGroup'); import('form.Form'); import('form.ActionForm'); @@ -42,6 +43,7 @@ class ttUser { var $role_name = null; // Role name. var $rank = null; // User role rank. var $client_id = null; // Client id for client user role. + var $quota_percent = 100.0; // Time quota percent for quotas plugin. var $behalf_id = null; // User id, on behalf of whom we are working. var $behalf_group_id = null; // Group id, on behalf of which we are working. var $behalf_name = null; // User name, on behalf of whom we are working. @@ -73,6 +75,7 @@ class ttUser { var $rights = array(); // An array of user rights such as 'track_own_time', etc. var $is_client = false; // Whether user is a client as determined by missing 'track_own_time' right. + var $behalfUser = null; // A ttBehalfUser instance with on behalf user attributes. var $behalfGroup = null; // A ttGroup instance with on behalf group attributes. // Constructor. @@ -84,11 +87,11 @@ class ttUser { $mdb2 = getConnection(); - $sql = "SELECT u.id, u.login, u.name, u.group_id, u.role_id, r.rank, r.name as role_name, r.rights, u.client_id, u.email, - g.org_id, g.name as group_name, g.currency, g.lang, g.decimal_mark, g.date_format, g.time_format, g.week_start, - g.tracking_mode, g.project_required, g.task_required, g.record_type, - g.bcc_email, g.allow_ip, g.password_complexity, g.plugins, g.config, g.lock_spec, g.workday_minutes, g.custom_logo - FROM tt_users u LEFT JOIN tt_groups g ON (u.group_id = g.id) LEFT JOIN tt_roles r on (r.id = u.role_id) WHERE "; + $sql = "SELECT u.id, u.login, u.name, u.group_id, u.role_id, r.rank, r.name as role_name, r.rights, u.client_id,". + " u.quota_percent, u.email, g.org_id, g.name as group_name, g.currency, g.lang, g.decimal_mark, g.date_format,". + " g.time_format, g.week_start, g.tracking_mode, g.project_required, g.task_required, g.record_type,". + " g.bcc_email, g.allow_ip, g.password_complexity, g.plugins, g.config, g.lock_spec, g.workday_minutes, g.custom_logo". + " FROM tt_users u LEFT JOIN tt_groups g ON (u.group_id = g.id) LEFT JOIN tt_roles r on (r.id = u.role_id) WHERE "; if ($id) $sql .= "u.id = $id"; else @@ -113,6 +116,7 @@ class ttUser { $this->rank = $val['rank']; $this->client_id = $val['client_id']; $this->is_client = $this->client_id && !in_array('track_own_time', $this->rights); + if ($val['quota_percent']) $this->quota_percent = $val['quota_percent']; $this->email = $val['email']; $this->lang = $val['lang']; $this->decimal_mark = $val['decimal_mark']; @@ -145,6 +149,8 @@ class ttUser { if (isset($_SESSION['behalf_id'])) { $this->behalf_id = $_SESSION['behalf_id']; $this->behalf_name = $_SESSION['behalf_name']; + + $this->behalfUser = new ttBehalfUser($this->behalf_id, $this->org_id); } // Set "on behalf" id and name (group). if (isset($_SESSION['behalf_group_id'])) { @@ -824,6 +830,7 @@ class ttUser { // Unset things first. $this->behalf_id = null; $this->behalf_name = null; + unset($this->behalfUser); unset($_SESSION['behalf_id']); unset($_SESSION['behalf_name']); @@ -839,6 +846,8 @@ class ttUser { $_SESSION['behalf_name'] = $onBehalfUserName; $this->behalf_id = $user_id; $this->behalf_name = $onBehalfUserName; + + $this->behalfUser = new ttBehalfUser($this->behalf_id, $this->org_id); return; } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 496a9fb2..7d3abc65 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.34.4670 | Copyright © Anuko | +  Anuko Time Tracker 1.18.34.4671 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1