--- loncom/interface/grouproster.pm	2006/07/17 15:07:26	1.3
+++ loncom/interface/grouproster.pm	2020/09/09 00:18:04	1.10.2.2
@@ -1,5 +1,7 @@
 # The LearningOnline Network with CAPA
 #
+# $Id: grouproster.pm,v 1.10.2.2 2020/09/09 00:18:04 raeburn Exp $
+#
 # Copyright Michigan State University Board of Trustees
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -31,6 +33,7 @@ use Apache::loncommon;
 use Apache::lonhtmlcommon;
 use Apache::lonlocal;
 use Apache::longroup;
+use Apache::lonnavmaps;
 use LONCAPA;
 use Apache::Constants qw(:common :http);
 use lib '/home/httpd/lib/perl/';
@@ -52,38 +55,49 @@ sub handler {
         return HTTP_NOT_ACCEPTABLE;
     }
 
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['group','ref']); 
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+                                            ['group','ref','status']); 
 
     my $gpterm  = &Apache::loncommon::group_term();
     my $ucgpterm = $gpterm;
     $ucgpterm =~ s/^(\w)/uc($1)/e;  
     my $crstype = &Apache::loncommon::course_type();
     my $group;
+    my %curr_groups;
 
+    # Validating group input.
+    my $badinput; 
     if ((!defined($env{'form.group'})) || ($env{'form.group'} eq '')) {
-        $r->print(&mt('No [_1] name provided',$gpterm));
-                                                                                   
+        $r->print(&mt('No group name provided.').'<br />');
+        $badinput = 1;
     } else {
         $group = $env{'form.group'};
         $group =~ s/\W//g;
     }
-    if ($group eq '') {
-        $r->print(&mt('Invalid [_1] name provided',$gpterm));
+    if (!$badinput && $group eq '') {
+        $r->print(&mt('Invalid group name provided.').'<br />');
+        $badinput = 1;
     }
 
     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 
     if ($cdom eq '' || $cnum eq '') {
-        $r->print(&mt('Invalid [_1]',$crstype));
+        $r->print(&mt('Invalid [_1]',$crstype).'<br />');
+        $badinput = 1;
     }
 
-    my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
-    if (!defined($curr_groups{$group})) {
-        $r->print(&mt('[_1] is not the name of a valid [_2] in this [_3].',
-                      $group,$gpterm,lc($crstype)));
+    if (!$badinput) {
+        %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
+        if (!defined($curr_groups{$group})) {
+            $r->print(&mt('"[_1]" is not the name of a valid group in this [_2].',
+                          $group,lc($crstype)));
+            $badinput = 1;
+        }
+    }
+    if ($badinput) {
         return OK;
-    } 
+    }
 
     &Apache::lonhtmlcommon::clear_breadcrumbs();
 
@@ -95,7 +109,7 @@ sub handler {
     my $editgrps = &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
 
     if ((!$can_view) && (!$view_details) && (!$viewgrps) && (!$editgrps)) {
-        $r->print(&mt('You do not have privileges to view the membership roster in this [_1]',$gpterm));
+        $r->print(&mt('You do not have privileges to view the membership roster in this '.$gpterm.'.'));
         return OK;
     }
     my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
@@ -119,30 +133,56 @@ sub handler {
 sub roster_header {
     my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm) = @_;
     my $refarg;
-    if (exists($env{'form.ref'})) {
+    if (exists($env{'form.ref'}) && $env{'form.ref'} ne 'popup') {
         $refarg = 'ref='.$env{'form.ref'};
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>"/adm/coursegroups",
               text=>"Groups",
               title=>"View course groups"});
     }
+    my $args;
+    if ($env{'form.ref'} eq 'popup') {
+        $args = { 
+                  'no_nav_bar'    => 1,
+                  'no_inline_link' => 1,
+                };
+    }
     my $jscript = qq|
 function changeSort(caller) {
     document.grouproster.sortby.value = caller;
     document.grouproster.submit();
 }\n|;
+    my $itemtitle = &mt('Group membership status - [_1]',$description);
     my $output =
-        &Apache::loncommon::start_page(&mt('[_1] Membership ',$ucgpterm),
+        &Apache::loncommon::start_page('Group Membership',
                                        '<script type="text/javascript">'.
-                                       $jscript.'</script>');
-    &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
-          text=>"$ucgpterm: $description",
-          title=>"Go to group's home page"},
-         {href=>'/adm/grouproster?group='.$group.'&amp;'.$refarg,
-          text=>"Membership roster",
-          title=>"Display group membership"},);
-    $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] membership status - [_2]',$gpterm,$description));
+                                       $jscript.'</script>',$args);
+    if ($env{'form.ref'} eq 'popup') {
+        $output .= '<h3>'.&mt('Group membership status - [_1]',$description).
+                   '</h3>';
+    } else {
+        my $view_permission =
+            &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
+        my $navmap=Apache::lonnavmaps::navmap->new();
+        my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg);
+        if ($grouppagelink) {
+            &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>$grouppagelink,
+              text=>&mt('Group').": $description",
+              title=>&mt("Go to group's home page"),
+              no_mt=>1},);
+        } else {
+            &Apache::lonhtmlcommon::add_breadcrumb
+            ({text=>&mt('Group').": $description",
+              no_mt=>1});
+        }
+        &Apache::lonhtmlcommon::add_breadcrumb
+             ({href=>'/adm/grouproster?group='.$group.'&amp;'.$refarg,
+              text=>"Membership Roster",
+              title=>"Display group membership"},);
+        $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group membership status - [_1]',$description),
+                                                       undef,undef,undef,undef,1);
+    }
     return $output;
 }
 
@@ -188,8 +228,7 @@ sub roster_table {
     if (($viewgrps) || ($editgrps) || 
         (&Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group))) {
         if (keys(%{$memberinfo}) == 0) {
-            $r->print(&mt('There are no membership data to display for this [_1]',
-                      $gpterm));  
+            $r->print(&mt('There are no membership data to display for this '.$gpterm.'.'));  
             return;  
         }  
         $r->print('<br /><form name="rosterstatus" method="post" action="/adm/grouproster">'.&mt('Membership status: ').'<select name="status">');
@@ -209,14 +248,15 @@ sub roster_table {
             $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.
                       '" />');
         }
-        $r->print('</form><br /><br />');
+        $r->print('</form><br />');
 
     }
+    $r->print('<br />');
     if (ref($numitems) eq 'HASH') {
         foreach my $key (keys(%{$numitems})) {
             if ($status eq $key && !$$numitems{$key}) {
-                $r->print(&mt('There are no [_1]s to display in this [_2].',
-                              lc($lt{$key}),$gpterm));
+                $r->print(&mt('There are no '.$gpterm.'s to display in this [_1].',
+                              lc($lt{$key})));
                 return;
             }
         }
@@ -225,6 +265,7 @@ sub roster_table {
 <form name="grouproster" action="/adm/grouproster" method="post">
  <input type="hidden" name="group" value="'.$group.'" />
  <input type="hidden" name="sortby" value="'.$env{'form.sortby'}.'" />
+ <input type="hidden" name="status" value="'.$status.'" />
 ');
     if (exists($env{'form.ref'})) {
         $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.
@@ -312,17 +353,19 @@ sub members_table_row {
             my $curr_tool;
             my $privlist;
             foreach my $priv (@{$$userinfo{'privs'}}) {
-                unless ($curr_tool eq $$tooltype{$priv}) {
-                    $curr_tool = $$tooltype{$priv};
-                    $privlist .= '<b>'.$curr_tool.'</b>: ';
+                if (defined($$tooltype{$priv})) {
+                    if ($curr_tool ne $$tooltype{$priv}) {
+                        $curr_tool = $$tooltype{$priv};
+                        $privlist .= '<b>'.$curr_tool.'</b>: ';
+                    }
+                    $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
                 }
-                $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
             }
             $privlist =~ s/, $//;
             $output .= '<td>'.$privlist.'</td>';
         } elsif ($view_details) {
-            $output .= '<td><nobr>'.join('&nbsp;&nbsp;&nbsp;',
-                      @{$$userinfo{'currtools'}}).'</nobr></td>';
+            $output .= '<td><span class="LC_nobreak">'.join('&nbsp;&nbsp;&nbsp;',
+                      @{$$userinfo{'currtools'}}).'</span></td>';
         }
     }
     $output .= &Apache::loncommon::end_data_table_row();