Optimized a bit more for uncompleted indicators option.
[timetracker.git] / WEB-INF / lib / ttClientHelper.class.php
index e557676..3dc60bd 100644 (file)
@@ -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->getGroup().
+    $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')) {
@@ -119,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);
@@ -187,12 +189,7 @@ class ttClientHelper {
     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, group_id, org_id) values($last_id, $p_id, $group_id, $org_id)";
@@ -287,7 +284,7 @@ class ttClientHelper {
   static function getClientsForUser()
   {
     global $user;
-    $user_id = $user->getActiveUser();
+    $user_id = $user->getUser();
 
     $result = array();
     $mdb2 = getConnection();