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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 23 Nov 2006 03:17:18 -0000


albertel		Wed Nov 22 22:17:18 2006 EDT

  Modified files:              
    /loncom/interface	londropadd.pm 
  Log:
  - switch to username helpers
  - stop splitting $cid on _
  - stop trying to turn course id is nto role decriptiors using re
  
  
Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.149 loncom/interface/londropadd.pm:1.150
--- loncom/interface/londropadd.pm:1.149	Wed Nov 22 19:17:01 2006
+++ loncom/interface/londropadd.pm	Wed Nov 22 22:17:17 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to drop and add students in courses 
 #
-# $Id: londropadd.pm,v 1.149 2006/11/23 00:17:01 albertel Exp $
+# $Id: londropadd.pm,v 1.150 2006/11/23 03:17:17 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,8 +60,8 @@
     # if $csec is undefined, drop the student from all the courses matching
     # this one.  If $csec is defined, drop them from all other sections of 
     # this course and add them to section $csec
-    $courseid=~s/\_/\//g;
-    $courseid=~s/^(\w)/\/$1/;
+    my $cdom = $env{'request.'.$courseid.'.domain'};
+    my $cnum = $env{'request.'.$courseid.'.num'};
     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
     my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles
@@ -69,10 +69,10 @@
     # Go through the roles looking for enrollment in this course
     my $result = '';
     foreach my $course (keys(%roles)) {
-        if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
+        if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) {
             # We are in this course
             my $section=$1;
-            $section='' if ($course eq $courseid.'_st');
+            $section='' if ($course eq "/$cdom/$cnum".'_st');
             if (defined($csec) && $section eq $csec) {
                 $result .= 'ok:';
             } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
@@ -135,7 +135,9 @@
     my ($r,$enrl_permission,$view_permission,$grp_manage_permission,
         $grp_view_permission)=@_;
     #
-    my ($cdom,$cnum) = split/_/,$env{'request.course.id'};
+    my $cid =$env{'request.course.id'};
+    my $cdom=$env{'course.'.$cid.'.domain'};
+    my $cnum=$env{'course.'.$cid.'.num'};
     my @menu = 
         ( 
           { text => 'Upload a class list', 
@@ -746,8 +748,12 @@
     $r->print('<h3>'.&mt('Enrolling Student').'</h3>');
     $r->print('<p>'.&mt('Enrolling').' '.$env{'form.cuname'}." \@ ".
               $env{'form.lcdomain'}.'</p>');
-    if (($env{'form.cuname'})&&($env{'form.cuname'}!~/\W/)&&
-        ($env{'form.lcdomain'})&&($env{'form.lcdomain'}!~/\W/)) {
+    if (($env{'form.cuname'})
+	&& ($env{'form.cuname'} 
+	    eq &LONCAPA::clean_username($env{'form.cuname'}))
+	&& ($env{'form.lcdomain'})
+	&& ($env{'form.lcdomain'}
+	    eq &LONCAPA::clean_domain($env{'form.lcdomain'}))) {
         # Deal with home server selection
         my $domain=$env{'form.lcdomain'};
         my $desiredhost = $env{'form.lcserver'};
@@ -957,10 +963,8 @@
     my $r=shift;
     $r->print("<h3>".&mt('Enroll One Student')."</h3>");
     #
-    my $username = $env{'form.cuname'};
-    my $domain   = $env{'form.cudomain'};
-    $username=~s/\W//gs;
-    $domain=~s/\W//gs;
+    my $username = &LONCAPA::clean_username($env{'form.cuname'});
+    my $domain   = &LONCAPA::clean_domain($env{'form.cudomain'});
     my $home = &Apache::lonnet::homeserver($username,$domain);
     # $new_user flags whether we are creating a new user or using an old one
     my $new_user = 1;
@@ -1177,7 +1181,7 @@
     }
     my $status_select = &Apache::lonhtmlcommon::StatusOptions
         ($env{'form.Status'});
-    my $cid=$env{'request.course.id'};
+    my $cid =$env{'request.course.id'};
     my $cdom=$env{'course.'.$cid.'.domain'};
     my $cnum=$env{'course.'.$cid.'.num'};
     #
@@ -1870,7 +1874,8 @@
 sub get_enrollment_data {
     my ($sname,$sdomain) = @_;
     my $courseid = $env{'request.course.id'};
-    $courseid =~ s:_:/:g;
+    my $cdom = $env{'request.'.$courseid.'.domain'};
+    my $cnum = $env{'request.'.$courseid.'.num'};
     my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname);
     my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles
@@ -1880,7 +1885,7 @@
     my $section = '';
     my $count = scalar(keys(%roles));
     while (my ($course,$role) = each(%roles)) {
-        if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) {
+        if ($course=~m{^/\Q$cdom\E/\Q$cnum\E/*\s*(\w+)*_st$} ) {
             #
             # Get active role
             $section=$1;
@@ -2193,7 +2198,8 @@
             $amode = ''; # This causes the loop below to be skipped
         }
     }
-    unless (($domain=~/\W/) || ($amode eq '')) {
+    if ( $domain eq &clean_domain($domain)
+	&& ($amode ne '')) {
         #######################################
         ##         Enroll Students           ##
         #######################################
@@ -2227,7 +2233,8 @@
                         $gen=$entries{$fields{'gen'}};
                     }
                 }
-                if ($entries{$fields{'username'}}=~/\W/) {
+                if ($entries{$fields{'username'}}
+		    ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
                     $r->print('<br />'.
       &mt('<b>[_1]</b>: Unacceptable username for user [_2] [_3] [_4] [_5]',
           $entries{$fields{'username'}},$fname,$mname,$lname,$gen).