Index: openacs-4/packages/imsld/tcl/imsld-parse-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/imsld/tcl/imsld-parse-procs.tcl,v
diff -u -r1.61 -r1.62
--- openacs-4/packages/imsld/tcl/imsld-parse-procs.tcl	24 Oct 2006 10:09:51 -0000	1.61
+++ openacs-4/packages/imsld/tcl/imsld-parse-procs.tcl	21 Dec 2006 12:08:36 -0000	1.62
@@ -1568,6 +1568,7 @@
 
 ad_proc -public imsld::parse::parse_and_create_forum { 
     -name
+    -is_moderated:boolean
 } {
     Create a forum with the given name.
 
@@ -1578,10 +1579,16 @@
     set forums_package_id [site_node_apm_integration::get_child_package_id \
                                -package_id [dotlrn_community::get_package_id $community_id] \
                                -package_key "forums"]
-    set acs_object_id [forum::new -name $name -package_id $forums_package_id]
+    if {$is_moderated_p} {
+        set acs_object_id [forum::new -name $name -package_id $forums_package_id -posting_policy "moderated"]   
+    } else { 
+        set acs_object_id [forum::new -name $name -package_id $forums_package_id]   
+    }
+
     #revoke read permissions until first usage
     if {[info exist acs_object_id]} {
         permission::set_not_inherit -object_id $acs_object_id
+
         set party_id [db_list get_allowed_parties {}]
         foreach parti $party_id {
             permission::revoke -party_id $parti -object_id $acs_object_id -privilege "read"
@@ -1748,7 +1755,16 @@
                             -parent_id $parent_id]
         
         if { [string eq $conference_type "asynchronous"] } {
+
+        set moderator_list [$conference selectNodes "*\[local-name()='moderator'\]"]
+        if { [llength $moderator_list] } {
+            set acs_object_id [imsld::parse::parse_and_create_forum -name $title -is_moderated]            
+        
+        } else {
             set acs_object_id [imsld::parse::parse_and_create_forum -name $title]            
+        }
+            
+
             set resource_id [imsld::cp::resource_new -manifest_id $manifest_id \
                                  -identifier "forumresource-$service_id" \
                                  -type "forum" \
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.91 -r1.92
--- openacs-4/packages/imsld/tcl/imsld-procs.tcl	19 Dec 2006 10:36:07 -0000	1.91
+++ openacs-4/packages/imsld/tcl/imsld-procs.tcl	21 Dec 2006 12:08:36 -0000	1.92
@@ -3553,6 +3553,13 @@
                                  from imsld_cp_resourcesi 
                                  where item_id=:resource_item_id
                                  }
+#first, revoke all permissions
+        permission::revoke -party_id $user_id -object_id $forum_id  -privilege "write"
+        permission::revoke -party_id $user_id -object_id $forum_id  -privilege "create"
+        permission::revoke -party_id $user_id -object_id $forum_id  -privilege "admin"
+        permission::revoke -party_id $user_id -object_id $forum_id  -privilege "forum_moderate"
+
+
     #get the user active role
     db_1row get_active_role {
                             select iruns.active_role_id as active_role
@@ -3565,34 +3572,45 @@
                                   and ar.rel_type='imsld_run_users_group_rel' 
                                   and ar.rel_id=iruns.rel_id
     }
-    
+
 #get the permissions related to that role
-    if {[db_0or1row is_manager {select ics.manager_id 
+    set manager_in_forum 0
+    if {[db_0or1row is_manager {select iri.role_id as manager_role_id
                                 from imsld_conference_services ics,
-                                     acs_rels ar
+                                     acs_rels ar,
+                                     imsld_rolesi iri
                                 where ar.rel_type='imsld_item_res_rel'
                                       and ar.object_id_two=:resource_item_id
                                       and ics.imsld_item_id=ar.object_id_one
-                                      and ics.manager_id=:active_role}]
+                                      and iri.item_id=ics.manager_id
+                                      }]
     } {
-        permission::grant -party_id $user_id -object_id $forum_id  -privilege "read"
-        permission::grant -party_id $user_id -object_id $forum_id  -privilege "create"
-        permission::grant -party_id $user_id -object_id $forum_id  -privilege "admin"
+        set manager_in_forum 1
+        if {[string equal $manager_role_id $active_role ]} {
+            permission::grant -party_id $user_id -object_id $forum_id  -privilege "admin"
+        }
     }
 
 #moderator
     if {[db_0or1row is_moderator {select ics.moderator_id 
                                 from imsld_conference_services ics, 
-                                     acs_rels ar
+                                     acs_rels ar,
+                                     imsld_rolesi iri
                                 where ics.imsld_item_id=ar.object_id_one
                                       and ar.rel_type='imsld_item_res_rel'
                                       and ar.object_id_two=:resource_item_id
-                                      and ics.moderator_id=:active_role}]
+                                      and iri.item_id=ics.moderator_id
+                                      and iri.role_id=:active_role}]
     } {
+        if {[string equal $manager_in_forum "0"]} {
+             permission::grant -party_id $user_id -object_id $forum_id  -privilege "write" 
+             set manager_in_forum 1
+        }
+
         permission::grant -party_id $user_id -object_id $forum_id  -privilege "read"
-        permission::grant -party_id $user_id -object_id $forum_id  -privilege "create"
-        permission::grant -party_id $user_id -object_id $forum_id  -privilege "admin"
-        permission::grant -party_id $user_id -object_id $forum_id  -privilege "forum_moderate"
+        db_foreach get_existing_messages { select message_id from forums_messages where forum_id=:forum_id } {
+            permission::grant -party_id $user_id -object_id $message_id -privilege "forum_moderate"
+        }
 
     }
 
@@ -3612,6 +3630,14 @@
     } {
         permission::grant -party_id $user_id -object_id $forum_id  -privilege "read"
         permission::grant -party_id $user_id -object_id $forum_id  -privilege "create"
+        if {[string equal $manager_in_forum "0"]} {
+             permission::grant -party_id $user_id -object_id $forum_id  -privilege "admin" 
+             set manager_in_forum 1
+        }
+
+        db_foreach get_existing_messages { select message_id from forums_messages where forum_id=:forum_id } {
+            permission::grant -party_id $user_id -object_id $message_id -privilege "write"
+        }
     }