Index: openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-create.sql,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-create.sql	10 Jul 2006 13:15:13 -0000	1.6
+++ openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-create.sql	25 Sep 2006 13:13:31 -0000	1.7
@@ -119,6 +119,10 @@
     run_id          integer
                     constraint imsld_pin_rn_fk  
                     references imsld_runs,
+    user_id         integer
+                    constraint imsld_attri_user_fk      -- the vissibility property is related to this user
+                    references users
+                    not null,
     is_visible_p    char(1)
                     check (is_visible_p in ('t','f')),  
     title           varchar(100),                       -- title for the class
@@ -128,6 +132,7 @@
 
 create index imsld_attri_own_idx on imsld_attribute_instances(owner_id);
 create index imsld_attri_run_idx on imsld_attribute_instances(run_id);
+create index imsld_attri_user_idx on imsld_attribute_instances(user_id);
 
 comment on table imsld_attribute_instances is '
 This table holds the attribute instances for those attributes like isvisible or class (by the 
Index: openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-package-create.sql,v
diff -u -r1.3 -r1.4
--- openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-package-create.sql	29 Jun 2006 09:27:57 -0000	1.3
+++ openacs-4/packages/imsld/sql/postgresql/imsld-production-delivery-package-create.sql	25 Sep 2006 13:13:31 -0000	1.4
@@ -161,13 +161,14 @@
     return 0; 
 end;' language 'plpgsql';
 
-select define_function_args('imsld_attribute_instance__new','instance_id,owner_id,type,identifier,run_id,is_visible_p,title,with_control_p');
+select define_function_args('imsld_attribute_instance__new','instance_id,owner_id,type,identifier,run_id,user_id,is_visible_p,title,with_control_p');
 create or replace function imsld_attribute_instance__new (
     integer,        -- instance_id
     integer,        -- owner_id
     varchar,        -- type
     varchar,        -- identifier
     integer,        -- run_id
+    integer,        -- user_id
     varchar,        -- is_visible_p
     varchar,        -- title
     varchar         -- with_control_p
@@ -179,9 +180,10 @@
     p_type alias for $3;
     p_identifier alias for $4;
     p_run_id alias for $5;
-    p_is_visible_p alias for $6;
-    p_title alias for $7;
-    p_with_control_p alias for $8;
+    p_user_id alias for $6;
+    p_is_visible_p alias for $7;
+    p_title alias for $8;
+    p_with_control_p alias for $9;
 
     v_attribute_instance_id        integer;
 
@@ -190,8 +192,8 @@
     select acs_object_id_seq.nextval
     into v_attribute_instance_id from dual;
 
-    insert into imsld_attribute_instances (instance_id, owner_id, type, identifier, run_id, is_visible_p, title, with_control_p)
-    values (v_attribute_instance_id, p_owner_id, p_type, p_identifier, p_run_id, p_is_visible_p, p_title, p_with_control_p);
+    insert into imsld_attribute_instances (instance_id, owner_id, type, identifier, run_id, user_id,  is_visible_p, title, with_control_p)
+    values (v_attribute_instance_id, p_owner_id, p_type, p_identifier, p_run_id, p_user_id, p_is_visible_p, p_title, p_with_control_p);
 
     return v_attribute_instance_id;
 end;
Index: openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl,v
diff -u -r1.16 -r1.17
--- openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl	20 Sep 2006 15:04:05 -0000	1.16
+++ openacs-4/packages/imsld/tcl/imsld-condition-procs.tcl	25 Sep 2006 13:13:31 -0000	1.17
@@ -41,6 +41,7 @@
     foreach ifNode $ifNodes {
         if {[imsld::expression::eval -run_id $run_id -expression [$ifNode childNodes]]} {
             foreach thenNode $thenNodes {
+                ns_log Notice "troncho: [$thenNode asXML]"
                 imsld::statement::execute -run_id $run_id -statement [$thenNode childNodes]
             }
         } else {
@@ -671,7 +672,7 @@
                             if { [string eq $class ""] } {
                                 
                                 # NOTE: according to the spec this attribute may be empty... what to do??
-                                ns_log notice "imsld::statement::execute: class ref is empty"
+d                                ns_log notice "imsld::statement::execute: class ref is empty"
                                 continue
                             }
                             imsld::runtime::class::show_hide -class $class -run_id $run_id -title $title -with_control_p $with_control_p -action "hide"
Index: openacs-4/packages/imsld/tcl/imsld-instance-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-instance-procs.tcl,v
diff -u -r1.10 -r1.11
--- openacs-4/packages/imsld/tcl/imsld-instance-procs.tcl	24 Jul 2006 14:19:30 -0000	1.10
+++ openacs-4/packages/imsld/tcl/imsld-instance-procs.tcl	25 Sep 2006 13:13:31 -0000	1.11
@@ -233,265 +233,285 @@
     is created, those attributes must be initialized according to the values parsed from the manifest, and not
     from the possible changed values of a previous run.
 } {
-    db_1row context_info {
-        select ic.item_id as component_item_id,
-        ii.imsld_id,
-        ii.learning_objective_id as imsld_learning_objective_id,
-        ii.prerequisite_id as imsld_prerequisite_id,
-        ii.item_id as run_imsld_item_id,
-        rug.group_id as run_group_id
-        from imsld_componentsi ic, imsld_imsldsi ii, imsld_runs ir, imsld_run_users_group_ext rug
-        where ic.imsld_id = ii.item_id
-        and content_revision__is_live(ii.imsld_id) = 't'
-        and ii.imsld_id = ir.imsld_id
-        and rug.run_id = ir.run_id
-        and ir.run_id = :run_id
+
+    set involved_roles [imsld::roles::get_list_of_roles -imsld_id [db_string get_imsld_from_run {select imsld_id from imsld_runs where run_id=:run_id}] ]
+    set involved_users [list]
+    foreach role $involved_roles {
+        set involved_users [concat $involved_users [imsld::roles::get_users_in_role -role_id [lindex $role 0] -run_id $run_id]]
     }
     
-    # 1. items --> learning objectives, prerequisites, roles, 
-    #      learning objects, activity description, information(activity structures)
-    
-    # 1.1 learning objectives items
-    set linear_item_list [db_list item_in_imsld_loi {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_learning_objectivesi lo
-        where ar.object_id_one = lo.item_id
-        and ar.object_id_two = ii.item_id
-        and lo.learning_objective_id = :imsld_learning_objective_id
-    }]
-    
-    set linear_item_list [concat $linear_item_list [db_list item_in_activity_loi {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_learning_activities ia, imsld_learning_objectivesi lo
-        where ar.object_id_one = lo.item_id
-        and ar.object_id_two = ii.item_id
-        and ia.learning_objective_id = lo.item_id
-        and ia.component_id = :component_item_id
-    }]]
-    
-    # 1.2. prerequisites
-    set linear_item_list [concat $linear_item_list [db_list item_in_imsld_pre {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_prerequisitesi pre
-        where ar.object_id_one = pre.item_id
-        and ar.object_id_two = ii.item_id
-        and pre.prerequisite_id = :imsld_prerequisite_id
-    }]]
-    
-    set linear_item_list [concat $linear_item_list [db_list item_in_activity_pre {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_learning_activities ia, imsld_prerequisitesi pre
-        where ar.object_id_one = pre.item_id
-        and ar.object_id_two = ii.item_id
-        and ia.prerequisite_id = pre.item_id
-        and ia.component_id = :component_item_id
-    }]]
+    foreach user_id [lsort -unique $involved_users] { 
+        
+        db_1row context_info {
+            select ic.item_id as component_item_id,
+            ii.imsld_id,
+            ii.learning_objective_id as imsld_learning_objective_id,
+            ii.prerequisite_id as imsld_prerequisite_id,
+            ii.item_id as run_imsld_item_id,
+            rug.group_id as run_group_id
+            from imsld_componentsi ic, imsld_imsldsi ii, imsld_runs ir, imsld_run_users_group_ext rug
+            where ic.imsld_id = ii.item_id
+            and content_revision__is_live(ii.imsld_id) = 't'
+            and ii.imsld_id = ir.imsld_id
+            and rug.run_id = ir.run_id
+            and ir.run_id = :run_id
+        }
+        
+        # 1. items --> learning objectives, prerequisites, roles, 
+        #      learning objects, activity description, information(activity structures)
+        
+        # 1.1 learning objectives items
+        set linear_item_list [db_list item_in_imsld_loi {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_learning_objectivesi lo
+            where ar.object_id_one = lo.item_id
+            and ar.object_id_two = ii.item_id
+            and lo.learning_objective_id = :imsld_learning_objective_id
+        }]
+        
+        set linear_item_list [concat $linear_item_list [db_list item_in_activity_loi {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_learning_activities ia, imsld_learning_objectivesi lo
+            where ar.object_id_one = lo.item_id
+            and ar.object_id_two = ii.item_id
+            and ia.learning_objective_id = lo.item_id
+            and ia.component_id = :component_item_id
+        }]]
+        
+        # 1.2. prerequisites
+        set linear_item_list [concat $linear_item_list [db_list item_in_imsld_pre {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_prerequisitesi pre
+            where ar.object_id_one = pre.item_id
+            and ar.object_id_two = ii.item_id
+            and pre.prerequisite_id = :imsld_prerequisite_id
+        }]]
+        
+        set linear_item_list [concat $linear_item_list [db_list item_in_activity_pre {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_learning_activities ia, imsld_prerequisitesi pre
+            where ar.object_id_one = pre.item_id
+            and ar.object_id_two = ii.item_id
+            and ia.prerequisite_id = pre.item_id
+            and ia.component_id = :component_item_id
+        }]]
 
-    # 1.3. roles
-    set linear_item_list [concat $linear_item_list [db_list item_in_role {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_rolesi ir
-        where ar.object_id_one = ir.item_id
-        and ar.object_id_two = ii.item_id
-        and ir.component_id = :component_item_id
-    }]]
+        # 1.3. roles
+        set linear_item_list [concat $linear_item_list [db_list item_in_role {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_rolesi ir
+            where ar.object_id_one = ir.item_id
+            and ar.object_id_two = ii.item_id
+            and ir.component_id = :component_item_id
+        }]]
 
-    # 1.4. learning objects (environments)
-    set linear_item_list [concat $linear_item_list [db_list item_in_lo {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_learning_objectsi lo, imsld_environmentsi env
-        where ar.object_id_one = lo.item_id
-        and ar.object_id_two = ii.item_id
-        and lo.environment_id = env.item_id
-        and env.component_id = :component_item_id
-    }]]
-    
-    # 1.5. activity description (learning activities)
-    set linear_item_list [concat $linear_item_list [db_list item_in_la_desc {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_learning_activitiesi la, imsld_activity_descsi ad
-        where ar.object_id_one = ad.item_id
-        and ar.object_id_two = ii.item_id
-        and la.activity_description_id = ad.item_id
-        and la.component_id = :component_item_id
-    }]]
+        # 1.4. learning objects (environments)
+        set linear_item_list [concat $linear_item_list [db_list item_in_lo {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_learning_objectsi lo, imsld_environmentsi env
+            where ar.object_id_one = lo.item_id
+            and ar.object_id_two = ii.item_id
+            and lo.environment_id = env.item_id
+            and env.component_id = :component_item_id
+        }]]
+        
+        # 1.5. activity description (learning activities)
+        set linear_item_list [concat $linear_item_list [db_list item_in_la_desc {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_learning_activitiesi la, imsld_activity_descsi ad
+            where ar.object_id_one = ad.item_id
+            and ar.object_id_two = ii.item_id
+            and la.activity_description_id = ad.item_id
+            and la.component_id = :component_item_id
+        }]]
 
-    # 1.6. activity description (support activities)
-    set linear_item_list [concat $linear_item_list [db_list item_in_sa_desc {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_support_activitiesi sa, imsld_activity_descsi ad
-        where ar.object_id_one = ad.item_id
-        and ar.object_id_two = ii.item_id
-        and sa.activity_description_id = ad.item_id
-        and sa.component_id = :component_item_id
-    }]]
-    
-    # 1.7. information(activity structures)
-    set linear_item_list [concat $linear_item_list [db_list item_in_as_info {
-        select ii.imsld_item_id
-        from acs_rels ar, imsld_itemsi ii, imsld_activity_structuresi ast
-        where ar.object_id_one = ast.item_id
-        and ar.object_id_two = ii.item_id
-        and ast.component_id = :component_item_id
-    }]]
+        # 1.6. activity description (support activities)
+        set linear_item_list [concat $linear_item_list [db_list item_in_sa_desc {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_support_activitiesi sa, imsld_activity_descsi ad
+            where ar.object_id_one = ad.item_id
+            and ar.object_id_two = ii.item_id
+            and sa.activity_description_id = ad.item_id
+            and sa.component_id = :component_item_id
+        }]]
+        
+        # 1.7. information(activity structures)
+        set linear_item_list [concat $linear_item_list [db_list item_in_as_info {
+            select ii.imsld_item_id
+            from acs_rels ar, imsld_itemsi ii, imsld_activity_structuresi ast
+            where ar.object_id_one = ast.item_id
+            and ar.object_id_two = ii.item_id
+            and ast.component_id = :component_item_id
+        }]]
 
-    foreach imsld_item_id $linear_item_list {
-        db_foreach nested_associated_items {
-            select ii.imsld_item_id, ii.item_id,
-            coalesce(ii.is_visible_p, 't') as is_visible_p,
-            ii.identifier
-            from imsld_itemsi ii
-            where (imsld_tree_sortkey between tree_left((select imsld_tree_sortkey from imsld_items where imsld_item_id = :imsld_item_id))
-                   and tree_right((select imsld_tree_sortkey from imsld_items where imsld_item_id = :imsld_item_id))
-                   or ii.imsld_item_id = :imsld_item_id)
+        foreach imsld_item_id $linear_item_list {
+            db_foreach nested_associated_items {
+                select ii.imsld_item_id, ii.item_id,
+                coalesce(ii.is_visible_p, 't') as is_visible_p,
+                ii.identifier
+                from imsld_itemsi ii
+                where (imsld_tree_sortkey between tree_left((select imsld_tree_sortkey from imsld_items where imsld_item_id = :imsld_item_id))
+                       and tree_right((select imsld_tree_sortkey from imsld_items where imsld_item_id = :imsld_item_id))
+                       or ii.imsld_item_id = :imsld_item_id)
+            } {
+                if { ![db_0or1row info_as_already_instantiated_p {
+                    select 1
+                    from imsld_attribute_instances
+                    where owner_id = :imsld_item_id
+                    and run_id = :run_id
+                    and user_id = :user_id
+                    and type = 'isvisible'
+                }] } {
+                    ns_log Notice "antes del tema: $user_id"
+                    set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $imsld_item_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list user_id $user_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+                    ns_log Notice "despues del tema"
+                }
+            }
+        }
+
+        # 2. learning activities
+        db_foreach learning_activity {
+            select la.activity_id,
+            coalesce(la.is_visible_p, 't') as is_visible_p,
+            la.identifier
+            from imsld_learning_activities la
+            where la.component_id = :component_item_id
         } {
-            if { ![db_0or1row info_as_already_instantiated_p {
+            if { ![db_0or1row la_already_instantiated_p {
                 select 1
                 from imsld_attribute_instances
-                where owner_id = :imsld_item_id
+                where owner_id = :activity_id
                 and run_id = :run_id
+                and user_id = :user_id
                 and type = 'isvisible'
             }] } {
-                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $imsld_item_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $activity_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list user_id $user_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
             }
         }
-    }
-
-    # 2. learning activities
-    db_foreach learning_activity {
-        select la.activity_id,
-        coalesce(la.is_visible_p, 't') as is_visible_p,
-        la.identifier
-        from imsld_learning_activities la
-        where la.component_id = :component_item_id
-    } {
-        if { ![db_0or1row la_already_instantiated_p {
-            select 1
-            from imsld_attribute_instances
-            where owner_id = :activity_id
-            and run_id = :run_id
-            and type = 'isvisible'
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $activity_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+        
+        # 3. support activities
+        db_foreach support_activity {
+            select sa.activity_id,
+            coalesce(sa.is_visible_p, 't') as is_visible_p,
+            sa.identifier
+            from imsld_support_activities sa
+            where sa.component_id = :component_item_id
+        } {
+            if { ![db_0or1row sa_already_instantiated_p {
+                select 1
+                from imsld_attribute_instances
+                where owner_id = :activity_id
+                and run_id = :run_id
+                and user_id = :user_id
+                and type = 'isvisible'
+            }] } {
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $activity_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list user_id $user_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+            }
         }
-    }
-    
-    # 3. support activities
-    db_foreach support_activity {
-        select sa.activity_id,
-        coalesce(sa.is_visible_p, 't') as is_visible_p,
-        sa.identifier
-        from imsld_support_activities sa
-        where sa.component_id = :component_item_id
-    } {
-        if { ![db_0or1row sa_already_instantiated_p {
-            select 1
-            from imsld_attribute_instances
-            where owner_id = :activity_id
-            and run_id = :run_id
-            and type = 'isvisible'
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $activity_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
-        }
-    }
 
-    # 4. learning object (environment)
-    db_foreach learning_object {
-        select lo.learning_object_id,
-        coalesce(lo.is_visible_p, 't') as is_visible_p,
-        class,
-        lo.identifier
-        from imsld_learning_objects lo, imsld_environmentsi env
-        where lo.environment_id = env.item_id
-        and env.component_id = :component_item_id
-    } {
-        if { ![db_0or1row lo_already_instantiated_p {
-            select 1
-            from imsld_attribute_instances
-            where owner_id = :learning_object_id
-            and run_id = :run_id
-            and type = 'isvisible'
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $learning_object_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+        # 4. learning object (environment)
+        db_foreach learning_object {
+            select lo.learning_object_id,
+            coalesce(lo.is_visible_p, 't') as is_visible_p,
+            class,
+            lo.identifier
+            from imsld_learning_objects lo, imsld_environmentsi env
+            where lo.environment_id = env.item_id
+            and env.component_id = :component_item_id
+        } {
+            if { ![db_0or1row lo_already_instantiated_p {
+                select 1
+                from imsld_attribute_instances
+                where owner_id = :learning_object_id
+                and run_id = :run_id
+                and user_id = :user_id
+                and type = 'isvisible'
+            }] } {
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $learning_object_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list user_id $user_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+            }
+            if { ![string eq "" $class] && ![db_0or1row lo_env_already_instantiated_p {
+                select 1
+                from imsld_attribute_instances
+                where run_id = :run_id
+                and user_id= :user_id
+                and type = 'class'
+                and identifier = :class
+            }] } {
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id ""] [list type "class"] [list identifier $class] [list run_id $run_id] [list user_id $user_id] [list is_visible_p "t"] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+            }
         }
-        if { ![string eq "" $class] && ![db_0or1row lo_env_already_instantiated_p {
-            select 1
-            from imsld_attribute_instances
-            where run_id = :run_id
-            and type = 'class'
-            and identifier = :class
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id ""] [list type "class"] [list identifier $class] [list run_id $run_id] [list is_visible_p "t"] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
-        }
-    }
 
-    # 5. service (enviroment)
-    db_foreach service {
-        select serv.service_id,
-        coalesce(serv.is_visible_p, 't') as is_visible_p,
-        class,
-        serv.identifier
-        from imsld_services serv, imsld_environmentsi env
-        where serv.environment_id = env.item_id
-        and env.component_id = :component_item_id
-    } {
-        if { ![db_0or1row serv_already_instantiated_p {
-            select 1
-            from imsld_attribute_instances
-            where owner_id = :service_id
-            and run_id = :run_id
-            and type = 'isvisible'
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $service_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+        # 5. service (enviroment)
+        db_foreach service {
+            select serv.service_id,
+            coalesce(serv.is_visible_p, 't') as is_visible_p,
+            class,
+            serv.identifier
+            from imsld_services serv, imsld_environmentsi env
+            where serv.environment_id = env.item_id
+            and env.component_id = :component_item_id
+        } {
+            if { ![db_0or1row serv_already_instantiated_p {
+                select 1
+                from imsld_attribute_instances
+                where owner_id = :service_id
+                and run_id = :run_id
+                and user_id = :user_id
+                and type = 'isvisible'
+            }] } {
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $service_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list user_id $user_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+            }
+            if { ![string eq "" $class] && ![db_0or1row serv_env_already_instantiated_p {
+                select 1
+                from imsld_attribute_instances
+                where run_id = :run_id
+                and user_id = :user_id
+                and type = 'class'
+                and identifier = :class
+            }] } {
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id ""] [list type "class"] [list identifier $class] [list run_id $run_id] [list user_id $user_id] [list is_visible_p "t"] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+            }
         }
-        if { ![string eq "" $class] && ![db_0or1row serv_env_already_instantiated_p {
-            select 1
-            from imsld_attribute_instances
-            where run_id = :run_id
-            and type = 'class'
-            and identifier = :class
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id ""] [list type "class"] [list identifier $class] [list run_id $run_id] [list is_visible_p "t"] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
-        }
-    }
 
-    # 6. play
-    db_foreach play {
-        select play.play_id,
-        coalesce(play.is_visible_p, 't') as is_visible_p,
-        play.identifier
-        from imsld_plays play, imsld_methodsi im
-        where play.method_id = im.item_id
-        and im.imsld_id = :run_imsld_item_id
-    } {
-        if { ![db_0or1row play_already_instantiated_p {
-            select 1
-            from imsld_attribute_instances
-            where owner_id = :play_id
-            and run_id = :run_id
-            and type = 'isvisible'
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $play_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+        # 6. play
+        db_foreach play {
+            select play.play_id,
+            coalesce(play.is_visible_p, 't') as is_visible_p,
+            play.identifier
+            from imsld_plays play, imsld_methodsi im
+            where play.method_id = im.item_id
+            and im.imsld_id = :run_imsld_item_id
+        } {
+            if { ![db_0or1row play_already_instantiated_p {
+                select 1
+                from imsld_attribute_instances
+                where owner_id = :play_id
+                and run_id = :run_id
+                and user_id = :user_id
+                and type = 'isvisible'
+            }] } {
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id $play_id] [list type "isvisible"] [list identifier $identifier] [list run_id $run_id] [list user_id $user_id] [list is_visible_p $is_visible_p] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+            }
         }
-    }
 
-    # 7. classes
-    db_foreach class {
-        select cla.class_id,
-        cla.identifier
-        from imsld_classesi cla, imsld_methodsi im
-        where cla.method_id = im.item_id
-        and im.imsld_id = :run_imsld_item_id
-    } {
-        if { ![db_0or1row already_instantiated {
-            select 1 from imsld_attribute_instances
-            where identifier = :identifier
-            and run_id = :run_id
-        }] } {
-            set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id ""] [list type "class"] [list identifier $identifier] [list run_id $run_id] [list is_visible_p "t"] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+        # 7. classes
+        db_foreach class {
+            select cla.class_id,
+            cla.identifier
+            from imsld_classesi cla, imsld_methodsi im
+            where cla.method_id = im.item_id
+            and im.imsld_id = :run_imsld_item_id
+        } {
+            if { ![db_0or1row already_instantiated {
+                select 1 from imsld_attribute_instances
+                where identifier = :identifier
+                and run_id = :run_id
+                and user_id = :user_id
+            }] } {
+                set instance_id [package_exec_plsql -var_list [list [list instance_id ""] [list owner_id ""] [list type "class"] [list identifier $identifier] [list run_id $run_id] [list user_id $user_id] [list is_visible_p "t"] [list title ""] [list with_control_p ""]] imsld_attribute_instance new]
+            }
         }
     }
-
     return
 }
 
Index: openacs-4/packages/imsld/tcl/imsld-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-procs.tcl,v
diff -u -r1.83 -r1.84
--- openacs-4/packages/imsld/tcl/imsld-procs.tcl	22 Sep 2006 10:58:11 -0000	1.83
+++ openacs-4/packages/imsld/tcl/imsld-procs.tcl	25 Sep 2006 13:13:31 -0000	1.84
@@ -1384,18 +1384,21 @@
     -run_id:required
     -owner_id:required
     -class_name:required
+    {-user_id ""}
 } { 
     @param run_id
     @param owner_id
     @param class_name
 
-    @return 1 if the class of the owner_id is currently visible in the run, 0 otherwise.
+    @return 1 if the class of the owner_id is currently visible in the run for a given user_id, 0 otherwise.
 } {
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     return [expr ![db_0or1row class_visible_p {
         select 1
         from imsld_attribute_instances
         where run_id = :run_id
         and type = 'class'
+        and user_id = :user_id
         and identifier = :class_name
         and is_visible_p = 'f'
     }]]
@@ -1407,6 +1410,7 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } { 
     @param service_item_id
     @param run_id
@@ -1416,6 +1420,7 @@
 
     @return a html list (in a dom tree) of the associated resources referenced from the given service.
 } {
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     set services_list [list]
 
     # get service info
@@ -1502,6 +1507,7 @@
     {-resource_mode "f"}
     -dom_node:required
     -dom_doc:required
+    {-user_id ""}
 } { 
     @param environment_item_id
     @param run_id
@@ -1511,6 +1517,7 @@
 
     @return a html list (in a dom tree) of the associated resources, files and environments referenced from the given environment.
 } {  
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     # get environment info
     db_1row environment_info { *SQL* }
 
@@ -1630,16 +1637,19 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param run_id
     @option imsld_item_id
     @option activity_item_id
     @option resource_mode
     @param dom_node
     @param dom_doc
+    @param user_id
 
     @return a html list (ul, using tdom) with the objective title and the associated resources referenced from the learning objective of the given activity or ims-ld
-} {  
+} { 
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     set learning_objective_item_id ""
     if { ![string eq "" $imsld_item_id] } {
         db_0or1row lo_id_from_imsld_item_id { *SQL* }
@@ -1683,6 +1693,7 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param run_id
     @option imsld_item_id
@@ -1692,7 +1703,8 @@
     @param dom_doc
 
     @return a html list (using tdom) of the associated resources referenced from the prerequisite of the given ims-ld or activity
-} {  
+} { 
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     set prerequisite_item_id ""
     if { ![string eq "" $imsld_item_id] } {
         db_0or1row lo_id_from_imsld_item_id { *SQL* }
@@ -1733,14 +1745,16 @@
     {-on_completion_item_id ""}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param run_id
     @option on_completion_item_id
     @param dom_node
     @param dom_doc
 
     @return a html list (using tdom) with the feedback title and the associated resources referenced from the given feedback (on_completion)
-} {  
+} { 
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     set feedback_item_id ""
     # get on completion info
     db_1row feedback_info { *SQL* }
@@ -1764,6 +1778,7 @@
     -dom_node 
     -dom_doc
     -li_mode:boolean
+    {-user_id ""}
 } {
     @param resource_item_id
     @param run_id
@@ -1773,6 +1788,7 @@
 
     @return The html ul (using tdom) of the files associated to the given resource_id
 } {
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     set community_id [expr { [string eq "" $community_id] ? "[dotlrn_community::get_community_id]" : $community_id }]
     set imsld_package_id [site_node_apm_integration::get_child_package_id \
                               -package_id [dotlrn_community::get_package_id $community_id] \
@@ -1888,6 +1904,8 @@
     -dom_node:required
     -dom_doc
     {-resource_mode "f"}
+    {-user_id ""}
+
 } {
     @param activity_item_id
     @param run_id
@@ -1899,6 +1917,7 @@
     It only works whith the learning and support activities, since it will only return the objectives, prerequistes,
     associated resources but not the environments.
 } {
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     if { [db_0or1row is_imsld {
         select 1 from imsld_imsldsi where item_id = :activity_item_id
     }] } {
@@ -1942,6 +1961,7 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param activity_item_id
     @param run_id
@@ -1952,7 +1972,7 @@
     
     @return The html list (using tdom) of resources (learning objects and services) associated to the activity's environment(s)
 } {
-    
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     # get the rel_type
     if { [db_0or1row is_imsld {
         select 1 from imsld_imsldsi where item_id = :activity_item_id
@@ -1996,13 +2016,15 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param imsld_item_id
     @param run_id
     @option resource_mode default f
     
     @return The html list (using tdom) of the resources associated to the given imsld_id (objectives and prerequisites).
 } {
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     db_1row imsld_info {
         select prerequisite_id as prerequisite_item_id,
         learning_objective_id as learning_objective_item_id,
@@ -2061,6 +2083,7 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param activity_item_id
     @param run_id
@@ -2071,7 +2094,7 @@
     
     @return The list (activity_name, list of associated urls, using tdom) of the activity in the IMS-LD.
 } {
-    set user_id [ad_conn user_id]
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     if { ![db_0or1row activity_info { *SQL* }] } {
         # is visible is false, do not show anything
         return
@@ -2194,6 +2217,7 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param activity_item_id
     @param run_id
@@ -2203,7 +2227,7 @@
 
     @return The list of items (resources, feedback, environments, using tdom) associated with the support activity
 } {
-    set user_id [ad_conn user_id]
+     set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     if { ![db_0or1row activity_info { *SQL* }] } {
         # is visible is false do not show anything
         return
@@ -2285,6 +2309,7 @@
     {-resource_mode "f"}
     -dom_node
     -dom_doc
+    {-user_id ""}
 } {
     @param structure_item_id
     @param run_id
@@ -2294,7 +2319,7 @@
     
     @return The html list (using tdom) of items (information) associated with the activity structure
 } {
-
+     set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id } ]
     # get the items associated with the activity
     set info_tab_node [$dom_doc createElement li]
     set text [$dom_doc createTextNode "[_ imsld.Information]"]
Index: openacs-4/packages/imsld/tcl/imsld-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-procs.xql,v
diff -u -r1.30 -r1.31
--- openacs-4/packages/imsld/tcl/imsld-procs.xql	20 Sep 2006 08:26:30 -0000	1.30
+++ openacs-4/packages/imsld/tcl/imsld-procs.xql	25 Sep 2006 13:13:31 -0000	1.31
@@ -1092,6 +1092,7 @@
         and content_revision__is_live(lo.learning_object_id) = 't'
         and attr.owner_id = lo.learning_object_id
         and attr.run_id = :run_id
+        and attr.user_id = :user_id
         and attr.type = 'isvisible'
         and attr.is_visible_p = 't'
         order by lo.creation_date
@@ -1133,6 +1134,7 @@
                      or ii.imsld_item_id = :imsld_item_id)
                 and attr.owner_id = ii.imsld_item_id
                 and attr.run_id = :run_id
+                and attr.user_id = :user_id
                 and attr.type = 'isvisible'
                 and attr.is_visible_p = 't'
                         
@@ -1154,6 +1156,7 @@
         and content_revision__is_live(ise.service_id) = 't'
         and attr.owner_id = ise.service_id
         and attr.run_id = :run_id
+        and attr.user_id = :user_id
         and attr.type = 'isvisible'
         and attr.is_visible_p = 't'
         
@@ -1240,6 +1243,7 @@
                  or ii.imsld_item_id = :imsld_item_id)
             and attr.owner_id = ii.imsld_item_id
             and attr.run_id = :run_id
+            and attr.user_id = :user_id
             and attr.type = 'isvisible'
             and attr.is_visible_p = 't'
                 
@@ -1314,6 +1318,7 @@
                  or ii.imsld_item_id = :imsld_item_id)
             and attr.owner_id = ii.imsld_item_id
             and attr.run_id = :run_id
+            and attr.user_id = :user_id
             and attr.type = 'isvisible'
             and attr.is_visible_p = 't'
                 
@@ -1363,6 +1368,7 @@
                  or ii.imsld_item_id = :imsld_item_id)
             and attr.owner_id = ii.imsld_item_id
             and attr.run_id = :run_id
+            and attr.user_id = :user_id
             and attr.type = 'isvisible'
             and attr.is_visible_p = 't'
                 
@@ -1484,6 +1490,7 @@
         and content_revision__is_live(la.activity_id) = 't'
         and attr.owner_id = la.activity_id
         and attr.run_id = :run_id
+        and attr.user_id = :user_id
         and attr.type = 'isvisible'
         and attr.is_visible_p = 't'
         
@@ -1524,6 +1531,7 @@
                  or ii.imsld_item_id = :imsld_item_id)
             and attr.owner_id = ii.imsld_item_id
             and attr.run_id = :run_id
+            and attr.user_id = :user_id
             and attr.type = 'isvisible'
             and attr.is_visible_p = 't'
 
@@ -1568,6 +1576,7 @@
         and content_revision__is_live(isa.activity_id) = 't'
         and attr.owner_id = isa.activity_id
         and attr.run_id = :run_id
+        and attr.user_id = :user_id
         and attr.type = 'isvisible'
         and attr.is_visible_p = 't'
         
@@ -1609,6 +1618,7 @@
                  or ii.imsld_item_id = :imsld_item_id)
             and attr.owner_id = ii.imsld_item_id
             and attr.run_id = :run_id
+            and attr.user_id = :user_id  
             and attr.type = 'isvisible'
             and attr.is_visible_p = 't'
                 
@@ -1671,6 +1681,7 @@
                  or ii.imsld_item_id = :imsld_item_id)
             and attr.owner_id = ii.imsld_item_id
             and attr.run_id = :run_id
+            and attr.user_id = :user_id  
             and attr.type = 'isvisible'
             and attr.is_visible_p = 't'
             
@@ -1716,6 +1727,7 @@
                     and content_revision__is_live(la.activity_id) = 't'
                     and attr.owner_id = la.activity_id
                     and attr.run_id = :run_id
+                    and attr.user_id = :user_id
                     and attr.type = 'isvisible'
 
 
@@ -1747,6 +1759,7 @@
                     and content_revision__is_live(sa.activity_id) = 't'
                     and attr.owner_id = sa.activity_id
                     and attr.run_id = :run_id
+                    and attr.user_id = :user_id
                     and attr.type = 'isvisible'
                 
 		</querytext>
@@ -1806,6 +1819,7 @@
         and content_revision__is_live(rp.role_part_id) = 't'
         and attr.owner_id = ip.play_id
         and attr.run_id = :run_id
+        and attr.user_id = :user_id
         and attr.type = 'isvisible'
         and attr.is_visible_p = 't'
         order by ip.sort_order, ia.sort_order, rp.sort_order
@@ -1825,6 +1839,7 @@
                     where activity_id = :activity_id
                     and attr.owner_id = la.activity_id
                     and attr.run_id = :run_id
+                    and attr.user_id = :user_id
                     and attr.type = 'isvisible'
                     
 		</querytext>
@@ -1842,6 +1857,7 @@
                     where sa.activity_id = :activity_id
                     and attr.owner_id = sa.activity_id
                     and attr.run_id = :run_id
+                    and attr.user_id = :user_id
                     and attr.type = 'isvisible'
                     
 		</querytext>
Index: openacs-4/packages/imsld/tcl/imsld-roles-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-roles-procs.tcl,v
diff -u -r1.14 -r1.15
--- openacs-4/packages/imsld/tcl/imsld-roles-procs.tcl	20 Sep 2006 08:26:30 -0000	1.14
+++ openacs-4/packages/imsld/tcl/imsld-roles-procs.tcl	25 Sep 2006 13:13:31 -0000	1.15
@@ -343,17 +343,19 @@
         }
     } elseif { [info exist run_id] } {
         if { [db_0or1row select_role_id_from_run {
-                select ar1.object_id_one as role_id
+                select iri.role_id
                 from imsld_rolesi iri, 
                      acs_rels ar1, 
-                     acs_rels ar2 
+                     acs_rels ar2,
+                     imsld_run_users_group_ext iruns
                 where ar1.object_id_two=ar2.object_id_one 
                       and ar1.rel_type='imsld_role_group_rel' 
                       and ar2.rel_type='imsld_roleinstance_run_rel' 
-                      and ar2.object_id_two=:run_id
+                      and ar2.object_id_two=iruns.group_id
+                      and iruns.run_id=:run_id
                       and iri.item_id=ar1.object_id_one 
                       and iri.identifier=:ref
-                group by ar1.object_id_one
+                group by iri.role_id
             }] } {
             return $role_id
         }
Index: openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl,v
diff -u -r1.11 -r1.12
--- openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl	20 Sep 2006 08:26:30 -0000	1.11
+++ openacs-4/packages/imsld/tcl/imsld-runtime-procs.tcl	25 Sep 2006 13:13:31 -0000	1.12
@@ -307,12 +307,15 @@
 ad_proc -public imsld::runtime::class::show_hide {
     -run_id
     -class
+    {-user_id ""}
     {-title ""}
     {-with_control_p ""}
     -action:required
 } {
     mark a class as showh or hidden. NOTE: not recursively
 } {
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
+
     if { [string eq $action "show"] } {
         set is_visible_p "t"
     } else {
@@ -325,10 +328,12 @@
 ad_proc -public imsld::runtime::isvisible::show_hide {
     -run_id
     -identifier
+    {-user_id ""}
     -action:required
 } {
     mark a isvisible as showh. NOTE: not recursively
 } {
+    set user_id [expr { [string eq "" $user_id] ? [ad_conn user_id] : $user_id }]
     if { [string eq $action "show"] } {
          set is_visible_p "t"
     } else {
Index: openacs-4/packages/imsld/tcl/imsld-runtime-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-runtime-procs.xql,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/imsld/tcl/imsld-runtime-procs.xql	6 Jul 2006 11:29:57 -0000	1.6
+++ openacs-4/packages/imsld/tcl/imsld-runtime-procs.xql	25 Sep 2006 13:13:31 -0000	1.7
@@ -35,6 +35,7 @@
             with_control_p = :with_control_p,
             title = :title
             where run_id = :run_id
+              and user_id = :user_id
               and identifier = :class
               and type = 'class'
         </querytext>
@@ -45,6 +46,7 @@
             update imsld_attribute_instances
             set is_visible_p = :is_visible_p
             where run_id = :run_id
+              and user_id = :user_id
               and identifier = :identifier
               and type = 'isvisible'
         </querytext>
Index: openacs-4/packages/imsld/www/imsld-content-serve.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/www/imsld-content-serve.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/imsld/www/imsld-content-serve.tcl	20 Sep 2006 15:04:05 -0000	1.9
+++ openacs-4/packages/imsld/www/imsld-content-serve.tcl	25 Sep 2006 13:13:31 -0000	1.10
@@ -511,6 +511,7 @@
             with_control_p
             from imsld_attribute_instances
             where run_id = :run_id
+            and user_id = :user_id
             and identifier = :class_name
             and type = 'class'
         }] } {
Index: openacs-4/packages/imsld/www/admin/imsld-confirm-finish.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/www/admin/imsld-confirm-finish.tcl,v
diff -u -r1.4 -r1.5
--- openacs-4/packages/imsld/www/admin/imsld-confirm-finish.tcl	19 Jul 2006 15:06:10 -0000	1.4
+++ openacs-4/packages/imsld/www/admin/imsld-confirm-finish.tcl	25 Sep 2006 13:13:32 -0000	1.5
@@ -11,8 +11,9 @@
 
 # instantiating properties and activity attributes for the run
 imsld::instance::instantiate_properties -run_id $run_id
+ns_log Notice "el run si que lo ha instanciado"
 imsld::instance::instantiate_activity_attributes -run_id $run_id
-
+ns_log Notice "los atributos.que lo ha instanciado"
 # NOTE: we should verify the permissions here
 set conditions 1
 if {$conditions == 1} {