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.69 -r1.70
--- openacs-4/packages/imsld/tcl/imsld-procs.tcl	29 Jun 2006 09:27:57 -0000	1.69
+++ openacs-4/packages/imsld/tcl/imsld-procs.tcl	29 Jun 2006 11:21:55 -0000	1.70
@@ -1050,13 +1050,15 @@
         from imsld_role_parts
         where role_part_id = :role_part_id
     }
+    # check if the referenced activities have been finished
     switch $type {
         learning {
             if { [db_string completed_from_la {
                 select count(*) from imsld_status_user
                 where completed_id = content_item__get_live_revision(:learning_activity_id)
                 and user_id = :user_id
                 and run_id = :run_id
+                and status = 'finished'
             }] } {
                 return 1
             }
@@ -1067,6 +1069,7 @@
                 where completed_id = content_item__get_live_revision(:support_activity_id)
                 and user_id = :user_id
                 and run_id = :run_id
+                and status = 'finished'
             }] } {
                 return 1
             }
@@ -1173,6 +1176,7 @@
         where completed_id = :play_id
         and user_id = :user_id
         and run_id = :run_id
+        and status = 'finished'
     }]
 } 
 
@@ -1194,6 +1198,7 @@
         where completed_id = :method_id
         and user_id = :user_id
         and run_id = :run_id
+        and status = 'finished'
     }]
 } 
 
@@ -1215,6 +1220,7 @@
         where completed_id = :imsld_id
         and user_id = :user_id
         and run_id = :run_id
+        and status = 'finished'
     }]
 } 
 
@@ -2353,6 +2359,7 @@
                     where related_id = :activity_id 
                     and user_id = :user_id 
                     and run_id = :run_id
+                    and status = 'finished'
                 }]
                 if { $completed_activity_p || [lsearch -exact $next_activity_id_list $activity_id] != -1 && ([string eq $complete_act_id ""] || [string eq $is_visible_p "t"])  } {
                     set activity_node [$dom_doc createElement li]
@@ -2392,6 +2399,7 @@
                     where related_id = :activity_id 
                     and user_id = :user_id 
                     and run_id = :run_id
+                    and status = 'finished'
                 }]
                 if { $completed_activity_p || [lsearch -exact $next_activity_id_list $activity_id] != -1 && ([string eq $complete_act_id ""] || [string eq $is_visible_p "t"])  } {
                     set activity_node [$dom_doc createElement li]
@@ -2887,6 +2895,7 @@
                     and icr.resource_id = stat.completed_id
                     and user_id = :user_id
                     and run_id = :run_id
+                    and status = 'finished'
                 }] } {
                     # if the resource is not in the imsld_status_user, then the resource is not finished
                     set all_finished_p 0
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.24 -r1.25
--- openacs-4/packages/imsld/tcl/imsld-procs.xql	29 Jun 2006 11:02:24 -0000	1.24
+++ openacs-4/packages/imsld/tcl/imsld-procs.xql	29 Jun 2006 11:21:55 -0000	1.25
@@ -1425,6 +1425,7 @@
         where user_id = :user_id
         and related_id = :activity_id
         and run_id = :run_id
+        and status = 'finished'
 
    		</querytext>
 	</fullquery>
@@ -1510,7 +1511,8 @@
         where user_id = :user_id
         and related_id = :activity_id
         and run_id = :run_id
-        
+        and status = 'finished'        
+
 		</querytext>
 	</fullquery>
 
@@ -1777,226 +1779,6 @@
 	</fullquery>
 
 
-	<fullquery name="imsld::next_activity.get_last_entry">
-		<querytext>
-        select count(*)
-        from imsld_status_user
-        where user_id = :user_id
-        and run_id = :run_id
-        and type in ('learning','support','structure')
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.get_first_role_part">
-		<querytext>
-
-            select irp.role_part_id, ia.act_id, ip.play_id
-            from cr_items cr0, cr_items cr1, cr_items cr2, imsld_methods im, imsld_plays ip, imsld_acts ia, imsld_role_parts irp
-            where im.imsld_id = :imsld_item_id
-            and ip.method_id = cr0.item_id
-            and cr0.live_revision = im.method_id
-            and ia.play_id = cr1.item_id
-            and cr1.live_revision = ip.play_id
-            and irp.act_id = cr2.item_id
-            and cr2.live_revision = ia.act_id
-            and content_revision__is_live(irp.role_part_id) = 't'
-            and ip.sort_order = (select min(ip2.sort_order) from imsld_plays ip2 where ip2.method_id = cr0.item_id)
-            and ia.sort_order = (select min(ia2.sort_order) from imsld_acts ia2 where ia2.play_id = cr1.item_id)
-            and irp.sort_order = (select min(irp2.sort_order) from imsld_role_parts irp2 where irp2.act_id = cr2.item_id)
-        </querytext>
-	</fullquery>
-
-
-
-	<fullquery name="imsld::next_activity.marked_activity">
-		<querytext>
-            select stat.related_id,
-            stat.role_part_id,
-            stat.type,
-            rp.sort_order,
-            rp.act_id,
-            stat.status
-            from imsld_status_user stat, imsld_role_parts rp
-            where stat.run_id = :run_id
-            and stat.user_id = :user_id
-            and stat.role_part_id = rp.role_part_id
-            and stat.type in ('learning','support','structure')
-            order by stat.status_date
-        
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.get_learning_activity_info">
-		<querytext>
-                        select title as activity_title,
-                        item_id as activity_item_id
-                        from imsld_learning_activitiesi
-                        where activity_id = :related_id
-                    
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.get_support_activity_info_from_isa">
-		<querytext>
-                        select title as activity_title,
-                        item_id as activity_item_id
-                        from imsld_support_activitiesi
-                        where activity_id = :related_id
-                    
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.get_support_activity_info_from_ias">
-		<querytext>
-                        select title as activity_title,
-                        item_id as structure_item_id
-                        from imsld_activity_structuresi
-                        where structure_id = :related_id
-                    
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.search_current_act">
-		<querytext>
-                select role_part_id
-                from imsld_role_parts
-                where sort_order = :sort_order + 1
-                and act_id = :act_id
-            
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.get_current_play_id">
-		<querytext>
-                    select ip.item_id as play_item_id,
-                    ip.play_id,
-                    ia.sort_order as act_sort_order
-                    from imsld_playsi ip, imsld_acts ia, cr_items cr
-                    where ip.item_id = ia.play_id
-                    and ia.act_id = cr.live_revision
-                    and cr.item_id = :act_id
-                
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.search_current_play">
-		<querytext>
-                    select rp.role_part_id
-                    from imsld_role_parts rp, imsld_actsi ia
-                    where ia.play_id = :play_item_id
-                    and ia.sort_order = :act_sort_order + 1
-                    and rp.act_id = ia.item_id
-                    and content_revision__is_live(rp.role_part_id) = 't'
-                    and content_revision__is_live(ia.act_id) = 't'
-                    and rp.sort_order = (select min(irp2.sort_order) from imsld_role_parts irp2 where irp2.act_id = rp.act_id)
-                
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.get_current_method">
-		<querytext>
-                        select im.item_id as method_item_id,
-                        ip.sort_order as play_sort_order
-                        from imsld_methodsi im, imsld_plays ip
-                        where im.item_id = ip.method_id
-                        and ip.play_id = :play_id
-                    
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.search_current_method">
-		<querytext>
-                        select rp.role_part_id
-                        from imsld_role_parts rp, imsld_actsi ia, imsld_playsi ip
-                        where ip.method_id = :method_item_id
-                        and ia.play_id = ip.item_id
-                        and rp.act_id = ia.item_id
-                        and ip.sort_order = :play_sort_order + 1
-                        and content_revision__is_live(rp.role_part_id) = 't'
-                        and content_revision__is_live(ia.act_id) = 't'
-                        and content_revision__is_live(ip.play_id) = 't'
-                        and ia.sort_order = (select min(ia2.sort_order) from imsld_acts ia2 where ia2.play_id = ip.item_id)
-                        and rp.sort_order = (select min(irp2.sort_order) from imsld_role_parts irp2 where irp2.act_id = ia.item_id)
-                    
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.get_role_part_activity">
-		<querytext>
-        select case
-        when learning_activity_id is not null
-        then 'learning'
-        when support_activity_id is not null
-        then 'support'
-        when activity_structure_id is not null
-        then 'structure'
-        else 'none'
-        end as activity_type,
-        case
-        when learning_activity_id is not null
-        then content_item__get_live_revision(learning_activity_id)
-        when support_activity_id is not null
-        then content_item__get_live_revision(support_activity_id)
-        when activity_structure_id is not null
-        then content_item__get_live_revision(activity_structure_id)
-        else content_item__get_live_revision(environment_id)
-        end as activity_id,
-        coalesce(learning_activity_id,support_activity_id,activity_structure_id) as activity_item_id,
-        environment_id as rp_environment_item_id
-        from imsld_role_parts
-        where role_part_id = :role_part_id
-    
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.learning_activity">
-		<querytext>
-            select la.activity_id,
-            la.item_id as activity_item_id,
-            la.title as activity_title,
-            la.identifier, la.component_id
-            from imsld_learning_activitiesi la
-            where la.activity_id = :activity_id
-        
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.support_activity">
-		<querytext>
-            select sa.activity_id,
-            sa.item_id as activity_item_id,
-            sa.title as activity_title,
-            sa.identifier
-            from imsld_support_activitiesi sa
-            where sa.activity_id = :activity_id
-        
-		</querytext>
-	</fullquery>
-
-
-	<fullquery name="imsld::next_activity.verify_not_completed">
-		<querytext>
-        select count(*) from imsld_status_user
-        where related_id = :activity_id
-        and user_id = :user_id
-        and status = 'finished'
-        and run_id = :run_id
-		</querytext>
-	</fullquery>
-
-
 	<fullquery name="imsld::get_activity_from_resource.learning_activity_resource">
 		<querytext>
         select ila.activity_id,