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

raeburn lon-capa-cvs@mail.lon-capa.org
Sat, 29 Jul 2006 00:32:00 -0000


This is a MIME encoded message

--raeburn1154133120
Content-Type: text/plain

raeburn		Fri Jul 28 20:32:00 2006 EDT

  Modified files:              
    /loncom/interface	loncoursegroups.pm longroup.pm lonhtmlcommon.pm 
                     	loncommon.pm 
  Log:
  Bug 4943.  Can now include custom roles used in course to build list of course users from which group members are selected.  Also form element names can now contain non-alpha characters without breaking SetFormElements() javascript by referring to elements as formName.elements['name'] etc.  Need to rewrite any / in custom role as _ has been eliminated (so conversion no longer required for autosec records in coursegroup.db). 
  
  
--raeburn1154133120
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060728203200.txt"

Index: loncom/interface/loncoursegroups.pm
diff -u loncom/interface/loncoursegroups.pm:1.58 loncom/interface/loncoursegroups.pm:1.59
--- loncom/interface/loncoursegroups.pm:1.58	Fri Jul 28 14:44:27 2006
+++ loncom/interface/loncoursegroups.pm	Fri Jul 28 20:31:58 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursegroups.pm,v 1.58 2006/07/28 18:44:27 raeburn Exp $
+# $Id: loncoursegroups.pm,v 1.59 2006/07/29 00:31:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1027,7 +1027,7 @@
                                  $userdata,$granularity,$quota,$specificity,
                                  $idx,$states,$navbuttons,$gpterm,$ucgpterm);
         } elsif ($state eq 'add_members') {
-            &add_members_form($r,$action,$state,$page,$startdate,
+            &add_members_form($r,$cdom,$cnum,$action,$state,$page,$startdate,
                               $enddate,$groupname,$description,$granularity,
                               $quota,$sectioncount,$tools,$functions,$stored,
                               $states,$navbuttons,$gpterm,$ucgpterm);
@@ -1194,8 +1194,8 @@
                            $gpterm,$ucgpterm,$crstype);
     &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
     if ($action eq 'create') {
-        &membership_options($r,$action,$formname,$sectioncount,3,$gpterm,
-			    $ucgpterm);
+        &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,3,
+                            $gpterm,$ucgpterm);
         $nexttext = $$navbuttons{'gtns'};
     } else {
         my @available = ();
@@ -1343,7 +1343,7 @@
 }
 
 sub membership_options {
-    my ($r,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm) = @_;
+    my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm)=@_;
     my $crstype = &Apache::loncommon::course_type();
     my %lt = &Apache::lonlocal::texthash(
                 'pipa' => 'Build a list of users for selection of group members',
@@ -1365,8 +1365,7 @@
                    future => &mt('Will have future access'),
                    );
 
-    #FIXME need to plumb around for the various cr roles defined by the user
-    my @roles = ('st','cc','in','ta','ep');
+    my @roles = ('st','cc','in','ta','ep','cr');
 
     my @sections = keys(%{$sectioncount});
 
@@ -1389,7 +1388,7 @@
       </tr><tr><td>');
     $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
     $r->print('</td><td>');
-    $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles));
+    $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
     if (@sections > 0) {
         @sections = sort {$a cmp $b} @sections;
         unshift(@sections,'none'); # Put 'no sections' next
@@ -2364,7 +2363,7 @@
 }
 
 sub add_members_form {
-    my ($r,$action,$formname,$page,$startdate,$enddate,$groupname,
+    my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
         $description,$granularity,$quota,$sectioncount,$tools,$functions,
         $stored,$states,$navbuttons,$gpterm,$ucgpterm)=@_; 
     $r->print(' <br />');
@@ -2374,7 +2373,8 @@
     &print_current_settings($r,$action,$functions,$startdate,$enddate,
 			    $groupname,$description,$granularity,$quota,
 			    \@available,\@unavailable,$gpterm,$ucgpterm);
-    &membership_options($r,$action,$formname,$sectioncount,1,$gpterm,$ucgpterm);
+    &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
+                        $ucgpterm);
     my $nexttext = $$navbuttons{'gtns'};
     my $prevtext = $$navbuttons{'gtpp'};
     &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
@@ -3140,7 +3140,7 @@
     }
     &topic_bar($r,$image,$$lt{'pirs'});
     my @roles = &standard_roles();
-    my %customroles = &course_custom_roles($cdom,$cnum);
+    my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
     $r->print(&Apache::loncommon::start_data_table().
 	      &Apache::loncommon::start_data_table_header_row());
     $r->print('
@@ -3157,7 +3157,6 @@
     my @customs;
     foreach my $role (sort(keys(%customroles))) {
         my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
-        $role =~ s/\//_/g;
         push (@customs,$role);
         $r->print(&print_autorole_item($role,$roletitle,\@sections));
     }
@@ -3206,23 +3205,6 @@
     return @roles;
 }
 
-sub course_custom_roles {
-    my ($cdom,$cnum) = @_;
-    my %returnhash=();
-    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;
-}
-
 sub modify_menu {
     my ($r,$groupname,$page,$gpterm) = @_;
     my @menu =
Index: loncom/interface/longroup.pm
diff -u loncom/interface/longroup.pm:1.11 loncom/interface/longroup.pm:1.12
--- loncom/interface/longroup.pm:1.11	Fri Jul 28 14:44:27 2006
+++ loncom/interface/longroup.pm	Fri Jul 28 20:31:58 2006
@@ -232,9 +232,6 @@
     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/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.146 loncom/interface/lonhtmlcommon.pm:1.147
--- loncom/interface/lonhtmlcommon.pm:1.146	Thu Jul 27 18:27:08 2006
+++ loncom/interface/lonhtmlcommon.pm	Fri Jul 28 20:31:58 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.146 2006/07/27 22:27:08 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.147 2006/07/29 00:31:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1418,7 +1418,7 @@
 }
 
 sub role_select_row {
-    my ($roles,$title,$css_class) = @_;
+    my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
     my $output;
     if (defined($title)) {
         $output = &row_title($title,$css_class);
@@ -1429,10 +1429,25 @@
         my $plrole;
         if ($role eq 'ow') {
             $plrole = &mt('Course Owner');
+        } elsif ($role eq 'cr') {
+            if ($show_separate_custom) {
+                if ($cdom ne '' && $cnum ne '') {
+                    my %course_customroles = &course_custom_roles($cdom,$cnum);
+                    foreach my $crrole (sort(keys(%course_customroles))) {
+                        my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
+                        $output .= '  <option value="'.$crrole.'">'.$plcrrole.
+                                   '</option>';
+                    }
+                }
+            } else {
+                $plrole = &mt('Custom Role');
+            }
         } else {
             $plrole=&Apache::lonnet::plaintext($role);
         }
-        $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
+        if (($role ne 'cr') || (!$show_separate_custom)) {
+            $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
+        }
     }
     $output .= qq|                </select>\n|;
     if (defined($title)) {
@@ -1585,6 +1600,24 @@
     return $output;
 }
 
+sub course_custom_roles {
+    my ($cdom,$cnum) = @_;
+    my %returnhash=();
+    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;
+}
+
+
 ##############################################
 ##############################################
                                                                              
@@ -1723,66 +1756,66 @@
                 my $valuestring = join('","',@{$values{$name}});
                 $output .= qq|
   var textvalues = new Array ("$valuestring");
-  var total = courseForm.$name.length;
+  var total = courseForm.elements['$name'].length;
   if (total > $numvalues) {
       total = $numvalues;
   }    
   for (var i=0; i<total; i++) {
-      courseForm.$name\[i].value = textvalues[i];
+      courseForm.elements['$name']\[i].value = textvalues[i];
   }
 |;
             } else {
                 $output .= qq|
-  courseForm.$name.value = "$values{$name}[0]";
+  courseForm.elements['$name'].value = "$values{$name}[0]";
 |;
             }
         } else {
             $output .=  qq|
-  var elementLength = courseForm.$name.length;
+  var elementLength = courseForm.elements['$name'].length;
   if (elementLength==undefined) {
 |;
             foreach my $value (@{$values{$name}}) {
                 if ($$elements{$name} eq 'selectbox') {
                     $output .=  qq|
-      if (courseForm.$name.options[0].value == "$value") {
-          courseForm.$name.options[0].selected = true;
+      if (courseForm.elements['$name'].options[0].value == "$value") {
+          courseForm.elements['$name'].options[0].selected = true;
       }|;
                 } elsif (($$elements{$name} eq 'radio') ||
                          ($$elements{$name} eq 'checkbox')) {
                     $output .= qq|
-      if (courseForm.$name.value == "$value") {
-          courseForm.$name.checked = true;
+      if (courseForm.elements['$name'].value == "$value") {
+          courseForm.elemenst['$name'].checked = true;
       }|;
                 }
             }
             $output .= qq|
   }
   else {
-      for (var i=0; i<courseForm.$name.length; i++) {
+      for (var i=0; i<courseForm.elements['$name'].length; i++) {
 |;
             if ($$elements{$name} eq 'selectbox') {
                 $output .=  qq|
-          courseForm.$name.options[i].selected = false;|;
+          courseForm.elements['$name'].options[i].selected = false;|;
             } elsif (($$elements{$name} eq 'radio') || 
                      ($$elements{$name} eq 'checkbox')) {
                 $output .= qq|
-          courseForm.$name\[i].checked = false;|; 
+          courseForm.elements['$name']\[i].checked = false;|; 
             }
             $output .= qq|
       }
-      for (var j=0; j<courseForm.$name.length; j++) {
+      for (var j=0; j<courseForm.elements['$name'].length; j++) {
 |;
             foreach my $value (@{$values{$name}}) {
                 if ($$elements{$name} eq 'selectbox') {
                     $output .=  qq|
-          if (courseForm.$name.options[j].value == "$value") {
-              courseForm.$name.options[j].selected = true;
+          if (courseForm.elements['$name'].options[j].value == "$value") {
+              courseForm.elements['$name'].options[j].selected = true;
           }|;
                 } elsif (($$elements{$name} eq 'radio') ||
                          ($$elements{$name} eq 'checkbox')) { 
                       $output .= qq|
-          if (courseForm.$name\[j].value == "$value") {
-              courseForm.$name\[j].checked = true;
+          if (courseForm.elements['$name']\[j].value == "$value") {
+              courseForm.elements['$name']\[j].checked = true;
           }|;
                 }
             }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.438 loncom/interface/loncommon.pm:1.439
--- loncom/interface/loncommon.pm:1.438	Fri Jul 28 02:09:34 2006
+++ loncom/interface/loncommon.pm	Fri Jul 28 20:31:58 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.438 2006/07/28 06:09:34 albertel Exp $
+# $Id: loncommon.pm,v 1.439 2006/07/29 00:31:58 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4342,13 +4342,20 @@
         }
     }
     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
-        my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$cdom,$cnum);
-        foreach my $person (@coursepersonnel) {
+        my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
+        my $now = time;
+        foreach my $person (sort(keys(%coursepersonnel))) {
             my $match = 0;
             my $secmatch = 0;
+            my $status;
             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
             $user =~ s/:$//;
-            if (($role) && (grep(/^\Q$role\E$/,@{$roles}))) {
+            my ($end,$start) = split(/:/,$coursepersonnel{$person});
+            if ($end == -1 || $start == -1) {
+                next;
+            }
+            if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
+                (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
                 my ($uname,$udom) = split(/:/,$user);
                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
                     if (grep(/^all$/,@{$sections})) {
@@ -4370,8 +4377,13 @@
                     $usec = 'none';
                 }
                 if ($uname ne '' && $udom ne '') {
-                    my $status = &check_user_status($udom,$uname,$cdom,$cnum,$role,
-                                                    $usec);
+                    if ($end < $now) {
+                        $status = 'previous';
+                    } elsif ($start > $now) {
+                        $status = 'future';
+                    } else {
+                        $status = 'active';
+                    }
                     foreach my $type (keys(%{$types})) { 
                         if ($status eq $type) {
                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
@@ -4396,7 +4408,10 @@
                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                 if ( defined($csettings{'internal.courseowner'}) ) {
                     my $owner = $csettings{'internal.courseowner'};
-                    @{$$users{'ow'}{$owner.':'.$cdom}} = 'any';
+                    if ($owner !~ /^[^:]+:[^:]+$/) {
+                        $owner = $owner.':'.$cdom;
+                    }
+                    @{$$users{'ow'}{$owner}} = 'any';
                     if (defined($userdata) && 
 			!exists($$userdata{$owner.':'.$cdom})) {
 			&get_user_info($cdom,$owner,\%idx,$userdata);

--raeburn1154133120--