X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttClientHelper.class.php;h=afa7afbd165c0026e337c3514fa0e9ade3841ac6;hb=47676f16efdde0b36a4ed09d2ab0476584aeb2a6;hp=3b7a9cd62959a6fe4fb34ec7b5aefe1a71abc6fa;hpb=8e340f1e9cb764f423c0a5e7067c892f88d0ec73;p=timetracker.git diff --git a/WEB-INF/lib/ttClientHelper.class.php b/WEB-INF/lib/ttClientHelper.class.php index 3b7a9cd6..afa7afbd 100644 --- a/WEB-INF/lib/ttClientHelper.class.php +++ b/WEB-INF/lib/ttClientHelper.class.php @@ -41,7 +41,7 @@ class ttClientHelper { else $sql .= 'name '; - $sql .= "from tt_clients where team_id = $user->team_id + $sql .= "from tt_clients where group_id = $user->group_id and id = $client_id and (status = 1 or status = 0)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -51,7 +51,7 @@ class ttClientHelper { return false; } - // getClients - returns an array of active and inactive clients in a team. + // getClients - returns an array of active and inactive clients in a group. static function getClients() { global $user; @@ -60,7 +60,7 @@ class ttClientHelper { $mdb2 = getConnection(); $sql = "select id, name from tt_clients - where team_id = $user->team_id and (status = 0 or status = 1) order by name"; + where group_id = $user->group_id and (status = 0 or status = 1) order by upper(name)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -76,7 +76,7 @@ class ttClientHelper { $mdb2 = getConnection(); global $user; - $sql = "select id from tt_clients where team_id = $user->team_id and name = ". + $sql = "select id from tt_clients where group_id = $user->group_id and name = ". $mdb2->quote($client_name)." and (status = 1 or status = 0)"; $res = $mdb2->query($sql); @@ -95,7 +95,7 @@ class ttClientHelper { $mdb2 = getConnection(); global $user; - $sql = "select name, address from tt_clients where team_id = $user->team_id + $sql = "select name, address from tt_clients where group_id = $user->group_id and id = $client_id and status is NULL"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -120,8 +120,9 @@ class ttClientHelper { } // Handle time records. + $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id); if ($delete_client_entries) { - $sql = "update tt_log set status = NULL where client_id = $id"; + $sql = 'update tt_log set status = NULL'.$modified_part." where client_id = $id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -129,7 +130,7 @@ class ttClientHelper { // Handle expense items. if ($delete_client_entries) { - $sql = "update tt_expense_items set status = NULL where client_id = $id"; + $sql = 'update tt_expense_items set status = NULL'.$modified_part." where client_id = $id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -137,7 +138,7 @@ class ttClientHelper { // Handle invoices. if ($delete_client_entries) { - $sql = "update tt_invoices set status = NULL where client_id = $id"; + $sql = "update tt_invoices set status = NULL where client_id = $id and group_id = $user->group_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -149,7 +150,14 @@ class ttClientHelper { if (is_a($affected, 'PEAR_Error')) return false; - $sql = "update tt_clients set status = NULL where id = $id and team_id = ".$user->team_id; + // Handle users for client. + $sql = 'update tt_users set status = NULL'.$modified_part." where client_id = $id and group_id = $user->group_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) + return false; + + // Mark client deleted. + $sql = "update tt_clients set status = NULL where id = $id and group_id = $user->group_id"; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } @@ -160,7 +168,7 @@ class ttClientHelper { global $user; $mdb2 = getConnection(); - $team_id = (int) $fields['team_id']; + $group_id = (int) $fields['group_id']; $name = $fields['name']; $address = $fields['address']; $tax = $fields['tax']; @@ -172,8 +180,8 @@ class ttClientHelper { $tax = str_replace(',', '.', $tax); if ($tax == '') $tax = 0; - $sql = "insert into tt_clients (team_id, name, address, tax, projects, status) - values ($team_id, ".$mdb2->quote($name).", ".$mdb2->quote($address).", $tax, ".$mdb2->quote($comma_separated).", ".$mdb2->quote($status).")"; + $sql = "insert into tt_clients (group_id, name, address, tax, projects, status)". + " values ($group_id, ".$mdb2->quote($name).", ".$mdb2->quote($address).", $tax, ".$mdb2->quote($comma_separated).", ".$mdb2->quote($status).")"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) @@ -228,16 +236,16 @@ class ttClientHelper { // Update client properties in tt_clients table. $comma_separated = implode(",", $projects); // This is a comma-separated list of associated project ids. $sql = "update tt_clients set name = ".$mdb2->quote($name).", address = ".$mdb2->quote($address). - ", tax = $tax, projects = ".$mdb2->quote($comma_separated).", status = $status where team_id = ".$user->team_id." and id = ".$id; + ", tax = $tax, projects = ".$mdb2->quote($comma_separated).", status = $status where group_id = ".$user->group_id." and id = ".$id; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } - // The setMappedClient function is used during team import to change client_id value for tt_users to a mapped value. - static function setMappedClient($team_id, $imported_id, $mapped_id) + // 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 team_id = $team_id "; + $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; @@ -264,7 +272,7 @@ class ttClientHelper { // Do a query with inner join to get assigned projects. $sql = "select p.id, p.name from tt_projects p inner join tt_client_project_binds cpb on (cpb.client_id = $client_id and cpb.project_id = p.id) - where p.team_id = $user->team_id and p.status = 1 order by p.name"; + where p.group_id = $user->group_id and p.status = 1 order by p.name"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -286,7 +294,7 @@ class ttClientHelper { $sql = "select distinct c.id, c.name, c.projects from tt_user_project_binds upb inner join tt_client_project_binds cpb on (cpb.project_id = upb.project_id) inner join tt_clients c on (c.id = cpb.client_id and c.status = 1) - where upb.user_id = $user_id and upb.status = 1 order by c.name"; + where upb.user_id = $user_id and upb.status = 1 order by upper(c.name)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -310,7 +318,7 @@ class ttClientHelper { $sql = "select p.id, p.name from tt_projects p inner join tt_client_project_binds cpb on (cpb.client_id = $client_id and cpb.project_id = p.id) inner join tt_user_project_binds upb on (upb.user_id = $user_id and upb.project_id = p.id and upb.status = 1) - where p.team_id = $user->team_id and p.status = 1 order by p.name"; + where p.group_id = $user->group_id and p.status = 1 order by p.name"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) {