X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttClientHelper.class.php;h=9009f570add7685a2e75b5a7b5e745b2a84ce4cc;hb=45a530c33fdd7ab2ccd1905c24a371c94e17eac5;hp=afa7afbd165c0026e337c3514fa0e9ade3841ac6;hpb=95356f167c97ca1a70fc78d91a9dbc7b1d258b31;p=timetracker.git diff --git a/WEB-INF/lib/ttClientHelper.class.php b/WEB-INF/lib/ttClientHelper.class.php index afa7afbd..9009f570 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,8 +43,8 @@ class ttClientHelper { else $sql .= 'name '; - $sql .= "from tt_clients where group_id = $user->group_id - and id = $client_id and (status = 1 or status = 0)"; + $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')) { $val = $res->fetchRow(); @@ -59,8 +61,7 @@ class ttClientHelper { $result = array(); $mdb2 = getConnection(); - $sql = "select id, name from tt_clients - where group_id = $user->group_id 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()) { @@ -76,8 +77,8 @@ class ttClientHelper { $mdb2 = getConnection(); global $user; - $sql = "select id from tt_clients where group_id = $user->group_id and name = ". - $mdb2->quote($client_name)." and (status = 1 or status = 0)"; + $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); if (!is_a($res, 'PEAR_Error')) { @@ -95,8 +96,8 @@ class ttClientHelper { $mdb2 = getConnection(); global $user; - $sql = "select name, address from tt_clients where group_id = $user->group_id - and id = $client_id and status is NULL"; + $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')) { $val = $res->fetchRow(); @@ -120,7 +121,7 @@ class ttClientHelper { } // Handle time records. - $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id); + $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$user->id; if ($delete_client_entries) { $sql = 'update tt_log set status = NULL'.$modified_part." where client_id = $id"; $affected = $mdb2->exec($sql); @@ -138,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->group_id"; + $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; @@ -151,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->group_id"; + $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->group_id"; + $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')); } @@ -169,6 +170,7 @@ class ttClientHelper { $mdb2 = getConnection(); $group_id = (int) $fields['group_id']; + $org_id = (int) $fields['org_id']; $name = $fields['name']; $address = $fields['address']; $tax = $fields['tax']; @@ -180,22 +182,17 @@ class ttClientHelper { $tax = str_replace(',', '.', $tax); if ($tax == '') $tax = 0; - $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).")"; + $sql = "insert into tt_clients (group_id, org_id, name, address, tax, projects, status)". + " values ($group_id, $org_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')) return false; - $last_id = 0; - $sql = "select last_insert_id() as last_insert_id"; - $res = $mdb2->query($sql); - $val = $res->fetchRow(); - $last_id = $val['last_insert_id']; - + $last_id = $mdb2->lastInsertID('tt_clients', 'id'); 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; @@ -236,23 +233,12 @@ 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 group_id = ".$user->group_id." and id = ".$id; + ", tax = $tax, projects = ".$mdb2->quote($comma_separated).", status = $status". + " where group_id = ".$user->getGroup()." and id = ".$id; $affected = $mdb2->exec($sql); 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); @@ -270,9 +256,9 @@ class ttClientHelper { $mdb2 = getConnection(); // 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->group_id and p.status = 1 order by p.name"; + $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->getGroup()." and p.status = 1 order by p.name"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { @@ -286,7 +272,7 @@ class ttClientHelper { static function getClientsForUser() { global $user; - $user_id = $user->getActiveUser(); + $user_id = $user->getUser(); $result = array(); $mdb2 = getConnection(); @@ -304,27 +290,4 @@ class ttClientHelper { } return $result; } - - // getAssignedProjectsForUser - returns an array of projects assigned to a user and associatied with a client. - static function getAssignedProjectsForUser($client_id) - { - global $user; - $user_id = $user->getActiveUser(); - - $result = array(); - $mdb2 = getConnection(); - - // 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) - 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.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()) { - $result[] = $val; - } - } - return $result; - } }