Introduced ttGroup class to store attributes of on behalf group.
[timetracker.git] / WEB-INF / lib / ttProjectHelper.class.php
index 72b7171..5e59a92 100644 (file)
@@ -159,23 +159,26 @@ class ttProjectHelper {
     global $user;
     $mdb2 = getConnection();
 
+    $group_id = $user->getActiveGroup();
+    $org_id = $user->org_id;
+
     // Start with project itself. Reason: if the passed in project_id is bogus,
     // we'll fail right here and don't damage any other data.
 
     // Mark project as deleted and remove associated tasks.
-    $sql = "update tt_projects set status = NULL, tasks = NULL where id = $id and group_id = ".$user->getActiveGroup();
+    $sql = "update tt_projects set status = NULL, tasks = NULL where id = $id and group_id = $group_id and org_id = $org_id";
     $affected = $mdb2->exec($sql);
     if (is_a($affected, 'PEAR_Error') || 0 == $affected)
       return false; // An error ocurred, or 0 rows updated.
 
     // Delete user binds to this project.
-    $sql = "delete from tt_user_project_binds where project_id = $id";
+    $sql = "delete from tt_user_project_binds where project_id = $id and group_id = $group_id and org_id = $org_id";
     $affected = $mdb2->exec($sql);
     if (is_a($affected, 'PEAR_Error'))
       return false;
 
     // Delete task binds to this project.
-    $sql = "delete from tt_project_task_binds where project_id = $id";
+    $sql = "delete from tt_project_task_binds where project_id = $id and group_id = $group_id and org_id = $org_id";
     $affected = $mdb2->exec($sql);
     if (is_a($affected, 'PEAR_Error'))
       return false;
@@ -214,8 +217,8 @@ class ttProjectHelper {
     $active_users = ttTeamHelper::getActiveUsers(array('getAllFields'=>true));
     foreach ($active_users as $u) {
       if(in_array($u['id'], $users)) {
-        $sql = "insert into tt_user_project_binds (project_id, user_id, status, rate) values(
-          $last_id, ".$u['id'].", 1, ".$u['rate'].")";
+        $sql = "insert into tt_user_project_binds (project_id, user_id, group_id, org_id, status, rate) values(
+          $last_id, ".$u['id'].", $group_id, $org_id, 1, ".$u['rate'].")";
         $affected = $mdb2->exec($sql);
         if (is_a($affected, 'PEAR_Error'))
           return false;
@@ -226,7 +229,8 @@ class ttProjectHelper {
     $all_tasks = ttTeamHelper::getAllTasks($group_id);
     foreach ($all_tasks as $task) {
       if(in_array($task['id'], $tasks)) {
-        $sql = "insert into tt_project_task_binds (project_id, task_id) values($last_id, ".$task['id'].")";
+        $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)".
+          " values($last_id, ".$task['id'].", $group_id, $org_id)";
         $affected = $mdb2->exec($sql);
         if (is_a($affected, 'PEAR_Error'))
           return false;
@@ -240,7 +244,9 @@ class ttProjectHelper {
   static function update($fields) {
     global $user;
     $mdb2 = getConnection();
-    
+
+    $group_id = $user->getActiveGroup();
+    $org_id = $user->org_id;
     $project_id = $fields['id']; // Project we are updating.
     $name = $fields['name']; // Project name.
     $description = $fields['description']; // Project description.
@@ -272,7 +278,8 @@ class ttProjectHelper {
         $user_rate[$row['id']] = $row['rate'];
       }
       foreach ($users_to_add as $id) {
-        $sql = "insert into tt_user_project_binds (user_id, project_id, rate, status) values($id, $project_id, ".$user_rate[$id].", 1)";
+        $sql = "insert into tt_user_project_binds (user_id, project_id, group_id, org_id, rate, status)".
+          " values($id, $project_id, $group_id, $org_id, ".$user_rate[$id].", 1)";
         $affected = $mdb2->exec($sql);
         if (is_a($affected, 'PEAR_Error'))
           return false;
@@ -305,7 +312,8 @@ class ttProjectHelper {
         return false;
     }    
     foreach ($task_binds_to_add as $task_id) {
-      $sql = "insert into tt_project_task_binds (project_id, task_id) values($project_id, $task_id)";
+      $sql = "insert into tt_project_task_binds (project_id, task_id, group_id, org_id)".
+        " values($project_id, $task_id, $group_id, $org_id)";
       $affected = $mdb2->exec($sql);
       if (is_a($affected, 'PEAR_Error'))
         return false;