From 448c3e07930dbf902c97c93f252a474cb0931e23 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Thu, 20 Dec 2018 22:09:50 +0000 Subject: [PATCH] Initial attempt to implement quota percent for users. --- WEB-INF/lib/ttUser.class.php | 2 +- WEB-INF/lib/ttUserHelper.class.php | 12 +++++++++--- WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/user_add.tpl | 8 +++++++- WEB-INF/templates/user_edit.tpl | 8 +++++++- user_add.php | 15 +++++++++++++-- user_edit.php | 16 ++++++++++++++-- 7 files changed, 52 insertions(+), 11 deletions(-) diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 7d6ee6de..f163e581 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -542,7 +542,7 @@ class ttUser { // then rank restriction does not apply. $max_rank = $this->behalfGroup ? MAX_RANK : $this->rank; - $sql = "select u.id, u.name, u.login, u.role_id, u.client_id, u.status, u.rate, u.email from tt_users u". + $sql = "select u.id, u.name, u.login, u.role_id, u.client_id, u.status, u.rate, u.quota_percent, u.email from tt_users u". " left join tt_roles r on (u.role_id = r.id)". " where u.id = $user_id and u.group_id = $group_id and u.org_id = $org_id and u.status is not null". " and (r.rank < $max_rank or (r.rank = $max_rank and u.id = $this->id))"; // Users with lesser roles or self. diff --git a/WEB-INF/lib/ttUserHelper.class.php b/WEB-INF/lib/ttUserHelper.class.php index f91128e7..26ced938 100644 --- a/WEB-INF/lib/ttUserHelper.class.php +++ b/WEB-INF/lib/ttUserHelper.class.php @@ -104,6 +104,7 @@ class ttUserHelper { $group_id = (int) $fields['group_id']; $org_id = (int) $fields['org_id']; $rate = str_replace(',', '.', isset($fields['rate']) ? $fields['rate'] : 0); + $quota_percent = str_replace(',', '.', isset($fields['quota_percent']) ? $fields['quota_percent'] : 100); if($rate == '') $rate = 0; if (array_key_exists('status', $fields)) { // Key exists and may be NULL during migration of deleted acounts. @@ -113,9 +114,9 @@ class ttUserHelper { $created_ip_v = ', '.$mdb2->quote($_SERVER['REMOTE_ADDR']); $created_by_v = ', '.$user->id; - $sql = "insert into tt_users (name, login, password, group_id, org_id, role_id, client_id, rate, email, created, created_ip, created_by $status_f) values (". + $sql = "insert into tt_users (name, login, password, group_id, org_id, role_id, client_id, rate, quota_percent, email, created, created_ip, created_by $status_f) values (". $mdb2->quote($fields['name']).", ".$mdb2->quote($fields['login']). - ", $password, $group_id, $org_id, ".$mdb2->quote($fields['role_id']).", ".$mdb2->quote($fields['client_id']).", $rate, ".$mdb2->quote($email).", now() $created_ip_v $created_by_v $status_v)"; + ", $password, $group_id, $org_id, ".$mdb2->quote($fields['role_id']).", ".$mdb2->quote($fields['client_id']).", $rate, $quota_percent, ".$mdb2->quote($email).", now() $created_ip_v $created_by_v $status_v)"; $affected = $mdb2->exec($sql); // Now deal with project assignment. @@ -178,6 +179,11 @@ class ttUserHelper { $rate_part = ", rate = ".$mdb2->quote($rate); } + if (array_key_exists('quota_percent', $fields)) { + $quota_percent = str_replace(',', '.', isset($fields['quota_percent']) ? $fields['quota_percent'] : 100); + $quota_percent_part = ", quota_percent = ".$mdb2->quote($quota_percent); + } + if (isset($fields['email'])) $email_part = ', email = '.$mdb2->quote($fields['email']); @@ -187,7 +193,7 @@ class ttUserHelper { } $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$user->id; - $parts = ltrim($login_part.$pass_part.$name_part.$role_part.$client_part.$rate_part.$email_part.$modified_part.$status_part, ','); + $parts = ltrim($login_part.$pass_part.$name_part.$role_part.$client_part.$rate_part.$quota_percent_part.$email_part.$modified_part.$status_part, ','); $sql = "update tt_users set $parts". " where id = $user_id and group_id = $group_id and org_id = $org_id"; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index a0c889c8..b1c606f4 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- -{if ($smarty.const.MODE_PROJECTS == $user->getTrackingMode() || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) && $show_projects} +{if $show_quota} + + + + +{/if} +{if $show_projects} diff --git a/WEB-INF/templates/user_edit.tpl b/WEB-INF/templates/user_edit.tpl index 0c24a011..b1026f2c 100644 --- a/WEB-INF/templates/user_edit.tpl +++ b/WEB-INF/templates/user_edit.tpl @@ -115,7 +115,13 @@ function handleClientControl() { -{if ($smarty.const.MODE_PROJECTS == $user->getTrackingMode() || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->getTrackingMode()) && $show_projects} +{if $show_quota} + + + + +{/if} +{if $show_projects} diff --git a/user_add.php b/user_add.php index 28baa2cf..6f1e02c1 100644 --- a/user_add.php +++ b/user_add.php @@ -46,6 +46,7 @@ if (!ttAccessAllowed('manage_users')) { // The "limit" plugin is not required for normal operation of Time Tracker. @include('plugins/limit/user_add.php'); +$show_quota = $user->isPluginEnabled('mq'); if ($user->isPluginEnabled('cl')) $clients = ttGroupHelper::getActiveClients(); @@ -61,6 +62,7 @@ if ($request->isPost()) { $cl_role_id = $request->getParameter('role'); $cl_client_id = $request->getParameter('client'); $cl_rate = $request->getParameter('rate'); + $cl_quota_percent = $request->getParameter('quota_percent'); $cl_projects = $request->getParameter('projects'); if (is_array($cl_projects)) { foreach ($cl_projects as $p) { @@ -90,8 +92,14 @@ if ($user->isPluginEnabled('cl')) $form->addInput(array('type'=>'combobox','name'=>'client','value'=>$cl_client_id,'data'=>$clients,'datakeys'=>array('id', 'name'),'empty'=>array(''=>$i18n->get('dropdown.select')))); $form->addInput(array('type'=>'floatfield','maxlength'=>'10','name'=>'rate','format'=>'.2','value'=>$cl_rate)); +if ($show_quota) + $form->addInput(array('type'=>'floatfield','maxlength'=>'10','name'=>'quota_percent','format'=>'.2','value'=>$cl_quota_percent)); -$projects = ttGroupHelper::getActiveProjects(); +$show_projects = MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode(); +if ($show_projects) { + $projects = ttGroupHelper::getActiveProjects(); + if (count($projects) == 0) $show_projects = false; +} // Define classes for the projects table. class NameCellRenderer extends DefaultCellRenderer { @@ -143,6 +151,7 @@ if ($request->isPost()) { // Require selection of a client for a client role. if ($user->isPluginEnabled('cl') && ttRoleHelper::isClientRole($cl_role_id) && !$cl_client_id) $err->add($i18n->get('error.client')); if (!ttValidFloat($cl_rate, true)) $err->add($i18n->get('error.field'), $i18n->get('form.users.default_rate')); + if (!ttValidFloat($cl_quota_percent, true)) $err->add($i18n->get('error.field'), $i18n->get('form.quota.quota')); if ($err->no()) { if (!ttUserHelper::getUserByLogin($cl_login)) { @@ -151,6 +160,7 @@ if ($request->isPost()) { 'login' => $cl_login, 'password' => $cl_password1, 'rate' => $cl_rate, + 'quota_percent' => $cl_quota_percent, 'group_id' => $user->getGroup(), 'org_id' => $user->org_id, 'role_id' => $cl_role_id, @@ -176,7 +186,8 @@ if ($request->isPost()) { $smarty->assign('auth_external', $auth->isPasswordExternal()); $smarty->assign('active_roles', $active_roles); $smarty->assign('forms', array($form->getName()=>$form->toArray())); -$smarty->assign('show_projects', count($projects) > 0); +$smarty->assign('show_quota', $show_quota); +$smarty->assign('show_projects', $show_projects); $smarty->assign('onload', 'onLoad="document.userForm.name.focus();handleClientControl();"'); $smarty->assign('title', $i18n->get('title.add_user')); $smarty->assign('content_page_name', 'user_add.tpl'); diff --git a/user_edit.php b/user_edit.php index 531d2efe..c3910db3 100644 --- a/user_edit.php +++ b/user_edit.php @@ -49,10 +49,15 @@ if (!$user_details) { } // End of access checks. +$show_quota = $user->isPluginEnabled('mq'); if ($user->isPluginEnabled('cl')) $clients = ttGroupHelper::getActiveClients(); -$projects = ttGroupHelper::getActiveProjects(); +$show_projects = MODE_PROJECTS == $user->getTrackingMode() || MODE_PROJECTS_AND_TASKS == $user->getTrackingMode(); +if ($show_projects) { + $projects = ttGroupHelper::getActiveProjects(); + if (count($projects) == 0) $show_projects = false; +} $assigned_projects = array(); if ($request->isPost()) { @@ -67,6 +72,7 @@ if ($request->isPost()) { $cl_client_id = $request->getParameter('client'); $cl_status = $request->getParameter('status'); $cl_rate = $request->getParameter('rate'); + $cl_quota_percent = $request->getParameter('quota_percent'); $cl_projects = $request->getParameter('projects'); if (is_array($cl_projects)) { foreach ($cl_projects as $p) { @@ -84,6 +90,7 @@ if ($request->isPost()) { $cl_login = $user_details['login']; $cl_email = $user_details['email']; $cl_rate = str_replace('.', $user->getDecimalMark(), $user_details['rate']); + $cl_quota_percent = str_replace('.', $user->getDecimalMark(), $user_details['quota_percent']); $cl_role_id = $user_details['role_id']; $cl_client_id = $user_details['client_id']; $cl_status = $user_details['status']; @@ -111,6 +118,8 @@ if ($user->isPluginEnabled('cl')) $form->addInput(array('type'=>'combobox','name'=>'status','value'=>$cl_status, 'data'=>array(ACTIVE=>$i18n->get('dropdown.status_active'),INACTIVE=>$i18n->get('dropdown.status_inactive')))); $form->addInput(array('type'=>'floatfield','maxlength'=>'10','name'=>'rate','format'=>'.2','value'=>$cl_rate)); +if ($show_quota) + $form->addInput(array('type'=>'floatfield','maxlength'=>'10','name'=>'quota_percent','format'=>'.2','value'=>$cl_quota_percent)); // Define classes for the projects table. class NameCellRenderer extends DefaultCellRenderer { @@ -164,6 +173,7 @@ if ($request->isPost()) { // Require selection of a client for a client role. if ($user->isPluginEnabled('cl') && ttRoleHelper::isClientRole($cl_role_id) && !$cl_client_id) $err->add($i18n->get('error.client')); if (!ttValidFloat($cl_rate, true)) $err->add($i18n->get('error.field'), $i18n->get('form.users.default_rate')); + if (!ttValidFloat($cl_quota_percent, true)) $err->add($i18n->get('error.field'), $i18n->get('form.quota.quota')); if ($err->no()) { $existing_user = ttUserHelper::getUserByLogin($cl_login); @@ -176,6 +186,7 @@ if ($request->isPost()) { 'email' => $cl_email, 'status' => $cl_status, 'rate' => $cl_rate, + 'quota_percent' => $cl_quota_percent, 'projects' => $assigned_projects); if (in_array('manage_users', $user->rights) && $cl_role_id) { $fields['role_id'] = $cl_role_id; @@ -228,7 +239,8 @@ $smarty->assign('rates', $rates); $smarty->assign('auth_external', $auth->isPasswordExternal()); $smarty->assign('active_roles', $active_roles); $smarty->assign('can_swap', $can_swap); -$smarty->assign('show_projects', count($projects) > 0); +$smarty->assign('show_quota', $show_quota); +$smarty->assign('show_projects', $show_projects); $smarty->assign('forms', array($form->getName()=>$form->toArray())); $smarty->assign('onload', 'onLoad="document.userForm.name.focus();handleClientControl();"'); $smarty->assign('user_id', $user_id); -- 2.20.1
 Anuko Time Tracker 1.18.34.4672 | Copyright © Anuko | +  Anuko Time Tracker 1.18.34.4673 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/user_add.tpl b/WEB-INF/templates/user_add.tpl index 29218d86..ea4809f1 100644 --- a/WEB-INF/templates/user_add.tpl +++ b/WEB-INF/templates/user_add.tpl @@ -81,7 +81,13 @@ function handleClientControl() { {$i18n.form.users.default_rate} (0{$user->getDecimalMark()}00): {$forms.userForm.rate.control}
{$i18n.form.quota.quota} (%):{$forms.userForm.quota_percent.control}
 
{$i18n.label.projects}:{$i18n.form.users.default_rate} (0{$user->getDecimalMark()}00): {$forms.userForm.rate.control}
{$i18n.form.quota.quota} (%):{$forms.userForm.quota_percent.control}
 
{$i18n.label.projects}: