--- loncom/interface/lonuserutils.pm	2009/09/12 17:06:16	1.100
+++ loncom/interface/lonuserutils.pm	2009/11/04 15:35:56	1.103
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.100 2009/09/12 17:06:16 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.103 2009/11/04 15:35:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -91,7 +91,7 @@ sub modifyuserrole {
     if ($setting eq 'course' || $context eq 'course') {
         $scope = '/'.$cid;
         $scope =~ s/\_/\//g;
-        if ($role ne 'cc' && $sec ne '') {
+        if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
             $scope .='/'.$sec;
         }
     } elsif ($context eq 'domain') {
@@ -235,7 +235,7 @@ sub domain_roles_select {
     # domain context   
     #
     # Role types
-    my @roletypes = ('domain','author','course');
+    my @roletypes = ('domain','author','course','community');
     my %lt = &role_type_names();
     #
     # build up the menu information to be passed to
@@ -247,6 +247,10 @@ sub domain_roles_select {
     foreach my $roletype (@roletypes) {
         # set up the text for this domain
         $select_menus{$roletype}->{'text'}= $lt{$roletype};
+        my $crstype;
+        if ($roletype eq 'community') {
+            $crstype = 'Community';
+        }
         # we want a choice of 'default' as the default in the second menu
         if ($env{'form.roletype'} ne '') {
             $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
@@ -261,7 +265,7 @@ sub domain_roles_select {
             @roles = &construction_space_roles();
         } else {
             my $custom = 1;
-            @roles = &course_roles('domain',undef,$custom);
+            @roles = &course_roles('domain',undef,$custom,$roletype);
         }
         my $order = ['Any',@roles];
         $select_menus{$roletype}->{'order'} = $order; 
@@ -271,14 +275,15 @@ sub domain_roles_select {
                               &mt('Custom role');
             } else {
                 $select_menus{$roletype}->{'select2'}->{$role} = 
-                              &Apache::lonnet::plaintext($role);
+                              &Apache::lonnet::plaintext($role,$crstype);
             }
         }
         $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
     }
     my $result = &Apache::loncommon::linked_select_forms
         ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
-         'roletype','showrole',\%select_menus,['domain','author','course']);
+         'roletype','showrole',\%select_menus,
+         ['domain','author','course','community']);
     return $result;
 }
 
@@ -290,7 +295,7 @@ sub hidden_input {
 }
 
 sub print_upload_manager_header {
-    my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
+    my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
     my $javascript;
     #
     if (! exists($env{'form.upfile_associate'})) {
@@ -327,7 +332,7 @@ sub print_upload_manager_header {
     my $javascript_validations =
         &javascript_validations('upload',$krbdefdom,$password_choice,undef,
                                 $env{'request.role.domain'},$context,
-                                $groupslist);
+                                $groupslist,$crstype);
     my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
     $r->print('<p>'
              .&mt('Total number of records found in file: [_1]'
@@ -360,7 +365,7 @@ sub print_upload_manager_header {
 ###############################################################
 sub javascript_validations {
     my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
-        $context,$groupslist)=@_;
+        $context,$groupslist,$crstype)=@_;
     my %param = (
                   kerb_def_dom => $krbdefdom,
                   curr_authtype => $curr_authtype,
@@ -381,10 +386,10 @@ sub javascript_validations {
         if (($context eq 'course') || ($context eq 'domain')) {
             if ($context eq 'course') {
                 if ($env{'request.course.sec'} eq '') {
-                    $setsection_call = 'setSections(document.'.$param{'formname'}.');';
+                    $setsection_call = 'setSections(document.'.$param{'formname'}."'$crstype'".');';
                     $setsections_js =
                         &setsections_javascript($param{'formname'},$groupslist,
-                                                $mode);
+                                                $mode,'',$crstype);
                 } else {
                     $setsection_call = "'ok'";
                 }
@@ -743,7 +748,7 @@ ENDPICK
 ###############################################################
 ###############################################################
 sub print_upload_manager_footer {
-    my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission) = @_;
+    my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype) = @_;
     my $form = 'document.studentform';
     my $formname = 'studentform';
     my ($krbdef,$krbdefdom) =
@@ -761,7 +766,7 @@ sub print_upload_manager_footer {
     my $intform = &Apache::loncommon::authform_internal(%param);
     my $locform = &Apache::loncommon::authform_local(%param);
     my $date_table = &date_setting_table(undef,undef,$context,undef,
-                                         $formname,$permission);
+                                         $formname,$permission,$crstype);
 
     my $Str = "\n".'<div class="LC_left_float">';
     $Str .= &hidden_input('nfields',$i);
@@ -825,7 +830,7 @@ sub print_upload_manager_footer {
                .'&nbsp;'.&mt('Add a domain role').'</label>'
                .'&nbsp;&nbsp;&nbsp;<label>'
                .'<input type="radio" name="roleaction" value="course" />'
-               .'&nbsp;'.&mt('Add a course role').'</label>'
+               .'&nbsp;'.&mt('Add a course/community role').'</label>'
                .'</span>';
     } elsif ($context eq 'author') {
         $Str .= &Apache::lonhtmlcommon::row_title(
@@ -860,15 +865,26 @@ sub print_upload_manager_footer {
         my ($cnum,$cdom) = &get_course_identity();
         my $rowtitle = &mt('section');
         my $secbox = &section_picker($cdom,$cnum,'Any',$rowtitle,
-                                     $permission,$context,'upload');
+                                     $permission,$context,'upload',$crstype);
         $Str .= $secbox
                .&Apache::lonhtmlcommon::row_closure();
-
+        my %lt;
+        if ($crstype eq 'Community') {
+            %lt = &Apache::lonlocal::texthash (
+                    disp => 'Display members with current/future access who are not in the uploaded file',
+                    stus => 'Members selected from this list can be dropped.'
+            );
+        } else {
+            %lt = &Apache::lonlocal::texthash (
+                    disp => 'Display students with current/future access who are not in the uploaded file',
+                    stus => 'Students selected from this list can be dropped.'
+            );
+        }
         $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
-               .'<label><input type="checkbox" name="fullup" value="yes" />'.
-                ' '.&mt('Display students with current/future access who are not in the uploaded file.')
+               .'<label><input type="checkbox" name="fullup" value="yes" />'
+               .' '.$lt{'disp'}
                .'</label><br />'
-               .&mt('Students selected from this list can be dropped.')
+               .$lt{'stus'}
                .&Apache::lonhtmlcommon::row_closure();
     }
     if ($context eq 'course' || $context eq 'domain') {
@@ -883,7 +899,7 @@ sub print_upload_manager_footer {
            .'<hr />';
     if ($context eq 'course') {
         $Str .= '<p class="LC_info">'
-               .&mt('Note: For large courses, this operation may be time consuming.')
+               .&mt('Note: This operation may be time consuming when adding several users.')
                .'</p>';
     }
     $Str .= '<p><input type="button"'
@@ -916,7 +932,7 @@ sub forceid_change {
 ###############################################################
 ###############################################################
 sub print_upload_manager_form {
-    my ($r,$context,$permission) = @_;
+    my ($r,$context,$permission,$crstype) = @_;
     my $firstLine;
     my $datatoken;
     if (!$env{'form.datatoken'}) {
@@ -963,7 +979,7 @@ sub print_upload_manager_form {
         &Apache::loncommon::get_kerberos_defaults($defdom);
     #
     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
-                                 $permission);
+                                 $permission,$crstype);
     my $i;
     my $keyfields;
     if ($total>=0) {
@@ -999,7 +1015,7 @@ sub print_upload_manager_form {
     }
     $r->print('</div>');
     &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
-                                 $context,$permission);
+                                 $context,$permission,$crstype);
 }
 
 sub setup_date_selectors {
@@ -1073,7 +1089,7 @@ sub get_dates_from_form {
 }
 
 sub date_setting_table {
-    my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_;
+    my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
     my $nolink;
     if ($bulkaction) {
         $nolink = 1;
@@ -1090,9 +1106,13 @@ sub date_setting_table {
             ($env{'form.action'} eq 'upload')) {
             if ($env{'request.course.sec'} eq '') {
                 $dateDefault = '<span class="LC_nobreak">'.
-                    '<label><input type="checkbox" name="makedatesdefault" value="1" /> '.
-                    &mt('make these dates the default access dates for future student enrollment').
-                    '</label></span>';
+                    '<label><input type="checkbox" name="makedatesdefault" value="1" /> ';
+                if ($crstype eq 'Community') {
+                    $dateDefault .= &mt("make these dates the default access dates for future community enrollment");
+                } else {
+                    $dateDefault .= &mt("make these dates the default access dates for future course enrollment");
+                }
+                $dateDefault .= '</label></span>';
             }
         }
     }
@@ -1121,7 +1141,7 @@ sub date_setting_table {
 }
 
 sub make_dates_default {
-    my ($startdate,$enddate,$context) = @_;
+    my ($startdate,$enddate,$context,$crstype) = @_;
     my $result = '';
     if ($context eq 'course') {
         my ($cnum,$cdom) = &get_course_identity();
@@ -1129,22 +1149,30 @@ sub make_dates_default {
                 {'default_enrollment_start_date'=>$startdate,
                  'default_enrollment_end_date'  =>$enddate},$cdom,$cnum);
         if ($put_result eq 'ok') {
-            $result .= &mt('Set default start and end access dates for course.').
-                       '<br />'."\n";
+            if ($crstype eq 'Community') {
+                $result .= &mt('Set default start and end access dates for community.');
+            } else {
+                $result .= &mt('Set default start and end access dates for course.');
+            }
+            $result .= '<br />'."\n";
             #
             # Refresh the course environment
             &Apache::lonnet::coursedescription($env{'request.course.id'},
                                                {'freshen_cache' => 1});
         } else {
-            $result .= &mt('Unable to set default access dates for course.').":".$put_result.
-                       '<br />';
+            if ($crstype eq 'Community') {
+                $result .= &mt('Unable to set default access dates for community');
+            } else {
+                $result .= &mt('Unable to set default access dates for course');
+            }
+            $result .= ':'.$put_result.'<br />';
         }
     }
     return $result;
 }
 
 sub default_role_selector {
-    my ($context,$checkpriv) = @_;
+    my ($context,$checkpriv,$crstype) = @_;
     my %customroles;
     my ($options,$coursepick,$cb_jscript);
     if ($context ne 'author') {
@@ -1160,7 +1188,7 @@ sub default_role_selector {
     $options = '<select name="defaultrole">'."\n".
                ' <option value="">'.&mt('Please select').'</option>'."\n"; 
     if ($context eq 'course') {
-        $options .= &default_course_roles($context,$checkpriv,%customroles);
+        $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
     } elsif ($context eq 'author') {
         my @roles = &construction_space_roles($checkpriv);
         foreach my $role (@roles) {
@@ -1174,18 +1202,18 @@ sub default_role_selector {
            $options .= '  <option value="'.$role.'">'.$plrole.'</option>';
         }
         my $courseform = &Apache::loncommon::selectcourse_link
-            ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
+            ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
         $cb_jscript = 
-            &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
+            &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community');
         $coursepick = &Apache::loncommon::start_data_table().
                       &Apache::loncommon::start_data_table_header_row().
                       '<th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th>'.
                       '<th>'.$lt{'grs'}.'</th>'.
                       &Apache::loncommon::end_data_table_header_row().
                       &Apache::loncommon::start_data_table_row()."\n".
-                      '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
+                      '<td><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'studentform','dccourse','dcdomain','coursedesc','','','','crstype'".')" /></td>'."\n".
                       '<td><select name="courserole">'."\n".
-                      &default_course_roles($context,$checkpriv,%customroles)."\n".
+                      &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
                       '</select></td><td>'.
                       '<table class="LC_createuser">'.
                       '<tr class="LC_section_row"><td valign"top">'.
@@ -1201,6 +1229,7 @@ sub default_role_selector {
                       $env{'request.role.domain'}.'" />'.
                       '<input type="hidden" name="dccourse" value="" />'.
                       '<input type="hidden" name="dcdomain" value="" />'.
+                      '<input type="hidden" name="crstype" value="" />'.
                       '</td></tr></table></td>'.
                       &Apache::loncommon::end_data_table_row().
                       &Apache::loncommon::end_data_table()."\n";
@@ -1210,13 +1239,13 @@ sub default_role_selector {
 }
 
 sub default_course_roles {
-    my ($context,$checkpriv,%customroles) = @_;
+    my ($context,$checkpriv,$crstype,%customroles) = @_;
     my $output;
     my $custom = 1;
-    my @roles = &course_roles($context,$checkpriv,$custom);
+    my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
     foreach my $role (@roles) {
         if ($role ne 'cr') {
-            my $plrole=&Apache::lonnet::plaintext($role);
+            my $plrole=&Apache::lonnet::plaintext($role,$crstype);
             $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
         }
     }
@@ -1265,8 +1294,14 @@ sub domain_roles {
 }
 
 sub course_roles {
-    my ($context,$checkpriv,$custom) = @_;
-    my @allroles = &roles_by_context('course',$custom);
+    my ($context,$checkpriv,$custom,$roletype) = @_;
+    my $crstype;
+    if ($roletype eq 'community') {
+        $crstype = 'Community' ;
+    } else {
+        $crstype = 'Course';
+    }
+    my @allroles = &roles_by_context('course',$custom,$crstype);
     my @roles;
     if ($context eq 'domain') {
         @roles = @allroles;
@@ -1277,7 +1312,7 @@ sub course_roles {
                     if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
                         push(@roles,$role);
                     } else {
-                        if ($role ne 'cc' && $env{'request.course.sec'} ne '') {
+                        if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
                             if (&Apache::lonnet::allowed('c'.$role,
                                              $env{'request.course.id'}.'/'.
                                              $env{'request.course.sec'})) {
@@ -1295,19 +1330,19 @@ sub course_roles {
 }
 
 sub curr_role_permissions {
-    my ($context,$setting,$checkpriv) = @_; 
+    my ($context,$setting,$checkpriv,$type) = @_; 
     my $custom = 1;
     my @roles;
     if ($context eq 'author') {
         @roles = &construction_space_roles($checkpriv);
     } elsif ($context eq 'domain') {
         if ($setting eq 'course') {
-            @roles = &course_roles($context,$checkpriv,$custom); 
+            @roles = &course_roles($context,$checkpriv,$custom,$type); 
         } else {
             @roles = &domain_roles($checkpriv);
         }
     } elsif ($context eq 'course') {
-        @roles = &course_roles($context,$checkpriv,$custom);
+        @roles = &course_roles($context,$checkpriv,$custom,$type);
     }
     return @roles;
 }
@@ -1413,19 +1448,32 @@ sub print_userlist {
     }
     my ($indexhash,$keylist) = &make_keylist_array();
     my (%userlist,%userinfo);
-    if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+    if (($context eq 'domain') && 
+        ($env{'form.roletype'} eq 'course') || 
+        ($env{'form.roletype'} eq 'community')) {
+        my ($crstype,$numcodes,$title,$warning);
+        if ($env{'form.roletype'} eq 'course') {
+            $crstype = 'Course';
+            $numcodes = $totcodes;
+            $title = &mt('Select Courses');
+            $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
+        } elsif ($env{'form.roletype'} eq 'community') {
+            $crstype = 'Community';
+            $numcodes = 0;
+            $title = &mt('Select Communities');
+            $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
+        }
         my $courseform =
-            &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
-                                         $codetitles,$idlist,$idlist_titles);
+            &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
+                            $codetitles,$idlist,$idlist_titles,$crstype);
         $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
                   &Apache::lonhtmlcommon::start_pick_box()."\n".
-                  &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),
-                                                    'LC_oddrow_value')."\n".
+                  &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".
                   $courseform."\n".
                   &Apache::lonhtmlcommon::row_closure(1).
                   &Apache::lonhtmlcommon::end_pick_box().'</p>'.
                   '<p>'.&list_submit_button(&mt('Update Display')).
-                  "\n".'</p><span class="LC_warning">'.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').'</span>'."\n");
+                  "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
         if ($env{'form.coursepick'}) {
             $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');
         }
@@ -1499,7 +1547,8 @@ sub print_userlist {
                         }
                     }
                 }
-            } elsif ($env{'form.roletype'} eq 'course') {
+            } elsif (($env{'form.roletype'} eq 'course') ||
+                     ($env{'form.roletype'} eq 'community')) {
                 if ($env{'form.coursepick'}) {
                     my %courses = &process_coursepick();
                     my %allusers;
@@ -1511,7 +1560,8 @@ sub print_userlist {
                         my (@roles,@sections,%access,%users,%userdata,
                             %statushash);
                         if ($env{'form.showrole'} eq 'Any') {
-                            @roles = &course_roles($context,undef,$custom);
+                            @roles = &course_roles($context,undef,$custom,
+                                                   $env{'form.roletype'});
                         } else {
                             @roles = ($env{'form.showrole'});
                         }
@@ -1557,6 +1607,8 @@ sub print_userlist {
                 $r->print(&mt('There are no authors or co-authors to display.')."\n");
             } elsif ($env{'form.roletype'} eq 'course') {
                 $r->print(&mt('There are no course users to display')."\n"); 
+            } elsif ($env{'form.roletype'} eq 'community') {
+                $r->print(&mt('There are no community users to display')."\n");
             }
         } elsif ($context eq 'course') {
             $r->print(&mt('There are no course users to display.')."\n");
@@ -1599,7 +1651,16 @@ sub role_filter {
         $role_select = '<select name="showrole">'."\n".
                        '<option value="Any" '.$roleselected.'>'.
                        &mt('Any role').'</option>';
-        my @poss_roles = &curr_role_permissions($context);
+        my ($roletype,$crstype);
+        if ($context eq 'course') {
+            $crstype = &Apache::loncommon::course_type();
+            if ($crstype eq 'Community') {
+                $roletype = 'community';
+            } else {
+                $roletype = 'course';
+            } 
+        }
+        my @poss_roles = &curr_role_permissions($context,'','',$roletype);
         foreach my $role (@poss_roles) {
             $roleselected = '';
             if ($role eq $env{'form.showrole'}) {
@@ -1609,7 +1670,7 @@ sub role_filter {
             if ($role eq 'cr') {
                 $plrole = &mt('Custom role');
             } else {
-                $plrole=&Apache::lonnet::plaintext($role);
+                $plrole=&Apache::lonnet::plaintext($role,$crstype);
             }
             $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
         }
@@ -1645,7 +1706,7 @@ sub section_group_filter {
             $env{'form.'.$name{$item}} = 'all';
         }
         if ($item eq 'sec') {
-            if ($env{'form.showrole'} eq 'cc') {
+            if (($env{'form.showrole'} eq 'cc') || ($env{'form.showrole'} eq 'co')) {
                 $env{'form.'.$name{$item}} = 'none';
             }
             my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
@@ -1724,7 +1785,8 @@ sub gather_userinfo {
                                            $indexhash,$uniqid,$userlist);
                     }
                 }
-            } elsif ($env{'form.roletype'} eq 'course') {
+            } elsif (($env{'form.roletype'} eq 'course') || 
+                     ($env{'form.roletype'} eq 'community')) {
                 ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
                     split(/:/,$item);
                 if (ref($rolehash->{$item}) eq 'HASH') {
@@ -1774,7 +1836,8 @@ sub gather_userinfo {
 sub build_user_record {
     my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
     next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
-    if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
+    if (!(($context eq 'domain') && (($env{'form.roletype'} eq 'course')
+                             && ($env{'form.roletype'} eq 'community')))) {
         &process_date_info($userdata);
     }
     my $username = $userdata->{'username'};
@@ -2039,9 +2102,10 @@ sub show_users_list {
         $sortby = 'username';
     }
     my $setting = $env{'form.roletype'};
-    my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
+    my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers,$crstype);
     if ($context eq 'course') {
         $cid = $env{'request.course.id'};
+        $crstype = &Apache::loncommon::course_type();
         ($cnum,$cdom) = &get_course_identity($cid);
         ($classgroups) = &Apache::loncoursedata::get_group_memberships(
                                      $userlist,$keylist,$cdom,$cnum);
@@ -2076,6 +2140,12 @@ function photowindow(photolink) {
 <input type="hidden" name="displayclickers" value="$displayclickers" />
 END
         }
+    } elsif ($context eq 'domain') {
+        if ($setting eq 'community') {
+            $crstype = 'Community';
+        } elsif ($crstype eq 'course') {
+            $crstype = 'Course';
+        }
     }
     if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
         my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
@@ -2172,6 +2242,8 @@ END
                       );
     if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
         $lt{'extent'} = &mt('Course(s): description, section(s), status');
+    } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
+        $lt{'extent'} = &mt('Communities: description, section(s), status');
     } elsif ($context eq 'author') {
         $lt{'extent'} = &mt('Author'); 
     }
@@ -2183,18 +2255,21 @@ END
         if ($context eq 'course') {
             push(@cols,'section');
         }
-        if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) { 
+        if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')
+                              && ($env{'form.roletype'} eq 'community'))) { 
             push(@cols,('start','end'));
         }
         if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
             push(@cols,'role');
         }
         if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
-                                    $env{'form.roletype'} eq 'course')) {
+                                    $env{'form.roletype'} eq 'course' ||
+                                    $env{'form.roletype'} eq 'community')) {
             push (@cols,'extent');
         }
         if (($statusmode eq 'Any') && 
-            (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
+            (!($context eq 'domain' && (($env{'form.roletype'} eq 'course')
+             || ($env{'form.roletype'} eq 'community'))))) {
             push(@cols,'status');
         }
         if ($context eq 'course') {
@@ -2207,12 +2282,12 @@ END
     if ($env{'form.showrole'} eq 'cr') {
         $rolefilter = &mt('custom');  
     } elsif ($env{'form.showrole'} ne 'Any') {
-        $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
+        $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'},$crstype);
     }
     my $results_description;
     if ($mode ne 'autoenroll') {
         $results_description = &results_header_row($rolefilter,$statusmode,
-                                                   $context,$permission,$mode);
+                                                   $context,$permission,$mode,$crstype);
         $r->print('<b>'.$results_description.'</b><br /><br />');
     }
     my ($output,$actionselect,%canchange,%canchangesec);
@@ -2239,9 +2314,9 @@ END
                 if ($env{'form.showrole'} eq 'Any') {
                     my $custom = 1;
                     if ($context eq 'domain') {
-                        @allroles = &roles_by_context($setting,$custom);
+                        @allroles = &roles_by_context($setting,$custom,$crstype);
                     } else {
-                        @allroles = &roles_by_context($context,$custom);
+                        @allroles = &roles_by_context($context,$custom,$crstype);
                     }
                 } else {
                     @allroles = ($env{'form.showrole'});
@@ -2448,7 +2523,8 @@ END
                 }
             } elsif ($env{'form.roletype'} eq 'author') {
                 ($uname,$udom,$role) = split(/:/,$user,-1);
-            } elsif ($env{'form.roletype'} eq 'course') {
+            } elsif (($env{'form.roletype'} eq 'course') || 
+                     ($env{'form.roletype'} eq 'community')) {
                 ($uname,$udom,$role) = split(/:/,$user);
             }
         } else {
@@ -2555,7 +2631,7 @@ END
         if ($clickers!~/\w/) { $clickers='-'; }
         $in{'clicker'} = $clickers; 
 	my $role = $in{'role'};
-        $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]); 
+        $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
         if (! defined($in{'start'}) || $in{'start'} == 0) {
             $in{'start'} = &mt('none');
         } else {
@@ -2853,6 +2929,7 @@ sub role_type_names {
                          'domain' => 'Domain Roles',
                          'author' => 'Co-Author Roles',
                          'course' => 'Course Roles',
+                         'community' => 'Community Roles',
              );
     return %lt;
 }
@@ -2989,7 +3066,7 @@ ENDTWO
 }
 
 sub date_section_selector {
-    my ($context,$permission) = @_;
+    my ($context,$permission,$crstype) = @_;
     my $callingform = $env{'form.callingform'};
     my $formname = 'dateselect';  
     my $groupslist = &get_groupslist();
@@ -3014,7 +3091,7 @@ END
         } else {
             opener.document.$callingform.retainsec.value = formname.retainsec.value;
         }
-        setSections(formname);
+        setSections(formname,'$crstype');
         if (seccheck == 'ok') {
             opener.document.$callingform.newsecs.value = formname.sections.value;
         }
@@ -3074,7 +3151,7 @@ ENDJS
                  fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',
                  forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
                  reta => "Retain each user's current section affiliations?", 
-                 dnap => '(Does not apply to student roles).', 
+                 dnap => '(Does not apply to student roles).',
             );
     my ($date_items,$headertext);
     if ($env{'form.bulkaction'} eq 'chgsec') {
@@ -3088,13 +3165,19 @@ ENDJS
         }
         $date_items = &date_setting_table($starttime,undef,$context,
                                           $env{'form.bulkaction'},$formname,
-                                          $permission);
+                                          $permission,$crstype);
     }
     $output .= '<h3>'.$headertext.'</h3>'.
                '<form name="'.$formname.'" method="post">'."\n".
                 $date_items;
     if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
         my ($cnum,$cdom) = &get_course_identity();
+        my $crstype = &Apache::loncommon::course_type();
+        if ($crstype eq 'Community') {
+            $lt{'fors'} = &mt('For member roles changing the section, will result in a section switch as members may only be in one section of a community at a time.');
+            $lt{'forn'} = &mt('For a role in a community that is not a member role, a user may have roles in more than one section of a community at a time.');
+            $lt{'dnap'} = &mt('(Does not apply to member roles).'); 
+        }
         my $info;
         if ($env{'form.showrole'} eq 'st') {
             $output .= '<p>'.$lt{'fors'}.'</p>'; 
@@ -3120,7 +3203,7 @@ ENDJS
             $info = '<input type="hidden" name="retainsec" value="0" />'; 
         }
         my $rowtitle = &mt('New section to assign');
-        my $secbox = &section_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context);
+        my $secbox = &section_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context,'',$crstype);
         $output .= $info.$secbox;
     }
     $output .= '<p>'.
@@ -3130,13 +3213,13 @@ ENDJS
 }
 
 sub section_picker {
-    my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_;
+    my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;
     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
     my $sections_select .= &course_sections(\%sections_count,$role);
     my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
     if ($mode eq 'upload') {
         my ($options,$cb_script,$coursepick) =
-            &default_role_selector($context,1);
+            &default_role_selector($context,1,$crstype);
         $secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
                    $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
     }
@@ -3160,26 +3243,50 @@ sub section_picker {
 }
 
 sub results_header_row {
-    my ($rolefilter,$statusmode,$context,$permission,$mode) = @_;
+    my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
     my ($description,$showfilter);
     if ($rolefilter ne 'Any') {
         $showfilter = $rolefilter;
     }
     if ($context eq 'course') {
         if ($mode eq 'csv' || $mode eq 'excel') {
-            $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
+            if ($crstype eq 'Community') {
+                $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
+            } else {
+                $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
+            }
         }
         if ($statusmode eq 'Expired') {
-            $description .= &mt('Users in course with expired [_1] roles',$showfilter);
+            if ($crstype eq 'Community') {
+                $description .= &mt('Users in community with expired [_1] roles',$showfilter);
+            } else {
+                $description .= &mt('Users in course with expired [_1] roles',$showfilter);
+            }
         } elsif ($statusmode eq 'Future') {
-            $description .= &mt('Users in course with future [_1] roles',$showfilter);
+            if ($crstype eq 'Community') {
+                $description .= &mt('Users in community with future [_1] roles',$showfilter);
+            } else {
+                $description .= &mt('Users in course with future [_1] roles',$showfilter);
+            }
         } elsif ($statusmode eq 'Active') {
-            $description .= &mt('Users in course with active [_1] roles',$showfilter);
+            if ($crstype eq 'Community') {
+                $description .= &mt('Users in community with active [_1] roles',$showfilter);
+            } else {
+                $description .= &mt('Users in course with active [_1] roles',$showfilter);
+            }
         } else {
             if ($rolefilter eq 'Any') {
-                $description .= &mt('All users in course');
+                if ($crstype eq 'Community') {
+                    $description .= &mt('All users in community');
+                } else {
+                    $description .= &mt('All users in course');
+                }
             } else {
-                $description .= &mt('All users in course with [_1] roles',$rolefilter);
+                if ($crstype eq 'Community') {
+                    $description .= &mt('All users in community with [_1] roles',$rolefilter);
+                } else {
+                    $description .= &mt('All users in course with [_1] roles',$rolefilter);
+                }
             }
         }
         my $constraint;
@@ -3187,7 +3294,7 @@ sub results_header_row {
         if ($viewablesec ne '') {
             if ($env{'form.showrole'} eq 'st') {
                 $constraint = &mt('only users in section "[_1]"',$viewablesec);
-            } elsif ($env{'form.showrole'} ne 'cc') {
+            } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
                 $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
             }
             if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
@@ -3275,19 +3382,28 @@ sub results_header_row {
                     $description .= &mt('All co-authors in domain  with [_1] roles',$rolefilter);
                 }
             }
-        } elsif ($env{'form.roletype'} eq 'course') {
+        } elsif (($env{'form.roletype'} eq 'course') || 
+                 ($env{'form.roletype'} eq 'community')) {
             my $coursefilter = $env{'form.coursepick'};
-            if ($coursefilter eq 'category') {
-                my $instcode = &instcode_from_coursefilter();
-                if ($instcode eq '.') {
+            if ($env{'form.roletype'} eq 'course') {
+                if ($coursefilter eq 'category') {
+                    my $instcode = &instcode_from_coursefilter();
+                    if ($instcode eq '.') {
+                        $description .= &mt('All courses in domain').' - ';
+                    } else {
+                        $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
+                    }
+                } elsif ($coursefilter eq 'selected') {
+                    $description .= &mt('Selected courses in domain').' - ';
+                } elsif ($coursefilter eq 'all') {
                     $description .= &mt('All courses in domain').' - ';
-                } else {
-                    $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
                 }
-            } elsif ($coursefilter eq 'selected') {
-                $description .= &mt('Selected courses in domain').' - ';
-            } elsif ($coursefilter eq 'all') {
-                $description .= &mt('All courses in domain').' - ';
+            } elsif ($env{'form.roletype'} eq 'community') {
+                if ($coursefilter eq 'selected') {
+                    $description .= &mt('Selected communities in domain').' - ';
+                } elsif ($coursefilter eq 'all') {
+                    $description .= &mt('All communities in domain').' - ';
+                }
             }
             if ($statusmode eq 'Expired') {
                 $description .= &mt('users with expired [_1] roles',$showfilter);
@@ -3324,7 +3440,7 @@ sub viewable_section {
 #################################################
 #################################################
 sub show_drop_list {
-    my ($r,$classlist,$nosort,$permission) = @_;
+    my ($r,$classlist,$nosort,$permission,$crstype) = @_;
     my $cid = $env{'request.course.id'};
     my ($cnum,$cdom) = &get_course_identity($cid);
     if (! exists($env{'form.sortby'})) {
@@ -3370,7 +3486,11 @@ END
         }
     }
     if (!$studentcount) {
-        $r->print(&mt('There are no students to drop.'));
+        if ($crstype eq 'Community') {
+            $r->print(&mt('There are no members to drop.'));
+        } else {
+            $r->print(&mt('There are no students to drop.'));
+        }
         return;
     }
     my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
@@ -3378,11 +3498,16 @@ END
     my %lt=&Apache::lonlocal::texthash('usrn'   => "username",
                                        'dom'    => "domain",
                                        'sn'     => "student name",
+                                       'mn'     => "member name",
                                        'sec'    => "section",
                                        'start'  => "start date",
                                        'end'    => "end date",
                                        'groups' => "active groups",
                                       );
+    my $nametitle = $lt{'sn'};
+    if ($crstype eq 'Community') {
+        $nametitle = $lt{'mn'};
+    }
     if ($nosort) {
         $r->print(&Apache::loncommon::start_data_table().
                   &Apache::loncommon::start_data_table_header_row());
@@ -3391,7 +3516,7 @@ END
     <th>$lt{'usrn'}</th>
     <th>$lt{'dom'}</th>
     <th>ID</th>
-    <th>$lt{'sn'}</th>
+    <th>$nametitle</th>
     <th>$lt{'sec'}</th>
     <th>$lt{'start'}</th>
     <th>$lt{'end'}</th>
@@ -3410,7 +3535,7 @@ END
     </th><th>
        <a href="/adm/createuser?action=$action&sortby=id">ID</a>
     </th><th>
-       <a href="/adm/createuser?action=$action&sortby=fullname">$lt{'sn'}</a>
+       <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>
     </th><th>
        <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
     </th><th>
@@ -3480,9 +3605,14 @@ END
     $r->print(&Apache::loncommon::end_data_table().'<br />');
     %lt=&Apache::lonlocal::texthash(
                        'dp'   => "Drop Students",
+                       'dm'   => "Drop Members",
                        'ca'   => "check all",
                        'ua'   => "uncheck all",
                                        );
+    my $btn = $lt{'dp'};
+    if ($crstype eq 'Community') {
+        $btn = $lt{'dm'}; 
+    }
     $r->print(<<"END");
 </p>
 <p>
@@ -3490,7 +3620,7 @@ END
 <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
 </p>
 <p>
-<input type="submit" value="$lt{'dp'}" />
+<input type="submit" value="$btn" />
 </p>
 END
     return;
@@ -3504,7 +3634,7 @@ sub print_first_users_upload_form {
     my $str;
     $str  = '<input type="hidden" name="phase" value="two" />';
     $str .= '<input type="hidden" name="action" value="upload" />';
-    $str .= '<input type="hidden"   name="state"  value="got_file" />';
+    $str .= '<input type="hidden" name="state"  value="got_file" />';
 
     $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
 
@@ -3518,11 +3648,15 @@ sub print_first_users_upload_form {
            ."</p>\n";
 
     $str .= &Apache::lonhtmlcommon::start_pick_box()
-           .&Apache::lonhtmlcommon::row_title(&mt('File'))
-           .'<p class="LC_info">'."\n"
-           .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
-           .'</p>'."\n"
-           .&Apache::loncommon::upfile_select_html()
+           .&Apache::lonhtmlcommon::row_title(&mt('File'));
+    if (&Apache::lonlocal::current_language() ne 'en') {
+        if ($context eq 'course') { 
+            $str .= '<p class="LC_info">'."\n"
+                   .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
+                   .'</p>'."\n";
+        }
+    }
+    $str .= &Apache::loncommon::upfile_select_html()
            .&Apache::lonhtmlcommon::row_closure()
            .&Apache::lonhtmlcommon::row_title(
                 '<label for="noFirstLine">'
@@ -3584,9 +3718,22 @@ sub upfile_drop_add {
                                                 'domain_choice' => 'scalar',
                                                 'inststatus_choice' => 'scalar'});
     #
+    my ($cid,$crstype,$setting);
+    if ($context eq 'domain') {
+        $setting = $env{'form.roleaction'};
+    }
+    if ($env{'request.course.id'} ne '') {
+        $cid = $env{'request.course.id'};
+        $crstype = &Apache::loncommon::course_type();
+    } elsif ($setting eq 'course') {
+        if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
+            $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
+            $crstype = &Apache::loncommon::course_type($cid);
+        }
+    }
     my ($startdate,$enddate) = &get_dates_from_form();
     if ($env{'form.makedatesdefault'}) {
-        $r->print(&make_dates_default($startdate,$enddate,$context));
+        $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
     }
     # Determine domain and desired host (home server)
     my $defdom=$env{'request.role.domain'};
@@ -3638,9 +3785,8 @@ sub upfile_drop_add {
             $amode = ''; # This causes the loop below to be skipped
         }
     }
-    my ($cid,$defaultsec,$defaultrole,$setting);
+    my ($defaultsec,$defaultrole);
     if ($context eq 'domain') {
-        $setting = $env{'form.roleaction'};
         if ($setting eq 'domain') {
             $defaultrole = $env{'form.defaultrole'};
         } elsif ($setting eq 'course') {
@@ -3653,13 +3799,6 @@ sub upfile_drop_add {
         $defaultrole = $env{'form.defaultrole'};
         $defaultsec = $env{'form.sections'};
     }
-    if ($env{'request.course.id'} ne '') {
-        $cid = $env{'request.course.id'};
-    } elsif ($setting eq 'course') {
-        if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
-            $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
-        }
-    }
     # Check to see if user information can be changed
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
@@ -3672,10 +3811,10 @@ sub upfile_drop_add {
     }
     my (%userlist,%modifiable_fields,@poss_roles);
     my $secidx = &Apache::loncoursedata::CL_SECTION();
-    my @courseroles = &roles_by_context('course',1);
+    my @courseroles = &roles_by_context('course',1,$crstype);
     if (!&Apache::lonnet::allowed('mau',$domain)) {
         if ($context eq 'course' || $context eq 'author') {
-            @poss_roles =  &curr_role_permissions($context);
+            @poss_roles =  &curr_role_permissions($context,'','',$crstype);
             my @statuses = ('active','future');
             my ($indexhash,$keylist) = &make_keylist_array();
             my %info;
@@ -3762,7 +3901,8 @@ sub upfile_drop_add {
         }
         my (%curr_rules,%got_rules,%alerts);
         my %customroles = &my_custom_roles();
-        my @permitted_roles = &roles_on_upload($context,$setting,%customroles); 
+        my @permitted_roles = 
+            &roles_on_upload($context,$setting,$crstype,%customroles); 
         # Get new users list
         foreach my $line (@userdata) {
             my @secs;
@@ -4004,7 +4144,7 @@ sub upfile_drop_add {
                                         $role = 'cr_'.$env{'user.domain'}.'_'.
                                                 $env{'user.name'}.'_'.$role;
                                     }
-                                    if ($role ne 'cc') { 
+                                    if (($role ne 'cc') && ($role ne 'co')) { 
                                         if (@secs > 1) {
                                             $multiple = 1;
                                             foreach my $sec (@secs) {
@@ -4205,14 +4345,24 @@ sub user_change_result {
 
 # ========================================================= Menu Phase Two Drop
 sub print_drop_menu {
-    my ($r,$context,$permission) = @_;
-    $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
+    my ($r,$context,$permission,$crstype) = @_;
+    my $heading;
+    if ($crstype eq 'Community') {
+        $heading = &mt("Drop Members");
+    } else {
+        $heading = &mt("Drop Students");
+    }
+    $r->print('<h3>'.$heading.'</h3>'."\n".
               '<form name="studentform" method="post">'."\n");
     my $classlist = &Apache::loncoursedata::get_classlist();
     if (! defined($classlist)) {
-        $r->print(&mt('There are no students currently enrolled.')."\n");
+        if ($crstype eq 'Community') {
+            $r->print(&mt('There are no members currently enrolled.')."\n");
+        } else {
+            $r->print(&mt('There are no students currently enrolled.')."\n");
+        }
     } else {
-        &show_drop_list($r,$classlist,'nosort',$permission);
+        &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
     }
     $r->print('</form>'. &Apache::loncommon::end_page());
     return;
@@ -4224,6 +4374,10 @@ sub update_user_list {
     my ($r,$context,$setting,$choice) = @_;
     my $now = time;
     my $count=0;
+    my $crstype;
+    if ($context eq 'course') {
+        $crstype = &Apache::loncommon::course_type();
+    }
     my @changelist;
     if ($choice eq 'drop') {
         @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
@@ -4294,7 +4448,7 @@ sub update_user_list {
                 }
             }
         }
-        my $plrole = &Apache::lonnet::plaintext($role);
+        my $plrole = &Apache::lonnet::plaintext($role,$crstype);
         my $start = $env{'form.'.$item.'_start'};
         my $end = $env{'form.'.$item.'_end'};
         if ($choice eq 'drop') {
@@ -4351,7 +4505,7 @@ sub update_user_list {
                 }
             } elsif ($choice eq 'chgsec') {
                 my (@newsecs,$revresult,$nochg,@retained);
-                if ($role ne 'cc') {
+                if (($role ne 'cc') && ($role ne 'co')) {
                     @newsecs = split(/,/,$env{'form.newsecs'});
                 }
                 # remove existing section if not to be retained.   
@@ -4459,7 +4613,7 @@ sub update_user_list {
     }
     if ($env{'form.makedatesdefault'}) {
         if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
-            $r->print(&make_dates_default($startdate,$enddate,$context));
+            $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
         }
     }
     my $linktext = &mt('Display User Lists');
@@ -4606,7 +4760,7 @@ sub get_groupslist {
 }
 
 sub setsections_javascript {
-    my ($formname,$groupslist,$mode,$checkauth) = @_;
+    my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
     my ($checkincluded,$finish,$rolecode,$setsection_js);
     if ($mode eq 'upload') {
         $checkincluded = 'formname.name == "'.$formname.'"';
@@ -4645,8 +4799,11 @@ sub setsections_javascript {
     }
     my %alerts = &Apache::lonlocal::texthash(
                     secd => 'Section designations do not apply to Course Coordinator roles.',
+                    sedn => 'Section designations do not apply to Coordinator roles.',
                     accr => 'A course coordinator role will be added with access to all sections.',
+                    acor => 'A coordinator role will be added with access to all sections',
                     inea => 'In each course, each user may only have one student role at a time.',
+                    inec => 'In each community, each user may only have on member role at a time.',
                     youh => 'You had selected ',
                     secs => 'sections.',
                     plmo => 'Please modify your selections so they include no more than one section.',
@@ -4657,7 +4814,7 @@ sub setsections_javascript {
                  );                
     $setsection_js .= <<"ENDSECCODE";
 
-function setSections(formname) {
+function setSections(formname,crstype) {
     var re1 = /^currsec_/;
     var groups = new Array($groupslist);
     for (var i=0;i<formname.elements.length;i++) {
@@ -4666,10 +4823,13 @@ function setSections(formname) {
         if (checkcurr != null) {
             if ($checkincluded) {
                 $rolecode
-                if (role == 'cc') {
-                    alert("$alerts{'secd'}\\n$alerts{'accr'}");
-                }
-                else {
+                if (role == 'cc' || role == 'co') {
+                    if (role == 'cc') {
+                        alert("$alerts{'secd'}\\n$alerts{'accr'}");
+                    } else {
+                        alert("$alerts{'sedn'}\\n$alerts{'acor'}");
+                    }
+                } else {
                     var sections = '';
                     var numsec = 0;
                     var sections;
@@ -4705,7 +4865,11 @@ function setSections(formname) {
                     }
 
                     if ((role == 'st') && (numsec > 1)) {
-                        alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
+                        if (crstype == 'Community') {
+                            alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+                        } else {
+                            alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+                        }
                         return;
                     }
                     else {
@@ -4843,14 +5007,19 @@ sub check_usertype {
 }
 
 sub roles_by_context {
-    my ($context,$custom) = @_;
+    my ($context,$custom,$crstype) = @_;
     my @allroles;
     if ($context eq 'course') {
         @allroles = ('st');
         if ($env{'request.role'} =~ m{^dc\./}) {
             push(@allroles,'ad');
         }
-        push(@allroles,('ta','ep','in','cc'));
+        push(@allroles,('ta','ep','in'));
+        if ($crstype eq 'Community') {
+            push(@allroles,'co');
+        } else {
+            push(@allroles,'cc');
+        }
         if ($custom) {
             push(@allroles,'cr');
         }
@@ -4863,11 +5032,11 @@ sub roles_by_context {
 }
 
 sub get_permission {
-    my ($context,$roles) = @_;
+    my ($context,$crstype) = @_;
     my %permission;
     if ($context eq 'course') {
         my $custom = 1;
-        my @allroles = &roles_by_context($context,$custom);
+        my @allroles = &roles_by_context($context,$custom,$crstype);
         foreach my $role (@allroles) {
             if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
                 $permission{'cusr'} = 1;
@@ -4936,9 +5105,9 @@ sub authorpriv {
 }
 
 sub roles_on_upload {
-    my ($context,$setting,%customroles) = @_;
+    my ($context,$setting,$crstype,%customroles) = @_;
     my (@possible_roles,@permitted_roles);
-    @possible_roles = &curr_role_permissions($context,$setting,1);
+    @possible_roles = &curr_role_permissions($context,$setting,1,$crstype);
     foreach my $role (@possible_roles) {
         if ($role eq 'cr') {
             push(@permitted_roles,keys(%customroles));
@@ -4974,6 +5143,7 @@ sub dc_setcourse_js {
     my ($formname,$mode,$context) = @_;
     my ($dc_setcourse_code,$authen_check);
     my $cctext = &Apache::lonnet::plaintext('cc');
+    my $cotext = &Apache::lonnet::plaintext('co');
     my %alerts = &sectioncheck_alerts();
     my $role = 'role';
     if ($mode eq 'upload') {
@@ -5020,7 +5190,11 @@ function setCourse() {
             numsections = numsections + newsecs.length;
         }
         if ((userrole == 'st') && (numsections > 1)) {
-            alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+            if (document.$formname.crstype.value == 'Community') {
+                alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+            } else {
+                alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+            }
             return;
         }
         for (var j=0; j<newsecs.length; j++) {
@@ -5032,7 +5206,11 @@ function setCourse() {
                 var groups = document.$formname.groups.value.split(/,/g);
                 for (var k=0; k<groups.length; k++) {
                     if (newsecs[j] == groups[k]) {
-                        alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
+                        if (document.$formname.crstype.value == 'Community') {
+                            alert("'"+newsecs[j]+"' $alerts{'mayc'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
+                        } else {
+                            alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
+                        }
                         return;
                     }
                 }
@@ -5042,13 +5220,21 @@ function setCourse() {
             alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
             section = "";
         }
+        if ((userrole == 'co') && (numsections > 0)) {
+            alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
+            section = "";
+        }
 SCRIPTTOP
     if ($mode ne 'upload') {
         $dc_setcourse_code .= (<<"ENDSCRIPT");
         var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
         var numcourse = getIndex(document.$formname.dccourse);
         if (numcourse == "-1") {
-            alert("$alerts{'thwa'}");
+            if (document.$formname.type == 'Community') {
+                alert("$alerts{'thwc'}");
+            } else {
+                alert("$alerts{'thwa'}");
+            }
             return;
         }
         else {
@@ -5157,19 +5343,22 @@ ENDSCRIPT
 
 sub sectioncheck_alerts {
     my %alerts = &Apache::lonlocal::texthash(
-                    curd => 'You must select a course in the current domain',
+                    curd => 'You must select a course or community in the current domain',
                     inea => 'In each course, each user may only have one student role at a time',
+                    inco => 'In each community, each user may only have one member role at a time', 
                     youh => 'You had selected',
                     sect => 'sections',
                     plsm => 'Please modify your selections so they include no more than one section',
                     mayn => 'may not be used as the name for a section, as it is a reserved word',
                     plsc => 'Please choose a different section name',
                     mayt => 'may not be used as the name for a section, as it is the name of a course group',
+                    mayc => 'may not be used as the name for a section, as it is the name of a community group',
                     secn => 'Section names and group names must be distinct',
                     secd => 'Section designations do not apply to ',
                     role => 'roles',
                     accr => 'role will be added with access to all sections',
-                    thwa => 'There was a problem with your course selection'
+                    thwa => 'There was a problem with your course selection',
+                    thwc => 'There was a problem with your community selection',
                  );
     return %alerts;
 }