--- loncom/interface/lonuserutils.pm	2009/11/12 15:58:22	1.104
+++ loncom/interface/lonuserutils.pm	2010/01/05 22:08:48	1.109.2.2
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.104 2009/11/12 15:58:22 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.109.2.2 2010/01/05 22:08:48 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -386,7 +386,7 @@ 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'}."'$crstype'".');';
+                    $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
                     $setsections_js =
                         &setsections_javascript($param{'formname'},$groupslist,
                                                 $mode,'',$crstype);
@@ -1185,8 +1185,10 @@ sub default_role_selector {
                     'exs'  => "Existing sections",
                     'new'  => "New section",
                   );
-    $options = '<select name="defaultrole">'."\n".
-               ' <option value="">'.&mt('Please select').'</option>'."\n"; 
+    $options = '<select name="defaultrole">'."\n";
+    unless (($context eq 'course') && (&Apache::loncommon::needs_gci_custom())) {
+        $options .= ' <option value="">'.&mt('Please select').'</option>'."\n";
+    }
     if ($context eq 'course') {
         $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
     } elsif ($context eq 'author') {
@@ -1446,12 +1448,13 @@ sub print_userlist {
                   '<input type="hidden" name="phase" value="" /></form>');
         return;
     }
-    if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
+    if (!(($context eq 'domain') && 
+          (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
         $r->print('&nbsp;'.&list_submit_button(&mt('Update Display')).
                   "\n</p>\n");
     }
     my ($indexhash,$keylist) = &make_keylist_array();
-    my (%userlist,%userinfo);
+    my (%userlist,%userinfo,$clearcoursepick);
     if (($context eq 'domain') && 
         ($env{'form.roletype'} eq 'course') || 
         ($env{'form.roletype'} eq 'community')) {
@@ -1476,9 +1479,15 @@ sub print_userlist {
                   $courseform."\n".
                   &Apache::lonhtmlcommon::row_closure(1).
                   &Apache::lonhtmlcommon::end_pick_box().'</p>'.
-                  '<p>'.&list_submit_button(&mt('Update Display')).
+                  '<p><input type="hidden" name="origroletype" value="'.$env{'form.roletype'}.'" />'.
+                  &list_submit_button(&mt('Update Display')).
                   "\n".'</p><span class="LC_warning">'.$warning.'</span>'."\n");
-        if ($env{'form.coursepick'}) {
+        $clearcoursepick = 0;
+        if (($env{'form.origroletype'} ne '') &&
+            ($env{'form.origroletype'} ne $env{'form.roletype'})) {
+            $clearcoursepick = 1;
+        }
+        if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
             $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');
         }
     } else {
@@ -1553,7 +1562,7 @@ sub print_userlist {
                 }
             } elsif (($env{'form.roletype'} eq 'course') ||
                      ($env{'form.roletype'} eq 'community')) {
-                if ($env{'form.coursepick'}) {
+                if (($env{'form.coursepick'}) && (!$clearcoursepick)) {
                     my %courses = &process_coursepick();
                     my %allusers;
                     my $hidepriv = 1;
@@ -1956,13 +1965,17 @@ sub process_coursepick {
     my $coursefilter = $env{'form.coursepick'};
     my $cdom = $env{'request.role.domain'};
     my %courses;
+    my $crssrch = 'Course';
+    if ($env{'form.roletype'} eq 'community') {
+        $crssrch = 'Community';
+    }
     if ($coursefilter eq 'all') {
         %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
-                                                 undef,undef,'Course');
+                                                 undef,undef,$crssrch);
     } elsif ($coursefilter eq 'category') {
         my $instcode = &instcode_from_coursefilter();
         %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
-                                                 undef,undef,'Course');
+                                                 undef,undef,$crssrch);
     } elsif ($coursefilter eq 'specific') {
         if ($env{'form.coursetotal'} > 1) {
             my @course_ids = split(/&&/,$env{'form.courselist'});
@@ -2147,7 +2160,7 @@ END
     } elsif ($context eq 'domain') {
         if ($setting eq 'community') {
             $crstype = 'Community';
-        } elsif ($crstype eq 'course') {
+        } elsif ($setting eq 'course') {
             $crstype = 'Course';
         }
     }
@@ -2298,7 +2311,11 @@ END
     if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
         if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
             if ($permission->{'cusr'}) {
-                $actionselect = &select_actions($context,$setting,$statusmode,$formname);
+                unless (($context eq 'domain') && 
+                        (($setting eq 'course') || ($setting eq 'community'))) {
+                    $actionselect = 
+                        &select_actions($context,$setting,$statusmode,$formname);
+                }
             }
             $r->print(<<END);
 <input type="hidden" name="srchby"  value="uname" />
@@ -2392,11 +2409,7 @@ END
  <th><a href=\"javascript:document.$formname.sortby.value='type';document.$formname.submit();\">$lt{'type'}</a></th>
             ";
         } else {
-            if ($mode eq 'pickauthor') {
-                $output .= "\n".'<th>&nbsp;</th>'."\n";
-            } else { 
-                $output .= "\n".'<th>'.&mt('Count').'</th>'."\n";
-            }
+            $output .= "\n".'<th>&nbsp;</th>'."\n";
             if ($actionselect) {
                 $output .= '<th>'.&mt('Select').'</th>'."\n";
             }
@@ -2451,9 +2464,13 @@ END
                        time.'_'.rand(1000000000).'.csv';
         unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
             $r->log_error("Couldn't open $CSVfilename for output $!");
-            $r->print(&mt('Problems occurred in writing the CSV file. '
-                         .'This error has been logged. '
-                         .'Please alert your LON-CAPA administrator.'));
+            $r->print(
+                '<p class="LC_error">'
+               .&mt('Problems occurred in writing the CSV file.')
+               .' '.&mt('This error has been logged.')
+               .' '.&mt('Please alert your LON-CAPA administrator.')
+               .'</p>'
+            );
             $CSVfile = undef;
         }
         #
@@ -3640,27 +3657,19 @@ sub print_first_users_upload_form {
     $str .= '<input type="hidden" name="action" value="upload" />';
     $str .= '<input type="hidden" name="state"  value="got_file" />';
 
-    $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
+    $str .= '<h3>'.&mt('Upload a file containing information about users').'</h3>'."\n";
 
     # Excel and CSV Help
-    $str .= '<p>'
+    $str .= '<div class="LC_left_float">'
            .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
                 &mt("How do I create a users list from a spreadsheet"))
-           ."<br />\n"
+           .'</div><div class="LC_left_float">'."\n"
            .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
                 &mt("How do I create a CSV file from a spreadsheet"))
-           ."</p>\n";
-
+           .'</div><br clear="all" />'."\n";
     $str .= &Apache::lonhtmlcommon::start_pick_box()
-           .&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_title(&mt('File'))
+           .&Apache::loncommon::upfile_select_html()
            .&Apache::lonhtmlcommon::row_closure()
            .&Apache::lonhtmlcommon::row_title(
                 '<label for="noFirstLine">'
@@ -3674,8 +3683,6 @@ sub print_first_users_upload_form {
            .'<input type="submit" name="fileupload" value="'.&mt('Next').'" />'
            .'</p>';
 
-    $str .= &Apache::loncommon::end_page();
-
     $r->print($str);
     return;
 }
@@ -5018,14 +5025,22 @@ sub roles_by_context {
         if ($env{'request.role'} =~ m{^dc\./}) {
             push(@allroles,'ad');
         }
-        push(@allroles,('ta','ep','in'));
-        if ($crstype eq 'Community') {
-            push(@allroles,'co');
+        if (&Apache::loncommon::needs_gci_custom()) {
+            if ($crstype eq 'Community') {
+                push(@allroles,'co');
+            } else {
+                push(@allroles,'cc');
+            }
         } else {
-            push(@allroles,'cc');
-        }
-        if ($custom) {
-            push(@allroles,'cr');
+            push(@allroles,('ta','ep','in'));
+            if ($crstype eq 'Community') {
+                push(@allroles,'co');
+            } else {
+                push(@allroles,'cc');
+            }
+            if ($custom) {
+                push(@allroles,'cr');
+            }
         }
     } elsif ($context eq 'author') {
         @allroles = ('ca','aa');