- // Update records in tt_project_task_binds table.
- // Obtain existing task binds.
- $existing_task_binds = array();
- $sql = "select task_id from tt_project_task_binds where project_id = $project_id";
- $res = $mdb2->query($sql);
- while ($val = $res->fetchRow()) {
- $existing_task_binds[] = $val['task_id'];
- }
- // Determine which task binds to delete and which ones to add.
- $task_binds_to_delete = array_diff($existing_task_binds, $tasks_to_bind);
- $task_binds_to_add = array_diff($tasks_to_bind, $existing_task_binds);
- foreach ($task_binds_to_delete as $task_id) {
- $sql = "delete from tt_project_task_binds where project_id = $project_id and task_id = $task_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- 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)";
+ // Update records in tt_project_task_binds table by deleting and inserting.
+ $sql = "delete from tt_project_task_binds".
+ " where project_id = $project_id and group_id = $group_id and org_id = $org_id";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error'))
+ return false;
+
+ foreach ($tasks_to_bind as $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)";