X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttClientHelper.class.php;h=3ae662a11dcbeb03c2f6792429d9732203f0b995;hb=fa6508ac21c30d6bfef008387fabd29a843d7b66;hp=0c12a9538de4b242a85ddcbbab1055c09f0f3486;hpb=0fdda830ba3e780c365c90e1fdfd5cfa7ed77244;p=timetracker.git diff --git a/WEB-INF/lib/ttClientHelper.class.php b/WEB-INF/lib/ttClientHelper.class.php index 0c12a953..3ae662a1 100644 --- a/WEB-INF/lib/ttClientHelper.class.php +++ b/WEB-INF/lib/ttClientHelper.class.php @@ -31,9 +31,11 @@ class ttClientHelper { // The getClient looks up a client by id. static function getClient($client_id, $all_fields = false) { - - $mdb2 = getConnection(); global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; $sql = 'select '; if ($all_fields) @@ -41,7 +43,7 @@ class ttClientHelper { else $sql .= 'name '; - $sql .= "from tt_clients where group_id = ".$user->getActiveGroup(). + $sql .= "from tt_clients where group_id = $group_id and org_id = $org_id". " and id = $client_id and (status = 1 or status = 0)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -59,7 +61,7 @@ class ttClientHelper { $result = array(); $mdb2 = getConnection(); - $sql = "select id, name from tt_clients where group_id = ".$user->getActiveGroup()." and (status = 0 or status = 1) order by upper(name)"; + $sql = "select id, name from tt_clients where group_id = ".$user->getGroup()." and (status = 0 or status = 1) order by upper(name)"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -75,7 +77,7 @@ class ttClientHelper { $mdb2 = getConnection(); global $user; - $sql = "select id from tt_clients where group_id = ".$user->getActiveGroup(). + $sql = "select id from tt_clients where group_id = ".$user->getGroup(). " and name = ".$mdb2->quote($client_name)." and (status = 1 or status = 0)"; $res = $mdb2->query($sql); @@ -94,7 +96,7 @@ class ttClientHelper { $mdb2 = getConnection(); global $user; - $sql = "select name, address from tt_clients where group_id = ".$user->getActiveGroup(). + $sql = "select name, address from tt_clients where group_id = ".$user->getGroup(). " and id = $client_id and status is NULL"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { @@ -137,7 +139,7 @@ class ttClientHelper { // Handle invoices. if ($delete_client_entries) { - $sql = "update tt_invoices set status = NULL where client_id = $id and group_id = ".$user->getActiveGroup(); + $sql = "update tt_invoices set status = NULL where client_id = $id and group_id = ".$user->getGroup(); $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -150,13 +152,13 @@ class ttClientHelper { return false; // Handle users for client. - $sql = 'update tt_users set status = NULL'.$modified_part." where client_id = $id and group_id = ".$user->getActiveGroup(); + $sql = 'update tt_users set status = NULL'.$modified_part." where client_id = $id and group_id = ".$user->getGroup(); $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->getActiveGroup(); + $sql = "update tt_clients set status = NULL where id = $id and group_id = ".$user->getGroup(); $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } @@ -195,7 +197,7 @@ class ttClientHelper { if (count($projects) > 0) foreach ($projects as $p_id) { - $sql = "insert into tt_client_project_binds (client_id, project_id) values($last_id, $p_id)"; + $sql = "insert into tt_client_project_binds (client_id, project_id, group_id, org_id) values($last_id, $p_id, $group_id, $org_id)"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -237,7 +239,7 @@ class ttClientHelper { $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 group_id = ".$user->getActiveGroup()." and id = ".$id; + " where group_id = ".$user->getGroup()." and id = ".$id; $affected = $mdb2->exec($sql); return (!is_a($affected, 'PEAR_Error')); } @@ -273,7 +275,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.group_id = ".$user->getActiveGroup()." and p.status = 1 order by p.name"; + " where p.group_id = ".$user->getGroup()." and p.status = 1 order by p.name"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -287,7 +289,7 @@ class ttClientHelper { static function getClientsForUser() { global $user; - $user_id = $user->getActiveUser(); + $user_id = $user->getUser(); $result = array(); $mdb2 = getConnection();