[LON-CAPA-cvs] cvs: loncom /interface loncoursegroups.pm longroup.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 28 Jul 2006 18:44:27 -0000


raeburn		Fri Jul 28 14:44:27 2006 EDT

  Modified files:              
    /loncom/interface	longroup.pm loncoursegroups.pm 
  Log:
  Custom roles can now be used in automated group memebership adds and drops.
  
  
Index: loncom/interface/longroup.pm
diff -u loncom/interface/longroup.pm:1.10 loncom/interface/longroup.pm:1.11
--- loncom/interface/longroup.pm:1.10	Mon Jul 17 11:07:26 2006
+++ loncom/interface/longroup.pm	Fri Jul 28 14:44:27 2006
@@ -232,6 +232,9 @@
     my $courseid = $cid;
     $courseid =~ s|^/||;
     $courseid =~ s|/|_|;
+    if ($role =~ /^cr/) {
+        $role =~ s/\//_/g;
+    }
     my %crshash=&Apache::lonnet::coursedescription($cid);
     $cdom = $crshash{'domain'};
     $cnum = $crshash{'num'};
Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.57 loncom/interface/loncoursegroups.pm:1.58
--- loncom/interface/loncoursegroups.pm:1.57	Thu Jul 20 22:51:31 2006
+++ loncom/interface/loncoursegroups.pm	Fri Jul 28 14:44:27 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursegroups.pm,v 1.57 2006/07/21 02:51:31 raeburn Exp $
+# $Id: loncoursegroups.pm,v 1.58 2006/07/28 18:44:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -965,6 +965,7 @@
 	foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) {
             if (ref($groupinfo{'autosec'}{$role}) eq 'ARRAY') {
 	        foreach my $section (@{$groupinfo{'autosec'}{$role}}) {
+
 	            push (@{$stored{'sec_'.$role}},$section);
 	        }
 	        if (@{$groupinfo{'autosec'}{$role}} > 0) {
@@ -1206,7 +1207,7 @@
 			       $gpterm,$ucgpterm);
         &mapping_options($r,$action,$formname,$page,$sectioncount,
                          $states,$stored,$navbuttons,4,5,
-			 $gpterm,$ucgpterm,$crstype);
+			 $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
         $nexttext = $$navbuttons{'mose'};
     }
     $prevtext = $$navbuttons{'gtpp'};
@@ -2413,7 +2414,7 @@
         my $img2 = 8;
         &mapping_options($r,$action,$formname,$page,$sectioncount,
                          $states,$stored,$navbuttons,$img1,$img2,
-                         $gpterm,$ucgpterm,$crstype);
+                         $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
     }
     my $prevtext = $$navbuttons{'gtps'};
     &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
@@ -3077,7 +3078,7 @@
 
 sub mapping_options {
     my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
-        $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype) = @_;
+        $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
     my %lt = &Apache::lonlocal::texthash(
         'auto' => "Settings for automatic $gpterm enrollment",
         'gmma' => "$ucgpterm membership mapping to specific sections/roles",
@@ -3094,7 +3095,8 @@
         'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
     );
     &automapping($r,$action,$stored,\%lt,$img1);
-    &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype);
+    &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
+                      $action);
     return;
 }
 
@@ -3127,7 +3129,7 @@
 }
 
 sub mapping_settings {
-    my ($r,$sectioncount,$lt,$stored,$image,$crstype) = @_;
+    my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
     my @sections = keys(%{$sectioncount});
     if (@sections > 0) {
         @sections = sort {$a cmp $b} @sections;
@@ -3138,7 +3140,7 @@
     }
     &topic_bar($r,$image,$$lt{'pirs'});
     my @roles = &standard_roles();
-    my %customroles = &my_custom_roles();
+    my %customroles = &course_custom_roles($cdom,$cnum);
     $r->print(&Apache::loncommon::start_data_table().
 	      &Apache::loncommon::start_data_table_header_row());
     $r->print('
@@ -3149,52 +3151,73 @@
     }
     $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
     foreach my $role (@roles) {
-        my $plrole=&Apache::lonnet::plaintext($role,$crstype);
-        my $sections_sel;
-        if (@sections > 0) {
-            if ($role eq 'cc') {
-                $sections_sel = '<td align="right">'.
-                                &mt('all sections').'<input type="hidden" '. 
-                                'name="sec_cc" value="all" /></td>';
-            } else { 
-                $sections_sel='<td align="right">'.
-                              &sections_selection(\@sections,'sec_'.$role).
-                              '</td>';
-            }
-        }
-        $r->print(&Apache::loncommon::start_data_table_row().
-		  '<td><input type="checkbox" '.
-                  'name="autorole" value="'.$role.'" /></td><td>'.$plrole.
-                  '</td>'.$sections_sel.
-		  &Apache::loncommon::end_data_table_row());
+        my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
+        $r->print(&print_autorole_item($role,$roletitle,\@sections));
     }
+    my @customs;
     foreach my $role (sort(keys(%customroles))) {
-        my $sections_sel;
-        if (@sections > 0) {
-            $sections_sel = 
-		'<td>'.&sections_selection(\@sections,'sec_'.$role).'</td>';
-        }
-        $r->print(&Apache::loncommon::start_data_table_row().
-		  '<td><input type="checkbox" '.
-                  'value="'.$role.'" /></td><td>'.&mt('Custom role: ').
-                  '<i>'.$role.'</i></td>'.$sections_sel.
-		  &Apache::loncommon::end_data_table_row());
+        my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
+        $role =~ s/\//_/g;
+        push (@customs,$role);
+        $r->print(&print_autorole_item($role,$roletitle,\@sections));
+    }
+    if ($action eq 'modify') {
+        foreach my $role (@{$$stored{'autorole'}}) {
+            if ((!grep(/^\Q$role\E$/,@customs)) && 
+                (!grep(/^\Q$role\E$/,@roles))) {
+                my $roletitle;
+                if ($role =~ /^cr/) {
+                    ($roletitle) = ($role =~ m|_([^_]+)$|);
+                } else {
+                    $roletitle = &Apache::lonnet::plaintext($role,$crstype);
+                }
+                $r->print(&print_autorole_item($role,$roletitle,\@sections));
+            }
+        }
     }
     $r->print(&Apache::loncommon::end_data_table());
     return;
 }
 
+sub print_autorole_item {
+    my ($role,$roletitle,$sections) = @_;
+    my $sections_sel;
+    if (@{$sections} > 0) {
+        if ($role eq 'cc') {
+            $sections_sel = '<td align="right">'.
+                            &mt('all sections').'<input type="hidden" '.
+                            'name="sec_cc" value="all" /></td>';
+        } else {
+            $sections_sel='<td align="right">'.
+                          &sections_selection($sections,'sec_'.$role).
+                          '</td>';
+        }
+    }
+    my $output = &Apache::loncommon::start_data_table_row().
+                 '<td><input type="checkbox" '.
+                 'name="autorole" value="'.$role.'" />'.
+                 '</td><td>'.$roletitle.'</td>'.$sections_sel.
+                 &Apache::loncommon::end_data_table_row();
+    return $output;
+} 
+
 sub standard_roles {
     my @roles = ('cc','in','ta','ep','st');
     return @roles;
 }
 
-sub my_custom_roles {
+sub course_custom_roles {
+    my ($cdom,$cnum) = @_;
     my %returnhash=();
-    my %rolehash=&Apache::lonnet::dump('roles');
-    foreach (keys %rolehash) {
-        if ($_=~/^rolesdef\_(\w+)$/) {
-            $returnhash{$1}=$1;
+    my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
+    foreach my $person (sort(keys(%coursepersonnel))) {
+        my ($role) = ($person =~ /^([^:]+):/);
+        my ($end,$start) = split(/:/,$coursepersonnel{$person});
+        if ($end == -1 && $start == -1) {
+            next;
+        }
+        if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
+            $returnhash{$role} ++;
         }
     }
     return %returnhash;