Index: openacs-4/contrib/packages/project-manager/sql/postgresql/project-manager-functions-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/project-manager/sql/postgresql/Attic/project-manager-functions-create.sql,v
diff -u -r1.11 -r1.12
--- openacs-4/contrib/packages/project-manager/sql/postgresql/project-manager-functions-create.sql	26 Jan 2004 15:39:40 -0000	1.11
+++ openacs-4/contrib/packages/project-manager/sql/postgresql/project-manager-functions-create.sql	26 Feb 2004 15:15:40 -0000	1.12
@@ -21,9 +21,9 @@
     p_pm_project_id      alias for $1;
     v_pm_project_name    varchar;
 begin
-        select project_code || ''_'' || p_pm_project_id into v_pm_project_name
-                from pm_projects
-                where project_id = p_pm_project_id;
+        select project_name || ''_'' || p_pm_project_id into v_pm_project_name
+                from pm_projectsx
+                where item_id = p_pm_project_id;
     return v_pm_project_name;
 end;
 ' language 'plpgsql';
@@ -130,10 +130,9 @@
 -- is null.  Otherwise a project folder will be created as a sub-folder
 -- of an existing project folder.
 
-select define_function_args('pm_project__new_project_item', 'project_id, project_name, project_code, parent_id, goal, description, planned_start_date, planned_end_date, actual_start_date, actual_end_date, ongoing_p, status_id, creation_date, creation_user, creation_ip, package_id');
+select define_function_args('pm_project__new_project_item', 'project_name, project_code, parent_id, goal, description, planned_start_date, planned_end_date, actual_start_date, actual_end_date, ongoing_p, status_id, customer_id, creation_date, creation_user, creation_ip, package_id');
 
 create function pm_project__new_project_item (
-        integer,        -- project_id
         varchar,        -- project_name
         varchar,        -- project_code
         integer,        -- parent_id
@@ -145,25 +144,26 @@
         timestamptz,    -- actual_end_date
         char(1),        -- ongoing_p
         integer,        -- status_id
+        integer,        -- customer_id (organization_id)
         timestamptz,    -- creation_date
         integer,        -- creation_user
         varchar,        -- creation_ip
         integer         -- package_id
 ) returns integer 
 as '
 declare
-        p_project_id                            alias for $1;
-        p_project_name                          alias for $2;
-        p_project_code                          alias for $3;
-        p_parent_id                             alias for $4;
-        p_goal                                  alias for $5;
-        p_description                           alias for $6;
-        p_planned_start_date                    alias for $7;
-        p_planned_end_date                      alias for $8;
-        p_actual_start_date                     alias for $9;
-        p_actual_end_date                       alias for $10;
-        p_ongoing_p                             alias for $11;
-        p_status_id                             alias for $12;
+        p_project_name                          alias for $1;
+        p_project_code                          alias for $2;
+        p_parent_id                             alias for $3;
+        p_goal                                  alias for $4;
+        p_description                           alias for $5;
+        p_planned_start_date                    alias for $6;
+        p_planned_end_date                      alias for $7;
+        p_actual_start_date                     alias for $8;
+        p_actual_end_date                       alias for $9;
+        p_ongoing_p                             alias for $10;
+        p_status_id                             alias for $11;
+        p_customer_id                           alias for $12;
         p_creation_date                         alias for $13;
         p_creation_user                         alias for $14;
         p_creation_ip                           alias for $15;
@@ -228,14 +228,14 @@
                 ongoing_p, estimated_finish_date, 
                 earliest_finish_date, latest_finish_date,
                 actual_hours_completed, 
-                estimated_hours_total, status_id) 
+                estimated_hours_total, status_id, customer_id) 
         values (
                 v_revision_id, p_project_code, 
                 p_goal, p_planned_start_date, 
                 p_planned_end_date, p_actual_start_date, 
                 p_actual_end_date, p_ongoing_p, p_planned_end_date,
                 p_planned_end_date, p_planned_end_date, ''0'',
-                ''0'', p_status_id
+                ''0'', p_status_id, p_customer_id
                 );
 
         PERFORM acs_permission__grant_permission(
@@ -260,9 +260,6 @@
 begin
         raise NOTICE ''Deleting pm_project...'';
 
-        delete from acs_permissions
-                where object_id = p_project_id;
-
         for v_child in select 
                 item_id
                 from 
@@ -274,17 +271,16 @@
                 PERFORM pm_project__delete_project_item(v_child.item_id);
         end loop;
 
-        delete from pm_projects
-                where project_id = p_project_id;
+        delete from pm_projects where project_id in (select revision_id from pm_projectsx where item_id = p_project_id);
 
         PERFORM content_item__delete(p_project_id);
         return 0;
 end;' language 'plpgsql';
 
 
-select define_function_args('pm_project__new_project_revision', 'item_id, project_name, project_code, parent_id, goal, description, planned_start_date, planned_end_date, actual_start_date, actual_end_date, ongoing_p, status_id, creation_date, creation_user, creation_ip, package_id');
+select define_function_args('pm_project__new_project_revision', 'item_id, project_name, project_code, parent_id, goal, description, planned_start_date, planned_end_date, actual_start_date, actual_end_date, ongoing_p, status_id, organization_id, creation_date, creation_user, creation_ip, package_id');
 
-create function pm_project__new_project_revision (
+create or replace function pm_project__new_project_revision (
         integer,        -- item_id
         varchar,        -- project_name
         varchar,        -- project_code
@@ -297,6 +293,7 @@
         timestamptz,    -- actual_end_date
         char(1),        -- ongoing_p
         integer,        -- status_id
+        integer,        -- organization_id (customer)
         timestamptz,    -- creation_date
         integer,        -- creation_user
         varchar,        -- creation_ip
@@ -316,10 +313,11 @@
         p_actual_end_date                       alias for $10;
         p_ongoing_p                             alias for $11;
         p_status_id                             alias for $12;
-        p_creation_date                         alias for $13;
-        p_creation_user                         alias for $14;
-        p_creation_ip                           alias for $15;
-        p_package_id                            alias for $16;
+        p_organization_id                       alias for $13;
+        p_creation_date                         alias for $14;
+        p_creation_user                         alias for $15;
+        p_creation_ip                           alias for $16;
+        p_package_id                            alias for $17;
 
         v_revision_id           cr_revisions.revision_id%TYPE;
 begin
@@ -346,13 +344,15 @@
                 project_id, project_code, 
                 goal, planned_start_date, 
                 planned_end_date, actual_start_date, actual_end_date, 
-                ongoing_p, status_id) 
+                ongoing_p, status_id, customer_id) 
         values (
                 v_revision_id, p_project_code, 
                 p_goal, p_planned_start_date, 
                 p_planned_end_date, p_actual_start_date, 
-                p_actual_end_date, p_ongoing_p, p_status_id);
+                p_actual_end_date, p_ongoing_p, p_status_id, p_organization_id);
 
+        -- make sure organizations are in as well
+
         PERFORM acs_permission__grant_permission(
                 v_revision_id,
                 p_creation_user,
@@ -422,10 +422,9 @@
 -- If it is not associated with a project, then it is placed in the root
 -- project repository folder.
 
-select define_function_args('pm_task__new_task_item', 'task_id, project_id, title, description, end_date, percent_complete, estimated_hours_work, estimated_hours_work_min, estimated_hours_work_max, creation_date, creation_user, creation_ip, package_id');
+select define_function_args('pm_task__new_task_item', 'project_id, title, description, end_date, percent_complete, estimated_hours_work, estimated_hours_work_min, estimated_hours_work_max, status_id, creation_date, creation_user, creation_ip, package_id');
 
 create function pm_task__new_task_item (
-        integer,        -- task_id
         integer,        -- project_id
         varchar,        -- title
         varchar,        -- description
@@ -434,22 +433,23 @@
         numeric,        -- estimated_hours_work
         numeric,        -- estimated_hours_work_min
         numeric,        -- estimated_hours_work_max,
+        integer,        -- status_id
         timestamptz,    -- creation_date
         integer,        -- creation_user
         varchar,        -- creation_ip
         integer         -- package_id
 ) returns integer 
 as '
 declare
-        p_task_id                               alias for $1;
-        p_project_id                            alias for $2;
-        p_title                                 alias for $3;
-        p_description                           alias for $4;
-        p_end_date                              alias for $5;
-        p_percent_complete                      alias for $6;
-        p_estimated_hours_work                  alias for $7;
-        p_estimated_hours_work_min              alias for $8;
-        p_estimated_hours_work_max              alias for $9;
+        p_project_id                            alias for $1;
+        p_title                                 alias for $2;
+        p_description                           alias for $3;
+        p_end_date                              alias for $4;
+        p_percent_complete                      alias for $5;
+        p_estimated_hours_work                  alias for $6;
+        p_estimated_hours_work_min              alias for $7;
+        p_estimated_hours_work_max              alias for $8;
+        p_status_id                             alias for $9;
         p_creation_date                         alias for $10;
         p_creation_user                         alias for $11;
         p_creation_ip                           alias for $12;
@@ -501,9 +501,9 @@
         PERFORM content_item__set_live_revision (v_revision_id);
 
         insert into pm_tasks (
-                task_id, task_number)
+                task_id, task_number, status)
         values (
-                v_item_id, v_task_number);
+                v_item_id, v_task_number, p_status_id);
 
         insert into pm_tasks_revisions (
                 task_revision_id, end_date, percent_complete, estimated_hours_work, estimated_hours_work_min, estimated_hours_work_max, actual_hours_worked)
@@ -533,6 +533,7 @@
         numeric,        -- estimated_hours_work_min
         numeric,        -- estimated_hours_work_max
         numeric,        -- actual_hours_worked
+        integer,        -- status_id
         timestamptz,    -- creation_date
         integer,        -- creation_user
         varchar,        -- creation_ip
@@ -550,10 +551,11 @@
         p_estimated_hours_work_min              alias for $8;
         p_estimated_hours_work_max              alias for $9;
         p_actual_hours_worked                   alias for $10;
-        p_creation_date                         alias for $11;
-        p_creation_user                         alias for $12;
-        p_creation_ip                           alias for $13;
-        p_package_id                            alias for $14;
+        p_status_id                             alias for $11;
+        p_creation_date                         alias for $12;
+        p_creation_user                         alias for $13
+        p_creation_ip                           alias for $14;
+        p_package_id                            alias for $15;
 
         v_revision_id           cr_revisions.revision_id%TYPE;
         v_id                    cr_items.item_id%TYPE;
@@ -583,6 +585,8 @@
         values (
                 v_revision_id, p_end_date, p_percent_complete, p_estimated_hours_work, p_estimated_hours_work_min, p_estimated_hours_work_max, p_actual_hours_worked);
 
+        update pm_tasks set status = p_status_id where task_id = p_task_id;
+
         PERFORM acs_permission__grant_permission(
                 v_revision_id,
                 p_creation_user,
@@ -602,11 +606,6 @@
 declare
         p_task_id                               alias for $1;
 begin
-        -- will not work because permissions are on revision_id not
-        -- item_id
-        -- delete from acs_permissions
-        --      where object_id = p_task_id;
-
         delete from pm_tasks_revisions
                 where task_revision_id in (select revision_id from pm_tasks_revisionsx where item_id = p_task_id);
 
