--- loncom/interface/loncreateuser.pm	2009/11/12 15:58:22	1.324
+++ loncom/interface/loncreateuser.pm	2010/09/19 16:44:44	1.329.2.4
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.324 2009/11/12 15:58:22 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.329.2.4 2010/09/19 16:44:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -472,6 +472,7 @@ sub print_username_entry_form {
     my ($r,$context,$response,$srch,$forcenewuser,$crstype) = @_;
     my $defdom=$env{'request.role.domain'};
     my $formtoset = 'crtuser';
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
     if (exists($env{'form.startrolename'})) {
         $formtoset = 'docustom';
         $env{'form.rolename'} = $env{'form.startrolename'};
@@ -497,8 +498,14 @@ sub print_username_entry_form {
                 'onload' => "javascript:setFormElements(document.$formtoset)",
                     );
     my %breadcrumb_text = &singleuser_breadcrumb($crstype);
+    my $title = 'User Management';
+    if ($context eq 'course') {
+        if ($is_custom) {
+            $title = 'Enrollment and Student Activity';
+        }
+    }
     my $start_page =
-	&Apache::loncommon::start_page('User Management',
+	&Apache::loncommon::start_page($title,
 				       $jscript,{'add_entries' => \%loaditems,});
     if ($env{'form.action'} eq 'custom') {
         &Apache::lonhtmlcommon::add_breadcrumb
@@ -516,7 +523,7 @@ sub print_username_entry_form {
     } elsif ($env{'form.action'} eq 'singlestudent') {
         $helpitem = 'Course_Add_Student';
     }
-    my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
+    my $crumbs = &Apache::lonhtmlcommon::breadcrumbs($title,
                                                      $helpitem);
     my %lt=&Apache::lonlocal::texthash(
                     'srst' => 'Search for a user and enroll as a student',
@@ -552,10 +559,10 @@ sub print_username_entry_form {
                           &mt('View/Modify existing role:').'</b></label></td>'.
                           '<td align="center"><br />'.
                           '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
-                          '<option value="" selected="selected" onchange="">'.
+                          '<option value="" selected="selected">'.
                           &mt('Select'));
                 foreach my $role (sort(keys(%existingroles))) {
-                    $r->print('<option value="$role">'.$role.'</option>');
+                    $r->print('<option value="'.$role.'">'.$role.'</option>');
                 }
                 $r->print('</select>'.
                           '</td>'.
@@ -660,7 +667,7 @@ $userpicker
 ENDBLOCK
     if ($env{'form.phase'} eq '') {
         my $defdom=$env{'request.role.domain'};
-        my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+        my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain','',1);
         my %lt=&Apache::lonlocal::texthash(
                   'enro' => 'Enroll one student',
                   'enrm' => 'Enroll one member',
@@ -709,7 +716,7 @@ $showresponse
 <table>
  <tr>
   <td>$lt{'usr'}:</td>
-  <td><input type="text" size="15" name="srchterm" /></td>
+  <td><input type="text" size="25" name="srchterm" /></td>
   <td>&nbsp;$lt{'dom'}:</td><td>$domform</td>
   <td>&nbsp;$sellink&nbsp;</td>
   <td>&nbsp;<input name="userrole" type="submit" value="$buttontext" /></td>
@@ -754,6 +761,7 @@ sub print_user_selection_page {
     my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype) = @_;
     my @fields = ('username','domain','lastname','firstname','permanentemail');
     my $sortby = $env{'form.sortby'};
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
 
     if (!grep(/^\Q$sortby\E$/,@fields)) {
         $sortby = 'lastname';
@@ -792,7 +800,13 @@ ENDSCRIPT
     if ($context eq 'requestcrs') {
         $r->print('<div>');
     } else {
-        $r->print(&Apache::loncommon::start_page('User Management',$jscript));
+        my $title = 'User Management';
+        if ($context eq 'course') {
+            if ($is_custom) {
+                $title = 'Enrollment and Student Activity';
+            }
+        }
+        $r->print(&Apache::loncommon::start_page($title,$jscript));
 
         my %breadcrumb_text = &singleuser_breadcrumb($crstype);
         &Apache::lonhtmlcommon::add_breadcrumb
@@ -803,13 +817,13 @@ ENDSCRIPT
               text=>$breadcrumb_text{'userpicked'},
               faq=>282,bug=>'Instructor Interface',});
         if ($env{'form.action'} eq 'singleuser') {
-            $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs($title,
                                                           'Course_Change_Privileges'));
             $r->print("<b>$lt{'usrch'}</b><br />");
             $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
             $r->print('<h3>'.$lt{'usel'}.'</h3>');
         } elsif ($env{'form.action'} eq 'singlestudent') {
-            $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs($title,
                                                           'Course_Add_Student'));
             $r->print($jscript."<b>");
             if ($crstype eq 'Community') {
@@ -918,12 +932,21 @@ sub print_user_modification_page {
     my %abv_auth = &auth_abbrev();
     my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
+    if ($is_custom) {
+        if ($uhome eq 'no_host') {
+            my $lc_ccuname = lc($ccuname);
+            if ($lc_ccuname ne $ccuname) {
+                $uhome = &Apache::lonnet::homeserver($lc_ccuname,$ccdomain);
+                $ccuname = $lc_ccuname;
+            }
+        }
+    }
     if ($uhome eq 'no_host') {
-        my $usertype;
         my ($rules,$ruleorder) =
             &Apache::lonnet::inst_userrules($ccdomain,'username');
-            $usertype =
-                &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
+        my $usertype =
+            &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules);
         my $cancreate =
             &Apache::lonuserutils::can_create_user($ccdomain,$context,
                                                    $usertype);
@@ -933,17 +956,26 @@ sub print_user_modification_page {
                 official   => 'institutional',
                 unofficial => 'non-institutional',
             );
+            if ($ccdomain eq 'gci') {
+                $usertypetext{'unofficial'} = 'institutional',
+            }
             my $response;
             if ($env{'form.origform'} eq 'crtusername') {
-                $response =  '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
-                            '</span><br />';
+                if ($is_custom) {
+                    $response = '<span class="LC_warning">'.&mt('Invalid format for username for new user: [_1]','<b>'.$ccuname.'</b>').
+                                '</span><br />';
+                } else {
+                    $response =  '<span class="LC_warning">'.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).'</span><br />';
+                }
             }
             $response .= '<p class="LC_warning">'
                         .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
-                        .' '
-                        .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
-                            ,'<a href="'.$helplink.'">','</a>')
-                        .'</p><br />';
+                        .'<br />';
+            if ($ccdomain eq 'gcitest') {
+                $response .= &mt('Enter a valid e-mail address as the username for the new user.').' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.'
+                             ,'<a href="'.$helplink.'">','</a>')
+                             .'</p><br />';
+            }
             $env{'form.phase'} = '';
             &print_username_entry_form($r,$context,$response,undef,undef,$crstype);
             return;
@@ -994,8 +1026,14 @@ sub print_user_modification_page {
     if ($env{'form.popup'}) {
        $args->{'no_nav_bar'} = 1; 
     }
+    my $title = 'User Management';
+    if ($context eq 'course') {
+        if ($is_custom) {
+            $title = 'Enrollment and Student Activity';
+        }
+    }
     my $start_page = 
-	&Apache::loncommon::start_page('User Management',$js,$args);
+	&Apache::loncommon::start_page($title,$js,$args);
     my %breadcrumb_text = &singleuser_breadcrumb($crstype);
     &Apache::lonhtmlcommon::add_breadcrumb
      ({href=>"javascript:backPage($form)",
@@ -1016,7 +1054,7 @@ sub print_user_modification_page {
     if ($env{'form.action'} eq 'singlestudent') {
         $helpitem = 'Course_Add_Student';
     }
-    my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
+    my $crumbs = &Apache::lonhtmlcommon::breadcrumbs($title,
                                                      $helpitem);
 
     my $forminfo =<<"ENDFORMINFO";
@@ -1028,10 +1066,24 @@ sub print_user_modification_page {
 <input type="hidden" name="pres_type"   value="" />
 <input type="hidden" name="pres_marker" value="" />
 ENDFORMINFO
-    my %inccourses;
-    foreach my $key (keys(%env)) {
-	if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
-	    $inccourses{$1.'_'.$2}=1;
+    my (%inccourses,$roledom);
+    if ($context eq 'course') {
+        $inccourses{$env{'request.course.id'}}=1;
+        $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    } elsif ($context eq 'author') {
+        $roledom = $env{'request.role.domain'};
+    } elsif ($context eq 'domain') {
+        foreach my $key (keys(%env)) {
+            $roledom = $env{'request.role.domain'};
+            if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
+                $inccourses{$1.'_'.$2}=1;
+            }
+        }
+    } else {
+        foreach my $key (keys(%env)) {
+	    if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
+	        $inccourses{$1.'_'.$2}=1;
+            }
         }
     }
     if ($newuser) {
@@ -1268,10 +1320,10 @@ ENDNOTOOLSPRIV
         }
         $r->print('</div><div class="LC_clear_float_footer"></div>');
         if ($env{'form.action'} ne 'singlestudent') {
-            &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
+            &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
+                                    $roledom,$crstype);
         }
     } ## End of new user/old user logic
-
     if ($env{'form.action'} eq 'singlestudent') {
         my $btntxt;
         if ($crstype eq 'Community') {
@@ -1389,13 +1441,9 @@ sub validation_javascript {
 }
 
 sub display_existing_roles {
-    my ($r,$ccuname,$ccdomain,$inccourses) = @_;
-    my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
-    # Build up table of user roles to allow revocation and re-enabling of roles.
-    my ($tmp) = keys(%rolesdump);
-    if ($tmp !~ /^(con_lost|error)/i) {
-        my $now=time;
-        my %lt=&Apache::lonlocal::texthash(
+    my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype) = @_;
+    my $now=time;
+    my %lt=&Apache::lonlocal::texthash(
                     'rer'  => "Existing Roles",
                     'rev'  => "Revoke",
                     'del'  => "Delete",
@@ -1405,198 +1453,255 @@ sub display_existing_roles {
                     'sta'  => "Start",
                     'end'  => "End",
                                        );
-        my (%roletext,%sortrole,%roleclass,%rolepriv);
-        foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
-                                    my $b1=join('_',(split('_',$b))[1,0]);
-                                    return $a1 cmp $b1;
-                                } keys(%rolesdump)) {
-            next if ($area =~ /^rolesdef/);
-            my $envkey=$area;
-            my $role = $rolesdump{$area};
-            my $thisrole=$area;
-            $area =~ s/\_\w\w$//;
-            my ($role_code,$role_end_time,$role_start_time) =
-                split(/_/,$role);
+    my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
+    if ($context eq 'course' || $context eq 'author') {
+        my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
+        my %roleshash = 
+            &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
+                              ['active','previous','future'],\@roles,$roledom,1);
+        foreach my $key (keys(%roleshash)) {
+            my ($start,$end) = split(':',$roleshash{$key});
+            next if ($start eq '-1' || $end eq '-1');
+            my ($rnum,$rdom,$role,$sec) = split(':',$key);
+            if ($context eq 'course') {
+                next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
+                             && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
+            } elsif ($context eq 'author') {
+                next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
+            }
+            my ($newkey,$newvalue,$newrole);
+            $newkey = '/'.$rdom.'/'.$rnum;
+            if ($sec ne '') {
+                $newkey .= '/'.$sec;
+            }
+            $newvalue = $role;
+            if ($role =~ /^cr/) {
+                $newrole = 'cr';
+            } else {
+                $newrole = $role;
+            }
+            $newkey .= '_'.$newrole;
+            if ($start ne '' && $end ne '') {
+                $newvalue .= '_'.$end.'_'.$start;
+            }
+            $rolesdump{$newkey} = $newvalue;
+        }
+    } else {
+        %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
+    }
+    # Build up table of user roles to allow revocation and re-enabling of roles.
+    my ($tmp) = keys(%rolesdump);
+    return if ($tmp =~ /^(con_lost|error)/i);
+    foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
+                                my $b1=join('_',(split('_',$b))[1,0]);
+                                return $a1 cmp $b1;
+                            } keys(%rolesdump)) {
+        next if ($area =~ /^rolesdef/);
+        my $envkey=$area;
+        my $role = $rolesdump{$area};
+        my $thisrole=$area;
+        $area =~ s/\_\w\w$//;
+        my ($role_code,$role_end_time,$role_start_time) =
+            split(/_/,$role);
 # Is this a custom role? Get role owner and title.
-            my ($croleudom,$croleuname,$croletitle)=
-                ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
-            my $allowed=0;
-            my $delallowed=0;
-            my $sortkey=$role_code;
-            my $class='Unknown';
-            if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
-                $class='Course';
-                my ($coursedom,$coursedir) = ($1,$2);
-                $sortkey.="\0$coursedom";
-                # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
-                my %coursedata=
-                    &Apache::lonnet::coursedescription($1.'_'.$2);
-                my $carea;
-                if (defined($coursedata{'description'})) {
-                    $carea=$coursedata{'description'}.
-                        '<br />'.&mt('Domain').': '.$coursedom.('&nbsp;'x8).
-     &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
-                    $sortkey.="\0".$coursedata{'description'};
-                    $class=$coursedata{'type'};
+        my ($croleudom,$croleuname,$croletitle)=
+            ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
+        my $allowed=0;
+        my $delallowed=0;
+        my $sortkey=$role_code;
+        my $class='Unknown';
+        if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
+            $class='Course';
+            my ($coursedom,$coursedir) = ($1,$2);
+            my $cid = $1.'_'.$2;
+            # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
+            my %coursedata=
+                &Apache::lonnet::coursedescription($cid);
+            if ($coursedir =~ /^$match_community$/) {
+                $class='Community';
+            }
+            $sortkey.="\0$coursedom";
+            my $carea;
+            if (defined($coursedata{'description'})) {
+                $carea=$coursedata{'description'}.
+                    '<br />'.&mt('Domain').': '.$coursedom.('&nbsp;'x8).
+    &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
+                $sortkey.="\0".$coursedata{'description'};
+            } else {
+                if ($class eq 'Community') {
+                    $carea=&mt('Unavailable community').': '.$area;
+                    $sortkey.="\0".&mt('Unavailable community').': '.$area;
                 } else {
                     $carea=&mt('Unavailable course').': '.$area;
                     $sortkey.="\0".&mt('Unavailable course').': '.$area;
                 }
-                $sortkey.="\0$coursedir";
-                $inccourses->{$1.'_'.$2}=1;
-                if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
-                    (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
-                    $allowed=1;
-                }
-                if ((&Apache::lonnet::allowed('dro',$1)) ||
-                    (&Apache::lonnet::allowed('dro',$ccdomain))) {
-                    $delallowed=1;
+            }
+            $sortkey.="\0$coursedir";
+            $inccourses->{$cid}=1;
+            if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
+                (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
+                $allowed=1;
+            }
+            unless ($allowed) {
+                my $isowner = &is_courseowner($cid,$coursedata{'internal.courseowner'});
+                if ($isowner) {
+                    if (($role_code eq 'co') && ($class eq 'Community')) {
+                        $allowed = 1;
+                    } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
+                        $allowed = 1;
+                    }
                 }
+            } 
+            if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
+                (&Apache::lonnet::allowed('dro',$ccdomain))) {
+                $delallowed=1;
+            }
 # - custom role. Needs more info, too
-                if ($croletitle) {
-                    if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
-                        $allowed=1;
-                        $thisrole.='.'.$role_code;
-                    }
+            if ($croletitle) {
+                if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
+                    $allowed=1;
+                    $thisrole.='.'.$role_code;
                 }
-                # Compute the background color based on $area
-                if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
-                    $carea.='<br />Section: '.$3;
-                    $sortkey.="\0$3";
-                    if (!$allowed) {
-                        if ($env{'request.course.sec'} eq $3) {
-                            if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
-                                $allowed = 1;
-                            }
+            }
+            if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
+                $carea.='<br />Section: '.$3;
+                $sortkey.="\0$3";
+                if (!$allowed) {
+                    if ($env{'request.course.sec'} eq $3) {
+                        if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
+                            $allowed = 1;
                         }
                     }
                 }
-                $area=$carea;
-            } else {
-                $sortkey.="\0".$area;
-                # Determine if current user is able to revoke privileges
-                if ($area=~m{^/($match_domain)/}) {
-                    if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
-                       (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
-                        $allowed=1;
-                    }
-                    if (((&Apache::lonnet::allowed('dro',$1))  ||
-                         (&Apache::lonnet::allowed('dro',$ccdomain))) &&
-                        ($role_code ne 'dc')) {
-                        $delallowed=1;
-                    }
-                } else {
-                    if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
-                        $allowed=1;
-                    }
+            }
+            $area=$carea;
+        } else {
+            $sortkey.="\0".$area;
+            # Determine if current user is able to revoke privileges
+            if ($area=~m{^/($match_domain)/}) {
+                if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
+                   (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
+                   $allowed=1;
                 }
-                if ($role_code eq 'ca' || $role_code eq 'au') {
-                    $class='Construction Space';
-                } elsif ($role_code eq 'su') {
-                    $class='System';
-                } else {
-                    $class='Domain';
+                if (((&Apache::lonnet::allowed('dro',$1))  ||
+                    (&Apache::lonnet::allowed('dro',$ccdomain))) &&
+                    ($role_code ne 'dc')) {
+                    $delallowed=1;
                 }
-            }
-            if (($role_code eq 'ca') || ($role_code eq 'aa')) {
-                $area=~m{/($match_domain)/($match_username)};
-                if (&Apache::lonuserutils::authorpriv($2,$1)) {
+            } else {
+                if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
                     $allowed=1;
-                } else {
-                    $allowed=0;
                 }
             }
-            my $row = '';
-            $row.= '<td>';
-            my $active=1;
-            $active=0 if (($role_end_time) && ($now>$role_end_time));
-            if (($active) && ($allowed)) {
-                $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
+            if ($role_code eq 'ca' || $role_code eq 'au') {
+                $class='Construction Space';
+            } elsif ($role_code eq 'su') {
+                $class='System';
             } else {
-                if ($active) {
-                   $row.='&nbsp;';
-                } else {
-                   $row.=&mt('expired or revoked');
-                }
+                $class='Domain';
             }
-            $row.='</td><td>';
-            if ($allowed && !$active) {
-                $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
+        }
+        if (($role_code eq 'ca') || ($role_code eq 'aa')) {
+            $area=~m{/($match_domain)/($match_username)};
+            if (&Apache::lonuserutils::authorpriv($2,$1)) {
+                $allowed=1;
             } else {
-                $row.='&nbsp;';
+                $allowed=0;
             }
-            $row.='</td><td>';
-            if ($delallowed) {
-                $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
+        }
+        my $row = '';
+        $row.= '<td>';
+        my $active=1;
+        $active=0 if (($role_end_time) && ($now>$role_end_time));
+        if (($active) && ($allowed)) {
+            $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
+        } else {
+            if ($active) {
+               $row.='&nbsp;';
             } else {
-                $row.='&nbsp;';
+               $row.=&mt('expired or revoked');
             }
-            my $plaintext='';
-            if (!$croletitle) {
-                $plaintext=&Apache::lonnet::plaintext($role_code,$class)
-            } else {
-                $plaintext=
+        }
+        $row.='</td><td>';
+        if ($allowed && !$active) {
+            $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
+        } else {
+            $row.='&nbsp;';
+        }
+        $row.='</td><td>';
+        if ($delallowed) {
+            $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
+        } else {
+            $row.='&nbsp;';
+        }
+        my $plaintext='';
+        if (!$croletitle) {
+            $plaintext=&Apache::lonnet::plaintext($role_code,$class)
+        } else {
+            $plaintext=
         "Customrole '$croletitle'<br />defined by $croleuname\@$croleudom";
+        }
+        $row.= '</td><td>'.$plaintext.
+               '</td><td>'.$area.
+               '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
+                                            : '&nbsp;' ).
+               '</td><td>'.($role_end_time  ?&Apache::lonlocal::locallocaltime($role_end_time)
+                                            : '&nbsp;' )
+               ."</td>";
+        $sortrole{$sortkey}=$envkey;
+        $roletext{$envkey}=$row;
+        $roleclass{$envkey}=$class;
+        $rolepriv{$envkey}=$allowed;
+    } # end of foreach        (table building loop)
+
+    my $rolesdisplay = 0;
+    my %output = ();
+    foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
+        $output{$type} = '';
+        foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
+            if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
+                 $output{$type}.=
+                      &Apache::loncommon::start_data_table_row().
+                      $roletext{$sortrole{$which}}.
+                      &Apache::loncommon::end_data_table_row();
             }
-            $row.= '</td><td>'.$plaintext.
-                   '</td><td>'.$area.
-                   '</td><td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
-                                                : '&nbsp;' ).
-                   '</td><td>'.($role_end_time  ?&Apache::lonlocal::locallocaltime($role_end_time)
-                                                : '&nbsp;' )
-                   ."</td>";
-            $sortrole{$sortkey}=$envkey;
-            $roletext{$envkey}=$row;
-            $roleclass{$envkey}=$class;
-            $rolepriv{$envkey}=$allowed;
-            #$r->print($row);
-        } # end of foreach        (table building loop)
-        my $rolesdisplay = 0;
-        my %output = ();
-        foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
-            $output{$type} = '';
-            foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
-                if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
-                    $output{$type}.=
-                          &Apache::loncommon::start_data_table_row().
-                          $roletext{$sortrole{$which}}.
-                          &Apache::loncommon::end_data_table_row();
-                }
-            }
-            unless($output{$type} eq '') {
-                $output{$type} = '<tr class="LC_info_row">'.
-                          "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
-                           $output{$type};
-                $rolesdisplay = 1;
-            }
-        }
-        if ($rolesdisplay == 1) {
-            my $contextrole='';
-            if ($env{'request.course.id'}) {
-                my $crstype = &Apache::loncommon::course_type();
-                $contextrole = "Existing Roles in this $crstype";
-            } elsif ($env{'request.role'} =~ /^au\./) {
-                $contextrole = 'Existing Co-Author Roles in your Construction Space';
+        }
+        unless($output{$type} eq '') {
+            $output{$type} = '<tr class="LC_info_row">'.
+                      "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
+                      $output{$type};
+            $rolesdisplay = 1;
+        }
+    }
+    if ($rolesdisplay == 1) {
+        my $contextrole='';
+        if ($env{'request.course.id'}) {
+            if (&Apache::loncommon::course_type() eq 'Community') {
+                $contextrole = &mt('Existing Roles in this Community');
             } else {
-                $contextrole = 'Existing Roles in this Domain';
+                $contextrole = &mt('Existing Roles in this Course');
             }
-            $r->print('
+        } elsif ($env{'request.role'} =~ /^au\./) {
+            $contextrole = &mt('Existing Co-Author Roles in your Construction Space');
+        } else {
+            $contextrole = &mt('Existing Roles in this Domain');
+        }
+        $r->print('
 <h3>'.$lt{'rer'}.'</h3>'.
-'<div>'.&mt($contextrole).'</div>'.
+'<div>'.$contextrole.'</div>'.
 &Apache::loncommon::start_data_table("LC_createuser").
 &Apache::loncommon::start_data_table_header_row().
 '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
 '</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.
 '</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
 &Apache::loncommon::end_data_table_header_row());
-           foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
-                if ($output{$type}) {
-                    $r->print($output{$type}."\n");
-                }
+        foreach my $type ('Construction Space','Course','Community','Domain','System','Unknown') {
+            if ($output{$type}) {
+                $r->print($output{$type}."\n");
             }
-            $r->print(&Apache::loncommon::end_data_table());
         }
-    }  # End of check for keys in rolesdump
+        $r->print(&Apache::loncommon::end_data_table());
+    }
     return;
 }
 
@@ -2084,7 +2189,8 @@ sub get_inststatuses {
 
 # ================================================================= Phase Three
 sub update_user_data {
-    my ($r,$context,$crstype) = @_; 
+    my ($r,$context,$crstype) = @_;
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
     my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
                                           $env{'form.ccdomain'});
     # Error messages
@@ -2137,7 +2243,13 @@ sub update_user_data {
     if ($env{'form.action'} eq 'singlestudent') {
         $helpitem = 'Course_Add_Student';
     }
-    $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+    my $title = 'User Management';
+    if ($context eq 'course') {
+        if ($is_custom) {
+            $title = 'Enrollment and Student Activity';
+        }
+    }
+    $r->print(&Apache::lonhtmlcommon::breadcrumbs($title,
                                                  $helpitem));
     $r->print(&update_result_form($uhome));
     # Check Inputs
@@ -2628,7 +2740,8 @@ sub update_user_data {
                                         $changeHash{'tools.'.$key};
                                 } else {
                                     $newenvhash{'environment.availabletools.'.$key} =
-          &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},                                            $key,'reload','tools');
+          &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
+                                            $key,'reload','tools');
                                 }
                             }
                         }
@@ -3564,6 +3677,13 @@ sub custom_role_editor {
         $context = 'domain';
         $crstype = $env{'form.templatecrstype'};
     }
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
+    my $title = 'User Management';
+    if ($context eq 'course') {
+        if ($is_custom) {
+            $title = 'Enrollment and Student Activity';
+        }
+    }
 # ------------------------------------------------------- What can be assigned?
     my %full=();
     my %courselevel=();
@@ -3572,7 +3692,6 @@ sub custom_role_editor {
     my $dompriv='';
     my $coursepriv='';
     my $body_top;
-    my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
     my ($rdummy,$roledef)=
 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
 # ------------------------------------------------------- Does this role exist?
@@ -3680,7 +3799,7 @@ sub custom_role_editor {
       {href=>"javascript:backPage(document.form1,'','')",
          text=>"Edit custom role",
          faq=>282,bug=>'Instructor Interface',});
-    $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+    $r->print(&Apache::lonhtmlcommon::breadcrumbs($title,
                                                   'Course_Editing_Custom_Roles'));
 
     $r->print($body_top);
@@ -3833,7 +3952,13 @@ sub set_custom_role {
                  .$jsback."\n"
                  .'// ]]>'."\n"
                  .'</script>'."\n";
-
+    my $title = 'User Management';
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
+    if ($context eq 'course') {
+        if ($is_custom) {
+            $title = 'Enrollment and Student Activity';
+        }
+    }
     $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
     &Apache::lonhtmlcommon::add_breadcrumb
         ({href=>"javascript:backPage(document.customresult,'pickrole','')",
@@ -3845,7 +3970,7 @@ sub set_custom_role {
          {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
           text=>"Result",
           faq=>282,bug=>'Instructor Interface',});
-    $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+    $r->print(&Apache::lonhtmlcommon::breadcrumbs($title,
                                                   'Course_Editing_Custom_Roles'));
 
     my ($rdummy,$roledef)=
@@ -3923,6 +4048,13 @@ sub handler {
     } else {
         $context = 'domain';
     }
+    my $title = 'User Management';
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
+    if ($context eq 'course') {
+        if ($is_custom) {
+            $title = 'Enrollment and Student Activity';
+        }
+    }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
         ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
          'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
@@ -3930,7 +4062,7 @@ sub handler {
     if ($env{'form.action'} ne 'dateselect') {
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>"/adm/createuser",
-              text=>"User Management",
+              text=>$title,
               help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'});
     }
     #SD Following files not added to help, because the corresponding .tex-files seem to
@@ -3950,7 +4082,7 @@ sub handler {
     # Main switch on form.action and form.state, as appropriate
     if (! exists($env{'form.action'})) {
         $r->print(&header());
-        $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs($title));
         $r->print(&print_main_menu($permission,$context,$crstype));
         $r->print(&Apache::loncommon::end_page());
     } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
@@ -3966,8 +4098,12 @@ sub handler {
         if (! exists($env{'form.state'})) {
             &Apache::lonuserutils::print_first_users_upload_form($r,$context);
         } elsif ($env{'form.state'} eq 'got_file') {
+            my $formname;
+            if ($env{'form.caller'} eq 'requestcrs') {
+                $formname = 'studentform';
+            }
             &Apache::lonuserutils::print_upload_manager_form($r,$context,
-                                                             $permission,$crstype);
+                                                             $permission,$crstype,$formname);
         } elsif ($env{'form.state'} eq 'enrolling') {
             if ($env{'form.datatoken'}) {
                 &Apache::lonuserutils::upfile_drop_add($r,$context,$permission);
@@ -3990,7 +4126,7 @@ sub handler {
             if ($env{'form.phase'} eq 'createnewuser') {
                 my $response;
                 if ($env{'form.srchterm'} !~ /^$match_username$/) {
-                    my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+                    my $response = '<p class="LC_warning">'.&mt('You must specify a valid username. Only the following are allowed: letters numbers - . @').'</p>';
                     $env{'form.phase'} = '';
                     &print_username_entry_form($r,$context,$response,$srch,undef,$crstype);
                 } else {
@@ -4206,7 +4342,7 @@ sub handler {
         $r->print(&Apache::loncommon::end_page());        
     } else {
         $r->print(&header());
-        $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs($title));
         $r->print(&print_main_menu($permission,$context,$crstype));
         $r->print(&Apache::loncommon::end_page());
     }
@@ -4252,6 +4388,10 @@ END
 #  Menu Phase One
 sub print_main_menu {
     my ($permission,$context,$crstype) = @_;
+    my $is_custom = &Apache::loncommon::needs_gci_custom();
+    if (($context eq 'course') && ($is_custom)) {
+        return &print_gci_main_menu($permission,$context,$crstype)
+    }
     my $linkcontext = $context;
     my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
     if (($context eq 'course') && ($crstype eq 'Community')) {
@@ -4418,7 +4558,7 @@ sub print_main_menu {
              linktitle => $linktitle{$crstype}{'groups'},
             },
             {
-             linktext => 'Change Logs',
+             linktext => 'Change Log',
              icon => 'document-properties.png',
              #help => 'Course_User_Logs',
              url => '/adm/createuser?action=changelogs',
@@ -4473,6 +4613,82 @@ return Apache::lonhtmlcommon::generate_m
 #               });
 }
 
+sub print_gci_main_menu {
+    my ($permission,$context,$crstype) = @_;
+    my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
+    my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
+    my %links = (
+        course => {
+                    single     => 'Add/Modify a Student',
+                    drop       => 'Drop Students',
+                    upload     => 'Upload a File of Course Users',
+                    singleuser => 'Add/Modify a Course User',
+                    listusers  => 'Concept Test Roster and Student Activity',
+                  },
+     );
+     my %linktitles = (
+        course => {
+                    singleuser => 'Add a user with a certain role to this course.',
+                    listusers  => 'Show and manage users in this course.',
+                    single     => 'Add a user with the role of student to this course',
+                    drop       => 'Remove a student from this course.',
+                    upload     => 'Upload a CSV or a text file containing users.', 
+                  },
+    );
+    my @menu = ( {categorytitle => 'Manage Users',
+         items =>
+         [
+            {
+             linktext => $links{$context}{'single'},
+             #help => 'Course_Add_Student',
+             icon => 'list-add.png',
+             url => '/adm/createuser?action=singlestudent',
+             permission => $permission->{'cusr'},
+             linktitle => $linktitles{$context}{'single'},
+
+            },
+            {
+             linktext => $links{$context}{'drop'},
+             icon => 'edit-undo.png',
+             #help => 'Course_Drop_Student',
+             url => '/adm/createuser?action=drop',
+             permission => $permission->{'cusr'},
+             linktitle => $linktitles{$context}{'drop'},
+            },
+            {
+             linktext => $links{$context}{'upload'},
+             icon => 'sctr.png',
+             #help => 'Course_Create_Class_List',
+             url => '/adm/createuser?action=upload',
+             permission => $permission->{'cusr'},
+             linktitle => $linktitles{$context}{'upload'},
+            },
+            {
+             linktext => $links{$context}{'listusers'},
+             icon => 'edit-find.png',
+             #help => 'Course_View_Class_List',
+             url => '/adm/createuser?action=listusers',
+             permission => ($permission->{'view'} || $permission->{'cusr'}),
+             linktitle => $linktitles{$context}{'listusers'},
+            },
+         ]},
+         {categorytitle => 'Administration',
+         items => [ ]},
+    );
+
+    push(@{ $menu[1]->{items} }, #Category: Administration
+        {
+           linktext => 'Change Log',
+           icon => 'document-properties.png',
+           #help => 'Course_User_Logs',
+           url => '/adm/createuser?action=changelogs',
+           permission => $permission->{'cusr'},
+           linktitle => 'View change log.',
+         },
+    );
+    return Apache::lonhtmlcommon::generate_menu(@menu);
+}
+
 sub restore_prev_selections {
     my %saveable_parameters = ('srchby'   => 'scalar',
 			       'srchin'   => 'scalar',
@@ -5162,7 +5378,6 @@ sub print_userchangelogs_display {
     my %roleslog=&Apache::lonnet::dump('nohist_rolelog',$cdom,$cnum);
     if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
 
-    $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
     my %saveable_parameters = ('show' => 'scalar',);
     &Apache::loncommon::store_course_settings('roles_log',
                                               \%saveable_parameters);
@@ -5197,7 +5412,6 @@ sub print_userchangelogs_display {
     }
     my (%whodunit,%changed,$version);
     ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
-    $r->print(&role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype));
     my ($minshown,$maxshown);
     $minshown = 1;
     my $count = 0;
@@ -5208,8 +5422,29 @@ sub print_userchangelogs_display {
         }
     }
 
-    # Collect user change log data
-    my $content = '';
+    # Form Header
+    $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
+              &role_display_filter($formname,$cdom,$cnum,\%curr,$version,$crstype));
+
+    # Create navigation
+    my ($nav_script,$nav_links) = &userlogdisplay_nav($formname,\%curr,$more_records);
+    my $showntableheader = 0;
+
+    # Table Header
+    my $tableheader = 
+        &Apache::loncommon::start_data_table_header_row()
+       .'<th>&nbsp;</th>'
+       .'<th>'.&mt('When').'</th>'
+       .'<th>'.&mt('Who made the change').'</th>'
+       .'<th>'.&mt('Changed User').'</th>'
+       .'<th>'.&mt('Role').'</th>'
+       .'<th>'.&mt('Section').'</th>'
+       .'<th>'.&mt('Context').'</th>'
+       .'<th>'.&mt('Start').'</th>'
+       .'<th>'.&mt('End').'</th>'
+       .&Apache::loncommon::end_data_table_header_row();
+
+    # Display user change log data
     foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
         next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
                  ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
@@ -5231,7 +5466,14 @@ sub print_userchangelogs_display {
         }
         $count ++;
         next if ($count < $minshown);
-
+        unless ($showntableheader) {
+            $r->print($nav_script
+                     .$nav_links
+                     .&Apache::loncommon::start_data_table()
+                     .$tableheader);
+            $r->rflush();
+            $showntableheader = 1;
+        }
         if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
             $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
                 &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
@@ -5270,7 +5512,7 @@ sub print_userchangelogs_display {
         if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
             $chgcontext = $lt{$chgcontext};
         }
-        $content .=
+        $r->print(
             &Apache::loncommon::start_data_table_row()
            .'<td>'.$count.'</td>'
            .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
@@ -5281,30 +5523,34 @@ sub print_userchangelogs_display {
            .'<td>'.$chgcontext.'</td>'
            .'<td>'.$rolestart.'</td>'
            .'<td>'.$roleend.'</td>'
-           .&Apache::loncommon::end_data_table_row();
+           .&Apache::loncommon::end_data_table_row()."\n");
     }
 
-    # Form Footer
-    my $form_footer =
-        '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
-       .'<input type="hidden" name="action" value="changelogs" />'
-       .'</form>';
-
-    # Only display table, if content is available (has been collected above)
-    if (!$content) {
+    if ($showntableheader) { # Table footer, if content displayed above
+        $r->print(&Apache::loncommon::end_data_table()
+                 .$nav_links);
+    } else { # No content displayed above
         $r->print('<p class="LC_info">'
                  .&mt('There are no records to display.')
                  .'</p>'
         );
-        $r->print($form_footer);
-        return;
     }
 
-    # Content to display, so create navigation and display table
+    # Form Footer
+    $r->print( 
+        '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
+       .'<input type="hidden" name="action" value="changelogs" />'
+       .'</form>');
+    return;
+}
 
-    # Create Navigation:
-    # Navigation Script
-    my $nav_script = <<"ENDSCRIPT";
+sub userlogdisplay_nav {
+    my ($formname,$curr,$more_records) = @_;
+    my ($nav_script,$nav_links);
+    if (ref($curr) eq 'HASH') {
+        # Create Navigation:
+        # Navigation Script
+        $nav_script = <<"ENDSCRIPT";
 <script type="text/javascript">
 // <![CDATA[
 function chgPage(caller) {
@@ -5314,57 +5560,31 @@ function chgPage(caller) {
     if (caller == 'next') {
         document.$formname.page.value ++;
     }
-    document.$formname.submit(); 
+    document.$formname.submit();
     return;
 }
 // ]]>
 </script>
 ENDSCRIPT
-    # Navigation Buttons
-    my $nav_links;
-    $nav_links = '<p>';
-    if (($curr{'page'} > 1) || ($more_records)) {
-        if ($curr{'page'} > 1) {
-            $nav_links .= '<input type="button"'
-                         .' onclick="javascript:chgPage('."'previous'".');"'
-                         .' value="'.&mt('Previous [_1] changes',$curr{'show'})
-                         .'" /> ';
-        }
-        if ($more_records) {
-            $nav_links .= '<input type="button"'
-                         .' onclick="javascript:chgPage('."'next'".');"'
-                         .' value="'.&mt('Next [_1] changes',$curr{'show'})
-                         .'" />';
+        # Navigation Buttons
+        $nav_links = '<p>';
+        if (($curr->{'page'} > 1) || ($more_records)) {
+            if ($curr->{'page'} > 1) {
+                $nav_links .= '<input type="button"'
+                             .' onclick="javascript:chgPage('."'previous'".');"'
+                             .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
+                             .'" /> ';
+            }
+            if ($more_records) {
+                $nav_links .= '<input type="button"'
+                             .' onclick="javascript:chgPage('."'next'".');"'
+                             .' value="'.&mt('Next [_1] changes',$curr->{'show'})
+                             .'" />';
+            }
         }
+        $nav_links .= '</p>';
     }
-    $nav_links .= '</p>';
-
-    # Table Header
-    my $tableheader =
-        &Apache::loncommon::start_data_table_header_row()
-       .'<th>&nbsp;</th>'
-       .'<th>'.&mt('When').'</th>'
-       .'<th>'.&mt('Who made the change').'</th>'
-       .'<th>'.&mt('Changed User').'</th>'
-       .'<th>'.&mt('Role').'</th>'
-       .'<th>'.&mt('Section').'</th>'
-       .'<th>'.&mt('Context').'</th>'
-       .'<th>'.&mt('Start').'</th>'
-       .'<th>'.&mt('End').'</th>'
-       .&Apache::loncommon::end_data_table_header_row();
-
-    # Print Content
-    $r->print(
-        $nav_script
-       .$nav_links
-       .&Apache::loncommon::start_data_table()
-       .$tableheader
-       .$content
-       .&Apache::loncommon::end_data_table()
-       .$nav_links
-       .$form_footer
-    );
-    return;
+    return ($nav_script,$nav_links);
 }
 
 sub role_display_filter {
@@ -5433,16 +5653,7 @@ sub role_display_filter {
     # Update Display button
     $output .= '<p>'
               .'<input type="submit" value="'.&mt('Update Display').'" />'
-              .'</p>';
-
-    # Server version info
-    $output .= '<p class="LC_info">'
-              .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
-                  ,'2.6.99.0');
-    if ($version) {
-        $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
-    }
-    $output .= '</p><hr />';
+              .'</p><hr />';
     return $output;
 }
 
@@ -5492,7 +5703,7 @@ sub user_search_result {
     if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
         if (($srch->{'srchdomain'} eq '') || 
 	    ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
-            $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
+            $response = '<p class="LC_warning">'.&mt('You must specify a valid domain when searching in a domain or institutional directory.').'</p>';
         }
     }
     if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
@@ -5505,7 +5716,7 @@ sub user_search_result {
                 }
             }
             if ($unamecheck !~ /^$match_username$/) {
-                $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+                $response = '<p class="LC_warning">'.&mt('You must specify a valid username. Only the following are allowed: letters numbers - . @').'</p>';
             }
         }
     }
@@ -5680,7 +5891,8 @@ sub user_search_result {
                 ($currstate,$response,$forcenewuser) = 
                     &build_search_response($context,$srch,%srch_results);
             } else {
-                my $showdom = &display_domain_info($srch->{'srchdomain'});                $response = '<span class="LC_warning">'.
+                my $showdom = &display_domain_info($srch->{'srchdomain'});
+                $response = '<span class="LC_warning">'.
                     &mt('Institutional directory search is not available in domain: [_1]',$showdom).
                     '</span><br />'.
                     &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
@@ -5973,10 +6185,11 @@ sub course_level_table {
             'end'  => "End"
     );
 
-    foreach my $protectedcourse (sort( keys(%inccourses))) {
+    foreach my $protectedcourse (sort(keys(%inccourses))) {
 	my $thiscourse=$protectedcourse;
 	$thiscourse=~s:_:/:g;
 	my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
+        my $isowner = &is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
 	my $area=$coursedata{'description'};
         my $crstype=$coursedata{'type'};
 	if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
@@ -5991,9 +6204,10 @@ sub course_level_table {
         my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
 	foreach my $role (@roles) {
             my $plrole=&Apache::lonnet::plaintext($role,$crstype);
-	    if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
+	    if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
+                ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
                 $table .= &course_level_row($protectedcourse,$role,$area,$domain,
-                                            $plrole,\%sections_count,\%lt);    
+                                            $plrole,\%sections_count,\%lt);
             } elsif ($env{'request.course.sec'} ne '') {
                 if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
                                              $env{'request.course.sec'})) {
@@ -6496,6 +6710,21 @@ sub get_selfenroll_titles {
     return (\@row,\%lt);
 }
 
+sub is_courseowner {
+    my ($thiscourse,$courseowner) = @_;
+    if ($courseowner eq '') {
+        if ($env{'request.course.id'} eq $thiscourse) {
+            $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
+        }
+    }
+    if ($courseowner ne '') {
+        if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
+                return 1;
+        }
+    }
+    return;
+}
+
 #---------------------------------------------- end functions for &phase_two
 
 #--------------------------------- functions for &phase_two and &phase_three