--- loncom/interface/loncoursegroups.pm	2009/11/06 19:49:26	1.104
+++ loncom/interface/loncoursegroups.pm	2012/12/17 17:27:20	1.116
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursegroups.pm,v 1.104 2009/11/06 19:49:26 raeburn Exp $
+# $Id: loncoursegroups.pm,v 1.116 2012/12/17 17:27:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -135,7 +135,7 @@ function changeSort(caller) {
 function openGroupRoster(group,status) {
     var url = '/adm/grouproster?';
     url += 'group='+group+'&status='+status+'&ref=popup';
-    var title = 'Group Membership';
+    var title = 'Group_Membership';
     var options = 'scrollbars=1,resizable=1,menubar=0';
     options += ',width=700,height=600';
     rosterbrowser = open(url,title,options,'1');
@@ -170,7 +170,7 @@ sub display_groups {
     my %actionlinks = (
       modify => '<a href="/adm/coursegroups?action=modify&refpage='.
                          $env{'form.refpage'}.'&state=pick_task&groupname=',
-      view => '<a href="/adm/'.$cdom.'/'.$cnum.'/',
+      view => '<a href="',
       delete => '<a href="/adm/coursegroups?action=delete&refpage='.
                          $env{'form.refpage'}.'&state=verify&groupname=',
       reenable => '<a href="/adm/coursegroups?action=reenable&refpage='.
@@ -221,6 +221,14 @@ sub display_groups {
                                                           $status);
 
         if (%curr_groups) {
+            my $navmap=Apache::lonnavmaps::navmap->new();
+            if (!defined($navmap)) {
+                $r->print('<div class="LC_error">'.
+                          &mt('An error occurred retrieving information about resources in the course.').'<br />'.
+                          &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this page.','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'&orgurl=%2fadm%2fcoursegroups">','</a>').
+                          '</div>');
+                return;
+            }
             if ($manage_permission) {
                 if ($action ne 'reenable') {
                     $r->print('<br /><a href="/adm/coursegroups?action=create&amp;refpage='.$env{'form.refpage'}.'">'.$lt{'crng'}.'</a>');
@@ -324,7 +332,9 @@ END
                         $action eq 'reenable') {
                         $link .= $group;
                     } else {
-                        $link .= $group.'/smppg?ref=grouplist';
+                        $link .= 
+                            &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap);
+                        $link .= (($link=~/\?/)?'&amp;':'?').'ref=grouplist';
                         if (exists($env{'form.refpage'})) {
                             $link .= '&amp;refpage='.$env{'form.refpage'};
                         }
@@ -386,16 +396,32 @@ END
             $r->print('<br /><br />');
             my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
             if (%curr_groups) {
+                my $navmap=Apache::lonnavmaps::navmap->new();
+                if (!defined($navmap)) {
+                    $r->print('<div class="LC_error">'.
+                              &mt('An error occurred retrieving information about resources in the course.').'<br />'.
+                              &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this page.','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'&orgurl=%2fadm%2fcoursegroups">','</a>').
+                              '</div>');
+                    return;
+                }
                 foreach my $group (@coursegroups) {
                     my %group_info =  &Apache::longroup::get_group_settings(
                                         $curr_groups{$group});
                     my $description = &unescape(
                                         $group_info{description});
-                    $r->print('<font size="+1"><a href="/adm/'.$cdom.'/'.$cnum.'/'.$group.'/smppg?ref=grouplist">'.$group,'</a><font><br /><small>'.$description.'</small><br /><br />');
+                    my $link = 
+                        &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap).
+                        '&amp;ref=grouplist';
+                    $r->print('<span style="font-size: larger"><a href="'.$link.'">'.$group,'</a></span><br /><small>'.$description.'</small><br /><br />');
                 }
             }
         } else {
-            $r->print(&mt('You are not currently a member of any active '.$gpterm.'s in this '.lc($crstype).'.'));
+            $r->print(
+                '<p class="LC_info">'
+               .&mt('You are not currently a member of any active '.$gpterm.'s'
+                   .' in this '.lc($crstype).'.')
+               .'</p>'
+            );
         }
     }
     return;
@@ -1210,12 +1236,12 @@ sub delete_group {
         if ($result eq 'ok') {
             my $outcome = &modify_folders($cdom,$cnum,$groupname,$crstype);
             if ($outcome eq '') {
-                $r->print('<div class="LC_success">'
-                         .&mt('Group successfully deleted.')
-                         .'</div>');
+                my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Group successfully deleted.'));
+                $message = &Apache::loncommon::confirmwrapper($message);
+                $r->print($message);
             } else {
                 $r->print('<div class="LC_error">');
-                if ($crstype eq 'Comunity') {
+                if ($crstype eq 'Community') {
                     $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Community Groups' folder: [_1]",$outcome));
                 } else {
                     $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Course Groups' folder: [_1]",$outcome));
@@ -1223,9 +1249,9 @@ sub delete_group {
                 $r->print('</div>');
             }
         } else {
-            $r->print('<div class="LC_error">'
-                     .&mt('Group deletion failed.')
-                     .'</div>');
+            my $msg = &Apache::lonhtmlcommon::confirm_success(&mt('Group deletion failed.'),1);
+            $msg = &Apache::loncommon::confirmwrapper($msg);
+            $r->print($msg);
         }
     }
     return;
@@ -1255,7 +1281,7 @@ sub reenable_folder {
         $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
                                          ':false:normal:res';
         $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
-        my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1);
+        my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1,1);
         if ($errtext) {
             $outcome='<div class="LC_error">'
                     .&mt('An error occurred when saving updated parent folder to group:'
@@ -1320,7 +1346,7 @@ sub modify_folders {
                     $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
                 }
                 $#LONCAPA::map::order--;
-                my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
+                my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1);
                 if ($errtext) {
                     $outcome='<div class="LC_error">'
                             .&mt('An error occurred when saving updated parent folder to group:')
@@ -1437,12 +1463,12 @@ $context) eq 'ok') {
         }
         my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description,$crstype);
         if ($outcome eq '') {
-            $r->print('<div class="LC_success">'
-                     .&mt('Group successfully re-enabled.')
-                     .'</div>');
+            my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Group successfully re-enabled.'));
+            $message = &Apache::loncommon::confirmwrapper($message);
+            $r->print($message);
         } else {
             $r->print('<div class="LC_error">');
-            if ($crstype eq 'Comunity') {
+            if ($crstype eq 'Community') {
                 $r->print(&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Community Groups' folder: [_1]",$outcome));
             } else {
                 $r->print(&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Course Groups' folder: [_1]",$outcome));
@@ -1450,9 +1476,9 @@ $context) eq 'ok') {
             $r->print('</div>');
         }
     } else {
-        $r->print('<div class="LC_error">'
-                 .&mt('Re-enabling group failed.')
-                 .'</div>');
+        my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling group failed.'),1);
+        $message = &Apache::loncommon::confirmwrapper($message);
+        $r->print($message);
     }
     return;
 }
@@ -1526,16 +1552,19 @@ sub build_members_list {
 sub group_files {
     my ($group,$portpath,$numfiles,$numdirs) = @_;
     my $dirptr=16384;
-    my @dir_list=&Apache::portfolio::get_dir_list($portpath,undef,$group);
-    foreach my $line (@dir_list) {
-        my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
-        if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) { 
-            if ($dirptr&$testdir) {
-                $portpath .= '/'.$filename;
-                $$numdirs ++;
-                &group_files($group,$portpath,$numfiles,$numdirs)
-            } else {
-                $$numfiles ++;
+    my ($dirlistref,$listerror) = 
+        &Apache::portfolio::get_dir_list($portpath,undef,$group);
+    if (ref($dirlistref) eq 'ARRAY') {
+        foreach my $line (@{$dirlistref}) {
+            my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
+            if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) { 
+                if ($dirptr&$testdir) {
+                    $portpath .= '/'.$filename;
+                    $$numdirs ++;
+                    &group_files($group,$portpath,$numfiles,$numdirs)
+                } else {
+                    $$numfiles ++;
+                }
             }
         }
     }
@@ -1774,7 +1803,6 @@ sub membership_options {
                 'picr' => 'Pick the criteria to use to build a list of course users from which you will select members of the new group.',
                 'pica' => 'Pick the criteria to use to build a list of course users from which you will select additional members of the group.',
                 'ifno' => 'If you do not wish to add members when you first create the group, there is no need to pick any criteria.', 
-                'asub' => 'A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section <i>changes</i> in the course.',
                 'acty' => 'Access types',
                 'coro' => 'Course roles',
                 'cose' => 'Course sections',
@@ -2231,11 +2259,12 @@ sub privilege_specificity {
                 "for users who receive specific sections/roles in the course ",
       'asyo' => "As you have chosen not to include any collaborative tools ".
                 "in the group, no default optional privileges need to be set.",
-      'plin' => 'Indicate which <b>optional</b> privileges members '.
                 'will receive by default for a specific tool.',
       'oppr' => 'Optional privileges',
       'defp' => 'The default privileges new members will receive are:', 
     );
+    $lt{'plin'} = &mt('Indicate which [_1]optional[_2] privileges members '.
+                      'will receive by default for a specific tool.','<b>','</b>');
     if ($crstype eq 'Community') {
         $lt{'thes'} = &mt('These will be the privileges given to members assigned in the future via automatic group assignment for users who receive specific sections/roles in the community '); 
     }
@@ -2337,9 +2366,9 @@ sub default_privileges {
 	      &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
      						'LC_groups_functionality'));
     my @tableHeader;
-    foreach my $key (sort(keys(%{$functions}))){
-        push (@tableHeader,&mt($functions->{$key}));
-    }   
+    if ((ref($functions) eq 'HASH') && (ref($tools) eq 'ARRAY')) {
+        @tableHeader = map { $functions->{$_}; } @{$tools};
+    }
  $r->print(join('</td><td class="LC_groups_functionality">', @tableHeader));
     $r->print(&Apache::lonhtmlcommon::row_closure(1));
     my $fixed = '';
@@ -3244,15 +3273,15 @@ sub write_group_data {
                                            $description,$tools,\%groupinfo,
                                            $gpterm,$ucgpterm,$crstype);
             if ($result eq 'ok') {
-                $r->print('<div class="LC_success">'
-                         .&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>')
-                         .'</div>');
+                my $msg = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>'));
+                $msg = &Apache::loncommon::confirmwrapper($msg);
+                $r->print($msg);
             } else {
-                $r->print('<div class="LC_error">'
-                         .&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
-                             ,'<i>'.$groupname.'</i>')
-                         .'<br />'.$result
-                         .'</div>');
+                my $msg = &Apache::lonhtmlcommon::confirm_success(&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
+                                                                     ,'<i>'.$groupname.'</i>')
+                                                                     .'<br />'.$result,1);
+                $msg = &Apache::loncommon::confirmwrapper($msg);
+                $r->print($msg);
             }
         } elsif ($action eq 'modify') {
             my (@oldtools,@newtools); 
@@ -3323,9 +3352,9 @@ sub write_group_data {
                     $r->print('<div class="LC_error">'.$error.'</div>');
                 }
             }
-            $r->print('<div class="LC_success">'
-                     .&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>')
-                     .'</div>');
+            my $message = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>'));
+            $message = &Apache::loncommon::confirmwrapper($message);
+            $r->print($message);
         }
     } else {
         my %actiontype = (
@@ -3503,12 +3532,13 @@ sub process_membership {
     my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
                                                        $cnum,\%usersettings);
     if ($num_ok) {
-        foreach my $type (sort(keys(%added))) { 
-            $r->print(&mt('The following users were successfully [_1]',$type));
+        my $msgall ='';
+        foreach my $type (sort(keys(%added))) {
+            my $message = &mt('The following users were successfully [_1]',$type); 
             if (!($type eq 'deleted' || $type eq 'expired')) {   
-                $r->print(&mt(' with the following privileges'));
+                $message .= &mt(' with the following privileges');
             }
-            $r->print(':<br />');
+            $message .= ':<br/>';
             foreach my $user (@{$added{$type}}) {
                 my $privlist = '';
                 if (!($type eq 'deleted' ||  $type eq 'expired')) {
@@ -3524,10 +3554,14 @@ sub process_membership {
                     }
                     $privlist =~ s/, $//;
                 }
-                $r->print($$userdata{$user}[$$idx{fullname}].'&nbsp;-&nbsp;'.$user.$privlist.'<br />');
+                $message .= $$userdata{$user}[$$idx{fullname}].'&nbsp;-&nbsp;'.$user.$privlist.'<br />';
             }
-            $r->print('<br />');
+            $message .= '<br/>';
+            $message = &Apache::lonhtmlcommon::confirm_success($message);
+            $msgall .= $message;
         }
+        $msgall = &Apache::loncommon::confirmwrapper($msgall);
+        $r->print($msgall);
     }
     if ($num_fail) {
         foreach my $type (sort(keys(%failed))) {
@@ -3540,13 +3574,15 @@ sub process_membership {
         }
         $r->print('<br />');
     }
-    if (@unchanged > 0) {
-        $r->print(&mt('No change occurred for the following users:').'<br />');
-        foreach my $user (sort(@unchanged)) {
-            $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
-        }
-        $r->print('<br />');
-    }
+# Is that really needed?
+#
+#    if (@unchanged > 0) {
+#        $r->print(&mt('No change occurred for the following users:').'<br />');
+#        foreach my $user (sort(@unchanged)) {
+#            $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
+#        }
+#        $r->print('<br />');
+#    }
     if ($roster_result eq 'ok') {
         $r->print('<div class="LC_success">'
                  .&mt($ucgpterm.' membership list updated.')
@@ -3710,36 +3746,32 @@ sub standard_roles {
 sub modify_menu {
     my ($r,$groupname,$page,$gpterm) = @_;
     my @menu =
-        (
-          { text => "Modify default $gpterm settings",
-            help => 'Course_Modify_Group',
-            state => 'change_settings',
-            branch => 'settings',
+        ( { categorytitle =>'Group Actions',
+	items => [
+
+          { linktext => "Modify default $gpterm settings",
+            url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_settings&branch=settings',
+            icon => 'grp_settings.png',
+            alttext => "Modify default $gpterm settings",
+            permission => '1',
+            help => 'Course_Modify_Group',            
             },
-          { text => 'Modify access, tools and/or privileges for previous, '.
-                    'future, or current members',
+          { linktext => 'Modify access, tools and privileges for members',
+            url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_members&branch=members',
+            icon => 'grp_tools.png',
+            alttext => 'Modify access, tools and privileges for members',
+            permission => '1',
             help => 'Course_Modify_Group_Membership',
-            state => 'change_members',
-            branch => 'members',
             },
-          { text => "Add member(s) to the $gpterm",
+          { linktext => "Add member(s) to the $gpterm",
+            url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=add_members&branch=adds',
+            icon => 'grp_add.png',
+            alttext =>  "Add member(s) to the $gpterm",
+            permission => '1',
             help => 'Course_Group_Add_Members',
-            state => 'add_members',
-            branch => 'adds',
-            },
-          );
-    my $menu_html = '';
-    foreach my $menu_item (@menu) {
-        $menu_html .=
-        '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
-        $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
-        if (exists($menu_item->{'help'})) {
-            $menu_html.=
-                &Apache::loncommon::help_open_topic($menu_item->{'help'});
-        }
-        $menu_html.='</p>'.$/;
-    }
-    $r->print($menu_html);
+            }]}
+          );   
+    $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
     return;
 }
 
@@ -4007,7 +4039,7 @@ sub map_updater {
         $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
                                                  ':false:normal:res';
         $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
-        my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
+        my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1,1);
         if ($errtext) {
             $outcome = '<div class="LC_error">'
                       .&mt('Error saving updated parent folder.')." ($parentmap):  $errtext"
@@ -4232,3 +4264,4 @@ sub check_changes {
 }
 
 1;
+