From: Nik Okuntseff Date: Sat, 1 Dec 2018 17:49:11 +0000 (+0000) Subject: A bit more refactoring of clients.php for subgroups. X-Git-Tag: timetracker_1.19-1~507 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=a96c4f4e05e68e875ce088201ad011d6fc3e1e1c;p=timetracker.git A bit more refactoring of clients.php for subgroups. --- diff --git a/WEB-INF/lib/ttClientHelper.class.php b/WEB-INF/lib/ttClientHelper.class.php index 3dc60bdb..9009f570 100644 --- a/WEB-INF/lib/ttClientHelper.class.php +++ b/WEB-INF/lib/ttClientHelper.class.php @@ -239,18 +239,6 @@ class ttClientHelper { return (!is_a($affected, 'PEAR_Error')); } - // The setMappedClient function is used during group import to change client_id value for tt_users to a mapped value. - static function setMappedClient($group_id, $imported_id, $mapped_id) - { - $mdb2 = getConnection(); - $sql = "update tt_users set client_id = $mapped_id where client_id = $imported_id and group_id = $group_id "; - $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; - - return true; - } - // The fillBean function fills the ActionForm object with client data. static function fillBean($client_id, &$bean) { $client = ttClientHelper::getClient($client_id, true); diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 8b02c85e..e04c221d 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -274,4 +274,50 @@ class ttGroupHelper { } return $roles; } + + // The getActiveClients returns an array of active clients for a group. + static function getActiveClients($all_fields = false) + { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + if ($all_fields) + $sql = "select * from tt_clients where group_id = $group_id and org_id = $org_id and status = 1 order by upper(name)"; + else + $sql = "select id, name from tt_clients where group_id = $group_id and org_id = $org_id and status = 1 order by upper(name)"; + + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + } + return $result; + } + + // The getInactiveClients returns an array of inactive clients for a group. + static function getInactiveClients($all_fields = false) + { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + if ($all_fields) + $sql = "select * from tt_clients where group_id = $group_id and org_id = $org_id and status = 0 order by upper(name)"; + else + $sql = "select id, name from tt_clients where group_id = $group_id and org_id = $org_id and status = 0 order by upper(name)"; + + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + } + return $result; + } } diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 1a9987d8..b11d78eb 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4557 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4559 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/clients.php b/clients.php index ca83efd9..cc08f9a3 100644 --- a/clients.php +++ b/clients.php @@ -29,6 +29,7 @@ require_once('initialize.php'); import('form.Form'); import('ttTeamHelper'); +import('ttGroupHelper'); // Access checks. if (!(ttAccessAllowed('view_own_clients') || ttAccessAllowed('manage_clients'))) { @@ -72,8 +73,8 @@ if ($user->can('manage_subgroups')) { } if($user->can('manage_clients')) { - $active_clients = ttTeamHelper::getActiveClients($user->getGroup(), true); - $inactive_clients = ttTeamHelper::getInactiveClients($user->getGroup(), true); + $active_clients = ttGroupHelper::getActiveClients(true); + $inactive_clients = ttGroupHelper::getInactiveClients(true); } else $active_clients = $user->getAssignedClients();