--- loncom/interface/grouproster.pm	2006/07/02 18:01:47	1.1
+++ loncom/interface/grouproster.pm	2019/08/05 18:02:17	1.10.2.1
@@ -1,5 +1,7 @@
 # The LearningOnline Network with CAPA
 #
+# $Id: grouproster.pm,v 1.10.2.1 2019/08/05 18:02:17 raeburn Exp $
+#
 # Copyright Michigan State University Board of Trustees
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -31,6 +33,8 @@ 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/';
 
@@ -51,38 +55,49 @@ sub handler {
         return HTTP_NOT_ACCEPTABLE;
     }
 
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['group']); 
+    &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 @coursegroups = split(/:/,$env{'request.course.groups'});
-    if ((@coursegroups == 0) || ((@coursegroups > 0) && 
-                                 (!(grep/^\Q$group\E$/,@coursegroups)))) {
-        $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();
 
@@ -90,15 +105,14 @@ sub handler {
                                             '/'.$group);
     my $view_details = &Apache::lonnet::allowed('vmd',$env{'request.course.id'}.'/'.$group);
 
-    my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
+    my $viewgrps = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
     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 %coursegroups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
-    my %content = &Apache::longroup::get_group_settings($coursegroups{$group});
+    my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
     my $description = &unescape($content{'description'});
     $r->print(&roster_header($cdom,$cnum,$group,$description,$gpterm,$ucgpterm));
 
@@ -118,23 +132,54 @@ sub handler {
 
 sub roster_header {
     my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm) = @_;
+    my $refarg;
+    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/grppg",
-          text=>"$ucgpterm: $description",
-          title=>"Go to group's home page"},
-         {href=>"/adm/grouproster?group=$group",
-          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=>"$ucgpterm: $description",
+              title=>"Go to group's home page"},);
+        } else {
+            &Apache::lonhtmlcommon::add_breadcrumb
+            ({text=>"$ucgpterm: $description",});
+        }
+        &Apache::lonhtmlcommon::add_breadcrumb
+             ({href=>'/adm/grouproster?group='.$group.'&amp;'.$refarg,
+              text=>"Membership Roster",
+              title=>"Display group membership"},);
+        $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt($gpterm.' membership status - [_1]',$description));
+    }
     return $output;
 }
 
@@ -144,7 +189,7 @@ sub roster_table {
 
     my $fixedprivs = &Apache::longroup::get_fixed_privs();
 
-    my ($memberinfo,$hastools,$addtools,$numitems) = 
+    my ($memberinfo,$numitems,$hastools,$addtools) = 
         &Apache::longroup::group_memberlist($cdom,$cnum,$group,$fixedprivs,
                                             $available);
     my (%tooltype,$toolprivs);
@@ -180,8 +225,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">');
@@ -196,15 +240,20 @@ sub roster_table {
                   '<input type="submit" name="statusbutton" value="'.
                   $lt{'updi'}.'"><input type="hidden" name="sortby" value="'.
                   $env{'form.sortby'}.'"/>'.
-                  '<input type="hidden" name="group" value="'.$group.
-                  '"/></form><br /><br />');
+                  '<input type="hidden" name="group" value="'.$group.'"/>');
+        if (exists($env{'form.ref'})) {
+            $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.
+                      '" />');
+        }
+        $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] members to display in this [_2]',
-                              $key,$gpterm));
+                $r->print(&mt('There are no '.$gpterm.'s to display in this [_1].',
+                              lc($lt{$key})));
                 return;
             }
         }
@@ -213,7 +262,12 @@ 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'}.
+                  '" />');
+    }
     my %Sortby = ();
     my $usercount = 0;
     foreach my $user (sort(keys(%{$memberinfo}))) {
@@ -296,17 +350,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();