Diff for /loncom/interface/Attic/londropadd.pm between versions 1.31 and 1.35

version 1.31, 2002/04/26 18:59:00 version 1.35, 2002/04/30 15:24:16
Line 75  ENDHEAD Line 75  ENDHEAD
   
 # =========== Drop student from all sections of a course, except optional $csec  # =========== Drop student from all sections of a course, except optional $csec
 sub modifystudent {  sub modifystudent {
     my ($udom,$unam,$courseid,$csec)=@_;      my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
     # if $csec is undefined, drop the student from all the courses matching      # 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 one.  If $csec is defined, drop them from all other sections of 
     # this course and add them to section $csec      # this course and add them to section $csec
Line 84  sub modifystudent { Line 84  sub modifystudent {
     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);      my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
     my ($tmp) = keys(%roles);      my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles      # Bail out if we were unable to get the students roles
     return if ($tmp =~ /^(con_lost|error|no_such_host)/i);      return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
     # Go through the roles looking for enrollment in this course      # Go through the roles looking for enrollment in this course
       my $result = '';
     foreach my $course (keys(%roles)) {      foreach my $course (keys(%roles)) {
         my $value = $roles{$course};          if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) {
         if ($course=~/^$courseid(?:\/)*(\w+)*\_st$/) {  
             # We are in this course              # We are in this course
             my $section=$1;              my $section=$1;
             $section='' if ($course eq $courseid.'_st');              $section='' if ($course eq $courseid.'_st');
             if (((!$section) && (!$csec)) || ($section ne $csec)) {              if ( ((!$section) && (!$csec)) || ($section ne $csec) ) {
                 my (undef,$end,$start)=split(/\_/,$roles{$course});                  my (undef,$end,$start)=split(/\_/,$roles{$course});
                 my $now=time;                  my $now=time;
                 if (!($start && ($now<$start)) || !($end && ($now>$end))) {                  if (!($start && ($now<$start)) || !($end && ($now>$end))) {
                     my $reply=&Apache::lonnet::modifystudent                      my $reply=&Apache::lonnet::modifystudent
                         ($udom,$unam,'','','','','','','',$section,time);                          ($udom,$unam,'','','','','','','',
                            $section,time,undef,undef,$desiredhost);
                       $result .= $reply.':';
                 }                  }
             }              }
         }          }
     }      }
       if ($result eq '') {
           $result eq 'Unable to find section for this student';
       } elsif ($result =~ /^(ok:)+$/) {
           $result eq 'ok';
       }
       return $result;
 }  }
   
 # ============ build a domain and server selection form  # ============ build a domain and server selection form
Line 502  sub menu_phase_two_upload { Line 510  sub menu_phase_two_upload {
 sub enroll_single_student {  sub enroll_single_student {
     my $r=shift;      my $r=shift;
     $r->print('<h3>Enrolling Student</h3>');      $r->print('<h3>Enrolling Student</h3>');
     $r->print($ENV{'form.cuname'}." in domain ".$ENV{'form.lcdomain'});      $r->print('<p>Enrolling '.$ENV{'form.cuname'}." in domain ".
                 $ENV{'form.lcdomain'}.'</p>');
     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&      if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
         ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {          ($ENV{'form.lcdomain'})&&($ENV{'form.lcdomain'}!~/\W/)) {
         # Deal with home server selection          # Deal with home server selection
Line 518  sub enroll_single_student { Line 527  sub enroll_single_student {
                 return;                  return;
             }              }
         }          }
         $r->print(" with server $desiredhost :");          $r->print(" with server $desiredhost :") if (defined($desiredhost));
         # End of home server selection logic          # End of home server selection logic
  my $amode='';   my $amode='';
         my $genpwd='';          my $genpwd='';
Line 533  sub enroll_single_student { Line 542  sub enroll_single_student {
     $genpwd=$ENV{'form.locarg'};      $genpwd=$ENV{'form.locarg'};
     if (!$genpwd) { $genpwd=" "; }      if (!$genpwd) { $genpwd=" "; }
  }   }
         if (($amode) && ($genpwd)) {          my $home = &Apache::lonnet::homeserver($ENV{'form.cuname'},
                                                      $ENV{'form.lcdomain'});
           if ((($amode) && ($genpwd)) || ($home ne 'no_host')) {
               &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},
                              $ENV{'request.course.id'},$ENV{'form.csec'},
                               $desiredhost);
           $r->print(&Apache::lonnet::modifystudent(            $r->print(&Apache::lonnet::modifystudent(
                       $ENV{'form.lcdomain'},$ENV{'form.cuname'},                        $ENV{'form.lcdomain'},$ENV{'form.cuname'},
                       $ENV{'form.cstid'},$amode,$genpwd,                        $ENV{'form.cstid'},$amode,$genpwd,
Line 542  sub enroll_single_student { Line 556  sub enroll_single_student {
                       $ENV{'form.csec'},$ENV{'form.enddate'},                        $ENV{'form.csec'},$ENV{'form.enddate'},
                       $ENV{'form.startdate'},$ENV{'form.forceid'},                        $ENV{'form.startdate'},$ENV{'form.forceid'},
                     $desiredhost));                      $desiredhost));
             &modifystudent($ENV{'form.lcdomain'},$ENV{'form.cuname'},  
                            $ENV{'request.course.id'},$ENV{'form.csec'});  
  } else {   } else {
            $r->print('Invalid login mode or password');                  $r->print('<p><font color="#ff0000">ERROR</font>&nbsp;'.
                         'Invalid login mode or password.  '.
                         'Unable to enroll '.$ENV{'form.cuname'}.'.</p>');
         }                    }          
     } else {      } else {
         $r->print('Invalid username or domain');          $r->print('Invalid username or domain');
Line 698  sub show_drop_list { Line 712  sub show_drop_list {
     my ($r,%currentlist)=@_;      my ($r,%currentlist)=@_;
     my $cid=$ENV{'request.course.id'};      my $cid=$ENV{'request.course.id'};
     $r->print(<<'END');      $r->print(<<'END');
   <script>
   function checkAll(field)
   {
       for (i = 0; i < field.length; i++)
           field[i].checked = true ;
   }
   
   function uncheckAll(field)
   {
       for (i = 0; i < field.length; i++)
           field[i].checked = false ;
   }
   </script>
   <p>
 <input type="hidden" name="phase" value="four">  <input type="hidden" name="phase" value="four">
 <table border=2>  <table border=2>
 <tr><th>&nbsp;</th><th>username</th><th>domain</th>  <tr><th>&nbsp;</th><th>username</th><th>domain</th>
Line 732  END Line 760  END
         }          }
     }      }
     $r->print('</table><br>');      $r->print('</table><br>');
     $r->print('<input type=submit value="Drop Students">');      $r->print(<<"END");
   </p><p>
   <input type="button" value="check all" onclick="javascript:checkAll(document.studentform.droplist)"> &nbsp;
   <input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)"> 
   <p><input type=submit value="Drop Students"></p>
   END
 }  }
   
 # ================================================= Drop/Add from uploaded file  # ================================================= Drop/Add from uploaded file
Line 852  sub upfile_drop_add { Line 885  sub upfile_drop_add {
                         }                          }
                     }                      }
                     if ($password) {                      if ($password) {
                           &modifystudent($domain,$username,$cid,$sec,
                                          $desiredhost);
                         my $reply=&Apache::lonnet::modifystudent                          my $reply=&Apache::lonnet::modifystudent
                             ($domain,$username,$id,$amode,$password,                              ($domain,$username,$id,$amode,$password,
                              $fname,$mname,$lname,$gen,$sec,$enddate,                               $fname,$mname,$lname,$gen,$sec,$enddate,
                              $startdate,$ENV{'form.forceid'},$desiredhost);                               $startdate,$ENV{'form.forceid'},$desiredhost);
                         &modifystudent($domain,$username,$cid,$sec);  
                         if ($reply ne 'ok') {                          if ($reply ne 'ok') {
                             $r->print('<p><b>'.                              $r->print('<p><b>'.
                                       'Error enrolling '.$username.': '.                                        'Error enrolling '.$username.': '.
Line 912  sub upfile_drop_add { Line 946  sub upfile_drop_add {
 sub drop_student_list {  sub drop_student_list {
     my $r=shift;      my $r=shift;
     my $count=0;      my $count=0;
     foreach (@{$ENV{'form.droplist'}}) {      my @droplist;
       if (ref($ENV{'form.droplist'})) {
           @droplist = @{$ENV{'form.droplist'}};
       } else {
           @droplist = ($ENV{'form.droplist'});
       }
       foreach (@droplist) {
         my ($uname,$udom)=split(/\:/,$_);          my ($uname,$udom)=split(/\:/,$_);
         &modifystudent($udom,$uname,$ENV{'request.course.id'});          my $result = &modifystudent($udom,$uname,$ENV{'request.course.id'});
         $r->print('Dropped '.$uname.' at '.$udom.'<br>');          if ($result eq 'ok') {
               $r->print('Dropped '.$uname.' at '.$udom.'<br>');
           } else {
               $r->print('Error dropping '.$uname.' at '.$udom.': '.$result.
                         '<br />');
           }
         $count++;          $count++;
     }      }
     $r->print('<p><b>Dropped '.$count.' student(s).</b>');      $r->print('<p><b>Dropped '.$count.' student(s).</b>');

Removed from v.1.31  
changed lines
  Added in v.1.35


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>